Back to index

php5  5.3.10
zend_ts_hash.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | Zend Engine                                                          |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 2.00 of the Zend license,     |
00008    | that is bundled with this package in the file LICENSE, and is        | 
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.zend.com/license/2_00.txt.                                |
00011    | If you did not receive a copy of the Zend license and are unable to  |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@zend.com so we can mail you a copy immediately.              |
00014    +----------------------------------------------------------------------+
00015    | Authors: Harald Radi <harald.radi@nme.at>                            |
00016    +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: zend_ts_hash.h 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifndef ZEND_TS_HASH_H
00022 #define ZEND_TS_HASH_H
00023 
00024 #include "zend.h"
00025 
00026 typedef struct _zend_ts_hashtable {
00027        HashTable hash;
00028        zend_uint reader;
00029 #ifdef ZTS
00030        MUTEX_T mx_reader;
00031        MUTEX_T mx_writer;
00032 #endif
00033 } TsHashTable;
00034 
00035 BEGIN_EXTERN_C()
00036 
00037 #define TS_HASH(table) (&(table->hash))
00038 
00039 /* startup/shutdown */
00040 ZEND_API int _zend_ts_hash_init(TsHashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC);
00041 ZEND_API int _zend_ts_hash_init_ex(TsHashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC);
00042 ZEND_API void zend_ts_hash_destroy(TsHashTable *ht);
00043 ZEND_API void zend_ts_hash_clean(TsHashTable *ht);
00044 
00045 #define zend_ts_hash_init(ht, nSize, pHashFunction, pDestructor, persistent) \
00046        _zend_ts_hash_init(ht, nSize, pHashFunction, pDestructor, persistent ZEND_FILE_LINE_CC)
00047 #define zend_ts_hash_init_ex(ht, nSize, pHashFunction, pDestructor, persistent, bApplyProtection) \
00048        _zend_ts_hash_init_ex(ht, nSize, pHashFunction, pDestructor, persistent, bApplyProtection ZEND_FILE_LINE_CC)
00049 
00050 
00051 /* additions/updates/changes */
00052 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);
00053 #define zend_ts_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest) \
00054               _zend_ts_hash_add_or_update(ht, arKey, nKeyLength, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC)
00055 #define zend_ts_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest) \
00056               _zend_ts_hash_add_or_update(ht, arKey, nKeyLength, pData, nDataSize, pDest, HASH_ADD ZEND_FILE_LINE_CC)
00057 
00058 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);
00059 #define zend_ts_hash_quick_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest) \
00060               _zend_ts_hash_quick_add_or_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC)
00061 #define zend_ts_hash_quick_add(ht, arKey, nKeyLength, h, pData, nDataSize, pDest) \
00062               _zend_ts_hash_quick_add_or_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest, HASH_ADD ZEND_FILE_LINE_CC)
00063 
00064 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);
00065 #define zend_ts_hash_index_update(ht, h, pData, nDataSize, pDest) \
00066               _zend_ts_hash_index_update_or_next_insert(ht, h, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC)
00067 #define zend_ts_hash_next_index_insert(ht, pData, nDataSize, pDest) \
00068               _zend_ts_hash_index_update_or_next_insert(ht, 0, pData, nDataSize, pDest, HASH_NEXT_INSERT ZEND_FILE_LINE_CC)
00069 
00070 ZEND_API int zend_ts_hash_add_empty_element(TsHashTable *ht, char *arKey, uint nKeyLength);
00071 
00072 ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht);
00073 ZEND_API void zend_ts_hash_apply(TsHashTable *ht, apply_func_t apply_func TSRMLS_DC);
00074 ZEND_API void zend_ts_hash_apply_with_argument(TsHashTable *ht, apply_func_arg_t apply_func, void * TSRMLS_DC);
00075 ZEND_API void zend_ts_hash_apply_with_arguments(TsHashTable *ht TSRMLS_DC, apply_func_args_t apply_func, int, ...);
00076 
00077 ZEND_API void zend_ts_hash_reverse_apply(TsHashTable *ht, apply_func_t apply_func TSRMLS_DC);
00078 
00079 
00080 /* Deletes */
00081 ZEND_API int zend_ts_hash_del_key_or_index(TsHashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag);
00082 #define zend_ts_hash_del(ht, arKey, nKeyLength) \
00083               zend_ts_hash_del_key_or_index(ht, arKey, nKeyLength, 0, HASH_DEL_KEY)
00084 #define zend_ts_hash_index_del(ht, h) \
00085               zend_ts_hash_del_key_or_index(ht, NULL, 0, h, HASH_DEL_INDEX)
00086 
00087 ZEND_API ulong zend_ts_get_hash_value(TsHashTable *ht, char *arKey, uint nKeyLength);
00088 
00089 /* Data retreival */
00090 ZEND_API int zend_ts_hash_find(TsHashTable *ht, char *arKey, uint nKeyLength, void **pData);
00091 ZEND_API int zend_ts_hash_quick_find(TsHashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData);
00092 ZEND_API int zend_ts_hash_index_find(TsHashTable *ht, ulong h, void **pData);
00093 
00094 /* Misc */
00095 ZEND_API int zend_ts_hash_exists(TsHashTable *ht, char *arKey, uint nKeyLength);
00096 ZEND_API int zend_ts_hash_index_exists(TsHashTable *ht, ulong h);
00097 
00098 /* Copying, merging and sorting */
00099 ZEND_API void zend_ts_hash_copy(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);
00100 ZEND_API void zend_ts_hash_copy_to_hash(HashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);
00101 ZEND_API void zend_ts_hash_merge(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite);
00102 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);
00103 ZEND_API int zend_ts_hash_sort(TsHashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber TSRMLS_DC);
00104 ZEND_API int zend_ts_hash_compare(TsHashTable *ht1, TsHashTable *ht2, compare_func_t compar, zend_bool ordered TSRMLS_DC);
00105 ZEND_API int zend_ts_hash_minmax(TsHashTable *ht, compare_func_t compar, int flag, void **pData TSRMLS_DC);
00106 
00107 ZEND_API int zend_ts_hash_num_elements(TsHashTable *ht);
00108 
00109 ZEND_API int zend_ts_hash_rehash(TsHashTable *ht);
00110 
00111 ZEND_API ulong zend_ts_hash_func(char *arKey, uint nKeyLength);
00112 
00113 #if ZEND_DEBUG
00114 /* debug */
00115 void zend_ts_hash_display_pListTail(TsHashTable *ht);
00116 void zend_ts_hash_display(TsHashTable *ht);
00117 #endif
00118 
00119 END_EXTERN_C()
00120 
00121 #define ZEND_TS_INIT_SYMTABLE(ht)                                                   \
00122        ZEND_TS_INIT_SYMTABLE_EX(ht, 2, 0)
00123 
00124 #define ZEND_TS_INIT_SYMTABLE_EX(ht, n, persistent)                   \
00125        zend_ts_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
00126 
00127 #endif                                           /* ZEND_HASH_H */
00128 
00129 /*
00130  * Local variables:
00131  * tab-width: 4
00132  * c-basic-offset: 4
00133  * indent-tabs-mode: t
00134  * End:
00135  */