/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2000-2013 The OpenLDAP Foundation.
+ * Copyright 2000-2015 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
-#include <assert.h>
#include "midl.h"
-/** @defgroup internal MDB Internals
+/** @defgroup internal LMDB Internals
* @{
*/
/** @defgroup idls ID List Management
return cursor;
}
}
-
+
if( val > 0 ) {
++cursor;
}
/* no room */
--ids[0];
return -2;
-
+
} else {
/* insert id */
for (i=ids[0]; i>x; i--)
num = (num + num/4 + (256 + 2)) & -256;
if (!(ids = realloc(ids-1, num * sizeof(MDB_ID))))
return ENOMEM;
- *ids++ = num -= 2;
+ *ids++ = num - 2;
*idp = ids;
}
return 0;
return 0;
}
+void mdb_midl_xmerge( MDB_IDL idl, MDB_IDL merge )
+{
+ MDB_ID old_id, merge_id, i = merge[0], j = idl[0], k = i+j, total = k;
+ idl[0] = (MDB_ID)-1; /* delimiter for idl scan below */
+ old_id = idl[j];
+ while (i) {
+ merge_id = merge[i--];
+ for (; old_id < merge_id; old_id = idl[--j])
+ idl[k--] = old_id;
+ idl[k--] = merge_id;
+ }
+ idl[0] = total;
+}
+
/* Quicksort + Insertion sort for small arrays */
#define SMALL 8
-#define SWAP(a,b) { itmp=(a); (a)=(b); (b)=itmp; }
+#define MIDL_SWAP(a,b) { itmp=(a); (a)=(b); (b)=itmp; }
void
mdb_midl_sort( MDB_IDL ids )
l = istack[jstack--];
} else {
k = (l + ir) >> 1; /* Choose median of left, center, right */
- SWAP(ids[k], ids[l+1]);
+ MIDL_SWAP(ids[k], ids[l+1]);
if (ids[l] < ids[ir]) {
- SWAP(ids[l], ids[ir]);
+ MIDL_SWAP(ids[l], ids[ir]);
}
if (ids[l+1] < ids[ir]) {
- SWAP(ids[l+1], ids[ir]);
+ MIDL_SWAP(ids[l+1], ids[ir]);
}
if (ids[l] < ids[l+1]) {
- SWAP(ids[l], ids[l+1]);
+ MIDL_SWAP(ids[l], ids[l+1]);
}
i = l+1;
j = ir;
do i++; while(ids[i] > a);
do j--; while(ids[j] < a);
if (j < i) break;
- SWAP(ids[i],ids[j]);
+ MIDL_SWAP(ids[i],ids[j]);
}
ids[l+1] = ids[j];
ids[j] = a;
unsigned x, i;
x = mdb_mid2l_search( ids, id->mid );
- assert( x > 0 );
if( x < 1 ) {
/* internal error */