| OLD | NEW |
| 1 /* | 1 /* |
| 2 ****************************************************************************** | 2 ****************************************************************************** |
| 3 * Copyright (C) 1997-2011, International Business Machines | 3 * Copyright (C) 1997-2014, International Business Machines |
| 4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
| 5 ****************************************************************************** | 5 ****************************************************************************** |
| 6 * Date Name Description | 6 * Date Name Description |
| 7 * 03/22/00 aliu Adapted from original C++ ICU Hashtable. | 7 * 03/22/00 aliu Adapted from original C++ ICU Hashtable. |
| 8 * 07/06/01 aliu Modified to support int32_t keys on | 8 * 07/06/01 aliu Modified to support int32_t keys on |
| 9 * platforms with sizeof(void*) < 32. | 9 * platforms with sizeof(void*) < 32. |
| 10 ****************************************************************************** | 10 ****************************************************************************** |
| 11 */ | 11 */ |
| 12 | 12 |
| 13 #include "uhash.h" | 13 #include "uhash.h" |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 return _uhash_init(fillinResult, keyHash, keyComp, valueComp, DEFAULT_PRIME_
INDEX, status); | 568 return _uhash_init(fillinResult, keyHash, keyComp, valueComp, DEFAULT_PRIME_
INDEX, status); |
| 569 } | 569 } |
| 570 | 570 |
| 571 U_CAPI void U_EXPORT2 | 571 U_CAPI void U_EXPORT2 |
| 572 uhash_close(UHashtable *hash) { | 572 uhash_close(UHashtable *hash) { |
| 573 if (hash == NULL) { | 573 if (hash == NULL) { |
| 574 return; | 574 return; |
| 575 } | 575 } |
| 576 if (hash->elements != NULL) { | 576 if (hash->elements != NULL) { |
| 577 if (hash->keyDeleter != NULL || hash->valueDeleter != NULL) { | 577 if (hash->keyDeleter != NULL || hash->valueDeleter != NULL) { |
| 578 int32_t pos=-1; | 578 int32_t pos=UHASH_FIRST; |
| 579 UHashElement *e; | 579 UHashElement *e; |
| 580 while ((e = (UHashElement*) uhash_nextElement(hash, &pos)) != NULL)
{ | 580 while ((e = (UHashElement*) uhash_nextElement(hash, &pos)) != NULL)
{ |
| 581 HASH_DELETE_KEY_VALUE(hash, e->key.pointer, e->value.pointer); | 581 HASH_DELETE_KEY_VALUE(hash, e->key.pointer, e->value.pointer); |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 uprv_free(hash->elements); | 584 uprv_free(hash->elements); |
| 585 hash->elements = NULL; | 585 hash->elements = NULL; |
| 586 } | 586 } |
| 587 if (hash->allocated) { | 587 if (hash->allocated) { |
| 588 uprv_free(hash); | 588 uprv_free(hash); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 U_CAPI int32_t U_EXPORT2 | 749 U_CAPI int32_t U_EXPORT2 |
| 750 uhash_iremovei(UHashtable *hash, | 750 uhash_iremovei(UHashtable *hash, |
| 751 int32_t key) { | 751 int32_t key) { |
| 752 UHashTok keyholder; | 752 UHashTok keyholder; |
| 753 keyholder.integer = key; | 753 keyholder.integer = key; |
| 754 return _uhash_remove(hash, keyholder).integer; | 754 return _uhash_remove(hash, keyholder).integer; |
| 755 } | 755 } |
| 756 | 756 |
| 757 U_CAPI void U_EXPORT2 | 757 U_CAPI void U_EXPORT2 |
| 758 uhash_removeAll(UHashtable *hash) { | 758 uhash_removeAll(UHashtable *hash) { |
| 759 int32_t pos = -1; | 759 int32_t pos = UHASH_FIRST; |
| 760 const UHashElement *e; | 760 const UHashElement *e; |
| 761 U_ASSERT(hash != NULL); | 761 U_ASSERT(hash != NULL); |
| 762 if (hash->count != 0) { | 762 if (hash->count != 0) { |
| 763 while ((e = uhash_nextElement(hash, &pos)) != NULL) { | 763 while ((e = uhash_nextElement(hash, &pos)) != NULL) { |
| 764 uhash_removeElement(hash, e); | 764 uhash_removeElement(hash, e); |
| 765 } | 765 } |
| 766 } | 766 } |
| 767 U_ASSERT(hash->count == 0); | 767 U_ASSERT(hash->count == 0); |
| 768 } | 768 } |
| 769 | 769 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 */ | 878 */ |
| 879 return FALSE; | 879 return FALSE; |
| 880 } | 880 } |
| 881 | 881 |
| 882 count1 = uhash_count(hash1); | 882 count1 = uhash_count(hash1); |
| 883 count2 = uhash_count(hash2); | 883 count2 = uhash_count(hash2); |
| 884 if(count1!=count2){ | 884 if(count1!=count2){ |
| 885 return FALSE; | 885 return FALSE; |
| 886 } | 886 } |
| 887 | 887 |
| 888 pos=-1; | 888 pos=UHASH_FIRST; |
| 889 for(i=0; i<count1; i++){ | 889 for(i=0; i<count1; i++){ |
| 890 const UHashElement* elem1 = uhash_nextElement(hash1, &pos); | 890 const UHashElement* elem1 = uhash_nextElement(hash1, &pos); |
| 891 const UHashTok key1 = elem1->key; | 891 const UHashTok key1 = elem1->key; |
| 892 const UHashTok val1 = elem1->value; | 892 const UHashTok val1 = elem1->value; |
| 893 /* here the keys are not compared, instead the key form hash1 is used to
fetch | 893 /* here the keys are not compared, instead the key form hash1 is used to
fetch |
| 894 * value from hash2. If the hashes are equal then then both hashes shoul
d | 894 * value from hash2. If the hashes are equal then then both hashes shoul
d |
| 895 * contain equal values for the same key! | 895 * contain equal values for the same key! |
| 896 */ | 896 */ |
| 897 const UHashElement* elem2 = _uhash_find(hash2, key1, hash2->keyHasher(ke
y1)); | 897 const UHashElement* elem2 = _uhash_find(hash2, key1, hash2->keyHasher(ke
y1)); |
| 898 const UHashTok val2 = elem2->value; | 898 const UHashTok val2 = elem2->value; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 | 964 |
| 965 U_CAPI int32_t U_EXPORT2 | 965 U_CAPI int32_t U_EXPORT2 |
| 966 uhash_hashLong(const UHashTok key) { | 966 uhash_hashLong(const UHashTok key) { |
| 967 return key.integer; | 967 return key.integer; |
| 968 } | 968 } |
| 969 | 969 |
| 970 U_CAPI UBool U_EXPORT2 | 970 U_CAPI UBool U_EXPORT2 |
| 971 uhash_compareLong(const UHashTok key1, const UHashTok key2) { | 971 uhash_compareLong(const UHashTok key1, const UHashTok key2) { |
| 972 return (UBool)(key1.integer == key2.integer); | 972 return (UBool)(key1.integer == key2.integer); |
| 973 } | 973 } |
| OLD | NEW |