1 /* ISC license. */ 2 3 #ifndef AVLNODE_H 4 #define AVLNODE_H 5 6 #include <stdint.h> 7 #include <skalibs/gccattributes.h> 8 #include <skalibs/functypes.h> 9 10 11 #define AVLNODE_MAXDEPTH 49 /* enough for 2^32 nodes in the worst case */ 12 13 typedef int avliterfunc_t (uint32_t, unsigned int, void *) ; 14 typedef avliterfunc_t *avliterfunc_t_ref ; 15 16 typedef struct avlnode_s avlnode, *avlnode_ref ; 17 struct avlnode_s 18 { 19 uint32_t data ; 20 uint32_t child[2] ; 21 signed char balance : 2 ; 22 } ; 23 24 #define AVLNODE_ZERO { .data = 0, .child = { UINT32_MAX, UINT32_MAX }, .balance = 0 } 25 extern avlnode const avlnode_zero ; 26 27 extern uint32_t avlnode_searchnode (avlnode const *, uint32_t, uint32_t, void const *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; 28 extern int avlnode_search (avlnode const *, uint32_t, uint32_t, void const *, uint32_t *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; 29 extern unsigned int avlnode_height (avlnode const *, uint32_t, uint32_t) gccattr_pure ; 30 31 extern uint32_t avlnode_extremenode (avlnode const *, uint32_t, uint32_t, int) gccattr_pure ; 32 #define avlnode_minnode(s, max, r) avlnode_extremenode(s, max, (r), 0) 33 #define avlnode_maxnode(s, max, r) avlnode_extremenode(s, max, (r), 1) 34 35 extern int avlnode_extreme (avlnode const *, uint32_t, uint32_t, int, uint32_t *) ; 36 #define avlnode_min(s, max, r, data) avlnode_extreme(s, max, (r), 0, data) 37 #define avlnode_max(s, max, r, data) avlnode_extreme(s, max, (r), 1, data) 38 39 extern uint32_t avlnode_insertnode (avlnode *, uint32_t, uint32_t, uint32_t, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; 40 extern uint32_t avlnode_delete (avlnode *, uint32_t, uint32_t *, void const *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; 41 42 extern uint32_t avlnode_iter_nocancel (avlnode *, uint32_t, uint32_t, uint32_t, avliterfunc_t_ref, void *) ; 43 #define avlnode_iter(tree, max, root, f, stuff) (avlnode_iter_nocancel(tree, max, max, root, f, stuff) == (max)) 44 extern int avlnode_iter_withcancel (avlnode *, uint32_t, uint32_t, avliterfunc_t_ref, avliterfunc_t_ref, void *) ; 45 46 #endif 47