libmdbx 0.14.1.444 (2026-03-04T00:16:49+03:00)
One of the fastest compact embeddable key-value ACID storage engine without WAL.
Loading...
Searching...
No Matches
mdbx.h++
Go to the documentation of this file.
1
25
26#pragma once
27
28//
29// Tested with, since 2026:
30// - Elbrus LCC >= 1.28 (http://www.mcst.ru/lcc);
31// - GNU C++ >= 11.3;
32// - CLANG >= 14.0;
33// - MSVC >= 19.44 (Visual Studio 2022 toolchain v143),
34// before 2026:
35// - Elbrus LCC >= 1.23 (http://www.mcst.ru/lcc);
36// - GNU C++ >= 4.8;
37// - CLANG >= 3.9;
38// - MSVC >= 14.0 (Visual Studio 2015),
39// but 19.2x could hang due optimizer bug;
40// - AppleClang, but without C++20 concepts.
41//
42
43/* Workaround for modern libstdc++ with CLANG < 4.x */
44#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4
45#define __GLIBCXX_BITSIZE_INT_N_0 128
46#define __GLIBCXX_TYPE_INT_N_0 __int128
47#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
48
49#if !defined(__cplusplus) || __cplusplus < 201103L
50#if !defined(_MSC_VER) || _MSC_VER < 1900
51#error "C++11 compiler or better is required"
52#elif _MSC_VER >= 1910
53#error "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
54#endif /* MSVC is mad and don't define __cplusplus properly */
55#endif /* __cplusplus < 201103L */
56
57#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
58#error "CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
59#endif /* Windows */
60
61#ifndef __has_include
62#define __has_include(header) (0)
63#endif /* __has_include */
64
65#if __has_include(<version>)
66#include <version>
67#endif /* <version> */
68
69/* Disable min/max macros from C' headers */
70#ifndef NOMINMAX
71#define NOMINMAX
72#endif
73
74#include <algorithm> // for std::min/max
75#include <cassert> // for assert()
76#include <climits> // for CHAR_BIT
77#include <cstring> // for std::strlen, str:memcmp
78#include <exception> // for std::exception_ptr
79#include <ostream> // for std::ostream
80#include <sstream> // for std::ostringstream
81#include <stdexcept> // for std::invalid_argument
82#include <string> // for std::string
83#include <type_traits> // for std::is_pod<>, etc.
84#include <utility> // for std::make_pair
85#include <vector> // for std::vector<> as template args
86
87#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
88#include <memory_resource>
89#endif
90
91#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
92#include <string_view>
93#endif
94
95#ifndef MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
96#ifdef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
97#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
98#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && __cplusplus >= 201703L
99#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
100#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
101 (defined(_MSC_VER) && defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && __cplusplus >= 201403L))
102#if defined(__cpp_lib_experimental_filesystem) && __cpp_lib_experimental_filesystem >= 201406L
103#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
104#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && __has_include(<experimental/filesystem>)
105#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
106#else
107#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
108#endif
109#else
110#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
111#endif
112#endif /* MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM */
113
114#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
115#include <experimental/filesystem>
116#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
117#include <filesystem>
118#endif
119
120#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
121#include <span>
122#endif
123
124#if !defined(_MSC_VER) || defined(__clang__)
125#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class API_ATTRIBUTES __VA_ARGS__
126#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class __VA_ARGS__
127#else
128#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class __VA_ARGS__
129#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class API_ATTRIBUTES __VA_ARGS__
130#endif
131
132#if defined(_MSC_VER) && _MSC_VER >= 1900
133#define MDBX_MSVC_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
134#else
135#define MDBX_MSVC_DECLSPEC_EMPTY_BASES /* nope */
136#endif /* _MSC_VER >= 1900 */
137
138#if __cplusplus >= 201103L
139#include <chrono>
140#include <ratio>
141#endif
142
143#include "mdbx.h"
144
145#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
146 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
147 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
148 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
149#include <bit>
150#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
151#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
152#define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
153#define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
154#define __BYTE_ORDER__ __BYTE_ORDER
155#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
156#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
157#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
158#define __BYTE_ORDER__ _BYTE_ORDER
159#else
160#define __ORDER_LITTLE_ENDIAN__ 1234
161#define __ORDER_BIG_ENDIAN__ 4321
162#if defined(__LITTLE_ENDIAN__) || (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || defined(__ARMEL__) || \
163 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
164 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || defined(__elbrus_4c__) || defined(__elbrus_8c__) || \
165 defined(__bfin__) || defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
166 defined(__ia64) || defined(_M_IA64) || defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
167 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || defined(__WINDOWS__)
168#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
169#elif defined(__BIG_ENDIAN__) || (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || defined(__ARMEB__) || \
170 defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
171 defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
172 defined(__sparc__) || defined(__sparc) || defined(__370__) || defined(__THW_370__) || defined(__s390__) || \
173 defined(__s390x__) || defined(__SYSC_ZARCH__)
174#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
175#endif
176#endif
177#endif /* Byte Order */
178
180#if defined(DOXYGEN)
181#define MDBX_CXX17_CONSTEXPR constexpr
182#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
183 ((defined(_MSC_VER) && _MSC_VER >= 1915) || (defined(__clang__) && __clang_major__ > 5) || \
184 (defined(__GNUC__) && __GNUC__ > 7) || (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
185#define MDBX_CXX17_CONSTEXPR constexpr
186#else
187#define MDBX_CXX17_CONSTEXPR inline
188#endif /* MDBX_CXX17_CONSTEXPR */
189
191#if defined(DOXYGEN)
192#define MDBX_CXX20_CONSTEXPR constexpr
193#elif defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L && \
194 defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
195#define MDBX_CXX20_CONSTEXPR constexpr
196#else
197#define MDBX_CXX20_CONSTEXPR inline
198#endif /* MDBX_CXX20_CONSTEXPR */
199
200#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
201#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
202#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
203#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
204#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
205#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
206#else
207#define MDBX_CXX01_CONSTEXPR_ENUM inline
208#define MDBX_CXX11_CONSTEXPR_ENUM inline
209#define MDBX_CXX14_CONSTEXPR_ENUM inline
210#define MDBX_CXX17_CONSTEXPR_ENUM inline
211#define MDBX_CXX20_CONSTEXPR_ENUM inline
212#endif /* CONSTEXPR_ENUM_FLAGS_OPERATIONS */
213
215#if defined(CONSTEXPR_ASSERT)
216#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
217#elif defined NDEBUG
218#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
219#else
220#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
221#endif /* MDBX_CONSTEXPR_ASSERT */
222
223#ifndef MDBX_LIKELY
224#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
225#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
226#else
227#define MDBX_LIKELY(x) (x)
228#endif
229#endif /* MDBX_LIKELY */
230
231#ifndef MDBX_UNLIKELY
232#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
233#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
234#else
235#define MDBX_UNLIKELY(x) (x)
236#endif
237#endif /* MDBX_UNLIKELY */
238
240#if defined(DOXYGEN)
241#define MDBX_IF_CONSTEXPR constexpr
242#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
243#define MDBX_IF_CONSTEXPR constexpr
244#else
245#define MDBX_IF_CONSTEXPR
246#endif /* MDBX_IF_CONSTEXPR */
247
248#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
249 __cplusplus >= 201703L
250#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
251#else
252#define MDBX_CXX17_FALLTHROUGH
253#endif /* MDBX_CXX17_FALLTHROUGH */
254
255#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
256#define MDBX_CXX20_LIKELY [[likely]]
257#else
258#define MDBX_CXX20_LIKELY
259#endif /* MDBX_CXX20_LIKELY */
260
261#ifndef MDBX_CXX20_UNLIKELY
262#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
263#define MDBX_CXX20_UNLIKELY [[unlikely]]
264#else
265#define MDBX_CXX20_UNLIKELY
266#endif
267#endif /* MDBX_CXX20_UNLIKELY */
268
269#ifndef MDBX_HAVE_CXX20_CONCEPTS
270#if defined(__cpp_concepts) && __cpp_concepts >= 202002L && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
271#include <concepts>
272#define MDBX_HAVE_CXX20_CONCEPTS 1
273#elif defined(DOXYGEN)
274#define MDBX_HAVE_CXX20_CONCEPTS 1
275#else
276#define MDBX_HAVE_CXX20_CONCEPTS 0
277#endif /* <concepts> */
278#endif /* MDBX_HAVE_CXX20_CONCEPTS */
279
280#ifndef MDBX_CXX20_CONCEPT
281#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
282#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
283#else
284#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
285#endif
286#endif /* MDBX_CXX20_CONCEPT */
287
288#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
289#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
290#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
291#else
292#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
293 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
294#endif
295#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
296
297#ifdef _MSC_VER
298#pragma warning(push, 4)
299#pragma warning(disable : 4127) /* conditional expression is constant */
300#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
301 be used by clients of 'mdbx::BAR' */
302#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
303 base for dll-interface 'mdbx::BAR' */
304/* MSVC is mad and can generate this warning for its own intermediate
305 * automatically generated code, which becomes unreachable after some kinds of
306 * optimization (copy elision, etc). */
307#pragma warning(disable : 4702) /* unreachable code */
308#endif /* _MSC_VER (warnings) */
309
310#if defined(__LCC__) && __LCC__ >= 126
311#pragma diagnostic push
312#if __LCC__ < 127
313#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
314 appearing in a constant expression `true` */
315#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
316 appearing in a constant expression `false` */
317#endif
318#endif /* E2K LCC (warnings) */
319
320//------------------------------------------------------------------------------
323namespace mdbx {
324
327
345#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
346using byte = char8_t;
347#else
348// Avoid `std::byte` since it doesn't add features but inconvenient restrictions.
349using byte = unsigned char;
350#endif /* __cpp_char8_t >= 201811*/
351
352#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
353using endian = ::std::endian;
354#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
355enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
356#else
357#error "Please use a C++ compiler provides byte order information or C++20 support"
358#endif /* Byte Order enum */
359
368
370static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
371
373static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
375static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
376
379using legacy_allocator = ::std::string::allocator_type;
380
383#if defined(DOXYGEN)
384#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
385#elif !defined(MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR)
386#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && \
387 (!defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI)
388#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
389#else
390#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 0
391#endif
392#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
393
394#if defined(DOXYGEN) || MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
396using polymorphic_allocator = ::std::pmr::string::allocator_type;
398#else
400#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
401
402struct slice;
404template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
406class env;
407class env_managed;
408class txn;
409class txn_managed;
410class cursor;
411class cursor_managed;
412
414using txnid = uint64_t;
415
417template <class ALLOCATOR = default_allocator>
418using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
419
421#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
422#ifdef _MSC_VER
423namespace filesystem = ::std::experimental::filesystem::v1;
424#else
425namespace filesystem = ::std::experimental::filesystem;
426#endif
427#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
428#elif defined(DOXYGEN) || \
429 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
430 __cpp_lib_string_view >= 201606L && \
431 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
432 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
433 (!defined(_MSC_VER) || __cplusplus >= 201703L)
434namespace filesystem = ::std::filesystem;
440#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
441#endif /* MDBX_STD_FILESYSTEM_PATH */
442
443#ifdef MDBX_STD_FILESYSTEM_PATH
445using path_string = MDBX_STD_FILESYSTEM_PATH::string_type;
446#elif defined(_WIN32) || defined(_WIN64)
447using path = ::std::wstring;
448using path_string = path;
449#else
450using path = ::std::string;
451using path_string = path;
452#endif /* mdbx::path */
453using path_char = path_string::value_type;
454
455#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
456#ifndef MDBX_U128_TYPE
457#define MDBX_U128_TYPE __uint128_t
458#endif /* MDBX_U128_TYPE */
459#ifndef MDBX_I128_TYPE
460#define MDBX_I128_TYPE __int128_t
461#endif /* MDBX_I128_TYPE */
462#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
463
464#if __cplusplus >= 201103L || defined(DOXYGEN)
466using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
467#endif /* Duration for C++11 */
468
471
477 ::std::exception_ptr captured_;
478
479public:
480 exception_thunk() noexcept = default;
483 exception_thunk &operator=(const exception_thunk &) = delete;
484 exception_thunk &operator=(exception_thunk &&) = delete;
485 inline bool is_clean() const noexcept;
486 inline void capture() noexcept;
487 inline void rethrow_captured() const;
488};
489
492 MDBX_error_t code_;
493 inline error &operator=(MDBX_error_t error_code) noexcept;
494
495public:
496 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
497 error(const error &) = default;
498 error(error &&) = default;
499 error &operator=(const error &) = default;
500 error &operator=(error &&) = default;
501
502 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
503 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
504
505 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
506 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
507 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
508 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
509
511 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
512
514 const char *what() const noexcept;
515
517 ::std::string message() const;
518
520 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
522 [[noreturn]] void panic(const char *context_where_when, const char *func_who_what) const noexcept;
523 [[noreturn]] void throw_exception() const;
524 [[noreturn]] static inline void throw_exception(int error_code);
525 inline void throw_on_failure() const;
526 inline void success_or_throw() const;
527 inline void success_or_throw(const exception_thunk &) const;
528 inline void panic_on_failure(const char *context_where, const char *func_who) const noexcept;
529 inline void success_or_panic(const char *context_where, const char *func_who) const noexcept;
530 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
531 static inline void success_or_throw(MDBX_error_t error_code);
532 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
533 static inline void throw_on_failure(int error_code);
534 static inline bool boolean_or_throw(int error_code);
535 static inline void success_or_throw(int error_code, const exception_thunk &);
536 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
537 static inline void panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept;
538 static inline void success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept;
539};
540
543class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
544 using base = ::std::runtime_error;
545 ::mdbx::error error_;
546
547public:
548 exception(const ::mdbx::error &) noexcept;
549 exception(const exception &) = default;
550 exception(exception &&) = default;
551 exception &operator=(const exception &) = default;
553 virtual ~exception() noexcept;
554 const ::mdbx::error error() const noexcept { return error_; }
555};
556
559 using base = exception;
560
561public:
562 fatal(const ::mdbx::error &) noexcept;
563 fatal(const exception &src) noexcept : fatal(src.error()) {}
564 fatal(exception &&src) noexcept : fatal(src.error()) {}
565 fatal(const fatal &src) noexcept : fatal(src.error()) {}
566 fatal(fatal &&src) noexcept : fatal(src.error()) {}
567 fatal &operator=(fatal &&) = default;
568 fatal &operator=(const fatal &) = default;
569 virtual ~fatal() noexcept;
570};
571
572#define MDBX_DECLARE_EXCEPTION(NAME) \
573 struct LIBMDBX_API_TYPE NAME : public exception { \
574 NAME(const ::mdbx::error &); \
575 virtual ~NAME() noexcept; \
576 }
610#undef MDBX_DECLARE_EXCEPTION
611
614[[noreturn]] LIBMDBX_API void throw_out_range();
618
619static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
620 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
621 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
622 return bytes;
623}
624
625static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
626 return check_length(check_length(headroom) + check_length(payload));
627}
628
629MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
630 return check_length(check_length(headroom, payload) + check_length(tailroom));
631}
632
634
635//------------------------------------------------------------------------------
636
639
651
652 enum : size_t { max_length = MDBX_MAXDATASIZE };
653
655 MDBX_CXX11_CONSTEXPR slice() noexcept;
656
658 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
659
661 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
662
664 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
665 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
666 }
667
668 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
669
672 template <class CHAR, class T, class A>
673 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
674 : slice(str.data(), str.length() * sizeof(CHAR)) {}
675
677 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
679 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
680
681#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
682 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
683 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
684 "Must be a standard layout type!");
685 }
686
687 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
688 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
689 "Must be a standard layout type!");
690 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
692 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
694 }
695
696 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
697 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
698 "Must be a standard layout type!");
699 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
701 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
703 }
704
705 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
706 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
707 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
708 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
709#endif /* __cpp_lib_span >= 202002L */
710
711#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
713 template <class CHAR, class T>
714 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv) : slice(sv.data(), sv.data() + sv.length()) {}
715
716 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
717#endif /* __cpp_lib_string_view >= 201606L */
718
719 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
720
721 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
722 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
723 "Must be a standard layout type!");
724 return slice(&pod, sizeof(pod));
725 }
726
727 inline slice &assign(const void *ptr, size_t bytes);
728 inline slice &assign(const slice &src) noexcept;
729 inline slice &assign(const ::MDBX_val &src);
730 inline slice &assign(slice &&src) noexcept;
731 inline slice &assign(::MDBX_val &&src);
732 inline slice &assign(const void *begin, const void *end);
733 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
734 return assign(str.data(), str.length() * sizeof(CHAR));
735 }
736 inline slice &assign(const char *c_str);
737#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
738 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
739 return assign(view.begin(), view.end());
740 }
741 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
742 assign(view);
743 view = {};
744 return *this;
745 }
746#endif /* __cpp_lib_string_view >= 201606L */
747
748 slice &operator=(const slice &) noexcept = default;
749 inline slice &operator=(slice &&src) noexcept;
750 inline slice &operator=(::MDBX_val &&src);
751 operator MDBX_val *() noexcept { return this; }
752 operator const MDBX_val *() const noexcept { return this; }
753
754#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
755 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
756 return assign(view);
757 }
758
759 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
760
762 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
763 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
764 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
765 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
766 }
767
769 template <class CHAR, class T>
770 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
771 return this->string_view<CHAR, T>();
772 }
773#endif /* __cpp_lib_string_view >= 201606L */
774
775 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
776 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
777 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
778 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
779 }
780
781 template <class CHAR, class T, class ALLOCATOR>
782 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
784 }
785
787 template <class ALLOCATOR = default_allocator>
788 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
789 const ALLOCATOR &alloc = ALLOCATOR()) const;
790
793 template <class ALLOCATOR = default_allocator>
794 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
795
798 template <class ALLOCATOR = default_allocator>
799 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
800
802 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
803 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
804 const ALLOCATOR &alloc = ALLOCATOR()) const;
805
808 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
809 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
810 const ALLOCATOR &alloc = ALLOCATOR()) const;
811
814 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
815 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
816 const ALLOCATOR &alloc = ALLOCATOR()) const;
817
819 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
820 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
821 const ALLOCATOR &alloc = ALLOCATOR()) const;
822
825 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
826 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
827 const ALLOCATOR &alloc = ALLOCATOR()) const;
828
831 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
832 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
833 const ALLOCATOR &alloc = ALLOCATOR()) const;
834
840 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
841
846 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
847
853 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
854
860 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
861
862#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
863 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
864 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
865 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
866 *this = view;
867 view = temp;
868 }
869#endif /* __cpp_lib_string_view >= 201606L */
870
872 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
873 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
874
876 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
877 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
878
880 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
881 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
882
884 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
885 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
886
888 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
889 MDBX_CXX11_CONSTEXPR void *data() noexcept;
890
892 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
893 MDBX_CXX11_CONSTEXPR void *end() noexcept;
894
896 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
897
899 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
900
902 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
903
905 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
906
908 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
909
911 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
912
914 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
915
917 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
918
920 MDBX_CXX14_CONSTEXPR void clear() noexcept;
921
924 inline void remove_prefix(size_t n) noexcept;
925
928 inline void remove_suffix(size_t n) noexcept;
929
932 inline void safe_remove_prefix(size_t n);
933
936 inline void safe_remove_suffix(size_t n);
937
939 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
940
942 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
943
946 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
947
950 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
951
954 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
955
958 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
959
962 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
963
966 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
967
970 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
971
974 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
975
980 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
981
990 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
991
997 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
998 const slice &b) noexcept;
999 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
1000 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
1001 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
1002 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
1003 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
1004 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
1005#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1006 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
1007#endif /* __cpp_impl_three_way_comparison */
1008
1010 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1011
1014 return slice(/* using special constructor without length checking */ ~size_t(0));
1015 }
1016
1018 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1019
1020 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1021 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1022 "Must be a standard layout type!");
1023 if (MDBX_LIKELY(size() == sizeof(POD)))
1025 POD r;
1026 memcpy(&r, data(), sizeof(r));
1027 return r;
1028 }
1030 }
1031
1032#ifdef MDBX_U128_TYPE
1033 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1034#endif /* MDBX_U128_TYPE */
1035 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1036 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1037 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1038 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1039
1040#ifdef MDBX_I128_TYPE
1041 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1042#endif /* MDBX_I128_TYPE */
1043 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1044 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1045 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1046 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1047
1048#ifdef MDBX_U128_TYPE
1049 MDBX_U128_TYPE as_uint128_adapt() const;
1050#endif /* MDBX_U128_TYPE */
1051 uint64_t as_uint64_adapt() const;
1052 uint32_t as_uint32_adapt() const;
1053 uint16_t as_uint16_adapt() const;
1054 uint8_t as_uint8_adapt() const;
1055
1056#ifdef MDBX_I128_TYPE
1057 MDBX_I128_TYPE as_int128_adapt() const;
1058#endif /* MDBX_I128_TYPE */
1059 int64_t as_int64_adapt() const;
1060 int32_t as_int32_adapt() const;
1061 int16_t as_int16_adapt() const;
1062 int8_t as_int8_adapt() const;
1063
1064protected:
1065 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1066};
1067
1071 bool done;
1072 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
1073 value_result(const value_result &) noexcept = default;
1074 value_result &operator=(const value_result &) noexcept = default;
1075 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1076 assert(!done || bool(value));
1077 return done;
1078 }
1079};
1080
1082struct pair {
1083 using stl_pair = std::pair<slice, slice>;
1085 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
1086 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
1087 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
1088 pair(const pair &) noexcept = default;
1089 pair &operator=(const pair &) noexcept = default;
1090 pair &operator=(pair &&couple) {
1091 key.assign(std::move(couple.key));
1092 value.assign(std::move(couple.value));
1093 return *this;
1094 }
1095 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1096 assert(bool(key) == bool(value));
1097 return key;
1098 }
1100
1101 pair &operator=(const stl_pair &couple) {
1102 key.assign(couple.first);
1103 value.assign(couple.second);
1104 return *this;
1105 }
1107 key.assign(std::move(couple.first));
1108 value.assign(std::move(couple.second));
1109 return *this;
1110 }
1111
1113 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
1114
1116 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
1117 const pair &b) noexcept;
1118 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
1119 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
1120 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
1121 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
1122 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
1123 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
1124#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1125 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
1126#endif /* __cpp_impl_three_way_comparison */
1127};
1128
1131struct pair_result : public pair {
1132 bool done;
1135 : pair(key, value), done(done) {}
1136 pair_result(const pair_result &) noexcept = default;
1137 pair_result &operator=(const pair_result &) noexcept = default;
1138 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1139 assert(!done || (bool(key) && bool(value)));
1140 return done;
1141 }
1142};
1143
1144#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
1145
1149template <typename T>
1150concept MutableByteProducer = requires(T a, char array[42]) {
1151 { a.is_empty() } -> std::same_as<bool>;
1152 { a.envisage_result_length() } -> std::same_as<size_t>;
1153 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1154};
1155
1159template <typename T>
1160concept ImmutableByteProducer = requires(const T &a, char array[42]) {
1161 { a.is_empty() } -> std::same_as<bool>;
1162 { a.envisage_result_length() } -> std::same_as<size_t>;
1163 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1164};
1165
1169template <typename T>
1170concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
1171 T(source);
1172 { a.is_erroneous() } -> std::same_as<bool>;
1173};
1174
1175#endif /* MDBX_HAVE_CXX20_CONCEPTS */
1176
1180 const bool uppercase = false;
1181 const unsigned wrap_width = 0;
1186
1188 template <class ALLOCATOR = default_allocator>
1189 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1190
1192 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1193 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1194
1198 const size_t bytes = source.length() << 1;
1199 return wrap_width ? bytes + bytes / wrap_width : bytes;
1200 }
1201
1204 char *write_bytes(char *dest, size_t dest_size) const;
1205
1208 ::std::ostream &output(::std::ostream &out) const;
1209
1212 bool is_empty() const noexcept { return source.empty(); }
1213
1216 bool is_erroneous() const noexcept { return false; }
1217};
1218
1223 const unsigned wrap_width = 0;
1228
1231 template <class ALLOCATOR = default_allocator>
1232 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1233
1236 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1237 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1238
1242 const size_t bytes = (source.length() * 11 + 7) / 8;
1243 return wrap_width ? bytes + bytes / wrap_width : bytes;
1244 }
1245
1248 char *write_bytes(char *dest, size_t dest_size) const;
1249
1252 ::std::ostream &output(::std::ostream &out) const;
1253
1255 bool is_empty() const noexcept { return source.empty(); }
1256
1258 bool is_erroneous() const noexcept { return false; }
1259};
1260
1265 const unsigned wrap_width = 0;
1270
1273 template <class ALLOCATOR = default_allocator>
1274 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1275
1278 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1279 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1280
1284 const size_t bytes = (source.length() + 2) / 3 * 4;
1285 return wrap_width ? bytes + bytes / wrap_width : bytes;
1286 }
1287
1291 char *write_bytes(char *dest, size_t dest_size) const;
1292
1296 ::std::ostream &output(::std::ostream &out) const;
1297
1300 bool is_empty() const noexcept { return source.empty(); }
1301
1304 bool is_erroneous() const noexcept { return false; }
1305};
1306
1310 const bool ignore_spaces = false;
1315
1317 template <class ALLOCATOR = default_allocator>
1318 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1319
1321 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1322 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1323
1326 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1327
1330 char *write_bytes(char *dest, size_t dest_size) const;
1331
1333 bool is_empty() const noexcept { return source.empty(); }
1334
1337 bool is_erroneous() const noexcept;
1338};
1339
1344 const bool ignore_spaces = false;
1349
1352 template <class ALLOCATOR = default_allocator>
1353 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1354
1357 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1358 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1359
1363 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1364 }
1365
1369 char *write_bytes(char *dest, size_t dest_size) const;
1370
1372 bool is_empty() const noexcept { return source.empty(); }
1373
1376 bool is_erroneous() const noexcept;
1377};
1378
1383 const bool ignore_spaces = false;
1388
1391 template <class ALLOCATOR = default_allocator>
1392 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1393
1396 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1397 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1398
1401 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1402
1406 char *write_bytes(char *dest, size_t dest_size) const;
1407
1410 bool is_empty() const noexcept { return source.empty(); }
1411
1415 bool is_erroneous() const noexcept;
1416};
1417
1419
1420template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1421#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1422 return ::std::allocator_traits<A>::is_always_equal::value;
1423#else
1424 return ::std::is_empty<A>::value;
1425#endif /* __cpp_lib_allocator_traits_is_always_equal */
1426}
1427
1428template <typename T, typename A = typename T::allocator_type,
1429 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1431
1432template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1433 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1434 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1435 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1436 }
1437 static MDBX_CXX20_CONSTEXPR void propagate(T *, T &) noexcept {}
1438};
1439
1440template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1441 static constexpr bool is_nothrow() noexcept {
1442 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1443 }
1444 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1445 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1446 target->get_allocator() = ::std::move(source.get_allocator());
1447 }
1448};
1449
1450template <typename T, typename A = typename T::allocator_type,
1451 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1453
1454template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1455 static constexpr bool is_nothrow() noexcept { return false; }
1456 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1457};
1458
1459template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1460 static constexpr bool is_nothrow() noexcept {
1461 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1462 }
1463 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1464 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1465 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1466 MDBX_CXX20_UNLIKELY target->get_allocator() =
1467 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1468 } else {
1469 /* gag for buggy compilers */
1470 (void)target;
1471 (void)source;
1472 }
1473 }
1474};
1475
1476template <typename T, typename A = typename T::allocator_type,
1477 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1479
1480template <typename T, typename A> struct swap_alloc<T, A, false> {
1481 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1482 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1484 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1485 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1486 } else {
1487 /* gag for buggy compilers */
1488 (void)left;
1489 (void)right;
1490 }
1491 }
1492};
1493
1494template <typename T, typename A> struct swap_alloc<T, A, true> {
1495 static constexpr bool is_nothrow() noexcept {
1496 return allocator_is_always_equal<A>() ||
1497#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1498 ::std::is_nothrow_swappable<A>() ||
1499#endif /* __cpp_lib_is_swappable >= 201603L */
1500 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1501 }
1502 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1503 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1504 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1505 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1506 } else {
1507 /* gag for buggy compilers */
1508 (void)left;
1509 (void)right;
1510 }
1511 }
1512};
1513
1514} // namespace allocation_aware_details
1515
1517 enum : size_t {
1522 };
1523
1524 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1525 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1526 static_assert(pettiness_threshold % 2 == 0, "pettiness_threshold must be even");
1527 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1528 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1529 return (value + pettiness_threshold - 1) & pettiness_mask;
1530 }
1531
1532 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1533 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1534 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1535
1536 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1537 return inplace;
1538
1539 if (wanna > current)
1540 /* doubling capacity, but don't made reserve more than max_reserve */
1541 return round(wanna + ::std::min(size_t(max_reserve), current));
1542
1543 if (current - wanna >
1544 /* shrink if reserve will more than half of current or max_reserve,
1545 * but not less than pettiness_threshold */
1546 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1547 return round(wanna);
1548
1549 /* keep unchanged */
1550 return current;
1551 }
1552};
1553
1555struct buffer_tag {};
1556
1558template <class ALLOCATOR, typename CAPACITY_POLICY>
1560public:
1562#if !defined(_MSC_VER) || _MSC_VER > 1900
1563 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1564#else
1565 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1566#endif /* MSVC is mad */
1567 using allocator_traits = ::std::allocator_traits<allocator_type>;
1568 using reservation_policy = CAPACITY_POLICY;
1569 enum : size_t {
1571 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1574 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1575 ? alignof(max_align_t) * 2
1578 };
1579
1580private:
1581 friend class txn;
1582 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1583 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1584 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1585
1586 using allocator_pointer = typename allocator_traits::pointer;
1587 using allocator_const_pointer = typename allocator_traits::const_pointer;
1588
1589 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1590 assert(bytes >= sizeof(bin));
1591 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1592 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1593 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1594 const size_t n = (bytes + unit - 1) / unit;
1595 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1596 }
1597
1598 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1599 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1600 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1601 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1602 }
1603
1604 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1605 const size_t capacity = bin::advise_capacity(0, bytes);
1606 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1607 : allocate_storage(capacity);
1608 }
1609
1610 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1611#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1612 return static_cast<void *>(::std::to_address(ptr));
1613#else
1614 return static_cast<void *>(::std::addressof(*ptr));
1615#endif /* __cpp_lib_to_address */
1616 }
1617
1618 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1619#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1620 return static_cast<const void *>(::std::to_address(ptr));
1621#else
1622 return static_cast<const void *>(::std::addressof(*ptr));
1623#endif /* __cpp_lib_to_address */
1624 }
1625
1626#ifdef _MSC_VER
1627#pragma warning(push)
1628#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1629#endif /* _MSC_VER */
1630
1631 union alignas(max_align_t) bin {
1632 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1633 с учетом выравнивания */
1634 {
1635 allocator_pointer stub_ptr_;
1637 };
1638
1640 enum : size_t {
1642 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1646 };
1647
1649 byte pad_[inplace_size - sizeof(allocator_pointer)];
1650 size_t bytes_;
1651 };
1652
1654 byte buffer_[inplace_size - sizeof(byte)];
1656 MDBX_CXX11_CONSTEXPR inplace_flag_holder(byte signature) : lastbyte_(signature) {};
1657 };
1658
1659 allocator_pointer allocated_ptr_;
1662
1663 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1664 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1665 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1666 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1667 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1668 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1669 return capacity_bytes <= inplace_capacity();
1670 }
1671
1672 constexpr bool is_inplace() const noexcept {
1673 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1674 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1676 "WTF?");
1677 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1678 }
1679 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1680
1681 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1682 if (destroy_ptr) {
1684 /* properly destroy allocator::pointer */
1685 allocated_ptr_.~allocator_pointer();
1686 }
1689 return address();
1690 }
1691
1692 template <bool construct_ptr>
1693 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1695 if (construct_ptr) {
1697 new (&allocated_ptr_) allocator_pointer(pair.first);
1698 } else {
1700 allocated_ptr_ = pair.first;
1701 }
1702 capacity_.bytes_ = pair.second;
1703 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1704 return address();
1705 }
1706
1708 if (::std::is_trivial<allocator_pointer>::value)
1709 /* workaround for "uninitialized" warning from some compilers */
1710 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1711 }
1712
1713 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1714 if (MDBX_UNLIKELY(wanna > max_capacity))
1715 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1716
1717 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1718 assert(advised >= wanna);
1719 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1720 }
1721
1722 constexpr bool is_inplace(const void *ptr) const noexcept {
1723 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1724 }
1725
1726 constexpr const byte *address() const noexcept {
1727 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1728 }
1730 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1731 }
1732 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1733 } bin_;
1734
1735#ifdef _MSC_VER
1736#pragma warning(pop)
1737#endif /* _MSC_VER */
1738
1739 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1740
1741 MDBX_CXX20_CONSTEXPR void release() noexcept {
1742 if (bin_.is_allocated()) {
1743 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1744 /* properly destroy allocator::pointer */
1745 bin_.allocated_ptr_.~allocator_pointer();
1746 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1747 }
1748 }
1749
1750 template <bool external_content>
1751 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1752 const void *const content, const size_t length) {
1753 assert(wanna_capacity >= wanna_headroom + length);
1754 const size_t old_capacity = bin_.capacity();
1755 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1756 if (MDBX_LIKELY(new_capacity == old_capacity))
1758 assert(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1759 byte *const new_place = bin_.address() + wanna_headroom;
1760 if (MDBX_LIKELY(length))
1762 if (external_content)
1763 memcpy(new_place, content, length);
1764 else {
1765 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1766 assert(old_capacity >= old_headroom + length);
1767 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1768 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1769 }
1770 }
1771 return new_place;
1772 }
1773
1774 if (bin::is_suitable_for_inplace(new_capacity)) {
1775 assert(bin_.is_allocated());
1776 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1777 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1778 if (MDBX_LIKELY(length))
1779 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1780 deallocate_storage(old_allocated, old_capacity);
1781 return new_place;
1782 }
1783
1784 if (bin_.is_inplace()) {
1785 const auto pair = allocate_storage(new_capacity);
1786 assert(pair.second >= new_capacity);
1787 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1788 if (MDBX_LIKELY(length))
1789 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1790 bin_.template make_allocated<true>(pair);
1791 return new_place;
1792 }
1793
1794 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1795 if (external_content)
1796 deallocate_storage(old_allocated, old_capacity);
1797 const auto pair = allocate_storage(new_capacity);
1798 assert(pair.second >= new_capacity);
1799 byte *const new_place = bin_.template make_allocated<false>(pair) + wanna_headroom;
1800 if (MDBX_LIKELY(length))
1801 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1802 if (!external_content)
1803 deallocate_storage(old_allocated, old_capacity);
1804 return new_place;
1805 }
1806
1807 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1808 assert(capacity() >= offset);
1809 return bin_.address() + offset;
1810 }
1811 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1812 assert(capacity() >= offset);
1813 return bin_.address() + offset;
1814 }
1815 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1816 assert(capacity() >= offset + length);
1817 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1818 }
1819
1820 //--------------------------------------------------------------------------
1821
1822 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1823 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1824 if (!bin::is_suitable_for_inplace(capacity))
1825 bin_.template make_allocated<true>(provide_storage(capacity));
1826 }
1827
1828 silo(silo &&other) = delete;
1830 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1831 : allocator_type(::std::move(other.get_allocator())) {
1832 if (!is_reference) {
1833 if (other.bin_.is_inplace()) {
1834 memcpy(&bin_, &other.bin_, sizeof(bin));
1835 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1836 } else {
1837 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1838 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1839 /* properly destroy allocator::pointer.
1840 *
1841 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1842 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1843 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1844 * from the 11th). */
1845 /* coverity[use_after_move] */
1846 other.bin_.allocated_ptr_.~allocator_pointer();
1847 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1848 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1849 }
1850 }
1851 }
1852
1853 MDBX_CXX17_CONSTEXPR bool move(silo &&other) noexcept {
1854 if (other.bin_.is_inplace()) {
1855 memcpy(&bin_, &other.bin_, sizeof(bin));
1856 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1857 return /* buffer's slice fixup is needed */ true;
1858 }
1859 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1860 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1861 /* properly destroy allocator::pointer.
1862 *
1863 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1864 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1865 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1866 * from the 11th). */
1867 /* coverity[use_after_move] */
1868 other.bin_.allocated_ptr_.~allocator_pointer();
1869 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1870 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1871 return false;
1872 }
1873
1874 MDBX_CXX17_CONSTEXPR bool assign_move(silo &&other, bool is_reference) noexcept {
1875 release();
1876 if (!allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, other))
1877 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, other);
1878 return is_reference ? false : move(std::move(other));
1879 }
1880
1881 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1882 exchange(silo &left, const bool left_is_reference, silo &right, const bool right_is_reference) noexcept(
1883 allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1884 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(left, right);
1885 bool left_need_fixup = false, right_need_fixup = false;
1886 if (left_is_reference || right_is_reference) {
1887 left_need_fixup = !right_is_reference && left.move(std::move(right));
1888 right_need_fixup = !left_is_reference && right.move(std::move(left));
1889 } else {
1890 silo temp(std::move(left), false);
1891 left_need_fixup = left.move(std::move(right));
1892 right_need_fixup = right.move(std::move(temp));
1893 }
1894 return std::make_pair(left_need_fixup, right_need_fixup);
1895 }
1896
1897 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1898 const allocator_type &alloc = allocator_type())
1899 : silo(capacity, alloc) {
1900 assert(capacity >= headroom + length);
1901 if (length)
1902 put(headroom, ptr, length);
1903 }
1904
1905 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1906 : silo(length, 0, ptr, length, alloc) {}
1907
1908 ~silo() { release(); }
1909
1910 //--------------------------------------------------------------------------
1911
1912 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1913 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1914 }
1915
1916 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1917
1918 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1919 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1920 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1921 }
1922
1923 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1924 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1925 }
1926
1927 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1928 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1929 return get(offset);
1930 }
1931 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1932 };
1933
1934 MDBX_CXX14_CONSTEXPR void fixup_import(const typename silo::bin &src) noexcept {
1935 auto ptr = inherited::byte_ptr();
1936 if (src.is_inplace(ptr)) {
1937 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1938 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1939 iov_base = ptr + offset;
1940 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1941 }
1942 }
1943
1944 silo silo_;
1945
1946 void insulate() {
1947 assert(is_reference());
1948 iov_base = silo_.assign(iov_base, iov_len);
1949 }
1950
1951 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1952 return static_cast<const byte *>(silo_.data());
1953 }
1954
1955 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1956 return silo_begin() + silo_.capacity();
1957 }
1958
1959 struct data_preserver : public exception_thunk {
1960 buffer data;
1961 data_preserver(allocator_type &alloc) : data(alloc) {}
1962 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1963 auto self = static_cast<data_preserver *>(context);
1964 assert(self->is_clean());
1965 assert(&self->data == target);
1966 (void)target;
1967 try {
1968 self->data.assign(src, bytes, false);
1969 return MDBX_RESULT_FALSE;
1970 } catch (... /* capture any exception to rethrow it over C code */) {
1971 self->capture();
1972 return MDBX_RESULT_TRUE;
1973 }
1974 }
1975 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1976 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1977 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1978 };
1979
1980public:
1983
1987
1988 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1989
1991 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1992
1996 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1997 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1998 }
1999
2004 return silo_.is_inplace(inherited::data());
2005 }
2006
2010
2013 return is_freestanding() ? silo_.capacity() : 0;
2014 }
2015
2019 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
2020 }
2021
2025 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2026 }
2027
2029 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2030
2032 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2033
2040
2045 return const_cast<byte *>(inherited::end_byte_ptr());
2046 }
2047
2049 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2050
2052 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2053
2058 return const_cast<char *>(inherited::char_ptr());
2059 }
2060
2065 return const_cast<char *>(inherited::end_char_ptr());
2066 }
2067
2069 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
2070
2072 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
2073
2076 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2078 return const_cast<void *>(inherited::data());
2079 }
2080
2083 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2085 return const_cast<void *>(inherited::end());
2086 }
2087
2092
2099
2102 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2103 return set_length(static_cast<const char *>(ptr) - char_ptr());
2104 }
2105
2110 if (is_reference())
2111 insulate();
2112 }
2113
2114 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2115 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2116 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2117 const allocator_type &alloc = allocator_type());
2118
2120 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2121 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2122
2123 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2124 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2125
2126 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2127 : buffer(inherited(c_str), make_reference, alloc) {}
2128
2129#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2130 template <class CHAR, class T>
2131 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2132 const allocator_type &alloc = allocator_type())
2133 : buffer(inherited(view), make_reference, alloc) {}
2134#endif /* __cpp_lib_string_view >= 201606L */
2135
2137 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2138 : buffer(src, src.empty() || src.is_null(), alloc) {}
2139
2141 buffer(const buffer &src)
2142 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2143
2145 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2146 : buffer(inherited(ptr, bytes), alloc) {}
2147
2148 template <class CHAR, class T, class A>
2149 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2150 const allocator_type &alloc = allocator_type())
2151 : buffer(inherited(str), alloc) {}
2152
2154 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2155
2156#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2157 template <class CHAR, class T>
2158 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2159 const allocator_type &alloc = allocator_type())
2160 : buffer(inherited(view), alloc) {}
2161#endif /* __cpp_lib_string_view >= 201606L */
2162
2163 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2164 : silo_(check_length(head_room, tail_room), alloc) {
2165 iov_base = silo_.get();
2166 assert(iov_len == 0);
2167 }
2168
2169 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2170 iov_base = silo_.get();
2171 assert(iov_len == 0);
2172 }
2173
2174 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2175 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2176 iov_base = memcpy(silo_.get(), src.data(), iov_len = src.length());
2177 }
2178
2179 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2180
2181 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2182 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2183 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2184 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2185 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2186 * 11th). */
2187 /* coverity[use_after_move] */
2188 fixup_import(src.silo_.bin_);
2189 src.invalidate();
2190 }
2191
2193 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2194
2197
2198 template <typename POD>
2199 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2200 return buffer(inherited::wrap(pod), make_reference, alloc);
2201 }
2202
2204 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2205 const allocator_type &alloc = allocator_type()) {
2206 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2207 }
2208
2211 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2212 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2213 }
2214
2216 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2217 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2218 }
2219
2221 template <typename POD>
2222 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2223 const allocator_type &alloc = allocator_type()) {
2224 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2225 }
2226
2229 template <typename POD>
2230 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2231 return base58(inherited::wrap(pod), wrap_width, alloc);
2232 }
2233
2236 template <typename POD>
2237 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2238 return base64(inherited::wrap(pod), wrap_width, alloc);
2239 }
2240
2242 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2243 const allocator_type &alloc = allocator_type()) const {
2244 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2245 }
2246
2249 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2250 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2251 }
2252
2254 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2255 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2256 }
2257
2259 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2260 const allocator_type &alloc = allocator_type()) {
2261 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2262 }
2263
2266 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2267 const allocator_type &alloc = allocator_type()) {
2268 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2269 }
2270
2273 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2274 const allocator_type &alloc = allocator_type()) {
2275 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2276 }
2277
2280 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2281 return hex_decode(*this, ignore_spaces, alloc);
2282 }
2283
2286 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2287 return base58_decode(*this, ignore_spaces, alloc);
2288 }
2289
2292 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2293 return base64_decode(*this, ignore_spaces, alloc);
2294 }
2295
2297 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2298 wanna_headroom = ::std::min(
2299 ::std::max(headroom(), wanna_headroom),
2300 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2301 wanna_tailroom = ::std::min(
2302 ::std::max(tailroom(), wanna_tailroom),
2303 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2304 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2305 silo_.resize(wanna_capacity, wanna_headroom, *this);
2306 assert(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2307 assert(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2308 }
2309
2311 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2312
2314 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2315
2316 buffer &assign_reference(const void *ptr, size_t bytes) {
2317 silo_.clear();
2319 return *this;
2320 }
2321
2322 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2323 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2324 return *this;
2325 }
2326
2327 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2328 const auto pair = silo::exchange(silo_, is_reference(), other.silo_, other.is_reference());
2329 std::swap(iov_base, other.iov_base);
2330 std::swap(iov_len, other.iov_len);
2331 if (pair.first)
2332 fixup_import(other.silo_.bin_);
2333 if (pair.second)
2334 other.fixup_import(silo_.bin_);
2335 }
2336
2337 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2338 left.swap(right);
2339 }
2340
2341 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2342 return buffer(src.headroom(), src, src.tailroom(), alloc);
2343 }
2344
2346 return buffer(slice(), !is_inplace(), allocator_traits::select_on_container_copy_construction(get_allocator()));
2347 }
2348
2350 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2351 invalidate();
2352 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2353 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2354 MDBX_CXX20_UNLIKELY {
2355 silo_.release();
2357 }
2358 }
2359
2360 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2361 iov_len = src.length();
2362 return *this;
2363 }
2364
2365 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2366 invalidate();
2367 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2368 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2369 MDBX_CXX20_UNLIKELY {
2370 silo_.release();
2372 }
2373 }
2374
2375 if (make_reference) {
2376 silo_.release();
2377 iov_base = src.iov_base;
2378 } else {
2379 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2380 }
2381 iov_len = src.length();
2382 return *this;
2383 }
2384
2387 const bool is_reference = src.is_reference();
2388 inherited::assign(std::move(src));
2389 if (silo_.assign_move(std::move(src.silo_), is_reference))
2390 fixup_import(src.silo_.bin_);
2391 return *this;
2392 }
2393
2394 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2395 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2396 }
2397
2398 buffer &assign(const struct slice &src, bool make_reference = false) {
2399 return assign(src.data(), src.length(), make_reference);
2400 }
2401
2402 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2403 return assign(src.iov_base, src.iov_len, make_reference);
2404 }
2405
2406 buffer &assign(struct slice &&src, bool make_reference = false) {
2407 assign(src.data(), src.length(), make_reference);
2408 src.invalidate();
2409 return *this;
2410 }
2411
2412 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2413 assign(src.iov_base, src.iov_len, make_reference);
2414 src.iov_base = nullptr;
2415 return *this;
2416 }
2417
2418 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2419 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2420 }
2421
2422 template <class CHAR, class T, class A>
2423 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2424 return assign(str.data(), str.length(), make_reference);
2425 }
2426
2427 buffer &assign(const char *c_str, bool make_reference = false) {
2428 return assign(c_str, strlen(c_str), make_reference);
2429 }
2430
2431#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2432 template <class CHAR, class T>
2433 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2434 return assign(view.data(), view.length(), make_reference);
2435 }
2436
2437 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2438 assign(view.data(), view.length(), make_reference);
2439 view = {};
2440 return *this;
2441 }
2442#endif /* __cpp_lib_string_view >= 201606L */
2443
2444 buffer &operator=(const buffer &src) { return assign(src); }
2445
2446 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2447
2448 buffer &operator=(const struct slice &src) { return assign(src); }
2449
2450 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2451
2452#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2453 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2454 return assign(view.begin(), view.length());
2455 }
2456#endif /* __cpp_lib_string_view >= 201606L */
2457
2458 template <class CHAR, class T, class A>
2459 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2460 return as_string<CHAR, T, A>();
2461 }
2462
2464 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2465
2467 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2468 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2469 }
2470
2472 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2473
2474 buffer &append(const void *src, size_t bytes) {
2475 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2476 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2477 memcpy(end_byte_ptr(), src, bytes);
2478 iov_len += bytes;
2479 return *this;
2480 }
2481
2482 buffer &append(const byte c) {
2483 if (MDBX_UNLIKELY(tailroom() < 1))
2484 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2485 *end_byte_ptr() = c;
2486 iov_len += 1;
2487 return *this;
2488 }
2489
2490 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2491
2492 buffer &add_header(const void *src, size_t bytes) {
2493 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2494 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2495 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2496 iov_len += bytes;
2497 return *this;
2498 }
2499
2500 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2501
2502 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2503 const size_t wanna_bytes = producer.envisage_result_length();
2504 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2505 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2506 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2507 }
2508
2509 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2510 const size_t wanna_bytes = producer.envisage_result_length();
2511 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2512 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2513 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2514 }
2515
2516 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2517 return append_producer(to_hex(data, uppercase, wrap_width));
2518 }
2519
2520 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2521 return append_producer(to_base58(data, wrap_width));
2522 }
2523
2524 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2525 return append_producer(to_base64(data, wrap_width));
2526 }
2527
2528 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2529 return append_producer(from_hex(data, ignore_spaces));
2530 }
2531
2532 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2533 return append_producer(from_base58(data, ignore_spaces));
2534 }
2535
2536 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2537 return append_producer(from_base64(data, ignore_spaces));
2538 }
2539
2540 buffer &append_u8(uint_fast8_t u8) {
2541 if (MDBX_UNLIKELY(tailroom() < 1))
2542 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2543 *end_byte_ptr() = uint8_t(u8);
2544 iov_len += 1;
2545 return *this;
2546 }
2547
2548 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2549
2550 buffer &append_u16(uint_fast16_t u16) {
2551 if (MDBX_UNLIKELY(tailroom() < 2))
2552 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2553 const auto ptr = end_byte_ptr();
2554 ptr[0] = uint8_t(u16);
2555 ptr[1] = uint8_t(u16 >> 8);
2556 iov_len += 2;
2557 return *this;
2558 }
2559
2560 buffer &append_u24(uint_fast32_t u24) {
2561 if (MDBX_UNLIKELY(tailroom() < 3))
2562 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2563 const auto ptr = end_byte_ptr();
2564 ptr[0] = uint8_t(u24);
2565 ptr[1] = uint8_t(u24 >> 8);
2566 ptr[2] = uint8_t(u24 >> 16);
2567 iov_len += 3;
2568 return *this;
2569 }
2570
2571 buffer &append_u32(uint_fast32_t u32) {
2572 if (MDBX_UNLIKELY(tailroom() < 4))
2573 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2574 const auto ptr = end_byte_ptr();
2575 ptr[0] = uint8_t(u32);
2576 ptr[1] = uint8_t(u32 >> 8);
2577 ptr[2] = uint8_t(u32 >> 16);
2578 ptr[3] = uint8_t(u32 >> 24);
2579 iov_len += 4;
2580 return *this;
2581 }
2582
2583 buffer &append_u48(uint_fast64_t u48) {
2584 if (MDBX_UNLIKELY(tailroom() < 6))
2585 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2586 const auto ptr = end_byte_ptr();
2587 ptr[0] = uint8_t(u48);
2588 ptr[1] = uint8_t(u48 >> 8);
2589 ptr[2] = uint8_t(u48 >> 16);
2590 ptr[3] = uint8_t(u48 >> 24);
2591 ptr[4] = uint8_t(u48 >> 32);
2592 ptr[5] = uint8_t(u48 >> 40);
2593 iov_len += 6;
2594 return *this;
2595 }
2596
2597 buffer &append_u64(uint_fast64_t u64) {
2598 if (MDBX_UNLIKELY(tailroom() < 8))
2599 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2600 const auto ptr = end_byte_ptr();
2601 ptr[0] = uint8_t(u64);
2602 ptr[1] = uint8_t(u64 >> 8);
2603 ptr[2] = uint8_t(u64 >> 16);
2604 ptr[3] = uint8_t(u64 >> 24);
2605 ptr[4] = uint8_t(u64 >> 32);
2606 ptr[5] = uint8_t(u64 >> 40);
2607 ptr[6] = uint8_t(u64 >> 48);
2608 ptr[7] = uint8_t(u64 >> 56);
2609 iov_len += 8;
2610 return *this;
2611 }
2612
2613 //----------------------------------------------------------------------------
2614
2615 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2616 return buffer(inherited(text), make_reference);
2617 }
2618
2619#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2620 template <class CHAR, class T>
2621 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2622 return buffer(src, make_reference);
2623 }
2624#endif /* __cpp_lib_string_view >= 201606L */
2625
2626 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2627
2628 template <class CHAR, class T, class A>
2629 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2630 return buffer(src, make_reference);
2631 }
2632
2633 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2634
2635 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2636
2637 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2638
2639 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2640
2641 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2642
2643 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2644
2645 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2646
2647 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2648
2649 static buffer key_from_jsonInteger(const int64_t json_integer) {
2650 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2651 }
2652
2653 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2654
2655 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2656
2657 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2658
2659 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2660
2661 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2662
2663 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2664
2665 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2666
2667 const slice &slice() const noexcept { return *this; }
2668};
2669
2670template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2674 using reservation_policy = CAPACITY_POLICY;
2675 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2677
2680 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2681
2683 : key(key, alloc), value(value, alloc) {}
2684 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2685 const allocator_type &alloc = allocator_type())
2686 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2687
2689 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2690 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2691 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2692
2694 : key(key, alloc), value(value, alloc) {}
2695 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2696 const allocator_type &alloc = allocator_type())
2697 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2698
2701 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2702 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2703
2704 buffer_pair_spec(const txn &transacton, const slice &key, const slice &value,
2705 const allocator_type &alloc = allocator_type())
2706 : key(transacton, key, alloc), value(transacton, value, alloc) {}
2707 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2708 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2709
2710 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2711 : key(::std::move(key)), value(::std::move(value)) {}
2713 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2714 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2715
2718 key.assign(std::move(src.key));
2719 value.assign(std::move(src.value));
2720 return *this;
2721 }
2722
2724 key.assign(src.key);
2725 value.assign(src.value);
2726 return *this;
2727 }
2729 key.assign(std::move(src.key));
2730 value.assign(std::move(src.value));
2731 return *this;
2732 }
2734 key.assign(src.first);
2735 value.assign(src.second);
2736 return *this;
2737 }
2739 key.assign(std::move(src.first));
2740 value.assign(std::move(src.second));
2741 return *this;
2742 }
2743
2747 return key.is_freestanding() && value.is_freestanding();
2748 }
2749
2752 return key.is_reference() || value.is_reference();
2753 }
2754
2758 key.make_freestanding();
2759 value.make_freestanding();
2760 }
2761
2762 operator pair() const noexcept { return pair(key, value); }
2763};
2764
2766
2769public:
2770 cache_entry() noexcept { reset(); }
2771 cache_entry(const cache_entry &) noexcept = default;
2772 cache_entry &operator=(const cache_entry &) noexcept = default;
2773 cache_entry(cache_entry &&other) noexcept {
2774 *this = other;
2775 other.reset();
2776 }
2777 void reset() noexcept { mdbx_cache_init(this); }
2778};
2779
2780//------------------------------------------------------------------------------
2781
2784enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2785
2802
2804 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2805}
2806
2808 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2809}
2810
2812 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2813}
2814
2816 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2817}
2818
2820
2878
2882
2884 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2885}
2886
2888 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2889}
2890
2892 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2893}
2894
2896 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2897}
2898
2900
2911 map_handle(const map_handle &) noexcept = default;
2912 map_handle &operator=(const map_handle &) noexcept = default;
2913 operator bool() const noexcept { return dbi != 0; }
2914 operator MDBX_dbi() const { return dbi; }
2915
2916#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2917 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2918 return a.dbi <=> b.dbi;
2919 }
2920#endif /* __cpp_impl_three_way_comparison */
2921 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2922 return a.dbi == b.dbi;
2923 }
2924 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2925 return a.dbi < b.dbi;
2926 }
2927 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2928 return a.dbi > b.dbi;
2929 }
2930 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2931 return a.dbi <= b.dbi;
2932 }
2933 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2934 return a.dbi >= b.dbi;
2935 }
2936 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2937 return a.dbi != b.dbi;
2938 }
2939
2951};
2952
2955 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2956}
2958 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2959}
2960
2967
2976 friend class txn;
2977
2978protected:
2980 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2981
2982public:
2983 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2984 env(const env &) noexcept = default;
2985 env &operator=(const env &) noexcept = default;
2986 inline env &operator=(env &&) noexcept;
2987 inline env(env &&) noexcept;
2988 inline ~env() noexcept;
2989
2990 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
2991 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
2992 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
2993 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
2994 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
2995
2996 //----------------------------------------------------------------------------
2997
3002
3004 enum : intptr_t {
3007 maximal_value = INTPTR_MAX,
3008 kB = 1000,
3009 MB = kB * 1000,
3010 GB = MB * 1000,
3011#if INTPTR_MAX > 0x7fffFFFFl
3012 TB = GB * 1000,
3013 PB = TB * 1000,
3014 EB = PB * 1000,
3015#endif /* 64-bit intptr_t */
3016 KiB = 1024,
3017 MiB = KiB << 10,
3018 GiB = MiB << 10,
3019#if INTPTR_MAX > 0x7fffFFFFl
3020 TiB = GiB << 10,
3021 PiB = TiB << 10,
3022 EiB = PiB << 10,
3023#endif /* 64-bit intptr_t */
3024 };
3025
3027 struct size {
3028 intptr_t bytes;
3029 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3030 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3031 };
3032
3035
3040
3052
3055
3058
3064
3065 inline geometry &make_fixed(intptr_t size) noexcept;
3066 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3069 geometry(const geometry &) noexcept = default;
3075 };
3076
3084
3092
3105
3127
3132 unsigned max_maps{0};
3135 unsigned max_readers{0};
3140
3151 operate_parameters(const operate_parameters &) noexcept = default;
3153 MDBX_env_flags_t make_flags(bool accede = true,
3156 bool use_subdirectory = false
3157 ) const;
3161 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3162 };
3163
3167 inline env::mode get_mode() const;
3169 inline env::durability get_durability() const;
3173 inline env::operate_options get_options() const;
3174
3177 bool is_pristine() const;
3178
3180 bool is_empty() const;
3181
3183 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3184
3185 struct limits {
3186 limits() = delete;
3188 static inline size_t pagesize_min() noexcept;
3190 static inline size_t pagesize_max() noexcept;
3192 static inline size_t dbsize_min(intptr_t pagesize);
3194 static inline size_t dbsize_max(intptr_t pagesize);
3196 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3198 static inline size_t key_min(key_mode mode) noexcept;
3200 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3202 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3204 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3206 static inline size_t key_max(const env &, key_mode mode);
3208 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3210 static inline size_t value_min(value_mode) noexcept;
3211
3213 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3215 static inline size_t value_max(intptr_t pagesize, value_mode);
3217 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3219 static inline size_t value_max(const env &, value_mode);
3220
3223 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3226 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3229 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3232 static inline size_t pairsize4page_max(const env &, value_mode);
3233
3236 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3239 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3242 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3245 static inline size_t valsize4page_max(const env &, value_mode);
3246
3249 static inline size_t transaction_size_max(intptr_t pagesize);
3250
3252 static inline size_t max_map_handles(void);
3253 };
3254
3256 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3258 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3260 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3262 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3264 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3266 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3270
3273#ifdef MDBX_STD_FILESYSTEM_PATH
3274 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3275#endif /* MDBX_STD_FILESYSTEM_PATH */
3276#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3277 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3278 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3279#endif /* Windows */
3280 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3281 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3282
3284 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3285
3301
3303#ifdef MDBX_STD_FILESYSTEM_PATH
3304 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3305#endif /* MDBX_STD_FILESYSTEM_PATH */
3306#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3307 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3308 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3309#endif /* Windows */
3310 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3311 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3312
3315
3318
3320 inline stat get_stat() const;
3321
3323 size_t get_pagesize() const { return get_stat().ms_psize; }
3324
3326 inline info get_info() const;
3327
3329 inline stat get_stat(const txn &) const;
3330
3332 inline info get_info(const txn &) const;
3333
3335 inline filehandle get_filehandle() const;
3336
3338 const path_char* get_path() const;
3339
3341 inline MDBX_env_flags_t get_flags() const;
3342
3343 inline bool is_readonly() const { return (get_flags() & MDBX_RDONLY) != 0; }
3344
3345 inline bool is_exclusive() const { return (get_flags() & MDBX_EXCLUSIVE) != 0; }
3346
3347 inline bool is_cooperative() const { return !is_exclusive(); }
3348
3349 inline bool is_writemap() const { return (get_flags() & MDBX_WRITEMAP) != 0; }
3350
3351 inline bool is_readwite() const { return !is_readonly(); }
3352
3353 inline bool is_nested_transactions_available() const { return (get_flags() & (MDBX_WRITEMAP | MDBX_RDONLY)) == 0; }
3354
3357 inline unsigned max_readers() const;
3358
3361 inline unsigned max_maps() const;
3362
3364 inline void *get_context() const noexcept;
3365
3367 inline env &set_context(void *your_context);
3368
3383 inline env &set_sync_threshold(size_t bytes);
3384
3390 inline size_t sync_threshold() const;
3391
3392#if __cplusplus >= 201103L || defined(DOXYGEN)
3412 inline env &set_sync_period(const duration &period);
3413
3419 inline duration sync_period() const;
3420#endif
3421
3425 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3426
3429 inline unsigned sync_period__seconds_16dot16() const;
3430
3434 inline env &set_sync_period__seconds_double(double seconds);
3435
3438 inline double sync_period__seconds_double() const;
3439
3477
3479 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3480
3482 inline uint64_t extra_option(extra_runtime_option option) const;
3483
3485 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3486
3488 inline env &set_geometry(const geometry &size);
3489
3493 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3494
3498 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3499
3518 inline void close_map(const map_handle &);
3519
3522 int slot;
3531 size_t bytes_used;
3540
3542 size_t used, size_t retained) noexcept;
3543 };
3544
3552 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3553
3556 inline unsigned check_readers();
3557
3576
3581 inline MDBX_hsr_func get_HandleSlowReaders() const noexcept;
3582
3584 inline txn_managed start_read() const;
3585
3587 inline txn_managed prepare_read() const;
3588
3590 inline txn_managed start_write(txn &parent);
3591
3593 inline txn_managed start_write(bool dont_wait = false);
3594
3597};
3598
3607class LIBMDBX_API_TYPE env_managed : public env {
3608 using inherited = env;
3610 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3611 void setup(unsigned max_maps, unsigned max_readers = 0);
3612
3613public:
3614 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3615
3617#ifdef MDBX_STD_FILESYSTEM_PATH
3618 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3619#endif /* MDBX_STD_FILESYSTEM_PATH */
3620#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3621 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3622 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3623#endif /* Windows */
3624 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3625 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3626
3637
3639#ifdef MDBX_STD_FILESYSTEM_PATH
3641 bool accede = true);
3642#endif /* MDBX_STD_FILESYSTEM_PATH */
3643#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3644 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3645 bool accede = true);
3646 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3647 bool accede = true);
3648#endif /* Windows */
3649 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3650 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3651
3665 void close(bool dont_sync = false);
3666
3667 env_managed(env_managed &&) = default;
3668 env_managed &operator=(env_managed &&other) noexcept {
3670 MDBX_CXX20_UNLIKELY {
3671 assert(handle_ != other.handle_);
3672 close();
3673 }
3674 inherited::operator=(std::move(other));
3675 return *this;
3676 }
3677 env_managed(const env_managed &) = delete;
3678 env_managed &operator=(const env_managed &) = delete;
3679 virtual ~env_managed() noexcept;
3680};
3681
3690protected:
3691 friend class cursor;
3693 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3694
3695public:
3696 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3697 txn(const txn &) noexcept = default;
3698 txn &operator=(const txn &) noexcept = default;
3699 inline txn &operator=(txn &&) noexcept;
3700 inline txn(txn &&) noexcept;
3701 inline ~txn() noexcept;
3702
3703 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3704 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3705 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3706 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3707 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3708
3710 inline ::mdbx::env env() const noexcept;
3712 inline MDBX_txn_flags_t flags() const;
3714 inline uint64_t id() const;
3715
3717 inline void *get_context() const noexcept;
3718
3720 inline txn &set_context(void *your_context);
3721
3723 inline bool is_dirty(const void *ptr) const;
3724
3726 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3727
3729 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3730
3732 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3733
3736 inline info get_info(bool scan_reader_lock_table = false) const;
3737
3740 size_t size_max() const { return env().transaction_size_max(); }
3741
3743 size_t size_current() const {
3744 assert(is_readwrite());
3745 return size_t(get_info().txn_space_dirty);
3746 }
3747
3748 //----------------------------------------------------------------------------
3749
3751 inline void reset_reading();
3752
3754 inline void renew_reading();
3755
3757 inline txn_managed clone(void *context = nullptr) const;
3758
3760 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
3761
3763 inline void make_broken();
3764
3766 inline void park_reading(bool autounpark = true);
3767
3770 inline bool unpark_reading(bool restart_if_ousted = true);
3771
3774
3777
3779 inline cursor_managed open_cursor(map_handle map) const;
3780
3782 inline size_t release_all_cursors(bool unbind) const;
3783
3785 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3786
3788 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3789
3791 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3792 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3794 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3795 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3797 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3798 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3799
3801 inline map_handle open_map_accede(const char *name) const;
3803 inline map_handle open_map_accede(const ::std::string &name) const;
3805 inline map_handle open_map_accede(const slice &name) const;
3806
3808 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3809 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3811 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3812 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3814 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3815 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3816
3818 inline void drop_map(map_handle map);
3822 bool drop_map(const char *name, bool throw_if_absent = false);
3826 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3830 bool drop_map(const slice &name, bool throw_if_absent = false);
3831
3833 inline void clear_map(map_handle map);
3836 bool clear_map(const char *name, bool throw_if_absent = false);
3839 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3842 bool clear_map(const slice &name, bool throw_if_absent = false);
3843
3845 inline void rename_map(map_handle map, const char *new_name);
3847 inline void rename_map(map_handle map, const ::std::string &new_name);
3849 inline void rename_map(map_handle map, const slice &new_name);
3853 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3857 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3861 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3862
3863#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3864
3866 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3867 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3868 return open_map(slice(name), key_mode, value_mode);
3869 }
3870
3871 inline map_handle open_map_accede(const ::std::string_view &name) const;
3873 inline map_handle create_map(const ::std::string_view &name,
3874 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3875 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3876 return create_map(slice(name), key_mode, value_mode);
3877 }
3878
3881 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3882 return drop_map(slice(name), throw_if_absent);
3883 }
3884
3886 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3887 return clear_map(slice(name), throw_if_absent);
3888 }
3889
3890 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3894 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3895 bool throw_if_absent = false) {
3896 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3897 }
3898#endif /* __cpp_lib_string_view >= 201606L */
3899
3902 inline map_stat get_map_stat(map_handle map) const;
3905 inline uint32_t get_tree_deepmask(map_handle map) const;
3907 inline map_handle::info get_map_flags(map_handle map) const;
3908
3911 inline txn &put_canary(const canary &);
3913 inline canary get_canary() const;
3914
3916 inline uint64_t sequence(map_handle map) const;
3918 inline uint64_t sequence(map_handle map, uint64_t increment);
3919
3921 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3923 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3925 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3927 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3928
3930 inline slice get(map_handle map, const slice &key) const;
3932 inline slice get(map_handle map, slice key, size_t &values_count) const;
3934 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3936 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3940 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3944 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3945
3946 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3947 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3948 inline void insert(map_handle map, const slice &key, slice value);
3949 inline value_result try_insert(map_handle map, const slice &key, slice value);
3950 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3951 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3952
3953 inline void upsert(map_handle map, const slice &key, const slice &value);
3954 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3955
3956 inline void update(map_handle map, const slice &key, const slice &value);
3957 inline bool try_update(map_handle map, const slice &key, const slice &value);
3958 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3959 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3960
3961 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3962 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3963 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3964 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3965
3967 inline bool erase(map_handle map, const slice &key);
3968
3970 inline bool erase(map_handle map, const slice &key, const slice &value);
3971
3973 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3974
3976 template <class ALLOCATOR, typename CAPACITY_POLICY>
3978 extract(map_handle map, const slice &key,
3981
3983 template <class ALLOCATOR, typename CAPACITY_POLICY>
3985 replace(map_handle map, const slice &key, const slice &new_value,
3988
3989 template <class ALLOCATOR, typename CAPACITY_POLICY>
3991 replace_reserve(map_handle map, const slice &key, slice &new_value,
3994
4011 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4012 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4013 return append(map, kv.key, kv.value, multivalue_order_preserved);
4014 }
4015
4016 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4017 const void *values_array, size_t values_count, put_mode mode,
4018 bool allow_partial = false);
4019 template <typename VALUE>
4020 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4021 put_mode mode, bool allow_partial = false) {
4022 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4023 !::std::is_array<VALUE>::value,
4024 "Must be a standard layout type!");
4025 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4026 }
4027 template <typename VALUE>
4028 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4029 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4030 }
4031
4032 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4033 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4034 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4035 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4036};
4037
4046class LIBMDBX_API_TYPE txn_managed : public txn {
4047 using inherited = txn;
4048 friend class env;
4049 friend class txn;
4051 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4052
4053public:
4054 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4055 txn_managed(txn_managed &&) = default;
4056 txn_managed &operator=(txn_managed &&other) noexcept {
4058 MDBX_CXX20_UNLIKELY {
4059 assert(handle_ != other.handle_);
4060 abort();
4061 }
4062 inherited::operator=(std::move(other));
4063 return *this;
4064 }
4065 txn_managed(const txn_managed &) = delete;
4066 txn_managed &operator=(const txn_managed &) = delete;
4067 ~txn_managed() noexcept;
4068
4069 //----------------------------------------------------------------------------
4071
4073 void abort();
4077 void abort(finalization_latency &latency) { return abort(&latency); }
4081 finalization_latency result;
4082 abort(&result);
4083 return result;
4084 }
4085
4087 void commit();
4091 void commit(finalization_latency &latency) { return commit(&latency); }
4095 finalization_latency result;
4096 commit(&result);
4097 return result;
4098 }
4099
4105 bool checkpoint(finalization_latency &latency) { return checkpoint(&latency); }
4108 std::pair<bool, finalization_latency> checkpoint_get_latency() {
4109 finalization_latency latency;
4110 bool result = checkpoint(&latency);
4111 return std::make_pair(result, latency);
4112 }
4113
4123 finalization_latency result;
4124 commit_embark_read(&result);
4125 return result;
4126 }
4127
4130 bool amend(bool dont_wait = false);
4131};
4132
4140protected:
4142
4143public:
4145 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4146 cursor(const cursor &) noexcept = default;
4147 cursor &operator=(const cursor &) noexcept = default;
4148 inline cursor &operator=(cursor &&) noexcept;
4149 inline cursor(cursor &&) noexcept;
4150 inline ~cursor() noexcept;
4151 inline cursor_managed clone(void *your_context = nullptr) const;
4152 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4153 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4154 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4155 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4156 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4157
4158 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4159 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4160
4161 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4162 return compare_position(*this, other, ignore_nested) < 0;
4163 }
4164
4165 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4166 return compare_position(*this, other, ignore_nested) <= 0;
4167 }
4168
4169 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4170 return compare_position(*this, other, ignore_nested) == 0;
4171 }
4172
4173 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4174 return compare_position(*this, other, ignore_nested) > 0;
4175 }
4176
4177 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4178 return compare_position(*this, other, ignore_nested) >= 0;
4179 }
4180
4182 inline void *get_context() const noexcept;
4183
4185 inline cursor &set_context(void *your_context);
4186
4193
4200
4203
4207
4208 /* Doubtless cursor positioning at a specified key. */
4214
4215 /* Doubtless cursor positioning at a specified key-value pair
4216 * for dupsort/multi-value hives. */
4222
4229
4234 };
4235
4236 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4237 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4238 // и других параметров в bool-throw_notfound.
4239
4240 struct move_result : public pair_result {
4241 inline move_result(const cursor &cursor, bool throw_notfound);
4242 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4243 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4244 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4245 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4246 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4247 bool throw_notfound);
4248 move_result(const move_result &) noexcept = default;
4249 move_result &operator=(const move_result &) noexcept = default;
4250 };
4251
4252 struct estimate_result : public pair {
4257 : estimate_result(cursor, operation, key, slice::invalid()) {}
4258 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4259 estimate_result(const estimate_result &) noexcept = default;
4260 estimate_result &operator=(const estimate_result &) noexcept = default;
4261 };
4262
4263protected:
4264 /* fake `const`, but for specific move/get operations */
4265 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4266
4267 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4268
4269public:
4270 template <typename CALLABLE_PREDICATE>
4271 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4272 struct wrapper : public exception_thunk {
4273 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4274 auto thunk = static_cast<wrapper *>(context);
4275 assert(thunk->is_clean());
4276 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4277 try {
4278 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4279 } catch (... /* capture any exception to rethrow it over C code */) {
4280 thunk->capture();
4281 return MDBX_RESULT_TRUE;
4282 }
4283 }
4284 } thunk;
4286 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4287 thunk);
4288 }
4289
4290 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4291 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4292 }
4293
4294 template <typename CALLABLE_PREDICATE>
4295 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4296 move_operation turn = next) {
4297 struct wrapper : public exception_thunk {
4298 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4299 auto thunk = static_cast<wrapper *>(context);
4300 assert(thunk->is_clean());
4301 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4302 try {
4303 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4304 } catch (... /* capture any exception to rethrow it over C code */) {
4305 thunk->capture();
4306 return MDBX_RESULT_TRUE;
4307 }
4308 }
4309 } thunk;
4310 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4311 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4312 thunk);
4313 }
4314
4315 template <typename CALLABLE_PREDICATE>
4316 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4317 move_operation turn = next) {
4318 struct wrapper : public exception_thunk {
4319 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4320 auto thunk = static_cast<wrapper *>(context);
4321 assert(thunk->is_clean());
4322 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4323 try {
4324 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4325 } catch (... /* capture any exception to rethrow it over C code */) {
4326 thunk->capture();
4327 return MDBX_RESULT_TRUE;
4328 }
4329 }
4330 } thunk;
4331 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4332 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4333 thunk);
4334 }
4335
4336 move_result move(move_operation operation, bool throw_notfound) {
4337 return move_result(*this, operation, throw_notfound);
4338 }
4339 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4340 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4341 }
4342 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4343 return move_result(*this, operation, key, value, throw_notfound);
4344 }
4345 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4346 return move(operation, &key, &value, throw_notfound);
4347 }
4348
4349 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4350 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4351 move_result to_previous_last_multi(bool throw_notfound = true) {
4352 return move(multi_prevkey_lastvalue, throw_notfound);
4353 }
4354 move_result to_current_first_multi(bool throw_notfound = true) {
4355 return move(multi_currentkey_firstvalue, throw_notfound);
4356 }
4357 move_result to_current_prev_multi(bool throw_notfound = true) {
4358 return move(multi_currentkey_prevvalue, throw_notfound);
4359 }
4360 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4361 move_result to_current_next_multi(bool throw_notfound = true) {
4362 return move(multi_currentkey_nextvalue, throw_notfound);
4363 }
4364 move_result to_current_last_multi(bool throw_notfound = true) {
4365 return move(multi_currentkey_lastvalue, throw_notfound);
4366 }
4367 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4368 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4369 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4370
4371 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4372 return move(key_lesser_than, key, throw_notfound);
4373 }
4374 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4375 return move(key_lesser_or_equal, key, throw_notfound);
4376 }
4377 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4378 return move(key_equal, key, throw_notfound);
4379 }
4380 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4381 return move(key_exact, key, throw_notfound);
4382 }
4383 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4384 return move(key_greater_or_equal, key, throw_notfound);
4385 }
4386 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4387 return move(key_greater_than, key, throw_notfound);
4388 }
4389
4390 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4391 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4392 }
4393 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4394 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4395 }
4396 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4397 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4398 }
4399 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4400 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4401 }
4402 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4403 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4404 }
4405
4406 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4407 return move(pair_lesser_than, key, value, throw_notfound);
4408 }
4409 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4410 return move(pair_lesser_or_equal, key, value, throw_notfound);
4411 }
4412 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4413 return move(pair_equal, key, value, throw_notfound);
4414 }
4415 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4416 return move(pair_exact, key, value, throw_notfound);
4417 }
4418 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4419 return move(pair_greater_or_equal, key, value, throw_notfound);
4420 }
4421 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4422 return move(pair_greater_than, key, value, throw_notfound);
4423 }
4424
4425 inline bool seek(const slice &key);
4426 inline move_result find(const slice &key, bool throw_notfound = true);
4427 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4428 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4429
4431 inline size_t count_multivalue() const;
4432
4433 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4434 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4435 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4436
4437 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4438 return move(seek_and_batch_samelength, key, throw_notfound);
4439 }
4440
4441 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4442 return move(batch_samelength, throw_notfound);
4443 }
4444
4445 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4446 return move(batch_samelength_next, throw_notfound);
4447 }
4448
4449 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4450 return move(batch_samelength_previous, throw_notfound);
4451 }
4452
4453 inline bool eof() const;
4454 inline bool on_first() const;
4455 inline bool on_last() const;
4456 inline bool on_first_multival() const;
4457 inline bool on_last_multival() const;
4458 inline estimate_result estimate(const slice &key, const slice &value) const;
4459 inline estimate_result estimate(const slice &key) const;
4460 inline estimate_result estimate(move_operation operation) const;
4461 inline estimate_result estimate(move_operation operation, slice &key) const;
4462
4463 //----------------------------------------------------------------------------
4464
4466 inline void renew(::mdbx::txn &txn);
4467
4470
4472 inline void unbind();
4473
4475 inline ::mdbx::txn txn() const;
4476 inline map_handle map() const;
4477
4478 inline operator ::mdbx::txn() const { return txn(); }
4479 inline operator ::mdbx::map_handle() const { return map(); }
4480
4481 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4482 inline void put(const slice &key, slice value, put_mode mode);
4483 inline void insert(const slice &key, slice value);
4484 inline value_result try_insert(const slice &key, slice value);
4485 inline slice insert_reserve(const slice &key, size_t value_length);
4486 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4487
4488 inline void upsert(const slice &key, const slice &value);
4489 inline slice upsert_reserve(const slice &key, size_t value_length);
4490
4492 void update_current(const slice &value);
4494 slice reverse_current(size_t value_length);
4495
4496 inline void update(const slice &key, const slice &value);
4497 inline bool try_update(const slice &key, const slice &value);
4498 inline slice update_reserve(const slice &key, size_t value_length);
4499 inline value_result try_update_reserve(const slice &key, size_t value_length);
4500
4501 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4502 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4503 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4504 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4505
4507 inline bool erase(bool whole_multivalue = false);
4508
4511 inline bool erase(const slice &key, bool whole_multivalue = true);
4512
4515 inline bool erase(const slice &key, const slice &value);
4516
4517 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4518 size_t values_count, put_mode mode, bool allow_partial = false);
4519 template <typename VALUE>
4520 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4521 bool allow_partial = false) {
4522 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4523 !::std::is_array<VALUE>::value,
4524 "Must be a standard layout type!");
4525 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4526 }
4527 template <typename VALUE>
4528 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4529 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4530 }
4531};
4532
4540class LIBMDBX_API_TYPE cursor_managed : public cursor {
4541 using inherited = cursor;
4542 friend class txn;
4544 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4545
4546public:
4548 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4549 if (MDBX_UNLIKELY(!handle_))
4550 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4551 }
4552
4554 inline void close() {
4556 handle_ = nullptr;
4557 }
4558
4559 cursor_managed(cursor_managed &&) = default;
4560 cursor_managed &operator=(cursor_managed &&other) noexcept {
4562 MDBX_CXX20_UNLIKELY {
4563 assert(handle_ != other.handle_);
4564 close();
4565 }
4566 inherited::operator=(std::move(other));
4567 return *this;
4568 }
4569
4570 inline MDBX_cursor *withdraw_handle() noexcept {
4571 MDBX_cursor *handle = handle_;
4572 handle_ = nullptr;
4573 return handle;
4574 }
4575
4576 cursor_managed(const cursor_managed &) = delete;
4577 cursor_managed &operator=(const cursor_managed &) = delete;
4579};
4580
4581//==============================================================================
4582//
4583// Inline body of the libmdbx C++ API
4584//
4585
4586MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4587MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4588
4589static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4590#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4591 if (::std::is_constant_evaluated()) {
4592 for (size_t i = 0; c_str; ++i)
4593 if (!c_str[i])
4594 return i;
4595 return 0;
4596 }
4597#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4598#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4599 return c_str ? ::std::string_view(c_str).length() : 0;
4600#else
4601 return c_str ? ::std::strlen(c_str) : 0;
4602#endif
4603}
4604
4605MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4606#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4607 if (::std::is_constant_evaluated()) {
4608 for (size_t i = 0; i < bytes; ++i)
4609 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4610 return dest;
4611 } else
4612#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4613 return ::std::memcpy(dest, src, bytes);
4614}
4615
4616static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4617#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4618 if (::std::is_constant_evaluated()) {
4619 for (size_t i = 0; i < bytes; ++i) {
4620 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4621 if (diff)
4622 return diff;
4623 }
4624 return 0;
4625 } else
4626#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4627 return ::std::memcmp(a, b, bytes);
4628}
4629
4630//------------------------------------------------------------------------------
4631
4634
4638
4642
4643inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4644
4645inline void exception_thunk::capture() noexcept {
4646 assert(is_clean());
4647 captured_ = ::std::current_exception();
4648}
4649
4651 if (captured_)
4652 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4653}
4654
4655//------------------------------------------------------------------------------
4656
4657MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4658
4659inline error &error::operator=(MDBX_error_t error_code) noexcept {
4660 code_ = error_code;
4661 return *this;
4662}
4663
4664MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4665
4666MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4667
4668MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4669
4670MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4671
4672MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4673
4675 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4676}
4677
4678MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4679
4684
4685inline void error::throw_exception(int error_code) {
4686 const error trouble(static_cast<MDBX_error_t>(error_code));
4687 trouble.throw_exception();
4688}
4689
4690inline void error::throw_on_failure() const {
4692 MDBX_CXX20_UNLIKELY throw_exception();
4693}
4694
4695inline void error::success_or_throw() const {
4696 if (MDBX_UNLIKELY(!is_success()))
4697 MDBX_CXX20_UNLIKELY throw_exception();
4698}
4699
4700inline void error::success_or_throw(const exception_thunk &thunk) const {
4701 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4702 if (MDBX_UNLIKELY(!is_success())) {
4703 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4704 else throw_exception();
4705 }
4706}
4707
4708inline void error::panic_on_failure(const char *context_where, const char *func_who) const noexcept {
4710 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4711}
4712
4713inline void error::success_or_panic(const char *context_where, const char *func_who) const noexcept {
4714 if (MDBX_UNLIKELY(!is_success()))
4715 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4716}
4717
4718inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4719 if (MDBX_UNLIKELY(ptr == nullptr))
4720 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4721}
4722
4723inline void error::throw_on_failure(int error_code) {
4724 error rc(static_cast<MDBX_error_t>(error_code));
4725 rc.throw_on_failure();
4726}
4727
4728inline void error::success_or_throw(MDBX_error_t error_code) {
4729 error rc(error_code);
4730 rc.success_or_throw();
4731}
4732
4733inline bool error::boolean_or_throw(int error_code) {
4734 switch (error_code) {
4735 case MDBX_RESULT_FALSE:
4736 return false;
4737 case MDBX_RESULT_TRUE:
4738 return true;
4739 default:
4740 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4741 }
4742}
4743
4744inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4745 error rc(static_cast<MDBX_error_t>(error_code));
4746 rc.success_or_throw(thunk);
4747}
4748
4749inline void error::panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept {
4750 error rc(static_cast<MDBX_error_t>(error_code));
4751 rc.panic_on_failure(context_where, func_who);
4752}
4753
4754inline void error::success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept {
4755 error rc(static_cast<MDBX_error_t>(error_code));
4756 rc.success_or_panic(context_where, func_who);
4757}
4758
4759inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4760 if (MDBX_UNLIKELY(!thunk.is_clean()))
4761 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4762 return boolean_or_throw(error_code);
4763}
4764
4765MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4766
4768 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4769
4770MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4771 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4772
4773MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4774
4775MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4776
4777MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4778
4779MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4780
4781inline slice &slice::assign(const void *ptr, size_t bytes) {
4782 iov_base = const_cast<void *>(ptr);
4783 iov_len = check_length(bytes);
4784 return *this;
4785}
4786
4787inline slice &slice::assign(const slice &src) noexcept {
4788 iov_base = src.iov_base;
4789 iov_len = src.iov_len;
4790 return *this;
4791}
4792
4793inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4794
4795slice &slice::assign(slice &&src) noexcept {
4796 assign(src);
4797 src.invalidate();
4798 return *this;
4799}
4800
4802 assign(src.iov_base, src.iov_len);
4803 src.iov_base = nullptr;
4804 return *this;
4805}
4806
4807inline slice &slice::assign(const void *begin, const void *end) {
4808 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4809}
4810
4811inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4812
4813inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4814
4815inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4816
4817MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4818
4819MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4820
4821MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4822
4824
4825MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4826
4827MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4828
4829MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4830
4832
4833MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4834
4835MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4836
4837MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4838
4839MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4840
4841MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4842
4844 iov_len = check_length(bytes);
4845 return *this;
4846}
4847
4849 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4850 return set_length(static_cast<const char *>(ptr) - char_ptr());
4851}
4852
4853MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4854
4855MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4856
4857MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4858
4859MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4860
4861MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4862
4864 iov_base = nullptr;
4865 iov_len = 0;
4866}
4867
4868inline void slice::remove_prefix(size_t n) noexcept {
4869 assert(n <= size());
4870 iov_base = static_cast<byte *>(iov_base) + n;
4871 iov_len -= n;
4872}
4873
4874inline void slice::safe_remove_prefix(size_t n) {
4875 if (MDBX_UNLIKELY(n > size()))
4876 MDBX_CXX20_UNLIKELY throw_out_range();
4877 remove_prefix(n);
4878}
4879
4880inline void slice::remove_suffix(size_t n) noexcept {
4881 assert(n <= size());
4882 iov_len -= n;
4883}
4884
4885inline void slice::safe_remove_suffix(size_t n) {
4886 if (MDBX_UNLIKELY(n > size()))
4887 MDBX_CXX20_UNLIKELY throw_out_range();
4888 remove_suffix(n);
4889}
4890
4891MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4892 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4893}
4894
4895MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4896 return length() >= suffix.length() &&
4897 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4898}
4899
4901 size_t h = length() * 3977471;
4902 for (size_t i = 0; i < length(); ++i)
4903 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4904 return h ^ 3863194411 * (h >> 11);
4905}
4906
4907MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4909 return byte_ptr()[n];
4910}
4911
4912MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4913 if (MDBX_UNLIKELY(n >= size()))
4914 MDBX_CXX20_UNLIKELY throw_out_range();
4915 return byte_ptr()[n];
4916}
4917
4918MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4920 return slice(data(), n);
4921}
4922
4923MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4925 return slice(char_ptr() + size() - n, n);
4926}
4927
4928MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4929 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4930 return slice(char_ptr() + from, n);
4931}
4932
4934 if (MDBX_UNLIKELY(n > size()))
4935 MDBX_CXX20_UNLIKELY throw_out_range();
4936 return head(n);
4937}
4938
4940 if (MDBX_UNLIKELY(n > size()))
4941 MDBX_CXX20_UNLIKELY throw_out_range();
4942 return tail(n);
4943}
4944
4945MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4946 if (MDBX_UNLIKELY(n > max_length))
4947 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4948 if (MDBX_UNLIKELY(from + n > size()))
4949 MDBX_CXX20_UNLIKELY throw_out_range();
4950 return middle(from, n);
4951}
4952
4953MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4954 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4955 return diff ? diff
4956 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4957 : memcmp(a.data(), b.data(), a.length());
4958}
4959
4961 const size_t shortest = ::std::min(a.length(), b.length());
4962 if (MDBX_LIKELY(shortest > 0))
4964 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4965 if (MDBX_LIKELY(diff != 0))
4966 MDBX_CXX20_LIKELY return diff;
4967 }
4968 return intptr_t(a.length()) - intptr_t(b.length());
4969}
4970
4972 return slice::compare_fast(a, b) == 0;
4973}
4974
4976 return slice::compare_lexicographically(a, b) < 0;
4977}
4978
4980 return slice::compare_lexicographically(a, b) > 0;
4981}
4982
4984 return slice::compare_lexicographically(a, b) <= 0;
4985}
4986
4988 return slice::compare_lexicographically(a, b) >= 0;
4989}
4990
4992 return slice::compare_fast(a, b) != 0;
4993}
4994
4995#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
4996MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
4998}
4999#endif /* __cpp_impl_three_way_comparison */
5000
5001template <class ALLOCATOR, typename CAPACITY_POLICY>
5003 const allocator_type &alloc)
5004 : inherited(src), silo_(alloc) {
5005 if (!make_reference)
5006 insulate();
5007}
5008
5009template <class ALLOCATOR, typename CAPACITY_POLICY>
5010inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
5011 const allocator_type &alloc)
5012 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
5013
5014template <class ALLOCATOR, typename CAPACITY_POLICY>
5015inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
5016 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
5017}
5018
5019#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
5021
5022#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
5024#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
5025#endif /* !MinGW || MDBX_EXPORTS */
5026
5029
5030//------------------------------------------------------------------------------
5031
5032template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5033inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
5034 if (MDBX_LIKELY(!producer.is_empty()))
5036 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5037 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5038 return result;
5039 }
5041}
5042
5043template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5044inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
5045 if (MDBX_LIKELY(!producer.is_empty()))
5047 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5048 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5049 return result;
5050 }
5052}
5053
5054template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5055inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
5056 string<ALLOCATOR> result(alloc);
5057 if (MDBX_LIKELY(!producer.is_empty()))
5059 result.resize(producer.envisage_result_length());
5060 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5061 }
5062 return result;
5063}
5064
5065template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5066inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
5067 string<ALLOCATOR> result(alloc);
5068 if (MDBX_LIKELY(!producer.is_empty()))
5070 result.resize(producer.envisage_result_length());
5071 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5072 }
5073 return result;
5074}
5075
5076template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
5077 return make_string<ALLOCATOR>(*this, alloc);
5078}
5079
5080template <class ALLOCATOR, typename CAPACITY_POLICY>
5082 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5083}
5084
5085template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
5086 return make_string<ALLOCATOR>(*this, alloc);
5087}
5088
5089template <class ALLOCATOR, typename CAPACITY_POLICY>
5091 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5092}
5093
5094template <class ALLOCATOR> string<ALLOCATOR> to_base64::as_string(const ALLOCATOR &alloc) const {
5095 return make_string<ALLOCATOR>(*this, alloc);
5096}
5097
5098template <class ALLOCATOR, typename CAPACITY_POLICY>
5100 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5101}
5102
5103template <class ALLOCATOR> string<ALLOCATOR> from_hex::as_string(const ALLOCATOR &alloc) const {
5104 return make_string<ALLOCATOR>(*this, alloc);
5105}
5106
5107template <class ALLOCATOR, typename CAPACITY_POLICY>
5109 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5110}
5111
5112template <class ALLOCATOR> string<ALLOCATOR> from_base58::as_string(const ALLOCATOR &alloc) const {
5113 return make_string<ALLOCATOR>(*this, alloc);
5114}
5115
5116template <class ALLOCATOR, typename CAPACITY_POLICY>
5118 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5119}
5120
5121template <class ALLOCATOR> string<ALLOCATOR> from_base64::as_string(const ALLOCATOR &alloc) const {
5122 return make_string<ALLOCATOR>(*this, alloc);
5123}
5124
5125template <class ALLOCATOR, typename CAPACITY_POLICY>
5127 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5128}
5129
5130template <class ALLOCATOR>
5131inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
5132 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
5133}
5134
5135template <class ALLOCATOR>
5136inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5137 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5138}
5139
5140template <class ALLOCATOR>
5141inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5142 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5143}
5144
5145template <class ALLOCATOR, class CAPACITY_POLICY>
5146inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5147 const ALLOCATOR &alloc) const {
5148 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5149}
5150
5151template <class ALLOCATOR, class CAPACITY_POLICY>
5152inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
5153 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5154}
5155
5156template <class ALLOCATOR, class CAPACITY_POLICY>
5157inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
5158 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5159}
5160
5161template <class ALLOCATOR, class CAPACITY_POLICY>
5162inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5163 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5164}
5165
5166template <class ALLOCATOR, class CAPACITY_POLICY>
5167inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5168 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5169}
5170
5171template <class ALLOCATOR, class CAPACITY_POLICY>
5172inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5173 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5174}
5175
5176//------------------------------------------------------------------------------
5177
5178MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5179 const auto diff = slice::compare_fast(a.key, b.key);
5180 return diff ? diff : slice::compare_fast(a.value, b.value);
5181}
5182
5183MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5184 const auto diff = slice::compare_lexicographically(a.key, b.key);
5185 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5186}
5187
5189 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5190 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5191 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5192}
5193
5195 return pair::compare_lexicographically(a, b) < 0;
5196}
5197
5199 return pair::compare_lexicographically(a, b) > 0;
5200}
5201
5203 return pair::compare_lexicographically(a, b) <= 0;
5204}
5205
5207 return pair::compare_lexicographically(a, b) >= 0;
5208}
5209
5211 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5212 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5213 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5214}
5215
5216#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5217MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5219}
5220#endif /* __cpp_impl_three_way_comparison */
5221
5223template <typename BUFFER>
5225
5228
5229//------------------------------------------------------------------------------
5230
5231inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
5232inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
5233inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
5234
5235MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5236 return !from_hex(*this, ignore_spaces).is_erroneous();
5237}
5238
5239MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5240 return !from_base58(*this, ignore_spaces).is_erroneous();
5241}
5242
5243MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5244 return !from_base64(*this, ignore_spaces).is_erroneous();
5245}
5246
5247//------------------------------------------------------------------------------
5248
5250
5251inline env &env::operator=(env &&other) noexcept {
5252 handle_ = other.handle_;
5253 other.handle_ = nullptr;
5254 return *this;
5255}
5256
5257inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5258
5259inline env::~env() noexcept {
5260#ifndef NDEBUG
5261 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5262#endif
5263}
5264
5265MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5266
5267MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5268
5269MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5270
5271MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5272
5273MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5274
5278 return *this;
5279}
5280
5281inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5282 size_now = size_lower = lower;
5283 size_upper = upper;
5285 return *this;
5286}
5287
5291
5295
5296inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5297
5298inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5299
5300inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5301 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5302 if (result < 0)
5303 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5304 return static_cast<size_t>(result);
5305}
5306
5307inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5308 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5309 if (result < 0)
5310 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5311 return static_cast<size_t>(result);
5312}
5313
5314inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5315
5316inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5317
5318inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5319 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5320 if (result < 0)
5321 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5322 return static_cast<size_t>(result);
5323}
5324
5325inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5326 return key_max(pagesize, MDBX_db_flags_t(mode));
5327}
5328
5329inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
5330 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5331 if (result < 0)
5332 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5333 return static_cast<size_t>(result);
5334}
5335
5337
5338inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5339
5341
5342inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5343 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5344 if (result < 0)
5345 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5346 return static_cast<size_t>(result);
5347}
5348
5349inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5350 return value_max(pagesize, MDBX_db_flags_t(mode));
5351}
5352
5353inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
5354 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5355 if (result < 0)
5356 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5357 return static_cast<size_t>(result);
5358}
5359
5361
5362inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5363 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5364 if (result < 0)
5365 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5366 return static_cast<size_t>(result);
5367}
5368
5369inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5370 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5371}
5372
5374 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5375 if (result < 0)
5376 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5377 return static_cast<size_t>(result);
5378}
5379
5383
5384inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5385 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5386 if (result < 0)
5387 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5388 return static_cast<size_t>(result);
5389}
5390
5391inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5392 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5393}
5394
5396 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5397 if (result < 0)
5398 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5399 return static_cast<size_t>(result);
5400}
5401
5405
5406inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5407 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5408 if (result < 0)
5409 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5410 return static_cast<size_t>(result);
5411}
5412
5413inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5414
5422
5424
5428
5432
5436
5437inline env::stat env::get_stat() const {
5438 env::stat r;
5439 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5440 return r;
5441}
5442
5443inline env::stat env::get_stat(const txn &txn) const {
5444 env::stat r;
5446 return r;
5447}
5448
5449inline env::info env::get_info() const {
5450 env::info r;
5451 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5452 return r;
5453}
5454
5455inline env::info env::get_info(const txn &txn) const {
5456 env::info r;
5458 return r;
5459}
5460
5462 filehandle fd;
5464 return fd;
5465}
5466
5468 unsigned bits = 0;
5470 return MDBX_env_flags_t(bits);
5471}
5472
5473inline unsigned env::max_readers() const {
5474 unsigned r;
5476 return r;
5477}
5478
5479inline unsigned env::max_maps() const {
5480 unsigned r;
5482 return r;
5483}
5484
5485inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5486
5487inline env &env::set_context(void *ptr) {
5489 return *this;
5490}
5491
5492inline env &env::set_sync_threshold(size_t bytes) {
5494 return *this;
5495}
5496
5497inline size_t env::sync_threshold() const {
5498 size_t bytes;
5500 return bytes;
5501}
5502
5503inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5505 return *this;
5506}
5507
5508inline unsigned env::sync_period__seconds_16dot16() const {
5509 unsigned seconds_16dot16;
5511 return seconds_16dot16;
5512}
5513
5515 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5516}
5517
5518inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5519
5520#if __cplusplus >= 201103L
5521inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5522
5524#endif
5525
5526inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5528 return *this;
5529}
5530
5531inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5532 uint64_t value;
5534 return value;
5535}
5536
5537inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
5539 return *this;
5540}
5541
5542inline env &env::set_geometry(const geometry &geo) {
5544 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5545 return *this;
5546}
5547
5548inline bool env::sync_to_disk(bool force, bool nonblock) {
5549 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5550 switch (err) {
5551 case MDBX_SUCCESS /* flush done */:
5552 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5553 return true;
5554 case MDBX_BUSY /* the environment is used by other thread */:
5555 return false;
5556 default:
5557 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5558 }
5559}
5560
5561inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5562
5564env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5565 size_t retained) noexcept
5567 bytes_retained(retained) {}
5568
5569template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5570 struct reader_visitor_thunk : public exception_thunk {
5571 VISITOR &visitor_;
5572 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5573 size_t used, size_t retained) noexcept {
5574 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5575 assert(thunk->is_clean());
5576 try {
5577 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5578 return loop_control(thunk->visitor_(info, number));
5579 } catch (... /* capture any exception to rethrow it over C code */) {
5580 thunk->capture();
5582 }
5583 }
5584 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5585 };
5586 reader_visitor_thunk thunk(visitor);
5587 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5588 thunk.rethrow_captured();
5589 return rc;
5590}
5591
5592inline unsigned env::check_readers() {
5593 int dead_count;
5594 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5595 assert(dead_count >= 0);
5596 return static_cast<unsigned>(dead_count);
5597}
5598
5603
5604inline MDBX_hsr_func env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5605
5607 ::MDBX_txn *ptr;
5609 assert(ptr != nullptr);
5610 return txn_managed(ptr);
5611}
5612
5614 ::MDBX_txn *ptr;
5616 assert(ptr != nullptr);
5617 return txn_managed(ptr);
5618}
5619
5620inline txn_managed env::start_write(bool dont_wait) {
5621 ::MDBX_txn *ptr;
5624 assert(ptr != nullptr || dont_wait);
5625 return txn_managed(ptr);
5626}
5627
5629 ::MDBX_txn *ptr;
5631 assert(ptr != nullptr);
5632 return txn_managed(ptr);
5633}
5634
5636
5638
5639inline txn &txn::operator=(txn &&other) noexcept {
5640 handle_ = other.handle_;
5641 other.handle_ = nullptr;
5642 return *this;
5643}
5644
5645inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5646
5647inline txn::~txn() noexcept {
5648#ifndef NDEBUG
5649 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5650#endif
5651}
5652
5653MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5654
5655MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5656
5657MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5658
5659MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5660
5661MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5662
5663inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5664
5665inline txn &txn::set_context(void *ptr) {
5667 return *this;
5668}
5669
5670inline bool txn::is_dirty(const void *ptr) const {
5671 int err = ::mdbx_is_dirty(handle_, ptr);
5672 switch (err) {
5673 default:
5674 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5675 case MDBX_RESULT_TRUE:
5676 return true;
5677 case MDBX_RESULT_FALSE:
5678 return false;
5679 }
5680}
5681
5682inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5683
5685 const int bits = mdbx_txn_flags(handle_);
5687 return static_cast<MDBX_txn_flags_t>(bits);
5688}
5689
5690inline uint64_t txn::id() const {
5691 const uint64_t txnid = mdbx_txn_id(handle_);
5693 return txnid;
5694}
5695
5697
5699
5701
5702inline txn_managed txn::clone(void *context) const {
5703 MDBX_txn *ptr = nullptr;
5705 assert(ptr != nullptr);
5706 return txn_managed(ptr);
5707}
5708
5709inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
5710 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
5711 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
5712 assert(txn_for_renew_into_clone.handle_ != nullptr);
5713}
5714
5715inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5716
5717inline bool txn::unpark_reading(bool restart_if_ousted) {
5718 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5719}
5720
5721inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5722 txn::info r;
5723 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5724 return r;
5725}
5726
5728 MDBX_cursor *ptr;
5730 return cursor_managed(ptr);
5731}
5732
5733inline size_t txn::release_all_cursors(bool unbind) const {
5734 size_t count;
5736 return count;
5737}
5738
5739inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5740 const ::mdbx::value_mode value_mode) const {
5741 map_handle map;
5744 assert(map.dbi != 0);
5745 return map;
5746}
5747
5748inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5749 const ::mdbx::value_mode value_mode) const {
5750 map_handle map;
5753 assert(map.dbi != 0);
5754 return map;
5755}
5756
5757inline map_handle txn::open_map_accede(const slice &name) const {
5758 map_handle map;
5760 assert(map.dbi != 0);
5761 return map;
5762}
5763
5764inline map_handle txn::open_map_accede(const char *name) const {
5765 map_handle map;
5767 assert(map.dbi != 0);
5768 return map;
5769}
5770
5771inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5772 const ::mdbx::value_mode value_mode) {
5773 map_handle map;
5776 assert(map.dbi != 0);
5777 return map;
5778}
5779
5780inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5781 const ::mdbx::value_mode value_mode) {
5782 map_handle map;
5785 assert(map.dbi != 0);
5786 return map;
5787}
5788
5790
5792
5793inline void txn::rename_map(map_handle map, const char *new_name) {
5795}
5796
5797inline void txn::rename_map(map_handle map, const slice &new_name) {
5799}
5800
5801inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5802 const ::mdbx::value_mode value_mode) const {
5803 return open_map(slice(name), key_mode, value_mode);
5804}
5805
5806inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5807
5808inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5809 const ::mdbx::value_mode value_mode) {
5810 return create_map(slice(name), key_mode, value_mode);
5811}
5812
5813inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5814 return drop_map(slice(name), throw_if_absent);
5815}
5816
5817inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5818 return clear_map(slice(name), throw_if_absent);
5819}
5820
5821inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5822
5824 txn::map_stat r;
5825 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5826 return r;
5827}
5828
5829inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5830 uint32_t r;
5832 return r;
5833}
5834
5840
5845
5847 txn::canary r;
5849 return r;
5850}
5851
5852inline uint64_t txn::sequence(map_handle map) const {
5853 uint64_t result;
5855 return result;
5856}
5857
5858inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5859 uint64_t result;
5860 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5861 return result;
5862}
5863
5864inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5865 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5866}
5867
5868inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5869 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5870}
5871
5872inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5873 return compare_keys(map, a.key, b.key);
5874}
5875
5876inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5877 return compare_values(map, a.value, b.value);
5878}
5879
5880inline slice txn::get(map_handle map, const slice &key) const {
5881 slice result;
5882 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5883 return result;
5884}
5885
5886inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5887 slice result;
5888 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5889 return result;
5890}
5891
5892inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5893 slice result;
5894 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5895 switch (err) {
5896 case MDBX_SUCCESS:
5897 return result;
5898 case MDBX_NOTFOUND:
5899 return value_at_absence;
5900 default:
5901 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5902 }
5903}
5904
5905inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5906 slice result;
5907 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5908 switch (err) {
5909 case MDBX_SUCCESS:
5910 return result;
5911 case MDBX_NOTFOUND:
5912 return value_at_absence;
5913 default:
5914 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5915 }
5916}
5917
5919 pair result(key, slice());
5920 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5921 return pair_result(result.key, result.value, exact);
5922}
5923
5924inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5925 pair result{key, slice()};
5926 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5927 switch (err) {
5928 case MDBX_SUCCESS:
5929 return pair_result{result.key, result.value, true};
5930 case MDBX_RESULT_TRUE:
5931 return pair_result{result.key, result.value, false};
5932 case MDBX_NOTFOUND:
5933 return pair_result{key, value_at_absence, false};
5934 default:
5935 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5936 }
5937}
5938
5939inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5940 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5941}
5942
5943inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5944 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5945}
5946
5947inline void txn::insert(map_handle map, const slice &key, slice value) {
5948 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5950}
5951
5952inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5953 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5955 switch (err) {
5956 case MDBX_SUCCESS:
5957 return value_result{slice(), true};
5958 case MDBX_KEYEXIST:
5959 return value_result{value, false};
5960 default:
5961 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5962 }
5963}
5964
5965inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5966 slice result(nullptr, value_length);
5967 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5969 return result;
5970}
5971
5972inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5973 slice result(nullptr, value_length);
5974 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5976 switch (err) {
5977 case MDBX_SUCCESS:
5978 return value_result{result, true};
5979 case MDBX_KEYEXIST:
5980 return value_result{result, false};
5981 default:
5982 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5983 }
5984}
5985
5986inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5987 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5988}
5989
5990inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
5991 slice result(nullptr, value_length);
5993 return result;
5994}
5995
5996inline void txn::update(map_handle map, const slice &key, const slice &value) {
5997 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
5998}
5999
6000inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
6001 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6002 switch (err) {
6003 case MDBX_SUCCESS:
6004 return true;
6005 case MDBX_NOTFOUND:
6006 return false;
6007 default:
6008 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6009 }
6010}
6011
6012inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
6013 slice result(nullptr, value_length);
6015 return result;
6016}
6017
6018inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
6019 slice result(nullptr, value_length);
6020 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6021 switch (err) {
6022 case MDBX_SUCCESS:
6023 return value_result{result, true};
6024 case MDBX_NOTFOUND:
6025 return value_result{slice(), false};
6026 default:
6027 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6028 }
6029}
6030
6031inline bool txn::erase(map_handle map, const slice &key) {
6032 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6033 switch (err) {
6034 case MDBX_SUCCESS:
6035 return true;
6036 case MDBX_NOTFOUND:
6037 return false;
6038 default:
6039 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6040 }
6041}
6042
6043inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6044 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
6045 switch (err) {
6046 case MDBX_SUCCESS:
6047 return true;
6048 case MDBX_NOTFOUND:
6049 return false;
6050 default:
6051 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6052 }
6053}
6054
6055inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
6056 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6057 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6058}
6059
6060template <class ALLOCATOR, typename CAPACITY_POLICY>
6064 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6066 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
6067 return result;
6068}
6069
6070template <class ALLOCATOR, typename CAPACITY_POLICY>
6072txn::replace(map_handle map, const slice &key, const slice &new_value,
6074 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6075 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
6076 MDBX_CURRENT, result, &result),
6077 result);
6078 return result;
6079}
6080
6081template <class ALLOCATOR, typename CAPACITY_POLICY>
6083txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
6085 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6086 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6087 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6088 result);
6089 return result;
6090}
6091
6092inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
6093 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6094 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
6095}
6096
6097inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
6098 const void *values_array, size_t values_count, put_mode mode,
6099 bool allow_partial) {
6100 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6101 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6102 switch (err) {
6103 case MDBX_SUCCESS:
6104 MDBX_CXX20_LIKELY break;
6105 case MDBX_KEYEXIST:
6106 if (allow_partial)
6107 break;
6109 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6110 default:
6111 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6112 }
6113 return args[1].iov_len /* done item count */;
6114}
6115
6116inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
6117 ptrdiff_t result;
6118 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6119 return result;
6120}
6121
6122inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6123 ptrdiff_t result;
6124 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6125 return result;
6126}
6127
6128inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6129 ptrdiff_t result;
6130 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6131 return result;
6132}
6133
6134inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6135 ptrdiff_t result;
6136 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6137 return result;
6138}
6139
6141
6142inline cursor_managed cursor::clone(void *your_context) const {
6143 cursor_managed clone(your_context);
6145 return clone;
6146}
6147
6148inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6149
6150inline cursor &cursor::set_context(void *ptr) {
6152 return *this;
6153}
6154
6155inline cursor &cursor::operator=(cursor &&other) noexcept {
6156 handle_ = other.handle_;
6157 other.handle_ = nullptr;
6158 return *this;
6159}
6160
6161inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6162
6163inline cursor::~cursor() noexcept {
6164#ifndef NDEBUG
6165 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6166#endif
6167}
6168
6169MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
6170
6171MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
6172
6173MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6174
6175MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6176
6177MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6178
6179inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6180 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6181}
6182
6183inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6184 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6185 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6186 if (MDBX_LIKELY(int16_t(diff) == diff))
6187 MDBX_CXX20_LIKELY return int(diff);
6188 else
6190}
6191
6192inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6193 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6194}
6195
6197 bool throw_notfound)
6198 : pair_result(key, value, false) {
6199 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6200}
6201
6202inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6203 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6204 switch (err) {
6205 case MDBX_SUCCESS:
6206 MDBX_CXX20_LIKELY return true;
6207 case MDBX_RESULT_TRUE:
6208 return false;
6209 case MDBX_NOTFOUND:
6210 if (!throw_notfound)
6211 return false;
6212 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6213 default:
6214 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6215 }
6216}
6217
6219 const slice &value)
6220 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6221 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6222}
6223
6224inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6225 ptrdiff_t result;
6226 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6227 return result;
6228}
6229
6230inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6231 ptrdiff_t result;
6233 return result;
6234}
6235
6236inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6237 return move(key_exact, key, throw_notfound);
6238}
6239
6240inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6241 return move(key_lowerbound, key, throw_notfound);
6242}
6243
6244inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6245 return move(key_greater_than, key, throw_notfound);
6246}
6247
6248inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6249 return move(multi_find_pair, key, value, throw_notfound);
6250}
6251
6252inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6253 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6254}
6255
6256inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6257 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6258}
6259
6260inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6261
6262inline size_t cursor::count_multivalue() const {
6263 size_t result;
6265 return result;
6266}
6267
6268inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6269
6271
6273
6275
6277
6278inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6279 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6280}
6281
6283 return estimate_result(*this, key_lowerbound, key);
6284}
6285
6287 return estimate_result(*this, operation);
6288}
6289
6291
6295
6297
6298inline txn cursor::txn() const {
6300 return ::mdbx::txn(txn);
6301}
6302
6303inline map_handle cursor::map() const {
6304 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6305 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6307 return map_handle(dbi);
6308}
6309
6310inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6311 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6312}
6313
6314inline void cursor::put(const slice &key, slice value, put_mode mode) {
6315 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6316}
6317
6318inline void cursor::insert(const slice &key, slice value) {
6320 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6321}
6322
6323inline value_result cursor::try_insert(const slice &key, slice value) {
6324 const int err =
6325 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6326 switch (err) {
6327 case MDBX_SUCCESS:
6328 return value_result{slice(), true};
6329 case MDBX_KEYEXIST:
6330 return value_result{value, false};
6331 default:
6332 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6333 }
6334}
6335
6336inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6337 slice result(nullptr, value_length);
6338 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6340 return result;
6341}
6342
6343inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6344 slice result(nullptr, value_length);
6345 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6347 switch (err) {
6348 case MDBX_SUCCESS:
6349 return value_result{result, true};
6350 case MDBX_KEYEXIST:
6351 return value_result{result, false};
6352 default:
6353 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6354 }
6355}
6356
6357inline void cursor::upsert(const slice &key, const slice &value) {
6358 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6359}
6360
6361inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6362 slice result(nullptr, value_length);
6364 return result;
6365}
6366
6367inline void cursor::update(const slice &key, const slice &value) {
6368 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6369}
6370
6371inline bool cursor::try_update(const slice &key, const slice &value) {
6372 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6373 switch (err) {
6374 case MDBX_SUCCESS:
6375 return true;
6376 case MDBX_NOTFOUND:
6377 return false;
6378 default:
6379 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6380 }
6381}
6382
6383inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6384 slice result(nullptr, value_length);
6386 return result;
6387}
6388
6389inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6390 slice result(nullptr, value_length);
6391 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6392 switch (err) {
6393 case MDBX_SUCCESS:
6394 return value_result{result, true};
6395 case MDBX_NOTFOUND:
6396 return value_result{slice(), false};
6397 default:
6398 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6399 }
6400}
6401
6402inline bool cursor::erase(bool whole_multivalue) {
6403 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6404 switch (err) {
6405 case MDBX_SUCCESS:
6406 MDBX_CXX20_LIKELY return true;
6407 case MDBX_NOTFOUND:
6408 return false;
6409 default:
6410 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6411 }
6412}
6413
6414inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6415 bool found = seek(key);
6416 return found ? erase(whole_multivalue) : found;
6417}
6418
6419inline bool cursor::erase(const slice &key, const slice &value) {
6420 move_result data = find_multivalue(key, value, false);
6421 return data.done && erase();
6422}
6423
6424inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6425 size_t values_count, put_mode mode, bool allow_partial) {
6426 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6427 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6428 switch (err) {
6429 case MDBX_SUCCESS:
6430 MDBX_CXX20_LIKELY break;
6431 case MDBX_KEYEXIST:
6432 if (allow_partial)
6433 break;
6435 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6436 default:
6437 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6438 }
6439 return args[1].iov_len /* done item count */;
6440}
6441
6442//------------------------------------------------------------------------------
6443
6444LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
6445LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
6446LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
6447LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
6448LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
6449LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
6450LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
6451LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
6452LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
6453LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
6454LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
6455
6456LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
6457LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
6458LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
6459
6460inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
6461
6463
6464} // namespace mdbx
6465
6466//------------------------------------------------------------------------------
6467
6470namespace std {
6471
6472inline string to_string(const ::mdbx::slice &value) {
6473 ostringstream out;
6474 out << value;
6475 return out.str();
6476}
6477
6478template <class ALLOCATOR, typename CAPACITY_POLICY>
6479inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6480 ostringstream out;
6481 out << buffer;
6482 return out.str();
6483}
6484
6485inline string to_string(const ::mdbx::pair &value) {
6486 ostringstream out;
6487 out << value;
6488 return out.str();
6489}
6490
6491inline string to_string(const ::mdbx::env::geometry &value) {
6492 ostringstream out;
6493 out << value;
6494 return out.str();
6495}
6496
6497inline string to_string(const ::mdbx::env::operate_parameters &value) {
6498 ostringstream out;
6499 out << value;
6500 return out.str();
6501}
6502
6503inline string to_string(const ::mdbx::env::mode &value) {
6504 ostringstream out;
6505 out << value;
6506 return out.str();
6507}
6508
6509inline string to_string(const ::mdbx::env::durability &value) {
6510 ostringstream out;
6511 out << value;
6512 return out.str();
6513}
6514
6515inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6516 ostringstream out;
6517 out << value;
6518 return out.str();
6519}
6520
6521inline string to_string(const ::mdbx::env::operate_options &value) {
6522 ostringstream out;
6523 out << value;
6524 return out.str();
6525}
6526
6527inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6528 ostringstream out;
6529 out << value;
6530 return out.str();
6531}
6532
6533inline string to_string(const ::MDBX_log_level_t &value) {
6534 ostringstream out;
6535 out << value;
6536 return out.str();
6537}
6538
6539inline string to_string(const ::MDBX_debug_flags_t &value) {
6540 ostringstream out;
6541 out << value;
6542 return out.str();
6543}
6544
6545inline string to_string(const ::mdbx::error &value) {
6546 ostringstream out;
6547 out << value;
6548 return out.str();
6549}
6550
6551inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6552
6553template <> struct hash<::mdbx::slice> {
6554 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6555};
6556
6557template <> struct hash<::mdbx::map_handle> {
6558 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6559};
6560
6561template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6562 using inherited = std::hash<const MDBX_env *>;
6563 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6564};
6565
6566template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6567 using inherited = std::hash<const MDBX_txn *>;
6568 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6569};
6570
6571template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6572 using inherited = std::hash<const MDBX_cursor *>;
6573 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6574};
6575
6576template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6577 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6578 return buffer.hash_value();
6579 }
6580};
6581
6582} // namespace std
6583
6584#if defined(__LCC__) && __LCC__ >= 126
6585#pragma diagnostic pop
6586#endif
6587
6588#ifdef _MSC_VER
6589#pragma warning(pop)
6590#endif
Definition mdbx.h++:1160
Definition mdbx.h++:1150
Definition mdbx.h++:1170
#define MDBX_CXX11_CONSTEXPR
Definition mdbx.h:458
#define MDBX_MAYBE_UNUSED
Definition mdbx.h:524
#define MDBX_CXX14_CONSTEXPR
Definition mdbx.h:477
#define MDBX_NOTHROW_PURE_FUNCTION
The 'pure nothrow' function attribute for optimization.
Definition mdbx.h:274
mode_t mdbx_mode_t
Definition mdbx.h:187
#define LIBMDBX_API
Definition mdbx.h:606
#define LIBMDBX_API_TYPE
Definition mdbx.h:621
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:780
pthread_t mdbx_tid_t
Definition mdbx.h:186
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition mdbx.h:713
int mdbx_filehandle_t
Definition mdbx.h:184
pid_t mdbx_pid_t
Definition mdbx.h:185
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:794
@ MDBX_MAXDATASIZE
Definition mdbx.h:788
@ MDBX_MAX_DBI
Definition mdbx.h:785
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:791
libmdbx build information
Definition mdbx.h:649
Lightweight transparent cache entry structure used by mdbx_cache_get().
Definition mdbx.h:5168
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4661
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4100
Information about the environment.
Definition mdbx.h:2794
Statistics for a table in the environment.
Definition mdbx.h:2748
Information about the transaction.
Definition mdbx.h:4002
libmdbx version information,
Definition mdbx.h:631
LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, MDBX_put_flags_t flags)
Delete current key/data pair.
int(* MDBX_preserve_func)(void *context, MDBX_val *target, const void *src, size_t bytes)
A data preservation callback for using within mdbx_replace_ex().
Definition mdbx.h:5461
LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result, uint64_t increment)
Sequence generation for a table.
LIBMDBX_API int mdbx_cursor_scan(MDBX_cursor *cursor, MDBX_predicate_func predicate, void *context, MDBX_cursor_op start_op, MDBX_cursor_op turn_op, void *arg)
Scans the table using the passed predicate, reducing the associated overhead.
LIBMDBX_API int mdbx_get_equal_or_great(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data)
Get equal or great item from a table.
LIBMDBX_API int mdbx_canary_put(MDBX_txn *txn, const MDBX_canary *canary)
Set integers markers (aka "canary") associated with the environment.
LIBMDBX_API int mdbx_canary_get(const MDBX_txn *txn, MDBX_canary *canary)
Returns fours integers markers (aka "canary") associated with the environment.
MDBX_put_flags_t
Data changing flags.
Definition mdbx.h:1629
LIBMDBX_API int mdbx_replace_ex(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *new_data, MDBX_val *old_data, MDBX_put_flags_t flags, MDBX_preserve_func preserver, void *preserver_context)
Replaces item in a table using preservation callback for an original data.
LIBMDBX_API int mdbx_cursor_count(const MDBX_cursor *cursor, size_t *count)
Return count values (aka duplicates) for current key.
int(* MDBX_cmp_func)(const MDBX_val *a, const MDBX_val *b) noexcept
A callback function used to compare two keys in a table.
Definition mdbx.h:4721
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5182
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, const MDBX_val *data)
Delete items from a table.
LIBMDBX_API int mdbx_get_ex(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, size_t *values_count)
Get items from a table and optionally number of data items for a given key.
LIBMDBX_API int mdbx_cursor_scan_from(MDBX_cursor *cursor, MDBX_predicate_func predicate, void *context, MDBX_cursor_op from_op, MDBX_val *from_key, MDBX_val *from_value, MDBX_cursor_op turn_op, void *arg)
LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store by cursor.
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store items into a table.
LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del)
Empty or delete and close a table.
LIBMDBX_API int mdbx_cursor_get(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, MDBX_cursor_op op)
Retrieve by cursor.
LIBMDBX_API int mdbx_get(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data)
Get items from a table.
@ MDBX_MULTIPLE
Definition mdbx.h:1666
@ MDBX_ALLDUPS
Definition mdbx.h:1649
@ MDBX_CURRENT
Definition mdbx.h:1644
@ MDBX_APPENDDUP
Definition mdbx.h:1662
@ MDBX_APPEND
Definition mdbx.h:1657
@ MDBX_UPSERT
Definition mdbx.h:1631
@ MDBX_RESERVE
Definition mdbx.h:1653
@ MDBX_NOOVERWRITE
Definition mdbx.h:1634
LIBMDBX_API int mdbx_cursor_on_first_dup(const MDBX_cursor *cursor)
Determines whether the cursor is on the first or single multi-value corresponding to the key.
LIBMDBX_API int mdbx_cursor_open(MDBX_txn *txn, MDBX_dbi dbi, MDBX_cursor **cursor)
Create a cursor handle for the specified transaction and DBI handle.
LIBMDBX_API int mdbx_cursor_unbind(MDBX_cursor *cursor)
Unbind cursor from a transaction.
LIBMDBX_API MDBX_cursor * mdbx_cursor_create(void *context)
Create a cursor handle but not bind it to transaction nor DBI-handle.
LIBMDBX_API MDBX_dbi mdbx_cursor_dbi(const MDBX_cursor *cursor)
Return the cursor's table handle.
MDBX_cursor_op
Cursor operationsThis is the set of all operations for retrieving data using a cursor.
Definition mdbx.h:1710
LIBMDBX_API int mdbx_cursor_compare(const MDBX_cursor *left, const MDBX_cursor *right, bool ignore_multival)
Compares the position of the cursors.
LIBMDBX_API int mdbx_cursor_on_last_dup(const MDBX_cursor *cursor)
Determines whether the cursor is on the last or single multi-value corresponding to the key.
LIBMDBX_API int mdbx_cursor_on_first(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to the first key-value pair or not.
LIBMDBX_API int mdbx_cursor_bind(MDBX_txn *txn, MDBX_cursor *cursor, MDBX_dbi dbi)
Bind cursor to specified transaction and DBI-handle.
LIBMDBX_API int mdbx_txn_release_all_cursors_ex(const MDBX_txn *txn, bool unbind, size_t *count)
Unbind or closes all cursors of a given transaction and of all its parent transactions if ones are.
struct MDBX_cursor MDBX_cursor
Opaque structure for navigating through a table.
Definition mdbx.h:743
LIBMDBX_API int mdbx_cursor_set_userctx(MDBX_cursor *cursor, void *ctx)
Set application information associated with the cursor.
LIBMDBX_API int mdbx_cursor_eof(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to a key-value pair or not, i.e. was not positioned or point...
LIBMDBX_API int mdbx_cursor_close2(MDBX_cursor *cursor)
Closes a cursor handle with returning error code.
LIBMDBX_API void * mdbx_cursor_get_userctx(const MDBX_cursor *cursor)
Get the application information associated with the MDBX_cursor.
LIBMDBX_API int mdbx_cursor_renew(MDBX_txn *txn, MDBX_cursor *cursor)
Renew a cursor handle for use within the given transaction.
LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor)
Closes a cursor handle without returning error code.
LIBMDBX_API MDBX_txn * mdbx_cursor_txn(const MDBX_cursor *cursor)
Return the cursor's transaction handle.
LIBMDBX_API int mdbx_cursor_on_last(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to the last key-value pair or not.
LIBMDBX_API int mdbx_cursor_copy(const MDBX_cursor *src, MDBX_cursor *dest)
Copy cursor position and state.
@ MDBX_SEEK_AND_GET_MULTIPLE
Definition mdbx.h:1829
@ MDBX_GET_CURRENT
Definition mdbx.h:1725
@ MDBX_GET_BOTH
Definition mdbx.h:1718
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1806
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1722
@ MDBX_SET_KEY
Definition mdbx.h:1765
@ MDBX_FIRST_DUP
Definition mdbx.h:1715
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1805
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1730
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1816
@ MDBX_NEXT_NODUP
Definition mdbx.h:1750
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1813
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1814
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1821
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1773
@ MDBX_SET_RANGE
Definition mdbx.h:1768
@ MDBX_LAST_DUP
Definition mdbx.h:1736
@ MDBX_PREV
Definition mdbx.h:1753
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1823
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1824
@ MDBX_LAST
Definition mdbx.h:1733
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1804
@ MDBX_PREV_DUP
Definition mdbx.h:1756
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1812
@ MDBX_SET
Definition mdbx.h:1762
@ MDBX_NEXT
Definition mdbx.h:1739
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1807
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1820
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1747
@ MDBX_PREV_NODUP
Definition mdbx.h:1759
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1822
@ MDBX_NEXT_DUP
Definition mdbx.h:1742
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1815
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1808
@ MDBX_FIRST
Definition mdbx.h:1712
LIBMDBX_API int mdbx_dbi_rename(MDBX_txn *txn, MDBX_dbi dbi, const char *name)
Renames the table using the DBI descriptor.
LIBMDBX_API int mdbx_dbi_rename2(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *name)
Renames the table using the DBI descriptor.
LIBMDBX_API int mdbx_dbi_close(MDBX_env *env, MDBX_dbi dbi)
Close a table handle. Normally unnecessary.
LIBMDBX_API int mdbx_dbi_open(MDBX_txn *txn, const char *name, MDBX_db_flags_t flags, MDBX_dbi *dbi)
Open or Create a named table in the environment.
LIBMDBX_API int mdbx_dbi_open2(MDBX_txn *txn, const MDBX_val *name, MDBX_db_flags_t flags, MDBX_dbi *dbi)
Open or Create a named table in the environment.
uint32_t MDBX_dbi
A handle for an individual table (key-value spaces) in the environment.
Definition mdbx.h:736
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1579
@ MDBX_INTEGERDUP
Definition mdbx.h:1603
@ MDBX_DB_ACCEDE
Definition mdbx.h:1621
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1581
@ MDBX_REVERSEKEY
Definition mdbx.h:1584
@ MDBX_DUPFIXED
Definition mdbx.h:1598
@ MDBX_INTEGERKEY
Definition mdbx.h:1594
@ MDBX_REVERSEDUP
Definition mdbx.h:1606
@ MDBX_CREATE
Definition mdbx.h:1609
@ MDBX_DUPSORT
Definition mdbx.h:1587
MDBX_log_level_t
Definition mdbx.h:856
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:915
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1837
LIBMDBX_API int mdbx_env_set_hsr(MDBX_env *env, MDBX_hsr_func hsr_callback)
Sets a Handle-Slow-Readers callback to resolve database full/overflow issue due to a reader(s) which ...
int(* MDBX_hsr_func)(const MDBX_env *env, const MDBX_txn *txn, mdbx_pid_t pid, mdbx_tid_t tid, uint64_t laggard, unsigned gap, size_t space, int retry) noexcept
A Handle-Slow-Readers callback function to resolve database full/overflow issue due to a reader(s) wh...
Definition mdbx.h:6752
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1851
@ MDBX_BAD_TXN
Definition mdbx.h:1914
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1928
@ MDBX_SUCCESS
Definition mdbx.h:1839
@ MDBX_NOTFOUND
Definition mdbx.h:1854
@ MDBX_RESULT_TRUE
Definition mdbx.h:1845
@ MDBX_BUSY
Definition mdbx.h:1932
@ MDBX_EINVAL
Definition mdbx.h:2008
@ MDBX_ENOMEM
Definition mdbx.h:2010
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1935
@ MDBX_RESULT_FALSE
Definition mdbx.h:1842
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:1987
@ MDBX_KEYEXIST
Definition mdbx.h:1848
LIBMDBX_API int mdbx_reader_check(MDBX_env *env, int *dead)
Check for stale entries in the reader lock table.
LIBMDBX_API int mdbx_env_sync_ex(MDBX_env *env, bool force, bool nonblock)
Flush the environment data buffers to disk.
@ MDBX_ENV_WAIT_FOR_UNUSED
Wait until other processes closes the environment before deletion.
Definition mdbx.h:2530
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2525
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2528
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1038
@ MDBX_WRITEMAP
Definition mdbx.h:1158
@ MDBX_EXCLUSIVE
Definition mdbx.h:1112
@ MDBX_RDONLY
Definition mdbx.h:1082
LIBMDBX_API int mdbx_estimate_distance(const MDBX_cursor *first, const MDBX_cursor *last, ptrdiff_t *distance_items)
Estimates the distance between cursors as a number of elements.
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 move distance.
LIBMDBX_API int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *begin_key, const MDBX_val *begin_data, const MDBX_val *end_key, const MDBX_val *end_data, ptrdiff_t *distance_items)
Estimates the size of a range as a number of elements.
LIBMDBX_API int mdbx_env_get_option(const MDBX_env *env, const MDBX_option_t option, uint64_t *pvalue)
Gets the value of extra runtime options from an environment.
int mdbx_env_set_syncperiod(MDBX_env *env, unsigned seconds_16dot16)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
Definition mdbx.h:3041
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2118
LIBMDBX_API int mdbx_env_set_geometry(MDBX_env *env, intptr_t size_lower, intptr_t size_now, intptr_t size_upper, intptr_t growth_step, intptr_t shrink_threshold, intptr_t pagesize)
Set all size-related parameters of environment, including page size and the min/max size of the memor...
int mdbx_env_set_syncbytes(MDBX_env *env, size_t threshold)
Sets threshold to force flush the data buffers to disk, even any of MDBX_SAFE_NOSYNC flag in the envi...
Definition mdbx.h:2980
LIBMDBX_API int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option, uint64_t value)
Sets the value of a extra runtime options for an environment.
LIBMDBX_API int mdbx_env_set_userctx(MDBX_env *env, void *ctx)
Sets application information (a context pointer) associated with the environment.
LIBMDBX_API int mdbx_env_set_flags(MDBX_env *env, MDBX_env_flags_t flags, bool onoff)
Set environment flags.
@ MDBX_opt_txn_dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h:2223
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2219
@ MDBX_opt_prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h:2323
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2127
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2290
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2150
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2255
@ MDBX_opt_spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h:2278
@ MDBX_opt_loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h:2190
@ MDBX_opt_rp_augment_limit
Controls the in-process limit to grow a list of reclaimed/recycled page's numbers for finding a seque...
Definition mdbx.h:2177
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2144
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2239
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2156
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2204
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2318
LIBMDBX_API int mdbx_dbi_stat(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_stat *stat, size_t bytes)
Retrieve statistics for a table.
LIBMDBX_API uint64_t mdbx_txn_id(const MDBX_txn *txn)
Return the transaction's ID.
LIBMDBX_API intptr_t mdbx_limits_valsize_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal data size in bytes for given page size and table flags, or -1 if pagesize is invalid.
LIBMDBX_API int mdbx_env_info_ex(const MDBX_env *env, const MDBX_txn *txn, MDBX_envinfo *info, size_t bytes)
Return information about the MDBX environment.
int mdbx_env_get_maxreaders(const MDBX_env *env, unsigned *readers)
Get the maximum number of threads/reader slots for the environment.
Definition mdbx.h:3658
int mdbx_env_get_syncperiod(const MDBX_env *env, unsigned *period_seconds_16dot16)
Get relative period since the last unsteady commit to force flush the data buffers to disk,...
Definition mdbx.h:3061
LIBMDBX_API int mdbx_env_get_maxkeysize_ex(const MDBX_env *env, MDBX_db_flags_t flags)
Returns the maximum size of keys can put.
LIBMDBX_API int mdbx_env_get_maxvalsize_ex(const MDBX_env *env, MDBX_db_flags_t flags)
Returns the maximum size of data we can put.
LIBMDBX_API int mdbx_env_stat_ex(const MDBX_env *env, const MDBX_txn *txn, MDBX_stat *stat, size_t bytes)
Return statistics about the MDBX environment.
LIBMDBX_API int mdbx_env_get_pairsize4page_max(const MDBX_env *env, MDBX_db_flags_t flags)
Returns maximal size of key-value pair to fit in a single page for specified table flags.
int mdbx_env_get_syncbytes(const MDBX_env *env, size_t *threshold)
Get threshold to force flush the data buffers to disk, even any of MDBX_SAFE_NOSYNC flag in the envir...
Definition mdbx.h:2998
LIBMDBX_API intptr_t mdbx_limits_valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal data size in bytes to fit in a leaf-page or single large/overflow-page with the given...
LIBMDBX_API intptr_t mdbx_limits_txnsize_max(intptr_t pagesize)
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes for gi...
LIBMDBX_API int mdbx_dbi_dupsort_depthmask(const MDBX_txn *txn, MDBX_dbi dbi, uint32_t *mask)
Retrieve depth (bitmask) information of nested dupsort (multi-value) B+trees for given table.
LIBMDBX_API int mdbx_txn_info(const MDBX_txn *txn, MDBX_txn_info *info, bool scan_rlt)
Return information about the MDBX transaction.
LIBMDBX_API int mdbx_is_dirty(const MDBX_txn *txn, const void *ptr)
Determines whether the given address is on a dirty database page of the transaction or not.
MDBX_dbi_state_t
DBI state bits returted by mdbx_dbi_flags_ex()
Definition mdbx.h:4983
LIBMDBX_API int mdbx_env_get_valsize4page_max(const MDBX_env *env, MDBX_db_flags_t flags)
Returns maximal data size in bytes to fit in a leaf-page or single large/overflow-page for specified ...
LIBMDBX_API int mdbx_env_get_fd(const MDBX_env *env, mdbx_filehandle_t *fd)
Return the file descriptor for the given environment.
LIBMDBX_API void * mdbx_env_get_userctx(const MDBX_env *env)
Returns an application information (a context pointer) associated with the environment.
int mdbx_env_get_maxdbs(const MDBX_env *env, MDBX_dbi *dbs)
Get the maximum number of named tables for the environment.
Definition mdbx.h:3703
LIBMDBX_API intptr_t mdbx_limits_keysize_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal key size in bytes for given page size and table flags, or -1 if pagesize is invalid.
LIBMDBX_API intptr_t mdbx_limits_pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal size of key-value pair to fit in a single page with the given size and table flags,...
LIBMDBX_API intptr_t mdbx_limits_dbsize_max(intptr_t pagesize)
Returns maximal database size in bytes for given page size, or -1 if pagesize is invalid.
LIBMDBX_API intptr_t mdbx_limits_dbsize_min(intptr_t pagesize)
Returns minimal database size in bytes for given page size, or -1 if pagesize is invalid.
LIBMDBX_API int mdbx_env_get_flags(const MDBX_env *env, unsigned *flags)
Get environment flags.
LIBMDBX_API int mdbx_dbi_flags_ex(const MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags, unsigned *state)
Retrieve the DB flags and status for a table handle.
LIBMDBX_API int mdbx_reader_list(const MDBX_env *env, MDBX_reader_list_func func, void *ctx)
Enumerate the entries in the reader lock table.
LIBMDBX_API int mdbx_txn_break(MDBX_txn *txn)
Marks transaction as broken to prevent further operations.
LIBMDBX_API int mdbx_txn_set_userctx(MDBX_txn *txn, void *ctx)
Sets application information associated (a context pointer) with the transaction.
LIBMDBX_API int mdbx_txn_clone(const MDBX_txn *origin, MDBX_txn **in_out_clone, void *context)
Starts a read-only clone of a given transaction.
LIBMDBX_API int mdbx_txn_park(MDBX_txn *txn, bool autounpark)
Puts the reading transaction in a "parked" state.
LIBMDBX_API int mdbx_txn_unpark(MDBX_txn *txn, bool restart_if_ousted)
Unparks a previously parked reading transaction.
MDBX_txn_flags_t
Definition mdbx.h:1478
LIBMDBX_API void * mdbx_txn_get_userctx(const MDBX_txn *txn)
Returns an application information (a context pointer) associated with the transaction.
int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, MDBX_txn_flags_t flags, MDBX_txn **txn)
Create a transaction for use with the environment.
Definition mdbx.h:3919
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:724
LIBMDBX_API int mdbx_txn_reset(MDBX_txn *txn)
Reset a read-only transaction.
LIBMDBX_API int mdbx_txn_renew(MDBX_txn *txn)
Renew a read-only transaction.
LIBMDBX_API MDBX_txn_flags_t mdbx_txn_flags(const MDBX_txn *txn)
Return the transaction's flags.
@ MDBX_TXN_RDONLY
Definition mdbx.h:1489
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1498
@ MDBX_TXN_READWRITE
Definition mdbx.h:1483
@ MDBX_TXN_TRY
Definition mdbx.h:1504
void commit(finalization_latency &latency)
ommits all changes of the transaction into a database with collecting latencies information.
Definition mdbx.h++:4091
friend class env
Definition mdbx.h++:4048
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:3734
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4548
~txn_managed() noexcept
::MDBX_stat map_stat
Definition mdbx.h++:3900
bool drop_map(const slice &name, bool throw_if_absent=false)
Drop key-value map.
txn & operator=(const txn &) noexcept=default
env & set_sync_period(const duration &period)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
bool amend(bool dont_wait=false)
Starts a writing transaction to amending data in the MVCC-snapshot used by the read-only transaction.
txn_managed start_nested()
Start nested write transaction.
extra_runtime_option
MDBX environment extra runtime options.
Definition mdbx.h++:3441
@ prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h++:3475
@ spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h++:3467
@ spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h++:3469
@ writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h++:3473
@ sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h++:3450
@ dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h++:3461
@ dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h++:3463
@ spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h++:3465
@ merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h++:3471
@ rp_augment_limit
Controls the in-process limit to grow a list of reclaimed/recycled page's numbers for finding a seque...
Definition mdbx.h++:3455
@ loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h++:3457
@ dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h++:3459
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3668
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3881
env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede=true)
map_handle(const map_handle &) noexcept=default
::MDBX_db_flags_t flags
Definition mdbx.h++:2940
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4393
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4449
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2909
durability
Durability level.
Definition mdbx.h++:3086
@ lazy_weak_tail
Definition mdbx.h++:3089
@ robust_synchronous
Definition mdbx.h++:3087
@ whole_fragile
Definition mdbx.h++:3090
@ half_synchronous_weak_last
Definition mdbx.h++:3088
void commit_embark_read()
Commits all the operations of a transaction into the database and then start read transaction.
friend constexpr bool operator!=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2936
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3256
map_handle & operator=(const map_handle &) noexcept=default
duration sync_period() const
Gets relative period since the last unsteady commit that used to force flush the data buffers to disk...
move_result seek_multiple_samelength(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4437
bool checkpoint(finalization_latency &latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4105
estimate_result estimate(move_operation operation, slice &key) const
cache_entry() noexcept
Definition mdbx.h++:2770
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3691
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4412
::MDBX_canary canary
Definition mdbx.h++:3909
std::pair< bool, finalization_latency > checkpoint_get_latency()
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4108
env & copy(const wchar_t *destination, bool compactify, bool force_dynamic_size=false)
bool is_readwrite() const
Checks whether the transaction is read-write.
Definition mdbx.h++:3732
void commit_embark_read(finalization_latency *latency)
Commits all the operations of a transaction into the database and then start read transaction.
map_handle open_map_accede(const ::std::string_view &name) const
Open existing key-value map.
move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound)
Definition mdbx.h++:4342
void update_current(const slice &value)
Updates value associated with a key at the current cursor position.
env_managed(const wchar_t *pathname, const operate_parameters &, bool accede=true)
move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4406
bool clear_map(const char *name, bool throw_if_absent=false)
constexpr env() noexcept=default
friend constexpr bool operator!=(const env &a, const env &b) noexcept
Definition mdbx.h++:5273
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4415
void rename_map(map_handle map, const ::std::string_view &new_name)
Переименовывает таблицу ключ-значение.
env & copy(filehandle fd, bool compactify, bool force_dynamic_size=false)
Copy an environment to the specified file descriptor.
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
void reset() noexcept
Definition mdbx.h++:2777
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2930
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2910
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4501
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4360
env & copy(const char *destination, bool compactify, bool force_dynamic_size=false)
move_result to_previous_last_multi(bool throw_notfound=true)
Definition mdbx.h++:4351
static bool remove(const ::mdbx::filesystem::path &pathname, const remove_mode mode=just_remove)
Removes the environment's files in a proper and multiprocess-safe way.
bool drop_map(const char *name, bool throw_if_absent=false)
Drops key-value map using name.
cursor & operator=(const cursor &) noexcept=default
bool is_same_or_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4177
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3788
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3964
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4383
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4169
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4173
env_managed & operator=(const env_managed &)=delete
map_handle create_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single)
Create new or open existing key-value map.
Definition mdbx.h++:3873
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3183
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4367
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4570
MDBX_txn * handle_
Definition mdbx.h++:3692
void abort()
Abandon all the operations of the transaction instead of saving ones.
MDBX_commit_latency finalization_latency
Definition mdbx.h++:4070
const path_char * get_path() const
Return the path that was used for opening the environment.
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4339
mode
Operation mode.
Definition mdbx.h++:3078
@ write_mapped_io
Definition mdbx.h++:3081
@ nested_transactions
Definition mdbx.h++:3082
@ readonly
Definition mdbx.h++:3079
@ write_file_io
Definition mdbx.h++:3080
bool is_writemap() const
Definition mdbx.h++:3349
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4336
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4295
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3317
operator::mdbx::txn() const
Definition mdbx.h++:4478
MDBX_env * handle_
Definition mdbx.h++:2979
slice reverse_current(size_t value_length)
Reserves and returns the space to storing a value associated with a key at the current cursor positio...
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4399
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4165
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4349
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4369
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:2773
bool is_nested_transactions_available() const
Definition mdbx.h++:3353
void close()
Explicitly closes the cursor.
Definition mdbx.h++:4554
void abort(finalization_latency &latency)
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4077
bool is_pristine() const
Returns true for a freshly created database, but false if at least one transaction was committed.
move_result to_key_exact(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4380
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3729
constexpr txn_managed() noexcept=default
bool clear_map(const slice &name, bool throw_if_absent=false)
move_result next_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4445
env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede=true)
void append(map_handle map, const pair &kv, bool multivalue_order_preserved=true)
Definition mdbx.h++:4012
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3287
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3297
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3299
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3294
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4271
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4354
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4316
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4560
::MDBX_dbi_state_t state
Definition mdbx.h++:2941
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3498
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4528
cursor_managed(cursor_managed &&)=default
static bool remove(const wchar_t *pathname, const remove_mode mode=just_remove)
size_t key_max(key_mode mode) const
Returns the maximal key size in bytes for specified keys mode.
Definition mdbx.h++:3262
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4409
env & copy(const ::mdbx::filesystem::path &destination, bool compactify, bool force_dynamic_size=false)
Make a copy (backup) of an existing environment to the specified path.
move_result get_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4441
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4371
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4368
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4479
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3258
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2933
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3785
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2924
void commit()
Commits all changes of the transaction into a database with collecting latencies information.
move_result to_key_greater_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4386
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3323
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3961
env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
friend int compare_position(const cursor &left, const cursor &right, bool ignore_nested)
Definition mdbx.h++:6183
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4028
bool checkpoint()
Commits all the operations of the transaction and immediately starts next without releasing any locks...
env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &, bool accede=true)
size_t transaction_size_max() const
Returns the maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3269
map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single) const
Open existing key-value map.
Definition mdbx.h++:3866
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2921
bool checkpoint(finalization_latency *latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
void commit_embark_read(finalization_latency &latency)
Commits all the operations of a transaction into the database and then start read transaction.
Definition mdbx.h++:4119
size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count, put_mode mode, bool allow_partial=false)
Definition mdbx.h++:4020
finalization_latency commit_embark_read_get_latency()
Commits all the operations of a transaction into the database and then start read transaction.
Definition mdbx.h++:4122
void commit(finalization_latency *)
Commits all changes of the transaction into a database with collecting latencies information.
friend constexpr bool operator>(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2927
bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
bool is_empty() const
Checks whether the database is empty.
void close(bool dont_sync=false)
Explicitly closes the environment and release the memory map.
move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4421
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4187
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4202
@ multi_exactkey_value_equal
Definition mdbx.h++:4219
@ pair_greater_or_equal
Definition mdbx.h++:4227
@ key_lesser_than
Definition mdbx.h++:4209
@ next
Definition mdbx.h++:4190
@ pair_exact
Definition mdbx.h++:4226
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4220
@ pair_lesser_or_equal
Definition mdbx.h++:4224
@ batch_samelength
Definition mdbx.h++:4230
@ seek_key
Definition mdbx.h++:4204
@ key_lowerbound
Definition mdbx.h++:4206
@ pair_lesser_than
Definition mdbx.h++:4223
@ pair_equal
Definition mdbx.h++:4225
@ key_greater_than
Definition mdbx.h++:4213
@ batch_samelength_next
Definition mdbx.h++:4231
@ multi_find_pair
Definition mdbx.h++:4201
@ key_greater_or_equal
Definition mdbx.h++:4212
@ key_exact
Definition mdbx.h++:4205
@ key_equal
Definition mdbx.h++:4211
@ multi_currentkey_prevvalue
Definition mdbx.h++:4196
@ key_lesser_or_equal
Definition mdbx.h++:4210
@ multi_nextkey_firstvalue
Definition mdbx.h++:4199
@ get_current
Definition mdbx.h++:4192
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4218
@ multi_prevkey_lastvalue
Definition mdbx.h++:4194
@ previous
Definition mdbx.h++:4191
@ last
Definition mdbx.h++:4189
@ pair_greater_than
Definition mdbx.h++:4228
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4217
@ multi_currentkey_firstvalue
Definition mdbx.h++:4195
@ first
Definition mdbx.h++:4188
@ batch_samelength_previous
Definition mdbx.h++:4232
@ multi_currentkey_nextvalue
Definition mdbx.h++:4197
@ seek_and_batch_samelength
Definition mdbx.h++:4233
@ multi_exactkey_value_greater
Definition mdbx.h++:4221
@ multi_currentkey_lastvalue
Definition mdbx.h++:4198
virtual ~env_managed() noexcept
finalization_latency commit_get_latency()
Commits all changes of the transaction into a database and return latency information.
Definition mdbx.h++:4094
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4345
void insert(const pair &kv)
Definition mdbx.h++:4502
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3726
cursor_managed(const cursor_managed &)=delete
env & operator=(const env &) noexcept=default
env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
void upsert(const pair &kv)
Definition mdbx.h++:4504
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4357
txn_managed & operator=(const txn_managed &)=delete
bool is_cooperative() const
Definition mdbx.h++:3347
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3886
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:5271
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4396
bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
env_managed(const env_managed &)=delete
move_result to_current_last_multi(bool throw_notfound=true)
Definition mdbx.h++:4364
bool is_readonly() const
Definition mdbx.h++:3343
value_result try_insert(const pair &kv)
Definition mdbx.h++:4503
size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode, bool allow_partial=false)
Definition mdbx.h++:4520
constexpr cursor() noexcept=default
bool is_exclusive() const
Definition mdbx.h++:3345
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4374
finalization_latency abort_get_latency()
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4080
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4418
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3266
MDBX_cursor * handle_
Definition mdbx.h++:4141
~cursor_managed() noexcept
Definition mdbx.h++:4578
bool is_readwite() const
Definition mdbx.h++:3351
MDBX_dbi dbi
Definition mdbx.h++:2908
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4390
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4361
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3740
env & copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size=false)
move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4402
txn_managed(const txn_managed &)=delete
friend int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept
Definition mdbx.h++:6179
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3314
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3264
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3963
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3962
env_managed(const ::mdbx::filesystem::path &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
Create new or open existing database.
txn_managed start_nested(bool readonly)
Start nested transaction.
cache_entry & operator=(const cache_entry &) noexcept=default
bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:3894
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4377
bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
move_result to_previous(bool throw_notfound=true)
Definition mdbx.h++:4350
friend class txn
Definition mdbx.h++:2976
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4161
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3260
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3743
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4290
Unmanaged cursor.
Definition mdbx.h++:4139
Managed cursor.
Definition mdbx.h++:4540
Unmanaged database environment.
Definition mdbx.h++:2975
Managed database environment.
Definition mdbx.h++:3607
Unmanaged database transaction.
Definition mdbx.h++:3689
Managed database transaction.
Definition mdbx.h++:4046
static size_t key_min(MDBX_db_flags_t flags) noexcept
Returns the minimal key size in bytes for specified table flags.
Definition mdbx.h++:5314
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5178
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4848
polymorphic_allocator default_allocator
Definition mdbx.h++:397
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4857
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4939
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base58(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base58 dump of the slice content.
Definition mdbx.h++:5152
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base58 dump of a passed slice.
Definition mdbx.h++:5090
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5081
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5663
static size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns the maximal value size in bytes for specified page size and table flags.
Definition mdbx.h++:5342
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4953
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4678
void replace(map_handle map, const slice &key, slice old_value, const slice &new_value)
Replaces the particular multi-value of the key with a new value.
Definition mdbx.h++:6055
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6290
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2822
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4835
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:4635
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4933
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5696
class MDBX_MSVC_DECLSPEC_EMPTY_BASES buffer
Definition mdbx.h++:405
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:4825
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4713
void rethrow_captured() const
Definition mdbx.h++:4650
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4833
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6248
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6224
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5307
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5281
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base64 dump of a passed slice.
Definition mdbx.h++:5099
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6018
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5972
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5561
env & set_sync_threshold(size_t bytes)
Sets threshold to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5492
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6192
string< ALLOCATOR > as_hex_string(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of the slice content.
Definition mdbx.h++:5131
::mdbx::filesystem::path::string_type path_string
Definition mdbx.h++:445
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4855
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6128
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base64(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base64 dump of the slice content.
Definition mdbx.h++:5157
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4880
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4781
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6296
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:466
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5965
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6140
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5793
void throw_on_failure() const
Definition mdbx.h++:4690
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6371
void update(const slice &key, const slice &value)
Definition mdbx.h++:6367
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:4632
int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept
Compare two keys according to a particular key-value map (aka table).
Definition mdbx.h++:5864
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:5002
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4843
::MDBX_cmp_func comparator
Definition mdbx.h++:2953
buffer< ALLOCATOR, CAPACITY_POLICY > encode_hex(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:5146
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5665
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5628
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6179
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4979
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5425
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5852
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6357
bool is_clean() const noexcept
Definition mdbx.h++:4643
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2815
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4733
string< ALLOCATOR > as_base58_string(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:5136
path_string::value_type path_char
Definition mdbx.h++:453
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5415
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2819
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:418
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:5467
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5300
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4923
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4657
buffer< ALLOCATOR, CAPACITY_POLICY > hex_decode(bool ignore_spaces=false, const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:5162
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4586
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5033
buffer< ALLOCATOR, CAPACITY_POLICY > replace_reserve(map_handle map, const slice &key, slice &new_value, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &alloc=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Definition mdbx.h++:6083
env & set_HandleSlowReaders(MDBX_hsr_func)
Sets a Handle-Slow-Readers callback to resolve database full/overflow issue due to a reader(s) which ...
Definition mdbx.h++:5599
constexpr reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used, size_t retained) noexcept
Definition mdbx.h++:5564
void insert(const slice &key, slice value)
Definition mdbx.h++:6318
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6252
map_handle open_map(const char *name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single) const
Open existing key-value map.
Definition mdbx.h++:5748
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:5227
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:396
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:2803
buffer< ALLOCATOR, CAPACITY_POLICY > base64_decode(bool ignore_spaces=false, const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:5172
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4765
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:6142
~cursor() noexcept
Definition mdbx.h++:6163
~txn() noexcept
Definition mdbx.h++:5647
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5497
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:5126
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6244
uint64_t txnid
Transaction ID and MVCC-snapshot number.
Definition mdbx.h++:414
constexpr void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition mdbx.h++:4861
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6298
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6343
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5292
map_handle map() const
Definition mdbx.h++:6303
unsigned sync_period__seconds_16dot16() const
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h++:5508
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:4639
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6236
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5764
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6256
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2883
void success_or_throw() const
Definition mdbx.h++:4695
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5700
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4895
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5548
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4983
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6183
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6262
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4891
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5298
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4900
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5670
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6361
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5423
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2811
void capture() noexcept
Definition mdbx.h++:4645
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:5108
uint32_t get_tree_deepmask(map_handle map) const
Returns depth (bitmask) information of nested dupsort (multi-value) B+trees for given table.
Definition mdbx.h++:5829
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6000
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4874
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2954
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6336
MDBX_hsr_func get_HandleSlowReaders() const noexcept
Returns the current Handle-Slow-Readers callback used to resolve database full/overflow issue due to ...
Definition mdbx.h++:5604
static size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal size of key-value pair to fit in a single page for specified size and table flags.
Definition mdbx.h++:5362
env & set_sync_period__seconds_16dot16(unsigned seconds_16dot16)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
Definition mdbx.h++:5503
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:6116
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5429
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5789
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6134
void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved=true)
Adding a key-value pair, provided that ascending order of the keys and (optionally) values are preser...
Definition mdbx.h++:6092
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5433
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5715
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4987
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6150
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5823
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6202
static size_t value_min(MDBX_db_flags_t flags) noexcept
Returns the minimal values size in bytes for specified table flags.
Definition mdbx.h++:5338
int compare_values(map_handle map, const slice &a, const slice &b) const noexcept
Compare two values according to a particular key-value map (aka table).
Definition mdbx.h++:5868
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5288
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5841
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5990
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4918
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4672
env & set_sync_period__seconds_double(double seconds)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
Definition mdbx.h++:5514
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4945
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4817
bool on_first() const
Definition mdbx.h++:6270
::MDBX_version_info version_info
libmdbx version information,
Definition mdbx.h++:361
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:4853
bool eof() const
Definition mdbx.h++:6268
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5698
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5684
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5485
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6310
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5613
::MDBX_build_info build_info
libmdbx build information
Definition mdbx.h++:365
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:5121
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5637
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4885
bool seek(const slice &key)
Definition mdbx.h++:6260
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5537
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5487
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4907
static size_t transaction_size_max(intptr_t pagesize)
Returns the maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes fo...
Definition mdbx.h++:5406
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5791
env & set_extra_option(extra_runtime_option option, uint64_t value)
Sets the value of a extra runtime options for an environment.
Definition mdbx.h++:5526
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5243
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4868
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6323
size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array, size_t values_count, put_mode mode, bool allow_partial=false)
Definition mdbx.h++:6424
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4718
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4666
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5682
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2962
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5183
buffer< ALLOCATOR, CAPACITY_POLICY > base58_decode(bool ignore_spaces=false, const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:5167
double sync_period__seconds_double() const
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h++:5518
::mdbx_filehandle_t filehandle
Definition mdbx.h++:420
static size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal data size in bytes to fit in a leaf-page or single large/overflow-page for specified ...
Definition mdbx.h++:5384
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5249
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4975
char8_t byte
The byte-like type that don't presumes aliases for pointers as does the char.
Definition mdbx.h++:346
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5846
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6402
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5437
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5076
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5690
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5952
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:379
constexpr bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition mdbx.h++:4680
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:5103
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:5085
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6230
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4960
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:5094
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:5112
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6012
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5239
~env() noexcept
Definition mdbx.h++:5259
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2784
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5880
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4674
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4863
size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length, const void *values_array, size_t values_count, put_mode mode, bool allow_partial=false)
Definition mdbx.h++:6097
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5996
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4912
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2787
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5606
::mdbx::filesystem::path path
Definition mdbx.h++:444
bool on_last_multival() const
Definition mdbx.h++:6276
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5479
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5947
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5473
static size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns the maximal key size in bytes for specified page size and table flags.
Definition mdbx.h++:5318
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5569
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6148
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5413
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5727
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2807
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5717
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5531
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4587
bool on_first_multival() const
Definition mdbx.h++:6274
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5939
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4708
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:5015
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4928
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5449
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5986
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5296
string< ALLOCATOR > as_base64_string(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:5141
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6383
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:5702
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6240
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4819
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4841
buffer_pair_spec< typename BUFFER::allocator_type, typename BUFFER::reservation_policy > buffer_pair
Combines pair of buffers for key and value to hold an operands for certain operations.
Definition mdbx.h++:5224
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5592
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:6031
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4670
bool on_last() const
Definition mdbx.h++:6272
buffer< ALLOCATOR, CAPACITY_POLICY > extract(map_handle map, const slice &key, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &alloc=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Removes and return a value of the key.
Definition mdbx.h++:6062
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:440
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:5461
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5542
void bind(::mdbx::txn &txn, ::mdbx::map_handle map_handle)
Bind/renew a cursor with a new transaction and specified key-value map handle.
Definition mdbx.h++:6292
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:5117
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5275
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5733
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4664
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5055
constexpr bool is_success() const noexcept
Definition mdbx.h++:4668
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6389
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:5028
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5635
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5235
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5721
map_handle create_map(const char *name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single)
Create new or open existing key-value map.
Definition mdbx.h++:5780
pair_result get_equal_or_great(map_handle map, const slice &key) const
Get value for equal or great key from a table.
Definition mdbx.h++:5918
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5835
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4827
@ multi_reverse_samelength
Definition mdbx.h++:2855
@ multi_samelength
Definition mdbx.h++:2840
@ multi_ordinal
Definition mdbx.h++:2847
@ msgpack
Definition mdbx.h++:2870
@ single
Definition mdbx.h++:2823
@ multi
Definition mdbx.h++:2825
@ multi_reverse
Definition mdbx.h++:2832
@ upsert
Insert or update.
Definition mdbx.h++:2964
@ update
Update existing, don't insert new.
Definition mdbx.h++:2965
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2963
@ continue_loop
Definition mdbx.h++:2784
@ exit_loop
Definition mdbx.h++:2784
@ usual
Definition mdbx.h++:2788
@ ordinal
Definition mdbx.h++:2793
@ reverse
Definition mdbx.h++:2790
@ msgpack
Definition mdbx.h++:2798
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2907
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2418
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2131
constexpr bool is_reference() const noexcept
Checks whether the buffer just refers to data located outside the buffer, rather than stores it.
Definition mdbx.h++:2009
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2036
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:706
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2101
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1991
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:719
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:682
static buffer base64_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:2273
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2314
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:673
buffer_pair_spec(const txn &transacton, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2704
const slice source
Definition mdbx.h++:1264
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base58 dump, and therefore there could be dec...
static buffer key_from(const double *ieee754_64bit)
Definition mdbx.h++:2639
static buffer hex(const POD &pod, bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a hexadecimal dump of the given pod.
Definition mdbx.h++:2222
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:741
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:2052
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2345
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2049
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2427
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2297
constexpr size_t tailroom() const noexcept
Returns the number of bytes that available in currently allocated storage after the currently data en...
Definition mdbx.h++:2024
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2158
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2398
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2311
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2043
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2163
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2671
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1567
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1037
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1241
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2349
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2076
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2528
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2072
buffer & append(const byte c)
Definition mdbx.h++:2482
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2322
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:759
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1018
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2327
buffer & operator=(const buffer &src)
Definition mdbx.h++:2444
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1036
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2550
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:2018
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2713
constexpr int64_t as_int64() const
Definition mdbx.h++:1043
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2069
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2629
static buffer hex(const slice &source, bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:2204
const bool ignore_spaces
Definition mdbx.h++:1344
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:863
buffer base58_decode(bool ignore_spaces=false, const allocator_type &alloc=allocator_type()) const
Decodes Base58 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2286
buffer hex_decode(bool ignore_spaces=false, const allocator_type &alloc=allocator_type()) const
Decodes hexadecimal dump from the buffer content to new returned buffer.
Definition mdbx.h++:2280
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2199
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2492
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2242
bool is_printable(bool disable_utf8=false) const noexcept
Checks whether the content of the slice is printable.
int128_t as_int128_adapt() const
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from Base64 dump from a passed slice.
pair & operator=(stl_pair &&couple)
Definition mdbx.h++:1106
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Definition mdbx.h++:776
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2682
constexpr int16_t as_int16() const
Definition mdbx.h++:1045
slice value
Definition mdbx.h++:1070
::std::ostream & output(::std::ostream &out) const
Output Base64 dump of passed slice to the std::ostream.
buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2684
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2423
static buffer base58_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:2266
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2649
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1212
buffer base64_decode(bool ignore_spaces=false, const allocator_type &alloc=allocator_type()) const
Decodes Base64 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2292
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2196
slice value
Definition mdbx.h++:1084
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2675
::std::ostream & output(::std::ostream &out) const
Output hexadecimal dump of passed slice to the std::ostream.
pair_result(const pair_result &) noexcept=default
allocation_aware_details::swap_alloc< struct silo, allocator_type > swap_alloc
Definition mdbx.h++:1986
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2655
const slice source
Definition mdbx.h++:1343
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2693
const slice source
Definition mdbx.h++:1179
static buffer base58(const POD &pod, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base58 dump of the given pod.
Definition mdbx.h++:2230
constexpr buffer & assign(buffer &&src) noexcept(allocation_aware_details::move_assign_alloc< silo, allocator_type >::is_nothrow())
Definition mdbx.h++:2386
constexpr size_t envisage_result_length() const noexcept
Returns the number of bytes needed for conversion hexadecimal dump from a passed slice to decoded dat...
Definition mdbx.h++:1326
const unsigned wrap_width
Definition mdbx.h++:1181
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2453
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2635
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:733
const slice & slice() const noexcept
Definition mdbx.h++:2667
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2406
const bool ignore_spaces
Definition mdbx.h++:1310
constexpr POD as_pod() const
Definition mdbx.h++:1020
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from Base58 dump from a passed slice.
constexpr pair_result() noexcept
Definition mdbx.h++:1133
pair & operator=(const pair &) noexcept=default
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1410
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2688
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2394
constexpr buffer(const buffer &src)
Definition mdbx.h++:2141
static buffer hex_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:2259
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1033
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2467
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2089
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2641
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2337
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1182
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2690
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2524
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2621
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1532
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2174
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:755
std::pair< slice, slice > stl_pair
Definition mdbx.h++:1083
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2548
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:2003
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
@ pettiness_threshold
Definition mdbx.h++:1520
@ extra_inplace_storage
Definition mdbx.h++:1518
@ max_reserve
Definition mdbx.h++:1521
@ inplace_storage_size_rounding
Definition mdbx.h++:1519
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2653
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:696
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1345
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2448
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2520
constexpr int8_t as_int8() const
Definition mdbx.h++:1046
constexpr ::std::span< char > chars()
Definition mdbx.h++:708
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1065
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1283
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2126
buffer(const txn &transaction, const slice &src, const allocator_type &alloc=allocator_type())
static constexpr size_t round(const size_t value)
Definition mdbx.h++:1524
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1255
constexpr size_t envisage_result_length() const noexcept
Returns the number of bytes needed for conversion Base64 dump from a passed slice to decoded data.
Definition mdbx.h++:1401
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:1072
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2633
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1372
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2254
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2169
const slice source
Definition mdbx.h++:1222
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:1086
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2412
constexpr bool is_freestanding() const noexcept
Checks whether data chunk stored inside the buffer, otherwise buffer just refers to data located outs...
Definition mdbx.h++:1995
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2657
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:707
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1384
buffer_pair_spec & operator=(buffer_pair_spec &&src)
Definition mdbx.h++:2717
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2583
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid data and could be encoded or unexpectedly not...
Definition mdbx.h++:1216
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1568
uint8_t as_uint8_adapt() const
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:687
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2647
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2120
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2450
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2733
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2500
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2571
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2532
constexpr size_t envisage_result_length() const noexcept
Returns the number of bytes needed for conversion Base58 dump from a passed slice to decoded data.
Definition mdbx.h++:1362
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:738
constexpr ::std::basic_string_view< CHAR, T > string_view() const noexcept
Return a string_view that references the same data as this slice.
Definition mdbx.h++:763
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1333
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:652
static buffer base64(const POD &pod, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base64 dump of the given pod.
Definition mdbx.h++:2237
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2663
slice inherited
Definition mdbx.h++:1561
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:1134
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1311
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2659
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by hexadecimal dump of a passed slice.
static buffer key_from(const uint32_t unsigned_int32)
Definition mdbx.h++:2661
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2316
static constexpr pair invalid() noexcept
Definition mdbx.h++:1099
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2109
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2402
bool done
Definition mdbx.h++:1132
::std::ostream & output(::std::ostream &out) const
Output Base58 dump of passed slice to the std::ostream.
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid data and could be encoded or unexpectedly not...
Definition mdbx.h++:1258
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:705
pair & operator=(pair &&couple)
Definition mdbx.h++:1090
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:721
allocation_aware_details::move_assign_alloc< silo, allocator_type > move_assign_alloc
Definition mdbx.h++:1984
const bool uppercase
Definition mdbx.h++:1180
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1985
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2056
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2365
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2490
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2536
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2701
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2063
const bool ignore_spaces
Definition mdbx.h++:1383
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1267
pair(const pair &) noexcept=default
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2615
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:1013
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base64 dump, and therefore there could be dec...
slice & operator=(const slice &) noexcept=default
uint128_t as_uint128_adapt() const
constexpr int128_t as_int128() const
Definition mdbx.h++:1041
slice key
Definition mdbx.h++:1084
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2474
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:1085
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2707
const slice source
Definition mdbx.h++:1382
pair_result & operator=(const pair_result &) noexcept=default
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2472
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1300
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2665
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2464
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2673
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from hexadecimal dump from a passed slice.
constexpr int32_t as_int32() const
Definition mdbx.h++:1044
static buffer base64(const slice &source, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base64 dump of the slice content.
Definition mdbx.h++:2216
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2145
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1563
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2637
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2029
pair & operator=(const stl_pair &couple)
Definition mdbx.h++:1101
int64_t as_int64_adapt() const
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2645
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2032
static buffer base58(const slice &source, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base58 dump of the slice content.
Definition mdbx.h++:2211
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2341
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2699
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1038
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2674
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2154
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1988
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2540
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2560
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1035
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2181
buffer(const ::std::basic_string< CHAR, T, A > &&)=delete
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2695
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2643
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid hexadecimal dump, and therefore there could b...
buffer encode_base58(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2249
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2597
const unsigned wrap_width
Definition mdbx.h++:1223
buffer(const ::std::basic_string< CHAR, T, A > &)=delete
buffer & append_hex(const struct slice &data, bool uppercase=false, unsigned wrap_width=0)
Definition mdbx.h++:2516
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2193
const unsigned wrap_width
Definition mdbx.h++:1265
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2446
uint32_t as_uint32_adapt() const
constexpr bool is_valid() const noexcept
Checks the slice is not refers to null address or has zero length.
Definition mdbx.h++:1010
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2083
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by Base64 dump of passed slice.
buffer & append_producer(PRODUCER &producer)
Definition mdbx.h++:2502
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2710
constexpr slice(const ::std::basic_string_view< CHAR, T > &sv)
Create a slice that refers to the same contents as "string_view".
Definition mdbx.h++:714
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2509
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2149
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2626
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2672
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid data and could be encoded or unexpectedly not...
Definition mdbx.h++:1304
uint64_t as_uint64_adapt() const
constexpr buffer_pair_spec() noexcept=default
constexpr to_base58(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1225
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2137
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:716
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for hexadecimal dump of a passed slice.
Definition mdbx.h++:1197
bool done
Definition mdbx.h++:1071
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by Base58 dump of passed slice.
const slice source
Definition mdbx.h++:1309
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:2012
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2094
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1559
Definition mdbx.h++:2670
Type tag for delivered buffer template classes.
Definition mdbx.h++:1555
Definition mdbx.h++:1516
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1342
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1381
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1308
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:1082
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:1131
References a data located outside the slice.
Definition mdbx.h++:647
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1221
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1263
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1178
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:1069
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:564
remote_media(const ::mdbx::error &)
dangling_map_id(const ::mdbx::error &)
constexpr friend bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4666
fatal(const ::mdbx::error &) noexcept
reader_slot_busy(const ::mdbx::error &)
exception(const exception &)=default
::std::string message() const
Returns message for any errors.
not_found(const ::mdbx::error &)
operation_not_permitted(const ::mdbx::error &)
key_exists(const ::mdbx::error &)
permission_denied_or_not_writeable(const ::mdbx::error &)
void throw_exception() const
fatal(const exception &src) noexcept
Definition mdbx.h++:563
no_data(const ::mdbx::error &)
transaction_full(const ::mdbx::error &)
exception(exception &&)=default
db_too_large(const ::mdbx::error &)
bad_map_id(const ::mdbx::error &)
transaction_overlapping(const ::mdbx::error &)
void panic(const char *context_where_when, const char *func_who_what) const noexcept
Panics on unrecoverable errors inside destructors etc.
static void success_or_throw(int error_code)
Definition mdbx.h++:532
laggard_reader(const ::mdbx::error &)
db_full(const ::mdbx::error &)
duplicated_lck_file(const ::mdbx::error &)
const ::mdbx::error error() const noexcept
Definition mdbx.h++:554
error(const error &)=default
virtual ~fatal() noexcept
something_busy(const ::mdbx::error &)
fatal & operator=(fatal &&)=default
const char * what() const noexcept
Returns message for MDBX's errors only and "SYSTEM" for others.
fatal(const fatal &src) noexcept
Definition mdbx.h++:565
transaction_ousted(const ::mdbx::error &)
key_mismatch(const ::mdbx::error &)
db_invalid(const ::mdbx::error &)
exception & operator=(exception &&)=default
db_wanna_write_for_recovery(const ::mdbx::error &)
error & operator=(error &&)=default
bad_transaction(const ::mdbx::error &)
internal_problem(const ::mdbx::error &)
multivalue(const ::mdbx::error &)
fatal(fatal &&src) noexcept
Definition mdbx.h++:566
fatal & operator=(const fatal &)=default
max_readers_reached(const ::mdbx::error &)
db_version_mismatch(const ::mdbx::error &)
exception_thunk() noexcept=default
exception & operator=(const exception &)=default
exception(const ::mdbx::error &) noexcept
db_unable_extend(const ::mdbx::error &)
constexpr friend bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4664
error & operator=(const error &)=default
virtual ~exception() noexcept
error(error &&)=default
thread_mismatch(const ::mdbx::error &)
db_corrupted(const ::mdbx::error &)
internal_page_full(const ::mdbx::error &)
mvcc_retarded(const ::mdbx::error &)
max_maps_reached(const ::mdbx::error &)
bad_value_size(const ::mdbx::error &)
Implements error information and throwing corresponding exceptions.
Definition mdbx.h++:491
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:476
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:572
LIBMDBX_API void throw_incomparable_cursors()
LIBMDBX_API void throw_out_range()
LIBMDBX_API void throw_bad_value_size()
LIBMDBX_API void throw_max_length_exceeded()
LIBMDBX_API void throw_too_small_target_buffer()
uint64_t mdbx_key_from_int64(const int64_t i64)
Definition mdbx.h:4922
LIBMDBX_API uint32_t mdbx_key_from_ptrfloat(const float *const ieee754_32bit)
LIBMDBX_API uint64_t mdbx_key_from_double(const double ieee754_64bit)
LIBMDBX_API uint32_t mdbx_key_from_float(const float ieee754_32bit)
LIBMDBX_API uint64_t mdbx_key_from_ptrdouble(const double *const ieee754_64bit)
uint32_t mdbx_key_from_int32(const int32_t i32)
Definition mdbx.h:4926
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition mdbx.h++:192
#define MDBX_MSVC_DECLSPEC_EMPTY_BASES
Definition mdbx.h++:135
#define MDBX_CXX17_FALLTHROUGH
Definition mdbx.h++:250
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:290
#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES,...)
Definition mdbx.h++:125
#define MDBX_LIKELY(cond)
Definition mdbx.h++:225
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:202
#define MDBX_UNLIKELY(cond)
Definition mdbx.h++:233
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:181
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:220
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:241
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:201
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:256
The libmdbx C API header file.
Definition mdbx.h++:1418
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1420
The libmdbx C++ API namespace.
Definition mdbx.h++:323
STL namespace.
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6472
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1654
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1656
byte lastbyte_
Definition mdbx.h++:1655
Definition mdbx.h++:4252
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4254
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4253
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4256
Definition mdbx.h++:4240
move_result & operator=(const move_result &) noexcept=default
move_result(const move_result &) noexcept=default
move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4244
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4242
Tagged type for output to std::ostream.
Definition mdbx.h++:3027
intptr_t bytes
Definition mdbx.h++:3028
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3029
Database geometry for size management.
Definition mdbx.h++:3003
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3051
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3063
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3010
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3006
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3009
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3018
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3007
@ default_value
Means "keep current or use default".
Definition mdbx.h++:3005
@ kB
bytes (0x03E8)
Definition mdbx.h++:3008
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3017
@ KiB
bytes (0x0400)
Definition mdbx.h++:3016
constexpr geometry() noexcept
Definition mdbx.h++:3067
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3054
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3039
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3057
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3034
constexpr geometry(intptr_t size_lower, intptr_t size_now=default_value, intptr_t size_upper=default_value, intptr_t growth_step=default_value, intptr_t shrink_threshold=default_value, intptr_t pagesize=default_value) noexcept
Definition mdbx.h++:3070
Operate options.
Definition mdbx.h++:3107
bool disable_readahead
Definition mdbx.h++:3116
bool enable_validation
Definition mdbx.h++:3120
bool no_sticky_threads
Definition mdbx.h++:3109
constexpr operate_options() noexcept
Definition mdbx.h++:3121
bool disable_clear_memory
Definition mdbx.h++:3118
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3114
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
bool nested_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3112
Operate parameters.
Definition mdbx.h++:3129
env::durability durability
Definition mdbx.h++:3137
env::operate_options options
Definition mdbx.h++:3139
constexpr operate_parameters(const unsigned max_maps, const unsigned max_readers=0, const env::mode mode=env::mode::write_mapped_io, env::durability durability=env::durability::robust_synchronous, const env::reclaiming_options &reclaiming=env::reclaiming_options(), const env::operate_options &options=env::operate_options()) noexcept
Definition mdbx.h++:3143
static env::mode mode_from_flags(MDBX_env_flags_t) noexcept
constexpr operate_parameters & operator=(const operate_parameters &) noexcept=default
unsigned max_readers
The maximum number of threads/reader slots for the environment. Zero means default value.
Definition mdbx.h++:3135
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3138
env::mode mode
Definition mdbx.h++:3136
static env::durability durability_from_flags(MDBX_env_flags_t) noexcept
unsigned max_maps
The maximum number of named tables/maps for the environment. Zero means default value.
Definition mdbx.h++:3132
constexpr operate_parameters() noexcept
Definition mdbx.h++:3141
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3521
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3524
uint64_t transaction_lag
Definition mdbx.h++:3527
size_t bytes_used
Definition mdbx.h++:3531
uint64_t transaction_id
Definition mdbx.h++:3525
int slot
The reader lock table slot number.
Definition mdbx.h++:3522
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3523
size_t bytes_retained
Definition mdbx.h++:3534
Garbage reclaiming options.
Definition mdbx.h++:3094
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
bool coalesce
Definition mdbx.h++:3098
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3099
bool lifo
Definition mdbx.h++:3096
Additional parameters for creating a new database.
Definition mdbx.h++:3630
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3632
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3633
env::geometry geometry
Definition mdbx.h++:3631
Definition mdbx.h++:2942
map_handle::state state
Definition mdbx.h++:2944
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2943
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6577
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6573
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6572
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6563
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6562
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6558
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6554
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6567
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6568
capacity_holder capacity_
Definition mdbx.h++:1660
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1693
allocator_pointer stub_ptr_
Definition mdbx.h++:1635
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1672
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1713
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1664
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1679
inplace_flag_holder inplace_
Definition mdbx.h++:1661
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1663
allocator_pointer allocated_ptr_
Definition mdbx.h++:1659
size_t stub_capacity_bytes_
Definition mdbx.h++:1636
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1732
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1649
size_t bytes_
Definition mdbx.h++:1650
constexpr const byte * address() const noexcept
Definition mdbx.h++:1726
constexpr bin() noexcept
Definition mdbx.h++:1707
@ inplace_size
Definition mdbx.h++:1644
@ inplace_signature_limit
Definition mdbx.h++:1641
@ inplace_size_rounding
Definition mdbx.h++:1643
constexpr byte * address() noexcept
Definition mdbx.h++:1729
@ lastbyte_poison
Definition mdbx.h++:1639
@ lastbyte_inplace_signature
Definition mdbx.h++:1639
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1722
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1681