Use a cursor to step through ID_BLOCKS.

This commit is contained in:
Kurt Zeilenga 1999-08-07 21:14:24 +00:00
parent eb328624bf
commit 136bb9c231
5 changed files with 30 additions and 25 deletions

View file

@ -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

View file

@ -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 );
}

View file

@ -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

View file

@ -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;

View file

@ -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,