#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 '%'
#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
/*
* 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;
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 );
}
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 {
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 );
(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 */
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 );
}
(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 ) ) {
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;
}
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;
}
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;