1 /* idl.c - ldap id list handling routines */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
16 #define IDL_MAX(x,y) ( x > y ? x : y )
17 #define IDL_MIN(x,y) ( x < y ? x : y )
19 #define IDL_CMP(x,y) ( x < y ? -1 : ( x > y ? 1 : 0 ) )
22 #define IDL_LRU_DELETE( bdb, e ) do { \
23 if ( e->idl_lru_prev != NULL ) { \
24 e->idl_lru_prev->idl_lru_next = e->idl_lru_next; \
26 bdb->bi_idl_lru_head = e->idl_lru_next; \
28 if ( e->idl_lru_next != NULL ) { \
29 e->idl_lru_next->idl_lru_prev = e->idl_lru_prev; \
31 bdb->bi_idl_lru_tail = e->idl_lru_prev; \
35 #define IDL_LRU_ADD( bdb, e ) do { \
36 e->idl_lru_next = bdb->bi_idl_lru_head; \
37 if ( e->idl_lru_next != NULL ) { \
38 e->idl_lru_next->idl_lru_prev = (e); \
40 (bdb)->bi_idl_lru_head = (e); \
41 e->idl_lru_prev = NULL; \
42 if ( (bdb)->bi_idl_lru_tail == NULL ) { \
43 (bdb)->bi_idl_lru_tail = (e); \
48 bdb_idl_entry_cmp( const void *v_idl1, const void *v_idl2 )
50 const bdb_idl_cache_entry_t *idl1 = v_idl1, *idl2 = v_idl2;
53 if ((rc = idl1->db - idl2->db )) return rc;
54 if ((rc = idl1->kstr.bv_len - idl2->kstr.bv_len )) return rc;
55 return ( memcmp ( idl1->kstr.bv_val, idl2->kstr.bv_val , idl1->kstr.bv_len ) );
60 static void idl_check( ID *ids )
62 if( BDB_IDL_IS_RANGE( ids ) ) {
63 assert( BDB_IDL_RANGE_FIRST(ids) <= BDB_IDL_RANGE_LAST(ids) );
66 for( i=1; i < ids[0]; i++ ) {
67 assert( ids[i+1] > ids[i] );
73 static void idl_dump( ID *ids )
75 if( BDB_IDL_IS_RANGE( ids ) ) {
77 LDAP_LOG( INDEX, INFO, "IDL: range (%ld - %ld)\n",
78 (long) BDB_IDL_RANGE_FIRST( ids ),
79 (long) BDB_IDL_RANGE_LAST( ids ), 0 );
81 Debug( LDAP_DEBUG_ANY,
82 "IDL: range ( %ld - %ld )\n",
83 (long) BDB_IDL_RANGE_FIRST( ids ),
84 (long) BDB_IDL_RANGE_LAST( ids ) );
90 LDAP_LOG( INDEX, INFO, "IDL: size %ld", (long) ids[0], 0, 0 );
92 Debug( LDAP_DEBUG_ANY, "IDL: size %ld", (long) ids[0], 0, 0 );
95 for( i=1; i<=ids[0]; i++ ) {
97 Debug( LDAP_DEBUG_ANY, "\n", 0, 0, 0 );
100 LDAP_LOG( INDEX, INFO, "%02lx",(long)ids[i], 0, 0 );
102 Debug( LDAP_DEBUG_ANY, " %02lx", (long) ids[i], 0, 0 );
106 Debug( LDAP_DEBUG_ANY, "\n", 0, 0, 0 );
111 #endif /* IDL_DEBUG > 1 */
112 #endif /* IDL_DEBUG > 0 */
114 unsigned bdb_idl_search( ID *ids, ID id )
116 #define IDL_BINARY_SEARCH 1
117 #ifdef IDL_BINARY_SEARCH
119 * binary search of id in ids
120 * if found, returns position of id
121 * if not found, returns first postion greater than id
134 cursor = base + pivot;
135 val = IDL_CMP( id, ids[cursor + 1] );
140 } else if ( val > 0 ) {
156 /* (reverse) linear search */
163 for( i=ids[0]; i; i-- ) {
173 int bdb_idl_insert( ID *ids, ID id )
175 unsigned x = bdb_idl_search( ids, id );
179 LDAP_LOG( INDEX, DETAIL1, "insert: %04lx at %d\n", (long) id, x, 0 );
181 Debug( LDAP_DEBUG_ANY, "insert: %04lx at %d\n", (long) id, x, 0 );
195 if ( x <= ids[0] && ids[x] == id ) {
200 if ( ++ids[0] >= BDB_IDL_DB_MAX ) {
203 ids[2] = ids[ids[0]-1];
204 } else if ( ids[ids[0]-1] < id ) {
207 ids[2] = ids[ids[0]-1];
213 AC_MEMCPY( &ids[x+1], &ids[x], (ids[0]-x) * sizeof(ID) );
227 static int idl_delete( ID *ids, ID id )
229 unsigned x = bdb_idl_search( ids, id );
233 LDAP_LOG( INDEX, DETAIL1, "delete: %04lx at %d\n", (long) id, x, 0 );
235 Debug( LDAP_DEBUG_ANY, "delete: %04lx at %d\n", (long) id, x, 0 );
249 if( x > ids[0] || ids[x] != id ) {
253 } else if ( --ids[0] == 0 ) {
259 AC_MEMCPY( &ids[x], &ids[x+1], (1+ids[0]-x) * sizeof(ID) );
277 if ( key->size == sizeof( ID ) ) {
278 unsigned char *c = key->data;
279 sprintf( buf, "[%02x%02x%02x%02x]", c[0], c[1], c[2], c[3] );
294 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
302 int flags = bdb->bi_db_opflags | DB_MULTIPLE;
303 #ifdef SLAP_IDL_CACHE
304 bdb_idl_cache_entry_t idl_tmp;
307 /* If using BerkeleyDB 4.0, the buf must be large enough to
308 * grab the entire IDL in one get(), otherwise BDB will leak
309 * resources on subsequent get's. We can safely call get()
310 * twice - once for the data, and once to get the DB_NOTFOUND
311 * result meaning there's no more data. See ITS#2040 for details.
312 * This bug is fixed in BDB 4.1 so a smaller buffer will work if
313 * stack space is too limited.
315 * configure now requires Berkeley DB 4.1.
317 #if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR == 0)
318 # define BDB_ENOUGH 5
320 # define BDB_ENOUGH 1
322 ID buf[BDB_IDL_DB_SIZE*BDB_ENOUGH];
327 LDAP_LOG( INDEX, ARGS,
328 "bdb_idl_fetch_key: %s\n",
329 bdb_show_key( key, keybuf ), 0, 0 );
331 Debug( LDAP_DEBUG_ARGS,
332 "bdb_idl_fetch_key: %s\n",
333 bdb_show_key( key, keybuf ), 0, 0 );
336 assert( ids != NULL );
338 #ifdef SLAP_IDL_CACHE
339 if ( bdb->bi_idl_cache_max_size ) {
340 bdb_idl_cache_entry_t *matched_idl_entry;
341 DBT2bv( key, &idl_tmp.kstr );
343 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
344 matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
346 if ( matched_idl_entry != NULL ) {
347 BDB_IDL_CPY( ids, matched_idl_entry->idl );
348 IDL_LRU_DELETE( bdb, matched_idl_entry );
349 IDL_LRU_ADD( bdb, matched_idl_entry );
350 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
353 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
360 data.ulen = sizeof(buf);
361 data.flags = DB_DBT_USERMEM;
363 if ( tid ) flags |= DB_RMW;
365 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
368 LDAP_LOG( INDEX, ERR,
369 "bdb_idl_fetch_key: cursor failed: %s (%d)\n",
370 db_strerror(rc), rc, 0 );
372 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
373 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
378 rc = cursor->c_get( cursor, key, &data, flags | DB_SET );
384 DB_MULTIPLE_INIT( ptr, &data );
386 DB_MULTIPLE_NEXT(ptr, &data, j, len);
389 AC_MEMCPY( i, j, sizeof(ID) );
392 rc = cursor->c_get( cursor, key, &data, flags | DB_NEXT_DUP );
394 if ( rc == DB_NOTFOUND ) rc = 0;
396 /* On disk, a range is denoted by 0 in the first element */
398 if (ids[0] != BDB_IDL_RANGE_SIZE) {
400 LDAP_LOG( INDEX, ERR,
401 "=> bdb_idl_fetch_key: range size mismatch: "
402 "expected %ld, got %ld\n",
403 BDB_IDL_RANGE_SIZE, ids[0], 0 );
405 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
406 "range size mismatch: expected %d, got %ld\n",
407 BDB_IDL_RANGE_SIZE, ids[0], 0 );
409 cursor->c_close( cursor );
412 BDB_IDL_RANGE( ids, ids[2], ids[3] );
414 data.size = BDB_IDL_SIZEOF(ids);
417 rc2 = cursor->c_close( cursor );
420 LDAP_LOG( INDEX, ERR,
421 "bdb_idl_fetch_key: close failed: %s (%d)\n",
422 db_strerror(rc2), rc2, 0 );
424 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
425 "close failed: %s (%d)\n", db_strerror(rc2), rc2, 0 );
430 if( rc == DB_NOTFOUND ) {
433 } else if( rc != 0 ) {
435 LDAP_LOG( INDEX, ERR,
436 "bdb_idl_fetch_key: get failed: %s (%d)\n",
437 db_strerror(rc), rc, 0 );
439 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
440 "get failed: %s (%d)\n",
441 db_strerror(rc), rc, 0 );
445 } else if ( data.size == 0 || data.size % sizeof( ID ) ) {
446 /* size not multiple of ID size */
448 LDAP_LOG( INDEX, ERR,
449 "bdb_idl_fetch_key: odd size: expected %ld multiple, got %ld\n",
450 (long) sizeof( ID ), (long) data.size, 0 );
452 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
453 "odd size: expected %ld multiple, got %ld\n",
454 (long) sizeof( ID ), (long) data.size, 0 );
458 } else if ( data.size != BDB_IDL_SIZEOF(ids) ) {
461 LDAP_LOG( INDEX, ERR,
462 "bdb_idl_fetch_key: get size mismatch: expected %ld, got %ld\n",
463 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
465 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
466 "get size mismatch: expected %ld, got %ld\n",
467 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
472 #ifdef SLAP_IDL_CACHE
473 if ( bdb->bi_idl_cache_max_size ) {
474 bdb_idl_cache_entry_t *ee;
475 ee = (bdb_idl_cache_entry_t *) ch_malloc(
476 sizeof( bdb_idl_cache_entry_t ) );
478 ee->idl = (ID*) ch_malloc( BDB_IDL_SIZEOF ( ids ) );
479 ee->idl_lru_prev = NULL;
480 ee->idl_lru_next = NULL;
481 BDB_IDL_CPY( ee->idl, ids );
482 ber_dupbv( &ee->kstr, &idl_tmp.kstr );
483 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
484 if ( avl_insert( &bdb->bi_idl_tree, (caddr_t) ee,
485 bdb_idl_entry_cmp, avl_dup_error ))
487 ch_free( ee->kstr.bv_val );
491 IDL_LRU_ADD( bdb, ee );
492 if ( ++bdb->bi_idl_cache_size > bdb->bi_idl_cache_max_size ) {
494 while ( bdb->bi_idl_lru_tail != NULL && i < 10 ) {
495 ee = bdb->bi_idl_lru_tail;
496 avl_delete( &bdb->bi_idl_tree, (caddr_t) ee,
498 IDL_LRU_DELETE( bdb, ee );
500 --bdb->bi_idl_cache_size;
501 ch_free( ee->kstr.bv_val );
507 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
523 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
533 LDAP_LOG( INDEX, ARGS,
534 "bdb_idl_insert_key: %lx %s\n",
535 (long) id, bdb_show_key( key, buf ), 0 );
537 Debug( LDAP_DEBUG_ARGS,
538 "bdb_idl_insert_key: %lx %s\n",
539 (long) id, bdb_show_key( key, buf ), 0 );
543 assert( id != NOID );
545 #ifdef SLAP_IDL_CACHE
546 if ( bdb->bi_idl_cache_size ) {
547 bdb_idl_cache_entry_t *matched_idl_entry, idl_tmp;
548 DBT2bv( key, &idl_tmp.kstr );
550 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
551 matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
553 if ( matched_idl_entry != NULL ) {
554 avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry,
556 --bdb->bi_idl_cache_size;
557 IDL_LRU_DELETE( bdb, matched_idl_entry );
558 free( matched_idl_entry->kstr.bv_val );
559 free( matched_idl_entry->idl );
560 free( matched_idl_entry );
562 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
567 data.size = sizeof( ID );
568 data.ulen = data.size;
569 data.flags = DB_DBT_USERMEM;
571 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
574 LDAP_LOG( INDEX, ERR,
575 "bdb_idl_insert_key: cursor failed: %s (%d)\n",
576 db_strerror(rc), rc, 0 );
578 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
579 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
584 /* Fetch the first data item for this key, to see if it
585 * exists and if it's a range.
587 rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
591 /* not a range, count the number of items */
593 rc = cursor->c_count( cursor, &count, 0 );
598 if ( count >= BDB_IDL_DB_MAX ) {
599 /* No room, convert to a range */
602 key2.dlen = key2.ulen;
603 key2.flags |= DB_DBT_PARTIAL;
607 rc = cursor->c_get( cursor, &key2, &data, DB_NEXT_NODUP );
608 if ( rc != 0 && rc != DB_NOTFOUND ) {
609 err = "c_get next_nodup";
612 if ( rc == DB_NOTFOUND ) {
613 rc = cursor->c_get( cursor, key, &data, DB_LAST );
619 rc = cursor->c_get( cursor, key, &data, DB_PREV );
629 rc = db->del( db, tid, key, 0 );
636 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
642 rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
648 rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
654 /* There's room, just store it */
658 /* It's a range, see if we need to rewrite
663 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
670 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
676 if ( id < lo || id > hi ) {
677 /* Delete the current lo/hi */
678 rc = cursor->c_del( cursor, 0 );
684 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
691 } else if ( rc == DB_NOTFOUND ) {
692 put1: data.data = &id;
693 rc = cursor->c_put( cursor, key, &data, DB_NODUPDATA );
694 /* Don't worry if it's already there */
695 if ( rc != 0 && rc != DB_KEYEXIST ) {
700 /* initial c_get failed, nothing was done */
703 LDAP_LOG( INDEX, ERR,
704 "bdb_idl_insert_key: %s failed: %s (%d)\n",
705 err, db_strerror(rc), rc );
707 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
708 "%s failed: %s (%d)\n", err, db_strerror(rc), rc );
710 cursor->c_close( cursor );
713 rc = cursor->c_close( cursor );
716 LDAP_LOG( INDEX, ERR,
717 "bdb_idl_insert_key: c_close failed: %s (%d)\n",
718 db_strerror(rc), rc, 0 );
720 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
721 "c_close failed: %s (%d)\n",
722 db_strerror(rc), rc, 0 );
736 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
746 LDAP_LOG( INDEX, ARGS,
747 "bdb_idl_delete_key: %lx %s\n",
748 (long) id, bdb_show_key( key, buf ), 0 );
750 Debug( LDAP_DEBUG_ARGS,
751 "bdb_idl_delete_key: %lx %s\n",
752 (long) id, bdb_show_key( key, buf ), 0 );
755 assert( id != NOID );
757 #ifdef SLAP_IDL_CACHE
758 if ( bdb->bi_idl_cache_max_size ) {
759 bdb_idl_cache_entry_t *matched_idl_entry, idl_tmp;
760 DBT2bv( key, &idl_tmp.kstr );
762 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
763 matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
765 if ( matched_idl_entry != NULL ) {
766 avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry,
768 --bdb->bi_idl_cache_size;
769 IDL_LRU_DELETE( bdb, matched_idl_entry );
770 free( matched_idl_entry->kstr.bv_val );
771 free( matched_idl_entry->idl );
772 free( matched_idl_entry );
774 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
780 data.size = sizeof( id );
781 data.ulen = data.size;
782 data.flags = DB_DBT_USERMEM;
784 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
787 LDAP_LOG( INDEX, ERR,
788 "bdb_idl_delete_key: cursor failed: %s (%d)\n",
789 db_strerror(rc), rc, 0 );
791 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
792 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
796 /* Fetch the first data item for this key, to see if it
797 * exists and if it's a range.
799 rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
803 /* Not a range, just delete it */
805 /* position to correct item */
807 rc = cursor->c_get( cursor, key, &data,
808 DB_GET_BOTH | DB_RMW );
814 rc = cursor->c_del( cursor, 0 );
820 /* It's a range, see if we need to rewrite
825 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
832 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
838 if ( id == lo || id == hi ) {
842 } else if ( id == hi ) {
847 /* The range has collapsed... */
848 rc = db->del( db, tid, key, 0 );
854 rc = cursor->c_del( cursor, 0 );
862 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
871 /* initial c_get failed, nothing was done */
873 if ( rc != DB_NOTFOUND ) {
875 LDAP_LOG( INDEX, ERR,
876 "bdb_idl_delete_key: %s failed: %s (%d)\n",
877 err, db_strerror(rc), rc );
879 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
880 "%s failed: %s (%d)\n", err, db_strerror(rc), rc );
883 cursor->c_close( cursor );
886 rc = cursor->c_close( cursor );
889 LDAP_LOG( INDEX, ERR, "bdb_idl_delete_key: c_close failed: %s (%d)\n",
890 db_strerror(rc), rc, 0 );
892 Debug( LDAP_DEBUG_ANY,
893 "=> bdb_idl_delete_key: c_close failed: %s (%d)\n",
894 db_strerror(rc), rc, 0 );
903 * idl_intersection - return a = a intersection b
906 bdb_idl_intersection(
912 ID cursora = 0, cursorb = 0, cursorc;
915 if ( BDB_IDL_IS_ZERO( a ) || BDB_IDL_IS_ZERO( b ) ) {
920 idmin = IDL_MAX( BDB_IDL_FIRST(a), BDB_IDL_FIRST(b) );
921 idmax = IDL_MIN( BDB_IDL_LAST(a), BDB_IDL_LAST(b) );
922 if ( idmin > idmax ) {
925 } else if ( idmin == idmax ) {
931 if ( BDB_IDL_IS_RANGE( a ) ) {
932 if ( BDB_IDL_IS_RANGE(b) ) {
933 /* If both are ranges, just shrink the boundaries */
938 /* Else swap so that b is the range, a is a list */
946 /* If a range completely covers the list, the result is
947 * just the list. If idmin to idmax is contiguous, just
948 * turn it into a range.
950 if ( BDB_IDL_IS_RANGE( b )
951 && BDB_IDL_FIRST( b ) <= BDB_IDL_FIRST( a )
952 && BDB_IDL_LAST( b ) >= BDB_IDL_LAST( a ) ) {
953 if (idmax - idmin + 1 == a[0])
962 /* Fine, do the intersection one element at a time.
963 * First advance to idmin in both IDLs.
965 cursora = cursorb = idmin;
966 ida = bdb_idl_first( a, &cursora );
967 idb = bdb_idl_first( b, &cursorb );
970 while( ida <= idmax || idb <= idmax ) {
973 ida = bdb_idl_next( a, &cursora );
974 idb = bdb_idl_next( b, &cursorb );
975 } else if ( ida < idb ) {
976 ida = bdb_idl_next( a, &cursora );
978 idb = bdb_idl_next( b, &cursorb );
991 * idl_union - return a = a union b
999 ID cursora = 0, cursorb = 0, cursorc;
1001 if ( BDB_IDL_IS_ZERO( b ) ) {
1005 if ( BDB_IDL_IS_ZERO( a ) ) {
1006 BDB_IDL_CPY( a, b );
1010 if ( BDB_IDL_IS_RANGE( a ) || BDB_IDL_IS_RANGE(b) ) {
1011 over: ida = IDL_MIN( BDB_IDL_FIRST(a), BDB_IDL_FIRST(b) );
1012 idb = IDL_MAX( BDB_IDL_LAST(a), BDB_IDL_LAST(b) );
1019 ida = bdb_idl_first( a, &cursora );
1020 idb = bdb_idl_first( b, &cursorb );
1024 /* The distinct elements of a are cat'd to b */
1025 while( ida != NOID || idb != NOID ) {
1027 if( ++cursorc > BDB_IDL_UM_MAX ) {
1031 ida = bdb_idl_next( a, &cursora );
1035 ida = bdb_idl_next( a, &cursora );
1036 idb = bdb_idl_next( b, &cursorb );
1040 /* b is copied back to a in sorted order */
1045 while (cursorb <= b[0] || cursorc <= a[0]) {
1050 if (cursorb <= b[0] && b[cursorb] < idb)
1051 a[cursora++] = b[cursorb++];
1064 * bdb_idl_notin - return a intersection ~b (or a minus b)
1073 ID cursora = 0, cursorb = 0;
1075 if( BDB_IDL_IS_ZERO( a ) ||
1076 BDB_IDL_IS_ZERO( b ) ||
1077 BDB_IDL_IS_RANGE( b ) )
1079 BDB_IDL_CPY( ids, a );
1083 if( BDB_IDL_IS_RANGE( a ) ) {
1084 BDB_IDL_CPY( ids, a );
1088 ida = bdb_idl_first( a, &cursora ),
1089 idb = bdb_idl_first( b, &cursorb );
1093 while( ida != NOID ) {
1094 if ( idb == NOID ) {
1095 /* we could shortcut this */
1096 ids[++ids[0]] = ida;
1097 ida = bdb_idl_next( a, &cursora );
1099 } else if ( ida < idb ) {
1100 ids[++ids[0]] = ida;
1101 ida = bdb_idl_next( a, &cursora );
1103 } else if ( ida > idb ) {
1104 idb = bdb_idl_next( b, &cursorb );
1107 ida = bdb_idl_next( a, &cursora );
1108 idb = bdb_idl_next( b, &cursorb );
1116 ID bdb_idl_first( ID *ids, ID *cursor )
1120 if ( ids[0] == 0 ) {
1125 if ( BDB_IDL_IS_RANGE( ids ) ) {
1126 if( *cursor < ids[1] ) {
1135 pos = bdb_idl_search( ids, *cursor );
1137 if( pos > ids[0] ) {
1145 ID bdb_idl_next( ID *ids, ID *cursor )
1147 if ( BDB_IDL_IS_RANGE( ids ) ) {
1148 if( ids[2] < ++(*cursor) ) {
1154 if ( ++(*cursor) <= ids[0] ) {
1155 return ids[*cursor];