skalibs

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

avltree_delete.c (489B)


      1 /* ISC license. */
      2 
      3 #include <stdint.h>
      4 #include <errno.h>
      5 #include <skalibs/gensetdyn.h>
      6 #include <skalibs/avlnode.h>
      7 #include <skalibs/avltree.h>
      8 
      9 int avltree_delete (avltree *t, void const *k)
     10 {
     11   uint32_t r = avltree_root(t) ;
     12   uint32_t i = avlnode_delete(avltree_nodes(t), avltree_totalsize(t), &r, k, t->dtok, t->kcmp, t->external) ;
     13   if (i >= avltree_totalsize(t)) return (errno = ESRCH, 0) ;
     14   avltree_setroot(t, r) ;
     15   if (!gensetdyn_delete(&t->x, i)) return 0 ;
     16   return 1 ;
     17 }