uelement.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #ifndef __UELEMENT_H__
  23. #define __UELEMENT_H__
  24. #include "unicode/utypes.h"
  25. U_CDECL_BEGIN
  26. /**
  27. * A UVector element, or a key or value within a UHashtable.
  28. * It may be either a 32-bit integral value or an opaque void* pointer.
  29. * The void* pointer may be smaller than 32 bits (e.g. 24 bits)
  30. * or may be larger (e.g. 64 bits).
  31. *
  32. * Because a UElement is the size of a native pointer or a 32-bit
  33. * integer, we pass it around by value.
  34. */
  35. union UElement {
  36. void* pointer;
  37. int32_t integer;
  38. };
  39. typedef union UElement UElement;
  40. /**
  41. * An element-equality (boolean) comparison function.
  42. * @param e1 An element (object or integer)
  43. * @param e2 An element (object or integer)
  44. * @return TRUE if the two elements are equal.
  45. */
  46. typedef UBool U_CALLCONV UElementsAreEqual(const UElement e1, const UElement e2);
  47. /**
  48. * An element sorting (three-way) comparison function.
  49. * @param e1 An element (object or integer)
  50. * @param e2 An element (object or integer)
  51. * @return 0 if the two elements are equal, -1 if e1 is < e2, or +1 if e1 is > e2.
  52. */
  53. typedef int8_t U_CALLCONV UElementComparator(UElement e1, UElement e2);
  54. /**
  55. * An element assignment function. It may copy an integer, copy
  56. * a pointer, or clone a pointer, as appropriate.
  57. * @param dst The element to be assigned to
  58. * @param src The element to assign from
  59. */
  60. typedef void U_CALLCONV UElementAssigner(UElement *dst, UElement *src);
  61. U_CDECL_END
  62. /**
  63. * Comparator function for UnicodeString* keys. Implements UElementsAreEqual.
  64. * @param key1 The string for comparison
  65. * @param key2 The string for comparison
  66. * @return true if key1 and key2 are equal, return false otherwise.
  67. */
  68. U_CAPI UBool U_EXPORT2
  69. uhash_compareUnicodeString(const UElement key1, const UElement key2);
  70. /**
  71. * Comparator function for UnicodeString* keys (case insensitive).
  72. * Make sure to use together with uhash_hashCaselessUnicodeString.
  73. * Implements UElementsAreEqual.
  74. * @param key1 The string for comparison
  75. * @param key2 The string for comparison
  76. * @return true if key1 and key2 are equal, return false otherwise.
  77. */
  78. U_CAPI UBool U_EXPORT2
  79. uhash_compareCaselessUnicodeString(const UElement key1, const UElement key2);
  80. #endif /* __UELEMENT_H__ */