From a3bbc8adeceb883ba479c6287d819b91f3aae521 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Tue, 4 May 2004 22:31:57 +0000 Subject: [PATCH] Update substr indexing macros to better separate initial/final string settings from any string settings. --- servers/slapd/schema_init.c | 88 ++++++++++++++++++------------------- servers/slapd/slap.h | 18 ++++++-- 2 files changed, 59 insertions(+), 47 deletions(-) diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index ae59168b88..963cc69c95 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -405,31 +405,27 @@ octetStringSubstringsIndexer( for( i=0; values[i].bv_val != NULL; i++ ) { /* count number of indices to generate */ - if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) { - continue; - } - if( flags & SLAP_INDEX_SUBSTR_INITIAL ) { - if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) { - nkeys += SLAP_INDEX_SUBSTR_MAXLEN - - (SLAP_INDEX_SUBSTR_MINLEN - 1); - } else { - nkeys += values[i].bv_len - (SLAP_INDEX_SUBSTR_MINLEN - 1); + if( values[i].bv_len >= SLAP_INDEX_SUBSTR_IF_MAXLEN ) { + nkeys += SLAP_INDEX_SUBSTR_IF_MAXLEN - + (SLAP_INDEX_SUBSTR_IF_MINLEN - 1); + } else if( values[i].bv_len >= SLAP_INDEX_SUBSTR_IF_MINLEN ) { + nkeys += values[i].bv_len - (SLAP_INDEX_SUBSTR_IF_MINLEN - 1); } } if( flags & SLAP_INDEX_SUBSTR_ANY ) { - if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) { - nkeys += values[i].bv_len - (SLAP_INDEX_SUBSTR_MAXLEN - 1); + if( values[i].bv_len >= SLAP_INDEX_SUBSTR_ANY_LEN ) { + nkeys += values[i].bv_len - (SLAP_INDEX_SUBSTR_ANY_LEN - 1); } } if( flags & SLAP_INDEX_SUBSTR_FINAL ) { - if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) { - nkeys += SLAP_INDEX_SUBSTR_MAXLEN - - ( SLAP_INDEX_SUBSTR_MINLEN - 1); - } else { - nkeys += values[i].bv_len - (SLAP_INDEX_SUBSTR_MINLEN - 1); + if( values[i].bv_len >= SLAP_INDEX_SUBSTR_IF_MAXLEN ) { + nkeys += SLAP_INDEX_SUBSTR_IF_MAXLEN - + ( SLAP_INDEX_SUBSTR_IF_MINLEN - 1); + } else if( values[i].bv_len >= SLAP_INDEX_SUBSTR_IF_MINLEN ) { + nkeys += values[i].bv_len - (SLAP_INDEX_SUBSTR_IF_MINLEN - 1); } } } @@ -449,13 +445,11 @@ octetStringSubstringsIndexer( for( i=0; values[i].bv_val != NULL; i++ ) { ber_len_t j,max; - if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue; - if( ( flags & SLAP_INDEX_SUBSTR_ANY ) && - ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) ) + ( values[i].bv_len >= SLAP_INDEX_SUBSTR_ANY_LEN ) ) { char pre = SLAP_INDEX_SUBSTR_PREFIX; - max = values[i].bv_len - (SLAP_INDEX_SUBSTR_MAXLEN - 1); + max = values[i].bv_len - (SLAP_INDEX_SUBSTR_ANY_LEN - 1); for( j=0; jsmr_oid, mlen ); HASH_Update( &HASHcontext, (unsigned char *)&values[i].bv_val[j], - SLAP_INDEX_SUBSTR_MAXLEN ); + SLAP_INDEX_SUBSTR_ANY_LEN ); HASH_Final( HASHdigest, &HASHcontext ); ber_dupbv_x( &keys[nkeys++], &digest, ctx ); } } - max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len - ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len; + /* skip if too short */ + if( values[i].bv_len < SLAP_INDEX_SUBSTR_IF_MINLEN ) continue; + + max = SLAP_INDEX_SUBSTR_IF_MAXLEN < values[i].bv_len + ? SLAP_INDEX_SUBSTR_IF_MAXLEN : values[i].bv_len; - for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) { + for( j=SLAP_INDEX_SUBSTR_IF_MINLEN; j<=max; j++ ) { char pre; if( flags & SLAP_INDEX_SUBSTR_INITIAL ) { @@ -526,7 +523,6 @@ octetStringSubstringsIndexer( } } - } if( nkeys > 0 ) { @@ -563,8 +559,9 @@ octetStringSubstringsFilter ( sa = (SubstringsAssertion *) assertedValue; - if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL - && sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN ) + if( flags & SLAP_INDEX_SUBSTR_INITIAL && + sa->sa_initial.bv_val != NULL && + sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_IF_MINLEN ) { nkeys++; } @@ -572,16 +569,17 @@ octetStringSubstringsFilter ( if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) { ber_len_t i; for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) { - if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) { - /* don't bother accounting for stepping */ + if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_ANY_LEN ) { + /* don't bother accounting with stepping */ nkeys += sa->sa_any[i].bv_len - - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 ); + ( SLAP_INDEX_SUBSTR_ANY_LEN - 1 ); } } } - if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL && - sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN ) + if( flags & SLAP_INDEX_SUBSTR_FINAL && + sa->sa_final.bv_val != NULL && + sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_IF_MINLEN ) { nkeys++; } @@ -600,14 +598,15 @@ octetStringSubstringsFilter ( keys = slap_sl_malloc( sizeof( struct berval ) * (nkeys+1), ctx ); nkeys = 0; - if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL && - sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN ) + if( flags & SLAP_INDEX_SUBSTR_INITIAL && + sa->sa_initial.bv_val != NULL && + sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_IF_MINLEN ) { pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX; value = &sa->sa_initial; - klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len - ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len; + klen = SLAP_INDEX_SUBSTR_IF_MAXLEN < value->bv_len + ? SLAP_INDEX_SUBSTR_IF_MAXLEN : value->bv_len; HASH_Init( &HASHcontext ); if( prefix != NULL && prefix->bv_len > 0 ) { @@ -630,18 +629,18 @@ octetStringSubstringsFilter ( if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) { ber_len_t i, j; pre = SLAP_INDEX_SUBSTR_PREFIX; - klen = SLAP_INDEX_SUBSTR_MAXLEN; + klen = SLAP_INDEX_SUBSTR_ANY_LEN; for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) { - if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) { + if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_ANY_LEN ) { continue; } value = &sa->sa_any[i]; for(j=0; - j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN; - j += SLAP_INDEX_SUBSTR_STEP ) + j <= value->bv_len - SLAP_INDEX_SUBSTR_ANY_LEN; + j += SLAP_INDEX_SUBSTR_ANY_STEP ) { HASH_Init( &HASHcontext ); if( prefix != NULL && prefix->bv_len > 0 ) { @@ -663,14 +662,15 @@ octetStringSubstringsFilter ( } } - if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL && - sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN ) + if( flags & SLAP_INDEX_SUBSTR_FINAL && + sa->sa_final.bv_val != NULL && + sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_IF_MINLEN ) { pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX; value = &sa->sa_final; - klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len - ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len; + klen = SLAP_INDEX_SUBSTR_IF_MAXLEN < value->bv_len + ? SLAP_INDEX_SUBSTR_IF_MAXLEN : value->bv_len; HASH_Init( &HASHcontext ); if( prefix != NULL && prefix->bv_len > 0 ) { diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 1c0bf3175c..3ea9dc2462 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -225,9 +225,21 @@ typedef struct slap_ssf_set { | SLAP_INDEX_SUBSTR_ANY \ | SLAP_INDEX_SUBSTR_FINAL ) -#define SLAP_INDEX_SUBSTR_MINLEN 2 -#define SLAP_INDEX_SUBSTR_MAXLEN 4 -#define SLAP_INDEX_SUBSTR_STEP 2 +/* constants for initial/final substrings indices */ +#ifndef SLAP_INDEX_SUBSTR_IF_MINLEN +# define SLAP_INDEX_SUBSTR_IF_MINLEN 2 +#endif +#ifndef SLAP_INDEX_SUBSTR_IF_MAXLEN +# define SLAP_INDEX_SUBSTR_IF_MAXLEN 4 +#endif + +/* constants for any substrings indices */ +#ifndef SLAP_INDEX_SUBSTR_ANY_LEN +# define SLAP_INDEX_SUBSTR_ANY_LEN 4 +#endif +#ifndef SLAP_INDEX_SUBSTR_ANY_STEP +# define SLAP_INDEX_SUBSTR_ANY_STEP 2 +#endif #define SLAP_INDEX_FLAGS 0xF000UL #define SLAP_INDEX_NOSUBTYPES 0x1000UL /* don't use index w/ subtypes */ -- 2.39.5