Add stricter checks for netnames.
[tinc] / src / splay_tree.h
index e4af0c4..3ddf217 100644 (file)
@@ -1,6 +1,6 @@
 /*
     splay_tree.h -- header file for splay_tree.c
-    Copyright (C) 2004-2006 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2004-2013 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -58,14 +58,16 @@ typedef struct splay_tree_t {
        splay_compare_t compare;
        splay_action_t delete;
 
+       int count;
+
 } splay_tree_t;
 
 /* (De)constructors */
 
-extern splay_tree_t *splay_alloc_tree(splay_compare_t, splay_action_t);
+extern splay_tree_t *splay_alloc_tree(splay_compare_t, splay_action_t) __attribute__ ((__malloc__));
 extern void splay_free_tree(splay_tree_t *);
 
-extern splay_node_t *splay_alloc_node(void);
+extern splay_node_t *splay_alloc_node(void) __attribute__ ((__malloc__));
 extern void splay_free_node(splay_tree_t *tree, splay_node_t *);
 
 /* Insertion and deletion */
@@ -104,4 +106,12 @@ extern splay_node_t *splay_search_closest_greater_node(splay_tree_t *, const voi
 extern void splay_foreach(const splay_tree_t *, splay_action_t);
 extern void splay_foreach_node(const splay_tree_t *, splay_action_t);
 
+/*
+   Iterates over a tree.
+
+   CAUTION: while this construct supports deleting the current item,
+   it does *not* support deleting *other* nodes while iterating on the tree.
+ */
+#define splay_each(type, item, tree) (type *item = (type *)1; item; item = NULL) for(splay_node_t *node = (tree)->head, *next; item = node ? node->data : NULL, next = node ? node->next : NULL, node; node = next)
+
 #endif