Changeset 3736 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Mar 3, 2003, 5:13:26 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r3373 r3736 178 178 } 179 179 180 // Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's 181 // or anything like that. 182 const unsigned PHI = 0x9e3779b9U; 183 184 // This hash algorithm comes from: 185 // http://burtleburtle.net/bob/hash/hashfaq.html 186 // http://burtleburtle.net/bob/hash/doobs.html 180 187 unsigned UString::Rep::computeHash(const UChar *s, int length) 181 188 { … … 183 190 int suffixPosition = length < 16 ? 8 : length - 8; 184 191 185 unsigned h = length; 186 for (int i = 0; i < prefixLength; i++) 187 h = 127 * h + s[i].uc; 188 for (int i = suffixPosition; i < length; i++) 189 h = 127 * h + s[i].uc; 192 unsigned h = PHI; 193 h += length; 194 h += (h << 10); 195 h ^= (h << 6); 196 197 for (int i = 0; i < prefixLength; i++) { 198 h += s[i].uc; 199 h += (h << 10); 200 h ^= (h << 6); 201 } 202 for (int i = suffixPosition; i < length; i++){ 203 h += s[i].uc; 204 h += (h << 10); 205 h ^= (h << 6); 206 } 207 208 h += (h << 3); 209 h ^= (h >> 11); 210 h += (h << 15); 211 190 212 if (h == 0) 191 213 h = 0x80000000; 214 192 215 return h; 193 216 } 194 217 218 // This hash algorithm comes from: 219 // http://burtleburtle.net/bob/hash/hashfaq.html 220 // http://burtleburtle.net/bob/hash/doobs.html 195 221 unsigned UString::Rep::computeHash(const char *s) 196 222 { … … 199 225 int suffixPosition = length < 16 ? 8 : length - 8; 200 226 201 unsigned h = length; 202 for (int i = 0; i < prefixLength; i++) 203 h = 127 * h + (unsigned char)s[i]; 204 for (int i = suffixPosition; i < length; i++) 205 h = 127 * h + (unsigned char)s[i]; 227 unsigned h = PHI; 228 h += length; 229 h += (h << 10); 230 h ^= (h << 6); 231 232 for (int i = 0; i < prefixLength; i++) { 233 h += (unsigned char)s[i]; 234 h += (h << 10); 235 h ^= (h << 6); 236 } 237 for (int i = suffixPosition; i < length; i++) { 238 h += (unsigned char)s[i]; 239 h += (h << 10); 240 h ^= (h << 6); 241 } 242 243 h += (h << 3); 244 h ^= (h >> 11); 245 h += (h << 15); 246 206 247 if (h == 0) 207 248 h = 0x80000000; 249 208 250 return h; 209 251 }
Note:
See TracChangeset
for help on using the changeset viewer.