* a big id list containing all the ids, which we will return.
*/
+#ifndef USE_INDIRECT_NIDS
/* count the number of blocks & allocate space for pointers to them */
for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ )
; /* NULL */
+#else
+ i = ID_BLOCK_NIDS(idl);
+#endif
tmp = (ID_BLOCK **) ch_malloc( (i + 1) * sizeof(ID_BLOCK *) );
/* read in all the blocks */
cont_alloc( &data, &key );
nids = 0;
+#ifndef USE_INDIRECT_NIDS
for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
+#else
+ for ( i = 0; i < ID_BLOCK_NIDS(idl); i++ ) {
+#endif
cont_id( &data, ID_BLOCK_ID(idl, i) );
if ( (tmp[i] = idl_fetch_one( be, db, data )) == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_ENTRY,
"idl_fetch: %ld ids (%ld max)\n",
- ID_BLOCK_NIDS(idl), ID_BLOCK_NMAX(idl) ));
+ ID_BLOCK_NIDS(idl), ID_BLOCK_NMAXN(idl) ));
#else
Debug( LDAP_DEBUG_TRACE, "<= idl_fetch %ld ids (%ld max)\n",
- ID_BLOCK_NIDS(idl), ID_BLOCK_NMAX(idl), 0 );
+ ID_BLOCK_NIDS(idl), ID_BLOCK_NMAXN(idl), 0 );
#endif
return( idl );
/* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */
data.dptr = (char *) idl;
- data.dsize = (ID_BLOCK_IDS_OFFSET + ID_BLOCK_NMAX(idl)) * sizeof(ID);
+ data.dsize = (ID_BLOCK_IDS_OFFSET + ID_BLOCK_NMAXN(idl)) * sizeof(ID);
#ifdef LDBM_DEBUG
Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
/* create the header indirect block */
idl = idl_alloc( 3 );
+#ifndef USE_INDIRECT_NIDS
ID_BLOCK_NMAX(idl) = 3;
ID_BLOCK_NIDS(idl) = ID_BLOCK_INDIRECT_VALUE;
ID_BLOCK_ID(idl, 0) = ID_BLOCK_ID(tmp, 0);
ID_BLOCK_ID(idl, 1) = ID_BLOCK_ID(tmp2, 0);
ID_BLOCK_ID(idl, 2) = NOID;
+#else
+ ID_BLOCK_NMAX(idl) = 2 | ID_BLOCK_INDIRECT_VALUE;
+ ID_BLOCK_NIDS(idl) = 2;
+ ID_BLOCK_ID(idl, 0) = ID_BLOCK_ID(tmp, 0);
+ ID_BLOCK_ID(idl, 1) = ID_BLOCK_ID(tmp2, 0);
+#endif
/* store it */
rc = idl_store( be, db, key, idl );
* need to write a new "header" block.
*/
+#ifndef USE_INDIRECT_NIDS
/* select the block to try inserting into *//* XXX linear search XXX */
for ( i = 0; !ID_BLOCK_NOID(idl, i) && id > ID_BLOCK_ID(idl, i); i++ )
; /* NULL */
+#else
+ i = idl_find(idl, id);
+ if (ID_BLOCK_ID(idl, i) < id)
+ i++;
+#endif
if ( i != 0 ) {
i--;
* into the beginning of the first block.
*/
+#ifndef USE_INDIRECT_NIDS
/* is there a next block? */
if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) {
+#else
+ if ( !first && (i + 1) < ID_BLOCK_NIDS(idl) ) {
+#endif
/* read it in */
cont_alloc( &k2, &key );
cont_id( &k2, ID_BLOCK_ID(idl, i) );
rc = 0; /* optimistic */
+#ifndef USE_INDIRECT_NIDS
/* count how many indirect blocks *//* XXX linear count XXX */
for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
; /* NULL */
+#else
+ j = ID_BLOCK_NIDS(idl);
+#endif
/* check it against all-id thresholed */
if ( j + 1 > db->dbc_maxindirect ) {
*/
/* delete all indirect blocks */
+#ifndef USE_INDIRECT_NIDS
for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) {
+#else
+ for ( j = 0; j < ID_BLOCK_NIDS(idl); j++ ) {
+#endif
cont_id( &k2, ID_BLOCK_ID(idl, j) );
rc = ldbm_cache_delete( db, k2 );
idl_free( tmp );
/* create a new updated indirect header block */
- tmp = idl_alloc( ID_BLOCK_NMAX(idl) + 1 );
+ tmp = idl_alloc( ID_BLOCK_NMAXN(idl) + 1 );
+#ifndef USE_INDIRECT_NIDS
ID_BLOCK_NIDS(tmp) = ID_BLOCK_INDIRECT_VALUE;
+#else
+ ID_BLOCK_NMAX(tmp) |= ID_BLOCK_INDIRECT_VALUE;
+#endif
/* everything up to the split block */
AC_MEMCPY(
(char *) &ID_BLOCK_ID(tmp, 0),
ID_BLOCK_ID(tmp, i) = ID_BLOCK_ID(tmp2, 0);
ID_BLOCK_ID(tmp, i + 1) = ID_BLOCK_ID(tmp3, 0);
/* everything after the split block */
+#ifndef USE_INDIRECT_NIDS
+ AC_MEMCPY(
+ (char *) &ID_BLOCK_ID(tmp, i + 2),
+ (char *) &ID_BLOCK_ID(idl, i + 1),
+ (ID_BLOCK_NMAXN(idl) - i - 1) * sizeof(ID) );
+#else
AC_MEMCPY(
(char *) &ID_BLOCK_ID(tmp, i + 2),
(char *) &ID_BLOCK_ID(idl, i + 1),
- (ID_BLOCK_NMAX(idl) - i - 1) * sizeof(ID) );
+ (ID_BLOCK_NIDS(idl) - i - 1) * sizeof(ID) );
+ ID_BLOCK_NIDS(idl)++;
+#endif
/* store the header block */
rc = idl_store( be, db, key, tmp );
i++;
/* do we need to make room for it? */
- if ( ID_BLOCK_NIDS(*idl) == ID_BLOCK_NMAX(*idl) ) {
+ if ( ID_BLOCK_NIDS(*idl) == ID_BLOCK_NMAXN(*idl) ) {
/* make room or indicate block needs splitting */
- if ( ID_BLOCK_NMAX(*idl) >= maxids ) {
+ if ( ID_BLOCK_NMAXN(*idl) >= maxids ) {
return( 3 ); /* block needs splitting */
}
ID_BLOCK_NMAX(*idl) *= 2;
- if ( ID_BLOCK_NMAX(*idl) > maxids ) {
+ if ( ID_BLOCK_NMAXN(*idl) > maxids ) {
ID_BLOCK_NMAX(*idl) = maxids;
}
*idl = (ID_BLOCK *) ch_realloc( (char *) *idl,
- (ID_BLOCK_NMAX(*idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
+ (ID_BLOCK_NMAXN(*idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
}
/* make a slot for the new id */
(void) memset(
(char *) &ID_BLOCK_ID((*idl), ID_BLOCK_NIDS(*idl)),
'\0',
- (ID_BLOCK_NMAX(*idl) - ID_BLOCK_NIDS(*idl)) * sizeof(ID) );
+ (ID_BLOCK_NMAXN(*idl) - ID_BLOCK_NIDS(*idl)) * sizeof(ID) );
#ifdef LDBM_DEBUG_IDL
idl_check(*idl);
}
if ( ! ID_BLOCK_INDIRECT( idl ) ) {
- for ( i=0; i < ID_BLOCK_NIDS(idl); i++ ) {
- if ( ID_BLOCK_ID(idl, i) == id ) {
- if( --ID_BLOCK_NIDS(idl) == 0 ) {
- ldbm_cache_delete( db, key );
-
- } else {
- AC_MEMCPY(
- &ID_BLOCK_ID(idl, i),
- &ID_BLOCK_ID(idl, i+1),
- (ID_BLOCK_NIDS(idl)-i) * sizeof(ID) );
+ i = idl_find(idl, id);
+ if ( ID_BLOCK_ID(idl, i) == id ) {
+ if( --ID_BLOCK_NIDS(idl) == 0 ) {
+ ldbm_cache_delete( db, key );
- ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)) = NOID;
+ } else {
+ AC_MEMCPY(
+ &ID_BLOCK_ID(idl, i),
+ &ID_BLOCK_ID(idl, i+1),
+ (ID_BLOCK_NIDS(idl)-i) * sizeof(ID) );
- idl_store( be, db, key, idl );
- }
+ ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)) = NOID;
- idl_free( idl );
- return 0;
+ idl_store( be, db, key, idl );
}
- /* We didn't find the ID. Hmmm... */
+
+ idl_free( idl );
+ return 0;
}
+ /* We didn't find the ID. Hmmm... */
idl_free( idl );
return -1;
}
/* We have to go through an indirect block and find the ID
in the list of IDL's
*/
+#ifndef USE_INDIRECT_NIDS
for ( nids = 0; !ID_BLOCK_NOID(idl, nids); nids++ )
; /* NULL */
cont_alloc( &data, &key );
- for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
+ for ( j = 0; j<nids; j++ )
+#else
+ nids = ID_BLOCK_NIDS(idl);
+ for ( j = idl_find(idl, id); j >= 0; j = -1) /* execute once */
+#endif
{
ID_BLOCK *tmp;
cont_id( &data, ID_BLOCK_ID(idl, j) );
/*
Now try to find the ID in tmp
*/
- for ( i=0; i < ID_BLOCK_NIDS(tmp); i++ )
+
+ i = idl_find(tmp, id);
+ if ( ID_BLOCK_ID(tmp, i) == id )
{
- if ( ID_BLOCK_ID(tmp, i) == id )
- {
+ AC_MEMCPY(
+ &ID_BLOCK_ID(tmp, i),
+ &ID_BLOCK_ID(tmp, i+1),
+ (ID_BLOCK_NIDS(tmp)-(i+1)) * sizeof(ID));
+ ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp)-1 ) = NOID;
+ ID_BLOCK_NIDS(tmp)--;
+
+ if ( ID_BLOCK_NIDS(tmp) ) {
+ idl_store ( be, db, data, tmp );
+
+ } else {
+ ldbm_cache_delete( db, data );
AC_MEMCPY(
- &ID_BLOCK_ID(tmp, i),
- &ID_BLOCK_ID(tmp, i+1),
- (ID_BLOCK_NIDS(tmp)-(i+1)) * sizeof(ID));
- ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp)-1 ) = NOID;
- ID_BLOCK_NIDS(tmp)--;
-
- if ( ID_BLOCK_NIDS(tmp) ) {
- idl_store ( be, db, data, tmp );
-
- } else {
- ldbm_cache_delete( db, data );
- AC_MEMCPY(
- &ID_BLOCK_ID(idl, j),
- &ID_BLOCK_ID(idl, j+1),
- (nids-(j+1)) * sizeof(ID));
- ID_BLOCK_ID(idl, nids-1) = NOID;
- nids--;
- if ( ! nids )
- ldbm_cache_delete( db, key );
- else
- idl_store( be, db, key, idl );
- }
- idl_free( tmp );
- cont_free( &data );
- idl_free( idl );
- return 0;
+ &ID_BLOCK_ID(idl, j),
+ &ID_BLOCK_ID(idl, j+1),
+ (nids-(j+1)) * sizeof(ID));
+ ID_BLOCK_ID(idl, nids-1) = NOID;
+ nids--;
+#ifdef USE_INDIRECT_NIDS
+ ID_BLOCK_NIDS(idl)--;
+#endif
+ if ( ! nids )
+ ldbm_cache_delete( db, key );
+ else
+ idl_store( be, db, key, idl );
}
+ idl_free( tmp );
+ cont_free( &data );
+ idl_free( idl );
+ return 0;
}
idl_free( tmp );
}
return( NULL );
}
- new = idl_alloc( ID_BLOCK_NMAX(idl) );
+ new = idl_alloc( ID_BLOCK_NMAXN(idl) );
AC_MEMCPY(
(char *) new,
(char *) idl,
- (ID_BLOCK_NMAX(idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
+ (ID_BLOCK_NMAXN(idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
#ifdef LDBM_DEBUG_IDL
idl_check(new);
ni = 0;
for ( ai = 1, bi = 0;
- ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n) && bi < ID_BLOCK_NMAX(b);
+ ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAXN(n) && bi < ID_BLOCK_NMAXN(b);
ai++ )
{
if ( ID_BLOCK_ID(b, bi) == ai ) {
}
}
- for ( ; ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n); ai++ ) {
+ for ( ; ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAXN(n); ai++ ) {
ID_BLOCK_ID(n, ni++) = ai;
}
- if ( ni == ID_BLOCK_NMAX(n) ) {
+ if ( ni == ID_BLOCK_NMAXN(n) ) {
idl_free( n );
return( idl_allids( be ) );
} else {