OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_COMMON_VISITEDLINK_COMMON_H__ | 5 #ifndef CHROME_COMMON_VISITEDLINK_COMMON_H__ |
6 #define CHROME_COMMON_VISITEDLINK_COMMON_H__ | 6 #define CHROME_COMMON_VISITEDLINK_COMMON_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 uint32 length; | 87 uint32 length; |
88 | 88 |
89 // goes into salt_ | 89 // goes into salt_ |
90 uint8 salt[LINK_SALT_LENGTH]; | 90 uint8 salt[LINK_SALT_LENGTH]; |
91 }; | 91 }; |
92 | 92 |
93 // Returns the fingerprint at the given index into the URL table. This | 93 // Returns the fingerprint at the given index into the URL table. This |
94 // function should be called instead of accessing the table directly to | 94 // function should be called instead of accessing the table directly to |
95 // contain endian issues. | 95 // contain endian issues. |
96 Fingerprint FingerprintAt(int32 table_offset) const { | 96 Fingerprint FingerprintAt(int32 table_offset) const { |
97 DCHECK(hash_table_); | |
98 if (!hash_table_) | 97 if (!hash_table_) |
99 return 0; | 98 return null_fingerprint_; |
100 return hash_table_[table_offset]; | 99 return hash_table_[table_offset]; |
101 } | 100 } |
102 | 101 |
103 // Computes the fingerprint of the given canonical URL. It is static so the | 102 // Computes the fingerprint of the given canonical URL. It is static so the |
104 // same algorithm can be re-used by the table rebuilder, so you will have to | 103 // same algorithm can be re-used by the table rebuilder, so you will have to |
105 // pass the salt as a parameter. See the non-static version above if you | 104 // pass the salt as a parameter. See the non-static version above if you |
106 // want to use the current class' salt. | 105 // want to use the current class' salt. |
107 static Fingerprint ComputeURLFingerprint(const char* canonical_url, | 106 static Fingerprint ComputeURLFingerprint(const char* canonical_url, |
108 size_t url_len, | 107 size_t url_len, |
109 const uint8 salt[LINK_SALT_LENGTH]); | 108 const uint8 salt[LINK_SALT_LENGTH]); |
110 | 109 |
111 // Computes the hash value of the given fingerprint, this is used as a lookup | 110 // Computes the hash value of the given fingerprint, this is used as a lookup |
112 // into the hashtable. | 111 // into the hashtable. |
113 static Hash HashFingerprint(Fingerprint fingerprint, int32 table_length) { | 112 static Hash HashFingerprint(Fingerprint fingerprint, int32 table_length) { |
| 113 if (table_length == 0) |
| 114 return null_hash_; |
114 return static_cast<Hash>(fingerprint % table_length); | 115 return static_cast<Hash>(fingerprint % table_length); |
115 } | 116 } |
116 // Uses the current hashtable. | 117 // Uses the current hashtable. |
117 Hash HashFingerprint(Fingerprint fingerprint) const { | 118 Hash HashFingerprint(Fingerprint fingerprint) const { |
118 return HashFingerprint(fingerprint, table_length_); | 119 return HashFingerprint(fingerprint, table_length_); |
119 } | 120 } |
120 | 121 |
121 // pointer to the first item | 122 // pointer to the first item |
122 VisitedLinkCommon::Fingerprint* hash_table_; | 123 VisitedLinkCommon::Fingerprint* hash_table_; |
123 | 124 |
124 // the number of items in the hash table | 125 // the number of items in the hash table |
125 int32 table_length_; | 126 int32 table_length_; |
126 | 127 |
127 // salt used for each URL when computing the fingerprint | 128 // salt used for each URL when computing the fingerprint |
128 uint8 salt_[LINK_SALT_LENGTH]; | 129 uint8 salt_[LINK_SALT_LENGTH]; |
129 | 130 |
130 private: | 131 private: |
131 DISALLOW_EVIL_CONSTRUCTORS(VisitedLinkCommon); | 132 DISALLOW_EVIL_CONSTRUCTORS(VisitedLinkCommon); |
132 }; | 133 }; |
133 | 134 |
134 #endif // WIN_COMMON_VISITEDLINK_COMMON_H__ | 135 #endif // WIN_COMMON_VISITEDLINK_COMMON_H__ |
OLD | NEW |