From 77ac97879ae869e53dc033fc5b544a46237ad01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Mon, 17 Nov 2025 14:51:22 +0300 Subject: [PATCH] mdbx++: add `cursor::update_current()` and `cursor::reverse_current()`. --- mdbx.h++ | 5 +++++ src/mdbx.c++ | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/mdbx.h++ b/mdbx.h++ index 6a44a6f8..c3e34466 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -4487,6 +4487,11 @@ public: inline void upsert(const slice &key, const slice &value); inline slice upsert_reserve(const slice &key, size_t value_length); + /// \brief Updates value associated with a key at the current cursor position. + void update_current(const slice &value); + /// \brief Reserves and returns the space to storing a value associated with a key at the current cursor position. + slice reverse_current(size_t value_length); + inline void update(const slice &key, const slice &value); inline bool try_update(const slice &key, const slice &value); inline slice update_reserve(const slice &key, size_t value_length); diff --git a/src/mdbx.c++ b/src/mdbx.c++ index d09cbc21..6f50fd55 100644 --- a/src/mdbx.c++ +++ b/src/mdbx.c++ @@ -1609,6 +1609,26 @@ __cold bool txn::rename_map(const ::std::string &old_name, const ::std::string & //------------------------------------------------------------------------------ +void cursor::update_current(const slice &value) { + default_buffer holder; + auto key = current().key; + if (error::boolean_or_throw(mdbx_is_dirty(handle_->txn, key.iov_base))) + key = holder.assign(key); + + update(key, value); +} + +slice cursor::reverse_current(size_t value_length) { + default_buffer holder; + auto key = current().key; + if (error::boolean_or_throw(mdbx_is_dirty(handle_->txn, key.iov_base))) + key = holder.assign(key); + + return update_reserve(key, value_length); +} + +//------------------------------------------------------------------------------ + __cold ::std::ostream &operator<<(::std::ostream &out, const slice &it) { out << "{"; if (!it.is_valid())