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);
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 */
477 case 3: /* id not inserted - block is full */
479 * first, see if it will fit in the next block,
480 * without splitting, unless we're trying to insert
481 * into the beginning of the first block.
484 /* is there a next block? */
485 if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) {
487 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
488 ID_BLOCK_ID(idl, i + 1), key.dptr );
490 k2.dsize = strlen( kstr ) + 1;
491 if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
492 Debug( LDAP_DEBUG_ANY,
493 "idl_fetch_one (%s) returns NULL\n",
498 switch ( (rc = idl_insert( &tmp2, id,
499 db->dbc_maxids )) ) {
500 case 1: /* id inserted first in block */
501 rc = idl_change_first( be, db, key, idl,
505 case 2: /* id already there - how? */
506 case 0: /* id inserted */
508 Debug( LDAP_DEBUG_ANY,
509 "id %ld already in next block\n",
518 case 3: /* split the original block */
525 * must split the block, write both new blocks + update
526 * and write the indirect header block.
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%ld%s", CONT_PREFIX,
546 ID_BLOCK_ID(idl, j), key.dptr );
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%ld%s", CONT_PREFIX,
589 ID_BLOCK_ID(tmp2, 0), key.dptr );
591 k2.dsize = strlen( kstr ) + 1;
592 rc = idl_store( be, db, k2, tmp2 );
594 /* store the second id block */
595 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
596 ID_BLOCK_ID(tmp3, 0), key.dptr );
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, unsigned 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 */
655 SAFEMEMCPY( &ID_BLOCK_ID(*idl, i), &ID_BLOCK_ID(*idl, i+1),
656 ID_BLOCK_NIDS(*idl) - i );
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 + CONT_SIZE );
727 for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ )
730 ldbm_datum_init( data );
731 sprintf( kstr, "%c%ld%s", CONT_PREFIX,
732 ID_BLOCK_ID(idl, j), key.dptr );
734 data.dsize = strlen( kstr ) + 1;
736 if ( (tmp = idl_fetch_one( be, db, data )) == NULL ) {
737 Debug( LDAP_DEBUG_ANY,
738 "idl_fetch of (%s) returns NULL\n", data.dptr, 0, 0 );
742 Now try to find the ID in tmp
744 for ( i=0; i < ID_BLOCK_NIDS(tmp); i++ )
746 if ( ID_BLOCK_ID(tmp, i) == id )
749 &ID_BLOCK_ID(tmp, i),
750 &ID_BLOCK_ID(tmp, i+1),
751 (ID_BLOCK_NIDS(tmp)-(i+1)) * sizeof(ID));
752 ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp)-1 ) = NOID;
753 ID_BLOCK_NIDS(tmp)--;
755 if ( ID_BLOCK_NIDS(tmp) ) {
756 idl_store ( be, db, data, tmp );
759 ldbm_cache_delete( db, data );
761 &ID_BLOCK_ID(idl, j),
762 &ID_BLOCK_ID(idl, j+1),
763 (nids-(j+1)) * sizeof(ID));
764 ID_BLOCK_ID(idl, nids-1) = NOID;
767 ldbm_cache_delete( db, key );
769 idl_store( be, db, key, idl );
785 /* return a duplicate of a single ID_BLOCK */
787 idl_dup( ID_BLOCK *idl )
795 new = idl_alloc( ID_BLOCK_NMAX(idl) );
800 (ID_BLOCK_NMAX(idl) + ID_BLOCK_IDS_OFFSET) * sizeof(ID) );
806 /* return the smaller ID_BLOCK */
808 idl_min( ID_BLOCK *a, ID_BLOCK *b )
810 return( ID_BLOCK_NIDS(a) > ID_BLOCK_NIDS(b) ? b : a );
815 * idl_intersection - return a intersection b
824 unsigned int ai, bi, ni;
827 if ( a == NULL || b == NULL ) {
830 if ( ID_BLOCK_ALLIDS( a ) ) {
831 return( idl_dup( b ) );
833 if ( ID_BLOCK_ALLIDS( b ) ) {
834 return( idl_dup( a ) );
837 n = idl_dup( idl_min( a, b ) );
839 for ( ni = 0, ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) {
841 bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai);
847 if ( bi == ID_BLOCK_NIDS(b) ) {
851 if ( ID_BLOCK_ID(b, bi) == ID_BLOCK_ID(a, ai) ) {
852 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
860 ID_BLOCK_NIDS(n) = ni;
867 * idl_union - return a union b
876 unsigned int ai, bi, ni;
880 return( idl_dup( b ) );
883 return( idl_dup( a ) );
885 if ( ID_BLOCK_ALLIDS( a ) || ID_BLOCK_ALLIDS( b ) ) {
886 return( idl_allids( be ) );
889 if ( ID_BLOCK_NIDS(b) < ID_BLOCK_NIDS(a) ) {
895 n = idl_alloc( ID_BLOCK_NIDS(a) + ID_BLOCK_NIDS(b) );
897 for ( ni = 0, ai = 0, bi = 0;
898 ai < ID_BLOCK_NIDS(a) && bi < ID_BLOCK_NIDS(b);
901 if ( ID_BLOCK_ID(a, ai) < ID_BLOCK_ID(b, bi) ) {
902 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai++);
904 } else if ( ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai) ) {
905 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(b, bi++);
908 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
913 for ( ; ai < ID_BLOCK_NIDS(a); ai++ ) {
914 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
916 for ( ; bi < ID_BLOCK_NIDS(b); bi++ ) {
917 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(b, bi);
919 ID_BLOCK_NIDS(n) = ni;
926 * idl_notin - return a intersection ~b (or a minus b)
935 unsigned int ni, ai, bi;
941 if ( b == NULL || ID_BLOCK_ALLIDS( b )) {
942 return( idl_dup( a ) );
945 if ( ID_BLOCK_ALLIDS( a ) ) {
946 n = idl_alloc( SLAPD_LDBM_MIN_MAXIDS );
949 for ( ai = 1, bi = 0;
950 ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n) && bi < ID_BLOCK_NMAX(b);
953 if ( ID_BLOCK_ID(b, bi) == ai ) {
956 ID_BLOCK_ID(n, ni++) = ai;
960 for ( ; ai < ID_BLOCK_NIDS(a) && ni < ID_BLOCK_NMAX(n); ai++ ) {
961 ID_BLOCK_ID(n, ni++) = ai;
964 if ( ni == ID_BLOCK_NMAX(n) ) {
966 return( idl_allids( be ) );
968 ID_BLOCK_NIDS(n) = ni;
976 for ( ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) {
978 bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai);
984 if ( bi == ID_BLOCK_NIDS(b) ) {
988 if ( ID_BLOCK_ID(b, bi) != ID_BLOCK_ID(a, ai) ) {
989 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
993 for ( ; ai < ID_BLOCK_NIDS(a); ai++ ) {
994 ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai);
996 ID_BLOCK_NIDS(n) = ni;
1001 /* return the first ID in the block
1004 * otherwise return NOID
1005 * otherwise return first ID
1007 * cursor is set to 1
1010 idl_firstid( ID_BLOCK *idl, ID *cursor )
1014 if ( idl == NULL || ID_BLOCK_NIDS(idl) == 0 ) {
1018 if ( ID_BLOCK_ALLIDS( idl ) ) {
1019 return( ID_BLOCK_NIDS(idl) > 1 ? 1 : NOID );
1022 return( ID_BLOCK_ID(idl, 0) );
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 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)++) );