mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 11:29:19 +08:00
mdbx: const
для начала и конца диапазона в аргументах mdbx_estimate_range()
.
This commit is contained in:
parent
b7605e8033
commit
44beae00ec
6
mdbx.h
6
mdbx.h
@ -5244,8 +5244,10 @@ LIBMDBX_API int mdbx_estimate_move(const MDBX_cursor *cursor, MDBX_val *key,
|
|||||||
*
|
*
|
||||||
* \returns A non-zero error value on failure and 0 on success. */
|
* \returns A non-zero error value on failure and 0 on success. */
|
||||||
LIBMDBX_API int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi,
|
LIBMDBX_API int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi,
|
||||||
MDBX_val *begin_key, MDBX_val *begin_data,
|
const MDBX_val *begin_key,
|
||||||
MDBX_val *end_key, MDBX_val *end_data,
|
const MDBX_val *begin_data,
|
||||||
|
const MDBX_val *end_key,
|
||||||
|
const MDBX_val *end_data,
|
||||||
ptrdiff_t *distance_items);
|
ptrdiff_t *distance_items);
|
||||||
|
|
||||||
/** \brief The EPSILON value for mdbx_estimate_range()
|
/** \brief The EPSILON value for mdbx_estimate_range()
|
||||||
|
34
src/core.c
34
src/core.c
@ -24725,9 +24725,10 @@ int mdbx_estimate_move(const MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
|
|||||||
return mdbx_estimate_distance(cursor, &next.outer, distance_items);
|
return mdbx_estimate_distance(cursor, &next.outer, distance_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi,
|
||||||
MDBX_val *begin_data, MDBX_val *end_key,
|
const MDBX_val *begin_key, const MDBX_val *begin_data,
|
||||||
MDBX_val *end_data, ptrdiff_t *size_items) {
|
const MDBX_val *end_key, const MDBX_val *end_data,
|
||||||
|
ptrdiff_t *size_items) {
|
||||||
int rc = check_txn(txn, MDBX_TXN_BLOCKED);
|
int rc = check_txn(txn, MDBX_TXN_BLOCKED);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
@ -24755,13 +24756,13 @@ int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
|||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MDBX_val stub;
|
||||||
if (!begin_key) {
|
if (!begin_key) {
|
||||||
if (unlikely(!end_key)) {
|
if (unlikely(!end_key)) {
|
||||||
/* LY: FIRST..LAST case */
|
/* LY: FIRST..LAST case */
|
||||||
*size_items = (ptrdiff_t)begin.outer.mc_db->md_entries;
|
*size_items = (ptrdiff_t)begin.outer.mc_db->md_entries;
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
MDBX_val stub = {0, 0};
|
|
||||||
rc = cursor_first(&begin.outer, &stub, &stub);
|
rc = cursor_first(&begin.outer, &stub, &stub);
|
||||||
if (unlikely(end_key == MDBX_EPSILON)) {
|
if (unlikely(end_key == MDBX_EPSILON)) {
|
||||||
/* LY: FIRST..+epsilon case */
|
/* LY: FIRST..+epsilon case */
|
||||||
@ -24773,7 +24774,6 @@ int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
|||||||
if (unlikely(begin_key == MDBX_EPSILON)) {
|
if (unlikely(begin_key == MDBX_EPSILON)) {
|
||||||
if (end_key == NULL) {
|
if (end_key == NULL) {
|
||||||
/* LY: -epsilon..LAST case */
|
/* LY: -epsilon..LAST case */
|
||||||
MDBX_val stub = {0, 0};
|
|
||||||
rc = cursor_last(&begin.outer, &stub, &stub);
|
rc = cursor_last(&begin.outer, &stub, &stub);
|
||||||
return (rc == MDBX_SUCCESS)
|
return (rc == MDBX_SUCCESS)
|
||||||
? mdbx_cursor_count(&begin.outer, (size_t *)size_items)
|
? mdbx_cursor_count(&begin.outer, (size_t *)size_items)
|
||||||
@ -24791,7 +24791,7 @@ int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
|||||||
(begin_key == end_key ||
|
(begin_key == end_key ||
|
||||||
begin.outer.mc_dbx->md_cmp(begin_key, end_key) == 0)) {
|
begin.outer.mc_dbx->md_cmp(begin_key, end_key) == 0)) {
|
||||||
/* LY: single key case */
|
/* LY: single key case */
|
||||||
rc = cursor_set(&begin.outer, begin_key, NULL, MDBX_SET).err;
|
rc = cursor_set(&begin.outer, (MDBX_val *)begin_key, NULL, MDBX_SET).err;
|
||||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||||
*size_items = 0;
|
*size_items = 0;
|
||||||
return (rc == MDBX_NOTFOUND) ? MDBX_SUCCESS : rc;
|
return (rc == MDBX_NOTFOUND) ? MDBX_SUCCESS : rc;
|
||||||
@ -24812,10 +24812,14 @@ int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
} else {
|
} else if (begin_data) {
|
||||||
rc = cursor_set(&begin.outer, begin_key, begin_data,
|
stub = *begin_data;
|
||||||
begin_data ? MDBX_GET_BOTH_RANGE : MDBX_SET_RANGE)
|
rc = cursor_set(&begin.outer, (MDBX_val *)begin_key, &stub,
|
||||||
|
MDBX_GET_BOTH_RANGE)
|
||||||
.err;
|
.err;
|
||||||
|
} else {
|
||||||
|
stub = *begin_key;
|
||||||
|
rc = cursor_set(&begin.outer, &stub, nullptr, MDBX_SET_RANGE).err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24828,13 +24832,15 @@ int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
|||||||
rc = cursor_init(&end.outer, txn, dbi);
|
rc = cursor_init(&end.outer, txn, dbi);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
if (!end_key) {
|
if (!end_key)
|
||||||
MDBX_val stub = {0, 0};
|
|
||||||
rc = cursor_last(&end.outer, &stub, &stub);
|
rc = cursor_last(&end.outer, &stub, &stub);
|
||||||
} else {
|
else if (end_data) {
|
||||||
rc = cursor_set(&end.outer, end_key, end_data,
|
stub = *end_data;
|
||||||
end_data ? MDBX_GET_BOTH_RANGE : MDBX_SET_RANGE)
|
rc = cursor_set(&end.outer, (MDBX_val *)end_key, &stub, MDBX_GET_BOTH_RANGE)
|
||||||
.err;
|
.err;
|
||||||
|
} else {
|
||||||
|
stub = *end_key;
|
||||||
|
rc = cursor_set(&end.outer, &stub, nullptr, MDBX_SET_RANGE).err;
|
||||||
}
|
}
|
||||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||||
if (rc != MDBX_NOTFOUND || !(end.outer.mc_flags & C_INITIALIZED))
|
if (rc != MDBX_NOTFOUND || !(end.outer.mc_flags & C_INITIALIZED))
|
||||||
|
Loading…
Reference in New Issue
Block a user