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 static void idl_check( ID *ids )
24 if( BDB_IDL_IS_RANGE( ids ) ) {
25 assert( BDB_IDL_RANGE_FIRST(ids) <= BDB_IDL_RANGE_LAST(ids) );
28 for( i=1; i < ids[0]; i++ ) {
29 assert( ids[i+1] > ids[i] );
35 static void idl_dump( ID *ids )
37 if( BDB_IDL_IS_RANGE( ids ) ) {
39 LDAP_LOG( INDEX, INFO, "IDL: range (%ld - %ld)\n",
40 (long) BDB_IDL_RANGE_FIRST( ids ),
41 (long) BDB_IDL_RANGE_LAST( ids ), 0 );
43 Debug( LDAP_DEBUG_ANY,
44 "IDL: range ( %ld - %ld )\n",
45 (long) BDB_IDL_RANGE_FIRST( ids ),
46 (long) BDB_IDL_RANGE_LAST( ids ) );
52 LDAP_LOG( INDEX, INFO, "IDL: size %ld", (long) ids[0], 0, 0 );
54 Debug( LDAP_DEBUG_ANY, "IDL: size %ld", (long) ids[0], 0, 0 );
57 for( i=1; i<=ids[0]; i++ ) {
59 Debug( LDAP_DEBUG_ANY, "\n", 0, 0, 0 );
62 LDAP_LOG( INDEX, INFO, "%02lx",(long)ids[i], 0, 0 );
64 Debug( LDAP_DEBUG_ANY, " %02lx", (long) ids[i], 0, 0 );
68 Debug( LDAP_DEBUG_ANY, "\n", 0, 0, 0 );
73 #endif /* IDL_DEBUG > 1 */
74 #endif /* IDL_DEBUG > 0 */
76 unsigned bdb_idl_search( ID *ids, ID id )
78 #define IDL_BINARY_SEARCH 1
79 #ifdef IDL_BINARY_SEARCH
81 * binary search of id in ids
82 * if found, returns position of id
83 * if not found, returns first postion greater than id
96 cursor = base + pivot;
97 val = IDL_CMP( id, ids[cursor + 1] );
102 } else if ( val > 0 ) {
118 /* (reverse) linear search */
125 for( i=ids[0]; i; i-- ) {
135 int bdb_idl_insert( ID *ids, ID id )
137 unsigned x = bdb_idl_search( ids, id );
141 LDAP_LOG( INDEX, DETAIL1, "insert: %04lx at %d\n", (long) id, x, 0 );
143 Debug( LDAP_DEBUG_ANY, "insert: %04lx at %d\n", (long) id, x, 0 );
157 if ( x <= ids[0] && ids[x] == id ) {
162 if ( ++ids[0] >= BDB_IDL_DB_MAX ) {
165 ids[2] = ids[ids[0]-1];
166 } else if ( ids[ids[0]-1] < id ) {
169 ids[2] = ids[ids[0]-1];
175 AC_MEMCPY( &ids[x+1], &ids[x], (ids[0]-x) * sizeof(ID) );
188 static int idl_delete( ID *ids, ID id )
190 unsigned x = bdb_idl_search( ids, id );
194 LDAP_LOG( INDEX, DETAIL1, "delete: %04lx at %d\n", (long) id, x, 0 );
196 Debug( LDAP_DEBUG_ANY, "delete: %04lx at %d\n", (long) id, x, 0 );
210 if( x > ids[0] || ids[x] != id ) {
214 } else if ( --ids[0] == 0 ) {
220 AC_MEMCPY( &ids[x], &ids[x+1], (1+ids[0]-x) * sizeof(ID) );
240 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
244 assert( ids != NULL );
251 /* buf must be large enough to grab the entire IDL in one
252 * get(), otherwise BDB 4 will leak resources on subsequent
253 * get's. We can safely call get() twice - once for the data,
254 * and once to get the DB_NOTFOUND result meaning there's
255 * no more data. See ITS#2040 for details.
257 ID buf[BDB_IDL_DB_SIZE*5];
262 int flags = bdb->bi_db_opflags | DB_MULTIPLE;
264 data.ulen = sizeof(buf);
265 data.flags = DB_DBT_USERMEM;
270 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
273 LDAP_LOG( INDEX, ERR,
274 "bdb_idl_fetch_key: cursor failed: %s (%d)\n",
275 db_strerror(rc), rc, 0 );
277 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
278 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
282 rc = cursor->c_get( cursor, key, &data, flags | DB_SET );
288 DB_MULTIPLE_INIT( ptr, &data );
290 DB_MULTIPLE_NEXT(ptr, &data, j, len);
293 AC_MEMCPY( i, j, sizeof(ID) );
296 rc = cursor->c_get( cursor, key, &data, flags | DB_NEXT_DUP );
298 if ( rc == DB_NOTFOUND ) rc = 0;
300 /* On disk, a range is denoted by 0 in the first element */
302 if (ids[0] != BDB_IDL_RANGE_SIZE) {
304 LDAP_LOG( INDEX, ERR,
305 "=> bdb_idl_fetch_key: range size mismatch: "
306 "expected %ld, got %ld\n",
307 BDB_IDL_RANGE_SIZE, ids[0], 0 );
309 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
310 "range size mismatch: expected %d, got %ld\n",
311 BDB_IDL_RANGE_SIZE, ids[0], 0 );
313 cursor->c_close( cursor );
316 BDB_IDL_RANGE( ids, ids[2], ids[3] );
318 data.size = BDB_IDL_SIZEOF(ids);
320 rc2 = cursor->c_close( cursor );
323 LDAP_LOG( INDEX, ERR,
324 "bdb_idl_fetch_key: close failed: %s (%d)\n",
325 db_strerror(rc2), rc2, 0 );
327 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
328 "close failed: %s (%d)\n", db_strerror(rc2), rc2, 0 );
335 data.ulen = BDB_IDL_UM_SIZEOF;
336 data.flags = DB_DBT_USERMEM;
338 rc = db->get( db, tid, key, &data, bdb->bi_db_opflags );
341 if( rc == DB_NOTFOUND ) {
344 } else if( rc != 0 ) {
346 LDAP_LOG( INDEX, ERR,
347 "bdb_idl_fetch_key: get failed: %s (%d)\n",
348 db_strerror(rc), rc, 0 );
350 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
351 "get failed: %s (%d)\n",
352 db_strerror(rc), rc, 0 );
356 } else if ( data.size == 0 || data.size % sizeof( ID ) ) {
357 /* size not multiple of ID size */
359 LDAP_LOG( INDEX, ERR,
360 "bdb_idl_fetch_key: odd size: expected %ld multiple, got %ld\n",
361 (long) sizeof( ID ), (long) data.size, 0 );
363 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
364 "odd size: expected %ld multiple, got %ld\n",
365 (long) sizeof( ID ), (long) data.size, 0 );
369 } else if ( data.size != BDB_IDL_SIZEOF(ids) ) {
372 LDAP_LOG( INDEX, ERR,
373 "bdb_idl_fetch_key: get size mismatch: expected %ld, got %ld\n",
374 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
376 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
377 "get size mismatch: expected %ld, got %ld\n",
378 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
394 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
397 #ifndef BDB_IDL_MULTI
398 ID ids[BDB_IDL_DB_SIZE];
402 /* for printable keys only */
404 LDAP_LOG( INDEX, ARGS, "bdb_idl_insert_key: %s %ld\n",
405 (char *)key->data, (long) id, 0 );
407 Debug( LDAP_DEBUG_ARGS,
408 "=> bdb_idl_insert_key: %s %ld\n",
409 (char *)key->data, (long) id, 0 );
413 assert( id != NOID );
422 data.size = sizeof( ID );
423 data.ulen = data.size;
424 data.flags = DB_DBT_USERMEM;
426 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
429 LDAP_LOG( INDEX, ERR,
430 "bdb_idl_insert_key: cursor failed: %s (%d)\n",
431 db_strerror(rc), rc, 0 );
433 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
434 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
439 /* Fetch the first data item for this key, to see if it
440 * exists and if it's a range.
442 rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
446 /* not a range, count the number of items */
448 rc = cursor->c_count( cursor, &count, 0 );
453 if ( count >= BDB_IDL_DB_MAX ) {
454 /* No room, convert to a range */
457 key2.dlen = key2.ulen;
458 key2.flags |= DB_DBT_PARTIAL;
462 rc = cursor->c_get( cursor, &key2, &data, DB_NEXT_NODUP );
463 if ( rc != 0 && rc != DB_NOTFOUND ) {
464 err = "c_get next_nodup";
467 if ( rc == DB_NOTFOUND ) {
468 rc = cursor->c_get( cursor, key, &data, DB_LAST );
474 rc = cursor->c_get( cursor, key, &data, DB_PREV );
484 rc = db->del( db, tid, key, 0 );
491 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
497 rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
503 rc = cursor->c_put( cursor, key, &data, DB_KEYLAST );
509 /* There's room, just store it */
513 /* It's a range, see if we need to rewrite
518 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
525 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
531 if ( id < lo || id > hi ) {
532 /* Delete the current lo/hi */
533 rc = cursor->c_del( cursor, 0 );
539 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
546 } else if ( rc == DB_NOTFOUND ) {
547 put1: data.data = &id;
548 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
549 /* Don't worry if it's already there */
550 if ( rc != 0 && rc != DB_KEYEXIST ) {
555 /* initial c_get failed, nothing was done */
558 LDAP_LOG( INDEX, ERR,
559 "bdb_idl_insert_key: %s failed: %s (%d)\n",
560 err, db_strerror(rc), rc );
562 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
563 "%s failed: %s (%d)\n", err, db_strerror(rc), rc );
565 cursor->c_close( cursor );
568 rc = cursor->c_close( cursor );
570 #else /* !BDB_IDL_MULTI */
572 data.ulen = sizeof ids;
573 data.flags = DB_DBT_USERMEM;
575 /* fetch the key for read/modify/write */
576 rc = db->get( db, tid, key, &data, DB_RMW | bdb->bi_db_opflags );
578 if( rc == DB_NOTFOUND ) {
581 data.size = 2 * sizeof( ID );
583 } else if ( rc != 0 ) {
585 LDAP_LOG( INDEX, ERR, "bdb_idl_insert_key: get failed: %s (%d)\n",
586 db_strerror(rc), rc, 0 );
588 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
589 "get failed: %s (%d)\n",
590 db_strerror(rc), rc, 0 );
594 } else if ( data.size == 0 || data.size % sizeof( ID ) ) {
595 /* size not multiple of ID size */
597 LDAP_LOG( INDEX, ERR,
598 "bdb_idl_insert_key: odd size: expected %ld multiple, got %ld\n",
599 (long) sizeof( ID ), (long) data.size, 0 );
601 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
602 "odd size: expected %ld multiple, got %ld\n",
603 (long) sizeof( ID ), (long) data.size, 0 );
607 } else if ( data.size != BDB_IDL_SIZEOF(ids) ) {
610 LDAP_LOG( INDEX, ERR,
611 "bdb_idl_insert_key: odd size: expected %ld multiple, got %ld\n",
612 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
614 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
615 "get size mismatch: expected %ld, got %ld\n",
616 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
620 } else if ( BDB_IDL_IS_RANGE(ids) ) {
623 } else if ( ids[2] > id ) {
630 rc = bdb_idl_insert( ids, id );
634 LDAP_LOG( INDEX, DETAIL1, "bdb_idl_insert_key: dup\n", 0, 0, 0 );
636 Debug( LDAP_DEBUG_TRACE, "=> bdb_idl_insert_key: dup\n",
643 LDAP_LOG( INDEX, ERR,
644 "bdb_idl_insert_key: insert failed: (%d)\n", rc, 0, 0 );
646 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
647 "bdb_idl_insert failed (%d)\n",
654 data.size = BDB_IDL_SIZEOF( ids );
658 rc = db->put( db, tid, key, &data, 0 );
660 if( rc != 0 && rc != DB_KEYEXIST ) {
662 LDAP_LOG( INDEX, ERR,
663 "bdb_idl_insert_key: put failed: %s (%d)\n",
664 db_strerror(rc), rc, 0 );
666 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: "
667 "put failed: %s (%d)\n",
668 db_strerror(rc), rc, 0 );
682 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
685 #ifndef BDB_IDL_MULTI
686 ID ids[BDB_IDL_DB_SIZE];
690 /* for printable keys only */
692 LDAP_LOG( INDEX, ARGS, "bdb_idl_delete_key: %s %ld\n",
693 (char *)key->data, (long) id, 0 );
695 Debug( LDAP_DEBUG_ARGS,
696 "=> bdb_idl_delete_key: %s %ld\n",
697 (char *)key->data, (long) id, 0 );
701 assert( id != NOID );
711 data.size = sizeof( id );
712 data.ulen = data.size;
713 data.flags = DB_DBT_USERMEM;
715 rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
718 LDAP_LOG( INDEX, ERR,
719 "bdb_idl_delete_key: cursor failed: %s (%d)\n",
720 db_strerror(rc), rc, 0 );
722 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
723 "cursor failed: %s (%d)\n", db_strerror(rc), rc, 0 );
727 /* Fetch the first data item for this key, to see if it
728 * exists and if it's a range.
730 rc = cursor->c_get( cursor, key, &data, DB_SET | DB_RMW );
734 /* Not a range, just delete it */
736 /* position to correct item */
738 rc = cursor->c_get( cursor, key, &data,
739 DB_GET_BOTH | DB_RMW );
742 rc = cursor->c_del( cursor, 0 );
749 /* It's a range, see if we need to rewrite
754 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
761 rc = cursor->c_get( cursor, key, &data, DB_NEXT_DUP );
767 if ( id == lo || id == hi ) {
771 } else if ( id == hi ) {
776 /* The range has collapsed... */
777 rc = db->del( db, tid, key, 0 );
783 rc = cursor->c_del( cursor, 0 );
791 rc = cursor->c_put( cursor, key, &data, DB_KEYFIRST );
800 /* initial c_get failed, nothing was done */
803 LDAP_LOG( INDEX, ERR,
804 "bdb_idl_delete_key: %s failed: %s (%d)\n",
805 err, db_strerror(rc), rc );
807 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
808 "%s failed: %s (%d)\n", err, db_strerror(rc), rc );
810 cursor->c_close( cursor );
813 rc = cursor->c_close( cursor );
817 data.ulen = sizeof( ids );
818 data.flags = DB_DBT_USERMEM;
820 /* fetch the key for read/modify/write */
821 rc = db->get( db, tid, key, &data, DB_RMW | bdb->bi_db_opflags );
825 LDAP_LOG( INDEX, ERR, "bdb_idl_delete_key: get failed: %s (%d)\n",
826 db_strerror(rc), rc, 0 );
828 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
829 "get failed: %s (%d)\n",
830 db_strerror(rc), rc, 0 );
834 } else if ( data.size == 0 || data.size % sizeof( ID ) ) {
835 /* size not multiple of ID size */
837 LDAP_LOG( INDEX, ERR,
838 "bdb_idl_delete_key: odd size: expected: %ld multiple, got %ld\n",
839 (long) sizeof( ID ), (long) data.size, 0 );
841 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
842 "odd size: expected %ld multiple, got %ld\n",
843 (long) sizeof( ID ), (long) data.size, 0 );
847 } else if ( BDB_IDL_IS_RANGE(ids) ) {
850 } else if ( data.size != (1 + ids[0]) * sizeof( ID ) ) {
853 LDAP_LOG( INDEX, ERR,
854 "bdb_idl_delete_key: get size mismatch: expected: %ld, got %ld\n",
855 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
857 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
858 "get size mismatch: expected %ld, got %ld\n",
859 (long) ((1 + ids[0]) * sizeof( ID )), (long) data.size, 0 );
864 rc = idl_delete( ids, id );
868 LDAP_LOG( INDEX, ERR,
869 "bdb_idl_delete_key: delete failed: (%d)\n", rc, 0, 0 );
871 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
872 "idl_delete failed (%d)\n",
880 rc = db->del( db, tid, key, 0 );
883 LDAP_LOG( INDEX, ERR,
884 "bdb_idl_delete_key: delete failed: %s (%d)\n",
885 db_strerror(rc), rc, 0 );
887 Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: "
888 "delete failed: %s (%d)\n",
889 db_strerror(rc), rc, 0 );
895 data.size = (ids[0]+1) * sizeof( ID );
899 rc = db->put( db, tid, key, &data, 0 );
901 #endif /* BDB_IDL_MULTI */
905 LDAP_LOG( INDEX, ERR, "bdb_idl_delete_key: put failed: %s (%d)\n",
906 db_strerror(rc), rc, 0 );
908 Debug( LDAP_DEBUG_ANY,
909 "=> bdb_idl_delete_key: put failed: %s (%d)\n",
910 db_strerror(rc), rc, 0 );
919 * idl_intersection - return a = a intersection b
922 bdb_idl_intersection(
928 ID cursora = 0, cursorb = 0, cursorc;
931 if ( BDB_IDL_IS_ZERO( a ) || BDB_IDL_IS_ZERO( b ) ) {
936 idmin = IDL_MAX( BDB_IDL_FIRST(a), BDB_IDL_FIRST(b) );
937 idmax = IDL_MIN( BDB_IDL_LAST(a), BDB_IDL_LAST(b) );
938 if ( idmin > idmax ) {
941 } else if ( idmin == idmax ) {
947 if ( BDB_IDL_IS_RANGE( a ) && BDB_IDL_IS_RANGE(b) ) {
953 if ( BDB_IDL_IS_RANGE( a ) ) {
960 if ( BDB_IDL_IS_RANGE( b ) && BDB_IDL_FIRST( b ) <= idmin &&
961 BDB_IDL_LAST( b ) >= idmax) {
962 if (idmax - idmin + 1 == a[0])
971 ida = bdb_idl_first( a, &cursora );
972 idb = bdb_idl_first( b, &cursorb );
976 ida = bdb_idl_next( a, &cursora );
978 idb = bdb_idl_next( b, &cursorb );
980 while( ida <= idmax || idb <= idmax ) {
983 ida = bdb_idl_next( a, &cursora );
984 idb = bdb_idl_next( b, &cursorb );
985 } else if ( ida < idb ) {
986 ida = bdb_idl_next( a, &cursora );
988 idb = bdb_idl_next( b, &cursorb );
1001 * idl_union - return a = a union b
1009 ID cursora = 0, cursorb = 0, cursorc;
1011 if ( BDB_IDL_IS_ZERO( b ) ) {
1015 if ( BDB_IDL_IS_ZERO( a ) ) {
1016 BDB_IDL_CPY( a, b );
1020 if ( BDB_IDL_IS_RANGE( a ) || BDB_IDL_IS_RANGE(b) ) {
1021 over: ida = IDL_MIN( BDB_IDL_FIRST(a), BDB_IDL_FIRST(b) );
1022 idb = IDL_MAX( BDB_IDL_LAST(a), BDB_IDL_LAST(b) );
1029 ida = bdb_idl_first( a, &cursora );
1030 idb = bdb_idl_first( b, &cursorb );
1034 /* The distinct elements of a are cat'd to b */
1035 while( ida != NOID || idb != NOID ) {
1037 if( ++cursorc > BDB_IDL_UM_MAX ) {
1041 ida = bdb_idl_next( a, &cursora );
1045 ida = bdb_idl_next( a, &cursora );
1046 idb = bdb_idl_next( b, &cursorb );
1050 /* b is copied back to a in sorted order */
1055 while (cursorb <= b[0] || cursorc <= a[0]) {
1060 if (cursorb <= b[0] && b[cursorb] < idb)
1061 a[cursora++] = b[cursorb++];
1074 * bdb_idl_notin - return a intersection ~b (or a minus b)
1083 ID cursora = 0, cursorb = 0;
1085 if( BDB_IDL_IS_ZERO( a ) ||
1086 BDB_IDL_IS_ZERO( b ) ||
1087 BDB_IDL_IS_RANGE( b ) )
1089 BDB_IDL_CPY( ids, a );
1093 if( BDB_IDL_IS_RANGE( a ) ) {
1094 BDB_IDL_CPY( ids, a );
1098 ida = bdb_idl_first( a, &cursora ),
1099 idb = bdb_idl_first( b, &cursorb );
1103 while( ida != NOID ) {
1104 if ( idb == NOID ) {
1105 /* we could shortcut this */
1106 ids[++ids[0]] = ida;
1107 ida = bdb_idl_next( a, &cursora );
1109 } else if ( ida < idb ) {
1110 ids[++ids[0]] = ida;
1111 ida = bdb_idl_next( a, &cursora );
1113 } else if ( ida > idb ) {
1114 idb = bdb_idl_next( b, &cursorb );
1117 ida = bdb_idl_next( a, &cursora );
1118 idb = bdb_idl_next( b, &cursorb );
1126 ID bdb_idl_first( ID *ids, ID *cursor )
1130 if ( ids[0] == 0 ) {
1135 if ( BDB_IDL_IS_RANGE( ids ) ) {
1136 if( *cursor < ids[1] ) {
1145 pos = bdb_idl_search( ids, *cursor );
1147 if( pos > ids[0] ) {
1155 ID bdb_idl_next( ID *ids, ID *cursor )
1157 if ( BDB_IDL_IS_RANGE( ids ) ) {
1158 if( ids[2] < ++(*cursor) ) {
1164 if ( ++(*cursor) <= ids[0] ) {
1165 return ids[*cursor];