Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: pdf/range_set.h

Issue 2349753003: Improve linearized pdf load/show time. (Closed)
Patch Set: Fix review issues. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pdf/range_set.h
diff --git a/pdf/range_set.h b/pdf/range_set.h
new file mode 100644
index 0000000000000000000000000000000000000000..39ef29f74478395c23f205ca93e4fe68555b2de9
--- /dev/null
+++ b/pdf/range_set.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Defines a set of geometric ranges, and standard operations on it.
+
+#ifndef PDF_RANGE_SET_H_
+#define PDF_RANGE_SET_H_
+
+#include <ostream>
+#include <set>
+#include <string>
+
+#include "ui/gfx/range/range.h"
+
+namespace chrome_pdf {
+
+class RangeSet {
+ public:
+ RangeSet();
+ explicit RangeSet(const gfx::Range& range);
+ ~RangeSet();
+
+ RangeSet(const RangeSet& range_set);
+ RangeSet(RangeSet&& range_set);
+ RangeSet& operator=(const RangeSet& other);
+
+ bool operator==(const RangeSet& other) const;
+ bool operator!=(const RangeSet& other) const;
+
+ void Union(const gfx::Range& range);
Lei Zhang 2016/10/21 09:33:10 Put this with the other RangeSet modifiers.
snake 2016/10/21 15:13:15 What do you mean?
Lei Zhang 2016/10/25 06:01:49 What I mean is, you have Contains() and Intersects
snake 2016/10/25 13:57:34 Done.
+ void Union(const RangeSet& range_set);
+
+ bool Contains(uint32_t point) const;
+ bool Contains(const gfx::Range& range) const;
+ bool Contains(const RangeSet& range_set) const;
+
+ bool Intersects(const gfx::Range& range) const;
+ bool Intersects(const RangeSet& range_set) const;
+
+ void Intersect(const gfx::Range& range);
+ void Intersect(const RangeSet& range_set);
+
+ void Subtract(const gfx::Range& range);
+ void Subtract(const RangeSet& range_set);
+
+ void Xor(const gfx::Range& range);
Lei Zhang 2016/10/21 09:33:10 Is this ever going to get used in anything but uni
snake 2016/10/21 15:13:15 I want to use it in my next CLs. Also, it is part
Lei Zhang 2016/10/25 06:01:49 Ok, got it. If you are going to use it soon, then
+ void Xor(const RangeSet& range_set);
+
+ bool IsEmpty() const;
+ void Clear();
+
+ gfx::Range First() const;
+ gfx::Range Last() const;
+ std::string ToString() const;
Lei Zhang 2016/10/21 09:33:10 Are ToString() and operator<< only used in one uni
snake 2016/10/21 15:13:15 It will be used in other unit test files.
+
+ struct range_compare {
+ bool operator()(const gfx::Range& lval, const gfx::Range& rval) const {
+ return lval.start() < rval.start();
+ }
+ };
+
+ typedef std::set<gfx::Range, range_compare> RangesContainer;
Lei Zhang 2016/10/21 09:33:10 not: using foo = bar, instead of typedef bar foo.
snake 2016/10/21 15:13:15 Done.
+
+ const RangesContainer& ranges() const { return ranges_; }
+ size_t Size() const { return ranges_.size(); }
+
+ private:
+ RangesContainer ranges_;
+};
+
+} // namespace chrome_pdf
+
+std::ostream& operator<<(std::ostream& os,
+ const chrome_pdf::RangeSet& range_set);
+
+#endif // PDF_RANGE_SET_H_

Powered by Google App Engine
This is Rietveld 408576698