OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // A read-only set implementation for |SBPrefix| items. Prefixes are | 5 // A read-only set implementation for |SBPrefix| items. Prefixes are |
6 // sorted and stored as 16-bit deltas from the previous prefix. An | 6 // sorted and stored as 16-bit deltas from the previous prefix. An |
7 // index structure provides quick random access, and also handles | 7 // index structure provides quick random access, and also handles |
8 // cases where 16 bits cannot encode a delta. | 8 // cases where 16 bits cannot encode a delta. |
9 // | 9 // |
10 // For example, the sequence {20, 25, 41, 65432, 150000, 160000} would | 10 // For example, the sequence {20, 25, 41, 65432, 150000, 160000} would |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 size_t GetSize() const; | 82 size_t GetSize() const; |
83 | 83 |
84 // Returns |true| if the element at |target_index| is between items in the | 84 // Returns |true| if the element at |target_index| is between items in the |
85 // |index_| array. | 85 // |index_| array. |
86 bool IsDeltaAt(size_t target_index) const; | 86 bool IsDeltaAt(size_t target_index) const; |
87 | 87 |
88 // Returns the delta used to calculate the element at | 88 // Returns the delta used to calculate the element at |
89 // |target_index|. Only call if |IsDeltaAt()| returned |true|. | 89 // |target_index|. Only call if |IsDeltaAt()| returned |true|. |
90 uint16 DeltaAt(size_t target_index) const; | 90 uint16 DeltaAt(size_t target_index) const; |
91 | 91 |
92 // Check whether |index_| and |deltas_| still match the CRC | 92 // Check whether |index_| and |deltas_| still match the checksum |
93 // generated during construction. | 93 // generated during construction. |
94 bool CheckChecksum() const; | 94 bool CheckChecksum() const; |
95 | 95 |
| 96 // Accumulates xor checksum over what GetPrefixes() would return, |
| 97 // without requiring a large temporary structure. |
| 98 SBPrefix GetPrefixesChecksum() const; |
| 99 |
96 private: | 100 private: |
97 // Maximum number of consecutive deltas to encode before generating | 101 // Maximum number of consecutive deltas to encode before generating |
98 // a new index entry. This helps keep the worst-case performance | 102 // a new index entry. This helps keep the worst-case performance |
99 // for |Exists()| under control. | 103 // for |Exists()| under control. |
100 static const size_t kMaxRun = 100; | 104 static const size_t kMaxRun = 100; |
101 | 105 |
102 // Helper for |LoadFile()|. Steals the contents of |index| and | 106 // Helper for |LoadFile()|. Steals the contents of |index| and |
103 // |deltas| using |swap()|. | 107 // |deltas| using |swap()|. |
104 PrefixSet(std::vector<std::pair<SBPrefix,size_t> > *index, | 108 PrefixSet(std::vector<std::pair<SBPrefix,size_t> > *index, |
105 std::vector<uint16> *deltas); | 109 std::vector<uint16> *deltas); |
(...skipping 13 matching lines...) Expand all Loading... |
119 // changed after generation during construction. |checksum_| is | 123 // changed after generation during construction. |checksum_| is |
120 // calculated from the data used to construct those vectors. | 124 // calculated from the data used to construct those vectors. |
121 uint32 checksum_; | 125 uint32 checksum_; |
122 | 126 |
123 DISALLOW_COPY_AND_ASSIGN(PrefixSet); | 127 DISALLOW_COPY_AND_ASSIGN(PrefixSet); |
124 }; | 128 }; |
125 | 129 |
126 } // namespace safe_browsing | 130 } // namespace safe_browsing |
127 | 131 |
128 #endif // CHROME_BROWSER_SAFE_BROWSING_PREFIX_SET_H_ | 132 #endif // CHROME_BROWSER_SAFE_BROWSING_PREFIX_SET_H_ |
OLD | NEW |