1 /* Lifted from OpenLDAP back-bdb/idl.c */
8 typedef unsigned long pgno_t;
10 /* Sort the IDLs from highest to lowest */
11 #define IDL_CMP(x,y) ( x > y ? -1 : ( x < y ? 1 : 0 ) )
13 unsigned mdb_idl_search( ID *ids, ID id )
16 * binary search of id in ids
17 * if found, returns position of id
18 * if not found, returns first position greater than id
27 cursor = base + pivot;
28 val = IDL_CMP( id, ids[cursor + 1] );
33 } else if ( val > 0 ) {
49 int mdb_idl_insert( ID *ids, ID id )
53 if (MDB_IDL_IS_RANGE( ids )) {
54 /* if already in range, treat as a dup */
55 if (id >= MDB_IDL_FIRST(ids) && id <= MDB_IDL_LAST(ids))
57 if (id < MDB_IDL_FIRST(ids))
59 else if (id > MDB_IDL_LAST(ids))
64 x = mdb_idl_search( ids, id );
72 if ( x <= ids[0] && ids[x] == id ) {
77 if ( ++ids[0] >= MDB_IDL_DB_MAX ) {
80 ids[2] = ids[ids[0]-1];
81 } else if ( ids[ids[0]-1] < id ) {
84 ids[2] = ids[ids[0]-1];
90 AC_MEMCPY( &ids[x+1], &ids[x], (ids[0]-x) * sizeof(ID) );