third-party/CART/cart.cpp
void* cart_search(const cart_tree *t, const unsigned char *key, int key_len) {
    cart_node **child;
    cart_node *n = t->root;
    int prefix_len, depth = 0;
    while (n) {
        // Might be a leaf
        if (IS_LEAF(n)) {
            n = (cart_node*)LEAF_RAW(n);
            // Check if the expanded path matches
            if (!leaf_matches((cart_leaf*)n, key, key_len, depth)) {
                return ((cart_leaf*)n)->value;
            }
            return NULL;
        }

        // Bail if the prefix does not match
        if (n->partial_len) {
            prefix_len = check_prefix(n, key, key_len, depth);
            if (prefix_len != min(MAX_PREFIX_LEN, n->partial_len))
                return NULL;
            depth = depth + n->partial_len;
        }

        // Recursively search
        child = find_child(n, key[depth]);
        n = (child) ? *child : NULL;
        depth++;
    }
    return NULL;
}
/**
 * Searches for a value in the cart tree
 * @arg t The tree
 * @arg key The key
 * @arg key_len The length of the key
 * @return NULL if the item was not found, otherwise
 * the value pointer is returned.
 */
Searches for a value in the cart tree
@arg t The tree
@arg key The key
@arg key_len The length of the key
@return NULL if the item was not found, otherwise
the value pointer is returned.
Searches for a value in the cart tree @arg t The tree @arg key The key @arg key_len The length of the key @return NULL if the item was not found otherwise the value pointer is returned .
void* cart_search(const cart_tree *t, const unsigned char *key, int key_len) {
    cart_node **child;
    cart_node *n = t->root;
    int prefix_len, depth = 0;
    while (n) {
        if (IS_LEAF(n)) {
            n = (cart_node*)LEAF_RAW(n);
            if (!leaf_matches((cart_leaf*)n, key, key_len, depth)) {
                return ((cart_leaf*)n)->value;
            }
            return NULL;
        }
        if (n->partial_len) {
            prefix_len = check_prefix(n, key, key_len, depth);
            if (prefix_len != min(MAX_PREFIX_LEN, n->partial_len))
                return NULL;
            depth = depth + n->partial_len;
        }
        child = find_child(n, key[depth]);
        n = (child) ? *child : NULL;
        depth++;
    }
    return NULL;
}
void * cart_search ( const cart_tree * t , const unsigned char * key , int key_len ) { cart_node * * child ; cart_node * n = t -> root ; int prefix_len , depth = 0 ; while ( n ) { if ( IS_LEAF ( n ) ) { n = ( cart_node * ) LEAF_RAW ( n ) ; if ( ! leaf_matches ( ( cart_leaf * ) n , key , key_len , depth ) ) { return ( ( cart_leaf * ) n ) -> value ; } return NULL ; } if ( n -> partial_len ) { prefix_len = check_prefix ( n , key , key_len , depth ) ; if ( prefix_len != min ( MAX_PREFIX_LEN , n -> partial_len ) ) return NULL ; depth = depth + n -> partial_len ; } child = find_child ( n , key [ depth ] ) ; n = ( child ) ? * child : NULL ; depth ++ ; } return NULL ; }
Searches for a value in the cart tree
 @arg t The tree
 @arg key The key
 @arg key_len The length of the key
 @return NULL if the item was not found, otherwise
 the value pointer is returned.
Searches for a value in the cart tree @arg t The tree @arg key The key @arg key_len The length of the key @return NULL if the item was not found otherwise the value pointer is returned .
// Might be a leaf // Check if the expanded path matches // Bail if the prefix does not match // Recursively search