From: Kurt Zeilenga Date: Sat, 7 Aug 1999 21:14:24 +0000 (+0000) Subject: Use a cursor to step through ID_BLOCKS. X-Git-Tag: TWEB_OL_BASE~254 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=136bb9c2319a2f45dcce1011a8e53dec6b4ff999;p=openldap Use a cursor to step through ID_BLOCKS. --- diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index 688f055b05..1cdad6be93 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -25,7 +25,7 @@ LDAP_BEGIN_DECL #define SUBLEN 3 /* - * there is a single index for each attribute. these prefixes insure + * there is a single index for each attribute. these prefixes ensure * that there is no collision among keys. */ #define EQ_PREFIX '=' /* prefix for equality keys */ @@ -116,7 +116,7 @@ typedef struct ldbm_attrinfo { */ } AttrInfo; -#define MAXDBCACHE 10 +#define MAXDBCACHE 16 /* this could be made an option */ #ifndef SLAPD_NEXTID_CHUNK diff --git a/servers/slapd/back-ldbm/idl.c b/servers/slapd/back-ldbm/idl.c index 0afef23333..670c608a54 100644 --- a/servers/slapd/back-ldbm/idl.c +++ b/servers/slapd/back-ldbm/idl.c @@ -1004,10 +1004,14 @@ idl_notin( * NIDS > 1 return 1 * otherwise return NOID * otherwise return first ID + * + * cursor is set to 1 */ ID -idl_firstid( ID_BLOCK *idl ) +idl_firstid( ID_BLOCK *idl, ID *cursor ) { + *cursor = 1; + if ( idl == NULL || ID_BLOCK_NIDS(idl) == 0 ) { return( NOID ); } @@ -1019,28 +1023,29 @@ idl_firstid( ID_BLOCK *idl ) return( ID_BLOCK_ID(idl, 0) ); } -/* return next ID after id - * if ALLIDS block, increment id. +/* return next ID + * if ALLIDS block, cursor is id. + * increment id * if id < NIDS return id * otherwise NOID. - * otherwise SEARCH for next id (ugh!) + * otherwise cursor is index into block + * if index < nids + * return id at index then increment */ ID -idl_nextid( ID_BLOCK *idl, ID id ) +idl_nextid( ID_BLOCK *idl, ID *cursor ) { - unsigned int i; - if ( ID_BLOCK_ALLIDS( idl ) ) { - return( ++id < ID_BLOCK_NIDS(idl) ? id : NOID ); + if( ++(*cursor) < ID_BLOCK_NIDS(idl) ) { + return *cursor; + } else { + return NOID; + } } - for ( i = 0; i < ID_BLOCK_NIDS(idl) && ID_BLOCK_ID(idl, i) <= id; i++ ) { - ; /* NULL */ + if ( *cursor < ID_BLOCK_NIDS(idl) ) { + return( ID_BLOCK_ID(idl, (*cursor)++) ); } - if ( i >= ID_BLOCK_NIDS(idl) ) { - return( NOID ); - } else { - return( ID_BLOCK_ID(idl, i) ); - } + return( NOID ); } diff --git a/servers/slapd/back-ldbm/proto-back-ldbm.h b/servers/slapd/back-ldbm/proto-back-ldbm.h index e8732bb0fc..8275b03752 100644 --- a/servers/slapd/back-ldbm/proto-back-ldbm.h +++ b/servers/slapd/back-ldbm/proto-back-ldbm.h @@ -126,8 +126,8 @@ int idl_delete_key LDAP_P(( Backend *be, DBCache *db, Datum key, ID id )); ID_BLOCK * idl_intersection LDAP_P(( Backend *be, ID_BLOCK *a, ID_BLOCK *b )); ID_BLOCK * idl_union LDAP_P(( Backend *be, ID_BLOCK *a, ID_BLOCK *b )); ID_BLOCK * idl_notin LDAP_P(( Backend *be, ID_BLOCK *a, ID_BLOCK *b )); -ID idl_firstid LDAP_P(( ID_BLOCK *idl )); -ID idl_nextid LDAP_P(( ID_BLOCK *idl, ID id )); +ID idl_firstid LDAP_P(( ID_BLOCK *idl, ID *cursor )); +ID idl_nextid LDAP_P(( ID_BLOCK *idl, ID *cursor )); /* * index.c diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index aaefcd3f12..9589c2fd9c 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -44,7 +44,7 @@ ldbm_back_search( char *text; time_t stoptime; ID_BLOCK *candidates; - ID id; + ID id, cursor; Entry *e; struct berval **v2refs = NULL; Entry *matched = NULL; @@ -151,8 +151,8 @@ ldbm_back_search( goto done; } - for ( id = idl_firstid( candidates ); id != NOID; - id = idl_nextid( candidates, id ) ) + for ( id = idl_firstid( candidates, &cursor ); id != NOID; + id = idl_nextid( candidates, &cursor ) ) { int scopeok = 0; diff --git a/servers/slapd/tools/ldbmtest.c b/servers/slapd/tools/ldbmtest.c index a1c0282290..fb058df05b 100644 --- a/servers/slapd/tools/ldbmtest.c +++ b/servers/slapd/tools/ldbmtest.c @@ -51,7 +51,7 @@ main( int argc, char **argv ) char buf[256]; Datum savekey, key, data, last; char *fname; - ID id; + ID id, cursor; ID_BLOCK *idl; Backend *tbe; int i; @@ -279,8 +279,8 @@ main( int argc, char **argv ) get_keydata( stdin, buf[1], &key, &data ); idl = (ID_BLOCK *) data.dptr; - for ( id = idl_firstid( idl ); id != NOID; - id = idl_nextid( idl, id ) ) { + for ( id = idl_firstid( idl, &cursor ); id != NOID; + id = idl_nextid( idl, &cursor ) ) { if ( idl_insert_key( be, dbc, key, id ) != 0 ) { fprintf( stderr,