third-party/CART/cart.cpp
static int prefix_mismatch(const cart_node *n, const unsigned char *key, int key_len, int depth) {
    int max_cmp = min(min(MAX_PREFIX_LEN, n->partial_len), key_len - depth);
    int idx;
    for (idx=0; idx < max_cmp; idx++) {
        if (n->partial[idx] != key[depth+idx])
            return idx;
    }

    // If the prefix is short we can avoid finding a leaf
    if (n->partial_len > MAX_PREFIX_LEN) {
        // Prefix is longer than what we've checked, find a leaf
        cart_leaf *l = minimum(n);
        max_cmp = min(l->key_len, key_len)- depth;
        for (; idx < max_cmp; idx++) {
            if (l->key[idx+depth] != key[depth+idx])
                return idx;
        }
    }
    return idx;
}
/**
 * Calculates the index at which the prefixes mismatch
 */
Calculates the index at which the prefixes mismatch
Calculates the index at which the prefixes mismatch
static int prefix_mismatch(const cart_node *n, const unsigned char *key, int key_len, int depth) {
    int max_cmp = min(min(MAX_PREFIX_LEN, n->partial_len), key_len - depth);
    int idx;
    for (idx=0; idx < max_cmp; idx++) {
        if (n->partial[idx] != key[depth+idx])
            return idx;
    }
    if (n->partial_len > MAX_PREFIX_LEN) {
        cart_leaf *l = minimum(n);
        max_cmp = min(l->key_len, key_len)- depth;
        for (; idx < max_cmp; idx++) {
            if (l->key[idx+depth] != key[depth+idx])
                return idx;
        }
    }
    return idx;
}
static int prefix_mismatch ( const cart_node * n , const unsigned char * key , int key_len , int depth ) { int max_cmp = min ( min ( MAX_PREFIX_LEN , n -> partial_len ) , key_len - depth ) ; int idx ; for ( idx = 0 ; idx < max_cmp ; idx ++ ) { if ( n -> partial [ idx ] != key [ depth + idx ] ) return idx ; } if ( n -> partial_len > MAX_PREFIX_LEN ) { cart_leaf * l = minimum ( n ) ; max_cmp = min ( l -> key_len , key_len ) - depth ; for ( ; idx < max_cmp ; idx ++ ) { if ( l -> key [ idx + depth ] != key [ depth + idx ] ) return idx ; } } return idx ; }
Calculates the index at which the prefixes mismatch
Calculates the index at which the prefixes mismatch
// If the prefix is short we can avoid finding a leaf // Prefix is longer than what we've checked, find a leaf