1 /* idl.c - ldap id list handling routines */
10 #include "ldapconfig.h"
12 #include "back-ldbm.h"
14 static ID_BLOCK* idl_dup( ID_BLOCK *idl );
16 /* Allocate an ID_BLOCK with room for nids ids */
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 idl_allids( Backend *be )
38 ID_BLOCK_NMAX(idl) = ID_BLOCK_ALLIDS_VALUE;
39 ID_BLOCK_NIDS(idl) = next_id_get( be );
45 /* Free an ID_BLOCK */
47 idl_free( ID_BLOCK *idl )
50 Debug( LDAP_DEBUG_TRACE,
51 "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 = ldbm_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 */
120 idl = 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 + 20 );
144 for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
145 ldbm_datum_init( data );
147 sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, ID_BLOCK_ID(idl, i) );
149 data.dsize = strlen( kstr ) + 1;
151 if ( (tmp[i] = idl_fetch_one( be, db, data )) == NULL ) {
152 Debug( LDAP_DEBUG_ANY,
153 "idl_fetch of (%s) returns NULL\n", data.dptr, 0, 0 );
157 nids += ID_BLOCK_NIDS(tmp[i]);
163 /* allocate space for the big block */
164 idl = idl_alloc( nids );
165 ID_BLOCK_NIDS(idl) = nids;
168 /* copy in all the ids from the component blocks */
169 for ( i = 0; tmp[i] != NULL; i++ ) {
170 if ( tmp[i] == NULL ) {
175 (char *) &ID_BLOCK_ID(idl, nids),
176 (char *) &ID_BLOCK_ID(tmp[i], 0),
177 ID_BLOCK_NIDS(tmp[i]) * sizeof(ID) );
178 nids += ID_BLOCK_NIDS(tmp[i]);
182 free( (char *) tmp );
184 Debug( LDAP_DEBUG_TRACE, "<= idl_fetch %lu ids (%lu max)\n",
185 ID_BLOCK_NIDS(idl), ID_BLOCK_NMAX(idl), 0 );
190 /* store a single block */
201 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
203 ldbm_datum_init( data );
205 /* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */
207 data.dptr = (char *) idl;
208 data.dsize = (ID_BLOCK_IDS_OFFSET + ID_BLOCK_NMAX(idl)) * sizeof(ID);
211 Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
215 flags = LDBM_REPLACE;
216 if( li->li_dbcachewsync ) flags |= LDBM_SYNC;
217 rc = ldbm_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 = idl_alloc( nr == 0 ? 1 : nr );
244 *left = 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 = ldbm_cache_delete( db, bkey )) != 0 ) {
294 Debug( LDAP_DEBUG_ANY,
295 "ldbm_delete of (%s) returns %d\n", bkey.dptr, rc,
300 /* write block with new key */
301 sprintf( bkey.dptr, "%c%s%ld", CONT_PREFIX, hkey.dptr, ID_BLOCK_ID(b, 0) );
302 bkey.dsize = strlen( bkey.dptr ) + 1;
303 if ( (rc = idl_store( be, db, bkey, b )) != 0 ) {
304 Debug( LDAP_DEBUG_ANY,
305 "idl_store of (%s) returns %d\n", bkey.dptr, rc, 0 );
309 /* update + write indirect header block */
310 ID_BLOCK_ID(h, pos) = ID_BLOCK_ID(b, 0);
311 if ( (rc = idl_store( be, db, hkey, h )) != 0 ) {
312 Debug( LDAP_DEBUG_ANY,
313 "idl_store of (%s) returns %d\n", hkey.dptr, rc, 0 );
330 ID_BLOCK *idl, *tmp, *tmp2, *tmp3;
334 ldbm_datum_init( k2 );
336 if ( (idl = idl_fetch_one( be, db, key )) == NULL ) {
338 Statslog( LDAP_DEBUG_STATS, "=> idl_insert_key(): no key yet\n",
342 idl = idl_alloc( 1 );
343 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)++) = id;
344 rc = idl_store( be, db, key, idl );
350 if ( ID_BLOCK_ALLIDS( idl ) ) {
356 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
358 switch ( idl_insert( &idl, id, db->dbc_maxids ) ) {
359 case 0: /* id inserted - store the updated block */
361 rc = idl_store( be, db, key, idl );
364 case 2: /* id already there - nothing to do */
368 case 3: /* id not inserted - block must be split */
369 /* check threshold for marking this an all-id block */
370 if ( db->dbc_maxindirect < 2 ) {
372 idl = idl_allids( be );
373 rc = idl_store( be, db, key, idl );
377 idl_split_block( idl, id, &tmp, &tmp2 );
380 /* create the header indirect block */
381 idl = idl_alloc( 3 );
382 ID_BLOCK_NMAX(idl) = 3;
383 ID_BLOCK_NIDS(idl) = ID_BLOCK_INDIRECT_VALUE;
384 ID_BLOCK_ID(idl, 0) = ID_BLOCK_ID(tmp, 0);
385 ID_BLOCK_ID(idl, 1) = ID_BLOCK_ID(tmp2, 0);
386 ID_BLOCK_ID(idl, 2) = NOID;
389 rc = idl_store( be, db, key, idl );
391 /* store the first id block */
392 kstr = (char *) ch_malloc( key.dsize + 20 );
393 sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
394 ID_BLOCK_ID(tmp, 0) );
396 k2.dsize = strlen( kstr ) + 1;
397 rc = idl_store( be, db, k2, tmp );
399 /* store the second id block */
400 sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
401 ID_BLOCK_ID(tmp2, 0) );
403 k2.dsize = strlen( kstr ) + 1;
404 rc = idl_store( be, db, k2, tmp2 );
417 * this is an indirect block which points to other blocks.
418 * we need to read in the block into which the id should be
419 * inserted, then insert the id and store the block. we might
420 * have to split the block if it is full, which means we also
421 * need to write a new "header" block.
424 /* select the block to try inserting into *//* XXX linear search XXX */
425 for ( i = 0; !ID_BLOCK_NOID(idl, i) && id > ID_BLOCK_ID(idl, i); i++ )
435 kstr = (char *) ch_malloc( key.dsize + 20 );
436 sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, ID_BLOCK_ID(idl, i) );
438 k2.dsize = strlen( kstr ) + 1;
439 if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) {
440 Debug( LDAP_DEBUG_ANY, "nonexistent continuation block (%s)\n",
448 switch ( idl_insert( &tmp, id, db->dbc_maxids ) ) {
449 case 0: /* id inserted ok */
450 if ( (rc = idl_store( be, db, k2, tmp )) != 0 ) {
451 Debug( LDAP_DEBUG_ANY,
452 "idl_store of (%s) returns %d\n", k2.dptr, rc, 0 );
456 case 1: /* id inserted - first id in block has changed */
458 * key for this block has changed, so we have to
459 * write the block under the new key, delete the
460 * old key block + update and write the indirect
464 rc = idl_change_first( be, db, key, idl, i, k2, tmp );
467 case 2: /* id not inserted - already there, do nothing */
471 case 3: /* id not inserted - block is full */
473 * first, see if it will fit in the next block,
474 * without splitting, unless we're trying to insert
475 * into the beginning of the first block.
478 /* is there a next block? */
479 if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) {
481 sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
482 ID_BLOCK_ID(idl, i + 1) );
484 k2.dsize = strlen( kstr ) + 1;
485 if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
486 Debug( LDAP_DEBUG_ANY,
487 "idl_fetch_one (%s) returns NULL\n",
489 /* split the original block */
493 switch ( (rc = idl_insert( &tmp2, id,
494 db->dbc_maxids )) ) {
495 case 1: /* id inserted first in block */
496 rc = idl_change_first( be, db, key, idl,
500 case 2: /* id already there - how? */
501 case 0: /* id inserted */
503 Debug( LDAP_DEBUG_ANY,
504 "id %lu already in next block\n",
513 case 3: /* split the original block */
522 * must split the block, write both new blocks + update
523 * and write the indirect header block.
526 rc = 0; /* optimistic */
529 /* count how many indirect blocks *//* XXX linear count XXX */
530 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
533 /* check it against all-id thresholed */
534 if ( j + 1 > db->dbc_maxindirect ) {
536 * we've passed the all-id threshold, meaning
537 * that this set of blocks should be replaced
538 * by a single "all-id" block. our job: delete
539 * all the indirect blocks, and replace the header
540 * block by an all-id block.
543 /* delete all indirect blocks */
544 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) {
545 sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
546 ID_BLOCK_ID(idl, j) );
548 k2.dsize = strlen( kstr ) + 1;
550 rc = ldbm_cache_delete( db, k2 );
553 /* store allid block in place of header block */
555 idl = idl_allids( be );
556 rc = idl_store( be, db, key, idl );
564 idl_split_block( tmp, id, &tmp2, &tmp3 );
567 /* create a new updated indirect header block */
568 tmp = idl_alloc( ID_BLOCK_NMAX(idl) + 1 );
569 ID_BLOCK_NIDS(tmp) = ID_BLOCK_INDIRECT_VALUE;
570 /* everything up to the split block */
572 (char *) &ID_BLOCK_ID(tmp, 0),
573 (char *) &ID_BLOCK_ID(idl, 0),
575 /* the two new blocks */
576 ID_BLOCK_ID(tmp, i) = ID_BLOCK_ID(tmp2, 0);
577 ID_BLOCK_ID(tmp, i + 1) = ID_BLOCK_ID(tmp3, 0);
578 /* everything after the split block */
580 (char *) &ID_BLOCK_ID(tmp, i + 2),
581 (char *) &ID_BLOCK_ID(idl, i + 1),
582 (ID_BLOCK_NMAX(idl) - i - 1) * sizeof(ID) );
584 /* store the header block */
585 rc = idl_store( be, db, key, tmp );
587 /* store the first id block */
588 sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
589 ID_BLOCK_ID(tmp2, 0) );
591 k2.dsize = strlen( kstr ) + 1;
592 rc = idl_store( be, db, k2, tmp2 );
594 /* store the second id block */
595 sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
596 ID_BLOCK_ID(tmp3, 0) );
598 k2.dsize = strlen( kstr ) + 1;
599 rc = idl_store( be, db, k2, tmp3 );
614 * idl_insert - insert an id into an id list.
618 * 1 id inserted, first id in block has changed
619 * 2 id not inserted, already there
620 * 3 id not inserted, block must be split
623 idl_insert( ID_BLOCK **idl, ID id, int maxids )
627 if ( ID_BLOCK_ALLIDS( *idl ) ) {
628 return( 2 ); /* already there */
631 /* is it already there? *//* XXX linear search XXX */
632 for ( i = 0; i < ID_BLOCK_NIDS(*idl) && id > ID_BLOCK_ID(*idl, i); i++ ) {
635 if ( i < ID_BLOCK_NIDS(*idl) && ID_BLOCK_ID(*idl, i) == id ) {
636 return( 2 ); /* already there */
639 /* do we need to make room for it? */
640 if ( ID_BLOCK_NIDS(*idl) == ID_BLOCK_NMAX(*idl) ) {
641 /* make room or indicate block needs splitting */
642 if ( ID_BLOCK_NMAX(*idl) >= maxids ) {
643 return( 3 ); /* block needs splitting */
646 ID_BLOCK_NMAX(*idl) *= 2;
647 if ( ID_BLOCK_NMAX(*idl) > maxids ) {
648 ID_BLOCK_NMAX(*idl) = maxids;
650 *idl = (ID_BLOCK *) ch_realloc( (char *) *idl,
651 (ID_BLOCK_NMAX(*idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
654 /* make a slot for the new id *//* XXX bubble move XXX */
655 for ( j = ID_BLOCK_NIDS(*idl); j != i; j-- ) {
656 ID_BLOCK_ID(*idl, j) = ID_BLOCK_ID(*idl, j-1);
658 ID_BLOCK_ID(*idl, i) = id;
659 ID_BLOCK_NIDS(*idl)++;
661 (char *) &ID_BLOCK_ID((*idl), ID_BLOCK_NIDS(*idl)),
663 (ID_BLOCK_NMAX(*idl) - ID_BLOCK_NIDS(*idl)) * sizeof(ID) );
665 return( i == 0 ? 1 : 0 ); /* inserted - first id changed or not */
683 if ( (idl = idl_fetch_one( be, db, key ) ) == NULL )
685 /* It wasn't found. Hmm... */
689 if ( ID_BLOCK_ALLIDS( idl ) ) {
694 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
695 for ( i=0; i < ID_BLOCK_NIDS(idl); i++ ) {
696 if ( ID_BLOCK_ID(idl, i) == id ) {
697 if( --ID_BLOCK_NIDS(idl) == 0 ) {
698 ldbm_cache_delete( db, key );
702 &ID_BLOCK_ID(idl, i),
703 &ID_BLOCK_ID(idl, i+1),
704 (ID_BLOCK_NIDS(idl)-i) * sizeof(ID) );
706 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)) = NOID;
708 idl_store( be, db, key, idl );
714 /* We didn't find the ID. Hmmm... */
720 /* We have to go through an indirect block and find the ID
723 for ( nids = 0; !ID_BLOCK_NOID(idl, nids); nids++ )
725 kstr = (char *) ch_malloc( key.dsize + 20 );
727 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
729 ldbm_datum_init( data );
730 sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, ID_BLOCK_ID(idl, j) );
732 data.dsize = strlen( kstr ) + 1;
734 if ( (tmp = idl_fetch_one( be, db, data )) == NULL ) {
735 Debug( LDAP_DEBUG_ANY,
736 "idl_fetch of (%s) returns NULL\n", data.dptr, 0, 0 );
740 Now try to find the ID in tmp
742 for ( i=0; i < ID_BLOCK_NIDS(tmp); i++ )
744 if ( ID_BLOCK_ID(tmp, i) == id )
747 &ID_BLOCK_ID(tmp, i),
748 &ID_BLOCK_ID(tmp, i+1),
749 (ID_BLOCK_NIDS(tmp)-(i+1)) * sizeof(ID));
750 ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp)-1 ) = NOID;
751 ID_BLOCK_NIDS(tmp)--;
753 if ( ID_BLOCK_NIDS(tmp) ) {
754 idl_store ( be, db, data, tmp );
757 ldbm_cache_delete( db, data );
759 &ID_BLOCK_ID(idl, j),
760 &ID_BLOCK_ID(idl, j+1),
761 (nids-(j+1)) * sizeof(ID));
762 ID_BLOCK_ID(idl, nids-1) = NOID;
765 ldbm_cache_delete( db, key );
767 idl_store( be, db, key, idl );
783 /* return a duplicate of a single ID_BLOCK */
785 idl_dup( ID_BLOCK *idl )
793 new = 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 * idl_intersection - return a intersection b
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 * 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( idl_allids( be ) );
887 if ( ID_BLOCK_NIDS(b) < ID_BLOCK_NIDS(a) ) {
893 n = 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 * 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 = 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( 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;
999 /* return the first ID in the block
1002 * otherwise return NOID
1003 * otherwise return first ID
1006 idl_firstid( ID_BLOCK *idl )
1008 if ( idl == NULL || ID_BLOCK_NIDS(idl) == 0 ) {
1012 if ( ID_BLOCK_ALLIDS( idl ) ) {
1013 return( ID_BLOCK_NIDS(idl) > 1 ? 1 : NOID );
1016 return( ID_BLOCK_ID(idl, 0) );
1019 /* return next ID after id
1020 * if ALLIDS block, increment id.
1021 * if id < NIDS return id
1023 * otherwise SEARCH for next id (ugh!)
1026 idl_nextid( ID_BLOCK *idl, ID id )
1030 if ( ID_BLOCK_ALLIDS( idl ) ) {
1031 return( ++id < ID_BLOCK_NIDS(idl) ? id : NOID );
1034 for ( i = 0; i < ID_BLOCK_NIDS(idl) && ID_BLOCK_ID(idl, i) <= id; i++ ) {
1038 if ( i >= ID_BLOCK_NIDS(idl) ) {
1041 return( ID_BLOCK_ID(idl, i) );