00001 #ifndef _CP_MULTIMAP_H
00002 #define _CP_MULTIMAP_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 #include "common.h"
00112
00113 __BEGIN_DECLS
00114
00115 #include "rb.h"
00116 #include "hashlist.h"
00117 #include "vector.h"
00118 #include "mempool.h"
00119
00120 struct _cp_multimap;
00121
00122 #define MM_RED 0
00123 #define MM_BLACK 1
00124
00125 typedef CPROPS_DLL struct _cp_index_map_node
00126 {
00127 void *entry;
00128
00129
00130 int color;
00131
00132 struct _cp_index_map_node *left;
00133 struct _cp_index_map_node *right;
00134 struct _cp_index_map_node *up;
00135 } cp_index_map_node;
00136
00137
00138 CPROPS_DLL
00139 cp_index_map_node *
00140 cp_index_map_node_create(void *entry, struct _cp_mempool *pool);
00141
00142 CPROPS_DLL
00143 void cp_multimap_destroy_node(struct _cp_multimap *owner,
00144 cp_index_map_node *node);
00145
00146 CPROPS_DLL
00147 void cp_multimap_destroy_node_deep(struct _cp_multimap *owner,
00148 cp_index_map_node *node);
00149
00150 struct _cp_multimap;
00151
00152 typedef CPROPS_DLL struct _cp_index_map
00153 {
00154 struct _cp_multimap *owner;
00155
00156 cp_index_map_node *root;
00157
00158 int mode;
00159 cp_index *index;
00160 } cp_index_map;
00161
00162 cp_index_map *
00163 cp_index_map_create(struct _cp_multimap *owner, int mode, cp_index *index);
00164
00165
00166 CPROPS_DLL
00167 int cp_index_map_reindex(cp_index_map *tree, void *before, void *after);
00168
00169
00170
00171 typedef CPROPS_DLL struct _cp_multimap
00172 {
00173 int mode;
00174
00175 int items;
00176
00177 cp_copy_fn copy;
00178 cp_destructor_fn dtr;
00179
00180 cp_index default_index;
00181 cp_index_map *default_map;
00182
00183 cp_index_map *primary;
00184
00185
00186 cp_hashlist *index;
00187
00188 cp_lock *lock;
00189 cp_thread txowner;
00190 int txtype;
00191
00192 cp_mempool *mempool;
00193 } cp_multimap;
00194
00195
00196
00197
00198
00199 CPROPS_DLL
00200 cp_multimap *cp_multimap_create(cp_key_fn key_fn, cp_compare_fn cmp);
00201
00202
00203
00204
00205
00206
00207 CPROPS_DLL
00208 cp_multimap *
00209 cp_multimap_create_by_option(int mode, cp_key_fn key_fn,
00210 cp_compare_fn cmp,
00211 cp_copy_fn copy,
00212 cp_destructor_fn dtr);
00213
00214
00215
00216
00217 CPROPS_DLL
00218 void cp_multimap_destroy(cp_multimap *tree);
00219
00220
00221
00222 CPROPS_DLL
00223 void cp_multimap_destroy_custom(cp_multimap *tree, cp_destructor_fn dtr);
00224
00225
00226
00227
00228
00229
00230
00231 CPROPS_DLL
00232 int cp_multimap_get_unique(cp_multimap *tree,
00233 void *entry,
00234 cp_index **index,
00235 void **existing);
00236
00237
00238 CPROPS_DLL
00239 void *cp_multimap_insert(cp_multimap *tree, void *entry, int *err);
00240
00241
00242 CPROPS_DLL
00243 void *cp_multimap_get(cp_multimap *tree, void *entry);
00244
00245
00246 CPROPS_DLL
00247 void *cp_multimap_get_by_index(cp_multimap *map, cp_index *index, void *entry);
00248
00249
00250 CPROPS_DLL
00251 void *cp_multimap_find(cp_multimap *map, void *key, cp_op op);
00252
00253
00254 CPROPS_DLL
00255 void *cp_multimap_find_by_index(cp_multimap *map,
00256 cp_index *index,
00257 void *entry,
00258 cp_op op);
00259
00260
00261 CPROPS_DLL
00262 int cp_multimap_contains(cp_multimap *tree, void *entry);
00263
00264
00265 CPROPS_DLL
00266 void *cp_multimap_remove(cp_multimap *tree, void *entry);
00267
00268
00269 CPROPS_DLL
00270 void *cp_multimap_remove_by_index(cp_multimap *map,
00271 cp_index *index,
00272 void *entry);
00273
00274
00275 CPROPS_DLL
00276 int cp_multimap_reindex(cp_multimap *map, void *before, void *after);
00277
00278
00279
00280
00281
00282 CPROPS_DLL
00283 int cp_multimap_callback_preorder(cp_multimap *tree,
00284 cp_callback_fn callback,
00285 void *prm);
00286
00287
00288
00289
00290 CPROPS_DLL
00291 int cp_multimap_callback(cp_multimap *tree, cp_callback_fn callback, void *prm);
00292
00293
00294
00295
00296 CPROPS_DLL
00297 int cp_multimap_callback_by_index(cp_multimap *tree,
00298 cp_index *index,
00299 cp_callback_fn callback,
00300 void *prm);
00301
00302
00303
00304
00305
00306 CPROPS_DLL
00307 int cp_multimap_callback_postorder(cp_multimap *tree,
00308 cp_callback_fn callback,
00309 void *prm);
00310
00311
00312 CPROPS_DLL
00313 int cp_multimap_count(cp_multimap *tree);
00314
00315 #define cp_multimap_size cp_multimap_count
00316
00317
00318
00319
00320 CPROPS_DLL
00321 int cp_multimap_lock(cp_multimap *tree, int type);
00322
00323 #define cp_multimap_rdlock(tree) (cp_multimap_lock((tree), COLLECTION_LOCK_READ))
00324
00325 #define cp_multimap_wrlock(tree) (cp_multimap_lock((tree), COLLECTION_LOCK_WRITE))
00326
00327 CPROPS_DLL
00328 int cp_multimap_unlock(cp_multimap *tree);
00329
00330
00331
00332 CPROPS_DLL
00333 int cp_multimap_get_mode(cp_multimap *tree);
00334
00335 CPROPS_DLL
00336 int cp_multimap_set_mode(cp_multimap *tree, int mode);
00337
00338
00339
00340
00341 CPROPS_DLL
00342 int cp_multimap_unset_mode(cp_multimap *tree, int mode);
00343
00344
00345
00346 CPROPS_DLL
00347 void cp_multimap_dump(cp_multimap *tree);
00348
00349
00350 CPROPS_DLL
00351 int cp_multimap_use_mempool(cp_multimap *tree, cp_mempool *pool);
00352
00353
00354 CPROPS_DLL
00355 int cp_multimap_share_mempool(cp_multimap *tree,
00356 struct _cp_shared_mempool *pool);
00357
00358
00359 CPROPS_DLL
00360 cp_index *cp_multimap_create_index(cp_multimap *map,
00361 cp_index_type type,
00362 cp_key_fn key,
00363 cp_compare_fn cmp,
00364 int *err);
00365
00366 __END_DECLS
00367
00368
00369
00370 #endif
00371