zend_ts_hash.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2018 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. #ifndef ZEND_TS_HASH_H
  19. #define ZEND_TS_HASH_H
  20. #include "zend.h"
  21. typedef struct _zend_ts_hashtable {
  22. HashTable hash;
  23. uint32_t reader;
  24. #ifdef ZTS
  25. MUTEX_T mx_reader;
  26. MUTEX_T mx_writer;
  27. #endif
  28. } TsHashTable;
  29. BEGIN_EXTERN_C()
  30. #define TS_HASH(table) (&(table->hash))
  31. /* startup/shutdown */
  32. ZEND_API void _zend_ts_hash_init(TsHashTable *ht, uint32_t nSize, dtor_func_t pDestructor, zend_bool persistent);
  33. ZEND_API void zend_ts_hash_destroy(TsHashTable *ht);
  34. ZEND_API void zend_ts_hash_clean(TsHashTable *ht);
  35. #define zend_ts_hash_init(ht, nSize, pHashFunction, pDestructor, persistent) \
  36. _zend_ts_hash_init(ht, nSize, pDestructor, persistent)
  37. #define zend_ts_hash_init_ex(ht, nSize, pHashFunction, pDestructor, persistent, bApplyProtection) \
  38. _zend_ts_hash_init(ht, nSize, pDestructor, persistent)
  39. /* additions/updates/changes */
  40. ZEND_API zval *zend_ts_hash_update(TsHashTable *ht, zend_string *key, zval *pData);
  41. ZEND_API zval *zend_ts_hash_add(TsHashTable *ht, zend_string *key, zval *pData);
  42. ZEND_API zval *zend_ts_hash_index_update(TsHashTable *ht, zend_ulong h, zval *pData);
  43. ZEND_API zval *zend_ts_hash_next_index_insert(TsHashTable *ht, zval *pData);
  44. ZEND_API zval* zend_ts_hash_add_empty_element(TsHashTable *ht, zend_string *key);
  45. ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht);
  46. ZEND_API void zend_ts_hash_apply(TsHashTable *ht, apply_func_t apply_func);
  47. ZEND_API void zend_ts_hash_apply_with_argument(TsHashTable *ht, apply_func_arg_t apply_func, void *);
  48. ZEND_API void zend_ts_hash_apply_with_arguments(TsHashTable *ht, apply_func_args_t apply_func, int, ...);
  49. ZEND_API void zend_ts_hash_reverse_apply(TsHashTable *ht, apply_func_t apply_func);
  50. /* Deletes */
  51. ZEND_API int zend_ts_hash_del(TsHashTable *ht, zend_string *key);
  52. ZEND_API int zend_ts_hash_index_del(TsHashTable *ht, zend_ulong h);
  53. /* Data retreival */
  54. ZEND_API zval *zend_ts_hash_find(TsHashTable *ht, zend_string *key);
  55. ZEND_API zval *zend_ts_hash_index_find(TsHashTable *ht, zend_ulong);
  56. /* Misc */
  57. ZEND_API int zend_ts_hash_exists(TsHashTable *ht, zend_string *key);
  58. ZEND_API int zend_ts_hash_index_exists(TsHashTable *ht, zend_ulong h);
  59. /* Copying, merging and sorting */
  60. ZEND_API void zend_ts_hash_copy(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor);
  61. ZEND_API void zend_ts_hash_copy_to_hash(HashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor);
  62. ZEND_API void zend_ts_hash_merge(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, int overwrite);
  63. ZEND_API void zend_ts_hash_merge_ex(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam);
  64. ZEND_API int zend_ts_hash_sort(TsHashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber);
  65. ZEND_API int zend_ts_hash_compare(TsHashTable *ht1, TsHashTable *ht2, compare_func_t compar, zend_bool ordered);
  66. ZEND_API zval *zend_ts_hash_minmax(TsHashTable *ht, compare_func_t compar, int flag);
  67. ZEND_API int zend_ts_hash_num_elements(TsHashTable *ht);
  68. ZEND_API int zend_ts_hash_rehash(TsHashTable *ht);
  69. #if ZEND_DEBUG
  70. /* debug */
  71. void zend_ts_hash_display_pListTail(TsHashTable *ht);
  72. void zend_ts_hash_display(TsHashTable *ht);
  73. #endif
  74. ZEND_API zval *zend_ts_hash_str_find(TsHashTable *ht, const char *key, size_t len);
  75. ZEND_API zval *zend_ts_hash_str_update(TsHashTable *ht, const char *key, size_t len, zval *pData);
  76. ZEND_API zval *zend_ts_hash_str_add(TsHashTable *ht, const char *key, size_t len, zval *pData);
  77. static zend_always_inline void *zend_ts_hash_str_find_ptr(TsHashTable *ht, const char *str, size_t len)
  78. {
  79. zval *zv;
  80. zv = zend_ts_hash_str_find(ht, str, len);
  81. return zv ? Z_PTR_P(zv) : NULL;
  82. }
  83. static zend_always_inline void *zend_ts_hash_str_update_ptr(TsHashTable *ht, const char *str, size_t len, void *pData)
  84. {
  85. zval tmp, *zv;
  86. ZVAL_PTR(&tmp, pData);
  87. zv = zend_ts_hash_str_update(ht, str, len, &tmp);
  88. return zv ? Z_PTR_P(zv) : NULL;
  89. }
  90. static zend_always_inline void *zend_ts_hash_str_add_ptr(TsHashTable *ht, const char *str, size_t len, void *pData)
  91. {
  92. zval tmp, *zv;
  93. ZVAL_PTR(&tmp, pData);
  94. zv = zend_ts_hash_str_add(ht, str, len, &tmp);
  95. return zv ? Z_PTR_P(zv) : NULL;
  96. }
  97. END_EXTERN_C()
  98. #define ZEND_TS_INIT_SYMTABLE(ht) \
  99. ZEND_TS_INIT_SYMTABLE_EX(ht, 2, 0)
  100. #define ZEND_TS_INIT_SYMTABLE_EX(ht, n, persistent) \
  101. zend_ts_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
  102. #endif /* ZEND_HASH_H */
  103. /*
  104. * Local variables:
  105. * tab-width: 4
  106. * c-basic-offset: 4
  107. * indent-tabs-mode: t
  108. * End:
  109. * vim600: sw=4 ts=4 fdm=marker
  110. * vim<600: sw=4 ts=4
  111. */