1 /*
2 *******************************************************************************
3 *   Copyright (C) 1997-2011, International Business Machines
4 *   Corporation and others.  All Rights Reserved.
5 *******************************************************************************
6 *   file name:  uelement.h
7 *   encoding:   US-ASCII
8 *   tab size:   8 (not used)
9 *   indentation:4
10 *
11 *   created on: 2011jul04
12 *   created by: Markus W. Scherer
13 *
14 *   Common definitions for UHashTable and UVector.
15 *   UHashTok moved here from uhash.h and renamed UElement.
16 *   This allows users of UVector to avoid the confusing #include of uhash.h.
17 *   uhash.h aliases UElement to UHashTok,
18 *   so that we need not change all of its code and its users.
19 */
20 
21 #ifndef __UELEMENT_H__
22 #define __UELEMENT_H__
23 
24 #include "unicode/utypes.h"
25 
26 U_CDECL_BEGIN
27 
28 /**
29  * A UVector element, or a key or value within a UHashtable.
30  * It may be either a 32-bit integral value or an opaque void* pointer.
31  * The void* pointer may be smaller than 32 bits (e.g. 24 bits)
32  * or may be larger (e.g. 64 bits).
33  *
34  * Because a UElement is the size of a native pointer or a 32-bit
35  * integer, we pass it around by value.
36  */
37 union UElement {
38     void*   pointer;
39     int32_t integer;
40 };
41 typedef union UElement UElement;
42 
43 /**
44  * An element-equality (boolean) comparison function.
45  * @param e1 An element (object or integer)
46  * @param e2 An element (object or integer)
47  * @return TRUE if the two elements are equal.
48  */
49 typedef UBool U_CALLCONV UElementsAreEqual(const UElement e1, const UElement e2);
50 
51 /**
52  * An element sorting (three-way) comparison function.
53  * @param e1 An element (object or integer)
54  * @param e2 An element (object or integer)
55  * @return 0 if the two elements are equal, -1 if e1 is < e2, or +1 if e1 is > e2.
56  */
57 typedef int8_t U_CALLCONV UElementComparator(UElement e1, UElement e2);
58 
59 /**
60  * An element assignment function.  It may copy an integer, copy
61  * a pointer, or clone a pointer, as appropriate.
62  * @param dst The element to be assigned to
63  * @param src The element to assign from
64  */
65 typedef void U_CALLCONV UElementAssigner(UElement *dst, UElement *src);
66 
67 U_CDECL_END
68 
69 /**
70  * Comparator function for UnicodeString* keys. Implements UElementsAreEqual.
71  * @param key1 The string for comparison
72  * @param key2 The string for comparison
73  * @return true if key1 and key2 are equal, return false otherwise.
74  */
75 U_CAPI UBool U_EXPORT2
76 uhash_compareUnicodeString(const UElement key1, const UElement key2);
77 
78 /**
79  * Comparator function for UnicodeString* keys (case insensitive).
80  * Make sure to use together with uhash_hashCaselessUnicodeString.
81  * Implements UElementsAreEqual.
82  * @param key1 The string for comparison
83  * @param key2 The string for comparison
84  * @return true if key1 and key2 are equal, return false otherwise.
85  */
86 U_CAPI UBool U_EXPORT2
87 uhash_compareCaselessUnicodeString(const UElement key1, const UElement key2);
88 
89 #endif  /* __UELEMENT_H__ */
90