pike.git / src / post_modules / CritBit / tree_low.c

version» Context lines:

pike.git/src/post_modules/CritBit/tree_low.c:89:   static inline cb_node_t node_init() {    cb_node_t tree;       tree = CB_NODE_ALLOC();    memset(tree, 0, sizeof(cb_node));    CB_INIT_VALUE(tree);       return tree;   }    - CB_STATIC CB_INLINE void cb_get_range(const struct cb_tree * src, + CB_STATIC inline void cb_get_range(const struct cb_tree * src,    struct cb_tree * dst,    const cb_key a, const cb_key b) {    const cb_node_t tree = src->root;    cb_node_t node = cb_index(tree, a);    cb_node_t end = cb_index(tree, b);    /* printf("start: %p, stop: %p in line %d\n", node, end, __LINE__); */    if (!node) node = cb_find_next(tree, a);    /* printf("start: %p, stop: %p in line %d\n", node, end, __LINE__); */    if (node) {   
pike.git/src/post_modules/CritBit/tree_low.c:168:    CB_ADD_KEY_REF(node->key);    CB_INIT_VALUE(node);    CB_SET_CHILD(nnode, 0, CB_CHILD(nnode, 0));    CB_SET_CHILD(nnode, 1, CB_CHILD(nnode, 1));    CB_SET_CHILD(node, 0, NULL);    CB_SET_CHILD(node, 1, NULL);       return nnode;   }    - CB_STATIC CB_INLINE void cb_copy_tree(struct cb_tree * dst, + CB_STATIC inline void cb_copy_tree(struct cb_tree * dst,    cb_node_t from) {       cb_node_t parent;    cb_node_t node = from;       if (!from) return;       parent = from->parent;    from->parent = NULL;   
pike.git/src/post_modules/CritBit/tree_low.c:212:    cb_zap_node(tree, node);   }      static inline void cb_zap_node(const struct cb_tree * UNUSED(tree),    cb_node_t node) {    CB_FREE_KEY(node->key);    CB_RM_VALUE(node);    CB_NODE_FREE(node);   }    - CB_STATIC CB_INLINE cb_node_t cb_find_first(cb_node_t tree) { + CB_STATIC inline cb_node_t cb_find_first(cb_node_t tree) {    while (tree && !CB_HAS_VALUE(tree)) { tree = CB_CHILD(tree, 0); };       return tree;   }    - CB_STATIC CB_INLINE cb_node_t cb_find_last(cb_node_t tree) { + CB_STATIC inline cb_node_t cb_find_last(cb_node_t tree) {    while (1) {    if (CB_HAS_CHILD(tree, 1)) tree = CB_CHILD(tree, 1);    else if (CB_HAS_CHILD(tree, 0)) tree = CB_CHILD(tree, 0);    else break;    }    return tree;   }    - CB_STATIC CB_INLINE size_t cb_get_depth(cb_node_t node) { + CB_STATIC inline size_t cb_get_depth(cb_node_t node) {    size_t a = 0, b = 0, len = 1;       if (CB_HAS_CHILD(node, 0)) {    a = cb_get_depth(CB_CHILD(node, 0));    }       if (CB_HAS_CHILD(node, 1)) {    b = cb_get_depth(CB_CHILD(node, 1));    }       return len + MAX(b, a);   }    - CB_STATIC CB_INLINE cb_node_t cb_subtree_prefix(cb_node_t node, cb_key key) { + CB_STATIC inline cb_node_t cb_subtree_prefix(cb_node_t node, cb_key key) {    cb_size start = {0,0};       do {    unsigned INT32 bit;    start = cb_prefix_count(node->key.str, key.str,    CB_MIN(node->key.len, key.len), start);       if (CB_S_EQ(start, key.len)) { /* key is substring */    return node;    }       bit = CB_GET_BIT(key.str, start);    node = CB_CHILD(node, bit);    } while (node);       return NULL;   }    - CB_STATIC CB_INLINE void cb_delete(struct cb_tree * tree, + CB_STATIC inline void cb_delete(struct cb_tree * tree,    const cb_key key, cb_value * val) {    cb_node_t node = cb_index(tree->root, key);       if (node && CB_HAS_VALUE(node)) {    unsigned INT32 bit;    cb_node_t t;    if (val) CB_GET_VALUE(node, val);       CB_RM_VALUE(node);    node->size--;
pike.git/src/post_modules/CritBit/tree_low.c:324:    tree->root = NULL;    return;    }    }       }       cb_check_node(tree->root);   }    - CB_STATIC CB_INLINE cb_node_t cb_index(const cb_node_t tree, const cb_key key) { + CB_STATIC inline cb_node_t cb_index(const cb_node_t tree, const cb_key key) {    cb_node_t node = tree;    if (tree) cb_check_node(tree);       while (node) {    if (CB_LT(node->key.len, key.len)) {    unsigned INT32 bit = CB_GET_BIT(key.str, node->key.len);       if (CB_HAS_CHILD(node, bit)) {    node = CB_CHILD(node, bit);    continue;
pike.git/src/post_modules/CritBit/tree_low.c:350:    return node;    }       break;    }       if (tree) cb_check_node(tree);    return NULL;   }    - CB_STATIC CB_INLINE cb_node_t cb_find_next(const cb_node_t tree, + CB_STATIC inline cb_node_t cb_find_next(const cb_node_t tree,    const cb_key key) {    cb_size size;    size_t bit;    cb_node_t node;    size.bits = size.chars = 0;       /* index is cheap. also in many cases its quite likely that we */    /* hit. */    node = cb_index(tree, key);   
pike.git/src/post_modules/CritBit/tree_low.c:433:    break;    }       if (node && !CB_HAS_VALUE(node))    WALK_FORWARD(node, {    if (CB_HAS_VALUE(_)) break;    });    return node;   }    - CB_STATIC CB_INLINE cb_node_t cb_find_ne(const cb_node_t tree, const cb_key key) { + CB_STATIC inline cb_node_t cb_find_ne(const cb_node_t tree, const cb_key key) {    cb_node_t ne = cb_index(tree, key);    if (!ne) ne = cb_find_next(tree, key);    return ne;   }    - CB_STATIC CB_INLINE cb_node_t cb_get_nth(const cb_node_t tree, size_t n) { + CB_STATIC inline cb_node_t cb_get_nth(const cb_node_t tree, size_t n) {    cb_node_t node = tree;    size_t ln;       while (node) {    if (n >= node->size) return NULL;       if (n == 0) return cb_find_first(node);    else if (n == node->size - 1) return cb_find_last(node);       if (CB_HAS_VALUE(node)) n--;
pike.git/src/post_modules/CritBit/tree_low.c:466:    }    n -= ln;    }       node = CB_CHILD(node, 1);    }       return NULL;   }    - CB_STATIC CB_INLINE cb_node_t cb_find_previous(const cb_node_t tree, + CB_STATIC inline cb_node_t cb_find_previous(const cb_node_t tree,    const cb_key key) {    cb_node_t node = cb_index(tree, key);    if (!node) node = cb_find_next(tree, key);    if (!node) return cb_find_last(tree);    if (node) WALK_BACKWARD(node, {    if (CB_HAS_VALUE(_)) break;    });    return node;   }    - CB_STATIC CB_INLINE cb_node_t cb_find_le(const cb_node_t tree, const cb_key key) { + CB_STATIC inline cb_node_t cb_find_le(const cb_node_t tree, const cb_key key) {    cb_node_t ne = cb_index(tree, key);    if (!ne) ne = cb_find_previous(tree, key);    return ne;   }      static inline int cb_low_insert(struct cb_tree * tree,    const cb_key key, const cb_value *val) {    cb_node_t node = tree->root;    cb_size size;    size.bits = 0;
pike.git/src/post_modules/CritBit/tree_low.c:564:    node->key.len = size;    bit = CB_GET_BIT(key.str, size);    CB_SET_CHILD(node, bit, cb_node_from_string(tree, key, val));    CB_SET_CHILD(node, !bit, new);    CB_RM_VALUE(node); /* do not free here, clone does take ref */       return 1;    }   }    - CB_STATIC CB_INLINE void cb_insert(struct cb_tree * tree, + CB_STATIC inline void cb_insert(struct cb_tree * tree,    const cb_key key,    const cb_value *val) {    if (!tree->root) {    tree->root = cb_node_from_string(tree, key, val);    return;    }       cb_check_node(tree->root);       cb_low_insert(tree, key, val);       cb_check_node(tree->root);   }