1 /* idl.c - ldap id list handling routines */
4 * Copyright 1998-2000 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 static void cont_alloc( Datum cont, Datum key )
22 ldbm_datum_init( cont );
23 cont.dsize = 1 + sizeof(ID) + key.dsize;
24 cont.dptr = ch_malloc( cont.dsize );
26 memcpy( &((unsigned char *)cont.dptr)[1 + sizeof(ID)],
27 key.dptr, key.dsize );
30 static void cont_id( Datum cont, ID id )
34 for( i=1; i <= sizeof(id); i++) {
35 ((unsigned char *)cont.dptr)[i] = (unsigned char)(id & 0xFF);
41 static void cont_free( Datum cont )
46 /* Allocate an ID_BLOCK with room for nids ids */
48 idl_alloc( unsigned int nids )
52 /* nmax + nids + space for the ids */
53 new = (ID_BLOCK *) ch_calloc( (ID_BLOCK_IDS_OFFSET + nids), sizeof(ID) );
54 ID_BLOCK_NMAX(new) = nids;
55 ID_BLOCK_NIDS(new) = 0;
61 /* Allocate an empty ALLIDS ID_BLOCK */
63 idl_allids( Backend *be )
68 ID_BLOCK_NMAX(idl) = ID_BLOCK_ALLIDS_VALUE;
69 ID_BLOCK_NIDS(idl) = next_id_get( be );
74 /* Free an ID_BLOCK */
76 idl_free( ID_BLOCK *idl )
79 Debug( LDAP_DEBUG_TRACE,
80 "idl_free: called with NULL pointer\n",
89 /* Fetch an single ID_BLOCK from the cache */
100 /* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch_one\n", 0, 0, 0 ); */
102 data = ldbm_cache_fetch( db, key );
104 if( data.dptr == NULL ) {
108 idl = idl_dup((ID_BLOCK *) data.dptr);
110 ldbm_datum_free( db->dbc_db, data );
116 /* Fetch a set of ID_BLOCKs from the cache
118 * if block return is an ALLIDS block,
119 * return an new ALLIDS block
122 * construct super block from all blocks referenced by INDIRECT block
137 idl = idl_fetch_one( be, db, key );
143 if ( ID_BLOCK_ALLIDS(idl) ) {
145 /* make sure we have the current value of highest id */
147 idl = idl_allids( be );
152 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
158 * this is an indirect block which points to other blocks.
159 * we need to read in all the blocks it points to and construct
160 * a big id list containing all the ids, which we will return.
163 /* count the number of blocks & allocate space for pointers to them */
164 for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ )
166 tmp = (ID_BLOCK **) ch_malloc( (i + 1) * sizeof(ID_BLOCK *) );
168 /* read in all the blocks */
169 cont_alloc( data, key );
171 for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
172 cont_id( data, ID_BLOCK_ID(idl, i) );
174 if ( (tmp[i] = idl_fetch_one( be, db, data )) == NULL ) {
175 Debug( LDAP_DEBUG_ANY,
176 "idl_fetch: one returned NULL\n", 0, 0, 0 );
180 nids += ID_BLOCK_NIDS(tmp[i]);
186 /* allocate space for the big block */
187 idl = idl_alloc( nids );
188 ID_BLOCK_NIDS(idl) = nids;
191 /* copy in all the ids from the component blocks */
192 for ( i = 0; tmp[i] != NULL; i++ ) {
193 if ( tmp[i] == NULL ) {
198 (char *) &ID_BLOCK_ID(idl, nids),
199 (char *) &ID_BLOCK_ID(tmp[i], 0),
200 ID_BLOCK_NIDS(tmp[i]) * sizeof(ID) );
201 nids += ID_BLOCK_NIDS(tmp[i]);
205 free( (char *) tmp );
207 Debug( LDAP_DEBUG_TRACE, "<= idl_fetch %ld ids (%ld max)\n",
208 ID_BLOCK_NIDS(idl), ID_BLOCK_NMAX(idl), 0 );
213 /* store a single block */
224 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
226 ldbm_datum_init( data );
228 /* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */
230 data.dptr = (char *) idl;
231 data.dsize = (ID_BLOCK_IDS_OFFSET + ID_BLOCK_NMAX(idl)) * sizeof(ID);
234 Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
238 flags = LDBM_REPLACE;
239 rc = ldbm_cache_store( db, key, data, flags );
241 /* Debug( LDAP_DEBUG_TRACE, "<= idl_store %d\n", rc, 0, 0 ); */
245 /* split the block at id
246 * locate ID greater than or equal to id.
258 /* find where to split the block *//* XXX linear search XXX */
259 for ( nr = 0; nr < ID_BLOCK_NIDS(b) && id > ID_BLOCK_ID(b, nr); nr++ )
262 nl = ID_BLOCK_NIDS(b) - nr;
264 *right = idl_alloc( nr == 0 ? 1 : nr );
265 *left = idl_alloc( nl + (nr == 0 ? 0 : 1));
268 * everything before the id being inserted in the first block
269 * unless there is nothing, in which case the id being inserted
273 ID_BLOCK_NIDS(*right) = 1;
274 ID_BLOCK_ID(*right, 0) = id;
277 (char *) &ID_BLOCK_ID(*right, 0),
278 (char *) &ID_BLOCK_ID(b, 0),
280 ID_BLOCK_NIDS(*right) = nr;
281 ID_BLOCK_ID(*left, 0) = id;
284 /* the id being inserted & everything after in the second block */
286 (char *) &ID_BLOCK_ID(*left, (nr == 0 ? 0 : 1)),
287 (char *) &ID_BLOCK_ID(b, nr),
289 ID_BLOCK_NIDS(*left) = nl + (nr == 0 ? 0 : 1);
294 * idl_change_first - called when an indirect block's first key has
295 * changed, meaning it needs to be stored under a new key, and the
296 * header block pointing to it needs updating.
302 Datum hkey, /* header block key */
303 ID_BLOCK *h, /* header block */
304 int pos, /* pos in h to update */
305 Datum bkey, /* data block key */
306 ID_BLOCK *b /* data block */
311 /* Debug( LDAP_DEBUG_TRACE, "=> idl_change_first\n", 0, 0, 0 ); */
313 /* delete old key block */
314 if ( (rc = ldbm_cache_delete( db, bkey )) != 0 ) {
315 Debug( LDAP_DEBUG_ANY,
316 "idl_change_first: ldbm_cache_delete returned %d\n",
321 /* write block with new key */
322 cont_id( bkey, ID_BLOCK_ID(b, 0) );
324 if ( (rc = idl_store( be, db, bkey, b )) != 0 ) {
325 Debug( LDAP_DEBUG_ANY,
326 "idl_change_first: idl_store returned %d\n", rc, 0, 0 );
330 /* update + write indirect header block */
331 ID_BLOCK_ID(h, pos) = ID_BLOCK_ID(b, 0);
332 if ( (rc = idl_store( be, db, hkey, h )) != 0 ) {
333 Debug( LDAP_DEBUG_ANY,
334 "idl_change_first: idl_store returned %d\n", rc, 0, 0 );
351 ID_BLOCK *idl, *tmp, *tmp2, *tmp3;
354 if ( (idl = idl_fetch_one( be, db, key )) == NULL ) {
355 idl = idl_alloc( 1 );
356 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)++) = id;
357 rc = idl_store( be, db, key, idl );
363 if ( ID_BLOCK_ALLIDS( idl ) ) {
369 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
371 switch ( idl_insert( &idl, id, db->dbc_maxids ) ) {
372 case 0: /* id inserted - store the updated block */
374 rc = idl_store( be, db, key, idl );
377 case 2: /* id already there - nothing to do */
381 case 3: /* id not inserted - block must be split */
382 /* check threshold for marking this an all-id block */
383 if ( db->dbc_maxindirect < 2 ) {
385 idl = idl_allids( be );
386 rc = idl_store( be, db, key, idl );
390 idl_split_block( idl, id, &tmp, &tmp2 );
393 /* create the header indirect block */
394 idl = idl_alloc( 3 );
395 ID_BLOCK_NMAX(idl) = 3;
396 ID_BLOCK_NIDS(idl) = ID_BLOCK_INDIRECT_VALUE;
397 ID_BLOCK_ID(idl, 0) = ID_BLOCK_ID(tmp, 0);
398 ID_BLOCK_ID(idl, 1) = ID_BLOCK_ID(tmp2, 0);
399 ID_BLOCK_ID(idl, 2) = NOID;
402 rc = idl_store( be, db, key, idl );
404 cont_alloc( k2, key );
405 cont_id( k2, ID_BLOCK_ID(tmp, 0) );
407 rc = idl_store( be, db, k2, tmp );
409 cont_id( k2, ID_BLOCK_ID(tmp2, 0) );
410 rc = idl_store( be, db, k2, tmp2 );
424 * this is an indirect block which points to other blocks.
425 * we need to read in the block into which the id should be
426 * inserted, then insert the id and store the block. we might
427 * have to split the block if it is full, which means we also
428 * need to write a new "header" block.
431 /* select the block to try inserting into *//* XXX linear search XXX */
432 for ( i = 0; !ID_BLOCK_NOID(idl, i) && id > ID_BLOCK_ID(idl, i); i++ )
443 cont_alloc( k2, key );
444 cont_id( k2, ID_BLOCK_ID(idl, i) );
446 if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) {
447 Debug( LDAP_DEBUG_ANY, "idl_insert_key: nonexistent continuation block\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_insert_key: idl_store returned %d\n", rc, 0, 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 cont_alloc( k2, key );
489 cont_id( k2, ID_BLOCK_ID(idl, i) );
490 if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
491 Debug( LDAP_DEBUG_ANY,
492 "idl_insert_key: idl_fetch_one returned NULL\n",
494 /* split the original block */
499 /* If the new id is less than the last id in the
500 * current block, it must not be put into the next
501 * block. Push the last id of the current block
502 * into the next block instead.
504 if (id < ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp) - 1)) {
505 ID id2 = ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp) - 1);
508 ldbm_datum_init( k3 );
510 --ID_BLOCK_NIDS(tmp);
511 /* This must succeed since we just popped one
512 * ID off the end of it.
514 rc = idl_insert( &tmp, id, db->dbc_maxids );
516 k3.dptr = ch_malloc(k2.dsize);
518 memcpy(k3.dptr, k2.dptr, k3.dsize);
519 if ( (rc = idl_store( be, db, k3, tmp )) != 0 ) {
520 Debug( LDAP_DEBUG_ANY,
521 "idl_insert_key: idl_store returned %d\n", rc, 0, 0 );
527 /* This new id will necessarily be inserted
528 * as the first id of the next block by the
529 * following switch() statement.
533 switch ( (rc = idl_insert( &tmp2, id,
534 db->dbc_maxids )) ) {
535 case 1: /* id inserted first in block */
536 rc = idl_change_first( be, db, key, idl,
540 case 2: /* id already there - how? */
541 case 0: /* id inserted: this can never be
542 * the result of idl_insert, because
543 * we guaranteed that idl_change_first
544 * will always be called.
547 Debug( LDAP_DEBUG_ANY,
548 "idl_insert_key: id %ld already in next block\n",
552 assert( 0 ); /* not yet implemented */
558 case 3: /* split the original block */
567 * must split the block, write both new blocks + update
568 * and write the indirect header block.
571 rc = 0; /* optimistic */
574 /* count how many indirect blocks *//* XXX linear count XXX */
575 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
578 /* check it against all-id thresholed */
579 if ( j + 1 > db->dbc_maxindirect ) {
581 * we've passed the all-id threshold, meaning
582 * that this set of blocks should be replaced
583 * by a single "all-id" block. our job: delete
584 * all the indirect blocks, and replace the header
585 * block by an all-id block.
588 /* delete all indirect blocks */
589 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) {
590 cont_id( k2, ID_BLOCK_ID(idl, j) );
592 rc = ldbm_cache_delete( db, k2 );
595 /* store allid block in place of header block */
597 idl = idl_allids( be );
598 rc = idl_store( be, db, key, idl );
606 idl_split_block( tmp, id, &tmp2, &tmp3 );
609 /* create a new updated indirect header block */
610 tmp = idl_alloc( ID_BLOCK_NMAX(idl) + 1 );
611 ID_BLOCK_NIDS(tmp) = ID_BLOCK_INDIRECT_VALUE;
612 /* everything up to the split block */
614 (char *) &ID_BLOCK_ID(tmp, 0),
615 (char *) &ID_BLOCK_ID(idl, 0),
617 /* the two new blocks */
618 ID_BLOCK_ID(tmp, i) = ID_BLOCK_ID(tmp2, 0);
619 ID_BLOCK_ID(tmp, i + 1) = ID_BLOCK_ID(tmp3, 0);
620 /* everything after the split block */
622 (char *) &ID_BLOCK_ID(tmp, i + 2),
623 (char *) &ID_BLOCK_ID(idl, i + 1),
624 (ID_BLOCK_NMAX(idl) - i - 1) * sizeof(ID) );
626 /* store the header block */
627 rc = idl_store( be, db, key, tmp );
629 /* store the first id block */
630 cont_id( k2, ID_BLOCK_ID(tmp2, 0) );
631 rc = idl_store( be, db, k2, tmp2 );
633 /* store the second id block */
634 cont_id( k2, ID_BLOCK_ID(tmp3, 0) );
635 rc = idl_store( be, db, k2, tmp3 );
650 * idl_insert - insert an id into an id list.
654 * 1 id inserted, first id in block has changed
655 * 2 id not inserted, already there
656 * 3 id not inserted, block must be split
659 idl_insert( ID_BLOCK **idl, ID id, unsigned int maxids )
663 if ( ID_BLOCK_ALLIDS( *idl ) ) {
664 return( 2 ); /* already there */
667 /* is it already there? *//* XXX linear search XXX */
668 for ( i = 0; i < ID_BLOCK_NIDS(*idl) && id > ID_BLOCK_ID(*idl, i); i++ ) {
671 if ( i < ID_BLOCK_NIDS(*idl) && ID_BLOCK_ID(*idl, i) == id ) {
672 return( 2 ); /* already there */
675 /* do we need to make room for it? */
676 if ( ID_BLOCK_NIDS(*idl) == ID_BLOCK_NMAX(*idl) ) {
677 /* make room or indicate block needs splitting */
678 if ( ID_BLOCK_NMAX(*idl) >= maxids ) {
679 return( 3 ); /* block needs splitting */
682 ID_BLOCK_NMAX(*idl) *= 2;
683 if ( ID_BLOCK_NMAX(*idl) > maxids ) {
684 ID_BLOCK_NMAX(*idl) = maxids;
686 *idl = (ID_BLOCK *) ch_realloc( (char *) *idl,
687 (ID_BLOCK_NMAX(*idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
690 /* make a slot for the new id */
691 SAFEMEMCPY( &ID_BLOCK_ID(*idl, i+1), &ID_BLOCK_ID(*idl, i),
692 (ID_BLOCK_NIDS(*idl) - i) * sizeof(ID) );
694 ID_BLOCK_ID(*idl, i) = id;
695 ID_BLOCK_NIDS(*idl)++;
697 (char *) &ID_BLOCK_ID((*idl), ID_BLOCK_NIDS(*idl)),
699 (ID_BLOCK_NMAX(*idl) - ID_BLOCK_NIDS(*idl)) * sizeof(ID) );
701 return( i == 0 ? 1 : 0 ); /* inserted - first id changed or not */
718 if ( (idl = idl_fetch_one( be, db, key ) ) == NULL )
720 /* It wasn't found. Hmm... */
724 if ( ID_BLOCK_ALLIDS( idl ) ) {
729 if ( ! ID_BLOCK_INDIRECT( idl ) ) {
730 for ( i=0; i < ID_BLOCK_NIDS(idl); i++ ) {
731 if ( ID_BLOCK_ID(idl, i) == id ) {
732 if( --ID_BLOCK_NIDS(idl) == 0 ) {
733 ldbm_cache_delete( db, key );
737 &ID_BLOCK_ID(idl, i),
738 &ID_BLOCK_ID(idl, i+1),
739 (ID_BLOCK_NIDS(idl)-i) * sizeof(ID) );
741 ID_BLOCK_ID(idl, ID_BLOCK_NIDS(idl)) = NOID;
743 idl_store( be, db, key, idl );
749 /* We didn't find the ID. Hmmm... */
755 /* We have to go through an indirect block and find the ID
758 for ( nids = 0; !ID_BLOCK_NOID(idl, nids); nids++ )
761 cont_alloc( data, key );
763 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
766 cont_id( data, ID_BLOCK_ID(idl, j) );
768 if ( (tmp = idl_fetch_one( be, db, data )) == NULL ) {
769 Debug( LDAP_DEBUG_ANY,
770 "idl_delete_key: idl_fetch of returned NULL\n", 0, 0, 0 );
774 Now try to find the ID in tmp
776 for ( i=0; i < ID_BLOCK_NIDS(tmp); i++ )
778 if ( ID_BLOCK_ID(tmp, i) == id )
781 &ID_BLOCK_ID(tmp, i),
782 &ID_BLOCK_ID(tmp, i+1),
783 (ID_BLOCK_NIDS(tmp)-(i+1)) * sizeof(ID));
784 ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp)-1 ) = NOID;
785 ID_BLOCK_NIDS(tmp)--;
787 if ( ID_BLOCK_NIDS(tmp) ) {
788 idl_store ( be, db, data, tmp );
791 ldbm_cache_delete( db, data );
793 &ID_BLOCK_ID(idl, j),
794 &ID_BLOCK_ID(idl, j+1),
795 (nids-(j+1)) * sizeof(ID));
796 ID_BLOCK_ID(idl, nids-1) = NOID;
799 ldbm_cache_delete( db, key );
801 idl_store( be, db, key, idl );
818 /* return a duplicate of a single ID_BLOCK */
820 idl_dup( ID_BLOCK *idl )
828 new = idl_alloc( ID_BLOCK_NMAX(idl) );
833 (ID_BLOCK_NMAX(idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
839 /* return the smaller ID_BLOCK */
841 idl_min( ID_BLOCK *a, ID_BLOCK *b )
843 return( ID_BLOCK_NIDS(a) > ID_BLOCK_NIDS(b) ? b : a );
848 * idl_intersection - return a intersection b
857 unsigned int ai, bi, ni;
860 if ( a == NULL || b == NULL ) {
863 if ( ID_BLOCK_ALLIDS( a ) ) {
864 return( idl_dup( b ) );
866 if ( ID_BLOCK_ALLIDS( b ) ) {
867 return( idl_dup( a ) );
870 n = idl_dup( idl_min( a, b ) );
872 for ( ni = 0, ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) {
874 bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai);
880 if ( bi == ID_BLOCK_NIDS(b) ) {
884 if ( ID_BLOCK_ID(b, bi) == ID_BLOCK_ID(a, ai) ) {
885 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
893 ID_BLOCK_NIDS(n) = ni;
900 * idl_union - return a union b
909 unsigned int ai, bi, ni;
913 return( idl_dup( b ) );
916 return( idl_dup( a ) );
918 if ( ID_BLOCK_ALLIDS( a ) || ID_BLOCK_ALLIDS( b ) ) {
919 return( idl_allids( be ) );
922 if ( ID_BLOCK_NIDS(b) < ID_BLOCK_NIDS(a) ) {
928 n = idl_alloc( ID_BLOCK_NIDS(a) + ID_BLOCK_NIDS(b) );
930 for ( ni = 0, ai = 0, bi = 0;
931 ai < ID_BLOCK_NIDS(a) && bi < ID_BLOCK_NIDS(b);
934 if ( ID_BLOCK_ID(a, ai) < ID_BLOCK_ID(b, bi) ) {
935 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai++);
937 } else if ( ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai) ) {
938 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(b, bi++);
941 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
946 for ( ; ai < ID_BLOCK_NIDS(a); ai++ ) {
947 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
949 for ( ; bi < ID_BLOCK_NIDS(b); bi++ ) {
950 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(b, bi);
952 ID_BLOCK_NIDS(n) = ni;
959 * idl_notin - return a intersection ~b (or a minus b)
968 unsigned int ni, ai, bi;
974 if ( b == NULL || ID_BLOCK_ALLIDS( b )) {
975 return( idl_dup( a ) );
978 if ( ID_BLOCK_ALLIDS( a ) ) {
979 n = idl_alloc( SLAPD_LDBM_MIN_MAXIDS );
982 for ( ai = 1, bi = 0;
983 ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n) && bi < ID_BLOCK_NMAX(b);
986 if ( ID_BLOCK_ID(b, bi) == ai ) {
989 ID_BLOCK_ID(n, ni++) = ai;
993 for ( ; ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n); ai++ ) {
994 ID_BLOCK_ID(n, ni++) = ai;
997 if ( ni == ID_BLOCK_NMAX(n) ) {
999 return( idl_allids( be ) );
1001 ID_BLOCK_NIDS(n) = ni;
1009 for ( ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) {
1011 bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai);
1017 if ( bi == ID_BLOCK_NIDS(b) ) {
1021 if ( ID_BLOCK_ID(b, bi) != ID_BLOCK_ID(a, ai) ) {
1022 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
1026 for ( ; ai < ID_BLOCK_NIDS(a); ai++ ) {
1027 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
1029 ID_BLOCK_NIDS(n) = ni;
1034 /* return the first ID in the block
1037 * otherwise return NOID
1038 * otherwise return first ID
1040 * cursor is set to 1
1043 idl_firstid( ID_BLOCK *idl, ID *cursor )
1047 if ( idl == NULL || ID_BLOCK_NIDS(idl) == 0 ) {
1051 if ( ID_BLOCK_ALLIDS( idl ) ) {
1052 return( ID_BLOCK_NIDS(idl) > 1 ? 1 : NOID );
1055 return( ID_BLOCK_ID(idl, 0) );
1059 * if ALLIDS block, cursor is id.
1061 * if id < NIDS return id
1063 * otherwise cursor is index into block
1065 * return id at index then increment
1068 idl_nextid( ID_BLOCK *idl, ID *cursor )
1070 if ( ID_BLOCK_ALLIDS( idl ) ) {
1071 if( ++(*cursor) < ID_BLOCK_NIDS(idl) ) {
1078 if ( *cursor < ID_BLOCK_NIDS(idl) ) {
1079 return( ID_BLOCK_ID(idl, (*cursor)++) );