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 avl_insert( &bdb->bi_idl_tree, (caddr_t) ee, (AVL_CMP) bdb_idl_entry_cmp, avl_dup_error );
473 IDL_LRU_ADD( bdb, ee );
474 if ( ++bdb->bi_idl_cache_size > bdb->bi_idl_cache_max_size ) {
476 while ( bdb->bi_idl_lru_tail != NULL && i < 10 ) {
477 ee = bdb->bi_idl_lru_tail;
478 avl_delete( &bdb->bi_idl_tree, (caddr_t) ee, (AVL_CMP) bdb_idl_entry_cmp );
479 IDL_LRU_DELETE( bdb, ee );
481 --bdb->bi_idl_cache_size;
482 free( ee->kstr.bv_val );
487 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
503 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
513 LDAP_LOG( INDEX, ARGS,
514 "bdb_idl_insert_key: %lx %s\n",
515 (long) id, bdb_show_key( key, buf ), 0 );
517 Debug( LDAP_DEBUG_ARGS,
518 "bdb_idl_insert_key: %lx %s\n",
519 (long) id, bdb_show_key( key, buf ), 0 );
523 assert( id != NOID );
525 #ifdef SLAP_IDL_CACHE
526 if ( bdb->bi_idl_cache_size ) {
527 bdb_idl_cache_entry_t *matched_idl_entry, idl_tmp;
528 DBT2bv( key, &idl_tmp.kstr );
530 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
531 matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp, (AVL_CMP) bdb_idl_entry_cmp );
532 if ( matched_idl_entry != NULL ) {
533 avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry, (AVL_CMP) bdb_idl_entry_cmp );
534 --bdb->bi_idl_cache_size;
535 IDL_LRU_DELETE( bdb, matched_idl_entry );
536 free( matched_idl_entry->kstr.bv_val );
537 free( matched_idl_entry->idl );
538 free( matched_idl_entry );
540 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
545 data.size = sizeof( ID );
546 data.ulen = data.size;
547 data.flags = DB_DBT_USERMEM;
549 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
552 LDAP_LOG( INDEX, ERR,
553 "bdb_idl_insert_key: cursor failed: %s (%d)\n",
554 db_strerror(rc), rc, 0 );
556 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
557 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
562 /* Fetch the first data item for this key, to see if it
563 * exists and if it's a range.
565 rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
569 /* not a range, count the number of items */
571 rc = cursor->c_count( cursor, &count, 0 );
576 if ( count >= BDB_IDL_DB_MAX ) {
577 /* No room, convert to a range */
580 key2.dlen = key2.ulen;
581 key2.flags |= DB_DBT_PARTIAL;
585 rc = cursor->c_get( cursor, &key2, &data, DB_NEXT_NODUP );
586 if ( rc != 0 && rc != DB_NOTFOUND ) {
587 err = "c_get next_nodup";
590 if ( rc == DB_NOTFOUND ) {
591 rc = cursor->c_get( cursor, key, &data, DB_LAST );
597 rc = cursor->c_get( cursor, key, &data, DB_PREV );
607 rc = db->del( db, tid, key, 0 );
614 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
620 rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
626 rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
632 /* There's room, just store it */
636 /* It's a range, see if we need to rewrite
641 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
648 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
654 if ( id < lo || id > hi ) {
655 /* Delete the current lo/hi */
656 rc = cursor->c_del( cursor, 0 );
662 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
669 } else if ( rc == DB_NOTFOUND ) {
670 put1: data.data = &id;
671 rc = cursor->c_put( cursor, key, &data, DB_NODUPDATA );
672 /* Don't worry if it's already there */
673 if ( rc != 0 && rc != DB_KEYEXIST ) {
678 /* initial c_get failed, nothing was done */
681 LDAP_LOG( INDEX, ERR,
682 "bdb_idl_insert_key: %s failed: %s (%d)\n",
683 err, db_strerror(rc), rc );
685 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
686 "%s failed: %s (%d)\n", err, db_strerror(rc), rc );
688 cursor->c_close( cursor );
691 rc = cursor->c_close( cursor );
694 LDAP_LOG( INDEX, ERR,
695 "bdb_idl_insert_key: c_close failed: %s (%d)\n",
696 db_strerror(rc), rc, 0 );
698 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
699 "c_close failed: %s (%d)\n",
700 db_strerror(rc), rc, 0 );
714 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
724 LDAP_LOG( INDEX, ARGS,
725 "bdb_idl_delete_key: %lx %s\n",
726 (long) id, bdb_show_key( key, buf ), 0 );
728 Debug( LDAP_DEBUG_ARGS,
729 "bdb_idl_delete_key: %lx %s\n",
730 (long) id, bdb_show_key( key, buf ), 0 );
733 assert( id != NOID );
735 #ifdef SLAP_IDL_CACHE
736 if ( bdb->bi_idl_cache_max_size ) {
737 bdb_idl_cache_entry_t *matched_idl_entry, idl_tmp;
738 DBT2bv( key, &idl_tmp.kstr );
740 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
741 matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp, (AVL_CMP) bdb_idl_entry_cmp );
742 if ( matched_idl_entry != NULL ) {
743 avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry, (AVL_CMP) bdb_idl_entry_cmp );
744 --bdb->bi_idl_cache_size;
745 IDL_LRU_DELETE( bdb, matched_idl_entry );
746 free( matched_idl_entry->kstr.bv_val );
747 free( matched_idl_entry->idl );
748 free( matched_idl_entry );
750 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
756 data.size = sizeof( id );
757 data.ulen = data.size;
758 data.flags = DB_DBT_USERMEM;
760 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
763 LDAP_LOG( INDEX, ERR,
764 "bdb_idl_delete_key: cursor failed: %s (%d)\n",
765 db_strerror(rc), rc, 0 );
767 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
768 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
772 /* Fetch the first data item for this key, to see if it
773 * exists and if it's a range.
775 rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
779 /* Not a range, just delete it */
781 /* position to correct item */
783 rc = cursor->c_get( cursor, key, &data,
784 DB_GET_BOTH | DB_RMW );
790 rc = cursor->c_del( cursor, 0 );
796 /* It's a range, see if we need to rewrite
801 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
808 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
814 if ( id == lo || id == hi ) {
818 } else if ( id == hi ) {
823 /* The range has collapsed... */
824 rc = db->del( db, tid, key, 0 );
830 rc = cursor->c_del( cursor, 0 );
838 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
847 /* initial c_get failed, nothing was done */
849 if ( rc != DB_NOTFOUND ) {
851 LDAP_LOG( INDEX, ERR,
852 "bdb_idl_delete_key: %s failed: %s (%d)\n",
853 err, db_strerror(rc), rc );
855 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
856 "%s failed: %s (%d)\n", err, db_strerror(rc), rc );
859 cursor->c_close( cursor );
862 rc = cursor->c_close( cursor );
865 LDAP_LOG( INDEX, ERR, "bdb_idl_delete_key: c_close failed: %s (%d)\n",
866 db_strerror(rc), rc, 0 );
868 Debug( LDAP_DEBUG_ANY,
869 "=> bdb_idl_delete_key: c_close failed: %s (%d)\n",
870 db_strerror(rc), rc, 0 );
879 * idl_intersection - return a = a intersection b
882 bdb_idl_intersection(
888 ID cursora = 0, cursorb = 0, cursorc;
891 if ( BDB_IDL_IS_ZERO( a ) || BDB_IDL_IS_ZERO( b ) ) {
896 idmin = IDL_MAX( BDB_IDL_FIRST(a), BDB_IDL_FIRST(b) );
897 idmax = IDL_MIN( BDB_IDL_LAST(a), BDB_IDL_LAST(b) );
898 if ( idmin > idmax ) {
901 } else if ( idmin == idmax ) {
907 if ( BDB_IDL_IS_RANGE( a ) ) {
908 if ( BDB_IDL_IS_RANGE(b) ) {
909 /* If both are ranges, just shrink the boundaries */
914 /* Else swap so that b is the range, a is a list */
922 /* If a range completely covers the list, the result is
923 * just the list. If idmin to idmax is contiguous, just
924 * turn it into a range.
926 if ( BDB_IDL_IS_RANGE( b )
927 && BDB_IDL_FIRST( b ) <= BDB_IDL_FIRST( a )
928 && BDB_IDL_LAST( b ) >= BDB_IDL_LAST( a ) ) {
929 if (idmax - idmin + 1 == a[0])
938 /* Fine, do the intersection one element at a time.
939 * First advance to idmin in both IDLs.
941 cursora = cursorb = idmin;
942 ida = bdb_idl_first( a, &cursora );
943 idb = bdb_idl_first( b, &cursorb );
946 while( ida <= idmax || idb <= idmax ) {
949 ida = bdb_idl_next( a, &cursora );
950 idb = bdb_idl_next( b, &cursorb );
951 } else if ( ida < idb ) {
952 ida = bdb_idl_next( a, &cursora );
954 idb = bdb_idl_next( b, &cursorb );
967 * idl_union - return a = a union b
975 ID cursora = 0, cursorb = 0, cursorc;
977 if ( BDB_IDL_IS_ZERO( b ) ) {
981 if ( BDB_IDL_IS_ZERO( a ) ) {
986 if ( BDB_IDL_IS_RANGE( a ) || BDB_IDL_IS_RANGE(b) ) {
987 over: ida = IDL_MIN( BDB_IDL_FIRST(a), BDB_IDL_FIRST(b) );
988 idb = IDL_MAX( BDB_IDL_LAST(a), BDB_IDL_LAST(b) );
995 ida = bdb_idl_first( a, &cursora );
996 idb = bdb_idl_first( b, &cursorb );
1000 /* The distinct elements of a are cat'd to b */
1001 while( ida != NOID || idb != NOID ) {
1003 if( ++cursorc > BDB_IDL_UM_MAX ) {
1007 ida = bdb_idl_next( a, &cursora );
1011 ida = bdb_idl_next( a, &cursora );
1012 idb = bdb_idl_next( b, &cursorb );
1016 /* b is copied back to a in sorted order */
1021 while (cursorb <= b[0] || cursorc <= a[0]) {
1026 if (cursorb <= b[0] && b[cursorb] < idb)
1027 a[cursora++] = b[cursorb++];
1040 * bdb_idl_notin - return a intersection ~b (or a minus b)
1049 ID cursora = 0, cursorb = 0;
1051 if( BDB_IDL_IS_ZERO( a ) ||
1052 BDB_IDL_IS_ZERO( b ) ||
1053 BDB_IDL_IS_RANGE( b ) )
1055 BDB_IDL_CPY( ids, a );
1059 if( BDB_IDL_IS_RANGE( a ) ) {
1060 BDB_IDL_CPY( ids, a );
1064 ida = bdb_idl_first( a, &cursora ),
1065 idb = bdb_idl_first( b, &cursorb );
1069 while( ida != NOID ) {
1070 if ( idb == NOID ) {
1071 /* we could shortcut this */
1072 ids[++ids[0]] = ida;
1073 ida = bdb_idl_next( a, &cursora );
1075 } else if ( ida < idb ) {
1076 ids[++ids[0]] = ida;
1077 ida = bdb_idl_next( a, &cursora );
1079 } else if ( ida > idb ) {
1080 idb = bdb_idl_next( b, &cursorb );
1083 ida = bdb_idl_next( a, &cursora );
1084 idb = bdb_idl_next( b, &cursorb );
1092 ID bdb_idl_first( ID *ids, ID *cursor )
1096 if ( ids[0] == 0 ) {
1101 if ( BDB_IDL_IS_RANGE( ids ) ) {
1102 if( *cursor < ids[1] ) {
1111 pos = bdb_idl_search( ids, *cursor );
1113 if( pos > ids[0] ) {
1121 ID bdb_idl_next( ID *ids, ID *cursor )
1123 if ( BDB_IDL_IS_RANGE( ids ) ) {
1124 if( ids[2] < ++(*cursor) ) {
1130 if ( ++(*cursor) <= ids[0] ) {
1131 return ids[*cursor];