multimap.h

Go to the documentation of this file.
00001 #ifndef _CP_MULTIMAP_H
00002 #define _CP_MULTIMAP_H
00003 
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     /* balance maintainance - color is either 'red' or 'black' */
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 /* (internal) allocate a new node */
00138 CPROPS_DLL
00139 cp_index_map_node *
00140     cp_index_map_node_create(void *entry, struct _cp_mempool *pool);
00141 /* (internal) deallocate a node */
00142 CPROPS_DLL
00143 void cp_multimap_destroy_node(struct _cp_multimap *owner, 
00144                               cp_index_map_node *node);
00145 /* (internal) deallocate a node and its subnodes */
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;  /* owning multimap */
00155 
00156     cp_index_map_node *root;     /* root node */
00157 
00158     int mode;                    /* mode flags */
00159     cp_index *index;             /* index information */
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 /* (internal) reposition an entry */
00166 CPROPS_DLL
00167 int cp_index_map_reindex(cp_index_map *tree, void *before, void *after);
00168 
00169 
00170 /* tree wrapper object */
00171 typedef CPROPS_DLL struct _cp_multimap
00172 {
00173     int mode;                     /* mode flags */
00174 
00175     int items;                    /* item count */
00176     
00177     cp_copy_fn copy;              /* entry copy function */
00178     cp_destructor_fn dtr;         /* entry destructor */
00179 
00180     cp_index default_index;       /* default index */
00181     cp_index_map *default_map;    /* default map */
00182 
00183     cp_index_map *primary;        /* primary unique index - identical to 
00184                                    * default if default is unique */
00185 
00186     cp_hashlist *index;           /* index table */
00187 
00188     cp_lock *lock;
00189     cp_thread txowner;            /* set if a transaction is in progress */
00190     int txtype;                   /* lock type */
00191 
00192     cp_mempool *mempool;          /* optional memory pool */
00193 } cp_multimap;
00194 
00195 /* 
00196  * default create function - equivalent to create_by_option with mode 
00197  * COLLECTION_MODE_NOSYNC
00198  */
00199 CPROPS_DLL
00200 cp_multimap *cp_multimap_create(cp_key_fn key_fn, cp_compare_fn cmp);
00201 
00202 /*
00203  * create function for multiple value trees, allows specifying mapping 
00204  * comparison function to delete individual mappings. The mode parameter
00205  * is logically or'ed with COLLECTION_MODE_MULTIPLE_VALUES.
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  * recursively destroy the tree structure 
00216  */
00217 CPROPS_DLL
00218 void cp_multimap_destroy(cp_multimap *tree);
00219 /*
00220  * recursively destroy the tree structure with the given destructor functions
00221  */
00222 CPROPS_DLL
00223 void cp_multimap_destroy_custom(cp_multimap *tree, cp_destructor_fn dtr);
00224 
00225 /*
00226  * check whether this entry is already present on any unique index. returns
00227  * non-zero if an matching entry on a non-unique index was found. If index
00228  * parameter is non-null, it is set to the first index an entry was found on. 
00229  * If existing parameter is non-null, it is set to the first entry found.
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 /* insertion function */
00238 CPROPS_DLL
00239 void *cp_multimap_insert(cp_multimap *tree, void *entry, int *err);
00240 
00241 /* retrieve the entry described by the given key */
00242 CPROPS_DLL
00243 void *cp_multimap_get(cp_multimap *tree, void *entry);
00244 
00245 /* retrieve the entry described by the given key using the given index */
00246 CPROPS_DLL
00247 void *cp_multimap_get_by_index(cp_multimap *map, cp_index *index, void *entry);
00248 
00249 /* find the value of the closest key by operator */
00250 CPROPS_DLL
00251 void *cp_multimap_find(cp_multimap *map, void *key, cp_op op);
00252 
00253 /* find the value of the closest key by operator and by the given index */
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 /* return non-zero if entry could be found on any index */
00261 CPROPS_DLL
00262 int cp_multimap_contains(cp_multimap *tree, void *entry);
00263 
00264 /* remove a mapping */
00265 CPROPS_DLL
00266 void *cp_multimap_remove(cp_multimap *tree, void *entry);
00267 
00268 /* delete mapping(s) matching given entry by given index */
00269 CPROPS_DLL
00270 void *cp_multimap_remove_by_index(cp_multimap *map, 
00271                                   cp_index *index, 
00272                                   void *entry);
00273 
00274 /* scan indices and replace entries */
00275 CPROPS_DLL
00276 int cp_multimap_reindex(cp_multimap *map, void *before, void *after);
00277 
00278 /* 
00279  * perform a pre-order iteration over the tree, calling 'callback' on each 
00280  * node
00281  */
00282 CPROPS_DLL
00283 int cp_multimap_callback_preorder(cp_multimap *tree, 
00284                                 cp_callback_fn callback, 
00285                                 void *prm);
00286 /* 
00287  * perform an in-order iteration over the tree, calling 'callback' on each 
00288  * node
00289  */
00290 CPROPS_DLL
00291 int cp_multimap_callback(cp_multimap *tree, cp_callback_fn callback, void *prm);
00292 
00293 /* 
00294  * perform an in-order iteration over the tree, calling 'callback' on each node
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  * perform a post-order iteration over the tree, calling 'callback' on each 
00304  * node
00305  */
00306 CPROPS_DLL
00307 int cp_multimap_callback_postorder(cp_multimap *tree, 
00308                                    cp_callback_fn callback, 
00309                                    void *prm);
00310 
00311 /* return the number of mappings in the tree */
00312 CPROPS_DLL
00313 int cp_multimap_count(cp_multimap *tree);
00314 
00315 #define cp_multimap_size cp_multimap_count
00316 
00317 /* 
00318  * lock tree for reading or writing as specified by type parameter. 
00319  */
00320 CPROPS_DLL
00321 int cp_multimap_lock(cp_multimap *tree, int type);
00322 /* read lock */
00323 #define cp_multimap_rdlock(tree) (cp_multimap_lock((tree), COLLECTION_LOCK_READ))
00324 /* write lock */
00325 #define cp_multimap_wrlock(tree) (cp_multimap_lock((tree), COLLECTION_LOCK_WRITE))
00326 /* unlock */
00327 CPROPS_DLL
00328 int cp_multimap_unlock(cp_multimap *tree);
00329 
00330 
00331 /* return the table mode indicator */
00332 CPROPS_DLL
00333 int cp_multimap_get_mode(cp_multimap *tree);
00334 /* set mode bits on the tree mode indicator */
00335 CPROPS_DLL
00336 int cp_multimap_set_mode(cp_multimap *tree, int mode);
00337 /* unset mode bits on the tree mode indicator. if unsetting 
00338  * COLLECTION_MODE_NOSYNC and the tree was not previously synchronized, the 
00339  * internal synchronization structure is initalized.
00340  */
00341 CPROPS_DLL
00342 int cp_multimap_unset_mode(cp_multimap *tree, int mode);
00343 
00344 
00346 CPROPS_DLL
00347 void cp_multimap_dump(cp_multimap *tree);
00348 
00349 /* set tree to use given mempool or allocate a new one if pool is NULL */
00350 CPROPS_DLL
00351 int cp_multimap_use_mempool(cp_multimap *tree, cp_mempool *pool);
00352 
00353 /* set tree to use a shared memory pool */
00354 CPROPS_DLL
00355 int cp_multimap_share_mempool(cp_multimap *tree, 
00356                               struct _cp_shared_mempool *pool);
00357 
00358 /* add an index */
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 
00370 #endif
00371 

Generated on Mon Dec 5 23:00:22 2011 for cprops by  doxygen 1.4.7