| OLD | NEW |
| 1 /* | 1 /* |
| 2 ****************************************************************************** | 2 ****************************************************************************** |
| 3 * | 3 * |
| 4 * Copyright (C) 1998-2012, International Business Machines | 4 * Copyright (C) 1998-2014, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
| 6 * | 6 * |
| 7 ****************************************************************************** | 7 ****************************************************************************** |
| 8 * | 8 * |
| 9 * File ustring.cpp | 9 * File ustring.cpp |
| 10 * | 10 * |
| 11 * Modification History: | 11 * Modification History: |
| 12 * | 12 * |
| 13 * Date Name Description | 13 * Date Name Description |
| 14 * 12/07/98 bertrand Creation. | 14 * 12/07/98 bertrand Creation. |
| (...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 /* | 1479 /* |
| 1480 Compute the hash by iterating sparsely over about 32 (up to 63) | 1480 Compute the hash by iterating sparsely over about 32 (up to 63) |
| 1481 characters spaced evenly through the string. For each character, | 1481 characters spaced evenly through the string. For each character, |
| 1482 multiply the previous hash value by a prime number and add the new | 1482 multiply the previous hash value by a prime number and add the new |
| 1483 character in, like a linear congruential random number generator, | 1483 character in, like a linear congruential random number generator, |
| 1484 producing a pseudorandom deterministic value well distributed over | 1484 producing a pseudorandom deterministic value well distributed over |
| 1485 the output range. [LIU] | 1485 the output range. [LIU] |
| 1486 */ | 1486 */ |
| 1487 | 1487 |
| 1488 #define STRING_HASH(TYPE, STR, STRLEN, DEREF) \ | 1488 #define STRING_HASH(TYPE, STR, STRLEN, DEREF) \ |
| 1489 int32_t hash = 0; \ | 1489 uint32_t hash = 0; \ |
| 1490 const TYPE *p = (const TYPE*) STR; \ | 1490 const TYPE *p = (const TYPE*) STR; \ |
| 1491 if (p != NULL) { \ | 1491 if (p != NULL) { \ |
| 1492 int32_t len = (int32_t)(STRLEN); \ | 1492 int32_t len = (int32_t)(STRLEN); \ |
| 1493 int32_t inc = ((len - 32) / 32) + 1; \ | 1493 int32_t inc = ((len - 32) / 32) + 1; \ |
| 1494 const TYPE *limit = p + len; \ | 1494 const TYPE *limit = p + len; \ |
| 1495 while (p<limit) { \ | 1495 while (p<limit) { \ |
| 1496 hash = (hash * 37) + DEREF; \ | 1496 hash = (hash * 37) + DEREF; \ |
| 1497 p += inc; \ | 1497 p += inc; \ |
| 1498 } \ | 1498 } \ |
| 1499 } \ | 1499 } \ |
| 1500 return hash | 1500 return static_cast<int32_t>(hash) |
| 1501 | 1501 |
| 1502 /* Used by UnicodeString to compute its hashcode - Not public API. */ | 1502 /* Used by UnicodeString to compute its hashcode - Not public API. */ |
| 1503 U_CAPI int32_t U_EXPORT2 | 1503 U_CAPI int32_t U_EXPORT2 |
| 1504 ustr_hashUCharsN(const UChar *str, int32_t length) { | 1504 ustr_hashUCharsN(const UChar *str, int32_t length) { |
| 1505 STRING_HASH(UChar, str, length, *p); | 1505 STRING_HASH(UChar, str, length, *p); |
| 1506 } | 1506 } |
| 1507 | 1507 |
| 1508 U_CAPI int32_t U_EXPORT2 | 1508 U_CAPI int32_t U_EXPORT2 |
| 1509 ustr_hashCharsN(const char *str, int32_t length) { | 1509 ustr_hashCharsN(const char *str, int32_t length) { |
| 1510 STRING_HASH(uint8_t, str, length, *p); | 1510 STRING_HASH(uint8_t, str, length, *p); |
| 1511 } | 1511 } |
| 1512 | 1512 |
| 1513 U_CAPI int32_t U_EXPORT2 | 1513 U_CAPI int32_t U_EXPORT2 |
| 1514 ustr_hashICharsN(const char *str, int32_t length) { | 1514 ustr_hashICharsN(const char *str, int32_t length) { |
| 1515 STRING_HASH(char, str, length, (uint8_t)uprv_tolower(*p)); | 1515 STRING_HASH(char, str, length, (uint8_t)uprv_tolower(*p)); |
| 1516 } | 1516 } |
| OLD | NEW |