• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/genericProc/programs/libcprops/trie.h

Go to the documentation of this file.
00001 #ifndef _CP_RTREE_H
00002 #define _CP_RTREE_H
00003 
00004 /**
00005  * @addtogroup cp_trie
00006  */
00007 /** @{ */
00008 
00009 #include "common.h"
00010 
00011 __BEGIN_DECLS
00012 
00013 #include "config.h"
00014 
00015 #include <string.h>
00016 #include <errno.h>
00017 #include "hashtable.h"
00018 #include "vector.h"
00019 #include "mtab.h"
00020 #include "mempool.h"
00021 
00022 #define NODE_MATCH(n, i) ((n)->others ? mtab_get((n)->others, *i) : NULL)
00023 #define BRANCH_COUNT(node) mtab_count((node)->others)
00024 
00025 typedef int (*cp_trie_match_fn)(void *leaf); 
00026 
00027 CPROPS_DLL struct _cp_trie;
00028 
00029 /* 
00030  * cp_trie nodes can have any number of subnodes mapped by an mtab - a hash
00031  * table designed for character keys
00032  */
00033 typedef CPROPS_DLL struct _cp_trie_node 
00034 { 
00035         mtab *others; 
00036         void *leaf; 
00037 } cp_trie_node; 
00038 
00039 CPROPS_DLL
00040 cp_trie_node *cp_trie_node_new(void *leaf, cp_mempool *pool); 
00041 CPROPS_DLL
00042 void *cp_trie_node_delete(struct _cp_trie *grp, cp_trie_node *node);
00043 CPROPS_DLL
00044 void cp_trie_delete_mapping(struct _cp_trie *grp, mtab_node *map_node);
00045 
00046 CPROPS_DLL
00047 void cp_trie_node_unmap(struct _cp_trie *grp, cp_trie_node **node); 
00048 
00049 /**
00050  * @file trie.h
00051  * cp_trie is a character trie implementation. Tries allow for prefix matching
00052  * with O(m) = O(1) time (m being the length of the key). Used to store key - 
00053  * value mappings, tries have certain advantages over hashtables in that worse 
00054  * case behavior is still O(1) and no hash function is needed. cp_trie is 
00055  * technically a compact trie in that collapses unused character paths. 
00056  */
00057 typedef CPROPS_DLL struct _cp_trie
00058 { 
00059         cp_trie_node *root;                /**< root node           */
00060         int path_count;                    /**< number of entries   */
00061 
00062         int mode;                          /**< collection mode     */
00063 
00064         cp_copy_fn copy_leaf;              /**< leaf copy function  */
00065         cp_destructor_fn delete_leaf;      /**< leaf destructor     */
00066 
00067         cp_lock *lock;                     /**< collection lock     */
00068         cp_thread txowner;                 /**< transaction owner   */
00069         int txtype;                        /**< lock type           */
00070 
00071         cp_mempool *mempool;                       /**< memory pool         */
00072 } cp_trie; 
00073 
00074 /** 
00075  * create a new cp_trie object with the specified collection mode and
00076  * leaf management functions
00077  */
00078 CPROPS_DLL
00079 cp_trie *cp_trie_create_trie(int mode, 
00080                                      cp_copy_fn copy_leaf, 
00081                                                          cp_destructor_fn delete_leaf);
00082 
00083 /** create a new cp_trie object with the specified collection mode */
00084 CPROPS_DLL
00085 cp_trie *cp_trie_create(int mode);
00086 /** delete a cp_trie object */
00087 CPROPS_DLL
00088 int cp_trie_destroy(cp_trie *grp); 
00089 /** add a mapping to a trie */
00090 CPROPS_DLL
00091 int cp_trie_add(cp_trie *grp, char *key, void *leaf); 
00092 /** remove a mapping from a trie */
00093 CPROPS_DLL
00094 int cp_trie_remove(cp_trie *grp, char *key, void **leaf); 
00095 /** return the mapping for the longest prefix of the given key */
00096 CPROPS_DLL
00097 int cp_trie_prefix_match(cp_trie *grp, char *key, void **leaf);
00098 /** return the mapping for the given key if any */
00099 CPROPS_DLL
00100 void *cp_trie_exact_match(cp_trie *grp, char *key);
00101 /** return a vector containing exact match and any prefix matches */
00102 CPROPS_DLL
00103 cp_vector *cp_trie_fetch_matches(cp_trie *grp, char *key);
00104 /** return a vector containing all entries in subtree under path given by key */
00105 CPROPS_DLL
00106 cp_vector *cp_trie_submatch(cp_trie *grp, char *key);
00107 
00108 /** return the number of stored items */
00109 CPROPS_DLL
00110 int cp_trie_count(cp_trie *grp);
00111 
00112 CPROPS_DLL
00113 void cp_trie_set_root(cp_trie *grp, void *leaf); 
00114 
00115 CPROPS_DLL
00116 int cp_trie_lock(cp_trie *grp, int type);
00117 #define cp_trie_rdlock(grp) (cp_trie_lock(grp, COLLECTION_LOCK_READ))
00118 #define cp_trie_wrlock(grp) (cp_trie_lock(grp, COLLECTION_LOCK_WRITE))
00119 CPROPS_DLL
00120 int cp_trie_unlock(cp_trie *grp);
00121 
00122 /* get the current collection mode */
00123 CPROPS_DLL
00124 int cp_trie_get_mode(cp_trie *grp);
00125 /* sets the bits defined by mode on the trie mode */
00126 CPROPS_DLL
00127 int cp_trie_set_mode(cp_trie *grp, int mode);
00128 /* clears the bits defined by mode on the trie mode */
00129 CPROPS_DLL
00130 int cp_trie_unset_mode(cp_trie *grp, int mode);
00131 
00132 CPROPS_DLL
00133 void cp_trie_dump(cp_trie *grp);
00134 
00135 /* set trie to use given mempool or allocate a new one if pool is NULL */
00136 CPROPS_DLL
00137 int cp_trie_use_mempool(cp_trie *tree, cp_mempool *pool);
00138 
00139 /* set trie to use a shared memory pool */
00140 CPROPS_DLL
00141 int cp_trie_share_mempool(cp_trie *tree, cp_shared_mempool *pool);
00142 
00143 __END_DECLS
00144 
00145 /** @} */
00146 
00147 #endif
00148 

Generated on Fri Oct 22 2010 11:02:23 for SST by  doxygen 1.7.1