1 /* idl.c - ldap id list handling routines */
3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
12 #include <ac/socket.h>
14 #include "ldap_defaults.h"
16 #include "back-ldbm.h"
18 static ID_BLOCK* idl_dup( ID_BLOCK *idl );
20 /* Allocate an ID_BLOCK with room for nids ids */
22 idl_alloc( unsigned int nids )
26 /* nmax + nids + space for the ids */
27 new = (ID_BLOCK *) ch_calloc( (ID_BLOCK_IDS_OFFSET + nids), sizeof(ID) );
28 ID_BLOCK_NMAX(new) = nids;
29 ID_BLOCK_NIDS(new) = 0;
35 /* Allocate an empty ALLIDS ID_BLOCK */
37 idl_allids( Backend *be )
42 ID_BLOCK_NMAX(idl) = ID_BLOCK_ALLIDS_VALUE;
43 ID_BLOCK_NIDS(idl) = next_id_get( be );
48 /* Free an ID_BLOCK */
50 idl_free( ID_BLOCK *idl )
53 Debug( LDAP_DEBUG_TRACE,
54 "idl_free: called with NULL pointer\n",
63 /* Fetch an single ID_BLOCK from the cache */
74 /* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch_one\n", 0, 0, 0 ); */
76 data = ldbm_cache_fetch( db, key );
78 if( data.dptr == NULL ) {
82 idl = idl_dup( (ID_BLOCK *) data.dptr);
83 ldbm_datum_free( db->dbc_db, data );
89 /* Fetch a set of ID_BLOCKs from the cache
91 * if block return is an ALLIDS block,
92 * return an new ALLIDS block
95 * construct super block from all blocks referenced by INDIRECT block
111 idl = idl_fetch_one( be, db, key );
117 if ( ID_BLOCK_ALLIDS(idl) ) {
119 /* make sure we have the current value of highest id */
121 idl = idl_allids( be );
126 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
132 * this is an indirect block which points to other blocks.
133 * we need to read in all the blocks it points to and construct
134 * a big id list containing all the ids, which we will return.
137 /* count the number of blocks & allocate space for pointers to them */
138 for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ )
140 tmp = (ID_BLOCK **) ch_malloc( (i + 1) * sizeof(ID_BLOCK *) );
142 /* read in all the blocks */
143 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
145 for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
146 ldbm_datum_init( data );
148 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
149 ID_BLOCK_ID(idl, i), key.dptr );
152 data.dsize = strlen( kstr ) + 1;
154 if ( (tmp[i] = idl_fetch_one( be, db, data )) == NULL ) {
155 Debug( LDAP_DEBUG_ANY,
156 "idl_fetch of (%s) returns NULL\n", data.dptr, 0, 0 );
160 nids += ID_BLOCK_NIDS(tmp[i]);
166 /* allocate space for the big block */
167 idl = idl_alloc( nids );
168 ID_BLOCK_NIDS(idl) = nids;
171 /* copy in all the ids from the component blocks */
172 for ( i = 0; tmp[i] != NULL; i++ ) {
173 if ( tmp[i] == NULL ) {
178 (char *) &ID_BLOCK_ID(idl, nids),
179 (char *) &ID_BLOCK_ID(tmp[i], 0),
180 ID_BLOCK_NIDS(tmp[i]) * sizeof(ID) );
181 nids += ID_BLOCK_NIDS(tmp[i]);
185 free( (char *) tmp );
187 Debug( LDAP_DEBUG_TRACE, "<= idl_fetch %ld ids (%ld max)\n",
188 ID_BLOCK_NIDS(idl), ID_BLOCK_NMAX(idl), 0 );
193 /* store a single block */
204 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
206 ldbm_datum_init( data );
208 /* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */
210 data.dptr = (char *) idl;
211 data.dsize = (ID_BLOCK_IDS_OFFSET + ID_BLOCK_NMAX(idl)) * sizeof(ID);
214 Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
218 flags = LDBM_REPLACE;
219 if( li->li_dbcachewsync ) flags |= LDBM_SYNC;
220 rc = ldbm_cache_store( db, key, data, flags );
222 /* Debug( LDAP_DEBUG_TRACE, "<= idl_store %d\n", rc, 0, 0 ); */
226 /* split the block at id
227 * locate ID greater than or equal to id.
239 /* find where to split the block *//* XXX linear search XXX */
240 for ( nr = 0; nr < ID_BLOCK_NIDS(b) && id > ID_BLOCK_ID(b, nr); nr++ )
243 nl = ID_BLOCK_NIDS(b) - nr;
245 *right = idl_alloc( nr == 0 ? 1 : nr );
246 *left = idl_alloc( nl + (nr == 0 ? 0 : 1));
249 * everything before the id being inserted in the first block
250 * unless there is nothing, in which case the id being inserted
254 ID_BLOCK_NIDS(*right) = 1;
255 ID_BLOCK_ID(*right, 0) = id;
258 (char *) &ID_BLOCK_ID(*right, 0),
259 (char *) &ID_BLOCK_ID(b, 0),
261 ID_BLOCK_NIDS(*right) = nr;
262 ID_BLOCK_ID(*left, 0) = id;
265 /* the id being inserted & everything after in the second block */
267 (char *) &ID_BLOCK_ID(*left, (nr == 0 ? 0 : 1)),
268 (char *) &ID_BLOCK_ID(b, nr),
270 ID_BLOCK_NIDS(*left) = nl + (nr == 0 ? 0 : 1);
275 * idl_change_first - called when an indirect block's first key has
276 * changed, meaning it needs to be stored under a new key, and the
277 * header block pointing to it needs updating.
283 Datum hkey, /* header block key */
284 ID_BLOCK *h, /* header block */
285 int pos, /* pos in h to update */
286 Datum bkey, /* data block key */
287 ID_BLOCK *b /* data block */
292 /* Debug( LDAP_DEBUG_TRACE, "=> idl_change_first\n", 0, 0, 0 ); */
294 /* delete old key block */
295 if ( (rc = ldbm_cache_delete( db, bkey )) != 0 ) {
296 Debug( LDAP_DEBUG_ANY,
297 "ldbm_delete of (%s) returns %d\n", bkey.dptr, rc,
302 /* write block with new key */
303 sprintf( bkey.dptr, "%c%ld%s", CONT_PREFIX,
304 ID_BLOCK_ID(b, 0), hkey.dptr );
306 bkey.dsize = strlen( bkey.dptr ) + 1;
307 if ( (rc = idl_store( be, db, bkey, b )) != 0 ) {
308 Debug( LDAP_DEBUG_ANY,
309 "idl_store of (%s) returns %d\n", bkey.dptr, rc, 0 );
313 /* update + write indirect header block */
314 ID_BLOCK_ID(h, pos) = ID_BLOCK_ID(b, 0);
315 if ( (rc = idl_store( be, db, hkey, h )) != 0 ) {
316 Debug( LDAP_DEBUG_ANY,
317 "idl_store of (%s) returns %d\n", hkey.dptr, rc, 0 );
334 ID_BLOCK *idl, *tmp, *tmp2, *tmp3;
338 ldbm_datum_init( k2 );
340 if ( (idl = idl_fetch_one( be, db, key )) == NULL ) {
342 Statslog( LDAP_DEBUG_STATS, "=> idl_insert_key(): no key yet\n",
346 idl = idl_alloc( 1 );
347 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)++) = id;
348 rc = idl_store( be, db, key, idl );
354 if ( ID_BLOCK_ALLIDS( idl ) ) {
360 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
362 switch ( idl_insert( &idl, id, db->dbc_maxids ) ) {
363 case 0: /* id inserted - store the updated block */
365 rc = idl_store( be, db, key, idl );
368 case 2: /* id already there - nothing to do */
372 case 3: /* id not inserted - block must be split */
373 /* check threshold for marking this an all-id block */
374 if ( db->dbc_maxindirect < 2 ) {
376 idl = idl_allids( be );
377 rc = idl_store( be, db, key, idl );
381 idl_split_block( idl, id, &tmp, &tmp2 );
384 /* create the header indirect block */
385 idl = idl_alloc( 3 );
386 ID_BLOCK_NMAX(idl) = 3;
387 ID_BLOCK_NIDS(idl) = ID_BLOCK_INDIRECT_VALUE;
388 ID_BLOCK_ID(idl, 0) = ID_BLOCK_ID(tmp, 0);
389 ID_BLOCK_ID(idl, 1) = ID_BLOCK_ID(tmp2, 0);
390 ID_BLOCK_ID(idl, 2) = NOID;
393 rc = idl_store( be, db, key, idl );
395 /* store the first id block */
396 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
397 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
398 ID_BLOCK_ID(tmp, 0), key.dptr );
401 k2.dsize = strlen( kstr ) + 1;
402 rc = idl_store( be, db, k2, tmp );
404 /* store the second id block */
405 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
406 ID_BLOCK_ID(tmp2, 0), key.dptr );
408 k2.dsize = strlen( kstr ) + 1;
409 rc = idl_store( be, db, k2, tmp2 );
422 * this is an indirect block which points to other blocks.
423 * we need to read in the block into which the id should be
424 * inserted, then insert the id and store the block. we might
425 * have to split the block if it is full, which means we also
426 * need to write a new "header" block.
429 /* select the block to try inserting into *//* XXX linear search XXX */
430 for ( i = 0; !ID_BLOCK_NOID(idl, i) && id > ID_BLOCK_ID(idl, i); i++ )
440 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
441 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
442 ID_BLOCK_ID(idl, i), key.dptr );
444 k2.dsize = strlen( kstr ) + 1;
445 if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) {
446 Debug( LDAP_DEBUG_ANY, "nonexistent continuation block (%s)\n",
454 switch ( idl_insert( &tmp, id, db->dbc_maxids ) ) {
455 case 0: /* id inserted ok */
456 if ( (rc = idl_store( be, db, k2, tmp )) != 0 ) {
457 Debug( LDAP_DEBUG_ANY,
458 "idl_store of (%s) returns %d\n", k2.dptr, rc, 0 );
462 case 1: /* id inserted - first id in block has changed */
464 * key for this block has changed, so we have to
465 * write the block under the new key, delete the
466 * old key block + update and write the indirect
470 rc = idl_change_first( be, db, key, idl, i, k2, tmp );
473 case 2: /* id not inserted - already there */
476 case 3: /* id not inserted - block is full */
478 * first, see if it will fit in the next block,
479 * without splitting, unless we're trying to insert
480 * into the beginning of the first block.
483 /* is there a next block? */
484 if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) {
486 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
487 ID_BLOCK_ID(idl, i + 1), key.dptr );
489 k2.dsize = strlen( kstr ) + 1;
490 if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
491 Debug( LDAP_DEBUG_ANY,
492 "idl_fetch_one (%s) returns NULL\n",
497 switch ( (rc = idl_insert( &tmp2, id,
498 db->dbc_maxids )) ) {
499 case 1: /* id inserted first in block */
500 rc = idl_change_first( be, db, key, idl,
504 case 2: /* id already there - how? */
505 case 0: /* id inserted */
507 Debug( LDAP_DEBUG_ANY,
508 "id %ld already in next block\n",
517 case 3: /* split the original block */
524 * must split the block, write both new blocks + update
525 * and write the indirect header block.
528 /* count how many indirect blocks *//* XXX linear count XXX */
529 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
532 /* check it against all-id thresholed */
533 if ( j + 1 > db->dbc_maxindirect ) {
535 * we've passed the all-id threshold, meaning
536 * that this set of blocks should be replaced
537 * by a single "all-id" block. our job: delete
538 * all the indirect blocks, and replace the header
539 * block by an all-id block.
542 /* delete all indirect blocks */
543 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) {
544 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
545 ID_BLOCK_ID(idl, j), key.dptr );
547 k2.dsize = strlen( kstr ) + 1;
549 rc = ldbm_cache_delete( db, k2 );
552 /* store allid block in place of header block */
554 idl = idl_allids( be );
555 rc = idl_store( be, db, key, idl );
563 idl_split_block( tmp, id, &tmp2, &tmp3 );
566 /* create a new updated indirect header block */
567 tmp = idl_alloc( ID_BLOCK_NMAX(idl) + 1 );
568 ID_BLOCK_NIDS(tmp) = ID_BLOCK_INDIRECT_VALUE;
569 /* everything up to the split block */
571 (char *) &ID_BLOCK_ID(tmp, 0),
572 (char *) &ID_BLOCK_ID(idl, 0),
574 /* the two new blocks */
575 ID_BLOCK_ID(tmp, i) = ID_BLOCK_ID(tmp2, 0);
576 ID_BLOCK_ID(tmp, i + 1) = ID_BLOCK_ID(tmp3, 0);
577 /* everything after the split block */
579 (char *) &ID_BLOCK_ID(tmp, i + 2),
580 (char *) &ID_BLOCK_ID(idl, i + 1),
581 (ID_BLOCK_NMAX(idl) - i - 1) * sizeof(ID) );
583 /* store the header block */
584 rc = idl_store( be, db, key, tmp );
586 /* store the first id block */
587 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
588 ID_BLOCK_ID(tmp2, 0), key.dptr );
590 k2.dsize = strlen( kstr ) + 1;
591 rc = idl_store( be, db, k2, tmp2 );
593 /* store the second id block */
594 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
595 ID_BLOCK_ID(tmp3, 0), key.dptr );
597 k2.dsize = strlen( kstr ) + 1;
598 rc = idl_store( be, db, k2, tmp3 );
613 * idl_insert - insert an id into an id list.
617 * 1 id inserted, first id in block has changed
618 * 2 id not inserted, already there
619 * 3 id not inserted, block must be split
622 idl_insert( ID_BLOCK **idl, ID id, unsigned int maxids )
626 if ( ID_BLOCK_ALLIDS( *idl ) ) {
627 return( 2 ); /* already there */
630 /* is it already there? *//* XXX linear search XXX */
631 for ( i = 0; i < ID_BLOCK_NIDS(*idl) && id > ID_BLOCK_ID(*idl, i); i++ ) {
634 if ( i < ID_BLOCK_NIDS(*idl) && ID_BLOCK_ID(*idl, i) == id ) {
635 return( 2 ); /* already there */
638 /* do we need to make room for it? */
639 if ( ID_BLOCK_NIDS(*idl) == ID_BLOCK_NMAX(*idl) ) {
640 /* make room or indicate block needs splitting */
641 if ( ID_BLOCK_NMAX(*idl) >= maxids ) {
642 return( 3 ); /* block needs splitting */
645 ID_BLOCK_NMAX(*idl) *= 2;
646 if ( ID_BLOCK_NMAX(*idl) > maxids ) {
647 ID_BLOCK_NMAX(*idl) = maxids;
649 *idl = (ID_BLOCK *) ch_realloc( (char *) *idl,
650 (ID_BLOCK_NMAX(*idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
653 /* make a slot for the new id */
654 SAFEMEMCPY( &ID_BLOCK_ID(*idl, i), &ID_BLOCK_ID(*idl, i+1),
655 ID_BLOCK_NIDS(*idl) - i );
657 ID_BLOCK_ID(*idl, i) = id;
658 ID_BLOCK_NIDS(*idl)++;
660 (char *) &ID_BLOCK_ID((*idl), ID_BLOCK_NIDS(*idl)),
662 (ID_BLOCK_NMAX(*idl) - ID_BLOCK_NIDS(*idl)) * sizeof(ID) );
664 return( i == 0 ? 1 : 0 ); /* inserted - first id changed or not */
682 if ( (idl = idl_fetch_one( be, db, key ) ) == NULL )
684 /* It wasn't found. Hmm... */
688 if ( ID_BLOCK_ALLIDS( idl ) ) {
693 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
694 for ( i=0; i < ID_BLOCK_NIDS(idl); i++ ) {
695 if ( ID_BLOCK_ID(idl, i) == id ) {
696 if( --ID_BLOCK_NIDS(idl) == 0 ) {
697 ldbm_cache_delete( db, key );
701 &ID_BLOCK_ID(idl, i),
702 &ID_BLOCK_ID(idl, i+1),
703 (ID_BLOCK_NIDS(idl)-i) * sizeof(ID) );
705 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)) = NOID;
707 idl_store( be, db, key, idl );
713 /* We didn't find the ID. Hmmm... */
719 /* We have to go through an indirect block and find the ID
722 for ( nids = 0; !ID_BLOCK_NOID(idl, nids); nids++ )
724 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
726 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
728 ldbm_datum_init( data );
729 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
730 ID_BLOCK_ID(idl, j), key.dptr );
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
1005 * cursor is set to 1
1008 idl_firstid( ID_BLOCK *idl, ID *cursor )
1012 if ( idl == NULL || ID_BLOCK_NIDS(idl) == 0 ) {
1016 if ( ID_BLOCK_ALLIDS( idl ) ) {
1017 return( ID_BLOCK_NIDS(idl) > 1 ? 1 : NOID );
1020 return( ID_BLOCK_ID(idl, 0) );
1024 * if ALLIDS block, cursor is id.
1026 * if id < NIDS return id
1028 * otherwise cursor is index into block
1030 * return id at index then increment
1033 idl_nextid( ID_BLOCK *idl, ID *cursor )
1035 if ( ID_BLOCK_ALLIDS( idl ) ) {
1036 if( ++(*cursor) < ID_BLOCK_NIDS(idl) ) {
1043 if ( *cursor < ID_BLOCK_NIDS(idl) ) {
1044 return( ID_BLOCK_ID(idl, (*cursor)++) );