rtrie.h

Go to the documentation of this file.
00001 #ifndef _CP_RRTREE_H
00002 #define _CP_RRTREE_H
00003 
00009 #include "common.h"
00010 
00011 __BEGIN_DECLS
00012 
00013 #include "config.h"
00014 
00015 #include <string.h>
00016 #include <errno.h>
00017 #include "vector.h"
00018 #include "bstr.h"
00019 #include "mempool.h"
00020 
00021 
00022 typedef int (*cp_rtrie_match_fn)(void *leaf); 
00023 
00024 CPROPS_DLL struct _cp_rtrie;
00025 
00026 /* 
00027  * cp_rtrie nodes can have just about 2 subnodes, which are a sequence of 1 
00028  * or more bits. 
00029  */
00030 typedef CPROPS_DLL struct _cp_rtrie_node 
00031 { 
00032     cp_bstr *zero;
00033     cp_bstr *one;
00034     struct _cp_rtrie_node *node_zero;
00035     struct _cp_rtrie_node *node_one;
00036     void *leaf; 
00037 } cp_rtrie_node; 
00038 
00039 CPROPS_DLL
00040 cp_rtrie_node *cp_rtrie_node_new(void *leaf, cp_mempool *pool); 
00041 CPROPS_DLL
00042 void *cp_rtrie_node_delete(struct _cp_rtrie *grp, cp_rtrie_node *node);
00043 
00044 CPROPS_DLL
00045 void cp_rtrie_node_unmap(struct _cp_rtrie *grp, cp_rtrie_node **node); 
00046 
00055 typedef CPROPS_DLL struct _cp_rtrie
00056 { 
00057     cp_rtrie_node *root;                
00058     int path_count;                    
00060     int mode;                          
00062     cp_copy_fn copy_leaf;              
00063     cp_destructor_fn delete_leaf;      
00065     cp_lock *lock;                     
00066     cp_thread txowner;                 
00067     int txtype;                        
00069     cp_mempool *mempool;               
00070 } cp_rtrie; 
00071 
00076 CPROPS_DLL
00077 cp_rtrie *cp_rtrie_create_rtrie(int mode, 
00078                              cp_copy_fn copy_leaf, 
00079                              cp_destructor_fn delete_leaf);
00080 
00082 CPROPS_DLL
00083 cp_rtrie *cp_rtrie_create(int mode);
00085 CPROPS_DLL
00086 int cp_rtrie_destroy(cp_rtrie *grp); 
00088 CPROPS_DLL
00089 int cp_rtrie_add(cp_rtrie *grp, cp_bstr *key, void *leaf);
00091 CPROPS_DLL
00092 int cp_rtrie_remove(cp_rtrie *grp, cp_bstr *key, void **leaf);
00094 CPROPS_DLL
00095 int cp_rtrie_prefix_match(cp_rtrie *grp, cp_bstr *key, void **leaf);
00097 CPROPS_DLL
00098 void *cp_rtrie_exact_match(cp_rtrie *grp, cp_bstr *key);
00100 CPROPS_DLL
00101 cp_vector *cp_rtrie_fetch_matches(cp_rtrie *grp, cp_bstr *key);
00103 CPROPS_DLL
00104 cp_vector *cp_rtrie_submatch(cp_rtrie *grp, cp_bstr *key);
00105 
00107 CPROPS_DLL
00108 int cp_rtrie_count(cp_rtrie *grp);
00109 
00110 CPROPS_DLL
00111 void cp_rtrie_set_root(cp_rtrie *grp, void *leaf); 
00112 
00113 CPROPS_DLL
00114 int cp_rtrie_lock(cp_rtrie *grp, int type);
00115 #define cp_rtrie_rdlock(grp) (cp_rtrie_lock(grp, COLLECTION_LOCK_READ))
00116 #define cp_rtrie_wrlock(grp) (cp_rtrie_lock(grp, COLLECTION_LOCK_WRITE))
00117 CPROPS_DLL
00118 int cp_rtrie_unlock(cp_rtrie *grp);
00119 
00120 /* get the current collection mode */
00121 CPROPS_DLL
00122 int cp_rtrie_get_mode(cp_rtrie *grp);
00123 /* sets the bits defined by mode on the rtrie mode */
00124 CPROPS_DLL
00125 int cp_rtrie_set_mode(cp_rtrie *grp, int mode);
00126 /* clears the bits defined by mode on the rtrie mode */
00127 CPROPS_DLL
00128 int cp_rtrie_unset_mode(cp_rtrie *grp, int mode);
00129 
00130 CPROPS_DLL
00131 void cp_rtrie_dump(cp_rtrie *grp);
00132 
00133 /* set rtrie to use given mempool or allocate a new one if pool is NULL */
00134 CPROPS_DLL
00135 int cp_rtrie_use_mempool(cp_rtrie *tree, cp_mempool *pool);
00136 
00137 /* set rtrie to use a shared memory pool */
00138 CPROPS_DLL
00139 int cp_rtrie_share_mempool(cp_rtrie *tree, cp_shared_mempool *pool);
00140 
00141 __END_DECLS
00142 
00145 #endif
00146 

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