lib/src/diet.c
void diet_remove(struct diet * const d, const uint64_t n)
{
    // rotate the interval that contains n or is closest to it to the top
    diet_find(d, n);

    if (n < splay_root(d)->lo || n > splay_root(d)->hi)
        return;

    if (n == splay_root(d)->lo) {
        if (n == splay_root(d)->hi) {
            free(splay_remove(diet, d, splay_root(d)));
            d->cnt--;
        } else
            // adjust lo bound
            splay_root(d)->lo++;
    } else if (n == splay_root(d)->hi) {
        // adjust hi bound
        splay_root(d)->hi--;
    } else {
        // split interval
        struct ival * const i =
            make_ival(splay_root(d)->lo, splay_root(d)->c, splay_root(d)->t);
        d->cnt++;
        i->hi = n - 1;
        splay_root(d)->lo = n + 1;
        splay_left(i, node) = splay_left(splay_root(d), node);
        splay_left(splay_root(d), node) = 0;
        splay_right(i, node) = splay_root(d);
        splay_root(d) = i;
    }
}
/// Remove integer @p n from the intervals stored in diet tree @p t.
///
/// @param      d     Diet tree.
/// @param[in]  n     Integer.
///
Remove integer @p n from the intervals stored in diet tree @p t.
Remove integer @p n from the intervals stored in diet tree @p t .
void diet_remove(struct diet * const d, const uint64_t n)
{
    diet_find(d, n);
    if (n < splay_root(d)->lo || n > splay_root(d)->hi)
        return;
    if (n == splay_root(d)->lo) {
        if (n == splay_root(d)->hi) {
            free(splay_remove(diet, d, splay_root(d)));
            d->cnt--;
        } else
            splay_root(d)->lo++;
    } else if (n == splay_root(d)->hi) {
        splay_root(d)->hi--;
    } else {
        struct ival * const i =
            make_ival(splay_root(d)->lo, splay_root(d)->c, splay_root(d)->t);
        d->cnt++;
        i->hi = n - 1;
        splay_root(d)->lo = n + 1;
        splay_left(i, node) = splay_left(splay_root(d), node);
        splay_left(splay_root(d), node) = 0;
        splay_right(i, node) = splay_root(d);
        splay_root(d) = i;
    }
}
void diet_remove ( struct diet * const d , const uint64_t n ) { diet_find ( d , n ) ; if ( n < splay_root ( d ) -> lo || n > splay_root ( d ) -> hi ) return ; if ( n == splay_root ( d ) -> lo ) { if ( n == splay_root ( d ) -> hi ) { free ( splay_remove ( diet , d , splay_root ( d ) ) ) ; d -> cnt -- ; } else splay_root ( d ) -> lo ++ ; } else if ( n == splay_root ( d ) -> hi ) { splay_root ( d ) -> hi -- ; } else { struct ival * const i = make_ival ( splay_root ( d ) -> lo , splay_root ( d ) -> c , splay_root ( d ) -> t ) ; d -> cnt ++ ; i -> hi = n - 1 ; splay_root ( d ) -> lo = n + 1 ; splay_left ( i , node ) = splay_left ( splay_root ( d ) , node ) ; splay_left ( splay_root ( d ) , node ) = 0 ; splay_right ( i , node ) = splay_root ( d ) ; splay_root ( d ) = i ; } }
Remove integer @p n from the intervals stored in diet tree @p t.
Remove integer @p n from the intervals stored in diet tree @p t .
// rotate the interval that contains n or is closest to it to the top // adjust lo bound // adjust hi bound // split interval