From 077c47c2a6a56639b43a014f86592f5cbe23798c Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Tue, 26 Sep 2000 22:22:42 +0000 Subject: [PATCH] replace ALLIDS with RANGE IDLs --- servers/slapd/back-bdb/back-bdb.h | 3 ++- servers/slapd/back-bdb/backbdb.dsp | 4 ++++ servers/slapd/back-bdb/idl.c | 36 +++++++++++++++++++++--------- servers/slapd/back-bdb/proto-bdb.h | 2 +- servers/slapd/back-bdb/search.c | 15 ++++++++----- 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 7859119d81..c9fa58d905 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -23,7 +23,8 @@ LDAP_BEGIN_DECL #define BDB_IDL_MAX (BDB_IDL_DB_SIZE-32) /* #define BDB_IDL_DB_ALLOC (BDB_IDL_DB_SIZE * sizeof(ID)) */ -#define BDB_IS_ALLIDS(ids) ((ids)[0] == NOID) +#define BDB_IDL_RANGE_SIZE (3 * sizeof(ID)) +#define BDB_IDL_IS_RANGE(ids) ((ids)[0] == NOID) #define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX #define DN_ONE_PREFIX '%' diff --git a/servers/slapd/back-bdb/backbdb.dsp b/servers/slapd/back-bdb/backbdb.dsp index 968c4c710c..49b043fc9d 100644 --- a/servers/slapd/back-bdb/backbdb.dsp +++ b/servers/slapd/back-bdb/backbdb.dsp @@ -187,6 +187,10 @@ SOURCE=".\proto-bdb.h" # End Source File # Begin Source File +SOURCE=.\referral.c +# End Source File +# Begin Source File + SOURCE=.\search.c # End Source File # Begin Source File diff --git a/servers/slapd/back-bdb/idl.c b/servers/slapd/back-bdb/idl.c index eff46e62fd..16146d12e5 100644 --- a/servers/slapd/back-bdb/idl.c +++ b/servers/slapd/back-bdb/idl.c @@ -14,7 +14,7 @@ #define IDL_CMP(x,y) ( x < y ? -1 : ( x > y ? 1 : 0 ) ) -int bdb_idl_search( ID *ids, ID id ) +unsigned bdb_idl_search( ID *ids, ID id ) { #if BDB_IDL_BINARY_SEARCH /* @@ -22,10 +22,10 @@ int bdb_idl_search( ID *ids, ID id ) * if found, returns position of id * if not found, returns first postion greater than id */ - int base = 0; - int cursor = 0; + unsigned base = 0; + unsigned cursor = 0; int val; - int n = ids[0]; + unsigned n = ids[0]; while( 0 < n ) { int pivot = n >> 1; @@ -64,7 +64,7 @@ int bdb_idl_search( ID *ids, ID id ) static int idl_insert( ID *ids, ID id ) { - int x = bdb_idl_search( ids, id ); + unsigned x = bdb_idl_search( ids, id ); assert( x > 0 ); @@ -79,6 +79,14 @@ static int idl_insert( ID *ids, ID id ) } if ( ++ids[0] >= BDB_IDL_DB_MAX ) { + if( id < ids[1] ) { + ids[1] = id; + ids[2] = ids[ids[0]-1]; + } else if ( ids[ids[0]-1] < id ) { + ids[2] = id; + } else { + ids[2] = ids[ids[0]-1]; + } ids[0] = NOID; } else { @@ -93,7 +101,7 @@ static int idl_insert( ID *ids, ID id ) static int idl_delete( ID *ids, ID id ) { - int x = bdb_idl_search( ids, id ); + unsigned x = bdb_idl_search( ids, id ); assert( x > 0 ); @@ -162,8 +170,14 @@ bdb_idl_insert_key( (long) sizeof( ID ), (long) data.size, 0 ); return -1; - } else if ( BDB_IS_ALLIDS(ids) ) { - return 0; + } else if ( BDB_IDL_IS_RANGE(ids) ) { + if( id < ids[1] ) { + ids[1] = id; + } else if ( ids[2] > id ) { + ids[2] = id; + } else { + return 0; + } } else if ( data.size != (1 + ids[0]) * sizeof( ID ) ) { /* size mismatch */ @@ -182,8 +196,8 @@ bdb_idl_insert_key( return rc; } - if( BDB_IS_ALLIDS( ids ) ) { - data.size = sizeof( ID ); + if( BDB_IDL_IS_RANGE( ids ) ) { + data.size = BDB_IDL_RANGE_SIZE; } else { data.size = (ids[0]+1) * sizeof( ID ); } @@ -239,7 +253,7 @@ bdb_idl_delete_key( (long) sizeof( ID ), (long) data.size, 0 ); return -1; - } else if ( BDB_IS_ALLIDS(ids) ) { + } else if ( BDB_IDL_IS_RANGE(ids) ) { return 0; } else if ( data.size != (1 + ids[0]) * sizeof( ID ) ) { diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index d64ce7c172..111b51685d 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -102,7 +102,7 @@ int bdb_id2entry( /* * idl.c */ -int bdb_idl_search( ID *ids, ID id ); +unsigned bdb_idl_search( ID *ids, ID id ); int bdb_idl_insert_key( BackendDB *be, diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index a4687be401..7c748142fb 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -381,7 +381,11 @@ static int search_candidates( Debug(LDAP_DEBUG_TRACE, "subtree_candidates: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id, 0); + /* return a RANGE IDL for now */ ids[0] = NOID; + ids[1] = e->e_id; + ids[2] = e->e_id+128; + return 0; } @@ -394,9 +398,10 @@ static ID idl_first( ID *ids, ID *cursor ) return NOID; } - if ( BDB_IS_ALLIDS( ids ) ) { - /* XXYYZ: quick hack for testing */ - ids[1] = 100; + if ( BDB_IDL_IS_RANGE( ids ) ) { + if( *cursor < ids[1] ) { + *cursor = ids[1]; + } return *cursor; } @@ -412,8 +417,8 @@ static ID idl_first( ID *ids, ID *cursor ) static ID idl_next( ID *ids, ID *cursor ) { - if ( BDB_IS_ALLIDS( ids ) ) { - if( ++(*cursor) <= ids[1] ) { + if ( BDB_IDL_IS_RANGE( ids ) ) { + if( ids[2] <= ++(*cursor) ) { return *cursor; } return NOID; -- 2.39.2