1 /* idl.c - ldap id list handling routines */
4 * Copyright 1998-2002 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( bdb_idl_cache_entry_t* idl1, bdb_idl_cache_entry_t* idl2 )
52 if ((rc = idl1->db - idl2->db )) return rc;
53 if ((rc = idl1->kstr.bv_len - idl2->kstr.bv_len )) return rc;
54 return ( memcmp ( idl1->kstr.bv_val, idl2->kstr.bv_val , idl1->kstr.bv_len ) );
59 static void idl_check( ID *ids )
61 if( BDB_IDL_IS_RANGE( ids ) ) {
62 assert( BDB_IDL_RANGE_FIRST(ids) <= BDB_IDL_RANGE_LAST(ids) );
65 for( i=1; i < ids[0]; i++ ) {
66 assert( ids[i+1] > ids[i] );
72 static void idl_dump( ID *ids )
74 if( BDB_IDL_IS_RANGE( ids ) ) {
76 LDAP_LOG( INDEX, INFO, "IDL: range (%ld - %ld)\n",
77 (long) BDB_IDL_RANGE_FIRST( ids ),
78 (long) BDB_IDL_RANGE_LAST( ids ), 0 );
80 Debug( LDAP_DEBUG_ANY,
81 "IDL: range ( %ld - %ld )\n",
82 (long) BDB_IDL_RANGE_FIRST( ids ),
83 (long) BDB_IDL_RANGE_LAST( ids ) );
89 LDAP_LOG( INDEX, INFO, "IDL: size %ld", (long) ids[0], 0, 0 );
91 Debug( LDAP_DEBUG_ANY, "IDL: size %ld", (long) ids[0], 0, 0 );
94 for( i=1; i<=ids[0]; i++ ) {
96 Debug( LDAP_DEBUG_ANY, "\n", 0, 0, 0 );
99 LDAP_LOG( INDEX, INFO, "%02lx",(long)ids[i], 0, 0 );
101 Debug( LDAP_DEBUG_ANY, " %02lx", (long) ids[i], 0, 0 );
105 Debug( LDAP_DEBUG_ANY, "\n", 0, 0, 0 );
110 #endif /* IDL_DEBUG > 1 */
111 #endif /* IDL_DEBUG > 0 */
113 unsigned bdb_idl_search( ID *ids, ID id )
115 #define IDL_BINARY_SEARCH 1
116 #ifdef IDL_BINARY_SEARCH
118 * binary search of id in ids
119 * if found, returns position of id
120 * if not found, returns first postion greater than id
133 cursor = base + pivot;
134 val = IDL_CMP( id, ids[cursor + 1] );
139 } else if ( val > 0 ) {
155 /* (reverse) linear search */
162 for( i=ids[0]; i; i-- ) {
172 int bdb_idl_insert( ID *ids, ID id )
174 unsigned x = bdb_idl_search( ids, id );
178 LDAP_LOG( INDEX, DETAIL1, "insert: %04lx at %d\n", (long) id, x, 0 );
180 Debug( LDAP_DEBUG_ANY, "insert: %04lx at %d\n", (long) id, x, 0 );
194 if ( x <= ids[0] && ids[x] == id ) {
199 if ( ++ids[0] >= BDB_IDL_DB_MAX ) {
202 ids[2] = ids[ids[0]-1];
203 } else if ( ids[ids[0]-1] < id ) {
206 ids[2] = ids[ids[0]-1];
212 AC_MEMCPY( &ids[x+1], &ids[x], (ids[0]-x) * sizeof(ID) );
226 static int idl_delete( ID *ids, ID id )
228 unsigned x = bdb_idl_search( ids, id );
232 LDAP_LOG( INDEX, DETAIL1, "delete: %04lx at %d\n", (long) id, x, 0 );
234 Debug( LDAP_DEBUG_ANY, "delete: %04lx at %d\n", (long) id, x, 0 );
248 if( x > ids[0] || ids[x] != id ) {
252 } else if ( --ids[0] == 0 ) {
258 AC_MEMCPY( &ids[x], &ids[x+1], (1+ids[0]-x) * sizeof(ID) );
276 if ( key->size == sizeof( ID ) ) {
277 unsigned char *c = key->data;
278 sprintf( buf, "[%02x%02x%02x%02x]", c[0], c[1], c[2], c[3] );
293 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
301 int flags = bdb->bi_db_opflags | DB_MULTIPLE;
302 #ifdef SLAP_IDL_CACHE
303 bdb_idl_cache_entry_t idl_tmp;
306 /* buf must be large enough to grab the entire IDL in one
307 * get(), otherwise BDB 4 will leak resources on subsequent
308 * get's. We can safely call get() twice - once for the data,
309 * and once to get the DB_NOTFOUND result meaning there's
310 * no more data. See ITS#2040 for details. This bug is fixed
311 * in BDB 4.1 so a smaller buffer will work if stack space is
314 ID buf[BDB_IDL_DB_SIZE*5];
319 LDAP_LOG( INDEX, ARGS,
320 "bdb_idl_fetch_key: %s\n",
321 bdb_show_key( key, buf ), 0, 0 );
323 Debug( LDAP_DEBUG_ARGS,
324 "bdb_idl_fetch_key: %s\n",
325 bdb_show_key( key, buf ), 0, 0 );
328 assert( ids != NULL );
330 #ifdef SLAP_IDL_CACHE
331 if ( bdb->bi_idl_cache_max_size ) {
332 bdb_idl_cache_entry_t *matched_idl_entry;
333 DBT2bv( key, &idl_tmp.kstr );
335 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
336 matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp, (AVL_CMP) bdb_idl_entry_cmp );
337 if ( matched_idl_entry != NULL ) {
338 BDB_IDL_CPY( ids, matched_idl_entry->idl );
339 IDL_LRU_DELETE( bdb, matched_idl_entry );
340 IDL_LRU_ADD( bdb, matched_idl_entry );
341 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
344 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
351 data.ulen = sizeof(buf);
352 data.flags = DB_DBT_USERMEM;
357 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
360 LDAP_LOG( INDEX, ERR,
361 "bdb_idl_fetch_key: cursor failed: %s (%d)\n",
362 db_strerror(rc), rc, 0 );
364 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
365 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
369 rc = cursor->c_get( cursor, key, &data, flags | DB_SET );
375 DB_MULTIPLE_INIT( ptr, &data );
377 DB_MULTIPLE_NEXT(ptr, &data, j, len);
380 AC_MEMCPY( i, j, sizeof(ID) );
383 rc = cursor->c_get( cursor, key, &data, flags | DB_NEXT_DUP );
385 if ( rc == DB_NOTFOUND ) rc = 0;
387 /* On disk, a range is denoted by 0 in the first element */
389 if (ids[0] != BDB_IDL_RANGE_SIZE) {
391 LDAP_LOG( INDEX, ERR,
392 "=> bdb_idl_fetch_key: range size mismatch: "
393 "expected %ld, got %ld\n",
394 BDB_IDL_RANGE_SIZE, ids[0], 0 );
396 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
397 "range size mismatch: expected %d, got %ld\n",
398 BDB_IDL_RANGE_SIZE, ids[0], 0 );
400 cursor->c_close( cursor );
403 BDB_IDL_RANGE( ids, ids[2], ids[3] );
405 data.size = BDB_IDL_SIZEOF(ids);
407 rc2 = cursor->c_close( cursor );
410 LDAP_LOG( INDEX, ERR,
411 "bdb_idl_fetch_key: close failed: %s (%d)\n",
412 db_strerror(rc2), rc2, 0 );
414 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
415 "close failed: %s (%d)\n", db_strerror(rc2), rc2, 0 );
419 if( rc == DB_NOTFOUND ) {
422 } else if( rc != 0 ) {
424 LDAP_LOG( INDEX, ERR,
425 "bdb_idl_fetch_key: get failed: %s (%d)\n",
426 db_strerror(rc), rc, 0 );
428 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
429 "get failed: %s (%d)\n",
430 db_strerror(rc), rc, 0 );
434 } else if ( data.size == 0 || data.size % sizeof( ID ) ) {
435 /* size not multiple of ID size */
437 LDAP_LOG( INDEX, ERR,
438 "bdb_idl_fetch_key: odd size: expected %ld multiple, got %ld\n",
439 (long) sizeof( ID ), (long) data.size, 0 );
441 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
442 "odd size: expected %ld multiple, got %ld\n",
443 (long) sizeof( ID ), (long) data.size, 0 );
447 } else if ( data.size != BDB_IDL_SIZEOF(ids) ) {
450 LDAP_LOG( INDEX, ERR,
451 "bdb_idl_fetch_key: get size mismatch: expected %ld, got %ld\n",
452 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
454 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
455 "get size mismatch: expected %ld, got %ld\n",
456 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
461 #ifdef SLAP_IDL_CACHE
462 if ( bdb->bi_idl_cache_max_size ) {
463 bdb_idl_cache_entry_t *ee;
464 ee = (bdb_idl_cache_entry_t *) malloc( sizeof( bdb_idl_cache_entry_t ) );
466 ee->idl = (ID*) malloc ( BDB_IDL_SIZEOF ( ids ) );
467 ee->idl_lru_prev = NULL;
468 ee->idl_lru_next = NULL;
469 BDB_IDL_CPY( ee->idl, ids );
470 ber_dupbv( &ee->kstr, &idl_tmp.kstr );
471 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
472 if ( avl_insert( &bdb->bi_idl_tree, (caddr_t) ee, (AVL_CMP) bdb_idl_entry_cmp, avl_dup_error )) {
473 free( ee->kstr.bv_val );
477 IDL_LRU_ADD( bdb, ee );
478 if ( ++bdb->bi_idl_cache_size > bdb->bi_idl_cache_max_size ) {
480 while ( bdb->bi_idl_lru_tail != NULL && i < 10 ) {
481 ee = bdb->bi_idl_lru_tail;
482 avl_delete( &bdb->bi_idl_tree, (caddr_t) ee, (AVL_CMP) bdb_idl_entry_cmp );
483 IDL_LRU_DELETE( bdb, ee );
485 --bdb->bi_idl_cache_size;
486 free( ee->kstr.bv_val );
492 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
508 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
518 LDAP_LOG( INDEX, ARGS,
519 "bdb_idl_insert_key: %lx %s\n",
520 (long) id, bdb_show_key( key, buf ), 0 );
522 Debug( LDAP_DEBUG_ARGS,
523 "bdb_idl_insert_key: %lx %s\n",
524 (long) id, bdb_show_key( key, buf ), 0 );
528 assert( id != NOID );
530 #ifdef SLAP_IDL_CACHE
531 if ( bdb->bi_idl_cache_size ) {
532 bdb_idl_cache_entry_t *matched_idl_entry, idl_tmp;
533 DBT2bv( key, &idl_tmp.kstr );
535 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
536 matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp, (AVL_CMP) bdb_idl_entry_cmp );
537 if ( matched_idl_entry != NULL ) {
538 avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry, (AVL_CMP) bdb_idl_entry_cmp );
539 --bdb->bi_idl_cache_size;
540 IDL_LRU_DELETE( bdb, matched_idl_entry );
541 free( matched_idl_entry->kstr.bv_val );
542 free( matched_idl_entry->idl );
543 free( matched_idl_entry );
545 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
550 data.size = sizeof( ID );
551 data.ulen = data.size;
552 data.flags = DB_DBT_USERMEM;
554 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
557 LDAP_LOG( INDEX, ERR,
558 "bdb_idl_insert_key: cursor failed: %s (%d)\n",
559 db_strerror(rc), rc, 0 );
561 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
562 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
567 /* Fetch the first data item for this key, to see if it
568 * exists and if it's a range.
570 rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
574 /* not a range, count the number of items */
576 rc = cursor->c_count( cursor, &count, 0 );
581 if ( count >= BDB_IDL_DB_MAX ) {
582 /* No room, convert to a range */
585 key2.dlen = key2.ulen;
586 key2.flags |= DB_DBT_PARTIAL;
590 rc = cursor->c_get( cursor, &key2, &data, DB_NEXT_NODUP );
591 if ( rc != 0 && rc != DB_NOTFOUND ) {
592 err = "c_get next_nodup";
595 if ( rc == DB_NOTFOUND ) {
596 rc = cursor->c_get( cursor, key, &data, DB_LAST );
602 rc = cursor->c_get( cursor, key, &data, DB_PREV );
612 rc = db->del( db, tid, key, 0 );
619 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
625 rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
631 rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
637 /* There's room, just store it */
641 /* It's a range, see if we need to rewrite
646 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
653 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
659 if ( id < lo || id > hi ) {
660 /* Delete the current lo/hi */
661 rc = cursor->c_del( cursor, 0 );
667 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
674 } else if ( rc == DB_NOTFOUND ) {
675 put1: data.data = &id;
676 rc = cursor->c_put( cursor, key, &data, DB_NODUPDATA );
677 /* Don't worry if it's already there */
678 if ( rc != 0 && rc != DB_KEYEXIST ) {
683 /* initial c_get failed, nothing was done */
686 LDAP_LOG( INDEX, ERR,
687 "bdb_idl_insert_key: %s failed: %s (%d)\n",
688 err, db_strerror(rc), rc );
690 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
691 "%s failed: %s (%d)\n", err, db_strerror(rc), rc );
693 cursor->c_close( cursor );
696 rc = cursor->c_close( cursor );
699 LDAP_LOG( INDEX, ERR,
700 "bdb_idl_insert_key: c_close failed: %s (%d)\n",
701 db_strerror(rc), rc, 0 );
703 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
704 "c_close failed: %s (%d)\n",
705 db_strerror(rc), rc, 0 );
719 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
729 LDAP_LOG( INDEX, ARGS,
730 "bdb_idl_delete_key: %lx %s\n",
731 (long) id, bdb_show_key( key, buf ), 0 );
733 Debug( LDAP_DEBUG_ARGS,
734 "bdb_idl_delete_key: %lx %s\n",
735 (long) id, bdb_show_key( key, buf ), 0 );
738 assert( id != NOID );
740 #ifdef SLAP_IDL_CACHE
741 if ( bdb->bi_idl_cache_max_size ) {
742 bdb_idl_cache_entry_t *matched_idl_entry, idl_tmp;
743 DBT2bv( key, &idl_tmp.kstr );
745 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
746 matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp, (AVL_CMP) bdb_idl_entry_cmp );
747 if ( matched_idl_entry != NULL ) {
748 avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry, (AVL_CMP) bdb_idl_entry_cmp );
749 --bdb->bi_idl_cache_size;
750 IDL_LRU_DELETE( bdb, matched_idl_entry );
751 free( matched_idl_entry->kstr.bv_val );
752 free( matched_idl_entry->idl );
753 free( matched_idl_entry );
755 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
761 data.size = sizeof( id );
762 data.ulen = data.size;
763 data.flags = DB_DBT_USERMEM;
765 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
768 LDAP_LOG( INDEX, ERR,
769 "bdb_idl_delete_key: cursor failed: %s (%d)\n",
770 db_strerror(rc), rc, 0 );
772 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
773 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
777 /* Fetch the first data item for this key, to see if it
778 * exists and if it's a range.
780 rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
784 /* Not a range, just delete it */
786 /* position to correct item */
788 rc = cursor->c_get( cursor, key, &data,
789 DB_GET_BOTH | DB_RMW );
795 rc = cursor->c_del( cursor, 0 );
801 /* It's a range, see if we need to rewrite
806 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
813 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
819 if ( id == lo || id == hi ) {
823 } else if ( id == hi ) {
828 /* The range has collapsed... */
829 rc = db->del( db, tid, key, 0 );
835 rc = cursor->c_del( cursor, 0 );
843 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
852 /* initial c_get failed, nothing was done */
854 if ( rc != DB_NOTFOUND ) {
856 LDAP_LOG( INDEX, ERR,
857 "bdb_idl_delete_key: %s failed: %s (%d)\n",
858 err, db_strerror(rc), rc );
860 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
861 "%s failed: %s (%d)\n", err, db_strerror(rc), rc );
864 cursor->c_close( cursor );
867 rc = cursor->c_close( cursor );
870 LDAP_LOG( INDEX, ERR, "bdb_idl_delete_key: c_close failed: %s (%d)\n",
871 db_strerror(rc), rc, 0 );
873 Debug( LDAP_DEBUG_ANY,
874 "=> bdb_idl_delete_key: c_close failed: %s (%d)\n",
875 db_strerror(rc), rc, 0 );
884 * idl_intersection - return a = a intersection b
887 bdb_idl_intersection(
893 ID cursora = 0, cursorb = 0, cursorc;
896 if ( BDB_IDL_IS_ZERO( a ) || BDB_IDL_IS_ZERO( b ) ) {
901 idmin = IDL_MAX( BDB_IDL_FIRST(a), BDB_IDL_FIRST(b) );
902 idmax = IDL_MIN( BDB_IDL_LAST(a), BDB_IDL_LAST(b) );
903 if ( idmin > idmax ) {
906 } else if ( idmin == idmax ) {
912 if ( BDB_IDL_IS_RANGE( a ) ) {
913 if ( BDB_IDL_IS_RANGE(b) ) {
914 /* If both are ranges, just shrink the boundaries */
919 /* Else swap so that b is the range, a is a list */
927 /* If a range completely covers the list, the result is
928 * just the list. If idmin to idmax is contiguous, just
929 * turn it into a range.
931 if ( BDB_IDL_IS_RANGE( b )
932 && BDB_IDL_FIRST( b ) <= BDB_IDL_FIRST( a )
933 && BDB_IDL_LAST( b ) >= BDB_IDL_LAST( a ) ) {
934 if (idmax - idmin + 1 == a[0])
943 /* Fine, do the intersection one element at a time.
944 * First advance to idmin in both IDLs.
946 cursora = cursorb = idmin;
947 ida = bdb_idl_first( a, &cursora );
948 idb = bdb_idl_first( b, &cursorb );
951 while( ida <= idmax || idb <= idmax ) {
954 ida = bdb_idl_next( a, &cursora );
955 idb = bdb_idl_next( b, &cursorb );
956 } else if ( ida < idb ) {
957 ida = bdb_idl_next( a, &cursora );
959 idb = bdb_idl_next( b, &cursorb );
972 * idl_union - return a = a union b
980 ID cursora = 0, cursorb = 0, cursorc;
982 if ( BDB_IDL_IS_ZERO( b ) ) {
986 if ( BDB_IDL_IS_ZERO( a ) ) {
991 if ( BDB_IDL_IS_RANGE( a ) || BDB_IDL_IS_RANGE(b) ) {
992 over: ida = IDL_MIN( BDB_IDL_FIRST(a), BDB_IDL_FIRST(b) );
993 idb = IDL_MAX( BDB_IDL_LAST(a), BDB_IDL_LAST(b) );
1000 ida = bdb_idl_first( a, &cursora );
1001 idb = bdb_idl_first( b, &cursorb );
1005 /* The distinct elements of a are cat'd to b */
1006 while( ida != NOID || idb != NOID ) {
1008 if( ++cursorc > BDB_IDL_UM_MAX ) {
1012 ida = bdb_idl_next( a, &cursora );
1016 ida = bdb_idl_next( a, &cursora );
1017 idb = bdb_idl_next( b, &cursorb );
1021 /* b is copied back to a in sorted order */
1026 while (cursorb <= b[0] || cursorc <= a[0]) {
1031 if (cursorb <= b[0] && b[cursorb] < idb)
1032 a[cursora++] = b[cursorb++];
1045 * bdb_idl_notin - return a intersection ~b (or a minus b)
1054 ID cursora = 0, cursorb = 0;
1056 if( BDB_IDL_IS_ZERO( a ) ||
1057 BDB_IDL_IS_ZERO( b ) ||
1058 BDB_IDL_IS_RANGE( b ) )
1060 BDB_IDL_CPY( ids, a );
1064 if( BDB_IDL_IS_RANGE( a ) ) {
1065 BDB_IDL_CPY( ids, a );
1069 ida = bdb_idl_first( a, &cursora ),
1070 idb = bdb_idl_first( b, &cursorb );
1074 while( ida != NOID ) {
1075 if ( idb == NOID ) {
1076 /* we could shortcut this */
1077 ids[++ids[0]] = ida;
1078 ida = bdb_idl_next( a, &cursora );
1080 } else if ( ida < idb ) {
1081 ids[++ids[0]] = ida;
1082 ida = bdb_idl_next( a, &cursora );
1084 } else if ( ida > idb ) {
1085 idb = bdb_idl_next( b, &cursorb );
1088 ida = bdb_idl_next( a, &cursora );
1089 idb = bdb_idl_next( b, &cursorb );
1097 ID bdb_idl_first( ID *ids, ID *cursor )
1101 if ( ids[0] == 0 ) {
1106 if ( BDB_IDL_IS_RANGE( ids ) ) {
1107 if( *cursor < ids[1] ) {
1116 pos = bdb_idl_search( ids, *cursor );
1118 if( pos > ids[0] ) {
1126 ID bdb_idl_next( ID *ids, ID *cursor )
1128 if ( BDB_IDL_IS_RANGE( ids ) ) {
1129 if( ids[2] < ++(*cursor) ) {
1135 if ( ++(*cursor) <= ids[0] ) {
1136 return ids[*cursor];