]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ****************************************************************************** | |
3 | * Copyright (C) 1997-2001, International Business Machines | |
4 | * Corporation and others. All Rights Reserved. | |
5 | ****************************************************************************** | |
6 | * Date Name Description | |
7 | * 03/22/00 aliu Creation. | |
8 | * 07/06/01 aliu Modified to support int32_t keys on | |
9 | * platforms with sizeof(void*) < 32. | |
10 | ****************************************************************************** | |
11 | */ | |
12 | ||
13 | #include "uhash.h" | |
14 | #include "hash.h" | |
15 | #include "uvector.h" | |
16 | #include "unicode/unistr.h" | |
17 | #include "unicode/uchar.h" | |
18 | ||
19 | /******************************************************************** | |
20 | * PUBLIC UnicodeString support functions for UHashtable | |
21 | ********************************************************************/ | |
22 | ||
23 | U_CAPI int32_t U_EXPORT2 | |
24 | uhash_hashUnicodeString(const UHashTok key) { | |
25 | U_NAMESPACE_USE | |
26 | const UnicodeString *str = (const UnicodeString*) key.pointer; | |
27 | return (str == NULL) ? 0 : str->hashCode(); | |
28 | } | |
29 | ||
30 | U_CAPI int32_t U_EXPORT2 | |
31 | uhash_hashCaselessUnicodeString(const UHashTok key) { | |
32 | U_NAMESPACE_USE | |
33 | const UnicodeString *str = (const UnicodeString*) key.pointer; | |
34 | if (str == NULL) { | |
35 | return 0; | |
36 | } | |
37 | // Inefficient; a better way would be to have a hash function in | |
38 | // UnicodeString that does case folding on the fly. | |
39 | UnicodeString copy(*str); | |
40 | return copy.foldCase().hashCode(); | |
41 | } | |
42 | ||
43 | U_CAPI void U_EXPORT2 | |
44 | uhash_deleteUnicodeString(void *obj) { | |
45 | U_NAMESPACE_USE | |
46 | delete (UnicodeString*) obj; | |
47 | } | |
48 | ||
49 | U_CAPI UBool U_EXPORT2 | |
50 | uhash_compareUnicodeString(const UHashTok key1, const UHashTok key2) { | |
51 | U_NAMESPACE_USE | |
52 | const UnicodeString *str1 = (const UnicodeString*) key1.pointer; | |
53 | const UnicodeString *str2 = (const UnicodeString*) key2.pointer; | |
54 | if (str1 == str2) { | |
55 | return TRUE; | |
56 | } | |
57 | if (str1 == NULL || str2 == NULL) { | |
58 | return FALSE; | |
59 | } | |
60 | return *str1 == *str2; | |
61 | } | |
62 | ||
63 | U_CAPI UBool U_EXPORT2 | |
64 | uhash_compareCaselessUnicodeString(const UHashTok key1, const UHashTok key2) { | |
65 | U_NAMESPACE_USE | |
66 | const UnicodeString *str1 = (const UnicodeString*) key1.pointer; | |
67 | const UnicodeString *str2 = (const UnicodeString*) key2.pointer; | |
68 | if (str1 == str2) { | |
69 | return TRUE; | |
70 | } | |
71 | if (str1 == NULL || str2 == NULL) { | |
72 | return FALSE; | |
73 | } | |
74 | return str1->caseCompare(*str2, U_FOLD_CASE_DEFAULT) == 0; | |
75 | } | |
76 | ||
77 | /** | |
78 | * Deleter for Hashtable objects. | |
79 | */ | |
80 | U_CAPI void U_EXPORT2 | |
81 | uhash_deleteHashtable(void *obj) { | |
82 | U_NAMESPACE_USE | |
83 | delete (Hashtable*) obj; | |
84 | } | |
85 | ||
86 | /** | |
87 | * Deleter for UVector objects. | |
88 | */ | |
89 | U_CAPI void U_EXPORT2 | |
90 | uhash_deleteUVector(void *obj) { | |
91 | U_NAMESPACE_USE | |
92 | delete (UVector*) obj; | |
93 | } | |
94 | ||
95 | //eof |