mdbx: adds functions for distance/move/range estimation (initial).

Change-Id: If59eccf7311123ab6384c4b93f9b1fed5a0a10d1
This commit is contained in:
Leonid Yuriev
2019-03-05 02:32:51 +03:00
parent 7d383350e8
commit 8ddfd1f34a
2 changed files with 402 additions and 0 deletions

47
mdbx.h
View File

@@ -1695,6 +1695,53 @@ LIBMDBX_API int mdbx_cursor_on_first(MDBX_cursor *mc);
/* Returns: MDBX_RESULT_TRUE, MDBX_RESULT_FALSE or Error code. */
LIBMDBX_API int mdbx_cursor_on_last(MDBX_cursor *mc);
/* Estimates the distance between cursors as the number of elements.
* Both cursors must be initialized for the same DBI.
*
* [in] cursor_a The first cursor for estimation.
* [in] cursor_b The second cursor for estimation.
* [out] distance_items A pointer to store estimated distance value,
* i.e. *distance_items = distance(a - b).
*
* Returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_estimate_distance(const MDBX_cursor *first,
const MDBX_cursor *last,
ptrdiff_t *distance_items);
/* Estimates the move distance, i.e. between the current cursor position and
* next position after the specified move-operation with given key and data.
* Current cursor position and state are preserved.
*
* [in] cursor Cursor for estimation.
* [in,out] key The key for a retrieved item.
* [in,out] data The data of a retrieved item.
* [in] op A cursor operation MDBX_cursor_op.
* [out] distance_items A pointer to store estimated move distance
* as the number of elements.
*
* Returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_estimate_move(const MDBX_cursor *cursor, MDBX_val *key,
MDBX_val *data, MDBX_cursor_op move_op,
ptrdiff_t *distance_items);
/* Estimates the size of a range in the number of elements.
*
* [in] txn A transaction handle returned by mdbx_txn_begin().
* [in] dbi A database handle returned by mdbx_dbi_open().
* [in] begin_key The key of range beginning or NULL for explicit FIRST.
* [in] begin_data Optional additional data to seeking among sorted
* duplicates. Only for MDBX_DUPSORT, NULL otherwise.
* [in] end_key The key of range ending or NULL for explicit LAST.
* [in] end_data Optional additional data to seeking among sorted
* duplicates. Only for MDBX_DUPSORT, NULL otherwise.
* [out] distance_items A pointer to store range estimation result.
*
* Returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_estimate_range(MDBX_txn *txn, MDBX_dbi dbi,
MDBX_val *begin_key, MDBX_val *begin_data,
MDBX_val *end_key, MDBX_val *end_data,
ptrdiff_t *size_items);
LIBMDBX_API int mdbx_replace(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
MDBX_val *new_data, MDBX_val *old_data,
unsigned flags);