skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

avlnode.h (1997B)


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