libmdbx 0.13.2.20 (2024-12-20T11:46:01+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
18
26
27#pragma once
28
29/* Workaround for modern libstdc++ with CLANG < 4.x */
30#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4
31#define __GLIBCXX_BITSIZE_INT_N_0 128
32#define __GLIBCXX_TYPE_INT_N_0 __int128
33#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
34
35#if !defined(__cplusplus) || __cplusplus < 201103L
36#if !defined(_MSC_VER) || _MSC_VER < 1900
37#error "C++11 compiler or better is required"
38#elif _MSC_VER >= 1910
39#error "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
40#endif /* MSVC is mad and don't define __cplusplus properly */
41#endif /* __cplusplus < 201103L */
42
43#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
44#error "CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
45#endif /* Windows */
46
47#ifndef __has_include
48#define __has_include(header) (0)
49#endif /* __has_include */
50
51#if __has_include(<version>)
52#include <version>
53#endif /* <version> */
54
55/* Disable min/max macros from C' headers */
56#ifndef NOMINMAX
57#define NOMINMAX
58#endif
59
60#include <algorithm> // for std::min/max
61#include <cassert> // for assert()
62#include <climits> // for CHAR_BIT
63#include <cstring> // for std::strlen, str:memcmp
64#include <exception> // for std::exception_ptr
65#include <ostream> // for std::ostream
66#include <sstream> // for std::ostringstream
67#include <stdexcept> // for std::invalid_argument
68#include <string> // for std::string
69#include <type_traits> // for std::is_pod<>, etc.
70#include <utility> // for std::make_pair
71#include <vector> // for std::vector<> as template args
72
73#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
74#include <memory_resource>
75#endif
76
77#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
78#include <string_view>
79#endif
80
81#ifndef MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
82#ifdef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
83#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
84#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && __cplusplus >= 201703L
85#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
86#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
87 (defined(_MSC_VER) && defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && __cplusplus >= 201403L))
88#if defined(__cpp_lib_experimental_filesystem) && __cpp_lib_experimental_filesystem >= 201406L
89#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
90#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && __has_include(<experimental/filesystem>)
91#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
92#else
93#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
94#endif
95#else
96#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
97#endif
98#endif /* MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM */
99
100#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
101#include <experimental/filesystem>
102#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
103#include <filesystem>
104#endif
105
106#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
107#include <span>
108#endif
109
110#if __cplusplus >= 201103L
111#include <chrono>
112#include <ratio>
113#endif
114
115#include "mdbx.h"
116
117#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
118 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
119 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
120 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
121#include <bit>
122#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
123#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
124#define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
125#define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
126#define __BYTE_ORDER__ __BYTE_ORDER
127#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
128#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
129#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
130#define __BYTE_ORDER__ _BYTE_ORDER
131#else
132#define __ORDER_LITTLE_ENDIAN__ 1234
133#define __ORDER_BIG_ENDIAN__ 4321
134#if defined(__LITTLE_ENDIAN__) || (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || defined(__ARMEL__) || \
135 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
136 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || defined(__elbrus_4c__) || defined(__elbrus_8c__) || \
137 defined(__bfin__) || defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
138 defined(__ia64) || defined(_M_IA64) || defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
139 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || defined(__WINDOWS__)
140#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
141#elif defined(__BIG_ENDIAN__) || (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || defined(__ARMEB__) || \
142 defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
143 defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
144 defined(__sparc__) || defined(__sparc) || defined(__370__) || defined(__THW_370__) || defined(__s390__) || \
145 defined(__s390x__) || defined(__SYSC_ZARCH__)
146#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
147#endif
148#endif
149#endif /* Byte Order */
150
153#if defined(DOXYGEN)
154#define MDBX_CXX17_CONSTEXPR constexpr
155#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
156 ((defined(_MSC_VER) && _MSC_VER >= 1915) || (defined(__clang__) && __clang_major__ > 5) || \
157 (defined(__GNUC__) && __GNUC__ > 7) || (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
158#define MDBX_CXX17_CONSTEXPR constexpr
159#else
160#define MDBX_CXX17_CONSTEXPR inline
161#endif /* MDBX_CXX17_CONSTEXPR */
162
165#if defined(DOXYGEN)
166#define MDBX_CXX20_CONSTEXPR constexpr
167#elif defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L && \
168 defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
169#define MDBX_CXX20_CONSTEXPR constexpr
170#else
171#define MDBX_CXX20_CONSTEXPR inline
172#endif /* MDBX_CXX20_CONSTEXPR */
173
174#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
175#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
176#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
177#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
178#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
179#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
180#else
181#define MDBX_CXX01_CONSTEXPR_ENUM inline
182#define MDBX_CXX11_CONSTEXPR_ENUM inline
183#define MDBX_CXX14_CONSTEXPR_ENUM inline
184#define MDBX_CXX17_CONSTEXPR_ENUM inline
185#define MDBX_CXX20_CONSTEXPR_ENUM inline
186#endif /* CONSTEXPR_ENUM_FLAGS_OPERATIONS */
187
190#if defined(CONSTEXPR_ASSERT)
191#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
192#elif defined NDEBUG
193#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
194#else
195#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
196#endif /* MDBX_CONSTEXPR_ASSERT */
197
198#ifndef MDBX_LIKELY
199#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
200#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
201#else
202#define MDBX_LIKELY(x) (x)
203#endif
204#endif /* MDBX_LIKELY */
205
206#ifndef MDBX_UNLIKELY
207#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
208#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
209#else
210#define MDBX_UNLIKELY(x) (x)
211#endif
212#endif /* MDBX_UNLIKELY */
213
216#if defined(DOXYGEN)
217#define MDBX_IF_CONSTEXPR constexpr
218#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
219#define MDBX_IF_CONSTEXPR constexpr
220#else
221#define MDBX_IF_CONSTEXPR
222#endif /* MDBX_IF_CONSTEXPR */
223
224#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
225 __cplusplus >= 201703L
226#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
227#else
228#define MDBX_CXX17_FALLTHROUGH
229#endif /* MDBX_CXX17_FALLTHROUGH */
230
231#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
232#define MDBX_CXX20_LIKELY [[likely]]
233#else
234#define MDBX_CXX20_LIKELY
235#endif /* MDBX_CXX20_LIKELY */
236
237#ifndef MDBX_CXX20_UNLIKELY
238#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
239#define MDBX_CXX20_UNLIKELY [[unlikely]]
240#else
241#define MDBX_CXX20_UNLIKELY
242#endif
243#endif /* MDBX_CXX20_UNLIKELY */
244
245#ifndef MDBX_HAVE_CXX20_CONCEPTS
246#if defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
247#include <concepts>
248#define MDBX_HAVE_CXX20_CONCEPTS 1
249#elif defined(DOXYGEN)
250#define MDBX_HAVE_CXX20_CONCEPTS 1
251#else
252#define MDBX_HAVE_CXX20_CONCEPTS 0
253#endif /* <concepts> */
254#endif /* MDBX_HAVE_CXX20_CONCEPTS */
255
256#ifndef MDBX_CXX20_CONCEPT
257#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
258#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
259#else
260#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
261#endif
262#endif /* MDBX_CXX20_CONCEPT */
263
264#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
265#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
266#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
267#else
268#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
269 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
270#endif
271#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
272
273#ifdef _MSC_VER
274#pragma warning(push, 4)
275#pragma warning(disable : 4127) /* conditional expression is constant */
276#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
277 be used by clients of 'mdbx::BAR' */
278#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
279 base for dll-interface 'mdbx::BAR' */
280/* MSVC is mad and can generate this warning for its own intermediate
281 * automatically generated code, which becomes unreachable after some kinds of
282 * optimization (copy elision, etc). */
283#pragma warning(disable : 4702) /* unreachable code */
284#endif /* _MSC_VER (warnings) */
285
286#if defined(__LCC__) && __LCC__ >= 126
287#pragma diagnostic push
288#if __LCC__ < 127
289#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
290 appearing in a constant expression `true` */
291#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
292 appearing in a constant expression `false` */
293#endif
294#endif /* E2K LCC (warnings) */
295
296//------------------------------------------------------------------------------
299namespace mdbx {
300
303
304// Functions whose signature depends on the `mdbx::byte` type
305// must be strictly defined as inline!
306#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
307// To enable all kinds of an compiler optimizations we use a byte-like type
308// that don't presumes aliases for pointers as does the `char` type and its
309// derivatives/typedefs.
310// Please see https://libmdbx.dqdkfa.ru/dead-github/issues/263
311// for reasoning of the use of `char8_t` type and switching to `__restrict__`.
312using byte = char8_t;
313#else
314// Avoid `std::byte` since it doesn't add features but inconvenient
315// restrictions.
316using byte = unsigned char;
317#endif /* __cpp_char8_t >= 201811*/
318
319#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
320using endian = ::std::endian;
321#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
322enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
323#else
324#error "Please use a C++ compiler provides byte order information or C++20 support"
325#endif /* Byte Order enum */
326
335
337static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
338
340static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
342static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
343
346using legacy_allocator = ::std::string::allocator_type;
347
348#if defined(DOXYGEN) || \
349 (defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI)
351using polymorphic_allocator = ::std::pmr::string::allocator_type;
353#else
355#endif /* __cpp_lib_memory_resource >= 201603L */
356
357struct slice;
359template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy> class buffer;
360class env;
361class env_managed;
362class txn;
363class txn_managed;
364class cursor;
365class cursor_managed;
366
369
371template <class ALLOCATOR = default_allocator>
372using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
373
375#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
376#ifdef _MSC_VER
377namespace filesystem = ::std::experimental::filesystem::v1;
378#else
379namespace filesystem = ::std::experimental::filesystem;
380#endif
381#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
382#elif defined(DOXYGEN) || \
383 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
384 __cpp_lib_string_view >= 201606L && \
385 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
386 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
387 (!defined(_MSC_VER) || __cplusplus >= 201703L)
388namespace filesystem = ::std::filesystem;
395#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
396#endif /* MDBX_STD_FILESYSTEM_PATH */
397
398#ifdef MDBX_STD_FILESYSTEM_PATH
400#elif defined(_WIN32) || defined(_WIN64)
401using path = ::std::wstring;
402#else
403using path = ::std::string;
404#endif /* mdbx::path */
405
406#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
407#ifndef MDBX_U128_TYPE
408#define MDBX_U128_TYPE __uint128_t
409#endif /* MDBX_U128_TYPE */
410#ifndef MDBX_I128_TYPE
411#define MDBX_I128_TYPE __int128_t
412#endif /* MDBX_I128_TYPE */
413#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
414
415#if __cplusplus >= 201103L || defined(DOXYGEN)
417using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
418#endif /* Duration for C++11 */
419
422
428 ::std::exception_ptr captured_;
429
430public:
431 exception_thunk() noexcept = default;
434 exception_thunk &operator=(const exception_thunk &) = delete;
435 exception_thunk &operator=(exception_thunk &&) = delete;
436 inline bool is_clean() const noexcept;
437 inline void capture() noexcept;
438 inline void rethrow_captured() const;
439};
440
443 MDBX_error_t code_;
444 inline error &operator=(MDBX_error_t error_code) noexcept;
445
446public:
447 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
448 error(const error &) = default;
449 error(error &&) = default;
450 error &operator=(const error &) = default;
451 error &operator=(error &&) = default;
452
453 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
454 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
455
456 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
457 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
458 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
459 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
460
462 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
463
465 const char *what() const noexcept;
466
468 ::std::string message() const;
469
471 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
473 [[noreturn]] void panic(const char *context_where_when, const char *func_who_what) const noexcept;
474 [[noreturn]] void throw_exception() const;
475 [[noreturn]] static inline void throw_exception(int error_code);
476 inline void throw_on_failure() const;
477 inline void success_or_throw() const;
478 inline void success_or_throw(const exception_thunk &) const;
479 inline void panic_on_failure(const char *context_where, const char *func_who) const noexcept;
480 inline void success_or_panic(const char *context_where, const char *func_who) const noexcept;
481 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
482 static inline void success_or_throw(MDBX_error_t error_code);
483 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
484 static inline void throw_on_failure(int error_code);
485 static inline bool boolean_or_throw(int error_code);
486 static inline void success_or_throw(int error_code, const exception_thunk &);
487 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
488 static inline void panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept;
489 static inline void success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept;
490};
491
496class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
497 using base = ::std::runtime_error;
498 ::mdbx::error error_;
499
500public:
501 exception(const ::mdbx::error &) noexcept;
502 exception(const exception &) = default;
503 exception(exception &&) = default;
504 exception &operator=(const exception &) = default;
506 virtual ~exception() noexcept;
507 const ::mdbx::error error() const noexcept { return error_; }
508};
509
513 using base = exception;
514
515public:
516 fatal(const ::mdbx::error &) noexcept;
517 fatal(const exception &src) noexcept : fatal(src.error()) {}
518 fatal(exception &&src) noexcept : fatal(src.error()) {}
519 fatal(const fatal &src) noexcept : fatal(src.error()) {}
520 fatal(fatal &&src) noexcept : fatal(src.error()) {}
521 fatal &operator=(fatal &&) = default;
522 fatal &operator=(const fatal &) = default;
523 virtual ~fatal() noexcept;
524};
525
526#define MDBX_DECLARE_EXCEPTION(NAME) \
527 struct LIBMDBX_API_TYPE NAME : public exception { \
528 NAME(const ::mdbx::error &); \
529 virtual ~NAME() noexcept; \
530 }
563#undef MDBX_DECLARE_EXCEPTION
564
567[[noreturn]] LIBMDBX_API void throw_out_range();
571static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes);
572static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload);
573static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom);
574
576
577//------------------------------------------------------------------------------
578
581
582#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
583
587template <typename T>
588concept MutableByteProducer = requires(T a, char array[42]) {
589 { a.is_empty() } -> std::same_as<bool>;
590 { a.envisage_result_length() } -> std::same_as<size_t>;
591 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
592};
593
597template <typename T>
598concept ImmutableByteProducer = requires(const T &a, char array[42]) {
599 { a.is_empty() } -> std::same_as<bool>;
600 { a.envisage_result_length() } -> std::same_as<size_t>;
601 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
602};
603
607template <typename T>
608concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
609 T(source);
610 { a.is_erroneous() } -> std::same_as<bool>;
611};
612
613#endif /* MDBX_HAVE_CXX20_CONCEPTS */
614
615template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy,
616 MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
617inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
618
619template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy,
620 MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
621inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer,
622 const ALLOCATOR &allocator = ALLOCATOR());
623
624template <class ALLOCATOR = default_allocator, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
625inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
626
627template <class ALLOCATOR = default_allocator, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
628inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
629
641
642 enum { max_length = MDBX_MAXDATASIZE };
643
645 MDBX_CXX11_CONSTEXPR slice() noexcept;
646
649 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
650
652 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
653
655 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
656 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
657 }
659 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
660
663 template <class CHAR, class T, class A>
664 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
665 : slice(str.data(), str.length() * sizeof(CHAR)) {}
666
668 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
670 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
671
672#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
673 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
674 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
675 "Must be a standard layout type!");
676 }
677
678 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
679 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
680 "Must be a standard layout type!");
681 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
683 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
685 }
686
687 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
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<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
694 }
695
696 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
697 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
698 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
699 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
700#endif /* __cpp_lib_span >= 202002L */
701
702#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
704 template <class CHAR, class T>
705 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv) : slice(sv.data(), sv.data() + sv.length()) {}
706
707 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
708#endif /* __cpp_lib_string_view >= 201606L */
709
710 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
711
712 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
713 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
714 "Must be a standard layout type!");
715 return slice(&pod, sizeof(pod));
716 }
717
718 inline slice &assign(const void *ptr, size_t bytes);
719 inline slice &assign(const slice &src) noexcept;
720 inline slice &assign(const ::MDBX_val &src);
721 inline slice &assign(slice &&src) noexcept;
722 inline slice &assign(::MDBX_val &&src);
723 inline slice &assign(const void *begin, const void *end);
724 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
725 return assign(str.data(), str.length() * sizeof(CHAR));
726 }
727 inline slice &assign(const char *c_str);
728#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
729 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
730 return assign(view.begin(), view.end());
731 }
732 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
733 assign(view);
734 view = {};
735 return *this;
736 }
737#endif /* __cpp_lib_string_view >= 201606L */
738
739 slice &operator=(const slice &) noexcept = default;
740 inline slice &operator=(slice &&src) noexcept;
741 inline slice &operator=(::MDBX_val &&src);
742 operator MDBX_val *() noexcept { return this; }
743 operator const MDBX_val *() const noexcept { return this; }
744
745#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
746 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
747 return assign(view);
748 }
749
750 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
751
753 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
754 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
755 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
756 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
757 }
758
760 template <class CHAR, class T>
761 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
762 return this->string_view<CHAR, T>();
763 }
764#endif /* __cpp_lib_string_view >= 201606L */
765
766 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
767 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR>
768 as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
769 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
770 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), allocator);
771 }
772
773 template <class CHAR, class T, class ALLOCATOR>
774 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
775 return as_string<CHAR, T, ALLOCATOR>();
776 }
777
779 template <class ALLOCATOR = default_allocator>
780 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
781 const ALLOCATOR &allocator = ALLOCATOR()) const;
782
785 template <class ALLOCATOR = default_allocator>
786 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &allocator = ALLOCATOR()) const;
787
790 template <class ALLOCATOR = default_allocator>
791 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &allocator = ALLOCATOR()) const;
792
794 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
795 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
796 const ALLOCATOR &allocator = ALLOCATOR()) const;
797
800 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
801 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
802 const ALLOCATOR &allocator = ALLOCATOR()) const;
803
806 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
807 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
808 const ALLOCATOR &allocator = ALLOCATOR()) const;
809
811 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
812 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
813 const ALLOCATOR &allocator = ALLOCATOR()) const;
814
817 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
818 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
819 const ALLOCATOR &allocator = ALLOCATOR()) const;
820
823 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
824 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
825 const ALLOCATOR &allocator = ALLOCATOR()) const;
826
832 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
833
838 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
839
845 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
846
852 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
853
854 inline void swap(slice &other) noexcept;
855
856#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
857 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
858 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
859 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
860 *this = view;
861 view = temp;
862 }
863#endif /* __cpp_lib_string_view >= 201606L */
864
866 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
867 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
868
870 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
871 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
872
874 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
875 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
876
878 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
879 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
880
882 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
883 MDBX_CXX11_CONSTEXPR void *data() noexcept;
884
886 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
887 MDBX_CXX11_CONSTEXPR void *end() noexcept;
888
890 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
891
893 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
894
896 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
897
899 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
900
902 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
903
905 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
906
908 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
909
911 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
912
914 MDBX_CXX14_CONSTEXPR void clear() noexcept;
915
918 inline void remove_prefix(size_t n) noexcept;
919
922 inline void remove_suffix(size_t n) noexcept;
923
926 inline void safe_remove_prefix(size_t n);
927
930 inline void safe_remove_suffix(size_t n);
931
933 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
934
936 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
937
940 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
941
944 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
945
948 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
949
952 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
953
956 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
957
960 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
961
964 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
965
968 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
969
974 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
975
984 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
985
991 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
992 const slice &b) noexcept;
993 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
994 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
995 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
996 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
997 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
998 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
999
1001 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1002
1005 MDBX_CXX14_CONSTEXPR static slice invalid() noexcept { return slice(size_t(-1)); }
1006
1007 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1008 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1009 "Must be a standard layout type!");
1010 if (MDBX_LIKELY(size() == sizeof(POD)))
1012 POD r;
1013 memcpy(&r, data(), sizeof(r));
1014 return r;
1015 }
1017 }
1018
1019#ifdef MDBX_U128_TYPE
1020 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1021#endif /* MDBX_U128_TYPE */
1022 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1023 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1024 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1025 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1026
1027#ifdef MDBX_I128_TYPE
1028 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1029#endif /* MDBX_I128_TYPE */
1030 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1031 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1032 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1033 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1034
1035#ifdef MDBX_U128_TYPE
1036 MDBX_U128_TYPE as_uint128_adapt() const;
1037#endif /* MDBX_U128_TYPE */
1038 uint64_t as_uint64_adapt() const;
1039 uint32_t as_uint32_adapt() const;
1040 uint16_t as_uint16_adapt() const;
1041 uint8_t as_uint8_adapt() const;
1042
1043#ifdef MDBX_I128_TYPE
1044 MDBX_I128_TYPE as_int128_adapt() const;
1045#endif /* MDBX_I128_TYPE */
1046 int64_t as_int64_adapt() const;
1047 int32_t as_int32_adapt() const;
1048 int16_t as_int16_adapt() const;
1049 int8_t as_int8_adapt() const;
1050
1051protected:
1052 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1053};
1054
1055//------------------------------------------------------------------------------
1056
1057namespace allocation_aware_details {
1058
1059template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1060#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1061 return ::std::allocator_traits<A>::is_always_equal::value;
1062#else
1063 return ::std::is_empty<A>::value;
1064#endif /* __cpp_lib_allocator_traits_is_always_equal */
1065}
1066
1067template <typename T, typename A = typename T::allocator_type,
1068 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1070
1071template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1072 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1073 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1074 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1075 }
1076 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1077 assert(target->get_allocator() != source.get_allocator());
1078 (void)target;
1079 (void)source;
1080 }
1081};
1082
1083template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1084 static constexpr bool is_nothrow() noexcept {
1085 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1086 }
1087 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1088 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) {
1089 assert(target->get_allocator() != source.get_allocator());
1090 target->get_allocator() = ::std::move(source.get_allocator());
1091 }
1092};
1093
1094template <typename T, typename A = typename T::allocator_type,
1095 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1097
1098template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1099 static constexpr bool is_nothrow() noexcept { return false; }
1100 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept {
1101 assert(target->get_allocator() != source.get_allocator());
1102 (void)target;
1103 (void)source;
1104 }
1105};
1106
1107template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1108 static constexpr bool is_nothrow() noexcept {
1109 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1110 }
1111 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1112 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1113 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1114 MDBX_CXX20_UNLIKELY target->get_allocator() =
1115 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1116 } else {
1117 /* gag for buggy compilers */
1118 (void)target;
1119 (void)source;
1120 }
1121 }
1122};
1123
1124template <typename T, typename A = typename T::allocator_type,
1125 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1127
1128template <typename T, typename A> struct swap_alloc<T, A, false> {
1129 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1130 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept(is_nothrow()) {
1131 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1132 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1133 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1134 } else {
1135 /* gag for buggy compilers */
1136 (void)target;
1137 (void)source;
1138 }
1139 }
1140};
1141
1142template <typename T, typename A> struct swap_alloc<T, A, true> {
1143 static constexpr bool is_nothrow() noexcept {
1144 return allocator_is_always_equal<A>() ||
1145#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1146 ::std::is_nothrow_swappable<A>() ||
1147#endif /* __cpp_lib_is_swappable >= 201603L */
1148 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1149 }
1150 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept(is_nothrow()) {
1151 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1152 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1153 MDBX_CXX20_UNLIKELY ::std::swap(*target, source);
1154 } else {
1155 /* gag for buggy compilers */
1156 (void)target;
1157 (void)source;
1158 }
1159 }
1160};
1161
1162} // namespace allocation_aware_details
1163
1165 enum : size_t { extra_inplace_storage = 0, pettiness_threshold = 64, max_reserve = 65536 };
1166
1167 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1168 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1169 static_assert(pettiness_threshold % 2 == 0, "pettiness_threshold must be even");
1170 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1171 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1172 return (value + pettiness_threshold - 1) & pettiness_mask;
1173 }
1174
1175 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna) {
1176 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1177 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1178 if (wanna > current)
1179 /* doubling capacity, but don't made reserve more than max_reserve */
1180 return round(wanna + ::std::min(size_t(max_reserve), current));
1181
1182 if (current - wanna >
1183 /* shrink if reserve will more than half of current or max_reserve,
1184 * but not less than pettiness_threshold */
1185 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1186 return round(wanna);
1187
1188 /* keep unchanged */
1189 return current;
1190 }
1191};
1192
1196 const bool uppercase = false;
1197 const unsigned wrap_width = 0;
1198 MDBX_CXX11_CONSTEXPR to_hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0) noexcept
1199 : source(source), uppercase(uppercase), wrap_width(wrap_width) {
1201 }
1202
1204 template <class ALLOCATOR = default_allocator>
1205 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1206 return make_string<ALLOCATOR>(*this, allocator);
1207 }
1208
1210 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1211 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1212 return make_buffer<ALLOCATOR>(*this, allocator);
1213 }
1214
1218 const size_t bytes = source.length() << 1;
1219 return wrap_width ? bytes + bytes / wrap_width : bytes;
1220 }
1221
1224 char *write_bytes(char *dest, size_t dest_size) const;
1225
1229 ::std::ostream &output(::std::ostream &out) const;
1230
1233 bool is_empty() const noexcept { return source.empty(); }
1234
1237 bool is_erroneous() const noexcept { return false; }
1238};
1239
1244 const unsigned wrap_width = 0;
1246 to_base58(const slice &source, unsigned wrap_width = 0) noexcept : source(source), wrap_width(wrap_width) {
1248 }
1249
1252 template <class ALLOCATOR = default_allocator>
1253 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1254 return make_string<ALLOCATOR>(*this, allocator);
1255 }
1256
1259 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1260 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1261 return make_buffer<ALLOCATOR>(*this, allocator);
1262 }
1263
1267 const size_t bytes = (source.length() * 11 + 7) / 8;
1268 return wrap_width ? bytes + bytes / wrap_width : bytes;
1269 }
1270
1274 char *write_bytes(char *dest, size_t dest_size) const;
1275
1280 ::std::ostream &output(::std::ostream &out) const;
1281
1284 bool is_empty() const noexcept { return source.empty(); }
1285
1288 bool is_erroneous() const noexcept { return false; }
1289};
1290
1295 const unsigned wrap_width = 0;
1297 to_base64(const slice &source, unsigned wrap_width = 0) noexcept : source(source), wrap_width(wrap_width) {
1299 }
1300
1303 template <class ALLOCATOR = default_allocator>
1304 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1305 return make_string<ALLOCATOR>(*this, allocator);
1306 }
1307
1310 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1311 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1312 return make_buffer<ALLOCATOR>(*this, allocator);
1313 }
1314
1318 const size_t bytes = (source.length() + 2) / 3 * 4;
1319 return wrap_width ? bytes + bytes / wrap_width : bytes;
1320 }
1321
1325 char *write_bytes(char *dest, size_t dest_size) const;
1326
1331 ::std::ostream &output(::std::ostream &out) const;
1332
1335 bool is_empty() const noexcept { return source.empty(); }
1336
1339 bool is_erroneous() const noexcept { return false; }
1340};
1341
1342inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
1343inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
1344inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
1345
1349 const bool ignore_spaces = false;
1350 MDBX_CXX11_CONSTEXPR from_hex(const slice &source, bool ignore_spaces = false) noexcept
1351 : source(source), ignore_spaces(ignore_spaces) {
1353 }
1354
1356 template <class ALLOCATOR = default_allocator>
1357 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1358 return make_string<ALLOCATOR>(*this, allocator);
1359 }
1360
1362 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1363 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1364 return make_buffer<ALLOCATOR>(*this, allocator);
1365 }
1366
1369 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1370
1374 char *write_bytes(char *dest, size_t dest_size) const;
1375
1378 bool is_empty() const noexcept { return source.empty(); }
1379
1382 bool is_erroneous() const noexcept;
1383};
1384
1389 const bool ignore_spaces = false;
1390 MDBX_CXX11_CONSTEXPR from_base58(const slice &source, bool ignore_spaces = false) noexcept
1391 : source(source), ignore_spaces(ignore_spaces) {
1393 }
1394
1397 template <class ALLOCATOR = default_allocator>
1398 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1399 return make_string<ALLOCATOR>(*this, allocator);
1400 }
1401
1404 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1405 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1406 return make_buffer<ALLOCATOR>(*this, allocator);
1407 }
1408
1413 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1414 }
1415
1419 char *write_bytes(char *dest, size_t dest_size) const;
1420
1423 bool is_empty() const noexcept { return source.empty(); }
1424
1428 bool is_erroneous() const noexcept;
1429};
1430
1435 const bool ignore_spaces = false;
1436 MDBX_CXX11_CONSTEXPR from_base64(const slice &source, bool ignore_spaces = false) noexcept
1437 : source(source), ignore_spaces(ignore_spaces) {
1439 }
1440
1443 template <class ALLOCATOR = default_allocator>
1444 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1445 return make_string<ALLOCATOR>(*this, allocator);
1446 }
1447
1450 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1451 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1452 return make_buffer<ALLOCATOR>(*this, allocator);
1453 }
1454
1458 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1459
1463 char *write_bytes(char *dest, size_t dest_size) const;
1464
1467 bool is_empty() const noexcept { return source.empty(); }
1468
1472 bool is_erroneous() const noexcept;
1473};
1474
1476template <class ALLOCATOR, typename CAPACITY_POLICY> class buffer {
1477public:
1478#if !defined(_MSC_VER) || _MSC_VER > 1900
1479 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1480#else
1481 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1482#endif /* MSVC is mad */
1483 using allocator_traits = ::std::allocator_traits<allocator_type>;
1484 using reservation_policy = CAPACITY_POLICY;
1485 enum : size_t {
1486 max_length = MDBX_MAXDATASIZE,
1487 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1488 extra_inplace_storage = reservation_policy::extra_inplace_storage,
1489 pettiness_threshold = reservation_policy::pettiness_threshold
1491
1492private:
1493 friend class txn;
1494 struct silo;
1496 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1497 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1498 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1499
1500 using allocator_pointer = typename allocator_traits::pointer;
1501 using allocator_const_pointer = typename allocator_traits::const_pointer;
1502
1503 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1504 assert(bytes >= sizeof(bin));
1505 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1506 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1507 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1508 const size_t n = (bytes + unit - 1) / unit;
1509 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1510 }
1511 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1512 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1513 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1514 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1515 }
1516
1517 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1518#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1519 return static_cast<void *>(::std::to_address(ptr));
1520#else
1521 return static_cast<void *>(::std::addressof(*ptr));
1522#endif /* __cpp_lib_to_address */
1523 }
1524 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1525#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1526 return static_cast<const void *>(::std::to_address(ptr));
1527#else
1528 return static_cast<const void *>(::std::addressof(*ptr));
1529#endif /* __cpp_lib_to_address */
1530 }
1531
1532 union bin {
1533 struct allocated {
1534 allocator_pointer ptr_;
1536 constexpr allocated(allocator_pointer ptr, size_t bytes) noexcept : ptr_(ptr), capacity_bytes_(bytes) {}
1537 constexpr allocated(const allocated &) noexcept = default;
1538 constexpr allocated(allocated &&) noexcept = default;
1539 MDBX_CXX17_CONSTEXPR allocated &operator=(const allocated &) noexcept = default;
1540 MDBX_CXX17_CONSTEXPR allocated &operator=(allocated &&) noexcept = default;
1541 };
1542
1543 allocated allocated_;
1544 uint64_t align_hint_;
1545 byte inplace_[(sizeof(allocated) + extra_inplace_storage + 7u) & ~size_t(7)];
1546
1547 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1548 static_assert(sizeof(bin) == sizeof(inplace_), "WTF?");
1549 return capacity_bytes < sizeof(bin);
1550 }
1551
1552 enum : byte { lastbyte_inplace_signature = byte(~byte(0)) };
1553 enum : size_t {
1554 inplace_signature_limit = size_t(lastbyte_inplace_signature)
1555 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT
1557
1558 constexpr byte inplace_lastbyte() const noexcept { return inplace_[sizeof(bin) - 1]; }
1559 MDBX_CXX17_CONSTEXPR byte &inplace_lastbyte() noexcept { return inplace_[sizeof(bin) - 1]; }
1560
1561 constexpr bool is_inplace() const noexcept {
1562 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1563 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1564 inplace_signature_limit,
1565 "WTF?");
1566 return inplace_lastbyte() == lastbyte_inplace_signature;
1567 }
1568 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1569
1570 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1571 if (destroy_ptr) {
1572 MDBX_CONSTEXPR_ASSERT(is_allocated());
1573 /* properly destroy allocator::pointer */
1574 allocated_.~allocated();
1575 }
1576 if (::std::is_trivial<allocator_pointer>::value)
1577 /* workaround for "uninitialized" warning from some compilers */
1578 memset(&allocated_.ptr_, 0, sizeof(allocated_.ptr_));
1579 inplace_lastbyte() = lastbyte_inplace_signature;
1580 MDBX_CONSTEXPR_ASSERT(is_inplace() && address() == inplace_ && is_suitable_for_inplace(capacity()));
1581 return address();
1582 }
1583
1584 template <bool construct_ptr>
1585 MDBX_CXX17_CONSTEXPR byte *make_allocated(allocator_pointer ptr, size_t capacity_bytes) noexcept {
1586 MDBX_CONSTEXPR_ASSERT(inplace_signature_limit > capacity_bytes);
1587 if (construct_ptr)
1588 /* properly construct allocator::pointer */
1589 new (&allocated_) allocated(ptr, capacity_bytes);
1590 else {
1591 MDBX_CONSTEXPR_ASSERT(is_allocated());
1592 allocated_.ptr_ = ptr;
1593 allocated_.capacity_bytes_ = capacity_bytes;
1594 }
1595 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(ptr) && capacity() == capacity_bytes);
1596 return address();
1597 }
1598
1599 MDBX_CXX20_CONSTEXPR bin(size_t capacity_bytes = 0) noexcept {
1600 MDBX_CONSTEXPR_ASSERT(is_suitable_for_inplace(capacity_bytes));
1601 make_inplace<false>();
1602 (void)capacity_bytes;
1603 }
1604 MDBX_CXX20_CONSTEXPR bin(allocator_pointer ptr, size_t capacity_bytes) noexcept {
1605 MDBX_CONSTEXPR_ASSERT(!is_suitable_for_inplace(capacity_bytes));
1606 make_allocated<true>(ptr, capacity_bytes);
1607 }
1609 if (is_allocated())
1610 /* properly destroy allocator::pointer */
1611 allocated_.~allocated();
1612 }
1613 MDBX_CXX20_CONSTEXPR bin(bin &&ditto) noexcept {
1614 if (ditto.is_inplace()) {
1615 // micro-optimization: don't use make_inplace<> here
1616 // since memcpy() will copy the flag.
1617 memcpy(inplace_, ditto.inplace_, sizeof(inplace_));
1618 MDBX_CONSTEXPR_ASSERT(is_inplace());
1619 } else {
1620 new (&allocated_) allocated(::std::move(ditto.allocated_));
1621 ditto.make_inplace<true>();
1622 MDBX_CONSTEXPR_ASSERT(is_allocated());
1623 }
1624 }
1625
1626 MDBX_CXX17_CONSTEXPR bin &operator=(const bin &ditto) noexcept {
1627 if (ditto.is_inplace()) {
1628 // micro-optimization: don't use make_inplace<> here
1629 // since memcpy() will copy the flag.
1630 if (is_allocated())
1631 /* properly destroy allocator::pointer */
1632 allocated_.~allocated();
1633 memcpy(inplace_, ditto.inplace_, sizeof(inplace_));
1634 MDBX_CONSTEXPR_ASSERT(is_inplace());
1635 } else if (is_inplace())
1636 make_allocated<true>(ditto.allocated_.ptr_, ditto.allocated_.capacity_bytes_);
1637 else
1638 make_allocated<false>(ditto.allocated_.ptr_, ditto.allocated_.capacity_bytes_);
1639 return *this;
1640 }
1641
1643 operator=(const_cast<const bin &>(ditto));
1644 if (ditto.is_allocated())
1645 ditto.make_inplace<true>();
1646 return *this;
1647 }
1648
1649 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1650 if (MDBX_UNLIKELY(wanna > max_capacity))
1651 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1652
1653 const size_t advised = reservation_policy::advise(current, wanna);
1654 assert(advised >= wanna);
1655 return ::std::min(size_t(max_capacity), ::std::max(sizeof(bin) - 1, advised));
1656 }
1657
1658 constexpr const byte *address() const noexcept {
1659 return is_inplace() ? inplace_ : static_cast<const byte *>(to_address(allocated_.ptr_));
1660 }
1662 return is_inplace() ? inplace_ : static_cast<byte *>(to_address(allocated_.ptr_));
1663 }
1664 constexpr size_t capacity() const noexcept { return is_inplace() ? sizeof(bin) - 1 : allocated_.capacity_bytes_; }
1665 } bin_;
1666
1667 MDBX_CXX20_CONSTEXPR void *init(size_t capacity) {
1668 capacity = bin::advise_capacity(0, capacity);
1669 if (bin_.is_suitable_for_inplace(capacity))
1670 new (&bin_) bin();
1671 else {
1672 const auto pair = allocate_storage(capacity);
1673 assert(pair.second >= capacity);
1674 new (&bin_) bin(pair.first, pair.second);
1675 }
1676 return bin_.address();
1677 }
1678
1679 MDBX_CXX20_CONSTEXPR void release() noexcept {
1680 if (bin_.is_allocated()) {
1681 deallocate_storage(bin_.allocated_.ptr_, bin_.allocated_.capacity_bytes_);
1682 bin_.template make_inplace<true>();
1683 }
1684 }
1685
1686 template <bool external_content>
1687 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1688 const void *const content, const size_t length) {
1689 assert(wanna_capacity >= wanna_headroom + length);
1690 const size_t old_capacity = bin_.capacity();
1691 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1692 if (MDBX_LIKELY(new_capacity == old_capacity))
1694 assert(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1695 byte *const new_place = bin_.address() + wanna_headroom;
1696 if (MDBX_LIKELY(length))
1698 if (external_content)
1699 memcpy(new_place, content, length);
1700 else {
1701 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1702 assert(old_capacity >= old_headroom + length);
1703 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1704 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1705 }
1706 }
1707 return new_place;
1708 }
1709
1710 if (bin::is_suitable_for_inplace(new_capacity)) {
1711 assert(bin_.is_allocated());
1712 const auto old_allocated = ::std::move(bin_.allocated_.ptr_);
1713 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1714 if (MDBX_LIKELY(length))
1715 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1716 deallocate_storage(old_allocated, old_capacity);
1717 return new_place;
1718 }
1719
1720 if (!bin_.is_allocated()) {
1721 const auto pair = allocate_storage(new_capacity);
1722 assert(pair.second >= new_capacity);
1723 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1724 if (MDBX_LIKELY(length))
1725 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1726 bin_.template make_allocated<true>(pair.first, pair.second);
1727 return new_place;
1728 }
1729
1730 const auto old_allocated = ::std::move(bin_.allocated_.ptr_);
1731 if (external_content)
1732 deallocate_storage(old_allocated, old_capacity);
1733 const auto pair = allocate_storage(new_capacity);
1734 assert(pair.second >= new_capacity);
1735 byte *const new_place = bin_.template make_allocated<false>(pair.first, pair.second) + wanna_headroom;
1736 if (MDBX_LIKELY(length))
1737 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1738 if (!external_content)
1739 deallocate_storage(old_allocated, old_capacity);
1740 return new_place;
1741 }
1742
1743 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1744 assert(capacity() >= offset);
1745 return bin_.address() + offset;
1746 }
1747 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1748 assert(capacity() >= offset);
1749 return bin_.address() + offset;
1750 }
1751 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1752 assert(capacity() >= offset + length);
1753 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1754 }
1755
1756 //--------------------------------------------------------------------------
1757
1759 silo() noexcept : allocator_type() { init(0); }
1761 silo(const allocator_type &alloc) noexcept : allocator_type(alloc) { init(0); }
1762 MDBX_CXX20_CONSTEXPR silo(size_t capacity) { init(capacity); }
1763 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc) : silo(alloc) { init(capacity); }
1764
1765 MDBX_CXX20_CONSTEXPR silo(silo &&ditto) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1766 : allocator_type(::std::move(ditto.get_allocator())), bin_(::std::move(ditto.bin_)) {}
1767
1768 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length) : silo(capacity) {
1769 assert(capacity >= headroom + length);
1770 if (length)
1771 put(headroom, ptr, length);
1772 }
1773
1774 // select_on_container_copy_construction()
1775 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1776 const allocator_type &alloc)
1777 : silo(capacity, alloc) {
1778 assert(capacity >= headroom + length);
1779 if (length)
1780 put(headroom, ptr, length);
1781 }
1782
1783 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length) : silo(length, 0, ptr, length) {}
1784 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc)
1785 : silo(length, 0, ptr, length, alloc) {}
1786
1787 ~silo() { release(); }
1788
1789 //--------------------------------------------------------------------------
1790
1791 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1792 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1793 }
1794 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1795
1796 MDBX_CXX20_CONSTEXPR silo &assign(const silo &ditto, size_t headroom, slice &content) {
1797 assert(ditto.get() + headroom == content.byte_ptr());
1798 if MDBX_IF_CONSTEXPR (!allocation_aware_details::allocator_is_always_equal<allocator_type>()) {
1799 if (MDBX_UNLIKELY(get_allocator() != ditto.get_allocator()))
1800 MDBX_CXX20_UNLIKELY {
1801 release();
1802 allocation_aware_details::copy_assign_alloc<silo, allocator_type>::propagate(this, ditto);
1803 }
1804 }
1805 content.iov_base = reshape<true>(ditto.capacity(), headroom, content.data(), content.length());
1806 return *this;
1807 }
1808
1810 assign(silo &&ditto, size_t headroom,
1811 slice &content) noexcept(allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_nothrow()) {
1812 assert(ditto.get() + headroom == content.byte_ptr());
1813 if (allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, ditto)) {
1814 release();
1815 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, ditto);
1816 /* no reallocation nor copying required */
1817 bin_ = ::std::move(ditto.bin_);
1818 assert(get() + headroom == content.byte_ptr());
1819 } else {
1820 /* copy content since allocators are different */
1821 content.iov_base = reshape<true>(ditto.capacity(), headroom, content.data(), content.length());
1822 ditto.release();
1823 }
1824 return *this;
1825 }
1826
1827 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1828 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1829 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1830 }
1831 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1832 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1833 }
1835 swap(silo &ditto) noexcept(allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1836 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(this, ditto);
1837 ::std::swap(bin_, ditto.bin_);
1838 }
1839
1840 /* MDBX_CXX20_CONSTEXPR void shrink_to_fit() { TODO } */
1841
1842 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1843 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1844 return get(offset);
1845 }
1846 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1847 };
1848
1849 silo silo_;
1850 ::mdbx::slice slice_;
1851
1852 void insulate() {
1853 assert(is_reference());
1854 silo_.assign(slice_.char_ptr(), slice_.length());
1855 slice_.iov_base = silo_.data();
1856 }
1857
1858 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1859 return static_cast<const byte *>(silo_.data());
1860 }
1861
1862 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1863 return silo_begin() + silo_.capacity();
1864 }
1865
1866 struct data_preserver : public exception_thunk {
1867 buffer data;
1868 data_preserver(allocator_type &allocator) : data(allocator) {}
1869 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1870 auto self = static_cast<data_preserver *>(context);
1871 assert(self->is_clean());
1872 assert(&self->data.slice_ == target);
1873 (void)target;
1874 try {
1875 self->data.assign(src, bytes, false);
1876 return MDBX_RESULT_FALSE;
1877 } catch (... /* capture any exception to rethrow it over C code */) {
1878 self->capture();
1879 return MDBX_RESULT_TRUE;
1880 }
1881 }
1882 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1883 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1884 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1885 };
1886
1887public:
1891
1894
1896 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1897
1901 static_assert(size_t(-long(max_length)) > max_length, "WTF?");
1902 return size_t(byte_ptr() - silo_begin()) < silo_.capacity();
1903 }
1904
1907 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR bool is_reference() const noexcept { return !is_freestanding(); }
1908
1912 return is_freestanding() ? silo_.capacity() : 0;
1913 }
1914
1918 return is_freestanding() ? slice_.byte_ptr() - silo_begin() : 0;
1919 }
1920
1924 return is_freestanding() ? capacity() - headroom() - slice_.length() : 0;
1925 }
1926
1928 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return slice_.byte_ptr(); }
1929
1931 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return slice_.end_byte_ptr(); }
1932
1937 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1938 return const_cast<byte *>(slice_.byte_ptr());
1939 }
1940
1945 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1946 return const_cast<byte *>(slice_.end_byte_ptr());
1947 }
1948
1950 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return slice_.char_ptr(); }
1951
1953 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return slice_.end_char_ptr(); }
1954
1959 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1960 return const_cast<char *>(slice_.char_ptr());
1961 }
1962
1967 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1968 return const_cast<char *>(slice_.end_char_ptr());
1969 }
1970
1972 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return slice_.data(); }
1973
1975 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return slice_.end(); }
1976
1980 MDBX_CXX11_CONSTEXPR void *data() noexcept {
1981 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1982 return const_cast<void *>(slice_.data());
1983 }
1984
1988 MDBX_CXX11_CONSTEXPR void *end() noexcept {
1989 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1990 return const_cast<void *>(slice_.end());
1991 }
1992
1995 return MDBX_CONSTEXPR_ASSERT(is_reference() || slice_.length() + headroom() <= silo_.capacity()), slice_.length();
1996 }
1997
2000 MDBX_CONSTEXPR_ASSERT(is_reference() || bytes + headroom() <= silo_.capacity());
2001 slice_.set_length(bytes);
2002 return *this;
2003 }
2004
2007 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2008 return set_length(static_cast<const char *>(ptr) - char_ptr());
2009 }
2010
2015 if (is_reference())
2016 insulate();
2017 }
2018
2019 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2020 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &allocator) noexcept : silo_(allocator) {}
2021
2022 buffer(const struct slice &src, bool make_reference, const allocator_type &allocator = allocator_type())
2023 : silo_(allocator), slice_(src) {
2024 if (!make_reference)
2025 insulate();
2026 }
2027
2028 buffer(const buffer &src, bool make_reference, const allocator_type &allocator = allocator_type())
2029 : buffer(src.slice_, make_reference, allocator) {}
2030
2031 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &allocator = allocator_type())
2032 : buffer(::mdbx::slice(ptr, bytes), make_reference, allocator) {}
2033
2034 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2035 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2036
2037 buffer(const char *c_str, bool make_reference, const allocator_type &allocator = allocator_type())
2038 : buffer(::mdbx::slice(c_str), make_reference, allocator) {}
2039
2040#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2041 template <class CHAR, class T>
2042 buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2043 const allocator_type &allocator = allocator_type())
2044 : buffer(::mdbx::slice(view), make_reference, allocator) {}
2045#endif /* __cpp_lib_string_view >= 201606L */
2046
2048 buffer(const struct slice &src, const allocator_type &allocator = allocator_type())
2049 : silo_(src.data(), src.length(), allocator), slice_(silo_.data(), src.length()) {}
2050
2052 buffer(const buffer &src, const allocator_type &allocator = allocator_type()) : buffer(src.slice_, allocator) {}
2053
2055 buffer(const void *ptr, size_t bytes, const allocator_type &allocator = allocator_type())
2056 : buffer(::mdbx::slice(ptr, bytes), allocator) {}
2057
2058 template <class CHAR, class T, class A>
2059 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2060 const allocator_type &allocator = allocator_type())
2061 : buffer(::mdbx::slice(str), allocator) {}
2062
2064 buffer(const char *c_str, const allocator_type &allocator = allocator_type())
2065 : buffer(::mdbx::slice(c_str), allocator) {}
2066
2067#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2068 template <class CHAR, class T>
2069 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2070 const allocator_type &allocator = allocator_type())
2071 : buffer(::mdbx::slice(view), allocator) {}
2072#endif /* __cpp_lib_string_view >= 201606L */
2073
2074 buffer(size_t head_room, size_t tail_room, const allocator_type &allocator = allocator_type()) : silo_(allocator) {
2075 slice_.iov_base = silo_.init(check_length(head_room, tail_room));
2076 assert(slice_.iov_len == 0);
2077 }
2078
2079 buffer(size_t capacity, const allocator_type &allocator = allocator_type()) : silo_(allocator) {
2080 slice_.iov_base = silo_.init(check_length(capacity));
2081 assert(slice_.iov_len == 0);
2082 }
2083
2084 buffer(size_t head_room, const struct slice &src, size_t tail_room,
2085 const allocator_type &allocator = allocator_type())
2086 : silo_(allocator) {
2087 slice_.iov_base = silo_.init(check_length(head_room, src.length(), tail_room));
2088 slice_.iov_len = src.length();
2089 memcpy(slice_.iov_base, src.data(), src.length());
2090 }
2091
2092 buffer(size_t head_room, const buffer &src, size_t tail_room, const allocator_type &allocator = allocator_type())
2093 : buffer(head_room, src.slice_, tail_room, allocator) {}
2094
2095 inline buffer(const ::mdbx::txn &txn, const struct slice &src, const allocator_type &allocator = allocator_type());
2096
2097 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2098 : silo_(::std::move(src.silo_)), slice_(::std::move(src.slice_)) {}
2099
2100 MDBX_CXX11_CONSTEXPR const struct slice &slice() const noexcept { return slice_; }
2101
2102 MDBX_CXX11_CONSTEXPR operator const struct slice &() const noexcept { return slice_; }
2103
2104#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
2105 template <typename POD> MDBX_CXX14_CONSTEXPR buffer(const ::std::span<POD> &span) : buffer(span.begin(), span.end()) {
2106 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
2107 "Must be a standard layout type!");
2108 }
2109
2110 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
2111 return slice_.template as_span<const POD>();
2112 }
2113 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() { return slice_.template as_span<POD>(); }
2114
2115 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
2116 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
2117 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
2118 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
2119#endif /* __cpp_lib_span >= 202002L */
2120
2121 template <typename POD>
2122 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &allocator = allocator_type()) {
2123 return buffer(::mdbx::slice::wrap(pod), make_reference, allocator);
2124 }
2125
2126 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const { return slice_.as_pod<POD>(); }
2127
2128#ifdef MDBX_U128_TYPE
2129 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return slice().as_uint128(); }
2130#endif /* MDBX_U128_TYPE */
2131 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return slice().as_uint64(); }
2132 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return slice().as_uint32(); }
2133 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return slice().as_uint16(); }
2134 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return slice().as_uint8(); }
2135
2136#ifdef MDBX_I128_TYPE
2137 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return slice().as_int128(); }
2138#endif /* MDBX_I128_TYPE */
2139 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return slice().as_int64(); }
2140 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return slice().as_int32(); }
2141 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return slice().as_int16(); }
2142 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return slice().as_int8(); }
2143
2144#ifdef MDBX_U128_TYPE
2145 MDBX_U128_TYPE as_uint128_adapt() const { return slice().as_uint128_adapt(); }
2146#endif /* MDBX_U128_TYPE */
2147 uint64_t as_uint64_adapt() const { return slice().as_uint64_adapt(); }
2148 uint32_t as_uint32_adapt() const { return slice().as_uint32_adapt(); }
2149 uint16_t as_uint16_adapt() const { return slice().as_uint16_adapt(); }
2150 uint8_t as_uint8_adapt() const { return slice().as_uint8_adapt(); }
2151
2152#ifdef MDBX_I128_TYPE
2153 MDBX_I128_TYPE as_int128_adapt() const { return slice().as_int128_adapt(); }
2154#endif /* MDBX_I128_TYPE */
2155 int64_t as_int64_adapt() const { return slice().as_int64_adapt(); }
2156 int32_t as_int32_adapt() const { return slice().as_int32_adapt(); }
2157 int16_t as_int16_adapt() const { return slice().as_int16_adapt(); }
2158 int8_t as_int8_adapt() const { return slice().as_int8_adapt(); }
2159
2161 static buffer hex(const ::mdbx::slice &source, bool uppercase = false, unsigned wrap_width = 0,
2162 const allocator_type &allocator = allocator_type()) {
2163 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, allocator);
2164 }
2165
2168 static buffer base58(const ::mdbx::slice &source, unsigned wrap_width = 0,
2169 const allocator_type &allocator = allocator_type()) {
2170 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, allocator);
2171 }
2174 static buffer base64(const ::mdbx::slice &source, unsigned wrap_width = 0,
2175 const allocator_type &allocator = allocator_type()) {
2176 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, allocator);
2177 }
2178
2180 template <typename POD>
2181 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2182 const allocator_type &allocator = allocator_type()) {
2183 return hex(mdbx::slice::wrap(pod), uppercase, wrap_width, allocator);
2184 }
2185
2188 template <typename POD>
2189 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &allocator = allocator_type()) {
2190 return base58(mdbx::slice::wrap(pod), wrap_width, allocator);
2191 }
2192
2195 template <typename POD>
2196 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &allocator = allocator_type()) {
2197 return base64(mdbx::slice::wrap(pod), wrap_width, allocator);
2198 }
2199
2201 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2202 const allocator_type &allocator = allocator_type()) const {
2203 return slice().template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, allocator);
2204 }
2205
2208 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &allocator = allocator_type()) const {
2209 return slice().template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, allocator);
2210 }
2213 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &allocator = allocator_type()) const {
2214 return slice().template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, allocator);
2215 }
2216
2218 static buffer hex_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2219 const allocator_type &allocator = allocator_type()) {
2220 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, allocator);
2221 }
2222
2225 static buffer base58_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2226 const allocator_type &allocator = allocator_type()) {
2227 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, allocator);
2228 }
2229
2232 static buffer base64_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2233 const allocator_type &allocator = allocator_type()) {
2234 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, allocator);
2235 }
2236
2239 buffer hex_decode(bool ignore_spaces = false, const allocator_type &allocator = allocator_type()) const {
2240 return hex_decode(slice(), ignore_spaces, allocator);
2241 }
2242
2245 buffer base58_decode(bool ignore_spaces = false, const allocator_type &allocator = allocator_type()) const {
2246 return base58_decode(slice(), ignore_spaces, allocator);
2247 }
2248
2251 buffer base64_decode(bool ignore_spaces = false, const allocator_type &allocator = allocator_type()) const {
2252 return base64_decode(slice(), ignore_spaces, allocator);
2253 }
2254
2256 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2257 wanna_headroom = ::std::min(::std::max(headroom(), wanna_headroom), wanna_headroom + pettiness_threshold);
2258 wanna_tailroom = ::std::min(::std::max(tailroom(), wanna_tailroom), wanna_tailroom + pettiness_threshold);
2259 const size_t wanna_capacity = check_length(wanna_headroom, slice_.length(), wanna_tailroom);
2260 silo_.resize(wanna_capacity, wanna_headroom, slice_);
2261 assert(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2262 assert(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2263 }
2264
2266 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2267
2269 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2270
2271 buffer &assign_reference(const void *ptr, size_t bytes) {
2272 silo_.clear();
2273 slice_.assign(ptr, bytes);
2274 return *this;
2275 }
2276
2277 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2278 silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes));
2279 slice_.assign(silo_.data(), bytes);
2280 return *this;
2281 }
2282
2283 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2284 silo_.swap(other.silo_);
2285 slice_.swap(other.slice_);
2286 }
2287
2288 static buffer clone(const buffer &src, const allocator_type &allocator = allocator_type()) {
2289 return buffer(src.headroom(), src.slice_, src.tailroom(), allocator);
2290 }
2291
2292 buffer &assign(const buffer &src, bool make_reference = false) { return assign(src.slice_, make_reference); }
2293
2294 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2295 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2296 }
2297
2298 buffer &assign(const struct slice &src, bool make_reference = false) {
2299 return assign(src.data(), src.length(), make_reference);
2300 }
2301
2302 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2303 return assign(src.iov_base, src.iov_len, make_reference);
2304 }
2305
2306 buffer &assign(struct slice &&src, bool make_reference = false) {
2307 assign(src.data(), src.length(), make_reference);
2308 src.invalidate();
2309 return *this;
2310 }
2311
2312 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2313 assign(src.iov_base, src.iov_len, make_reference);
2314 src.iov_base = nullptr;
2315 return *this;
2316 }
2317
2318 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2319 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2320 }
2321
2322 template <class CHAR, class T, class A>
2323 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2324 return assign(str.data(), str.length(), make_reference);
2325 }
2326
2327 buffer &assign(const char *c_str, bool make_reference = false) {
2328 return assign(c_str, ::mdbx::strlen(c_str), make_reference);
2329 }
2330
2331#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2332 template <class CHAR, class T>
2333 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2334 return assign(view.data(), view.length(), make_reference);
2335 }
2336
2337 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2338 assign(view.data(), view.length(), make_reference);
2339 view = {};
2340 return *this;
2341 }
2342#endif /* __cpp_lib_string_view >= 201606L */
2343
2344 buffer &operator=(const buffer &src) { return assign(src); }
2345
2346 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2347
2348 buffer &operator=(const struct slice &src) { return assign(src); }
2349
2350 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2351
2352#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2353 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2354 return assign(view);
2355 }
2356
2358 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
2359 ::std::basic_string_view<CHAR, T> string_view() const noexcept {
2360 return slice_.string_view<CHAR, T>();
2361 }
2362
2364 template <class CHAR, class T> operator ::std::basic_string_view<CHAR, T>() const noexcept {
2365 return string_view<CHAR, T>();
2366 }
2367#endif /* __cpp_lib_string_view >= 201606L */
2368
2370 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR bool empty() const noexcept { return length() == 0; }
2371
2373 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept { return data() == nullptr; }
2374
2376 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR size_t size() const noexcept { return length(); }
2377
2382 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept { return slice_.hash_value(); }
2383
2384 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class A = legacy_allocator>
2385 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, A> as_string(const A &allocator = A()) const {
2386 return slice_.as_string<CHAR, T, A>(allocator);
2387 }
2388
2389 template <class CHAR, class T, class A>
2390 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2391 return as_string<CHAR, T, A>();
2392 }
2393
2395 MDBX_NOTHROW_PURE_FUNCTION bool starts_with(const struct slice &prefix) const noexcept {
2396 return slice_.starts_with(prefix);
2397 }
2398
2400 MDBX_NOTHROW_PURE_FUNCTION bool ends_with(const struct slice &suffix) const noexcept {
2401 return slice_.ends_with(suffix);
2402 }
2403
2405 void clear() noexcept { slice_.assign(silo_.clear(), size_t(0)); }
2406
2408 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2409 slice_.assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2410 }
2411
2413 void shrink_to_fit() { reserve(0, 0); }
2414
2417 void remove_prefix(size_t n) noexcept { slice_.remove_prefix(n); }
2418
2421 void remove_suffix(size_t n) noexcept { slice_.remove_suffix(n); }
2422
2425 void safe_remove_prefix(size_t n) { slice_.safe_remove_prefix(n); }
2426
2429 void safe_remove_suffix(size_t n) { slice_.safe_remove_suffix(n); }
2430
2433 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept {
2434 MDBX_CONSTEXPR_ASSERT(n < size());
2435 return slice_[n];
2436 }
2437
2440 MDBX_CXX11_CONSTEXPR byte &operator[](size_t n) noexcept {
2441 MDBX_CONSTEXPR_ASSERT(n < size());
2442 return byte_ptr()[n];
2443 }
2444
2447 MDBX_CXX14_CONSTEXPR byte at(size_t n) const { return slice_.at(n); }
2448
2451 MDBX_CXX14_CONSTEXPR byte &at(size_t n) {
2452 if (MDBX_UNLIKELY(n >= size()))
2453 MDBX_CXX20_UNLIKELY throw_out_range();
2454 return byte_ptr()[n];
2455 }
2456
2459 MDBX_CXX14_CONSTEXPR struct slice head(size_t n) const noexcept { return slice_.head(n); }
2460
2463 MDBX_CXX14_CONSTEXPR struct slice tail(size_t n) const noexcept { return slice_.tail(n); }
2464
2467 MDBX_CXX14_CONSTEXPR struct slice middle(size_t from, size_t n) const noexcept { return slice_.middle(from, n); }
2468
2471 MDBX_CXX14_CONSTEXPR struct slice safe_head(size_t n) const { return slice_.safe_head(n); }
2472
2475 MDBX_CXX14_CONSTEXPR struct slice safe_tail(size_t n) const { return slice_.safe_tail(n); }
2476
2479 MDBX_CXX14_CONSTEXPR struct slice safe_middle(size_t from, size_t n) const { return slice_.safe_middle(from, n); }
2480
2481 buffer &append(const void *src, size_t bytes) {
2482 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2483 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2484 memcpy(end_byte_ptr(), src, bytes);
2485 slice_.iov_len += bytes;
2486 return *this;
2487 }
2488
2489 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2490
2491 buffer &add_header(const void *src, size_t bytes) {
2492 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2493 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2494 slice_.iov_base = memcpy(static_cast<char *>(slice_.iov_base) - bytes, src, bytes);
2495 slice_.iov_len += bytes;
2496 return *this;
2497 }
2498
2499 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2500
2501 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2502 const size_t wanna_bytes = producer.envisage_result_length();
2503 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2504 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2505 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2506 }
2507
2508 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2509 const size_t wanna_bytes = producer.envisage_result_length();
2510 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2511 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2512 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2513 }
2514
2515 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2516 return append_producer(to_hex(data, uppercase, wrap_width));
2517 }
2518
2519 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2520 return append_producer(to_base58(data, wrap_width));
2521 }
2522
2523 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2524 return append_producer(to_base64(data, wrap_width));
2525 }
2526
2527 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2528 return append_producer(from_hex(data, ignore_spaces));
2529 }
2530
2531 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2532 return append_producer(from_base58(data, ignore_spaces));
2533 }
2534
2535 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2536 return append_producer(from_base64(data, ignore_spaces));
2537 }
2538
2539 buffer &append_u8(uint_fast8_t u8) {
2540 if (MDBX_UNLIKELY(tailroom() < 1))
2541 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2542 *slice_.end_byte_ptr() = uint8_t(u8);
2543 slice_.iov_len += 1;
2544 return *this;
2545 }
2546
2547 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2548
2549 buffer &append_u16(uint_fast16_t u16) {
2550 if (MDBX_UNLIKELY(tailroom() < 2))
2551 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2552 const auto ptr = slice_.end_byte_ptr();
2553 ptr[0] = uint8_t(u16);
2554 ptr[1] = uint8_t(u16 >> 8);
2555 slice_.iov_len += 2;
2556 return *this;
2557 }
2558
2559 buffer &append_u24(uint_fast32_t u24) {
2560 if (MDBX_UNLIKELY(tailroom() < 3))
2561 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2562 const auto ptr = slice_.end_byte_ptr();
2563 ptr[0] = uint8_t(u24);
2564 ptr[1] = uint8_t(u24 >> 8);
2565 ptr[2] = uint8_t(u24 >> 16);
2566 slice_.iov_len += 3;
2567 return *this;
2568 }
2569
2570 buffer &append_u32(uint_fast32_t u32) {
2571 if (MDBX_UNLIKELY(tailroom() < 4))
2572 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2573 const auto ptr = slice_.end_byte_ptr();
2574 ptr[0] = uint8_t(u32);
2575 ptr[1] = uint8_t(u32 >> 8);
2576 ptr[2] = uint8_t(u32 >> 16);
2577 ptr[3] = uint8_t(u32 >> 24);
2578 slice_.iov_len += 4;
2579 return *this;
2580 }
2581
2582 buffer &append_u48(uint_fast64_t u48) {
2583 if (MDBX_UNLIKELY(tailroom() < 6))
2584 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2585 const auto ptr = slice_.end_byte_ptr();
2586 ptr[0] = uint8_t(u48);
2587 ptr[1] = uint8_t(u48 >> 8);
2588 ptr[2] = uint8_t(u48 >> 16);
2589 ptr[3] = uint8_t(u48 >> 24);
2590 ptr[4] = uint8_t(u48 >> 32);
2591 ptr[5] = uint8_t(u48 >> 40);
2592 slice_.iov_len += 6;
2593 return *this;
2594 }
2595
2596 buffer &append_u64(uint_fast64_t u64) {
2597 if (MDBX_UNLIKELY(tailroom() < 8))
2598 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2599 const auto ptr = slice_.end_byte_ptr();
2600 ptr[0] = uint8_t(u64);
2601 ptr[1] = uint8_t(u64 >> 8);
2602 ptr[2] = uint8_t(u64 >> 16);
2603 ptr[3] = uint8_t(u64 >> 24);
2604 ptr[4] = uint8_t(u64 >> 32);
2605 ptr[5] = uint8_t(u64 >> 40);
2606 ptr[6] = uint8_t(u64 >> 48);
2607 ptr[7] = uint8_t(u64 >> 56);
2608 slice_.iov_len += 8;
2609 return *this;
2610 }
2611
2612 //----------------------------------------------------------------------------
2613
2614 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2615 return buffer(::mdbx::slice(text), make_reference);
2616 }
2617
2618#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2619 template <class CHAR, class T>
2620 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2621 return buffer(src, make_reference);
2622 }
2623#endif /* __cpp_lib_string_view >= 201606L */
2624
2625 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2626
2627 template <class CHAR, class T, class A>
2628 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2629 return buffer(src, make_reference);
2630 }
2631
2632 static buffer key_from(silo &&src) noexcept { return buffer(::std::move(src)); }
2633
2634 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2635
2636 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2637
2638 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2639
2640 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2641
2642 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2643
2644 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2645
2646 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2647
2648 static buffer key_from_jsonInteger(const int64_t json_integer) {
2649 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2650 }
2651
2652 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2653
2654 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2655
2656 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2657
2658 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2659
2660 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2661
2662 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2663
2664 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2665};
2666
2667template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2668inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &allocator) {
2669 if (MDBX_LIKELY(!producer.is_empty()))
2671 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), allocator);
2672 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
2673 return result;
2674 }
2675 return buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
2676}
2677
2678template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2679inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &allocator) {
2680 if (MDBX_LIKELY(!producer.is_empty()))
2682 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), allocator);
2683 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
2684 return result;
2685 }
2686 return buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
2687}
2688
2689template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2690inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &allocator) {
2691 string<ALLOCATOR> result(allocator);
2692 if (MDBX_LIKELY(!producer.is_empty()))
2694 result.resize(producer.envisage_result_length());
2695 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
2696 }
2697 return result;
2698}
2699
2700template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2701inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &allocator) {
2702 string<ALLOCATOR> result(allocator);
2703 if (MDBX_LIKELY(!producer.is_empty()))
2705 result.resize(producer.envisage_result_length());
2706 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
2707 }
2708 return result;
2709}
2710
2715 bool done;
2716 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
2717 value_result(const value_result &) noexcept = default;
2718 value_result &operator=(const value_result &) noexcept = default;
2719 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2720 assert(!done || bool(value));
2721 return done;
2722 }
2723};
2724
2727struct pair {
2728 using stl_pair = std::pair<slice, slice>;
2729 slice key, value;
2730 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
2731 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
2732 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
2733 pair(const pair &) noexcept = default;
2734 pair &operator=(const pair &) noexcept = default;
2735 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2736 assert(bool(key) == bool(value));
2737 return key;
2738 }
2739 MDBX_CXX14_CONSTEXPR static pair invalid() noexcept { return pair(slice::invalid(), slice::invalid()); }
2740
2742 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
2743
2745 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
2746 const pair &b) noexcept;
2747 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
2748 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
2749 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
2750 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
2751 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
2752 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
2753};
2754
2757struct pair_result : public pair {
2758 bool done;
2759 MDBX_CXX11_CONSTEXPR pair_result() noexcept : pair(pair::invalid()), done(false) {}
2760 MDBX_CXX11_CONSTEXPR pair_result(const slice &key, const slice &value, bool done) noexcept
2761 : pair(key, value), done(done) {}
2762 pair_result(const pair_result &) noexcept = default;
2763 pair_result &operator=(const pair_result &) noexcept = default;
2764 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2765 assert(!done || (bool(key) && bool(value)));
2766 return done;
2767 }
2768};
2769
2770template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2774 using reservation_policy = CAPACITY_POLICY;
2775 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2777
2780 buffer_pair_spec(const allocator_type &allocator) noexcept : key(allocator), value(allocator) {}
2781
2782 buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &allocator = allocator_type())
2783 : key(key, allocator), value(value, allocator) {}
2784 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2785 const allocator_type &allocator = allocator_type())
2786 : key(key, make_reference, allocator), value(value, make_reference, allocator) {}
2787
2789 : buffer_pair_spec(pair.first, pair.second, allocator) {}
2790 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &allocator = allocator_type())
2791 : buffer_pair_spec(pair.first, pair.second, make_reference, allocator) {}
2792
2793 buffer_pair_spec(const slice &key, const slice &value, const allocator_type &allocator = allocator_type())
2794 : key(key, allocator), value(value, allocator) {}
2795 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2796 const allocator_type &allocator = allocator_type())
2797 : key(key, make_reference, allocator), value(value, make_reference, allocator) {}
2798
2800 : buffer_pair_spec(pair.key, pair.value, allocator) {}
2801 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &allocator = allocator_type())
2802 : buffer_pair_spec(pair.key, pair.value, make_reference, allocator) {}
2803
2804 buffer_pair_spec(const txn &txn, const slice &key, const slice &value,
2805 const allocator_type &allocator = allocator_type())
2806 : key(txn, key, allocator), value(txn, value, allocator) {}
2807 buffer_pair_spec(const txn &txn, const pair &pair, const allocator_type &allocator = allocator_type())
2808 : buffer_pair_spec(txn, pair.key, pair.value, allocator) {}
2809
2810 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2811 : key(::std::move(key)), value(::std::move(value)) {}
2812 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2813 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2814
2818 return key.is_freestanding() && value.is_freestanding();
2819 }
2823 return key.is_reference() || value.is_reference();
2824 }
2829 key.make_freestanding();
2830 value.make_freestanding();
2831 }
2832
2833 operator pair() const noexcept { return pair(key, value); }
2834};
2835
2836template <typename BUFFER>
2838
2840
2841//------------------------------------------------------------------------------
2842
2845enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2846
2848enum class key_mode {
2859 msgpack = -1
2862};
2863
2865 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2866}
2867
2869 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2870}
2871
2873 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2874}
2875
2877 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2878}
2879
2880MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept { return mode == key_mode::msgpack; }
2881
2884enum class value_mode {
2893#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
2926#else
2927 multi_reverse = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_REVERSEDUP),
2928 multi_samelength = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_DUPFIXED),
2929 multi_ordinal = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_DUPFIXED) | uint32_t(MDBX_INTEGERDUP),
2930 multi_reverse_samelength = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_REVERSEDUP) | uint32_t(MDBX_DUPFIXED),
2931#endif
2932 msgpack = -1
2939};
2940
2944
2946 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2947}
2948
2950 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2951}
2952
2954 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2955}
2956
2958 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2959}
2960
2961MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(value_mode mode) noexcept { return mode == value_mode::msgpack; }
2962
2971 MDBX_dbi dbi{0};
2973 MDBX_CXX11_CONSTEXPR map_handle(MDBX_dbi dbi) noexcept : dbi(dbi) {}
2974 map_handle(const map_handle &) noexcept = default;
2975 map_handle &operator=(const map_handle &) noexcept = default;
2976 operator bool() const noexcept { return dbi != 0; }
2977 operator MDBX_dbi() const { return dbi; }
2978
2990};
2991
2993inline comparator default_comparator(key_mode mode) noexcept {
2994 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2995}
2997 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2998}
2999
3006
3017 friend class txn;
3018
3019protected:
3020 MDBX_env *handle_{nullptr};
3021 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
3022
3023public:
3024 MDBX_CXX11_CONSTEXPR env() noexcept = default;
3025 env(const env &) noexcept = default;
3026 inline env &operator=(env &&other) noexcept;
3027 inline env(env &&other) noexcept;
3028 inline ~env() noexcept;
3029
3030 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3031 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
3032 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
3033 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
3034 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
3035
3036 //----------------------------------------------------------------------------
3037
3042
3044 enum : intptr_t {
3045 default_value = -1,
3046 minimal_value = 0,
3047 maximal_value = INTPTR_MAX,
3048 kB = 1000,
3049 MB = kB * 1000,
3050 GB = MB * 1000,
3051#if INTPTR_MAX > 0x7fffFFFFl
3052 TB = GB * 1000,
3053 PB = TB * 1000,
3054 EB = PB * 1000,
3055#endif /* 64-bit intptr_t */
3056 KiB = 1024,
3057 MiB = KiB << 10,
3058 GiB = MiB << 10,
3059#if INTPTR_MAX > 0x7fffFFFFl
3060 TiB = GiB << 10,
3061 PiB = TiB << 10,
3062 EiB = PiB << 10,
3063#endif /* 64-bit intptr_t */
3064 };
3065
3067 struct size {
3068 intptr_t bytes;
3069 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3070 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3071 };
3072
3074 intptr_t size_lower{minimal_value};
3075
3079 intptr_t size_now{default_value};
3080
3091 intptr_t size_upper{maximal_value};
3092
3095 intptr_t growth_step{default_value};
3096
3099 intptr_t shrink_threshold{default_value};
3100
3105 intptr_t pagesize{default_value};
3106
3107 inline geometry &make_fixed(intptr_t size) noexcept;
3108 inline geometry &make_dynamic(intptr_t lower = minimal_value, intptr_t upper = maximal_value) noexcept;
3111 geometry(const geometry &) noexcept = default;
3112 MDBX_CXX11_CONSTEXPR geometry(intptr_t size_lower, intptr_t size_now = default_value,
3113 intptr_t size_upper = maximal_value, intptr_t growth_step = default_value,
3114 intptr_t shrink_threshold = default_value, intptr_t pagesize = default_value) noexcept
3115 : size_lower(size_lower), size_now(size_now), size_upper(size_upper), growth_step(growth_step),
3116 shrink_threshold(shrink_threshold), pagesize(pagesize) {}
3117 };
3118
3120 enum mode {
3122 write_file_io, // don't available on OpenBSD
3124 nested_transactions = write_file_io
3126
3134
3147
3151 bool no_sticky_threads{false};
3154 bool nested_write_transactions{false};
3156 bool exclusive{false};
3158 bool disable_readahead{false};
3160 bool disable_clear_memory{false};
3162 bool enable_validation{false};
3165 operate_options(const operate_options &) noexcept = default;
3168 };
3169
3174 unsigned max_maps{0};
3177 unsigned max_readers{0};
3178 env::mode mode{write_mapped_io};
3179 env::durability durability{robust_synchronous};
3182
3185 operate_parameters(const unsigned max_maps, const unsigned max_readers = 0,
3186 const env::mode mode = env::mode::write_mapped_io,
3187 env::durability durability = env::durability::robust_synchronous,
3189 const env::operate_options &options = env::operate_options()) noexcept
3190 : max_maps(max_maps), max_readers(max_readers), mode(mode), durability(durability), reclaiming(reclaiming),
3191 options(options) {}
3193 operate_parameters(const operate_parameters &) noexcept = default;
3195 MDBX_env_flags_t make_flags(bool accede = true,
3198 bool use_subdirectory = false
3199 ) const;
3202 inline static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept;
3203 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3204 };
3205
3207 inline env::operate_parameters get_operation_parameters() const;
3209 inline env::mode get_mode() const;
3211 inline env::durability get_durability() const;
3213 inline env::reclaiming_options get_reclaiming() const;
3215 inline env::operate_options get_options() const;
3216
3219 bool is_pristine() const;
3220
3222 bool is_empty() const;
3223
3225 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3226
3227 struct limits {
3228 limits() = delete;
3230 static inline size_t pagesize_min() noexcept;
3232 static inline size_t pagesize_max() noexcept;
3235 static inline size_t dbsize_min(intptr_t pagesize);
3238 static inline size_t dbsize_max(intptr_t pagesize);
3241 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3243 static inline size_t key_min(key_mode mode) noexcept;
3246 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3249 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3252 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3255 static inline size_t key_max(const env &, key_mode mode);
3258 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3261 static inline size_t value_min(value_mode) noexcept;
3262
3265 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3268 static inline size_t value_max(intptr_t pagesize, value_mode);
3271 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3274 static inline size_t value_max(const env &, value_mode);
3275
3278 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3281 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3284 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3287 static inline size_t pairsize4page_max(const env &, value_mode);
3288
3291 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3294 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3297 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3300 static inline size_t valsize4page_max(const env &, value_mode);
3301
3304 static inline size_t transaction_size_max(intptr_t pagesize);
3305
3307 static inline size_t max_map_handles(void);
3308 };
3309
3311 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3313 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3315 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3317 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3319 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3321 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3324 size_t transaction_size_max() const { return limits::transaction_size_max(this->get_pagesize()); }
3325
3328#ifdef MDBX_STD_FILESYSTEM_PATH
3329 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3330#endif /* MDBX_STD_FILESYSTEM_PATH */
3331#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3332 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3333 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3334#endif /* Windows */
3335 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3336 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3337
3339 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3340
3352 ensure_unused = MDBX_ENV_ENSURE_UNUSED,
3355 wait_for_unused = MDBX_ENV_WAIT_FOR_UNUSED
3357
3360#ifdef MDBX_STD_FILESYSTEM_PATH
3361 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3362#endif /* MDBX_STD_FILESYSTEM_PATH */
3363#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3364 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3365 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3366#endif /* Windows */
3367 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3368 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3369
3372
3375
3377 inline stat get_stat() const;
3378
3380 size_t get_pagesize() const { return get_stat().ms_psize; }
3381
3383 inline info get_info() const;
3384
3387 inline stat get_stat(const txn &) const;
3388
3391 inline info get_info(const txn &) const;
3392
3394 inline filehandle get_filehandle() const;
3395
3398
3400 inline MDBX_env_flags_t get_flags() const;
3401
3405 inline unsigned max_readers() const;
3406
3409 inline unsigned max_maps() const;
3410
3412 inline void *get_context() const noexcept;
3413
3415 inline env &set_context(void *your_context);
3416
3431 inline env &set_sync_threshold(size_t bytes);
3432
3438 inline size_t sync_threshold() const;
3439
3440#if __cplusplus >= 201103L || defined(DOXYGEN)
3460 inline env &set_sync_period(const duration &period);
3461
3467 inline duration sync_period() const;
3468#endif
3469
3473 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3474
3477 inline unsigned sync_period__seconds_16dot16() const;
3478
3482 inline env &set_sync_period__seconds_double(double seconds);
3483
3486 inline double sync_period__seconds_double() const;
3487
3492 max_maps = MDBX_opt_max_db,
3495 max_readers = MDBX_opt_max_readers,
3498 sync_bytes = MDBX_opt_sync_bytes,
3501 sync_period = MDBX_opt_sync_period,
3503 rp_augment_limit = MDBX_opt_rp_augment_limit,
3505 loose_limit = MDBX_opt_loose_limit,
3507 dp_reserve_limit = MDBX_opt_dp_reserve_limit,
3509 dp_limit = MDBX_opt_txn_dp_limit,
3511 dp_initial = MDBX_opt_txn_dp_initial,
3513 spill_max_denominator = MDBX_opt_spill_max_denominator,
3515 spill_min_denominator = MDBX_opt_spill_min_denominator,
3517 spill_parent4child_denominator = MDBX_opt_spill_parent4child_denominator,
3519 merge_threshold_16dot16_percent = MDBX_opt_merge_threshold_16dot16_percent,
3521 writethrough_threshold = MDBX_opt_writethrough_threshold,
3523 prefault_write_enable = MDBX_opt_prefault_write_enable,
3524 };
3525
3527 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3528
3530 inline uint64_t extra_option(extra_runtime_option option) const;
3531
3533 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3534
3536 inline env &set_geometry(const geometry &size);
3537
3541 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3542
3546 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3547
3566 inline void close_map(const map_handle &);
3567
3570 int slot;
3579 size_t bytes_used;
3588
3589 MDBX_CXX11_CONSTEXPR reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
3590 size_t used, size_t retained) noexcept;
3591 };
3592
3600 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3601
3604 inline unsigned check_readers();
3605
3623 inline env &set_HandleSlowReaders(MDBX_hsr_func *);
3624
3629 inline MDBX_hsr_func *get_HandleSlowReaders() const noexcept;
3630
3632 inline txn_managed start_read() const;
3633
3635 inline txn_managed prepare_read() const;
3636
3638 inline txn_managed start_write(txn &parent);
3639
3641 inline txn_managed start_write(bool dont_wait = false);
3642
3644 inline txn_managed try_start_write();
3645};
3646
3656 using inherited = env;
3658 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3659 void setup(unsigned max_maps, unsigned max_readers = 0);
3660
3661public:
3662 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3663
3665#ifdef MDBX_STD_FILESYSTEM_PATH
3666 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3667#endif /* MDBX_STD_FILESYSTEM_PATH */
3668#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3669 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3670 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3671#endif /* Windows */
3672 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3673 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3674
3680 mdbx_mode_t file_mode_bits{0640};
3681 bool use_subdirectory{false};
3683 create_parameters(const create_parameters &) noexcept = default;
3684 };
3685
3687#ifdef MDBX_STD_FILESYSTEM_PATH
3689 bool accede = true);
3690#endif /* MDBX_STD_FILESYSTEM_PATH */
3691#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3692 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3693 bool accede = true);
3694 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3695 bool accede = true);
3696#endif /* Windows */
3697 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3698 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3699
3713 void close(bool dont_sync = false);
3714
3716 env_managed &operator=(env_managed &&other) noexcept {
3717 if (MDBX_UNLIKELY(handle_))
3718 MDBX_CXX20_UNLIKELY {
3719 assert(handle_ != other.handle_);
3720 close();
3721 }
3722 inherited::operator=(std::move(other));
3723 return *this;
3724 }
3725 env_managed(const env_managed &) = delete;
3727 virtual ~env_managed() noexcept;
3728};
3729
3739protected:
3740 friend class cursor;
3741 MDBX_txn *handle_{nullptr};
3742 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3743
3744public:
3745 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3746 txn(const txn &) noexcept = default;
3747 inline txn &operator=(txn &&other) noexcept;
3748 inline txn(txn &&other) noexcept;
3749 inline ~txn() noexcept;
3750
3751 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3752 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3753 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3754 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3755 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3756
3758 inline ::mdbx::env env() const noexcept;
3760 inline MDBX_txn_flags_t flags() const;
3762 inline uint64_t id() const;
3763
3765 inline void *get_context() const noexcept;
3766
3768 inline txn &set_context(void *your_context);
3769
3771 inline bool is_dirty(const void *ptr) const;
3772
3774 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3775
3777 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3778
3781 inline info get_info(bool scan_reader_lock_table = false) const;
3782
3785 size_t size_max() const { return env().transaction_size_max(); }
3786
3789 size_t size_current() const {
3790 assert(is_readwrite());
3791 return size_t(get_info().txn_space_dirty);
3792 }
3793
3794 //----------------------------------------------------------------------------
3795
3797 inline void reset_reading();
3798
3800 inline void renew_reading();
3801
3803 inline void park_reading(bool autounpark = true);
3804
3807 inline bool unpark_reading(bool restart_if_ousted = true);
3808
3811
3813 inline cursor_managed open_cursor(map_handle map) const;
3814
3816 inline size_t release_all_cursors(bool unbind) const;
3817
3819 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3820
3822 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3823
3825 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3826 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3828 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3829 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3831 inline map_handle open_map(const ::mdbx::slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3832 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3833
3835 inline map_handle open_map_accede(const char *name) const;
3837 inline map_handle open_map_accede(const ::std::string &name) const;
3839 inline map_handle open_map_accede(const ::mdbx::slice &name) const;
3840
3842 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3843 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3845 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3846 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3848 inline map_handle create_map(const ::mdbx::slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3849 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3850
3852 inline void drop_map(map_handle map);
3856 bool drop_map(const char *name, bool throw_if_absent = false);
3860 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3864 bool drop_map(const ::mdbx::slice &name, bool throw_if_absent = false);
3865
3867 inline void clear_map(map_handle map);
3870 bool clear_map(const char *name, bool throw_if_absent = false);
3873 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3876 bool clear_map(const ::mdbx::slice &name, bool throw_if_absent = false);
3877
3879 inline void rename_map(map_handle map, const char *new_name);
3881 inline void rename_map(map_handle map, const ::std::string &new_name);
3883 inline void rename_map(map_handle map, const ::mdbx::slice &new_name);
3887 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3891 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3895 bool rename_map(const ::mdbx::slice &old_name, const ::mdbx::slice &new_name, bool throw_if_absent = false);
3896
3897#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3898
3900 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3901 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3902 return open_map(::mdbx::slice(name), key_mode, value_mode);
3903 }
3905 inline map_handle open_map_accede(const ::std::string_view &name) const;
3907 inline map_handle create_map(const ::std::string_view &name,
3908 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3909 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3910 return create_map(::mdbx::slice(name), key_mode, value_mode);
3911 }
3915 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3916 return drop_map(::mdbx::slice(name), throw_if_absent);
3917 }
3920 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3921 return clear_map(::mdbx::slice(name), throw_if_absent);
3922 }
3924 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3928 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3929 bool throw_if_absent = false) {
3930 return rename_map(::mdbx::slice(old_name), ::mdbx::slice(new_name), throw_if_absent);
3931 }
3932#endif /* __cpp_lib_string_view >= 201606L */
3933
3936 inline map_stat get_map_stat(map_handle map) const;
3939 inline uint32_t get_tree_deepmask(map_handle map) const;
3941 inline map_handle::info get_handle_info(map_handle map) const;
3942
3946 inline txn &put_canary(const canary &);
3949 inline canary get_canary() const;
3950
3953 inline uint64_t sequence(map_handle map) const;
3956 inline uint64_t sequence(map_handle map, uint64_t increment);
3957
3960 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3963 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3966 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3969 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3970
3972 inline slice get(map_handle map, const slice &key) const;
3975 inline slice get(map_handle map, slice key, size_t &values_count) const;
3977 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3980 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3984 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3988 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3989
3990 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3991 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3992 inline void insert(map_handle map, const slice &key, slice value);
3993 inline value_result try_insert(map_handle map, const slice &key, slice value);
3994 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3995 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3996
3997 inline void upsert(map_handle map, const slice &key, const slice &value);
3998 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3999
4000 inline void update(map_handle map, const slice &key, const slice &value);
4001 inline bool try_update(map_handle map, const slice &key, const slice &value);
4002 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
4003 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
4004
4005 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
4006 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
4007 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
4008 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
4009
4011 inline bool erase(map_handle map, const slice &key);
4012
4014 inline bool erase(map_handle map, const slice &key, const slice &value);
4015
4017 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
4018
4020 template <class ALLOCATOR, typename CAPACITY_POLICY>
4022 extract(map_handle map, const slice &key,
4023 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator =
4025
4027 template <class ALLOCATOR, typename CAPACITY_POLICY>
4029 replace(map_handle map, const slice &key, const slice &new_value,
4030 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator =
4032
4033 template <class ALLOCATOR, typename CAPACITY_POLICY>
4035 replace_reserve(map_handle map, const slice &key, slice &new_value,
4036 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator =
4038
4055 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4056 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4057 return append(map, kv.key, kv.value, multivalue_order_preserved);
4058 }
4059
4060 size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length, const void *values_array,
4061 size_t values_count, put_mode mode, bool allow_partial = false);
4062 template <typename VALUE>
4063 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4064 put_mode mode, bool allow_partial = false) {
4065 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4066 !::std::is_array<VALUE>::value,
4067 "Must be a standard layout type!");
4068 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4069 }
4070 template <typename VALUE>
4071 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4072 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4073 }
4074
4075 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4076 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4077 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4078 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4079};
4080
4090 using inherited = txn;
4091 friend class env;
4092 friend class txn;
4094 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4095
4096public:
4097 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4099 txn_managed &operator=(txn_managed &&other) noexcept {
4100 if (MDBX_UNLIKELY(handle_))
4101 MDBX_CXX20_UNLIKELY {
4102 assert(handle_ != other.handle_);
4103 abort();
4104 }
4105 inherited::operator=(std::move(other));
4106 return *this;
4107 }
4108 txn_managed(const txn_managed &) = delete;
4110 ~txn_managed() noexcept;
4111
4112 //----------------------------------------------------------------------------
4113
4116 void abort();
4117
4119 void commit();
4120
4123 void commit_embark_read();
4124
4126
4129 void commit(commit_latency *);
4130
4133 void commit(commit_latency &latency) { return commit(&latency); }
4134
4139 commit_latency result;
4140 commit(&result);
4141 return result;
4142 }
4143};
4144
4153protected:
4154 MDBX_cursor *handle_{nullptr};
4156
4157public:
4158 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4159 cursor(const cursor &) noexcept = default;
4160 inline cursor &operator=(cursor &&other) noexcept;
4161 inline cursor(cursor &&other) noexcept;
4162 inline ~cursor() noexcept;
4163 inline cursor_managed clone(void *your_context = nullptr) const;
4164 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4165 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4166 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4167 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4168 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4169
4170 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4171 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4172
4173 bool is_before_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_before_than(const cursor &other, bool ignore_nested = false) const {
4178 return compare_position(*this, other, ignore_nested) <= 0;
4179 }
4180
4181 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4182 return compare_position(*this, other, ignore_nested) == 0;
4183 }
4184
4185 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4186 return compare_position(*this, other, ignore_nested) > 0;
4187 }
4188
4189 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4190 return compare_position(*this, other, ignore_nested) >= 0;
4191 }
4192
4194 inline void *get_context() const noexcept;
4195
4197 inline cursor &set_context(void *your_context);
4198
4200 first = MDBX_FIRST,
4203 previous = MDBX_PREV,
4204 get_current = MDBX_GET_CURRENT,
4205
4206 multi_prevkey_lastvalue = MDBX_PREV_NODUP,
4207 multi_currentkey_firstvalue = MDBX_FIRST_DUP,
4208 multi_currentkey_prevvalue = MDBX_PREV_DUP,
4209 multi_currentkey_nextvalue = MDBX_NEXT_DUP,
4210 multi_currentkey_lastvalue = MDBX_LAST_DUP,
4211 multi_nextkey_firstvalue = MDBX_NEXT_NODUP,
4212
4213 multi_find_pair = MDBX_GET_BOTH,
4214 multi_exactkey_lowerboundvalue = MDBX_GET_BOTH_RANGE,
4215
4216 seek_key = MDBX_SET,
4217 key_exact = MDBX_SET_KEY,
4218 key_lowerbound = MDBX_SET_RANGE,
4219
4220 /* Doubtless cursor positioning at a specified key. */
4221 key_lesser_than = MDBX_TO_KEY_LESSER_THAN,
4222 key_lesser_or_equal = MDBX_TO_KEY_LESSER_OR_EQUAL,
4224 key_greater_or_equal = MDBX_TO_KEY_GREATER_OR_EQUAL,
4225 key_greater_than = MDBX_TO_KEY_GREATER_THAN,
4226
4227 /* Doubtless cursor positioning at a specified key-value pair
4228 * for dupsort/multi-value hives. */
4229 multi_exactkey_value_lesser_than = MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN,
4230 multi_exactkey_value_lesser_or_equal = MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL,
4231 multi_exactkey_value_equal = MDBX_TO_EXACT_KEY_VALUE_EQUAL,
4232 multi_exactkey_value_greater_or_equal = MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL,
4233 multi_exactkey_value_greater = MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN,
4234
4235 pair_lesser_than = MDBX_TO_PAIR_LESSER_THAN,
4236 pair_lesser_or_equal = MDBX_TO_PAIR_LESSER_OR_EQUAL,
4238 pair_exact = pair_equal,
4239 pair_greater_or_equal = MDBX_TO_PAIR_GREATER_OR_EQUAL,
4240 pair_greater_than = MDBX_TO_PAIR_GREATER_THAN,
4241
4242 batch_samelength = MDBX_GET_MULTIPLE,
4243 batch_samelength_next = MDBX_NEXT_MULTIPLE,
4244 batch_samelength_previous = MDBX_PREV_MULTIPLE
4246
4247 struct move_result : public pair_result {
4248 inline move_result(const cursor &cursor, bool throw_notfound);
4249 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4250 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4251 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4252 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4253 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4254 bool throw_notfound);
4255 move_result(const move_result &) noexcept = default;
4256 move_result &operator=(const move_result &) noexcept = default;
4257 };
4258
4259 struct estimate_result : public pair {
4262 : estimate_result(cursor, operation, slice::invalid(), slice::invalid()) {}
4263 estimate_result(const cursor &cursor, move_operation operation, const slice &key)
4264 : estimate_result(cursor, operation, key, slice::invalid()) {}
4265 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4266 estimate_result(const estimate_result &) noexcept = default;
4267 estimate_result &operator=(const estimate_result &) noexcept = default;
4268 };
4269
4270protected:
4271 /* fake const, i.e. for some move/get operations */
4272 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4273
4274 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4275
4276public:
4277 template <typename CALLABLE_PREDICATE>
4278 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4279 struct wrapper : public exception_thunk {
4280 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4281 auto thunk = static_cast<wrapper *>(context);
4282 assert(thunk->is_clean());
4283 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4284 try {
4285 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4286 } catch (... /* capture any exception to rethrow it over C code */) {
4287 thunk->capture();
4288 return MDBX_RESULT_TRUE;
4289 }
4290 }
4291 } thunk;
4292 return error::boolean_or_throw(
4293 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4294 thunk);
4295 }
4296
4297 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4298 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4299 }
4300
4301 template <typename CALLABLE_PREDICATE>
4302 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4303 move_operation turn = next) {
4304 struct wrapper : public exception_thunk {
4305 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4306 auto thunk = static_cast<wrapper *>(context);
4307 assert(thunk->is_clean());
4308 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4309 try {
4310 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4311 } catch (... /* capture any exception to rethrow it over C code */) {
4312 thunk->capture();
4313 return MDBX_RESULT_TRUE;
4314 }
4315 }
4316 } thunk;
4317 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4318 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4319 thunk);
4320 }
4321
4322 template <typename CALLABLE_PREDICATE>
4323 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4324 move_operation turn = next) {
4325 struct wrapper : public exception_thunk {
4326 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4327 auto thunk = static_cast<wrapper *>(context);
4328 assert(thunk->is_clean());
4329 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4330 try {
4331 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4332 } catch (... /* capture any exception to rethrow it over C code */) {
4333 thunk->capture();
4334 return MDBX_RESULT_TRUE;
4335 }
4336 }
4337 } thunk;
4338 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4339 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4340 thunk);
4341 }
4342
4343 move_result move(move_operation operation, bool throw_notfound) {
4344 return move_result(*this, operation, throw_notfound);
4345 }
4346 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4347 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4348 }
4349 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4350 return move_result(*this, operation, key, value, throw_notfound);
4351 }
4352 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4353 return move(operation, &key, &value, throw_notfound);
4354 }
4355
4356 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4357 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4358 move_result to_previous_last_multi(bool throw_notfound = true) {
4359 return move(multi_prevkey_lastvalue, throw_notfound);
4360 }
4361 move_result to_current_first_multi(bool throw_notfound = true) {
4362 return move(multi_currentkey_firstvalue, throw_notfound);
4363 }
4364 move_result to_current_prev_multi(bool throw_notfound = true) {
4365 return move(multi_currentkey_prevvalue, throw_notfound);
4366 }
4367 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4368 move_result to_current_next_multi(bool throw_notfound = true) {
4369 return move(multi_currentkey_nextvalue, throw_notfound);
4370 }
4371 move_result to_current_last_multi(bool throw_notfound = true) {
4372 return move(multi_currentkey_lastvalue, throw_notfound);
4373 }
4374 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4375 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4376 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4377
4378 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4379 return move(key_lesser_than, key, throw_notfound);
4380 }
4381 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4382 return move(key_lesser_or_equal, key, throw_notfound);
4383 }
4384 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4385 return move(key_equal, key, throw_notfound);
4386 }
4387 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4388 return move(key_exact, key, throw_notfound);
4389 }
4390 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4391 return move(key_greater_or_equal, key, throw_notfound);
4392 }
4393 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4394 return move(key_greater_than, key, throw_notfound);
4395 }
4396
4397 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4398 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4399 }
4400 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4401 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4402 }
4403 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4404 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4405 }
4406 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4407 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4408 }
4409 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4410 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4411 }
4412
4413 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4414 return move(pair_lesser_than, key, value, throw_notfound);
4415 }
4416 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4417 return move(pair_lesser_or_equal, key, value, throw_notfound);
4418 }
4419 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4420 return move(pair_equal, key, value, throw_notfound);
4421 }
4422 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4423 return move(pair_exact, key, value, throw_notfound);
4424 }
4425 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4426 return move(pair_greater_or_equal, key, value, throw_notfound);
4427 }
4428 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4429 return move(pair_greater_than, key, value, throw_notfound);
4430 }
4431
4432 inline bool seek(const slice &key);
4433 inline move_result find(const slice &key, bool throw_notfound = true);
4434 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4435 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4436
4438 inline size_t count_multivalue() const;
4439
4440 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4441 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4442 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4443
4444 inline move_result get_multiple_samelength(const slice &key, bool throw_notfound = true) {
4445 return move(batch_samelength, key, throw_notfound);
4446 }
4447
4448 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4449 return move(batch_samelength, throw_notfound);
4450 }
4451
4452 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4453 return move(batch_samelength_next, throw_notfound);
4454 }
4455
4456 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4457 return move(batch_samelength_previous, throw_notfound);
4458 }
4459
4460 inline bool eof() const;
4461 inline bool on_first() const;
4462 inline bool on_last() const;
4463 inline bool on_first_multival() const;
4464 inline bool on_last_multival() const;
4465 inline estimate_result estimate(const slice &key, const slice &value) const;
4466 inline estimate_result estimate(const slice &key) const;
4467 inline estimate_result estimate(move_operation operation) const;
4468 inline estimate_result estimate(move_operation operation, slice &key) const;
4469
4470 //----------------------------------------------------------------------------
4471
4474 inline void renew(const ::mdbx::txn &txn);
4475
4478 inline void bind(const ::mdbx::txn &txn, ::mdbx::map_handle map_handle);
4479
4481 inline void unbind();
4482
4484 inline ::mdbx::txn txn() const;
4485 inline map_handle map() const;
4486
4487 inline operator ::mdbx::txn() const { return txn(); }
4488 inline operator ::mdbx::map_handle() const { return map(); }
4489
4490 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4491 inline void put(const slice &key, slice value, put_mode mode);
4492 inline void insert(const slice &key, slice value);
4493 inline value_result try_insert(const slice &key, slice value);
4494 inline slice insert_reserve(const slice &key, size_t value_length);
4495 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4496
4497 inline void upsert(const slice &key, const slice &value);
4498 inline slice upsert_reserve(const slice &key, size_t value_length);
4499
4500 inline void update(const slice &key, const slice &value);
4501 inline bool try_update(const slice &key, const slice &value);
4502 inline slice update_reserve(const slice &key, size_t value_length);
4503 inline value_result try_update_reserve(const slice &key, size_t value_length);
4504
4505 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4506 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4507 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4508 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4509
4512 inline bool erase(bool whole_multivalue = false);
4513
4517 inline bool erase(const slice &key, bool whole_multivalue = true);
4518
4521 inline bool erase(const slice &key, const slice &value);
4522};
4523
4532 using inherited = cursor;
4533 friend class txn;
4536
4537public:
4539 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4540 if (MDBX_UNLIKELY(!handle_))
4541 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4542 }
4543
4545 void close();
4546
4549 if (MDBX_UNLIKELY(handle_))
4550 MDBX_CXX20_UNLIKELY {
4551 assert(handle_ != other.handle_);
4552 close();
4553 }
4554 inherited::operator=(std::move(other));
4555 return *this;
4556 }
4557
4560 ~cursor_managed() noexcept { ::mdbx_cursor_close(handle_); }
4561};
4562
4563//------------------------------------------------------------------------------
4564
4565LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
4566LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
4567LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
4568template <class ALLOCATOR, typename CAPACITY_POLICY>
4569inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
4570 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
4571}
4572LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
4573LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
4574LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
4575LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
4576LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
4577LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
4578LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
4579LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
4580
4581LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
4582LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
4583LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
4584inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
4585
4586//==============================================================================
4587//
4588// Inline body of the libmdbx C++ API
4589//
4590
4591MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4592MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4593
4594static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4595#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4596 if (::std::is_constant_evaluated()) {
4597 for (size_t i = 0; c_str; ++i)
4598 if (!c_str[i])
4599 return i;
4600 return 0;
4601 }
4602#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4603#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4604 return c_str ? ::std::string_view(c_str).length() : 0;
4605#else
4606 return c_str ? ::std::strlen(c_str) : 0;
4607#endif
4608}
4609
4610MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4611#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4612 if (::std::is_constant_evaluated()) {
4613 for (size_t i = 0; i < bytes; ++i)
4614 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4615 return dest;
4616 } else
4617#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4618 return ::std::memcpy(dest, src, bytes);
4619}
4620
4621static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4622#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4623 if (::std::is_constant_evaluated()) {
4624 for (size_t i = 0; i < bytes; ++i) {
4625 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4626 if (diff)
4627 return diff;
4628 }
4629 return 0;
4630 } else
4631#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4632 return ::std::memcmp(a, b, bytes);
4633}
4634
4635static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
4636 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
4637 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4638 return bytes;
4639}
4640
4641static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
4642 return check_length(check_length(headroom) + check_length(payload));
4643}
4644
4645MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
4646 return check_length(check_length(headroom, payload) + check_length(tailroom));
4647}
4648
4649inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4650
4651inline void exception_thunk::capture() noexcept {
4652 assert(is_clean());
4653 captured_ = ::std::current_exception();
4654}
4655
4656inline void exception_thunk::rethrow_captured() const {
4657 if (captured_)
4658 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4659}
4660
4661//------------------------------------------------------------------------------
4662
4663MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4664
4665inline error &error::operator=(MDBX_error_t error_code) noexcept {
4666 code_ = error_code;
4667 return *this;
4668}
4669
4670MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4671
4672MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4673
4674MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4675
4676MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4677
4678MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4679
4680MDBX_CXX11_CONSTEXPR bool error::is_failure() const noexcept {
4681 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4682}
4683
4684MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4685
4686MDBX_CXX11_CONSTEXPR bool error::is_mdbx_error() const noexcept {
4687 return (code() >= MDBX_FIRST_LMDB_ERRCODE && code() <= MDBX_LAST_LMDB_ERRCODE) ||
4688 (code() >= MDBX_FIRST_ADDED_ERRCODE && code() <= MDBX_LAST_ADDED_ERRCODE);
4689}
4690
4691inline void error::throw_exception(int error_code) {
4692 const error trouble(static_cast<MDBX_error_t>(error_code));
4693 trouble.throw_exception();
4694}
4695
4696inline void error::throw_on_failure() const {
4697 if (MDBX_UNLIKELY(is_failure()))
4698 MDBX_CXX20_UNLIKELY throw_exception();
4699}
4700
4701inline void error::success_or_throw() const {
4702 if (MDBX_UNLIKELY(!is_success()))
4703 MDBX_CXX20_UNLIKELY throw_exception();
4704}
4705
4706inline void error::success_or_throw(const exception_thunk &thunk) const {
4707 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4708 if (MDBX_UNLIKELY(!is_success())) {
4709 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4710 else throw_exception();
4711 }
4712}
4713
4714inline void error::panic_on_failure(const char *context_where, const char *func_who) const noexcept {
4715 if (MDBX_UNLIKELY(is_failure()))
4716 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4717}
4718
4719inline void error::success_or_panic(const char *context_where, const char *func_who) const noexcept {
4720 if (MDBX_UNLIKELY(!is_success()))
4721 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4722}
4723
4724inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4725 if (MDBX_UNLIKELY(ptr == nullptr))
4726 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4727}
4728
4729inline void error::throw_on_failure(int error_code) {
4730 error rc(static_cast<MDBX_error_t>(error_code));
4731 rc.throw_on_failure();
4732}
4733
4734inline void error::success_or_throw(MDBX_error_t error_code) {
4735 error rc(error_code);
4736 rc.success_or_throw();
4737}
4738
4739inline bool error::boolean_or_throw(int error_code) {
4740 switch (error_code) {
4741 case MDBX_RESULT_FALSE:
4742 return false;
4743 case MDBX_RESULT_TRUE:
4744 return true;
4745 default:
4746 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4747 }
4748}
4749
4750inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4751 error rc(static_cast<MDBX_error_t>(error_code));
4752 rc.success_or_throw(thunk);
4753}
4754
4755inline void error::panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept {
4756 error rc(static_cast<MDBX_error_t>(error_code));
4757 rc.panic_on_failure(context_where, func_who);
4758}
4759
4760inline void error::success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept {
4761 error rc(static_cast<MDBX_error_t>(error_code));
4762 rc.success_or_panic(context_where, func_who);
4763}
4764
4765inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4766 if (MDBX_UNLIKELY(!thunk.is_clean()))
4767 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4768 return boolean_or_throw(error_code);
4769}
4770
4771//------------------------------------------------------------------------------
4772
4773MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4774
4775MDBX_CXX14_CONSTEXPR slice::slice(const void *ptr, size_t bytes)
4776 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4777
4778MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4779 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4780
4781MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, ::mdbx::strlen(c_str)) {}
4782
4783MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4784
4785MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4786
4787MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4788
4789inline slice &slice::assign(const void *ptr, size_t bytes) {
4790 iov_base = const_cast<void *>(ptr);
4791 iov_len = check_length(bytes);
4792 return *this;
4793}
4794
4795inline slice &slice::assign(const slice &src) noexcept {
4796 iov_base = src.iov_base;
4797 iov_len = src.iov_len;
4798 return *this;
4799}
4800
4801inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4802
4803slice &slice::assign(slice &&src) noexcept {
4804 assign(src);
4805 src.invalidate();
4806 return *this;
4807}
4808
4810 assign(src.iov_base, src.iov_len);
4811 src.iov_base = nullptr;
4812 return *this;
4813}
4814
4815inline slice &slice::assign(const void *begin, const void *end) {
4816 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4817}
4818
4819inline slice &slice::assign(const char *c_str) { return assign(c_str, ::mdbx::strlen(c_str)); }
4820
4821inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4822
4823inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4824
4825inline void slice::swap(slice &other) noexcept {
4826 const auto temp = *this;
4827 *this = other;
4828 other = temp;
4829}
4830
4831MDBX_CXX11_CONSTEXPR const ::mdbx::byte *slice::byte_ptr() const noexcept {
4832 return static_cast<const byte *>(iov_base);
4833}
4834
4835MDBX_CXX11_CONSTEXPR const ::mdbx::byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4836
4837MDBX_CXX11_CONSTEXPR ::mdbx::byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4838
4839MDBX_CXX11_CONSTEXPR ::mdbx::byte *slice::end_byte_ptr() noexcept { return byte_ptr() + length(); }
4840
4841MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4842
4843MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4844
4845MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4846
4848
4849MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4850
4851MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4852
4853MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4854
4855MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4856
4857MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4858
4860 iov_len = check_length(bytes);
4861 return *this;
4862}
4863
4865 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4866 return set_length(static_cast<const char *>(ptr) - char_ptr());
4867}
4868
4869MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4870
4871MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4872
4873MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4874
4875MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4876
4877MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4878
4880 iov_base = nullptr;
4881 iov_len = 0;
4882}
4883
4884inline void slice::remove_prefix(size_t n) noexcept {
4885 assert(n <= size());
4886 iov_base = static_cast<byte *>(iov_base) + n;
4887 iov_len -= n;
4888}
4889
4890inline void slice::safe_remove_prefix(size_t n) {
4891 if (MDBX_UNLIKELY(n > size()))
4892 MDBX_CXX20_UNLIKELY throw_out_range();
4893 remove_prefix(n);
4894}
4895
4896inline void slice::remove_suffix(size_t n) noexcept {
4897 assert(n <= size());
4898 iov_len -= n;
4899}
4900
4901inline void slice::safe_remove_suffix(size_t n) {
4902 if (MDBX_UNLIKELY(n > size()))
4903 MDBX_CXX20_UNLIKELY throw_out_range();
4904 remove_suffix(n);
4905}
4906
4907MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4908 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4909}
4910
4911MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4912 return length() >= suffix.length() &&
4913 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4914}
4915
4917 size_t h = length() * 3977471;
4918 for (size_t i = 0; i < length(); ++i)
4919 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4920 return h ^ 3863194411 * (h >> 11);
4921}
4922
4923MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4924 MDBX_CONSTEXPR_ASSERT(n < size());
4925 return byte_ptr()[n];
4926}
4927
4928MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4929 if (MDBX_UNLIKELY(n >= size()))
4930 MDBX_CXX20_UNLIKELY throw_out_range();
4931 return byte_ptr()[n];
4932}
4933
4934MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4935 MDBX_CONSTEXPR_ASSERT(n <= size());
4936 return slice(data(), n);
4937}
4938
4939MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4940 MDBX_CONSTEXPR_ASSERT(n <= size());
4941 return slice(char_ptr() + size() - n, n);
4942}
4943
4944MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4945 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4946 return slice(char_ptr() + from, n);
4947}
4948
4950 if (MDBX_UNLIKELY(n > size()))
4951 MDBX_CXX20_UNLIKELY throw_out_range();
4952 return head(n);
4953}
4954
4956 if (MDBX_UNLIKELY(n > size()))
4957 MDBX_CXX20_UNLIKELY throw_out_range();
4958 return tail(n);
4959}
4960
4961MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4962 if (MDBX_UNLIKELY(n > max_length))
4963 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4964 if (MDBX_UNLIKELY(from + n > size()))
4965 MDBX_CXX20_UNLIKELY throw_out_range();
4966 return middle(from, n);
4967}
4968
4969MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4970 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4971 return diff ? diff
4972 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4973 : memcmp(a.data(), b.data(), a.length());
4974}
4975
4977 const size_t shortest = ::std::min(a.length(), b.length());
4978 if (MDBX_LIKELY(shortest > 0))
4980 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4981 if (MDBX_LIKELY(diff != 0))
4982 MDBX_CXX20_LIKELY return diff;
4983 }
4984 return intptr_t(a.length()) - intptr_t(b.length());
4985}
4986
4988 return slice::compare_fast(a, b) == 0;
4989}
4990
4992 return slice::compare_lexicographically(a, b) < 0;
4993}
4994
4996 return slice::compare_lexicographically(a, b) > 0;
4997}
4998
5000 return slice::compare_lexicographically(a, b) <= 0;
5001}
5002
5004 return slice::compare_lexicographically(a, b) >= 0;
5005}
5006
5008 return slice::compare_fast(a, b) != 0;
5009}
5010
5011template <class ALLOCATOR>
5012inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &allocator) const {
5013 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(allocator);
5014}
5015
5016template <class ALLOCATOR>
5017inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &allocator) const {
5018 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(allocator);
5019}
5020
5021template <class ALLOCATOR>
5022inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &allocator) const {
5023 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(allocator);
5024}
5025
5026template <class ALLOCATOR, class CAPACITY_POLICY>
5027inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5028 const ALLOCATOR &allocator) const {
5029 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5030}
5031
5032template <class ALLOCATOR, class CAPACITY_POLICY>
5033inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &allocator) const {
5034 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5035}
5036
5037template <class ALLOCATOR, class CAPACITY_POLICY>
5038inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &allocator) const {
5039 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5040}
5041
5042template <class ALLOCATOR, class CAPACITY_POLICY>
5043inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5044 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5045}
5046
5047template <class ALLOCATOR, class CAPACITY_POLICY>
5048inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5049 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5050}
5051
5052template <class ALLOCATOR, class CAPACITY_POLICY>
5053inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5054 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5055}
5056
5057MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5058 return !from_hex(*this, ignore_spaces).is_erroneous();
5059}
5060
5061MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5062 return !from_base58(*this, ignore_spaces).is_erroneous();
5063}
5064
5065MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5066 return !from_base64(*this, ignore_spaces).is_erroneous();
5067}
5068
5069//------------------------------------------------------------------------------
5070
5071MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5072 const auto diff = slice::compare_fast(a.key, b.key);
5073 return diff ? diff : slice::compare_fast(a.value, b.value);
5074}
5075
5076MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5077 const auto diff = slice::compare_lexicographically(a.key, b.key);
5078 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5079}
5080
5082 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5083 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5084 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5085}
5086
5088 return pair::compare_lexicographically(a, b) < 0;
5089}
5090
5092 return pair::compare_lexicographically(a, b) > 0;
5093}
5094
5096 return pair::compare_lexicographically(a, b) <= 0;
5097}
5098
5100 return pair::compare_lexicographically(a, b) >= 0;
5101}
5102
5104 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5105 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5106 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5107}
5108
5109//------------------------------------------------------------------------------
5110
5111template <class ALLOCATOR, typename CAPACITY_POLICY>
5113 const allocator_type &allocator)
5114 : buffer(src, !txn.is_dirty(src.data()), allocator) {}
5115
5116//------------------------------------------------------------------------------
5117
5120
5124
5128
5129//------------------------------------------------------------------------------
5130
5131MDBX_CXX11_CONSTEXPR env::env(MDBX_env *ptr) noexcept : handle_(ptr) {}
5132
5133inline env &env::operator=(env &&other) noexcept {
5134 handle_ = other.handle_;
5135 other.handle_ = nullptr;
5136 return *this;
5137}
5138
5139inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5140
5141inline env::~env() noexcept {
5142#ifndef NDEBUG
5143 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5144#endif
5145}
5146
5147MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5148
5149MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5150
5151MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5152
5153MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5154
5155MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5156
5158 size_lower = size_now = size_upper = size;
5159 growth_step = shrink_threshold = 0;
5160 return *this;
5161}
5162
5163inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5164 size_now = size_lower = lower;
5165 size_upper = upper;
5166 growth_step = shrink_threshold = default_value;
5167 return *this;
5168}
5169
5173
5177
5178inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5179
5180inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5181
5182inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5183 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5184 if (result < 0)
5185 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5186 return static_cast<size_t>(result);
5187}
5188
5189inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5190 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5191 if (result < 0)
5192 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5193 return static_cast<size_t>(result);
5194}
5195
5196inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5197
5198inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5199
5200inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5201 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5202 if (result < 0)
5203 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5204 return static_cast<size_t>(result);
5205}
5206
5207inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5208 return key_max(pagesize, MDBX_db_flags_t(mode));
5209}
5210
5212 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5213 if (result < 0)
5214 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5215 return static_cast<size_t>(result);
5216}
5217
5218inline size_t env::limits::key_max(const env &env, key_mode mode) { return key_max(env, MDBX_db_flags_t(mode)); }
5219
5220inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5221
5222inline size_t env::limits::value_min(value_mode mode) noexcept { return value_min(MDBX_db_flags_t(mode)); }
5223
5224inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5225 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5226 if (result < 0)
5227 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5228 return static_cast<size_t>(result);
5229}
5230
5231inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5232 return value_max(pagesize, MDBX_db_flags_t(mode));
5233}
5234
5236 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5237 if (result < 0)
5238 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5239 return static_cast<size_t>(result);
5240}
5241
5242inline size_t env::limits::value_max(const env &env, value_mode mode) { return value_max(env, MDBX_db_flags_t(mode)); }
5243
5244inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5245 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5246 if (result < 0)
5247 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5248 return static_cast<size_t>(result);
5249}
5250
5251inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5252 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5253}
5254
5256 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5257 if (result < 0)
5258 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5259 return static_cast<size_t>(result);
5260}
5261
5263 return pairsize4page_max(env, MDBX_db_flags_t(mode));
5264}
5265
5266inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5267 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5268 if (result < 0)
5269 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5270 return static_cast<size_t>(result);
5271}
5272
5273inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5274 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5275}
5276
5278 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5279 if (result < 0)
5280 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5281 return static_cast<size_t>(result);
5282}
5283
5285 return valsize4page_max(env, MDBX_db_flags_t(mode));
5286}
5287
5288inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5289 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5290 if (result < 0)
5291 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5292 return static_cast<size_t>(result);
5293}
5294
5295inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5296
5298 const auto flags = get_flags();
5299 return operate_parameters(max_maps(), max_readers(), operate_parameters::mode_from_flags(flags),
5300 operate_parameters::durability_from_flags(flags),
5301 operate_parameters::reclaiming_from_flags(flags),
5302 operate_parameters::options_from_flags(flags));
5303}
5304
5305inline env::mode env::get_mode() const { return operate_parameters::mode_from_flags(get_flags()); }
5306
5310
5314
5318
5319inline env::stat env::get_stat() const {
5320 env::stat r;
5321 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5322 return r;
5323}
5324
5325inline env::stat env::get_stat(const txn &txn) const {
5326 env::stat r;
5327 error::success_or_throw(::mdbx_env_stat_ex(handle_, txn, &r, sizeof(r)));
5328 return r;
5329}
5330
5331inline env::info env::get_info() const {
5332 env::info r;
5333 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5334 return r;
5335}
5336
5337inline env::info env::get_info(const txn &txn) const {
5338 env::info r;
5339 error::success_or_throw(::mdbx_env_info_ex(handle_, txn, &r, sizeof(r)));
5340 return r;
5341}
5342
5344 filehandle fd;
5346 return fd;
5347}
5348
5350 unsigned bits = 0;
5352 return MDBX_env_flags_t(bits);
5353}
5354
5355inline unsigned env::max_readers() const {
5356 unsigned r;
5358 return r;
5359}
5360
5361inline unsigned env::max_maps() const {
5362 unsigned r;
5364 return r;
5365}
5366
5367inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5368
5369inline env &env::set_context(void *ptr) {
5371 return *this;
5372}
5373
5374inline env &env::set_sync_threshold(size_t bytes) {
5376 return *this;
5377}
5378
5379inline size_t env::sync_threshold() const {
5380 size_t bytes;
5382 return bytes;
5383}
5384
5385inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5386 error::success_or_throw(::mdbx_env_set_syncperiod(handle_, seconds_16dot16));
5387 return *this;
5388}
5389
5390inline unsigned env::sync_period__seconds_16dot16() const {
5391 unsigned seconds_16dot16;
5392 error::success_or_throw(::mdbx_env_get_syncperiod(handle_, &seconds_16dot16));
5393 return seconds_16dot16;
5394}
5395
5397 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5398}
5399
5400inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5401
5402#if __cplusplus >= 201103L
5403inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5404
5405inline duration env::sync_period() const { return duration(sync_period__seconds_16dot16()); }
5406#endif
5407
5408inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5410 return *this;
5411}
5412
5413inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5414 uint64_t value;
5416 return value;
5417}
5418
5421 return *this;
5422}
5423
5424inline env &env::set_geometry(const geometry &geo) {
5426 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5427 return *this;
5428}
5429
5430inline bool env::sync_to_disk(bool force, bool nonblock) {
5431 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5432 switch (err) {
5433 case MDBX_SUCCESS /* flush done */:
5434 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5435 return true;
5436 case MDBX_BUSY /* the environment is used by other thread */:
5437 return false;
5438 default:
5439 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5440 }
5441}
5442
5443inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5444
5446env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5447 size_t retained) noexcept
5448 : slot(slot), pid(pid), thread(thread), transaction_id(txnid), transaction_lag(lag), bytes_used(used),
5449 bytes_retained(retained) {}
5450
5451template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5452 struct reader_visitor_thunk : public exception_thunk {
5453 VISITOR &visitor_;
5454 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5455 size_t used, size_t retained) noexcept {
5456 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5457 assert(thunk->is_clean());
5458 try {
5459 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5460 return loop_control(thunk->visitor_(info, number));
5461 } catch (... /* capture any exception to rethrow it over C code */) {
5462 thunk->capture();
5463 return loop_control::exit_loop;
5464 }
5465 }
5466 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5467 };
5468 reader_visitor_thunk thunk(visitor);
5469 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5470 thunk.rethrow_captured();
5471 return rc;
5472}
5473
5474inline unsigned env::check_readers() {
5475 int dead_count;
5476 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5477 assert(dead_count >= 0);
5478 return static_cast<unsigned>(dead_count);
5479}
5480
5483 return *this;
5484}
5485
5486inline MDBX_hsr_func *env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5487
5489 ::MDBX_txn *ptr;
5491 assert(ptr != nullptr);
5492 return txn_managed(ptr);
5493}
5494
5496 ::MDBX_txn *ptr;
5498 assert(ptr != nullptr);
5499 return txn_managed(ptr);
5500}
5501
5502inline txn_managed env::start_write(bool dont_wait) {
5503 ::MDBX_txn *ptr;
5504 error::success_or_throw(::mdbx_txn_begin(handle_, nullptr, dont_wait ? MDBX_TXN_TRY : MDBX_TXN_READWRITE, &ptr));
5505 assert(ptr != nullptr);
5506 return txn_managed(ptr);
5507}
5508
5510 ::MDBX_txn *ptr;
5512 assert(ptr != nullptr);
5513 return txn_managed(ptr);
5514}
5515
5516inline txn_managed env::try_start_write() { return start_write(true); }
5517
5518//------------------------------------------------------------------------------
5519
5520MDBX_CXX11_CONSTEXPR txn::txn(MDBX_txn *ptr) noexcept : handle_(ptr) {}
5521
5522inline txn &txn::operator=(txn &&other) noexcept {
5523 handle_ = other.handle_;
5524 other.handle_ = nullptr;
5525 return *this;
5526}
5527
5528inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5529
5530inline txn::~txn() noexcept {
5531#ifndef NDEBUG
5532 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5533#endif
5534}
5535
5536MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5537
5538MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5539
5540MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5541
5542MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5543
5544MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5545
5546inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5547
5548inline txn &txn::set_context(void *ptr) {
5550 return *this;
5551}
5552
5553inline bool txn::is_dirty(const void *ptr) const {
5554 int err = ::mdbx_is_dirty(handle_, ptr);
5555 switch (err) {
5556 default:
5557 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5558 case MDBX_RESULT_TRUE:
5559 return true;
5560 case MDBX_RESULT_FALSE:
5561 return false;
5562 }
5563}
5564
5565inline ::mdbx::env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5566
5568 const int bits = mdbx_txn_flags(handle_);
5570 return static_cast<MDBX_txn_flags_t>(bits);
5571}
5572
5573inline uint64_t txn::id() const {
5574 const uint64_t txnid = mdbx_txn_id(handle_);
5576 return txnid;
5577}
5578
5580
5582
5583inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5584
5585inline bool txn::unpark_reading(bool restart_if_ousted) {
5586 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5587}
5588
5589inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5590 txn::info r;
5591 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5592 return r;
5593}
5594
5596 MDBX_cursor *ptr;
5597 error::success_or_throw(::mdbx_cursor_open(handle_, map.dbi, &ptr));
5598 return cursor_managed(ptr);
5599}
5600
5601inline size_t txn::release_all_cursors(bool unbind) const {
5602 int err = ::mdbx_txn_release_all_cursors(handle_, unbind);
5603 if (MDBX_UNLIKELY(err < 0))
5604 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5605 return size_t(err);
5606}
5607
5608inline ::mdbx::map_handle txn::open_map(const ::mdbx::slice &name, const ::mdbx::key_mode key_mode,
5609 const ::mdbx::value_mode value_mode) const {
5613 assert(map.dbi != 0);
5614 return map;
5615}
5616
5617inline ::mdbx::map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5618 const ::mdbx::value_mode value_mode) const {
5622 assert(map.dbi != 0);
5623 return map;
5624}
5625
5626inline ::mdbx::map_handle txn::open_map_accede(const ::mdbx::slice &name) const {
5629 assert(map.dbi != 0);
5630 return map;
5631}
5632
5633inline ::mdbx::map_handle txn::open_map_accede(const char *name) const {
5636 assert(map.dbi != 0);
5637 return map;
5638}
5639
5640inline ::mdbx::map_handle txn::create_map(const ::mdbx::slice &name, const ::mdbx::key_mode key_mode,
5641 const ::mdbx::value_mode value_mode) {
5645 assert(map.dbi != 0);
5646 return map;
5647}
5648
5649inline ::mdbx::map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5650 const ::mdbx::value_mode value_mode) {
5654 assert(map.dbi != 0);
5655 return map;
5656}
5657
5658inline void txn::drop_map(map_handle map) { error::success_or_throw(::mdbx_drop(handle_, map.dbi, true)); }
5659
5660inline void txn::clear_map(map_handle map) { error::success_or_throw(::mdbx_drop(handle_, map.dbi, false)); }
5661
5662inline void txn::rename_map(map_handle map, const char *new_name) {
5663 error::success_or_throw(::mdbx_dbi_rename(handle_, map, new_name));
5664}
5665
5666inline void txn::rename_map(map_handle map, const ::mdbx::slice &new_name) {
5667 error::success_or_throw(::mdbx_dbi_rename2(handle_, map, new_name));
5668}
5669
5670inline ::mdbx::map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5671 const ::mdbx::value_mode value_mode) const {
5672 return open_map(::mdbx::slice(name), key_mode, value_mode);
5673}
5674
5675inline ::mdbx::map_handle txn::open_map_accede(const ::std::string &name) const {
5676 return open_map_accede(::mdbx::slice(name));
5677}
5678
5679inline ::mdbx::map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5680 const ::mdbx::value_mode value_mode) {
5681 return create_map(::mdbx::slice(name), key_mode, value_mode);
5682}
5683
5684inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5685 return drop_map(::mdbx::slice(name), throw_if_absent);
5686}
5687
5688inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5689 return clear_map(::mdbx::slice(name), throw_if_absent);
5690}
5691
5692inline void txn::rename_map(map_handle map, const ::std::string &new_name) {
5693 return rename_map(map, ::mdbx::slice(new_name));
5694}
5695
5697 txn::map_stat r;
5698 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5699 return r;
5700}
5701
5702inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5703 uint32_t r;
5705 return r;
5706}
5707
5713
5716 return *this;
5717}
5718
5720 txn::canary r;
5722 return r;
5723}
5724
5725inline uint64_t txn::sequence(map_handle map) const {
5726 uint64_t result;
5727 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, 0));
5728 return result;
5729}
5730
5731inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5732 uint64_t result;
5733 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5734 return result;
5735}
5736
5737inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5738 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5739}
5740
5741inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5742 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5743}
5744
5745inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5746 return compare_keys(map, a.key, b.key);
5747}
5748
5749inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5750 return compare_values(map, a.value, b.value);
5751}
5752
5753inline slice txn::get(map_handle map, const slice &key) const {
5754 slice result;
5755 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5756 return result;
5757}
5758
5759inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5760 slice result;
5761 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5762 return result;
5763}
5764
5765inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5766 slice result;
5767 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5768 switch (err) {
5769 case MDBX_SUCCESS:
5770 return result;
5771 case MDBX_NOTFOUND:
5772 return value_at_absence;
5773 default:
5774 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5775 }
5776}
5777
5778inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5779 slice result;
5780 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5781 switch (err) {
5782 case MDBX_SUCCESS:
5783 return result;
5784 case MDBX_NOTFOUND:
5785 return value_at_absence;
5786 default:
5787 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5788 }
5789}
5790
5792 pair result(key, slice());
5793 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5794 return pair_result(result.key, result.value, exact);
5795}
5796
5797inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5798 pair result{key, slice()};
5799 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5800 switch (err) {
5801 case MDBX_SUCCESS:
5802 return pair_result{result.key, result.value, true};
5803 case MDBX_RESULT_TRUE:
5804 return pair_result{result.key, result.value, false};
5805 case MDBX_NOTFOUND:
5806 return pair_result{key, value_at_absence, false};
5807 default:
5808 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5809 }
5810}
5811
5812inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5813 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5814}
5815
5816inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5817 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5818}
5819
5820inline void txn::insert(map_handle map, const slice &key, slice value) {
5821 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5823}
5824
5825inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5826 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5828 switch (err) {
5829 case MDBX_SUCCESS:
5830 return value_result{slice(), true};
5831 case MDBX_KEYEXIST:
5832 return value_result{value, false};
5833 default:
5834 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5835 }
5836}
5837
5838inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5839 slice result(nullptr, value_length);
5840 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5842 return result;
5843}
5844
5845inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5846 slice result(nullptr, value_length);
5847 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5849 switch (err) {
5850 case MDBX_SUCCESS:
5851 return value_result{result, true};
5852 case MDBX_KEYEXIST:
5853 return value_result{result, false};
5854 default:
5855 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5856 }
5857}
5858
5859inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5860 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5861}
5862
5863inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
5864 slice result(nullptr, value_length);
5866 return result;
5867}
5868
5869inline void txn::update(map_handle map, const slice &key, const slice &value) {
5870 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
5871}
5872
5873inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
5874 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
5875 switch (err) {
5876 case MDBX_SUCCESS:
5877 return true;
5878 case MDBX_NOTFOUND:
5879 return false;
5880 default:
5881 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5882 }
5883}
5884
5885inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
5886 slice result(nullptr, value_length);
5888 return result;
5889}
5890
5891inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
5892 slice result(nullptr, value_length);
5893 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
5894 switch (err) {
5895 case MDBX_SUCCESS:
5896 return value_result{result, true};
5897 case MDBX_NOTFOUND:
5898 return value_result{slice(), false};
5899 default:
5900 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5901 }
5902}
5903
5904inline bool txn::erase(map_handle map, const slice &key) {
5905 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
5906 switch (err) {
5907 case MDBX_SUCCESS:
5908 return true;
5909 case MDBX_NOTFOUND:
5910 return false;
5911 default:
5912 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5913 }
5914}
5915
5916inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
5917 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
5918 switch (err) {
5919 case MDBX_SUCCESS:
5920 return true;
5921 case MDBX_NOTFOUND:
5922 return false;
5923 default:
5924 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5925 }
5926}
5927
5928inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
5929 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
5930 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
5931}
5932
5933template <class ALLOCATOR, typename CAPACITY_POLICY>
5936 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator) {
5937 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
5939 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
5940 return result;
5941}
5942
5943template <class ALLOCATOR, typename CAPACITY_POLICY>
5945txn::replace(map_handle map, const slice &key, const slice &new_value,
5946 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator) {
5947 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
5948 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
5949 MDBX_CURRENT, result, &result),
5950 result);
5951 return result;
5952}
5953
5954template <class ALLOCATOR, typename CAPACITY_POLICY>
5956txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
5957 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator) {
5958 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
5959 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
5960 MDBX_CURRENT | MDBX_RESERVE, result, &result),
5961 result);
5962 return result;
5963}
5964
5965inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
5966 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
5967 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
5968}
5969
5970inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
5971 const void *values_array, size_t values_count, put_mode mode,
5972 bool allow_partial) {
5973 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
5974 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
5975 switch (err) {
5976 case MDBX_SUCCESS:
5977 MDBX_CXX20_LIKELY break;
5978 case MDBX_KEYEXIST:
5979 if (allow_partial)
5980 break;
5981 mdbx_txn_break(handle_);
5982 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
5983 default:
5984 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5985 }
5986 return args[1].iov_len /* done item count */;
5987}
5988
5989inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
5990 ptrdiff_t result;
5991 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
5992 return result;
5993}
5994
5995inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
5996 ptrdiff_t result;
5997 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
5998 return result;
5999}
6000
6001inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6002 ptrdiff_t result;
6003 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6004 return result;
6005}
6006
6007inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6008 ptrdiff_t result;
6009 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6010 return result;
6011}
6012
6013//------------------------------------------------------------------------------
6014
6015MDBX_CXX11_CONSTEXPR cursor::cursor(MDBX_cursor *ptr) noexcept : handle_(ptr) {}
6016
6017inline cursor_managed cursor::clone(void *your_context) const {
6018 cursor_managed clone(your_context);
6020 return clone;
6021}
6022
6023inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6024
6025inline cursor &cursor::set_context(void *ptr) {
6027 return *this;
6028}
6029
6030inline cursor &cursor::operator=(cursor &&other) noexcept {
6031 handle_ = other.handle_;
6032 other.handle_ = nullptr;
6033 return *this;
6034}
6035
6036inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6037
6038inline cursor::~cursor() noexcept {
6039#ifndef NDEBUG
6040 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6041#endif
6042}
6043
6044MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
6045
6046MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
6047
6048MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6049
6050MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6051
6052MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6053
6054inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6055 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6056}
6057
6058inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6059 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6060 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6061 if (MDBX_LIKELY(int16_t(diff) == diff))
6062 MDBX_CXX20_LIKELY return int(diff);
6063 else
6065}
6066
6067inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6068 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6069}
6070
6071inline cursor::move_result::move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
6072 bool throw_notfound)
6073 : pair_result(key, value, false) {
6074 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6075}
6076
6077inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6078 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6079 switch (err) {
6080 case MDBX_SUCCESS:
6081 MDBX_CXX20_LIKELY return true;
6082 case MDBX_RESULT_TRUE:
6083 return false;
6084 case MDBX_NOTFOUND:
6085 if (!throw_notfound)
6086 return false;
6087 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6088 default:
6089 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6090 }
6091}
6092
6094 const slice &value)
6095 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6096 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6097}
6098
6099inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6100 ptrdiff_t result;
6101 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6102 return result;
6103}
6104
6105inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6106 ptrdiff_t result;
6108 return result;
6109}
6110
6111inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6112 return move(key_exact, key, throw_notfound);
6113}
6114
6115inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6116 return move(key_lowerbound, key, throw_notfound);
6117}
6118
6119inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6120 return move(key_greater_than, key, throw_notfound);
6121}
6122
6123inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6124 return move(multi_find_pair, key, value, throw_notfound);
6125}
6126
6127inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6128 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6129}
6130
6131inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6132 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6133}
6134
6135inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6136
6137inline size_t cursor::count_multivalue() const {
6138 size_t result;
6140 return result;
6141}
6142
6143inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6144
6146
6148
6150
6152
6153inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6154 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6155}
6156
6158 return estimate_result(*this, key_lowerbound, key);
6159}
6160
6162 return estimate_result(*this, operation);
6163}
6164
6166
6170
6172
6173inline txn cursor::txn() const {
6176 return ::mdbx::txn(txn);
6177}
6178
6179inline map_handle cursor::map() const {
6180 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6181 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6183 return map_handle(dbi);
6184}
6185
6186inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6187 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6188}
6189
6190inline void cursor::put(const slice &key, slice value, put_mode mode) {
6191 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6192}
6193
6194inline void cursor::insert(const slice &key, slice value) {
6196 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6197}
6198
6199inline value_result cursor::try_insert(const slice &key, slice value) {
6200 const int err =
6201 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6202 switch (err) {
6203 case MDBX_SUCCESS:
6204 return value_result{slice(), true};
6205 case MDBX_KEYEXIST:
6206 return value_result{value, false};
6207 default:
6208 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6209 }
6210}
6211
6212inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6213 slice result(nullptr, value_length);
6214 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6216 return result;
6217}
6218
6219inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6220 slice result(nullptr, value_length);
6221 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6223 switch (err) {
6224 case MDBX_SUCCESS:
6225 return value_result{result, true};
6226 case MDBX_KEYEXIST:
6227 return value_result{result, false};
6228 default:
6229 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6230 }
6231}
6232
6233inline void cursor::upsert(const slice &key, const slice &value) {
6234 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6235}
6236
6237inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6238 slice result(nullptr, value_length);
6240 return result;
6241}
6242
6243inline void cursor::update(const slice &key, const slice &value) {
6244 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6245}
6246
6247inline bool cursor::try_update(const slice &key, const slice &value) {
6248 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6249 switch (err) {
6250 case MDBX_SUCCESS:
6251 return true;
6252 case MDBX_NOTFOUND:
6253 return false;
6254 default:
6255 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6256 }
6257}
6258
6259inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6260 slice result(nullptr, value_length);
6262 return result;
6263}
6264
6265inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6266 slice result(nullptr, value_length);
6267 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6268 switch (err) {
6269 case MDBX_SUCCESS:
6270 return value_result{result, true};
6271 case MDBX_NOTFOUND:
6272 return value_result{slice(), false};
6273 default:
6274 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6275 }
6276}
6277
6278inline bool cursor::erase(bool whole_multivalue) {
6279 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6280 switch (err) {
6281 case MDBX_SUCCESS:
6282 MDBX_CXX20_LIKELY return true;
6283 case MDBX_NOTFOUND:
6284 return false;
6285 default:
6286 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6287 }
6288}
6289
6290inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6291 bool found = seek(key);
6292 return found ? erase(whole_multivalue) : found;
6293}
6294
6295inline bool cursor::erase(const slice &key, const slice &value) {
6296 move_result data = find_multivalue(key, value, false);
6297 return data.done && erase();
6298}
6299
6301} // namespace mdbx
6302
6303//------------------------------------------------------------------------------
6304
6307namespace std {
6308
6311
6312inline string to_string(const ::mdbx::slice &value) {
6313 ostringstream out;
6314 out << value;
6315 return out.str();
6316}
6317
6318template <class ALLOCATOR, typename CAPACITY_POLICY>
6319inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6320 ostringstream out;
6321 out << buffer;
6322 return out.str();
6323}
6324
6325inline string to_string(const ::mdbx::pair &value) {
6326 ostringstream out;
6327 out << value;
6328 return out.str();
6329}
6330
6331inline string to_string(const ::mdbx::env::geometry &value) {
6332 ostringstream out;
6333 out << value;
6334 return out.str();
6335}
6336
6337inline string to_string(const ::mdbx::env::operate_parameters &value) {
6338 ostringstream out;
6339 out << value;
6340 return out.str();
6341}
6342
6343inline string to_string(const ::mdbx::env::mode &value) {
6344 ostringstream out;
6345 out << value;
6346 return out.str();
6347}
6348
6349inline string to_string(const ::mdbx::env::durability &value) {
6350 ostringstream out;
6351 out << value;
6352 return out.str();
6353}
6354
6355inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6356 ostringstream out;
6357 out << value;
6358 return out.str();
6359}
6360
6361inline string to_string(const ::mdbx::env::operate_options &value) {
6362 ostringstream out;
6363 out << value;
6364 return out.str();
6365}
6366
6367inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6368 ostringstream out;
6369 out << value;
6370 return out.str();
6371}
6372
6373inline string to_string(const ::MDBX_log_level_t &value) {
6374 ostringstream out;
6375 out << value;
6376 return out.str();
6377}
6378
6379inline string to_string(const ::MDBX_debug_flags_t &value) {
6380 ostringstream out;
6381 out << value;
6382 return out.str();
6383}
6384
6385inline string to_string(const ::mdbx::error &value) {
6386 ostringstream out;
6387 out << value;
6388 return out.str();
6389}
6390
6391inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6392
6393template <> struct hash<::mdbx::slice> {
6394 MDBX_CXX14_CONSTEXPR size_t operator()(::mdbx::slice const &slice) const noexcept { return slice.hash_value(); }
6395};
6396
6398} // namespace std
6399
6400#if defined(__LCC__) && __LCC__ >= 126
6401#pragma diagnostic pop
6402#endif
6403
6404#ifdef _MSC_VER
6405#pragma warning(pop)
6406#endif
Definition mdbx.h++:598
Definition mdbx.h++:588
Definition mdbx.h++:608
#define MDBX_CXX11_CONSTEXPR
Definition mdbx.h:443
#define MDBX_MAYBE_UNUSED
Definition mdbx.h:509
#define MDBX_CXX14_CONSTEXPR
Definition mdbx.h:462
#define MDBX_NOTHROW_PURE_FUNCTION
The 'pure nothrow' function attribute for optimization.
Definition mdbx.h:259
mode_t mdbx_mode_t
Definition mdbx.h:174
int(* MDBX_preserve_func)(void *context, MDBX_val *target, const void *src, size_t bytes)
Definition mdbx.h:5030
#define LIBMDBX_API
Definition mdbx.h:590
#define LIBMDBX_API_TYPE
Definition mdbx.h:605
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:765
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)
pthread_t mdbx_tid_t
Definition mdbx.h:173
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition mdbx.h:697
int mdbx_filehandle_t
Definition mdbx.h:171
pid_t mdbx_pid_t
Definition mdbx.h:172
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:779
@ MDBX_MAXDATASIZE
Definition mdbx.h:773
@ MDBX_MAX_DBI
Definition mdbx.h:770
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:776
libmdbx build information
Definition mdbx.h:633
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4405
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4057
Information about the environment.
Definition mdbx.h:2783
Statistics for a table in the environment.
Definition mdbx.h:2737
Information about the transaction.
Definition mdbx.h:3959
libmdbx version information,
Definition mdbx.h:615
LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, MDBX_put_flags_t flags)
Delete current key/data pair.
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_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_cursor_scan(MDBX_cursor *cursor, MDBX_predicate_func *predicate, void *context, MDBX_cursor_op start_op, MDBX_cursor_op turn_op, void *arg)
Сканирует таблицу с использованием передаваемого предиката, с уменьшением сопутствующих накладных рас...
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:1625
LIBMDBX_API int mdbx_cursor_count(const MDBX_cursor *cursor, size_t *count)
Return count values (aka duplicates) for current 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)
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:4465
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_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:1662
@ MDBX_ALLDUPS
Definition mdbx.h:1645
@ MDBX_CURRENT
Definition mdbx.h:1640
@ MDBX_APPENDDUP
Definition mdbx.h:1658
@ MDBX_APPEND
Definition mdbx.h:1653
@ MDBX_UPSERT
Definition mdbx.h:1627
@ MDBX_RESERVE
Definition mdbx.h:1649
@ MDBX_NOOVERWRITE
Definition mdbx.h:1630
LIBMDBX_API int mdbx_cursor_on_first_dup(const MDBX_cursor *cursor)
Определяет стоит ли курсор на первом или единственном мульти-значении соответствующем ключу.
LIBMDBX_API int mdbx_cursor_renew(const MDBX_txn *txn, MDBX_cursor *cursor)
Renew a cursor handle for use within the given transaction.
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:1702
LIBMDBX_API int mdbx_cursor_compare(const MDBX_cursor *left, const MDBX_cursor *right, bool ignore_multival)
Сравнивает позицию курсоров.
LIBMDBX_API int mdbx_cursor_on_last_dup(const MDBX_cursor *cursor)
Определяет стоит ли курсор на последнем или единственном мульти-значении соответствующем ключу.
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.
struct MDBX_cursor MDBX_cursor
Opaque structure for navigating through a table.
Definition mdbx.h:727
LIBMDBX_API int mdbx_cursor_set_userctx(MDBX_cursor *cursor, void *ctx)
Set application information associated with the cursor.
LIBMDBX_API int mdbx_cursor_open(const 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_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_bind(const MDBX_txn *txn, MDBX_cursor *cursor, MDBX_dbi dbi)
Bind cursor to specified transaction and DBI-handle.
LIBMDBX_API void * mdbx_cursor_get_userctx(const MDBX_cursor *cursor)
Get the application information associated with the MDBX_cursor.
LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor)
Close a cursor handle.
LIBMDBX_API MDBX_txn * mdbx_cursor_txn(const MDBX_cursor *cursor)
Return the cursor's transaction handle.
LIBMDBX_API int mdbx_txn_release_all_cursors(const MDBX_txn *txn, bool unbind)
Unbind or closes all cursors of a given transaction.
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_GET_CURRENT
Definition mdbx.h:1717
@ MDBX_GET_BOTH
Definition mdbx.h:1710
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1797
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1714
@ MDBX_SET_KEY
Definition mdbx.h:1757
@ MDBX_FIRST_DUP
Definition mdbx.h:1707
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1796
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1722
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1807
@ MDBX_NEXT_NODUP
Definition mdbx.h:1742
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1804
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1805
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1810
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1764
@ MDBX_SET_RANGE
Definition mdbx.h:1760
@ MDBX_LAST_DUP
Definition mdbx.h:1728
@ MDBX_PREV
Definition mdbx.h:1745
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1812
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1813
@ MDBX_LAST
Definition mdbx.h:1725
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1795
@ MDBX_PREV_DUP
Definition mdbx.h:1748
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1803
@ MDBX_SET
Definition mdbx.h:1754
@ MDBX_NEXT
Definition mdbx.h:1731
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1798
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1809
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1739
@ MDBX_PREV_NODUP
Definition mdbx.h:1751
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1811
@ MDBX_NEXT_DUP
Definition mdbx.h:1734
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1806
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1799
@ MDBX_FIRST
Definition mdbx.h:1704
LIBMDBX_API int mdbx_dbi_rename(MDBX_txn *txn, MDBX_dbi dbi, const char *name)
Переименовает таблицу по DBI-дескриптору
LIBMDBX_API int mdbx_dbi_rename2(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *name)
Переименовает таблицу по DBI-дескриптору
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:720
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1575
@ MDBX_INTEGERDUP
Definition mdbx.h:1599
@ MDBX_DB_ACCEDE
Definition mdbx.h:1617
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1577
@ MDBX_REVERSEKEY
Definition mdbx.h:1580
@ MDBX_DUPFIXED
Definition mdbx.h:1594
@ MDBX_INTEGERKEY
Definition mdbx.h:1590
@ MDBX_REVERSEDUP
Definition mdbx.h:1602
@ MDBX_CREATE
Definition mdbx.h:1605
@ MDBX_DUPSORT
Definition mdbx.h:1583
MDBX_log_level_t
Definition mdbx.h:840
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:897
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:6195
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1821
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1835
@ MDBX_BAD_TXN
Definition mdbx.h:1901
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1915
@ MDBX_SUCCESS
Definition mdbx.h:1823
@ MDBX_NOTFOUND
Definition mdbx.h:1838
@ MDBX_RESULT_TRUE
Definition mdbx.h:1829
@ MDBX_BUSY
Definition mdbx.h:1919
@ MDBX_EINVAL
Definition mdbx.h:1993
@ MDBX_ENOMEM
Definition mdbx.h:1995
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1922
@ MDBX_RESULT_FALSE
Definition mdbx.h:1826
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:1972
@ MDBX_KEYEXIST
Definition mdbx.h:1832
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:2519
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2513
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2516
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1016
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:3027
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2094
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:2966
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:2198
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2194
@ 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:2298
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2103
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2265
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2126
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2230
@ 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:2253
@ 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:2166
@ 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:2153
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2120
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2214
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2132
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2180
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2293
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:3663
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:3047
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:2984
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:4730
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:3708
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 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 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_txn_break(MDBX_txn *txn)
Marks transaction as broken.
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_park(MDBX_txn *txn, bool autounpark)
Переводит читающую транзакцию в "припаркованное" состояние.
LIBMDBX_API int mdbx_txn_unpark(MDBX_txn *txn, bool restart_if_ousted)
Распарковывает ранее припаркованную читающую транзакцию.
MDBX_txn_flags_t
Definition mdbx.h:1477
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:3928
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:708
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:1488
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1497
@ MDBX_TXN_READWRITE
Definition mdbx.h:1482
@ MDBX_TXN_TRY
Definition mdbx.h:1503
bool rename_map(const ::mdbx::slice &old_name, const ::mdbx::slice &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2318
buffer(size_t head_room, const struct slice &src, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2084
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
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++:1907
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4539
~txn_managed() noexcept
env & set_sync_period(const duration &period)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
txn_managed start_nested()
Start nested write transaction.
extra_runtime_option
MDBX environment extra runtime options.
Definition mdbx.h++:3489
static buffer key_from(silo &&src) noexcept
Definition mdbx.h++:2632
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3716
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:1936
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2006
constexpr allocator_type get_allocator() const
Returns the associated allocator.
Definition mdbx.h++:1896
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3915
env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede=true)
map_handle(const map_handle &) noexcept=default
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2269
::MDBX_db_flags_t flags
Definition mdbx.h++:2979
path get_path() const
Return the path that was used for opening the environment.
static buffer hex_decode(const ::mdbx::slice &source, bool ignore_spaces=false, const allocator_type &allocator=allocator_type())
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:2218
int64_t as_int64_adapt() const
Definition mdbx.h++:2155
constexpr ::std::basic_string< CHAR, T, A > as_string(const A &allocator=A()) const
Definition mdbx.h++:2385
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4400
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4456
buffer encode_base64(unsigned wrap_width=0, const allocator_type &allocator=allocator_type()) const
Returns a new buffer with a Base64 dump of the slice content.
Definition mdbx.h++:2213
static buffer key_from(const double *ieee754_64bit)
Definition mdbx.h++:2638
static buffer base58(const POD &pod, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base58 dump of the given pod.
Definition mdbx.h++:2189
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:1953
constexpr byte & operator[](size_t n) noexcept
Accesses the specified byte of data chunk.
Definition mdbx.h++:2440
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:1950
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2327
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2256
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++:1923
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2298
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2266
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:1944
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2972
durability
Durability level.
Definition mdbx.h++:3128
@ lazy_weak_tail
Definition mdbx.h++:3131
@ robust_synchronous
Definition mdbx.h++:3129
@ half_synchronous_weak_last
Definition mdbx.h++:3130
constexpr buffer(const buffer &src, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2052
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1483
constexpr byte operator[](size_t n) const noexcept
Accesses the specified byte of data chunk.
Definition mdbx.h++:2433
static buffer base64_decode(const ::mdbx::slice &source, bool ignore_spaces=false, const allocator_type &allocator=allocator_type())
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:2232
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:1980
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2527
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...
buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2042
constexpr int32_t as_int32() const
Definition mdbx.h++:2140
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:1975
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2277
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2283
buffer & operator=(const buffer &src)
Definition mdbx.h++:2344
estimate_result estimate(move_operation operation, slice &key) const
uint16_t as_uint16_adapt() const
Definition mdbx.h++:2149
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2549
static bool remove(const char *pathname, const remove_mode mode=just_remove)
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:1917
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4419
env & copy(const wchar_t *destination, bool compactify, bool force_dynamic_size=false)
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from the data chunk.
Definition mdbx.h++:2429
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from the data chunk.
Definition mdbx.h++:2425
bool is_readwrite() const
Checks whether the transaction is read-write.
Definition mdbx.h++:3777
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++:4349
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:1972
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2628
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++:4413
buffer base64_decode(bool ignore_spaces=false, const allocator_type &allocator=allocator_type()) const
Decodes Base64 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2251
bool clear_map(const char *name, bool throw_if_absent=false)
constexpr env() noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2491
uint8_t as_uint8_adapt() const
Definition mdbx.h++:2150
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4422
buffer encode_base58(unsigned wrap_width=0, const allocator_type &allocator=allocator_type()) const
Returns a new buffer with a Base58 dump of the slice content.
Definition mdbx.h++:2208
void rename_map(map_handle map, const ::std::string_view &new_name)
Переименовывает таблицу ключ-значение.
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2376
env & copy(filehandle fd, bool compactify, bool force_dynamic_size=false)
Copy an environment to the specified file descriptor.
buffer(size_t head_room, const buffer &src, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2092
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2323
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
constexpr int16_t as_int16() const
Definition mdbx.h++:2141
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2648
static buffer hex(const POD &pod, bool uppercase=false, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a hexadecimal dump of the given pod.
Definition mdbx.h++:2181
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2973
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4505
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4367
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++:4358
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2654
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.
bool is_same_or_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4189
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3822
static buffer hex(const ::mdbx::slice &source, bool uppercase=false, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:2161
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:4008
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4390
constexpr bool empty() const noexcept
Checks whether the string is empty.
Definition mdbx.h++:2370
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4181
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:2116
buffer(const buffer &src, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2028
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4185
static buffer base58_decode(const ::mdbx::slice &source, bool ignore_spaces=false, const allocator_type &allocator=allocator_type())
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:2225
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2353
uint32_t as_uint32_adapt() const
Definition mdbx.h++:2148
buffer(size_t head_room, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2074
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2634
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from the data chunk.
Definition mdbx.h++:2421
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++:3907
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2306
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3225
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4374
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2294
bool clear_map(const ::mdbx::slice &name, bool throw_if_absent=false)
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2408
static buffer base64(const POD &pod, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base64 dump of the given pod.
Definition mdbx.h++:2196
MDBX_txn * handle_
Definition mdbx.h++:3741
bool starts_with(const struct slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:2395
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:1994
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2640
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4346
mode
Operation mode.
Definition mdbx.h++:3120
@ write_mapped_io
Definition mdbx.h++:3123
@ readonly
Definition mdbx.h++:3121
@ write_file_io
Definition mdbx.h++:3122
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4343
constexpr byte at(size_t n) const
Accesses the specified byte of data chunk with bounds checking.
Definition mdbx.h++:2447
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4302
operator::mdbx::txn() const
Definition mdbx.h++:4487
constexpr int8_t as_int8() const
Definition mdbx.h++:2142
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2523
MDBX_env * handle_
Definition mdbx.h++:3020
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2620
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4406
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2547
commit_latency commit_get_latency()
Commit all the operations of a transaction into the database and return latency information.
Definition mdbx.h++:4138
static buffer base58(const ::mdbx::slice &source, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base58 dump of the slice content.
Definition mdbx.h++:2168
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4177
bool ends_with(const struct slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:2400
constexpr POD as_pod() const
Definition mdbx.h++:2126
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2652
buffer(const struct slice &src, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2022
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:2115
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4356
buffer hex_decode(bool ignore_spaces=false, const allocator_type &allocator=allocator_type()) const
Decodes hexadecimal dump from the buffer content to new returned buffer.
Definition mdbx.h++:2239
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4376
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2348
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2055
buffer(const ::mdbx::txn &txn, const struct slice &src, const allocator_type &allocator=allocator_type())
void close()
Explicitly closes the cursor.
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2059
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2519
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++:4387
constexpr txn_managed() noexcept=default
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2312
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++:1900
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2656
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2069
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2582
move_result next_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4452
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++:4056
cursor_managed & operator=(const cursor_managed &)=delete
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1484
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3342
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2646
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4278
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4361
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2350
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2499
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2570
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2531
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4323
uint128_t as_uint128_adapt() const
Definition mdbx.h++:2145
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4548
::MDBX_dbi_state_t state
Definition mdbx.h++:2980
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:2117
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3546
constexpr uint32_t as_uint32() const
Definition mdbx.h++:2132
cursor_managed(cursor_managed &&)=default
void commit(commit_latency &latency)
Commit all the operations of a transaction into the database and collect latency information.
Definition mdbx.h++:4133
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++:3317
constexpr size_t hash_value() const noexcept
Returns the hash value of the data.
Definition mdbx.h++:2382
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4416
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.
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2662
move_result get_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4448
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4378
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4375
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4488
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3313
move_result get_multiple_samelength(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4444
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &allocator=allocator_type()) const
Returns a new buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:2201
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2122
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2658
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from the data chunk.
Definition mdbx.h++:2417
bool drop_map(const ::mdbx::slice &name, bool throw_if_absent=false)
Drop key-value map.
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3819
static buffer key_from(const uint32_t unsigned_int32)
Definition mdbx.h++:2660
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2271
move_result to_key_greater_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4393
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:2113
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3380
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2014
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:4005
env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2302
buffer(const char *c_str, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2037
constexpr buffer(const struct slice &src, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2048
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4071
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++:3324
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++:3900
int32_t as_int32_adapt() const
Definition mdbx.h++:2156
buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2292
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++:4063
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:1958
bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2031
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2489
bool is_empty() const
Checks whether the database is empty.
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2535
void close(bool dont_sync=false)
Explicitly closes the environment and release the memory map.
constexpr byte & at(size_t n)
Accesses the specified byte of data chunk with bounds checking.
Definition mdbx.h++:2451
move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4428
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:1966
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4199
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4214
@ seek_key
Definition mdbx.h++:4216
@ key_lowerbound
Definition mdbx.h++:4218
@ key_greater_than
Definition mdbx.h++:4225
@ multi_find_pair
Definition mdbx.h++:4213
@ key_exact
Definition mdbx.h++:4217
@ get_current
Definition mdbx.h++:4204
@ multi_exactkey_value_greater
Definition mdbx.h++:4233
virtual ~env_managed() noexcept
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4352
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2614
void insert(const pair &kv)
Definition mdbx.h++:4506
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2481
cursor_managed(const cursor_managed &)=delete
env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
void upsert(const pair &kv)
Definition mdbx.h++:4508
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4364
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2413
int16_t as_int16_adapt() const
Definition mdbx.h++:2157
txn_managed & operator=(const txn_managed &)=delete
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2664
constexpr size_t operator()(::mdbx::slice const &slice) const noexcept
Definition mdbx.h++:6394
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2405
static buffer base64(const ::mdbx::slice &source, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base64 dump of the slice content.
Definition mdbx.h++:2174
constexpr int64_t as_int64() const
Definition mdbx.h++:2139
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3920
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4403
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:2110
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1479
bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
env_managed(const env_managed &)=delete
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2636
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:1928
move_result to_current_last_multi(bool throw_notfound=true)
Definition mdbx.h++:4371
value_result try_insert(const pair &kv)
Definition mdbx.h++:4507
constexpr uint128_t as_uint128() const
Definition mdbx.h++:2129
constexpr cursor() noexcept=default
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4381
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2644
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:1931
constexpr const struct slice & slice() const noexcept
Definition mdbx.h++:2100
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4425
uint64_t as_uint64_adapt() const
Definition mdbx.h++:2147
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3321
MDBX_cursor * handle_
Definition mdbx.h++:4154
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2539
~cursor_managed() noexcept
Definition mdbx.h++:4560
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2559
constexpr uint8_t as_uint8() const
Definition mdbx.h++:2134
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2097
MDBX_dbi dbi
Definition mdbx.h++:2971
buffer(const ::std::basic_string< CHAR, T, A > &&)=delete
constexpr uint64_t as_uint64() const
Definition mdbx.h++:2131
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4397
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2642
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4368
constexpr int128_t as_int128() const
Definition mdbx.h++:2137
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2596
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++:2515
constexpr uint16_t as_uint16() const
Definition mdbx.h++:2133
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3785
constexpr bool is_null() const noexcept
Checks whether the data pointer of the buffer is nullptr.
Definition mdbx.h++:2373
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2346
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++:4409
txn_managed(const txn_managed &)=delete
constexpr ::std::span< char > chars()
Definition mdbx.h++:2118
static buffer clone(const buffer &src, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2288
buffer(size_t capacity, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2079
constexpr buffer(const ::std::span< POD > &span)
Definition mdbx.h++:2105
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3319
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:1988
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:4007
buffer & append_producer(PRODUCER &producer)
Definition mdbx.h++:2501
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:4006
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2508
int128_t as_int128_adapt() const
Definition mdbx.h++:2153
env_managed(const ::mdbx::filesystem::path &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
Create new or open existing database.
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2625
bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:3928
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4384
move_result to_previous(bool throw_notfound=true)
Definition mdbx.h++:4357
constexpr buffer(const char *c_str, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2064
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3315
int8_t as_int8_adapt() const
Definition mdbx.h++:2158
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:1911
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3789
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:1999
buffer base58_decode(bool ignore_spaces=false, const allocator_type &allocator=allocator_type()) const
Decodes Base58 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2245
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4297
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1476
Unmanaged cursor.
Definition mdbx.h++:4152
Managed cursor.
Definition mdbx.h++:4531
Unmanaged database environment.
Definition mdbx.h++:3016
Managed database environment.
Definition mdbx.h++:3655
Unmanaged database transaction.
Definition mdbx.h++:3738
Managed database transaction.
Definition mdbx.h++:4089
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++:5196
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5071
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4864
polymorphic_allocator default_allocator
Definition mdbx.h++:352
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4873
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4955
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base58(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base58 dump of the slice content.
Definition mdbx.h++:5033
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++:5481
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5546
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++:5224
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4969
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++:5928
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2884
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4851
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:5121
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4949
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5579
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:4841
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4719
void rethrow_captured() const
Definition mdbx.h++:4656
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4849
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6123
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6099
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++:5649
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5189
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5891
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5845
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5443
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++:5374
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6067
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4871
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6001
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4896
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4789
env & operator=(env &&other) noexcept
Definition mdbx.h++:5133
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6171
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:417
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5838
string< ALLOCATOR > as_hex_string(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a hexadecimal dump of the slice content.
Definition mdbx.h++:5012
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5662
void throw_on_failure() const
Definition mdbx.h++:4696
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6247
void update(const slice &key, const slice &value)
Definition mdbx.h++:6243
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:5118
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++:5737
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4859
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5548
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5509
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6054
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4995
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5307
uint64_t sequence(map_handle map) const
Definition mdbx.h++:5725
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6233
bool is_clean() const noexcept
Definition mdbx.h++:4649
string< ALLOCATOR > as_base58_string(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:5017
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2876
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4739
void swap(slice &other) noexcept
Definition mdbx.h++:4825
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5297
void bind(const ::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++:6167
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2880
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:372
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:5349
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5182
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4939
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4591
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++:5446
void insert(const slice &key, slice value)
Definition mdbx.h++:6194
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6127
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:351
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:2864
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++:5486
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4773
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:6017
~cursor() noexcept
Definition mdbx.h++:6038
~txn() noexcept
Definition mdbx.h++:5530
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5379
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6119
constexpr void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition mdbx.h++:4877
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6173
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6219
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5174
map_handle map() const
Definition mdbx.h++:6179
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++:5390
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:5125
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6111
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6131
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2945
void success_or_throw() const
Definition mdbx.h++:4701
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base64(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base64 dump of the slice content.
Definition mdbx.h++:5038
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5581
buffer< ALLOCATOR, CAPACITY_POLICY > base64_decode(bool ignore_spaces=false, const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:5053
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4911
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5430
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4999
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6058
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6137
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4907
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5180
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4916
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5553
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6237
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5305
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2872
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5565
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++:5702
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5873
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4890
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2993
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6212
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++:5244
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++:5385
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:5989
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5311
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5658
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6007
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++:5965
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5315
buffer< ALLOCATOR, CAPACITY_POLICY > extract(map_handle map, const slice &key, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &allocator=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Removes and return a value of the key.
Definition mdbx.h++:5935
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5583
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5003
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6025
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5696
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6077
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++:5220
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++:5741
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5170
buffer< ALLOCATOR, CAPACITY_POLICY > encode_hex(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:5027
cursor & operator=(cursor &&other) noexcept
Definition mdbx.h++:6030
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5714
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5863
buffer< ALLOCATOR, CAPACITY_POLICY > hex_decode(bool ignore_spaces=false, const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:5043
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4934
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6312
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++:5396
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4961
bool on_first() const
Definition mdbx.h++:6145
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:4869
bool eof() const
Definition mdbx.h++:6143
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5567
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5367
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6186
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5633
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5495
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4901
bool seek(const slice &key)
Definition mdbx.h++:6135
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5419
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5369
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4923
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++:5288
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5660
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++:5408
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5065
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4884
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6199
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4724
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4672
string< ALLOCATOR > as_base64_string(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:5022
::MDBX_cmp_func * comparator
Definition mdbx.h++:2992
put_mode
Key-value pairs put mode.
Definition mdbx.h++:3001
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5076
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++:5400
::mdbx_filehandle_t filehandle
Definition mdbx.h++:374
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4835
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++:5266
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4991
char8_t byte
Definition mdbx.h++:312
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5719
txn & operator=(txn &&other) noexcept
Definition mdbx.h++:5522
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6278
buffer< ALLOCATOR, CAPACITY_POLICY > replace_reserve(map_handle map, const slice &key, slice &new_value, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &allocator=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Definition mdbx.h++:5956
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5319
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5573
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5825
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:346
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6105
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4976
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5885
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5061
~env() noexcept
Definition mdbx.h++:5141
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2845
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5753
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4879
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++:5970
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5869
geometry & make_dynamic(intptr_t lower=minimal_value, intptr_t upper=maximal_value) noexcept
Definition mdbx.h++:5163
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4928
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4831
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2848
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5488
::mdbx::filesystem::path path
Definition mdbx.h++:399
bool on_last_multival() const
Definition mdbx.h++:6151
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5361
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5820
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5355
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++:5200
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5451
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6023
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5295
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5595
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2868
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5585
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5413
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4592
bool on_first_multival() const
Definition mdbx.h++:6149
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5812
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4714
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4944
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5331
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5859
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5178
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6259
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6115
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4857
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5474
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:5904
bool on_last() const
Definition mdbx.h++:6147
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:395
buffer< ALLOCATOR, CAPACITY_POLICY > base58_decode(bool ignore_spaces=false, const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:5048
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:5343
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5424
map_handle::info get_handle_info(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5708
void renew(const ::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6165
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5157
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5601
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4670
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6265
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++:5617
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5516
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5057
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5589
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++:5791
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4843
@ upsert
Insert or update.
Definition mdbx.h++:3003
@ update
Update existing, don't insert new.
Definition mdbx.h++:3004
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:3002
@ continue_loop
Definition mdbx.h++:2845
@ exit_loop
Definition mdbx.h++:2845
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2970
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:697
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:710
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:673
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:1405
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of a passed slice.
Definition mdbx.h++:1211
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:664
const slice source
Definition mdbx.h++:1294
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base58 dump, and therefore there could be dec...
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:732
int8_t as_int8_adapt() const
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1024
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1266
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:750
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1023
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2812
constexpr int64_t as_int64() const
Definition mdbx.h++:1030
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base58 dump of a passed slice.
Definition mdbx.h++:1260
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:857
value_result & operator=(const value_result &) noexcept=default
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.
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:1398
constexpr int16_t as_int16() const
Definition mdbx.h++:1032
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:1444
slice value
Definition mdbx.h++:2714
::std::ostream & output(::std::ostream &out) const
Output Base64 dump of passed slice to the std::ostream.
constexpr bool is_reference() const noexcept
Checks whether one of the buffers just refers to data located outside the buffer, rather than stores ...
Definition mdbx.h++:2822
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1233
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2793
slice value
Definition mdbx.h++:2729
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2775
::std::ostream & output(::std::ostream &out) const
Output hexadecimal dump of passed slice to the std::ostream.
pair_result(const pair_result &) noexcept=default
@ max_length
Definition mdbx.h++:642
const slice source
Definition mdbx.h++:1388
const slice source
Definition mdbx.h++:1195
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++:1369
buffer_pair_spec(const txn &txn, const pair &pair, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2807
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:1363
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:724
constexpr bool is_freestanding() const noexcept
Checks whether data chunk stored inside the buffers both, otherwise at least one of buffers just refe...
Definition mdbx.h++:2817
constexpr POD as_pod() const
Definition mdbx.h++:1007
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++:2759
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++:1467
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1020
uint16_t as_uint16_adapt() const
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1198
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base64 dump of a passed slice.
Definition mdbx.h++:1311
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2795
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:746
std::pair< slice, slice > stl_pair
Definition mdbx.h++:2728
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:687
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:1205
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1390
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2790
buffer_type key
Definition mdbx.h++:2776
constexpr int8_t as_int8() const
Definition mdbx.h++:1033
constexpr ::std::span< char > chars()
Definition mdbx.h++:699
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1052
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1317
static constexpr size_t round(const size_t value)
Definition mdbx.h++:1167
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1284
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++:1458
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:2716
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1423
const slice source
Definition mdbx.h++:1243
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:2731
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:698
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1436
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++:1237
uint8_t as_uint8_adapt() const
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:1357
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:678
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++:1412
buffer_pair_spec(const txn &txn, const slice &key, const slice &value, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2804
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:729
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++:754
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1378
int32_t as_int32_adapt() const
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:1304
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:2760
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1350
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2782
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by hexadecimal dump of a passed slice.
static constexpr pair invalid() noexcept
Definition mdbx.h++:2739
bool done
Definition mdbx.h++:2758
::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++:1288
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2801
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:696
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:712
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:1451
void make_freestanding()
Makes buffers owning the data.
Definition mdbx.h++:2828
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1297
pair(const pair &) noexcept=default
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:1005
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++:1028
slice key
Definition mdbx.h++:2729
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:2730
const slice source
Definition mdbx.h++:1434
pair_result & operator=(const pair_result &) noexcept=default
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:1253
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1335
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2773
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from hexadecimal dump from a passed slice.
static constexpr size_t advise(const size_t current, const size_t wanna)
Definition mdbx.h++:1175
constexpr int32_t as_int32() const
Definition mdbx.h++:1031
int64_t as_int64_adapt() const
buffer_pair_spec(const stl_pair &pair, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2788
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Definition mdbx.h++:768
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1025
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2774
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1022
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid hexadecimal dump, and therefore there could b...
uint32_t as_uint32_adapt() const
buffer_pair_spec(const pair &pair, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2799
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by Base64 dump of passed slice.
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2810
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++:705
int16_t as_int16_adapt() const
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2772
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++:1339
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++:1246
buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2784
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:707
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++:1217
bool done
Definition mdbx.h++:2715
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++:1348
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &allocator=ALLOCATOR())
Definition mdbx.h++:2668
inline ::std::ostream & operator<<(::std::ostream &out, const to_hex &wrapper)
Definition mdbx.h++:1342
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &allocator=ALLOCATOR())
Definition mdbx.h++:2690
Definition mdbx.h++:2770
Definition mdbx.h++:1164
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1387
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1433
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1347
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:2727
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:2757
References a data located outside the slice.
Definition mdbx.h++:637
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1242
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1293
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1194
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:2713
fatal(exception &&src) noexcept
Definition mdbx.h++:518
fatal(const ::mdbx::error &) noexcept
exception(const exception &)=default
void throw_exception() const
fatal(const exception &src) noexcept
Definition mdbx.h++:517
exception(exception &&)=default
static void success_or_throw(int error_code)
Definition mdbx.h++:483
error(const error &)=default
virtual ~fatal() noexcept
fatal & operator=(fatal &&)=default
fatal(const fatal &src) noexcept
Definition mdbx.h++:519
exception & operator=(exception &&)=default
error & operator=(error &&)=default
fatal(fatal &&src) noexcept
Definition mdbx.h++:520
fatal & operator=(const fatal &)=default
exception_thunk() noexcept=default
exception & operator=(const exception &)=default
exception(const ::mdbx::error &) noexcept
error & operator=(const error &)=default
virtual ~exception() noexcept
error(error &&)=default
Implements error information and throwing corresponding exceptions.
Definition mdbx.h++:442
Base class for all libmdbx's exceptions that are corresponds to libmdbx errors.
Definition mdbx.h++:496
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:427
Fatal exception that lead termination anyway in dangerous unrecoverable cases.
Definition mdbx.h++:512
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:526
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()
Definition mdbx.h++:531
Definition mdbx.h++:532
Definition mdbx.h++:533
Definition mdbx.h++:560
Definition mdbx.h++:534
Definition mdbx.h++:535
Definition mdbx.h++:536
Definition mdbx.h++:537
Definition mdbx.h++:538
Definition mdbx.h++:539
Definition mdbx.h++:540
Definition mdbx.h++:559
Definition mdbx.h++:541
Definition mdbx.h++:542
Definition mdbx.h++:543
Definition mdbx.h++:544
Definition mdbx.h++:545
Definition mdbx.h++:546
Definition mdbx.h++:547
Definition mdbx.h++:548
Definition mdbx.h++:562
Definition mdbx.h++:549
Definition mdbx.h++:550
Definition mdbx.h++:551
Definition mdbx.h++:553
Definition mdbx.h++:554
Definition mdbx.h++:555
Definition mdbx.h++:556
Definition mdbx.h++:557
Definition mdbx.h++:561
Definition mdbx.h++:558
uint64_t mdbx_key_from_int64(const int64_t i64)
Definition mdbx.h:4669
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:4673
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition mdbx.h++:166
#define MDBX_CXX17_FALLTHROUGH
Definition mdbx.h++:226
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:266
#define MDBX_LIKELY(cond)
Definition mdbx.h++:200
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:176
#define MDBX_UNLIKELY(cond)
Definition mdbx.h++:208
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:154
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:195
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:217
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:175
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:232
The libmdbx C API header file.
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1059
The libmdbx C++ API namespace.
Definition mdbx.h++:299
STL namespace.
Definition mdbx.h++:1533
constexpr allocated(allocator_pointer ptr, size_t bytes) noexcept
Definition mdbx.h++:1536
constexpr allocated(const allocated &) noexcept=default
constexpr allocated(allocated &&) noexcept=default
allocator_pointer ptr_
Definition mdbx.h++:1534
size_t capacity_bytes_
Definition mdbx.h++:1535
Definition mdbx.h++:4259
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4261
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4260
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4263
Definition mdbx.h++:4247
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++:4251
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4249
Tagged type for output to std::ostream.
Definition mdbx.h++:3067
intptr_t bytes
Definition mdbx.h++:3068
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3069
Database geometry for size management.
Definition mdbx.h++:3043
constexpr geometry(intptr_t size_lower, intptr_t size_now=default_value, intptr_t size_upper=maximal_value, intptr_t growth_step=default_value, intptr_t shrink_threshold=default_value, intptr_t pagesize=default_value) noexcept
Definition mdbx.h++:3112
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3091
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3105
constexpr geometry() noexcept
Definition mdbx.h++:3109
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3095
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3079
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3099
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3074
Definition mdbx.h++:3227
Operate options.
Definition mdbx.h++:3149
constexpr operate_options() noexcept
Definition mdbx.h++:3163
constexpr operate_options & operator=(const operate_options &) noexcept=default
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
Operate parameters.
Definition mdbx.h++:3171
env::operate_options options
Definition mdbx.h++:3181
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++:3185
static env::mode mode_from_flags(MDBX_env_flags_t) noexcept
constexpr operate_parameters & operator=(const operate_parameters &) noexcept=default
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3180
static env::durability durability_from_flags(MDBX_env_flags_t) noexcept
constexpr operate_parameters() noexcept
Definition mdbx.h++:3183
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3569
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3572
uint64_t transaction_lag
Definition mdbx.h++:3575
size_t bytes_used
Definition mdbx.h++:3579
uint64_t transaction_id
Definition mdbx.h++:3573
int slot
The reader lock table slot number.
Definition mdbx.h++:3570
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3571
size_t bytes_retained
Definition mdbx.h++:3582
Garbage reclaiming options.
Definition mdbx.h++:3136
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3141
Additional parameters for creating a new database.
Definition mdbx.h++:3678
constexpr create_parameters() noexcept=default
env::geometry geometry
Definition mdbx.h++:3679
Definition mdbx.h++:2981
map_handle::state state
Definition mdbx.h++:2983
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2982
info & operator=(const info &) noexcept=default
Definition mdbx.h++:1532
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1561
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1649
constexpr bin & operator=(const bin &ditto) noexcept
Definition mdbx.h++:1626
constexpr bin(size_t capacity_bytes=0) noexcept
Definition mdbx.h++:1599
constexpr byte inplace_lastbyte() const noexcept
Definition mdbx.h++:1558
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1568
constexpr bin(bin &&ditto) noexcept
Definition mdbx.h++:1613
constexpr byte & inplace_lastbyte() noexcept
Definition mdbx.h++:1559
constexpr bin(allocator_pointer ptr, size_t capacity_bytes) noexcept
Definition mdbx.h++:1604
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1664
constexpr ~bin()
Definition mdbx.h++:1608
constexpr const byte * address() const noexcept
Definition mdbx.h++:1658
constexpr byte * make_allocated(allocator_pointer ptr, size_t capacity_bytes) noexcept
Definition mdbx.h++:1585
constexpr byte * address() noexcept
Definition mdbx.h++:1661
constexpr bin & operator=(bin &&ditto) noexcept
Definition mdbx.h++:1642
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1570