Data-RadixTree-Shared

 view release on metacpan or  search on metacpan

radix.h  view on Meta::CPAN

 * Append-only: existing bytes never move, so pointers into the arena stay
 * valid across appends.  The caller pre-checked that len bytes fit. */
static inline uint32_t rdx_arena_append(RdxHandle *h, const uint8_t *bytes, uint32_t len) {
    RdxHeader *hdr = h->hdr;
    uint32_t off = hdr->arena_used;
    if (len) memcpy(rdx_arena(h) + off, bytes, len);
    hdr->arena_used += len;
    return off;
}

/* Worst case any single insert consumes: up to 2 new nodes (a split makes a
 * mid node + a leaf node) and up to klen arena bytes (the leaf's label).
 * v1 has no freelist, so the 2 nodes must come fresh from the high-water mark.
 * Returns 1 if both fit, 0 otherwise.  Caller holds the write lock. */
static inline int rdx_insert_has_room(RdxHandle *h, uint32_t klen) {
    RdxHeader *hdr = h->hdr;
    if (hdr->node_cap - hdr->node_used < 2) return 0;
    if (hdr->arena_cap - hdr->arena_used < klen) return 0;
    return 1;
}



( run in 2.120 seconds using v1.01-cache-2.11-cpan-7fcb06a456a )