uelement.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 32-bit signed integer comparison result:
  52. * ==0 if the two elements are equal,
  53. * <0 if e1 is < e2, or
  54. * >0 if e1 is > e2.
  55. */
  56. typedef int32_t U_CALLCONV UElementComparator(UElement e1, UElement e2);
  57. /**
  58. * An element assignment function. It may copy an integer, copy
  59. * a pointer, or clone a pointer, as appropriate.
  60. * @param dst The element to be assigned to
  61. * @param src The element to assign from
  62. */
  63. typedef void U_CALLCONV UElementAssigner(UElement *dst, UElement *src);
  64. U_CDECL_END
  65. /**
  66. * Comparator function for UnicodeString* keys. Implements UElementsAreEqual.
  67. * @param key1 The string for comparison
  68. * @param key2 The string for comparison
  69. * @return true if key1 and key2 are equal, return false otherwise.
  70. */
  71. U_CAPI UBool U_EXPORT2
  72. uhash_compareUnicodeString(const UElement key1, const UElement key2);
  73. /**
  74. * Comparator function for UnicodeString* keys (case insensitive).
  75. * Make sure to use together with uhash_hashCaselessUnicodeString.
  76. * Implements UElementsAreEqual.
  77. * @param key1 The string for comparison
  78. * @param key2 The string for comparison
  79. * @return true if key1 and key2 are equal, return false otherwise.
  80. */
  81. U_CAPI UBool U_EXPORT2
  82. uhash_compareCaselessUnicodeString(const UElement key1, const UElement key2);
  83. #endif /* __UELEMENT_H__ */