mirror of
https://github.com/isar/libmdbx.git
synced 2025-02-03 12:40:52 +08:00
mdbx: initial mdbx_cursor_on_ first/last().
This commit is contained in:
parent
d47d8c25d8
commit
2b924524ec
41
mdbx.c
41
mdbx.c
@ -354,6 +354,47 @@ size_t mdbx_canary_get(MDB_txn *txn, mdbx_canary* canary)
|
||||
return txn->mt_txnid;
|
||||
}
|
||||
|
||||
int mdbx_cursor_on_first(MDB_cursor *mc)
|
||||
{
|
||||
if (unlikely(mc == NULL))
|
||||
return EINVAL;
|
||||
|
||||
if (unlikely(mc->mc_signature != MDBX_MC_SIGNATURE))
|
||||
return MDB_VERSION_MISMATCH;
|
||||
|
||||
if (!(mc->mc_flags & C_INITIALIZED))
|
||||
return MDBX_RESULT_FALSE;
|
||||
|
||||
unsigned i;
|
||||
for(i = 0; i < mc->mc_snum; ++i) {
|
||||
if (mc->mc_ki[i])
|
||||
return MDBX_RESULT_FALSE;
|
||||
}
|
||||
|
||||
return MDBX_RESULT_TRUE;
|
||||
}
|
||||
|
||||
int mdbx_cursor_on_last(MDB_cursor *mc)
|
||||
{
|
||||
if (unlikely(mc == NULL))
|
||||
return EINVAL;
|
||||
|
||||
if (unlikely(mc->mc_signature != MDBX_MC_SIGNATURE))
|
||||
return MDB_VERSION_MISMATCH;
|
||||
|
||||
if (!(mc->mc_flags & C_INITIALIZED))
|
||||
return MDBX_RESULT_FALSE;
|
||||
|
||||
unsigned i;
|
||||
for(i = 0; i < mc->mc_snum; ++i) {
|
||||
unsigned nkeys = NUMKEYS(mc->mc_pg[i]);
|
||||
if (mc->mc_ki[i] != nkeys - 1)
|
||||
return MDBX_RESULT_FALSE;
|
||||
}
|
||||
|
||||
return MDBX_RESULT_TRUE;
|
||||
}
|
||||
|
||||
int mdbx_cursor_eof(MDB_cursor *mc)
|
||||
{
|
||||
if (unlikely(mc == NULL))
|
||||
|
13
mdbx.h
13
mdbx.h
@ -219,10 +219,19 @@ typedef struct mdbx_canary {
|
||||
int mdbx_canary_put(MDB_txn *txn, const mdbx_canary* canary);
|
||||
size_t mdbx_canary_get(MDB_txn *txn, mdbx_canary* canary);
|
||||
|
||||
/* Returns 1 when no more data available or cursor not positioned,
|
||||
* 0 otherwise or less that zero in error case. */
|
||||
/* Returns:
|
||||
* - MDBX_RESULT_TRUE when no more data available
|
||||
* or cursor not positioned;
|
||||
* - MDBX_RESULT_FALSE when data available;
|
||||
* - Otherwise the error code. */
|
||||
int mdbx_cursor_eof(MDB_cursor *mc);
|
||||
|
||||
/* Returns: MDBX_RESULT_TRUE, MDBX_RESULT_FALSE or Error code. */
|
||||
int mdbx_cursor_on_first(MDB_cursor *mc);
|
||||
|
||||
/* Returns: MDBX_RESULT_TRUE, MDBX_RESULT_FALSE or Error code. */
|
||||
int mdbx_cursor_on_last(MDB_cursor *mc);
|
||||
|
||||
#define MDBX_EMULTIVAL (MDB_LAST_ERRCODE - 42)
|
||||
#define MDBX_RESULT_FALSE MDB_SUCCESS
|
||||
#define MDBX_RESULT_TRUE (-1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user