aboutsummaryrefslogtreecommitdiff
path: root/external/db_drivers/liblmdb/midl.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--external/db_drivers/liblmdb/midl.c (renamed from external/db_drivers/liblmdb64/midl.c)66
1 files changed, 63 insertions, 3 deletions
diff --git a/external/db_drivers/liblmdb64/midl.c b/external/db_drivers/liblmdb/midl.c
index 16782dcaf..e2005d16c 100644
--- a/external/db_drivers/liblmdb64/midl.c
+++ b/external/db_drivers/liblmdb/midl.c
@@ -116,7 +116,7 @@ void mdb_midl_free(MDB_IDL ids)
free(ids-1);
}
-int mdb_midl_shrink( MDB_IDL *idp )
+void mdb_midl_shrink( MDB_IDL *idp )
{
MDB_IDL ids = *idp;
if (*(--ids) > MDB_IDL_UM_MAX &&
@@ -124,9 +124,7 @@ int mdb_midl_shrink( MDB_IDL *idp )
{
*ids++ = MDB_IDL_UM_MAX;
*idp = ids;
- return 1;
}
- return 0;
}
static int mdb_midl_grow( MDB_IDL *idp, int num )
@@ -356,5 +354,67 @@ int mdb_mid2l_append( MDB_ID2L ids, MDB_ID2 *id )
return 0;
}
+#ifdef MDB_VL32
+unsigned mdb_mid3l_search( MDB_ID3L ids, MDB_ID id )
+{
+ /*
+ * binary search of id in ids
+ * if found, returns position of id
+ * if not found, returns first position greater than id
+ */
+ unsigned base = 0;
+ unsigned cursor = 1;
+ int val = 0;
+ unsigned n = (unsigned)ids[0].mid;
+
+ while( 0 < n ) {
+ unsigned pivot = n >> 1;
+ cursor = base + pivot + 1;
+ val = CMP( id, ids[cursor].mid );
+
+ if( val < 0 ) {
+ n = pivot;
+
+ } else if ( val > 0 ) {
+ base = cursor;
+ n -= pivot + 1;
+
+ } else {
+ return cursor;
+ }
+ }
+
+ if( val > 0 ) {
+ ++cursor;
+ }
+ return cursor;
+}
+
+int mdb_mid3l_insert( MDB_ID3L ids, MDB_ID3 *id )
+{
+ unsigned x, i;
+
+ x = mdb_mid3l_search( ids, id->mid );
+
+ if( x < 1 ) {
+ /* internal error */
+ return -2;
+ }
+
+ if ( x <= ids[0].mid && ids[x].mid == id->mid ) {
+ /* duplicate */
+ return -1;
+ }
+
+ /* insert id */
+ ids[0].mid++;
+ for (i=(unsigned)ids[0].mid; i>x; i--)
+ ids[i] = ids[i-1];
+ ids[x] = *id;
+
+ return 0;
+}
+#endif /* MDB_VL32 */
+
/** @} */
/** @} */