00001 #ifndef _SORTED_HASH_H
00002 #define _SORTED_HASH_H
00003
00017 #include "common.h"
00018
00019 __BEGIN_DECLS
00020
00021 #include "collection.h"
00022 #include "vector.h"
00023 #include "mempool.h"
00024
00025 struct _cp_sorted_hash;
00026
00027 #define SH_RED 0
00028 #define SH_BLACK 1
00029
00030 typedef CPROPS_DLL struct _cp_sh_entry
00031 {
00032 void *key;
00033 void *value;
00034
00035 unsigned long code;
00036
00037
00038 int color;
00039
00040 struct _cp_sh_entry *bucket;
00041 struct _cp_sh_entry *multiple;
00042 struct _cp_sh_entry *multiple_prev;
00043
00044 struct _cp_sh_entry *left;
00045 struct _cp_sh_entry *right;
00046 struct _cp_sh_entry *up;
00047 } cp_sh_entry;
00048
00049
00050 CPROPS_DLL
00051 cp_sh_entry *cp_sh_entry_create(void *key, void *value, cp_mempool *pool);
00052
00053 CPROPS_DLL
00054 void cp_sorted_hash_destroy_entry(struct _cp_sorted_hash *owner,
00055 cp_sh_entry *entry);
00056
00057 CPROPS_DLL
00058 void cp_sorted_hash_destroy_entry_deep(struct _cp_sorted_hash *owner,
00059 cp_sh_entry *entry);
00060
00061
00062 typedef CPROPS_DLL struct _cp_sorted_hash
00063 {
00064 cp_sh_entry *root;
00065 cp_sh_entry **table;
00066 int size;
00067
00068 int items;
00069
00070 int mode;
00071 cp_hashfunction hash;
00072 cp_compare_fn cmp_key;
00073 cp_mapping_cmp_fn cmp_mapping;
00074 cp_copy_fn key_copy;
00075 cp_destructor_fn key_dtr;
00076 cp_copy_fn value_copy;
00077 cp_destructor_fn value_dtr;
00078
00079 cp_lock *lock;
00080 cp_thread txowner;
00081 int txtype;
00082
00083 cp_mempool *mempool;
00084 } cp_sorted_hash;
00085
00086
00087
00088
00089
00090 CPROPS_DLL
00091 cp_sorted_hash *cp_sorted_hash_create(cp_hashfunction hash,
00092 cp_compare_fn cmp_key,
00093 cp_mapping_cmp_fn cmp_mapping);
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 CPROPS_DLL
00104 cp_sorted_hash *
00105 cp_sorted_hash_create_by_option(int mode,
00106 unsigned long size_hint,
00107 cp_hashfunction hash,
00108 cp_compare_fn cmp_key,
00109 cp_mapping_cmp_fn cmp_mapping,
00110 cp_copy_fn key_copy,
00111 cp_destructor_fn key_dtr,
00112 cp_copy_fn val_copy,
00113 cp_destructor_fn val_dtr);
00114
00115
00116
00117
00118 CPROPS_DLL
00119 void cp_sorted_hash_destroy(cp_sorted_hash *tree);
00120
00121
00122
00123 CPROPS_DLL
00124 void cp_sorted_hash_destroy_custom(cp_sorted_hash *tree,
00125 cp_destructor_fn key_dtr,
00126 cp_destructor_fn val_dtr);
00127
00128
00129 CPROPS_DLL
00130 void *cp_sorted_hash_insert(cp_sorted_hash *tree, void *key, void *value);
00131
00132
00133 CPROPS_DLL
00134 void *cp_sorted_hash_get(cp_sorted_hash *tree, void *key);
00135
00136
00137 CPROPS_DLL
00138 void *cp_sorted_hash_find(cp_sorted_hash *tree, cp_mapping *mapping, cp_op op);
00139
00140
00141 CPROPS_DLL
00142 int cp_sorted_hash_contains(cp_sorted_hash *tree, void *key);
00143
00144
00145 CPROPS_DLL
00146 void *cp_sorted_hash_delete(cp_sorted_hash *tree, void *key);
00147
00148
00149
00150
00151
00152 CPROPS_DLL
00153 int cp_sorted_hash_callback_preorder(cp_sorted_hash *tree,
00154 cp_callback_fn callback,
00155 void *prm);
00156
00157
00158
00159
00160 CPROPS_DLL
00161 int cp_sorted_hash_callback(cp_sorted_hash *tree,
00162 cp_callback_fn callback,
00163 void *prm);
00164
00165
00166
00167
00168
00169 CPROPS_DLL
00170 int cp_sorted_hash_callback_postorder(cp_sorted_hash *tree,
00171 cp_callback_fn callback,
00172 void *prm);
00173
00174
00175 CPROPS_DLL
00176 int cp_sorted_hash_count(cp_sorted_hash *tree);
00177
00178
00179
00180
00181 CPROPS_DLL
00182 int cp_sorted_hash_lock(cp_sorted_hash *tree, int type);
00183
00184 #define cp_sorted_hash_rdlock(tree) (cp_sorted_hash_lock((tree), COLLECTION_LOCK_READ))
00185
00186 #define cp_sorted_hash_wrlock(tree) (cp_sorted_hash_lock((tree), COLLECTION_LOCK_WRITE))
00187
00188 CPROPS_DLL
00189 int cp_sorted_hash_unlock(cp_sorted_hash *tree);
00190
00191
00192
00193 CPROPS_DLL
00194 int cp_sorted_hash_get_mode(cp_sorted_hash *tree);
00195
00196 CPROPS_DLL
00197 int cp_sorted_hash_set_mode(cp_sorted_hash *tree, int mode);
00198
00199
00200
00201
00202 CPROPS_DLL
00203 int cp_sorted_hash_unset_mode(cp_sorted_hash *tree, int mode);
00204
00205
00207 CPROPS_DLL
00208 void cp_sorted_hash_dump(cp_sorted_hash *tree);
00209
00210 __END_DECLS
00211
00214 #endif
00215