zend_ts_hash.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2016 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Harald Radi <harald.radi@nme.at> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifndef ZEND_TS_HASH_H
  20. #define ZEND_TS_HASH_H
  21. #include "zend.h"
  22. typedef struct _zend_ts_hashtable {
  23. HashTable hash;
  24. zend_uint reader;
  25. #ifdef ZTS
  26. MUTEX_T mx_reader;
  27. MUTEX_T mx_writer;
  28. #endif
  29. } TsHashTable;
  30. BEGIN_EXTERN_C()
  31. #define TS_HASH(table) (&(table->hash))
  32. /* startup/shutdown */
  33. ZEND_API int _zend_ts_hash_init(TsHashTable *ht, uint nSize, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC);
  34. ZEND_API int _zend_ts_hash_init_ex(TsHashTable *ht, uint nSize, dtor_func_t pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC);
  35. ZEND_API void zend_ts_hash_destroy(TsHashTable *ht);
  36. ZEND_API void zend_ts_hash_clean(TsHashTable *ht);
  37. #define zend_ts_hash_init(ht, nSize, pHashFunction, pDestructor, persistent) \
  38. _zend_ts_hash_init(ht, nSize, pDestructor, persistent ZEND_FILE_LINE_CC)
  39. #define zend_ts_hash_init_ex(ht, nSize, pHashFunction, pDestructor, persistent, bApplyProtection) \
  40. _zend_ts_hash_init_ex(ht, nSize, pDestructor, persistent, bApplyProtection ZEND_FILE_LINE_CC)
  41. /* additions/updates/changes */
  42. ZEND_API int _zend_ts_hash_add_or_update(TsHashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC);
  43. #define zend_ts_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest) \
  44. _zend_ts_hash_add_or_update(ht, arKey, nKeyLength, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC)
  45. #define zend_ts_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest) \
  46. _zend_ts_hash_add_or_update(ht, arKey, nKeyLength, pData, nDataSize, pDest, HASH_ADD ZEND_FILE_LINE_CC)
  47. ZEND_API int _zend_ts_hash_quick_add_or_update(TsHashTable *ht, char *arKey, uint nKeyLength, ulong h, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC);
  48. #define zend_ts_hash_quick_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest) \
  49. _zend_ts_hash_quick_add_or_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC)
  50. #define zend_ts_hash_quick_add(ht, arKey, nKeyLength, h, pData, nDataSize, pDest) \
  51. _zend_ts_hash_quick_add_or_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest, HASH_ADD ZEND_FILE_LINE_CC)
  52. ZEND_API int _zend_ts_hash_index_update_or_next_insert(TsHashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC);
  53. #define zend_ts_hash_index_update(ht, h, pData, nDataSize, pDest) \
  54. _zend_ts_hash_index_update_or_next_insert(ht, h, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC)
  55. #define zend_ts_hash_next_index_insert(ht, pData, nDataSize, pDest) \
  56. _zend_ts_hash_index_update_or_next_insert(ht, 0, pData, nDataSize, pDest, HASH_NEXT_INSERT ZEND_FILE_LINE_CC)
  57. ZEND_API int zend_ts_hash_add_empty_element(TsHashTable *ht, char *arKey, uint nKeyLength);
  58. ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht);
  59. ZEND_API void zend_ts_hash_apply(TsHashTable *ht, apply_func_t apply_func TSRMLS_DC);
  60. ZEND_API void zend_ts_hash_apply_with_argument(TsHashTable *ht, apply_func_arg_t apply_func, void * TSRMLS_DC);
  61. ZEND_API void zend_ts_hash_apply_with_arguments(TsHashTable *ht TSRMLS_DC, apply_func_args_t apply_func, int, ...);
  62. ZEND_API void zend_ts_hash_reverse_apply(TsHashTable *ht, apply_func_t apply_func TSRMLS_DC);
  63. /* Deletes */
  64. ZEND_API int zend_ts_hash_del_key_or_index(TsHashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag);
  65. #define zend_ts_hash_del(ht, arKey, nKeyLength) \
  66. zend_ts_hash_del_key_or_index(ht, arKey, nKeyLength, 0, HASH_DEL_KEY)
  67. #define zend_ts_hash_index_del(ht, h) \
  68. zend_ts_hash_del_key_or_index(ht, NULL, 0, h, HASH_DEL_INDEX)
  69. ZEND_API ulong zend_ts_get_hash_value(TsHashTable *ht, char *arKey, uint nKeyLength);
  70. /* Data retreival */
  71. ZEND_API int zend_ts_hash_find(TsHashTable *ht, char *arKey, uint nKeyLength, void **pData);
  72. ZEND_API int zend_ts_hash_quick_find(TsHashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData);
  73. ZEND_API int zend_ts_hash_index_find(TsHashTable *ht, ulong h, void **pData);
  74. /* Misc */
  75. ZEND_API int zend_ts_hash_exists(TsHashTable *ht, char *arKey, uint nKeyLength);
  76. ZEND_API int zend_ts_hash_index_exists(TsHashTable *ht, ulong h);
  77. /* Copying, merging and sorting */
  78. ZEND_API void zend_ts_hash_copy(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);
  79. ZEND_API void zend_ts_hash_copy_to_hash(HashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);
  80. ZEND_API void zend_ts_hash_merge(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite);
  81. ZEND_API void zend_ts_hash_merge_ex(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, uint size, merge_checker_func_t pMergeSource, void *pParam);
  82. ZEND_API int zend_ts_hash_sort(TsHashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber TSRMLS_DC);
  83. ZEND_API int zend_ts_hash_compare(TsHashTable *ht1, TsHashTable *ht2, compare_func_t compar, zend_bool ordered TSRMLS_DC);
  84. ZEND_API int zend_ts_hash_minmax(TsHashTable *ht, compare_func_t compar, int flag, void **pData TSRMLS_DC);
  85. ZEND_API int zend_ts_hash_num_elements(TsHashTable *ht);
  86. ZEND_API int zend_ts_hash_rehash(TsHashTable *ht);
  87. ZEND_API ulong zend_ts_hash_func(char *arKey, uint nKeyLength);
  88. #if ZEND_DEBUG
  89. /* debug */
  90. void zend_ts_hash_display_pListTail(TsHashTable *ht);
  91. void zend_ts_hash_display(TsHashTable *ht);
  92. #endif
  93. END_EXTERN_C()
  94. #define ZEND_TS_INIT_SYMTABLE(ht) \
  95. ZEND_TS_INIT_SYMTABLE_EX(ht, 2, 0)
  96. #define ZEND_TS_INIT_SYMTABLE_EX(ht, n, persistent) \
  97. zend_ts_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
  98. #endif /* ZEND_HASH_H */
  99. /*
  100. * Local variables:
  101. * tab-width: 4
  102. * c-basic-offset: 4
  103. * indent-tabs-mode: t
  104. * End:
  105. */