1 /* idl.c - ldap id list handling routines */
12 #include "back-bdb2.h"
14 static ID_BLOCK* idl_dup( ID_BLOCK *idl );
16 /* Allocate an ID_BLOCK with room for nids ids */
18 bdb2i_idl_alloc( unsigned int nids )
22 /* nmax + nids + space for the ids */
23 new = (ID_BLOCK *) ch_calloc( (ID_BLOCK_IDS_OFFSET + nids), sizeof(ID) );
24 ID_BLOCK_NMAX(new) = nids;
25 ID_BLOCK_NIDS(new) = 0;
31 /* Allocate an empty ALLIDS ID_BLOCK */
33 bdb2i_idl_allids( BackendDB *be )
37 idl = bdb2i_idl_alloc( 0 );
38 ID_BLOCK_NMAX(idl) = ID_BLOCK_ALLIDS_VALUE;
39 ID_BLOCK_NIDS(idl) = bdb2i_next_id_get( be );
45 /* Free an ID_BLOCK */
47 bdb2i_idl_free( ID_BLOCK *idl )
50 Debug( LDAP_DEBUG_TRACE,
51 "bdb2i_idl_free: called with NULL pointer\n",
60 /* Fetch an single ID_BLOCK from the cache */
71 ldbm_datum_init( data );
73 /* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch_one\n", 0, 0, 0 ); */
75 data = bdb2i_cache_fetch( db, key );
77 if( data.dptr == NULL ) {
81 idl = idl_dup( (ID_BLOCK *) data.dptr);
82 ldbm_datum_free( db->dbc_db, data );
88 /* Fetch a set of ID_BLOCKs from the cache
90 * if block return is an ALLIDS block,
91 * return an new ALLIDS block
94 * construct super block from all blocks referenced by INDIRECT block
110 idl = idl_fetch_one( be, db, key );
116 if ( ID_BLOCK_ALLIDS(idl) ) {
118 /* make sure we have the current value of highest id */
119 bdb2i_idl_free( idl );
120 idl = bdb2i_idl_allids( be );
125 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
131 * this is an indirect block which points to other blocks.
132 * we need to read in all the blocks it points to and construct
133 * a big id list containing all the ids, which we will return.
136 /* count the number of blocks & allocate space for pointers to them */
137 for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ )
139 tmp = (ID_BLOCK **) ch_malloc( (i + 1) * sizeof(ID_BLOCK *) );
141 /* read in all the blocks */
142 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
144 for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
145 ldbm_datum_init( data );
147 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
148 ID_BLOCK_ID(idl, i), key.dptr );
150 data.dsize = strlen( kstr ) + 1;
152 if ( (tmp[i] = idl_fetch_one( be, db, data )) == NULL ) {
153 Debug( LDAP_DEBUG_ANY,
154 "bdb2i_idl_fetch of (%s) returns NULL\n", data.dptr, 0, 0 );
158 nids += ID_BLOCK_NIDS(tmp[i]);
162 bdb2i_idl_free( idl );
164 /* allocate space for the big block */
165 idl = bdb2i_idl_alloc( nids );
166 ID_BLOCK_NIDS(idl) = nids;
169 /* copy in all the ids from the component blocks */
170 for ( i = 0; tmp[i] != NULL; i++ ) {
171 if ( tmp[i] == NULL ) {
176 (char *) &ID_BLOCK_ID(idl, nids),
177 (char *) &ID_BLOCK_ID(tmp[i], 0),
178 ID_BLOCK_NIDS(tmp[i]) * sizeof(ID) );
179 nids += ID_BLOCK_NIDS(tmp[i]);
181 bdb2i_idl_free( tmp[i] );
183 free( (char *) tmp );
185 Debug( LDAP_DEBUG_TRACE, "<= bdb2i_idl_fetch %ld ids (%ld max)\n",
186 ID_BLOCK_NIDS(idl), ID_BLOCK_NMAX(idl), 0 );
191 /* store a single block */
202 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
204 ldbm_datum_init( data );
206 /* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */
208 data.dptr = (char *) idl;
209 data.dsize = (ID_BLOCK_IDS_OFFSET + ID_BLOCK_NMAX(idl)) * sizeof(ID);
212 Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
216 flags = LDBM_REPLACE;
217 rc = bdb2i_cache_store( db, key, data, flags );
219 /* Debug( LDAP_DEBUG_TRACE, "<= idl_store %d\n", rc, 0, 0 ); */
224 /* split the block at id
225 * locate ID greater than or equal to id.
237 /* find where to split the block *//* XXX linear search XXX */
238 for ( nr = 0; nr < ID_BLOCK_NIDS(b) && id > ID_BLOCK_ID(b, nr); nr++ )
241 nl = ID_BLOCK_NIDS(b) - nr;
243 *right = bdb2i_idl_alloc( nr == 0 ? 1 : nr );
244 *left = bdb2i_idl_alloc( nl + (nr == 0 ? 0 : 1));
247 * everything before the id being inserted in the first block
248 * unless there is nothing, in which case the id being inserted
252 ID_BLOCK_NIDS(*right) = 1;
253 ID_BLOCK_ID(*right, 0) = id;
256 (char *) &ID_BLOCK_ID(*right, 0),
257 (char *) &ID_BLOCK_ID(b, 0),
259 ID_BLOCK_NIDS(*right) = nr;
260 ID_BLOCK_ID(*left, 0) = id;
263 /* the id being inserted & everything after in the second block */
265 (char *) &ID_BLOCK_ID(*left, (nr == 0 ? 0 : 1)),
266 (char *) &ID_BLOCK_ID(b, nr),
268 ID_BLOCK_NIDS(*left) = nl + (nr == 0 ? 0 : 1);
273 * idl_change_first - called when an indirect block's first key has
274 * changed, meaning it needs to be stored under a new key, and the
275 * header block pointing to it needs updating.
281 Datum hkey, /* header block key */
282 ID_BLOCK *h, /* header block */
283 int pos, /* pos in h to update */
284 Datum bkey, /* data block key */
285 ID_BLOCK *b /* data block */
290 /* Debug( LDAP_DEBUG_TRACE, "=> idl_change_first\n", 0, 0, 0 ); */
292 /* delete old key block */
293 if ( (rc = bdb2i_cache_delete( db, bkey )) != 0 ) {
294 Debug( LDAP_DEBUG_ANY,
295 "bdb2i_db_delete of (%s) returns %d\n", bkey.dptr, rc,
300 /* write block with new key */
301 sprintf( bkey.dptr, "%c%ld%s", CONT_PREFIX,
302 ID_BLOCK_ID(b, 0), hkey.dptr );
303 bkey.dsize = strlen( bkey.dptr ) + 1;
304 if ( (rc = idl_store( be, db, bkey, b )) != 0 ) {
305 Debug( LDAP_DEBUG_ANY,
306 "idl_store of (%s) returns %d\n", bkey.dptr, rc, 0 );
310 /* update + write indirect header block */
311 ID_BLOCK_ID(h, pos) = ID_BLOCK_ID(b, 0);
312 if ( (rc = idl_store( be, db, hkey, h )) != 0 ) {
313 Debug( LDAP_DEBUG_ANY,
314 "idl_store of (%s) returns %d\n", hkey.dptr, rc, 0 );
323 bdb2i_idl_insert_key(
331 ID_BLOCK *idl, *tmp, *tmp2, *tmp3;
335 ldbm_datum_init( k2 );
337 if ( (idl = idl_fetch_one( be, db, key )) == NULL ) {
339 Statslog( LDAP_DEBUG_STATS, "=> bdb2i_idl_insert_key(): no key yet\n",
343 idl = bdb2i_idl_alloc( 1 );
344 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)++) = id;
345 rc = idl_store( be, db, key, idl );
347 bdb2i_idl_free( idl );
351 if ( ID_BLOCK_ALLIDS( idl ) ) {
353 bdb2i_idl_free( idl );
357 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
359 switch ( bdb2i_idl_insert( &idl, id, db->dbc_maxids ) ) {
360 case 0: /* id inserted - store the updated block */
362 rc = idl_store( be, db, key, idl );
365 case 2: /* id already there - nothing to do */
369 case 3: /* id not inserted - block must be split */
370 /* check threshold for marking this an all-id block */
371 if ( db->dbc_maxindirect < 2 ) {
372 bdb2i_idl_free( idl );
373 idl = bdb2i_idl_allids( be );
374 rc = idl_store( be, db, key, idl );
378 idl_split_block( idl, id, &tmp, &tmp2 );
379 bdb2i_idl_free( idl );
381 /* create the header indirect block */
382 idl = bdb2i_idl_alloc( 3 );
383 ID_BLOCK_NMAX(idl) = 3;
384 ID_BLOCK_NIDS(idl) = ID_BLOCK_INDIRECT_VALUE;
385 ID_BLOCK_ID(idl, 0) = ID_BLOCK_ID(tmp, 0);
386 ID_BLOCK_ID(idl, 1) = ID_BLOCK_ID(tmp2, 0);
387 ID_BLOCK_ID(idl, 2) = NOID;
390 rc = idl_store( be, db, key, idl );
392 /* store the first id block */
393 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
394 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
395 ID_BLOCK_ID(tmp, 0), key.dptr );
397 k2.dsize = strlen( kstr ) + 1;
398 rc = idl_store( be, db, k2, tmp );
400 /* store the second id block */
401 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
402 ID_BLOCK_ID(tmp2, 0), key.dptr );
404 k2.dsize = strlen( kstr ) + 1;
405 rc = idl_store( be, db, k2, tmp2 );
408 bdb2i_idl_free( tmp );
409 bdb2i_idl_free( tmp2 );
413 bdb2i_idl_free( idl );
418 * this is an indirect block which points to other blocks.
419 * we need to read in the block into which the id should be
420 * inserted, then insert the id and store the block. we might
421 * have to split the block if it is full, which means we also
422 * need to write a new "header" block.
425 /* select the block to try inserting into *//* XXX linear search XXX */
426 for ( i = 0; !ID_BLOCK_NOID(idl, i) && id > ID_BLOCK_ID(idl, i); i++ )
436 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
437 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
438 ID_BLOCK_ID(idl, i), key.dptr );
440 k2.dsize = strlen( kstr ) + 1;
441 if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) {
442 Debug( LDAP_DEBUG_ANY, "nonexistent continuation block (%s)\n",
445 bdb2i_idl_free( idl );
450 switch ( bdb2i_idl_insert( &tmp, id, db->dbc_maxids ) ) {
451 case 0: /* id inserted ok */
452 if ( (rc = idl_store( be, db, k2, tmp )) != 0 ) {
453 Debug( LDAP_DEBUG_ANY,
454 "idl_store of (%s) returns %d\n", k2.dptr, rc, 0 );
458 case 1: /* id inserted - first id in block has changed */
460 * key for this block has changed, so we have to
461 * write the block under the new key, delete the
462 * old key block + update and write the indirect
466 rc = idl_change_first( be, db, key, idl, i, k2, tmp );
469 case 2: /* id not inserted - already there, do nothing */
473 case 3: /* id not inserted - block is full */
475 * first, see if it will fit in the next block,
476 * without splitting, unless we're trying to insert
477 * into the beginning of the first block.
480 /* is there a next block? */
481 if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) {
483 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
484 ID_BLOCK_ID(idl, i + 1), key.dptr );
486 k2.dsize = strlen( kstr ) + 1;
487 if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
488 Debug( LDAP_DEBUG_ANY,
489 "idl_fetch_one (%s) returns NULL\n",
491 /* split the original block */
495 switch ( (rc = bdb2i_idl_insert( &tmp2, id,
496 db->dbc_maxids )) ) {
497 case 1: /* id inserted first in block */
498 rc = idl_change_first( be, db, key, idl,
502 case 2: /* id already there - how? */
503 case 0: /* id inserted */
505 Debug( LDAP_DEBUG_ANY,
506 "id %ld already in next block\n",
510 bdb2i_idl_free( tmp );
511 bdb2i_idl_free( tmp2 );
512 bdb2i_idl_free( idl );
515 case 3: /* split the original block */
519 bdb2i_idl_free( tmp2 );
524 * must split the block, write both new blocks + update
525 * and write the indirect header block.
528 rc = 0; /* optimistic */
531 /* count how many indirect blocks *//* XXX linear count XXX */
532 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
535 /* check it against all-id thresholed */
536 if ( j + 1 > db->dbc_maxindirect ) {
538 * we've passed the all-id threshold, meaning
539 * that this set of blocks should be replaced
540 * by a single "all-id" block. our job: delete
541 * all the indirect blocks, and replace the header
542 * block by an all-id block.
545 /* delete all indirect blocks */
546 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) {
547 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
548 ID_BLOCK_ID(idl, j), key.dptr );
550 k2.dsize = strlen( kstr ) + 1;
552 rc = bdb2i_cache_delete( db, k2 );
555 /* store allid block in place of header block */
556 bdb2i_idl_free( idl );
557 idl = bdb2i_idl_allids( be );
558 rc = idl_store( be, db, key, idl );
561 bdb2i_idl_free( idl );
562 bdb2i_idl_free( tmp );
566 idl_split_block( tmp, id, &tmp2, &tmp3 );
567 bdb2i_idl_free( tmp );
569 /* create a new updated indirect header block */
570 tmp = bdb2i_idl_alloc( ID_BLOCK_NMAX(idl) + 1 );
571 ID_BLOCK_NIDS(tmp) = ID_BLOCK_INDIRECT_VALUE;
572 /* everything up to the split block */
574 (char *) &ID_BLOCK_ID(tmp, 0),
575 (char *) &ID_BLOCK_ID(idl, 0),
577 /* the two new blocks */
578 ID_BLOCK_ID(tmp, i) = ID_BLOCK_ID(tmp2, 0);
579 ID_BLOCK_ID(tmp, i + 1) = ID_BLOCK_ID(tmp3, 0);
580 /* everything after the split block */
582 (char *) &ID_BLOCK_ID(tmp, i + 2),
583 (char *) &ID_BLOCK_ID(idl, i + 1),
584 (ID_BLOCK_NMAX(idl) - i - 1) * sizeof(ID) );
586 /* store the header block */
587 rc = idl_store( be, db, key, tmp );
589 /* store the first id block */
590 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
591 ID_BLOCK_ID(tmp2, 0), key.dptr );
593 k2.dsize = strlen( kstr ) + 1;
594 rc = idl_store( be, db, k2, tmp2 );
596 /* store the second id block */
597 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
598 ID_BLOCK_ID(tmp3, 0), key.dptr );
600 k2.dsize = strlen( kstr ) + 1;
601 rc = idl_store( be, db, k2, tmp3 );
603 bdb2i_idl_free( tmp2 );
604 bdb2i_idl_free( tmp3 );
609 bdb2i_idl_free( tmp );
610 bdb2i_idl_free( idl );
616 * bdb2i_idl_insert - insert an id into an id list.
620 * 1 id inserted, first id in block has changed
621 * 2 id not inserted, already there
622 * 3 id not inserted, block must be split
625 bdb2i_idl_insert( ID_BLOCK **idl, ID id, unsigned int maxids )
629 if ( ID_BLOCK_ALLIDS( *idl ) ) {
630 return( 2 ); /* already there */
633 /* is it already there? *//* XXX linear search XXX */
634 for ( i = 0; i < ID_BLOCK_NIDS(*idl) && id > ID_BLOCK_ID(*idl, i); i++ ) {
637 if ( i < ID_BLOCK_NIDS(*idl) && ID_BLOCK_ID(*idl, i) == id ) {
638 return( 2 ); /* already there */
641 /* do we need to make room for it? */
642 if ( ID_BLOCK_NIDS(*idl) == ID_BLOCK_NMAX(*idl) ) {
643 /* make room or indicate block needs splitting */
644 if ( ID_BLOCK_NMAX(*idl) >= maxids ) {
645 return( 3 ); /* block needs splitting */
648 ID_BLOCK_NMAX(*idl) *= 2;
649 if ( ID_BLOCK_NMAX(*idl) > maxids ) {
650 ID_BLOCK_NMAX(*idl) = maxids;
652 *idl = (ID_BLOCK *) ch_realloc( (char *) *idl,
653 (ID_BLOCK_NMAX(*idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
656 /* make a slot for the new id */
657 SAFEMEMCPY( &ID_BLOCK_ID(*idl, i+1), &ID_BLOCK_ID(*idl, i),
658 (ID_BLOCK_NIDS(*idl) - i) * sizeof(ID) );
660 ID_BLOCK_ID(*idl, i) = id;
661 ID_BLOCK_NIDS(*idl)++;
663 (char *) &ID_BLOCK_ID((*idl), ID_BLOCK_NIDS(*idl)),
665 (ID_BLOCK_NMAX(*idl) - ID_BLOCK_NIDS(*idl)) * sizeof(ID) );
667 return( i == 0 ? 1 : 0 ); /* inserted - first id changed or not */
672 bdb2i_idl_delete_key (
685 if ( (idl = idl_fetch_one( be, db, key ) ) == NULL )
687 /* It wasn't found. Hmm... */
691 if ( ID_BLOCK_ALLIDS( idl ) ) {
692 bdb2i_idl_free( idl );
696 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
697 for ( i=0; i < ID_BLOCK_NIDS(idl); i++ ) {
698 if ( ID_BLOCK_ID(idl, i) == id ) {
699 if( --ID_BLOCK_NIDS(idl) == 0 ) {
700 bdb2i_cache_delete( db, key );
704 &ID_BLOCK_ID(idl, i),
705 &ID_BLOCK_ID(idl, i+1),
706 (ID_BLOCK_NIDS(idl)-i) * sizeof(ID) );
708 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)) = NOID;
710 idl_store( be, db, key, idl );
713 bdb2i_idl_free( idl );
716 /* We didn't find the ID. Hmmm... */
718 bdb2i_idl_free( idl );
722 /* We have to go through an indirect block and find the ID
725 for ( nids = 0; !ID_BLOCK_NOID(idl, nids); nids++ )
727 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
728 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
730 ldbm_datum_init( data );
731 sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(idl, j), key.dptr );
733 data.dsize = strlen( kstr ) + 1;
735 if ( (tmp = idl_fetch_one( be, db, data )) == NULL ) {
736 Debug( LDAP_DEBUG_ANY,
737 "bdb2i_idl_fetch of (%s) returns NULL\n", data.dptr, 0, 0 );
741 Now try to find the ID in tmp
743 for ( i=0; i < ID_BLOCK_NIDS(tmp); i++ )
745 if ( ID_BLOCK_ID(tmp, i) == id )
748 &ID_BLOCK_ID(tmp, i),
749 &ID_BLOCK_ID(tmp, i+1),
750 (ID_BLOCK_NIDS(tmp)-(i+1)) * sizeof(ID));
751 ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp)-1 ) = NOID;
752 ID_BLOCK_NIDS(tmp)--;
754 if ( ID_BLOCK_NIDS(tmp) ) {
755 idl_store ( be, db, data, tmp );
758 bdb2i_cache_delete( db, data );
760 &ID_BLOCK_ID(idl, j),
761 &ID_BLOCK_ID(idl, j+1),
762 (nids-(j+1)) * sizeof(ID));
763 ID_BLOCK_ID(idl, nids-1) = NOID;
766 bdb2i_cache_delete( db, key );
768 idl_store( be, db, key, idl );
770 bdb2i_idl_free( tmp );
772 bdb2i_idl_free( idl );
776 bdb2i_idl_free( tmp );
779 bdb2i_idl_free( idl );
784 /* return a duplicate of a single ID_BLOCK */
786 idl_dup( ID_BLOCK *idl )
794 new = bdb2i_idl_alloc( ID_BLOCK_NMAX(idl) );
798 (ID_BLOCK_NMAX(idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
804 /* return the smaller ID_BLOCK */
806 idl_min( ID_BLOCK *a, ID_BLOCK *b )
808 return( ID_BLOCK_NIDS(a) > ID_BLOCK_NIDS(b) ? b : a );
813 * bdb2i_idl_intersection - return a intersection b
816 bdb2i_idl_intersection(
822 unsigned int ai, bi, ni;
825 if ( a == NULL || b == NULL ) {
828 if ( ID_BLOCK_ALLIDS( a ) ) {
829 return( idl_dup( b ) );
831 if ( ID_BLOCK_ALLIDS( b ) ) {
832 return( idl_dup( a ) );
835 n = idl_dup( idl_min( a, b ) );
837 for ( ni = 0, ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) {
839 bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai);
845 if ( bi == ID_BLOCK_NIDS(b) ) {
849 if ( ID_BLOCK_ID(b, bi) == ID_BLOCK_ID(a, ai) ) {
850 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
858 ID_BLOCK_NIDS(n) = ni;
865 * bdb2i_idl_union - return a union b
874 unsigned int ai, bi, ni;
878 return( idl_dup( b ) );
881 return( idl_dup( a ) );
883 if ( ID_BLOCK_ALLIDS( a ) || ID_BLOCK_ALLIDS( b ) ) {
884 return( bdb2i_idl_allids( be ) );
887 if ( ID_BLOCK_NIDS(b) < ID_BLOCK_NIDS(a) ) {
893 n = bdb2i_idl_alloc( ID_BLOCK_NIDS(a) + ID_BLOCK_NIDS(b) );
895 for ( ni = 0, ai = 0, bi = 0;
896 ai < ID_BLOCK_NIDS(a) && bi < ID_BLOCK_NIDS(b);
899 if ( ID_BLOCK_ID(a, ai) < ID_BLOCK_ID(b, bi) ) {
900 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai++);
902 } else if ( ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai) ) {
903 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(b, bi++);
906 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
911 for ( ; ai < ID_BLOCK_NIDS(a); ai++ ) {
912 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
914 for ( ; bi < ID_BLOCK_NIDS(b); bi++ ) {
915 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(b, bi);
917 ID_BLOCK_NIDS(n) = ni;
924 * bdb2i_idl_notin - return a intersection ~b (or a minus b)
933 unsigned int ni, ai, bi;
939 if ( b == NULL || ID_BLOCK_ALLIDS( b )) {
940 return( idl_dup( a ) );
943 if ( ID_BLOCK_ALLIDS( a ) ) {
944 n = bdb2i_idl_alloc( SLAPD_LDBM_MIN_MAXIDS );
947 for ( ai = 1, bi = 0;
948 ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n) && bi < ID_BLOCK_NMAX(b);
951 if ( ID_BLOCK_ID(b, bi) == ai ) {
954 ID_BLOCK_ID(n, ni++) = ai;
958 for ( ; ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n); ai++ ) {
959 ID_BLOCK_ID(n, ni++) = ai;
962 if ( ni == ID_BLOCK_NMAX(n) ) {
964 return( bdb2i_idl_allids( be ) );
966 ID_BLOCK_NIDS(n) = ni;
974 for ( ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) {
976 bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai);
982 if ( bi == ID_BLOCK_NIDS(b) ) {
986 if ( ID_BLOCK_ID(b, bi) != ID_BLOCK_ID(a, ai) ) {
987 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
991 for ( ; ai < ID_BLOCK_NIDS(a); ai++ ) {
992 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
994 ID_BLOCK_NIDS(n) = ni;
1000 /* return the first ID in the block
1003 * otherwise return NOID
1004 * otherwise return first ID
1006 * cursor is set to 1
1009 bdb2i_idl_firstid( ID_BLOCK *idl, ID *cursor )
1013 if ( idl == NULL || ID_BLOCK_NIDS(idl) == 0 ) {
1017 if ( ID_BLOCK_ALLIDS( idl ) ) {
1018 return( ID_BLOCK_NIDS(idl) > 1 ? 1 : NOID );
1021 return( ID_BLOCK_ID(idl, 0) );
1025 /* return next ID after id
1026 * if ALLIDS block, cursor is id
1028 * if id < NIDS return id
1030 * otherwise cursor is index into block
1032 * return id at index then increment
1035 bdb2i_idl_nextid( ID_BLOCK *idl, ID *cursor )
1037 if ( ID_BLOCK_ALLIDS( idl ) ) {
1038 if( ++(*cursor) < ID_BLOCK_NIDS(idl) ) {
1045 if ( *cursor < ID_BLOCK_NIDS(idl) ) {
1046 return ID_BLOCK_ID(idl, (*cursor)++);