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