void *
-se_tree_lookup32(emem_tree_t *se_tree, guint32 key)
+emem_tree_lookup32(emem_tree_t *se_tree, guint32 key)
{
emem_tree_node_t *node;
}
void *
-se_tree_lookup32_le(emem_tree_t *se_tree, guint32 key)
+emem_tree_lookup32_le(emem_tree_t *se_tree, guint32 key)
{
emem_tree_node_t *node;
/* insert a new node in the tree. if this node matches an already existing node
* then just replace the data for that node */
void
-se_tree_insert32(emem_tree_t *se_tree, guint32 key, void *data)
+emem_tree_insert32(emem_tree_t *se_tree, guint32 key, void *data)
{
emem_tree_node_t *node;
return tree_list;
}
+/* create another (sub)tree using the same memory allocation scope
+ * as the parent tree.
+ */
+static emem_tree_t *
+emem_tree_create_subtree(emem_tree_t *parent_tree, char *name)
+{
+ emem_tree_t *tree_list;
+
+ tree_list=parent_tree->malloc(sizeof(emem_tree_t));
+ tree_list->next=NULL;
+ tree_list->type=parent_tree->type;
+ tree_list->tree=NULL;
+ tree_list->name=name;
+ tree_list->malloc=parent_tree->malloc;
+
+ return tree_list;
+}
+
static void* create_sub_tree(void* d) {
emem_tree_t *se_tree = d;
- return se_tree_create_non_persistent(se_tree->type, "subtree");
+ return emem_tree_create_subtree(se_tree, "subtree");
}
/* insert a new node in the tree. if this node matches an already existing node
* then just replace the data for that node */
void
-se_tree_insert32_array(emem_tree_t *se_tree, emem_tree_key_t *key, void *data)
+emem_tree_insert32_array(emem_tree_t *se_tree, emem_tree_key_t *key, void *data)
{
emem_tree_t *next_tree;
DISSECTOR_ASSERT_NOT_REACHED();
}
if((key[0].length==1)&&(key[1].length==0)){
- se_tree_insert32(se_tree, *key[0].key, data);
+ emem_tree_insert32(se_tree, *key[0].key, data);
return;
}
key[0].length--;
key[0].key++;
}
- se_tree_insert32_array(next_tree, key, data);
+ emem_tree_insert32_array(next_tree, key, data);
}
void *
-se_tree_lookup32_array(emem_tree_t *se_tree, emem_tree_key_t *key)
+emem_tree_lookup32_array(emem_tree_t *se_tree, emem_tree_key_t *key)
{
emem_tree_t *next_tree;
DISSECTOR_ASSERT_NOT_REACHED();
}
if((key[0].length==1)&&(key[1].length==0)){
- return se_tree_lookup32(se_tree, *key[0].key);
+ return emem_tree_lookup32(se_tree, *key[0].key);
}
- next_tree=se_tree_lookup32(se_tree, *key[0].key);
+ next_tree=emem_tree_lookup32(se_tree, *key[0].key);
if(!next_tree){
return NULL;
}
key[0].length--;
key[0].key++;
}
- return se_tree_lookup32_array(next_tree, key);
+ return emem_tree_lookup32_array(next_tree, key);
}
-void se_tree_insert_string(emem_string_hash_t* se_tree, const gchar* k, void* v) {
+void
+emem_tree_insert_string(emem_tree_t* se_tree, const gchar* k, void* v) {
guint32 len = strlen(k);
guint32 div = (len-1)/4;
guint32 residual = 0;
break;
}
- se_tree_insert32_array(se_tree,key,v);
+ emem_tree_insert32_array(se_tree,key,v);
}
-void* se_tree_lookup_string(emem_string_hash_t* se_tree, const gchar* k) {
+void *
+emem_tree_lookup_string(emem_tree_t* se_tree, const gchar* k) {
guint32 len = strlen(k);
guint32 div = (len-1)/4;
guint32 residual = 0;
break;
}
- return se_tree_lookup32_array(se_tree, key);
+ return emem_tree_lookup32_array(se_tree, key);
}
extern emem_tree_t *se_trees;
+/* *******************************************************************
+ * Tree functions for SE memory allocation scope
+ * ******************************************************************* */
/* This function is used to create a se based tree with monitoring.
* When the SE heap is released back to the system the pointer to the
* tree is automatically reset to NULL.
*/
emem_tree_t *se_tree_create(int type, char *name);
+/* This function is similar to the se_tree_create() call but with the
+ * difference that when the se memory is release everything including the
+ * pointer to the tree itself will be released.
+ * This tree will not be just reset to zero it will be completely forgotten
+ * by the allocator.
+ * Use this function for when you want to store the pointer to a tree inside
+ * another structure that is also se allocated so that when the structure is
+ * released, the tree will be completely released as well.
+ */
+emem_tree_t *se_tree_create_non_persistent(int type, char *name);
+
+/* se_tree_insert32
+ * Insert data into the tree and key it by a 32bit integer value
+ */
+#define se_tree_insert32 emem_tree_insert32
+
+/* se_tree_lookup32
+ * Retreive the data at the search key. the search key is a 32bit integer value
+ */
+#define se_tree_lookup32 emem_tree_lookup32
+
+/* se_tree_lookup32_le
+ * Retreive the data for the largest key that is less than or equal
+ * to the search key.
+ */
+#define se_tree_lookup32_le emem_tree_lookup32_le
+
+/* se_tree_insert32_array
+ * Insert data into the tree and key it by a 32bit integer value
+ */
+#define se_tree_insert32_array emem_tree_insert32_array
+
+/* se_tree_lookup32_array
+ * Lookup data from the tree that is index by an array
+ */
+#define se_tree_lookup32_array emem_tree_lookup32_array
+
+
+
+/* Create a new string based hash table */
+#define se_tree_create_string() se_tree_create(SE_TREE_TYPE_RED_BLACK)
+
+/* Insert a new value under a string key */
+#define se_tree_insert_string emem_tree_insert_string
+
+/* Lookup the value under a string key */
+#define se_tree_lookup_string emem_tree_lookup_string
+
+
+
+
+
+/* ******************************************************************
+ * Real tree functions
+ * ****************************************************************** */
+
/* This function is used to insert a node indexed by a guint32 key value.
- * The data pointer should be allocated by SE allocators so that the
- * data will be released at the same time as the tree itself is destroyed.
+ * The data pointer should be allocated by the appropriate storage scope
+ * so that it will be released at the same time as the tree itself is
+ * destroyed.
*/
-void se_tree_insert32(emem_tree_t *se_tree, guint32 key, void *data);
+void emem_tree_insert32(emem_tree_t *se_tree, guint32 key, void *data);
/* This function will look up a node in the tree indexed by a guint32 integer
* value.
*/
-void *se_tree_lookup32(emem_tree_t *se_tree, guint32 key);
+void *emem_tree_lookup32(emem_tree_t *se_tree, guint32 key);
/* This function will look up a node in the tree indexed by a guint32 integer
* value.
* equal to or smaller than the search key, or NULL if no such key was
* found.
*/
-void *se_tree_lookup32_le(emem_tree_t *se_tree, guint32 key);
-
-
-/* This function is similar to the se_tree_create() call but with the
- * difference that when the se memory is release everything including the
- * pointer to the tree itself will be released.
- * This tree will not be just reset to zero it will be completely forgotten
- * by the allocator.
- * Use this function for when you want to store the pointer to a tree inside
- * another structure that is also se allocated so that when the structure is
- * released, the tree will be completely released as well.
- */
-emem_tree_t *se_tree_create_non_persistent(int type, char *name);
-
-
+void *emem_tree_lookup32_le(emem_tree_t *se_tree, guint32 key);
typedef struct _emem_tree_key_t {
guint32 length; /*length in guint32 words */
* fhkey[1].key=nns->fh;
* fhkey[2].length=0;
*/
-void se_tree_insert32_array(emem_tree_t *se_tree, emem_tree_key_t *key, void *data);
+void emem_tree_insert32_array(emem_tree_t *se_tree, emem_tree_key_t *key, void *data);
/* This function will look up a node in the tree indexed by a sequence of
* guint32 integer values.
*/
-void *se_tree_lookup32_array(emem_tree_t *se_tree, emem_tree_key_t *key);
-
-/*
- * A hash table with string keys based on the red/black tree
- */
-typedef struct _emem_tree_t emem_string_hash_t;
-
-/* Create a new string based hash table */
-#define se_tree_create_string() se_tree_create(SE_TREE_TYPE_RED_BLACK)
+void *emem_tree_lookup32_array(emem_tree_t *se_tree, emem_tree_key_t *key);
/* Insert a new value under a string key */
-void se_tree_insert_string(emem_string_hash_t* h, const gchar* k, void* v);
+void emem_tree_insert_string(emem_tree_t* h, const gchar* k, void* v);
/* Lookup the value under a string key */
-void* se_tree_lookup_string(emem_string_hash_t* h, const gchar* k);
+void* emem_tree_lookup_string(emem_tree_t* h, const gchar* k);
+
+
+
+
+
+
+
#endif /* emem.h */