2 * @brief ldap bdb back-end ID List functions */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 * Copyright 2000-2011 The OpenLDAP Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
19 #include <sys/types.h>
23 /** @defgroup internal MDB Internals
26 /** @defgroup idls ID List Management
29 #define CMP(x,y) ( (x) < (y) ? -1 : (x) > (y) )
31 static unsigned mdb_midl_search( IDL ids, ID id )
34 * binary search of id in ids
35 * if found, returns position of id
36 * if not found, returns first position greater than id
45 cursor = base + pivot;
46 val = CMP( ids[cursor + 1], id );
51 } else if ( val > 0 ) {
67 int mdb_midl_insert( IDL ids, ID id )
71 if (MDB_IDL_IS_RANGE( ids )) {
72 /* if already in range, treat as a dup */
73 if (id >= MDB_IDL_FIRST(ids) && id <= MDB_IDL_LAST(ids))
75 if (id < MDB_IDL_FIRST(ids))
77 else if (id > MDB_IDL_LAST(ids))
82 x = mdb_midl_search( ids, id );
90 if ( x <= ids[0] && ids[x] == id ) {
95 if ( ++ids[0] >= MDB_IDL_DB_MAX ) {
98 ids[2] = ids[ids[0]-1];
99 } else if ( ids[ids[0]-1] < id ) {
102 ids[2] = ids[ids[0]-1];
108 for (i=ids[0]; i>x; i--)
116 unsigned mdb_mid2l_search( ID2L ids, ID id )
119 * binary search of id in ids
120 * if found, returns position of id
121 * if not found, returns first position greater than id
126 unsigned n = ids[0].mid;
130 cursor = base + pivot;
131 val = CMP( id, ids[cursor + 1].mid );
136 } else if ( val > 0 ) {
152 int mdb_mid2l_insert( ID2L ids, ID2 *id )
156 x = mdb_mid2l_search( ids, id->mid );
164 if ( x <= ids[0].mid && ids[x].mid == id->mid ) {
169 if ( ids[0].mid >= MDB_IDL_DB_MAX ) {
176 for (i=ids[0].mid; i>x; i--)