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

Side by Side Diff: third_party/re2/util/sparse_set.h

Issue 10873029: Migrate WebRequestRedirectByRegExAction to use RE2 and roll RE2 to revision 97:401ab4168e8e (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/re2/util/sparse_array.h ('k') | third_party/re2/util/util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006 The RE2 Authors. All Rights Reserved. 1 // Copyright 2006 The RE2 Authors. All Rights Reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // DESCRIPTION 5 // DESCRIPTION
6 // 6 //
7 // SparseSet<T>(m) is a set of integers in [0, m). 7 // SparseSet<T>(m) is a set of integers in [0, m).
8 // It requires sizeof(int)*m memory, but it provides 8 // It requires sizeof(int)*m memory, but it provides
9 // fast iteration through the elements in the set and fast clearing 9 // fast iteration through the elements in the set and fast clearing
10 // of the set. 10 // of the set.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #ifndef RE2_UTIL_SPARSE_SET_H__ 47 #ifndef RE2_UTIL_SPARSE_SET_H__
48 #define RE2_UTIL_SPARSE_SET_H__ 48 #define RE2_UTIL_SPARSE_SET_H__
49 49
50 #include "util/util.h" 50 #include "util/util.h"
51 51
52 namespace re2 { 52 namespace re2 {
53 53
54 class SparseSet { 54 class SparseSet {
55 public: 55 public:
56 SparseSet() 56 SparseSet()
57 : size_(0), max_size_(0), sparse_to_dense_(NULL), dense_(NULL) {} 57 : size_(0), max_size_(0), sparse_to_dense_(NULL), dense_(NULL), valgrind_(Ru nningOnValgrind()) {}
58 58
59 SparseSet(int max_size) { 59 SparseSet(int max_size) {
60 max_size_ = max_size; 60 max_size_ = max_size;
61 sparse_to_dense_ = new int[max_size]; 61 sparse_to_dense_ = new int[max_size];
62 dense_ = new int[max_size]; 62 dense_ = new int[max_size];
63 valgrind_ = RunningOnValgrind();
63 // Don't need to zero the memory, but do so anyway 64 // Don't need to zero the memory, but do so anyway
64 // to appease Valgrind. 65 // to appease Valgrind.
65 if (RunningOnValgrind()) { 66 if (valgrind_) {
66 for (int i = 0; i < max_size; i++) { 67 for (int i = 0; i < max_size; i++) {
67 dense_[i] = 0xababababU; 68 dense_[i] = 0xababababU;
68 sparse_to_dense_[i] = 0xababababU; 69 sparse_to_dense_[i] = 0xababababU;
69 } 70 }
70 } 71 }
71 size_ = 0; 72 size_ = 0;
72 } 73 }
73 74
74 ~SparseSet() { 75 ~SparseSet() {
75 delete[] sparse_to_dense_; 76 delete[] sparse_to_dense_;
(...skipping 11 matching lines...) Expand all
87 88
88 // Change the maximum size of the array. 89 // Change the maximum size of the array.
89 // Invalidates all iterators. 90 // Invalidates all iterators.
90 void resize(int new_max_size) { 91 void resize(int new_max_size) {
91 if (size_ > new_max_size) 92 if (size_ > new_max_size)
92 size_ = new_max_size; 93 size_ = new_max_size;
93 if (new_max_size > max_size_) { 94 if (new_max_size > max_size_) {
94 int* a = new int[new_max_size]; 95 int* a = new int[new_max_size];
95 if (sparse_to_dense_) { 96 if (sparse_to_dense_) {
96 memmove(a, sparse_to_dense_, max_size_*sizeof a[0]); 97 memmove(a, sparse_to_dense_, max_size_*sizeof a[0]);
97 if (RunningOnValgrind()) { 98 if (valgrind_) {
98 for (int i = max_size_; i < new_max_size; i++) 99 for (int i = max_size_; i < new_max_size; i++)
99 a[i] = 0xababababU; 100 a[i] = 0xababababU;
100 } 101 }
101 delete[] sparse_to_dense_; 102 delete[] sparse_to_dense_;
102 } 103 }
103 sparse_to_dense_ = a; 104 sparse_to_dense_ = a;
104 105
105 a = new int[new_max_size]; 106 a = new int[new_max_size];
106 if (dense_) { 107 if (dense_) {
107 memmove(a, dense_, size_*sizeof a[0]); 108 memmove(a, dense_, size_*sizeof a[0]);
108 if (RunningOnValgrind()) { 109 if (valgrind_) {
109 for (int i = size_; i < new_max_size; i++) 110 for (int i = size_; i < new_max_size; i++)
110 a[i] = 0xababababU; 111 a[i] = 0xababababU;
111 } 112 }
112 delete[] dense_; 113 delete[] dense_;
113 } 114 }
114 dense_ = a; 115 dense_ = a;
115 } 116 }
116 max_size_ = new_max_size; 117 max_size_ = new_max_size;
117 } 118 }
118 119
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // Can sort the sparse array so that future iterations 162 // Can sort the sparse array so that future iterations
162 // will visit indices in increasing order using 163 // will visit indices in increasing order using
163 // sort(arr.begin(), arr.end(), arr.less); 164 // sort(arr.begin(), arr.end(), arr.less);
164 static bool less(int a, int b) { return a < b; } 165 static bool less(int a, int b) { return a < b; }
165 166
166 private: 167 private:
167 int size_; 168 int size_;
168 int max_size_; 169 int max_size_;
169 int* sparse_to_dense_; 170 int* sparse_to_dense_;
170 int* dense_; 171 int* dense_;
172 bool valgrind_;
171 173
172 DISALLOW_EVIL_CONSTRUCTORS(SparseSet); 174 DISALLOW_EVIL_CONSTRUCTORS(SparseSet);
173 }; 175 };
174 176
175 } // namespace re2 177 } // namespace re2
176 178
177 #endif // RE2_UTIL_SPARSE_SET_H__ 179 #endif // RE2_UTIL_SPARSE_SET_H__
OLDNEW
« no previous file with comments | « third_party/re2/util/sparse_array.h ('k') | third_party/re2/util/util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698