Skip to content

Commit f24d7d2

Browse files
hychfuru
authored andcommitted
Add MDB_PREV_MULTIPLE (collected mdb.master changes)
Logical counterpart to GET_MULTIPLE, NEXT_MULTIPLE
1 parent fe2b1cd commit f24d7d2

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

libraries/liblmdb/lmdb.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ typedef enum MDB_cursor_op {
388388
MDB_PREV_NODUP, /**< Position at last data item of previous key */
389389
MDB_SET, /**< Position at specified key */
390390
MDB_SET_KEY, /**< Position at specified key, return key + data */
391-
MDB_SET_RANGE /**< Position at first key greater than or equal to specified key. */
391+
MDB_SET_RANGE, /**< Position at first key greater than or equal to specified key. */
392+
MDB_PREV_MULTIPLE /**< Position at previous page and return key and up to
393+
a page of duplicate data items. Only for #MDB_DUPFIXED */
392394
} MDB_cursor_op;
393395

394396
/** @defgroup errors Return Codes
@@ -1095,8 +1097,9 @@ int mdb_txn_renew(MDB_txn *txn);
10951097
* This flag may only be used in combination with #MDB_DUPSORT. This option
10961098
* tells the library that the data items for this database are all the same
10971099
* size, which allows further optimizations in storage and retrieval. When
1098-
* all data items are the same size, the #MDB_GET_MULTIPLE and #MDB_NEXT_MULTIPLE
1099-
* cursor operations may be used to retrieve multiple items at once.
1100+
* all data items are the same size, the #MDB_GET_MULTIPLE, #MDB_NEXT_MULTIPLE
1101+
* and #MDB_PREV_MULTIPLE cursor operations may be used to retrieve multiple
1102+
* items at once.
11001103
* <li>#MDB_INTEGERDUP
11011104
* This option specifies that duplicate data items are binary integers,
11021105
* similar to #MDB_INTEGERKEY keys.

libraries/liblmdb/mdb.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ mdb_strerror(int err)
14371437
* and the actual use of the message uses more than 4K of stack.
14381438
*/
14391439
#define MSGSIZE 1024
1440-
#define PADSIZE 4096
1440+
#define PADSIZE 4096
14411441
char buf[MSGSIZE+PADSIZE], *ptr = buf;
14421442
#endif
14431443
int i;
@@ -6215,6 +6215,30 @@ mdb_cursor_get(MDB_cursor *mc, MDB_val *key, MDB_val *data,
62156215
}
62166216
}
62176217
break;
6218+
case MDB_PREV_MULTIPLE:
6219+
if (data == NULL) {
6220+
rc = EINVAL;
6221+
break;
6222+
}
6223+
if (!(mc->mc_db->md_flags & MDB_DUPFIXED)) {
6224+
rc = MDB_INCOMPATIBLE;
6225+
break;
6226+
}
6227+
if (!(mc->mc_flags & C_INITIALIZED))
6228+
rc = mdb_cursor_last(mc, key, data);
6229+
else
6230+
rc = MDB_SUCCESS;
6231+
if (rc == MDB_SUCCESS) {
6232+
MDB_cursor *mx = &mc->mc_xcursor->mx_cursor;
6233+
if (mx->mc_flags & C_INITIALIZED) {
6234+
rc = mdb_cursor_sibling(mx, 0);
6235+
if (rc == MDB_SUCCESS)
6236+
goto fetchm;
6237+
} else {
6238+
rc = MDB_NOTFOUND;
6239+
}
6240+
}
6241+
break;
62186242
case MDB_NEXT:
62196243
case MDB_NEXT_DUP:
62206244
case MDB_NEXT_NODUP:

0 commit comments

Comments
 (0)