summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-09 16:10:40 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-09 16:10:40 +0000
commitb59ce39f9779cf4b1ad423783b6a532f94a8e880 (patch)
tree4db0c2cc5de6b4fe5d01fb5cc762b6a74ce32d34 /src/include
parent157ecd01d6cc4598ce4b0ec9bd477abbbf41d6c5 (diff)
downloadskalibs-b59ce39f9779cf4b1ad423783b6a532f94a8e880.tar.xz
Add cancellation to iterators over avltree(n) and genset(dyn)
Diffstat (limited to 'src/include')
-rw-r--r--src/include/skalibs/avlnode.h4
-rw-r--r--src/include/skalibs/avltree.h2
-rw-r--r--src/include/skalibs/avltreen.h4
-rw-r--r--src/include/skalibs/genset.h5
-rw-r--r--src/include/skalibs/gensetdyn.h4
5 files changed, 15 insertions, 4 deletions
diff --git a/src/include/skalibs/avlnode.h b/src/include/skalibs/avlnode.h
index faaee10..245eef4 100644
--- a/src/include/skalibs/avlnode.h
+++ b/src/include/skalibs/avlnode.h
@@ -39,6 +39,8 @@ extern unsigned int avlnode_insertnode (avlnode *, unsigned int, unsigned int, u
extern unsigned int avlnode_delete (avlnode *, unsigned int, unsigned int *, void const *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
#define avlnode_deletenode(s, max, r, i, dtok, f, p) avlnode_delete(s, max, r, (*(dtok))((s)[i].data), dtok, f, p)
-extern int avlnode_iter (avlnode *, unsigned int, unsigned int, avliterfunc_t_ref, void *) ;
+extern unsigned int avlnode_iter_nocancel (avlnode *, unsigned int, unsigned int, unsigned int, avliterfunc_t_ref, void *) ;
+#define avlnode_iter(tree, max, root, f, stuff) (avlnode_iter_nocancel(tree, max, max, root, f, stuff) == (max))
+extern int avlnode_iter_withcancel (avlnode *, unsigned int, unsigned int, avliterfunc_t_ref, avliterfunc_t_ref, void *) ;
#endif
diff --git a/src/include/skalibs/avltree.h b/src/include/skalibs/avltree.h
index cd035f6..0b74235 100644
--- a/src/include/skalibs/avltree.h
+++ b/src/include/skalibs/avltree.h
@@ -51,5 +51,7 @@ extern int avltree_insert (avltree *, unsigned int) ;
extern int avltree_delete (avltree *, void const *) ;
#define avltree_iter(t, f, p) avlnode_iter(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), f, p)
+#define avltree_iter_nocancel(t, cut, f, p) avlnode_iter(avltree_nodes(t), avltree_totalsize(t), cut, avltree_root(t), f, p)
+#define avltree_iter_withcancel(t, f, cancelf, p) avlnode_iter_withcancel(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), f, cancelf, p)
#endif
diff --git a/src/include/skalibs/avltreen.h b/src/include/skalibs/avltreen.h
index c453b99..8b14db7 100644
--- a/src/include/skalibs/avltreen.h
+++ b/src/include/skalibs/avltreen.h
@@ -50,6 +50,8 @@ extern int avltreen_insert (avltreen *, unsigned int) ;
extern int avltreen_delete (avltreen *, void const *) ;
#define avltreen_iter(t, f, p) avlnode_iter(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), f, p)
+#define avltreen_iter_nocancel(t, cut, f, p) avlnode_iter_nocancel(avltreen_nodes(t), avltreen_totalsize(t), cut, avltreen_root(t), f, p)
+#define avltreen_iter_withcancel(t, f, cancelf, p) avlnode_iter_withcancel(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), f, cancelf, p)
/* avltreeb: everything in one place. Stack or BSS, or heap if you insist */
@@ -83,5 +85,7 @@ extern int avltreen_delete (avltreen *, void const *) ;
#define avltreeb_delete(t, k) avltreen_delete(&(t)->info, k)
#define avltreeb_iter(t, f, p) avlnode_iter(avltreeb_nodes(t), avltreeb_totalsize(t), avltreeb_root(t), f, p)
+#define avltreeb_iter_nocancel(t, cut, f, p) avlnode_iter_nocancel(avltreeb_nodes(t), avltreeb_totalsize(t), cut, avltreeb_root(t), f, p)
+#define avltreeb_iter_withcancel(t, f, cancelf, p) avlnode_iter_withcancel(avltreeb_nodes(t), avltreeb_totalsize(t), avltreeb_root(t), f, cancelf, p)
#endif
diff --git a/src/include/skalibs/genset.h b/src/include/skalibs/genset.h
index 5e27821..83e0519 100644
--- a/src/include/skalibs/genset.h
+++ b/src/include/skalibs/genset.h
@@ -23,8 +23,9 @@ extern void genset_init (genset *, void *, unsigned int *, unsigned int, unsigne
extern unsigned int genset_new (genset *) ;
extern int genset_delete (genset *, unsigned int) ;
#define genset_n(g) ((g)->max - (g)->sp)
-extern unsigned int genset_iter (genset *, iterfunc_t_ref, void *) ;
-
+extern unsigned int genset_iter_nocancel (genset *, unsigned int, iterfunc_t_ref, void *) ;
+#define genset_iter(g, f, stuff) genset_iter_nocancel(g, (g)->max, f, stuff)
+extern int genset_iter_withcancel (genset *, iterfunc_t_ref, iterfunc_t_ref, void *) ;
#define GENSETB_TYPE(type, size) struct { type storage[size] ; unsigned int freelist[size] ; genset info ; }
#define GENSETB_init(type, g, size) GENSET_init(&(g)->info, type, (g)->storage, (g)->freelist, size)
diff --git a/src/include/skalibs/gensetdyn.h b/src/include/skalibs/gensetdyn.h
index 20dfde6..7a1cc47 100644
--- a/src/include/skalibs/gensetdyn.h
+++ b/src/include/skalibs/gensetdyn.h
@@ -35,6 +35,8 @@ extern int gensetdyn_delete (gensetdyn *, unsigned int) ;
#define gensetdyn_p(g, i) ((g)->storage.s + (i) * (g)->esize)
#define GENSETDYN_P(type, g, i) ((type *)gensetdyn_p(g, i))
-extern unsigned int gensetdyn_iter (gensetdyn *, iterfunc_t_ref, void *) ;
+extern unsigned int gensetdyn_iter_nocancel (gensetdyn *, unsigned int, iterfunc_t_ref, void *) ;
+#define gensetdyn_iter(g, f, stuff) gensetdyn_iter_nocancel(g, (g)->storage.len, f, stuff)
+extern int gensetdyn_iter_withcancel (gensetdyn *, iterfunc_t_ref, iterfunc_t_ref, void *) ;
#endif