1 /* idl.c - ldap id list handling routines */
4 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.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);
84 ldbm_datum_free( db->dbc_db, data );
90 /* Fetch a set of ID_BLOCKs from the cache
92 * if block return is an ALLIDS block,
93 * return an new ALLIDS block
96 * construct super block from all blocks referenced by INDIRECT block
112 idl = idl_fetch_one( be, db, key );
118 if ( ID_BLOCK_ALLIDS(idl) ) {
120 /* make sure we have the current value of highest id */
122 idl = idl_allids( be );
127 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
133 * this is an indirect block which points to other blocks.
134 * we need to read in all the blocks it points to and construct
135 * a big id list containing all the ids, which we will return.
138 /* count the number of blocks & allocate space for pointers to them */
139 for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ )
141 tmp = (ID_BLOCK **) ch_malloc( (i + 1) * sizeof(ID_BLOCK *) );
143 /* read in all the blocks */
144 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
146 for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
147 ldbm_datum_init( data );
149 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
150 ID_BLOCK_ID(idl, i), key.dptr );
153 data.dsize = strlen( kstr ) + 1;
155 if ( (tmp[i] = idl_fetch_one( be, db, data )) == NULL ) {
156 Debug( LDAP_DEBUG_ANY,
157 "idl_fetch of (%s) returns NULL\n", data.dptr, 0, 0 );
161 nids += ID_BLOCK_NIDS(tmp[i]);
167 /* allocate space for the big block */
168 idl = idl_alloc( nids );
169 ID_BLOCK_NIDS(idl) = nids;
172 /* copy in all the ids from the component blocks */
173 for ( i = 0; tmp[i] != NULL; i++ ) {
174 if ( tmp[i] == NULL ) {
179 (char *) &ID_BLOCK_ID(idl, nids),
180 (char *) &ID_BLOCK_ID(tmp[i], 0),
181 ID_BLOCK_NIDS(tmp[i]) * sizeof(ID) );
182 nids += ID_BLOCK_NIDS(tmp[i]);
186 free( (char *) tmp );
188 Debug( LDAP_DEBUG_TRACE, "<= idl_fetch %ld ids (%ld max)\n",
189 ID_BLOCK_NIDS(idl), ID_BLOCK_NMAX(idl), 0 );
194 /* store a single block */
205 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
207 ldbm_datum_init( data );
209 /* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */
211 data.dptr = (char *) idl;
212 data.dsize = (ID_BLOCK_IDS_OFFSET + ID_BLOCK_NMAX(idl)) * sizeof(ID);
215 Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
219 flags = LDBM_REPLACE;
220 if( li->li_dbcachewsync ) flags |= LDBM_SYNC;
221 rc = ldbm_cache_store( db, key, data, flags );
223 /* Debug( LDAP_DEBUG_TRACE, "<= idl_store %d\n", rc, 0, 0 ); */
227 /* split the block at id
228 * locate ID greater than or equal to id.
240 /* find where to split the block *//* XXX linear search XXX */
241 for ( nr = 0; nr < ID_BLOCK_NIDS(b) && id > ID_BLOCK_ID(b, nr); nr++ )
244 nl = ID_BLOCK_NIDS(b) - nr;
246 *right = idl_alloc( nr == 0 ? 1 : nr );
247 *left = idl_alloc( nl + (nr == 0 ? 0 : 1));
250 * everything before the id being inserted in the first block
251 * unless there is nothing, in which case the id being inserted
255 ID_BLOCK_NIDS(*right) = 1;
256 ID_BLOCK_ID(*right, 0) = id;
259 (char *) &ID_BLOCK_ID(*right, 0),
260 (char *) &ID_BLOCK_ID(b, 0),
262 ID_BLOCK_NIDS(*right) = nr;
263 ID_BLOCK_ID(*left, 0) = id;
266 /* the id being inserted & everything after in the second block */
268 (char *) &ID_BLOCK_ID(*left, (nr == 0 ? 0 : 1)),
269 (char *) &ID_BLOCK_ID(b, nr),
271 ID_BLOCK_NIDS(*left) = nl + (nr == 0 ? 0 : 1);
276 * idl_change_first - called when an indirect block's first key has
277 * changed, meaning it needs to be stored under a new key, and the
278 * header block pointing to it needs updating.
284 Datum hkey, /* header block key */
285 ID_BLOCK *h, /* header block */
286 int pos, /* pos in h to update */
287 Datum bkey, /* data block key */
288 ID_BLOCK *b /* data block */
293 /* Debug( LDAP_DEBUG_TRACE, "=> idl_change_first\n", 0, 0, 0 ); */
295 /* delete old key block */
296 if ( (rc = ldbm_cache_delete( db, bkey )) != 0 ) {
297 Debug( LDAP_DEBUG_ANY,
298 "ldbm_delete of (%s) returns %d\n", bkey.dptr, rc,
303 /* write block with new key */
304 sprintf( bkey.dptr, "%c%ld%s", CONT_PREFIX,
305 ID_BLOCK_ID(b, 0), hkey.dptr );
307 bkey.dsize = strlen( bkey.dptr ) + 1;
308 if ( (rc = idl_store( be, db, bkey, b )) != 0 ) {
309 Debug( LDAP_DEBUG_ANY,
310 "idl_store of (%s) returns %d\n", bkey.dptr, rc, 0 );
314 /* update + write indirect header block */
315 ID_BLOCK_ID(h, pos) = ID_BLOCK_ID(b, 0);
316 if ( (rc = idl_store( be, db, hkey, h )) != 0 ) {
317 Debug( LDAP_DEBUG_ANY,
318 "idl_store of (%s) returns %d\n", hkey.dptr, rc, 0 );
335 ID_BLOCK *idl, *tmp, *tmp2, *tmp3;
339 ldbm_datum_init( k2 );
341 if ( (idl = idl_fetch_one( be, db, key )) == NULL ) {
343 Statslog( LDAP_DEBUG_STATS, "=> idl_insert_key(): no key yet\n",
347 idl = idl_alloc( 1 );
348 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)++) = id;
349 rc = idl_store( be, db, key, idl );
355 if ( ID_BLOCK_ALLIDS( idl ) ) {
361 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
363 switch ( idl_insert( &idl, id, db->dbc_maxids ) ) {
364 case 0: /* id inserted - store the updated block */
366 rc = idl_store( be, db, key, idl );
369 case 2: /* id already there - nothing to do */
373 case 3: /* id not inserted - block must be split */
374 /* check threshold for marking this an all-id block */
375 if ( db->dbc_maxindirect < 2 ) {
377 idl = idl_allids( be );
378 rc = idl_store( be, db, key, idl );
382 idl_split_block( idl, id, &tmp, &tmp2 );
385 /* create the header indirect block */
386 idl = idl_alloc( 3 );
387 ID_BLOCK_NMAX(idl) = 3;
388 ID_BLOCK_NIDS(idl) = ID_BLOCK_INDIRECT_VALUE;
389 ID_BLOCK_ID(idl, 0) = ID_BLOCK_ID(tmp, 0);
390 ID_BLOCK_ID(idl, 1) = ID_BLOCK_ID(tmp2, 0);
391 ID_BLOCK_ID(idl, 2) = NOID;
394 rc = idl_store( be, db, key, idl );
396 /* store the first id block */
397 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
398 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
399 ID_BLOCK_ID(tmp, 0), key.dptr );
402 k2.dsize = strlen( kstr ) + 1;
403 rc = idl_store( be, db, k2, tmp );
405 /* store the second id block */
406 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
407 ID_BLOCK_ID(tmp2, 0), key.dptr );
409 k2.dsize = strlen( kstr ) + 1;
410 rc = idl_store( be, db, k2, tmp2 );
423 * this is an indirect block which points to other blocks.
424 * we need to read in the block into which the id should be
425 * inserted, then insert the id and store the block. we might
426 * have to split the block if it is full, which means we also
427 * need to write a new "header" block.
430 /* select the block to try inserting into *//* XXX linear search XXX */
431 for ( i = 0; !ID_BLOCK_NOID(idl, i) && id > ID_BLOCK_ID(idl, i); i++ )
441 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
442 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
443 ID_BLOCK_ID(idl, i), key.dptr );
445 k2.dsize = strlen( kstr ) + 1;
446 if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) {
447 Debug( LDAP_DEBUG_ANY, "nonexistent continuation block (%s)\n",
455 switch ( idl_insert( &tmp, id, db->dbc_maxids ) ) {
456 case 0: /* id inserted ok */
457 if ( (rc = idl_store( be, db, k2, tmp )) != 0 ) {
458 Debug( LDAP_DEBUG_ANY,
459 "idl_store of (%s) returns %d\n", k2.dptr, rc, 0 );
463 case 1: /* id inserted - first id in block has changed */
465 * key for this block has changed, so we have to
466 * write the block under the new key, delete the
467 * old key block + update and write the indirect
471 rc = idl_change_first( be, db, key, idl, i, k2, tmp );
474 case 2: /* id not inserted - already there, do nothing */
478 case 3: /* id not inserted - block is full */
480 * first, see if it will fit in the next block,
481 * without splitting, unless we're trying to insert
482 * into the beginning of the first block.
485 /* is there a next block? */
486 if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) {
488 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
489 ID_BLOCK_ID(idl, i + 1), key.dptr );
491 k2.dsize = strlen( kstr ) + 1;
492 if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
493 Debug( LDAP_DEBUG_ANY,
494 "idl_fetch_one (%s) returns NULL\n",
496 /* split the original block */
500 switch ( (rc = idl_insert( &tmp2, id,
501 db->dbc_maxids )) ) {
502 case 1: /* id inserted first in block */
503 rc = idl_change_first( be, db, key, idl,
507 case 2: /* id already there - how? */
508 case 0: /* id inserted */
510 Debug( LDAP_DEBUG_ANY,
511 "id %ld already in next block\n",
520 case 3: /* split the original block */
529 * must split the block, write both new blocks + update
530 * and write the indirect header block.
533 rc = 0; /* optimistic */
536 /* count how many indirect blocks *//* XXX linear count XXX */
537 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
540 /* check it against all-id thresholed */
541 if ( j + 1 > db->dbc_maxindirect ) {
543 * we've passed the all-id threshold, meaning
544 * that this set of blocks should be replaced
545 * by a single "all-id" block. our job: delete
546 * all the indirect blocks, and replace the header
547 * block by an all-id block.
550 /* delete all indirect blocks */
551 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) {
552 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
553 ID_BLOCK_ID(idl, j), key.dptr );
555 k2.dsize = strlen( kstr ) + 1;
557 rc = ldbm_cache_delete( db, k2 );
560 /* store allid block in place of header block */
562 idl = idl_allids( be );
563 rc = idl_store( be, db, key, idl );
571 idl_split_block( tmp, id, &tmp2, &tmp3 );
574 /* create a new updated indirect header block */
575 tmp = idl_alloc( ID_BLOCK_NMAX(idl) + 1 );
576 ID_BLOCK_NIDS(tmp) = ID_BLOCK_INDIRECT_VALUE;
577 /* everything up to the split block */
579 (char *) &ID_BLOCK_ID(tmp, 0),
580 (char *) &ID_BLOCK_ID(idl, 0),
582 /* the two new blocks */
583 ID_BLOCK_ID(tmp, i) = ID_BLOCK_ID(tmp2, 0);
584 ID_BLOCK_ID(tmp, i + 1) = ID_BLOCK_ID(tmp3, 0);
585 /* everything after the split block */
587 (char *) &ID_BLOCK_ID(tmp, i + 2),
588 (char *) &ID_BLOCK_ID(idl, i + 1),
589 (ID_BLOCK_NMAX(idl) - i - 1) * sizeof(ID) );
591 /* store the header block */
592 rc = idl_store( be, db, key, tmp );
594 /* store the first id block */
595 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
596 ID_BLOCK_ID(tmp2, 0), key.dptr );
598 k2.dsize = strlen( kstr ) + 1;
599 rc = idl_store( be, db, k2, tmp2 );
601 /* store the second id block */
602 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
603 ID_BLOCK_ID(tmp3, 0), key.dptr );
605 k2.dsize = strlen( kstr ) + 1;
606 rc = idl_store( be, db, k2, tmp3 );
621 * idl_insert - insert an id into an id list.
625 * 1 id inserted, first id in block has changed
626 * 2 id not inserted, already there
627 * 3 id not inserted, block must be split
630 idl_insert( ID_BLOCK **idl, ID id, unsigned int maxids )
634 if ( ID_BLOCK_ALLIDS( *idl ) ) {
635 return( 2 ); /* already there */
638 /* is it already there? *//* XXX linear search XXX */
639 for ( i = 0; i < ID_BLOCK_NIDS(*idl) && id > ID_BLOCK_ID(*idl, i); i++ ) {
642 if ( i < ID_BLOCK_NIDS(*idl) && ID_BLOCK_ID(*idl, i) == id ) {
643 return( 2 ); /* already there */
646 /* do we need to make room for it? */
647 if ( ID_BLOCK_NIDS(*idl) == ID_BLOCK_NMAX(*idl) ) {
648 /* make room or indicate block needs splitting */
649 if ( ID_BLOCK_NMAX(*idl) >= maxids ) {
650 return( 3 ); /* block needs splitting */
653 ID_BLOCK_NMAX(*idl) *= 2;
654 if ( ID_BLOCK_NMAX(*idl) > maxids ) {
655 ID_BLOCK_NMAX(*idl) = maxids;
657 *idl = (ID_BLOCK *) ch_realloc( (char *) *idl,
658 (ID_BLOCK_NMAX(*idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
661 /* make a slot for the new id */
662 SAFEMEMCPY( &ID_BLOCK_ID(*idl, i+1), &ID_BLOCK_ID(*idl, i),
663 (ID_BLOCK_NIDS(*idl) - i) * sizeof(ID) );
665 ID_BLOCK_ID(*idl, i) = id;
666 ID_BLOCK_NIDS(*idl)++;
668 (char *) &ID_BLOCK_ID((*idl), ID_BLOCK_NIDS(*idl)),
670 (ID_BLOCK_NMAX(*idl) - ID_BLOCK_NIDS(*idl)) * sizeof(ID) );
672 return( i == 0 ? 1 : 0 ); /* inserted - first id changed or not */
690 if ( (idl = idl_fetch_one( be, db, key ) ) == NULL )
692 /* It wasn't found. Hmm... */
696 if ( ID_BLOCK_ALLIDS( idl ) ) {
701 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
702 for ( i=0; i < ID_BLOCK_NIDS(idl); i++ ) {
703 if ( ID_BLOCK_ID(idl, i) == id ) {
704 if( --ID_BLOCK_NIDS(idl) == 0 ) {
705 ldbm_cache_delete( db, key );
709 &ID_BLOCK_ID(idl, i),
710 &ID_BLOCK_ID(idl, i+1),
711 (ID_BLOCK_NIDS(idl)-i) * sizeof(ID) );
713 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)) = NOID;
715 idl_store( be, db, key, idl );
721 /* We didn't find the ID. Hmmm... */
727 /* We have to go through an indirect block and find the ID
730 for ( nids = 0; !ID_BLOCK_NOID(idl, nids); nids++ )
732 kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
734 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
737 ldbm_datum_init( data );
738 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
739 ID_BLOCK_ID(idl, j), key.dptr );
741 data.dsize = strlen( kstr ) + 1;
743 if ( (tmp = idl_fetch_one( be, db, data )) == NULL ) {
744 Debug( LDAP_DEBUG_ANY,
745 "idl_fetch of (%s) returns NULL\n", data.dptr, 0, 0 );
749 Now try to find the ID in tmp
751 for ( i=0; i < ID_BLOCK_NIDS(tmp); i++ )
753 if ( ID_BLOCK_ID(tmp, i) == id )
756 &ID_BLOCK_ID(tmp, i),
757 &ID_BLOCK_ID(tmp, i+1),
758 (ID_BLOCK_NIDS(tmp)-(i+1)) * sizeof(ID));
759 ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp)-1 ) = NOID;
760 ID_BLOCK_NIDS(tmp)--;
762 if ( ID_BLOCK_NIDS(tmp) ) {
763 idl_store ( be, db, data, tmp );
766 ldbm_cache_delete( db, data );
768 &ID_BLOCK_ID(idl, j),
769 &ID_BLOCK_ID(idl, j+1),
770 (nids-(j+1)) * sizeof(ID));
771 ID_BLOCK_ID(idl, nids-1) = NOID;
774 ldbm_cache_delete( db, key );
776 idl_store( be, db, key, idl );
792 /* return a duplicate of a single ID_BLOCK */
794 idl_dup( ID_BLOCK *idl )
802 new = idl_alloc( ID_BLOCK_NMAX(idl) );
807 (ID_BLOCK_NMAX(idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
813 /* return the smaller ID_BLOCK */
815 idl_min( ID_BLOCK *a, ID_BLOCK *b )
817 return( ID_BLOCK_NIDS(a) > ID_BLOCK_NIDS(b) ? b : a );
822 * idl_intersection - return a intersection b
831 unsigned int ai, bi, ni;
834 if ( a == NULL || b == NULL ) {
837 if ( ID_BLOCK_ALLIDS( a ) ) {
838 return( idl_dup( b ) );
840 if ( ID_BLOCK_ALLIDS( b ) ) {
841 return( idl_dup( a ) );
844 n = idl_dup( idl_min( a, b ) );
846 for ( ni = 0, ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) {
848 bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai);
854 if ( bi == ID_BLOCK_NIDS(b) ) {
858 if ( ID_BLOCK_ID(b, bi) == ID_BLOCK_ID(a, ai) ) {
859 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
867 ID_BLOCK_NIDS(n) = ni;
874 * idl_union - return a union b
883 unsigned int ai, bi, ni;
887 return( idl_dup( b ) );
890 return( idl_dup( a ) );
892 if ( ID_BLOCK_ALLIDS( a ) || ID_BLOCK_ALLIDS( b ) ) {
893 return( idl_allids( be ) );
896 if ( ID_BLOCK_NIDS(b) < ID_BLOCK_NIDS(a) ) {
902 n = idl_alloc( ID_BLOCK_NIDS(a) + ID_BLOCK_NIDS(b) );
904 for ( ni = 0, ai = 0, bi = 0;
905 ai < ID_BLOCK_NIDS(a) && bi < ID_BLOCK_NIDS(b);
908 if ( ID_BLOCK_ID(a, ai) < ID_BLOCK_ID(b, bi) ) {
909 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai++);
911 } else if ( ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai) ) {
912 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(b, bi++);
915 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
920 for ( ; ai < ID_BLOCK_NIDS(a); ai++ ) {
921 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
923 for ( ; bi < ID_BLOCK_NIDS(b); bi++ ) {
924 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(b, bi);
926 ID_BLOCK_NIDS(n) = ni;
933 * idl_notin - return a intersection ~b (or a minus b)
942 unsigned int ni, ai, bi;
948 if ( b == NULL || ID_BLOCK_ALLIDS( b )) {
949 return( idl_dup( a ) );
952 if ( ID_BLOCK_ALLIDS( a ) ) {
953 n = idl_alloc( SLAPD_LDBM_MIN_MAXIDS );
956 for ( ai = 1, bi = 0;
957 ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n) && bi < ID_BLOCK_NMAX(b);
960 if ( ID_BLOCK_ID(b, bi) == ai ) {
963 ID_BLOCK_ID(n, ni++) = ai;
967 for ( ; ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n); ai++ ) {
968 ID_BLOCK_ID(n, ni++) = ai;
971 if ( ni == ID_BLOCK_NMAX(n) ) {
973 return( idl_allids( be ) );
975 ID_BLOCK_NIDS(n) = ni;
983 for ( ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) {
985 bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai);
991 if ( bi == ID_BLOCK_NIDS(b) ) {
995 if ( ID_BLOCK_ID(b, bi) != ID_BLOCK_ID(a, ai) ) {
996 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
1000 for ( ; ai < ID_BLOCK_NIDS(a); ai++ ) {
1001 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
1003 ID_BLOCK_NIDS(n) = ni;
1008 /* return the first ID in the block
1011 * otherwise return NOID
1012 * otherwise return first ID
1014 * cursor is set to 1
1017 idl_firstid( ID_BLOCK *idl, ID *cursor )
1021 if ( idl == NULL || ID_BLOCK_NIDS(idl) == 0 ) {
1025 if ( ID_BLOCK_ALLIDS( idl ) ) {
1026 return( ID_BLOCK_NIDS(idl) > 1 ? 1 : NOID );
1029 return( ID_BLOCK_ID(idl, 0) );
1033 * if ALLIDS block, cursor is id.
1035 * if id < NIDS return id
1037 * otherwise cursor is index into block
1039 * return id at index then increment
1042 idl_nextid( ID_BLOCK *idl, ID *cursor )
1044 if ( ID_BLOCK_ALLIDS( idl ) ) {
1045 if( ++(*cursor) < ID_BLOCK_NIDS(idl) ) {
1052 if ( *cursor < ID_BLOCK_NIDS(idl) ) {
1053 return( ID_BLOCK_ID(idl, (*cursor)++) );