aboutsummaryrefslogtreecommitdiffstats
path: root/src/radix.h
diff options
context:
space:
mode:
authorcebka@lenovo-laptop <cebka@lenovo-laptop>2010-02-25 18:55:40 +0300
committercebka@lenovo-laptop <cebka@lenovo-laptop>2010-02-25 18:55:40 +0300
commit2cab3a9c488cb9042acf4350dc327a7dcb0c9eb9 (patch)
tree981fc9c30d87a66d15c0804ba62e56dde8505af6 /src/radix.h
parentc6636a9fc339468d02b47498945711d25623b3e5 (diff)
downloadrspamd-2cab3a9c488cb9042acf4350dc327a7dcb0c9eb9.tar.gz
rspamd-2cab3a9c488cb9042acf4350dc327a7dcb0c9eb9.zip
* Add first custom filter for making marks for ip addresses and networks
* Some additions to radix tree library: - allow tree traverse - add new insert methods (add and replace) - store keys in radix nodes (thought we can calculate key by bits, but I think that storing key is not too expensive) - values in a tree are now uintptr_t
Diffstat (limited to 'src/radix.h')
-rw-r--r--src/radix.h58
1 files changed, 54 insertions, 4 deletions
diff --git a/src/radix.h b/src/radix.h
index 46c6adb05..70aac1f74 100644
--- a/src/radix.h
+++ b/src/radix.h
@@ -4,7 +4,7 @@
#include "config.h"
#include "mem_pool.h"
-#define RADIX_NO_VALUE (unsigned char)-1
+#define RADIX_NO_VALUE (uintptr_t)-1
typedef struct radix_node_s radix_node_t;
@@ -12,7 +12,8 @@ struct radix_node_s {
radix_node_t *right;
radix_node_t *left;
radix_node_t *parent;
- unsigned char value;
+ uintptr_t value;
+ uint32_t key;
};
@@ -22,11 +23,60 @@ typedef struct {
memory_pool_t *pool;
} radix_tree_t;
+typedef gboolean (*radix_tree_traverse_func)(uint32_t key, uint32_t mask, uintptr_t value, void *user_data);
+/**
+ * Create new radix tree
+ */
radix_tree_t *radix_tree_create ();
-int radix32tree_insert (radix_tree_t *tree, uint32_t key, uint32_t mask, unsigned char value);
+
+/**
+ * Insert value to radix tree
+ * returns: 1 if value already exists
+ * 0 if operation was successfull
+ * -1 if there was some error
+ */
+int radix32tree_insert (radix_tree_t *tree, uint32_t key, uint32_t mask, uintptr_t value);
+
+/**
+ * Add value to radix tree or insert it if value does not exists
+ * returns: value if value already exists and was added
+ * 0 if value was inserted
+ * -1 if there was some error
+ */
+uintptr_t radix32tree_add (radix_tree_t *tree, uint32_t key, uint32_t mask, uintptr_t value);
+
+/**
+ * Replace value in radix tree or insert it if value does not exists
+ * returns: 1 if value already exists and was replaced
+ * 0 if value was inserted
+ * -1 if there was some error
+ */
+int radix32tree_replace (radix_tree_t *tree, uint32_t key, uint32_t mask, uintptr_t value);
+
+/**
+ * Delete value from radix tree
+ * returns: 1 if value does not exist
+ * 0 if value was deleted
+ * -1 if there was some error
+ */
int radix32tree_delete (radix_tree_t *tree, uint32_t key, uint32_t mask);
-unsigned char radix32tree_find (radix_tree_t *tree, uint32_t key);
+
+/**
+ * Find value in radix tree
+ * returns: value if value was found
+ * RADIX_NO_VALUE if value was not found
+ */
+uintptr_t radix32tree_find (radix_tree_t *tree, uint32_t key);
+
+/**
+ * Traverse via the whole tree calling specified callback
+ */
+void radix32tree_traverse (radix_tree_t *tree, radix_tree_traverse_func func, void *user_data);
+
+/**
+ * Frees radix tree
+ */
void radix_tree_free (radix_tree_t *tree);
#endif