mdbx: добавление mdbx_cursor_on_first/last_dup() в API.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev)
2023-11-18 02:34:07 +03:00
parent eee3e6eb6b
commit ed59ad22c6
3 changed files with 65 additions and 0 deletions

View File

@@ -24533,6 +24533,29 @@ int mdbx_cursor_on_first(const MDBX_cursor *mc) {
return MDBX_RESULT_TRUE;
}
int mdbx_cursor_on_first_dup(const MDBX_cursor *mc) {
if (unlikely(mc == NULL))
return MDBX_EINVAL;
if (unlikely(mc->mc_signature != MDBX_MC_LIVE))
return (mc->mc_signature == MDBX_MC_READY4CLOSE) ? MDBX_EINVAL
: MDBX_EBADSIGN;
if (!(mc->mc_flags & C_INITIALIZED))
return mc->mc_db->md_entries ? MDBX_RESULT_FALSE : MDBX_RESULT_TRUE;
if (!mc->mc_xcursor)
return MDBX_RESULT_TRUE;
mc = &mc->mc_xcursor->mx_cursor;
for (size_t 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(const MDBX_cursor *mc) {
if (unlikely(mc == NULL))
return MDBX_EINVAL;
@@ -24553,6 +24576,30 @@ int mdbx_cursor_on_last(const MDBX_cursor *mc) {
return MDBX_RESULT_TRUE;
}
int mdbx_cursor_on_last_dup(const MDBX_cursor *mc) {
if (unlikely(mc == NULL))
return MDBX_EINVAL;
if (unlikely(mc->mc_signature != MDBX_MC_LIVE))
return (mc->mc_signature == MDBX_MC_READY4CLOSE) ? MDBX_EINVAL
: MDBX_EBADSIGN;
if (!(mc->mc_flags & C_INITIALIZED))
return mc->mc_db->md_entries ? MDBX_RESULT_FALSE : MDBX_RESULT_TRUE;
if (!mc->mc_xcursor)
return MDBX_RESULT_TRUE;
mc = &mc->mc_xcursor->mx_cursor;
for (size_t i = 0; i < mc->mc_snum; ++i) {
size_t nkeys = page_numkeys(mc->mc_pg[i]);
if (mc->mc_ki[i] < nkeys - 1)
return MDBX_RESULT_FALSE;
}
return MDBX_RESULT_TRUE;
}
int mdbx_cursor_eof(const MDBX_cursor *mc) {
if (unlikely(mc == NULL))
return MDBX_EINVAL;