/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2000-2011 The OpenLDAP Foundation.
+ * Copyright 2000-2013 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
int
mdb_idl_insert_keys(
+ BackendDB *be,
MDB_cursor *cursor,
struct berval *keys,
ID id )
{
+ struct mdb_info *mdb = be->be_private;
MDB_val key, data;
ID lo, hi, *i;
char *err;
- int rc, k;
+ int rc = 0, k;
+ unsigned int flag = MDB_NODUPDATA;
+#ifndef MISALIGNED_OK
+ int kbuf[2];
+#endif
{
char buf[16];
assert( id != NOID );
+#ifndef MISALIGNED_OK
+ if (keys[0].bv_len & ALIGNER)
+ kbuf[1] = 0;
+#endif
for ( k=0; keys[k].bv_val; k++ ) {
/* Fetch the first data item for this key, to see if it
* exists and if it's a range.
*/
- key.mv_size = keys[k].bv_len;
- key.mv_data = keys[k].bv_val;
+#ifndef MISALIGNED_OK
+ if (keys[k].bv_len & ALIGNER) {
+ key.mv_size = sizeof(kbuf);
+ key.mv_data = kbuf;
+ memcpy(key.mv_data, keys[k].bv_val, keys[k].bv_len);
+ } else
+#endif
+ {
+ key.mv_size = keys[k].bv_len;
+ key.mv_data = keys[k].bv_val;
+ }
rc = mdb_cursor_get( cursor, &key, &data, MDB_SET );
err = "c_get";
if ( rc == 0 ) {
}
} else {
/* There's room, just store it */
+ if (id == mdb->mi_nextid)
+ flag |= MDB_APPENDDUP;
goto put1;
}
} else {
}
}
} else if ( rc == MDB_NOTFOUND ) {
+ flag &= ~MDB_APPENDDUP;
put1: data.mv_data = &id;
data.mv_size = sizeof(ID);
- rc = mdb_cursor_put( cursor, &key, &data, MDB_NODUPDATA );
+ rc = mdb_cursor_put( cursor, &key, &data, flag );
/* Don't worry if it's already there */
if ( rc == MDB_KEYEXIST )
rc = 0;
int
mdb_idl_delete_keys(
+ BackendDB *be,
MDB_cursor *cursor,
struct berval *keys,
ID id )
{
- int rc, k;
+ int rc = 0, k;
MDB_val key, data;
ID lo, hi, tmp, *i;
char *err;
+#ifndef MISALIGNED_OK
+ int kbuf[2];
+#endif
{
char buf[16];
}
assert( id != NOID );
+#ifndef MISALIGNED_OK
+ if (keys[0].bv_len & ALIGNER)
+ kbuf[1] = 0;
+#endif
for ( k=0; keys[k].bv_val; k++) {
/* Fetch the first data item for this key, to see if it
* exists and if it's a range.
*/
- key.mv_size = keys[k].bv_len;
- key.mv_data = keys[k].bv_val;
+#ifndef MISALIGNED_OK
+ if (keys[k].bv_len & ALIGNER) {
+ key.mv_size = sizeof(kbuf);
+ key.mv_data = kbuf;
+ memcpy(key.mv_data, keys[k].bv_val, keys[k].bv_len);
+ } else
+#endif
+ {
+ key.mv_size = keys[k].bv_len;
+ key.mv_data = keys[k].bv_val;
+ }
rc = mdb_cursor_get( cursor, &key, &data, MDB_SET );
err = "c_get";
if ( rc == 0 ) {
/* 8 bit Radix sort + insertion sort
*
* based on code from http://www.cubic.org/docs/radix.htm
- * with improvements by mbackes@symas.com and hyc@symas.com
+ * with improvements by ebackes@symas.com and hyc@symas.com
*
* This code is O(n) but has a relatively high constant factor. For lists
* up to ~50 Quicksort is slightly faster; up to ~100 they are even.