From 2395564c172d51862e28901b848e16cd3b2359b6 Mon Sep 17 00:00:00 2001 From: Andrea Lanfranchi Date: Mon, 26 Jul 2021 19:28:10 +0200 Subject: [PATCH] mdbx++: add `cursor::erase()` overloads for `key` and for `key-value`. Resolves https://github.com/erthink/libmdbx/pull/226 --- mdbx.h++ | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mdbx.h++ b/mdbx.h++ index d44f930d..a87877fd 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -3626,6 +3626,7 @@ public: inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length); + /// \brief Removes all values for given key. inline bool erase(map_handle map, const slice &key); /// \brief Removes the particular multi-value entry of the key. @@ -3864,7 +3865,18 @@ public: inline slice update_reserve(const slice &key, size_t value_length); inline value_result try_update_reserve(const slice &key, size_t value_length); + /// \brief Removes single key-value pair or all multi-values at the current + /// cursor position. inline bool erase(bool whole_multivalue = false); + + /// \brief Seeks and removes first value or whole multi-value of the given + /// key. + /// \return `True` if the key is found and a value(s) is removed. + inline bool erase(const slice &key, bool whole_multivalue = true); + + /// \brief Seeks and removes the particular multi-value entry of the key. + /// \return `True` if the given key-value pair is found and removed. + inline bool erase(const slice &key, const slice &value); }; /// \brief Managed cursor. @@ -5740,6 +5752,16 @@ inline bool cursor::erase(bool whole_multivalue) { } } +inline bool cursor::erase(const slice &key, bool whole_multivalue) { + bool found = seek(key); + return found ? erase(whole_multivalue) : found; +} + +inline bool cursor::erase(const slice &key, const slice &value) { + move_result data = find_multivalue(key, value, false); + return data.done ? erase() : data.done; +} + } // namespace mdbx //------------------------------------------------------------------------------