libmdbx 0.13.1.73 (2024-11-15T15:58:48+03:00)
One of the fastest compact embeddable key-value ACID database without WAL.
 
Loading...
Searching...
No Matches
mdbx.h++
Go to the documentation of this file.
1
15
23
24#pragma once
25
26/* Workaround for modern libstdc++ with CLANG < 4.x */
27#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && \
28 defined(__clang__) && __clang_major__ < 4
29#define __GLIBCXX_BITSIZE_INT_N_0 128
30#define __GLIBCXX_TYPE_INT_N_0 __int128
31#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
32
33#if !defined(__cplusplus) || __cplusplus < 201103L
34#if !defined(_MSC_VER) || _MSC_VER < 1900
35#error "C++11 compiler or better is required"
36#elif _MSC_VER >= 1910
37#error \
38 "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
39#endif /* MSVC is mad and don't define __cplusplus properly */
40#endif /* __cplusplus < 201103L */
41
42#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
43#error \
44 "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 && \
85 __cplusplus >= 201703L
86#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
87#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
88 (defined(_MSC_VER) && \
89 defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && \
90 __cplusplus >= 201403L))
91#if defined(__cpp_lib_experimental_filesystem) && \
92 __cpp_lib_experimental_filesystem >= 201406L
93#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
94#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && \
95 __has_include(<experimental/filesystem>)
96#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
97#else
98#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
99#endif
100#else
101#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
102#endif
103#endif /* MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM */
104
105#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
106#include <experimental/filesystem>
107#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
108#include <filesystem>
109#endif
110
111#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
112#include <span>
113#endif
114
115#if __cplusplus >= 201103L
116#include <chrono>
117#include <ratio>
118#endif
119
120#include "mdbx.h"
121
122#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
123 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
124 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
125 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
126#include <bit>
127#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
128 defined(__ORDER_BIG_ENDIAN__))
129#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
130#define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
131#define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
132#define __BYTE_ORDER__ __BYTE_ORDER
133#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
134#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
135#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
136#define __BYTE_ORDER__ _BYTE_ORDER
137#else
138#define __ORDER_LITTLE_ENDIAN__ 1234
139#define __ORDER_BIG_ENDIAN__ 4321
140#if defined(__LITTLE_ENDIAN__) || \
141 (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || \
142 defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
143 defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
144 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || \
145 defined(__elbrus_4c__) || defined(__elbrus_8c__) || defined(__bfin__) || \
146 defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || \
147 defined(__IA64__) || defined(__ia64) || defined(_M_IA64) || \
148 defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
149 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || \
150 defined(__WINDOWS__)
151#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
152#elif defined(__BIG_ENDIAN__) || \
153 (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || \
154 defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
155 defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
156 defined(__m68k__) || defined(M68000) || defined(__hppa__) || \
157 defined(__hppa) || defined(__HPPA__) || defined(__sparc__) || \
158 defined(__sparc) || defined(__370__) || defined(__THW_370__) || \
159 defined(__s390__) || defined(__s390x__) || defined(__SYSC_ZARCH__)
160#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
161#endif
162#endif
163#endif /* Byte Order */
164
167#if defined(DOXYGEN)
168#define MDBX_CXX17_CONSTEXPR constexpr
169#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
170 ((defined(_MSC_VER) && _MSC_VER >= 1915) || \
171 (defined(__clang__) && __clang_major__ > 5) || \
172 (defined(__GNUC__) && __GNUC__ > 7) || \
173 (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
174#define MDBX_CXX17_CONSTEXPR constexpr
175#else
176#define MDBX_CXX17_CONSTEXPR inline
177#endif /* MDBX_CXX17_CONSTEXPR */
178
181#if defined(DOXYGEN)
182#define MDBX_CXX20_CONSTEXPR constexpr
183#elif defined(__cpp_lib_is_constant_evaluated) && \
184 __cpp_lib_is_constant_evaluated >= 201811L && \
185 defined(__cpp_lib_constexpr_string) && \
186 __cpp_lib_constexpr_string >= 201907L
187#define MDBX_CXX20_CONSTEXPR constexpr
188#else
189#define MDBX_CXX20_CONSTEXPR inline
190#endif /* MDBX_CXX20_CONSTEXPR */
191
192#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
193#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
194#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
195#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
196#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
197#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
198#else
199#define MDBX_CXX01_CONSTEXPR_ENUM inline
200#define MDBX_CXX11_CONSTEXPR_ENUM inline
201#define MDBX_CXX14_CONSTEXPR_ENUM inline
202#define MDBX_CXX17_CONSTEXPR_ENUM inline
203#define MDBX_CXX20_CONSTEXPR_ENUM inline
204#endif /* CONSTEXPR_ENUM_FLAGS_OPERATIONS */
205
208#if defined(CONSTEXPR_ASSERT)
209#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
210#elif defined NDEBUG
211#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
212#else
213#define MDBX_CONSTEXPR_ASSERT(expr) \
214 ((expr) ? void(0) : [] { assert(!#expr); }())
215#endif /* MDBX_CONSTEXPR_ASSERT */
216
217#ifndef MDBX_LIKELY
218#if defined(DOXYGEN) || \
219 (defined(__GNUC__) || __has_builtin(__builtin_expect)) && \
220 !defined(__COVERITY__)
221#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
222#else
223#define MDBX_LIKELY(x) (x)
224#endif
225#endif /* MDBX_LIKELY */
226
227#ifndef MDBX_UNLIKELY
228#if defined(DOXYGEN) || \
229 (defined(__GNUC__) || __has_builtin(__builtin_expect)) && \
230 !defined(__COVERITY__)
231#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
232#else
233#define MDBX_UNLIKELY(x) (x)
234#endif
235#endif /* MDBX_UNLIKELY */
236
239#if defined(DOXYGEN)
240#define MDBX_IF_CONSTEXPR constexpr
241#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
242#define MDBX_IF_CONSTEXPR constexpr
243#else
244#define MDBX_IF_CONSTEXPR
245#endif /* MDBX_IF_CONSTEXPR */
246
247#if defined(DOXYGEN) || \
248 (__has_cpp_attribute(fallthrough) && \
249 (!defined(__clang__) || __clang__ > 4)) || \
250 __cplusplus >= 201703L
251#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
252#else
253#define MDBX_CXX17_FALLTHROUGH
254#endif /* MDBX_CXX17_FALLTHROUGH */
255
256#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && \
257 (!defined(__GNUC__) || __GNUC__ > 9))
258#define MDBX_CXX20_LIKELY [[likely]]
259#else
260#define MDBX_CXX20_LIKELY
261#endif /* MDBX_CXX20_LIKELY */
262
263#ifndef MDBX_CXX20_UNLIKELY
264#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && \
265 (!defined(__GNUC__) || __GNUC__ > 9))
266#define MDBX_CXX20_UNLIKELY [[unlikely]]
267#else
268#define MDBX_CXX20_UNLIKELY
269#endif
270#endif /* MDBX_CXX20_UNLIKELY */
271
272#ifndef MDBX_HAVE_CXX20_CONCEPTS
273#if defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
274#include <concepts>
275#define MDBX_HAVE_CXX20_CONCEPTS 1
276#elif defined(DOXYGEN)
277#define MDBX_HAVE_CXX20_CONCEPTS 1
278#else
279#define MDBX_HAVE_CXX20_CONCEPTS 0
280#endif /* <concepts> */
281#endif /* MDBX_HAVE_CXX20_CONCEPTS */
282
283#ifndef MDBX_CXX20_CONCEPT
284#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
285#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
286#else
287#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
288#endif
289#endif /* MDBX_CXX20_CONCEPT */
290
291#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
292#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
293#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) \
294 static_assert(CONCEPT<TYPE>)
295#else
296#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
297 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
298#endif
299#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
300
301#ifdef _MSC_VER
302#pragma warning(push, 4)
303#pragma warning(disable : 4127) /* conditional expression is constant */
304#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
305 be used by clients of 'mdbx::BAR' */
306#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
307 base for dll-interface 'mdbx::BAR' */
308/* MSVC is mad and can generate this warning for its own intermediate
309 * automatically generated code, which becomes unreachable after some kinds of
310 * optimization (copy elision, etc). */
311#pragma warning(disable : 4702) /* unreachable code */
312#endif /* _MSC_VER (warnings) */
313
314#if defined(__LCC__) && __LCC__ >= 126
315#pragma diagnostic push
316#if __LCC__ < 127
317#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
318 appearing in a constant expression `true` */
319#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
320 appearing in a constant expression `false` */
321#endif
322#endif /* E2K LCC (warnings) */
323
324//------------------------------------------------------------------------------
327namespace mdbx {
328
331
332// Functions whose signature depends on the `mdbx::byte` type
333// must be strictly defined as inline!
334#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
335// To enable all kinds of an compiler optimizations we use a byte-like type
336// that don't presumes aliases for pointers as does the `char` type and its
337// derivatives/typedefs.
338// Please see https://libmdbx.dqdkfa.ru/dead-github/issues/263
339// for reasoning of the use of `char8_t` type and switching to `__restrict__`.
340using byte = char8_t;
341#else
342// Avoid `std::byte` since it doesn't add features but inconvenient
343// restrictions.
344using byte = unsigned char;
345#endif /* __cpp_char8_t >= 201811*/
346
347#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
348using endian = ::std::endian;
349#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
350 defined(__ORDER_BIG_ENDIAN__)
351enum class endian {
352 little = __ORDER_LITTLE_ENDIAN__,
353 big = __ORDER_BIG_ENDIAN__,
354 native = __BYTE_ORDER__
355};
356#else
357#error \
358 "Please use a C++ compiler provides byte order information or C++20 support"
359#endif /* Byte Order enum */
360
369
371static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
372
374static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src,
375 size_t bytes) noexcept;
377static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b,
378 size_t bytes) noexcept;
379
382using legacy_allocator = ::std::string::allocator_type;
383
384#if defined(DOXYGEN) || \
385 (defined(__cpp_lib_memory_resource) && \
386 __cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI)
388using polymorphic_allocator = ::std::pmr::string::allocator_type;
390#else
392#endif /* __cpp_lib_memory_resource >= 201603L */
393
394struct slice;
396template <class ALLOCATOR = default_allocator,
397 class CAPACITY_POLICY = default_capacity_policy>
398class buffer;
399class env;
400class env_managed;
401class txn;
402class txn_managed;
403class cursor;
404class cursor_managed;
405
408
410template <class ALLOCATOR = default_allocator>
411using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
412
414#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
415#ifdef _MSC_VER
416namespace filesystem = ::std::experimental::filesystem::v1;
417#else
418namespace filesystem = ::std::experimental::filesystem;
419#endif
420#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
421#elif defined(DOXYGEN) || \
422 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && \
423 defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && \
424 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || \
425 __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
426 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || \
427 __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
428 (!defined(_MSC_VER) || __cplusplus >= 201703L)
429namespace filesystem = ::std::filesystem;
436#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
437#endif /* MDBX_STD_FILESYSTEM_PATH */
438
439#ifdef MDBX_STD_FILESYSTEM_PATH
441#elif defined(_WIN32) || defined(_WIN64)
442using path = ::std::wstring;
443#else
444using path = ::std::string;
445#endif /* mdbx::path */
446
447#if defined(__SIZEOF_INT128__) || \
448 (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
449#ifndef MDBX_U128_TYPE
450#define MDBX_U128_TYPE __uint128_t
451#endif /* MDBX_U128_TYPE */
452#ifndef MDBX_I128_TYPE
453#define MDBX_I128_TYPE __int128_t
454#endif /* MDBX_I128_TYPE */
455#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
456
457#if __cplusplus >= 201103L || defined(DOXYGEN)
459using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
460#endif /* Duration for C++11 */
461
464
470 ::std::exception_ptr captured_;
471
472public:
473 exception_thunk() noexcept = default;
476 exception_thunk &operator=(const exception_thunk &) = delete;
477 exception_thunk &operator=(exception_thunk &&) = delete;
478 inline bool is_clean() const noexcept;
479 inline void capture() noexcept;
480 inline void rethrow_captured() const;
481};
482
485 MDBX_error_t code_;
486 inline error &operator=(MDBX_error_t error_code) noexcept;
487
488public:
489 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
490 error(const error &) = default;
491 error(error &&) = default;
492 error &operator=(const error &) = default;
493 error &operator=(error &&) = default;
494
495 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a,
496 const error &b) noexcept;
497 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a,
498 const error &b) noexcept;
499
500 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
501 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
502 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
503 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
504
506 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
507
509 const char *what() const noexcept;
510
512 ::std::string message() const;
513
515 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
517 [[noreturn]] void panic(const char *context_where_when,
518 const char *func_who_what) const noexcept;
519 [[noreturn]] void throw_exception() const;
520 [[noreturn]] static inline void throw_exception(int error_code);
521 inline void throw_on_failure() const;
522 inline void success_or_throw() const;
523 inline void success_or_throw(const exception_thunk &) const;
524 inline void panic_on_failure(const char *context_where,
525 const char *func_who) const noexcept;
526 inline void success_or_panic(const char *context_where,
527 const char *func_who) const noexcept;
528 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
529 static inline void success_or_throw(MDBX_error_t error_code);
530 static void success_or_throw(int error_code) {
531 success_or_throw(static_cast<MDBX_error_t>(error_code));
532 }
533 static inline void throw_on_failure(int error_code);
534 static inline bool boolean_or_throw(int error_code);
535 static inline void success_or_throw(int error_code, const exception_thunk &);
536 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
537 static inline void panic_on_failure(int error_code, const char *context_where,
538 const char *func_who) noexcept;
539 static inline void success_or_panic(int error_code, const char *context_where,
540 const char *func_who) noexcept;
541};
542
547class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
548 using base = ::std::runtime_error;
549 ::mdbx::error error_;
550
551public:
552 exception(const ::mdbx::error &) noexcept;
553 exception(const exception &) = default;
554 exception(exception &&) = default;
555 exception &operator=(const exception &) = default;
557 virtual ~exception() noexcept;
558 const ::mdbx::error error() const noexcept { return error_; }
559};
560
564 using base = exception;
565
566public:
567 fatal(const ::mdbx::error &) noexcept;
568 fatal(const exception &src) noexcept : fatal(src.error()) {}
569 fatal(exception &&src) noexcept : fatal(src.error()) {}
570 fatal(const fatal &src) noexcept : fatal(src.error()) {}
571 fatal(fatal &&src) noexcept : fatal(src.error()) {}
572 fatal &operator=(fatal &&) = default;
573 fatal &operator=(const fatal &) = default;
574 virtual ~fatal() noexcept;
575};
576
577#define MDBX_DECLARE_EXCEPTION(NAME) \
578 struct LIBMDBX_API_TYPE NAME : public exception { \
579 NAME(const ::mdbx::error &); \
580 virtual ~NAME() noexcept; \
581 }
614#undef MDBX_DECLARE_EXCEPTION
615
618[[noreturn]] LIBMDBX_API void throw_out_range();
622static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes);
623static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom,
624 size_t payload);
625static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload,
626 size_t tailroom);
627
629
630//------------------------------------------------------------------------------
631
634
635#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
636
640template <typename T>
641concept MutableByteProducer = requires(T a, char array[42]) {
642 { a.is_empty() } -> std::same_as<bool>;
643 { a.envisage_result_length() } -> std::same_as<size_t>;
644 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
645};
646
650template <typename T>
651concept ImmutableByteProducer = requires(const T &a, char array[42]) {
652 { a.is_empty() } -> std::same_as<bool>;
653 { a.envisage_result_length() } -> std::same_as<size_t>;
654 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
655};
656
660template <typename T>
662 ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
663 T(source);
664 { a.is_erroneous() } -> std::same_as<bool>;
665 };
666
667#endif /* MDBX_HAVE_CXX20_CONCEPTS */
668
669template <class ALLOCATOR = default_allocator,
670 typename CAPACITY_POLICY = default_capacity_policy,
671 MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
673make_buffer(PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
674
675template <class ALLOCATOR = default_allocator,
676 typename CAPACITY_POLICY = default_capacity_policy,
677 MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
679make_buffer(const PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
680
681template <class ALLOCATOR = default_allocator,
682 MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
683inline string<ALLOCATOR> make_string(PRODUCER &producer,
684 const ALLOCATOR &allocator = ALLOCATOR());
685
686template <class ALLOCATOR = default_allocator,
687 MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
688inline string<ALLOCATOR> make_string(const PRODUCER &producer,
689 const ALLOCATOR &allocator = ALLOCATOR());
690
702
703 enum { max_length = MDBX_MAXDATASIZE };
704
706 MDBX_CXX11_CONSTEXPR slice() noexcept;
707
710 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
711
713 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
714
716 template <size_t SIZE>
717 MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
718 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
719 }
721 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
722
725 template <class CHAR, class T, class A>
726 explicit MDBX_CXX20_CONSTEXPR
727 slice(const ::std::basic_string<CHAR, T, A> &str)
728 : slice(str.data(), str.length() * sizeof(CHAR)) {}
729
731 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
733 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
734
735#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
736 template <typename POD>
737 MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span)
738 : slice(span.begin(), span.end()) {
739 static_assert(::std::is_standard_layout<POD>::value &&
740 !::std::is_pointer<POD>::value,
741 "Must be a standard layout type!");
742 }
743
744 template <typename POD>
745 MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
746 static_assert(::std::is_standard_layout<POD>::value &&
747 !::std::is_pointer<POD>::value,
748 "Must be a standard layout type!");
749 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
751 return ::std::span<const POD>(static_cast<const POD *>(data()),
752 size() / sizeof(POD));
754 }
755
756 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
757 static_assert(::std::is_standard_layout<POD>::value &&
758 !::std::is_pointer<POD>::value,
759 "Must be a standard layout type!");
760 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
762 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
764 }
765
766 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const {
767 return as_span<const byte>();
768 }
769 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
770 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const {
771 return as_span<const char>();
772 }
773 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
774#endif /* __cpp_lib_span >= 202002L */
775
776#if defined(DOXYGEN) || \
777 (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
779 template <class CHAR, class T>
780 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv)
781 : slice(sv.data(), sv.data() + sv.length()) {}
782
783 template <class CHAR, class T>
784 slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) {
785 sv = {};
786 }
787#endif /* __cpp_lib_string_view >= 201606L */
788
789 template <size_t SIZE>
790 static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) {
791 return slice(text);
792 }
793
794 template <typename POD>
795 MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
796 static_assert(::std::is_standard_layout<POD>::value &&
797 !::std::is_pointer<POD>::value,
798 "Must be a standard layout type!");
799 return slice(&pod, sizeof(pod));
800 }
801
802 inline slice &assign(const void *ptr, size_t bytes);
803 inline slice &assign(const slice &src) noexcept;
804 inline slice &assign(const ::MDBX_val &src);
805 inline slice &assign(slice &&src) noexcept;
806 inline slice &assign(::MDBX_val &&src);
807 inline slice &assign(const void *begin, const void *end);
808 template <class CHAR, class T, class ALLOCATOR>
809 slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
810 return assign(str.data(), str.length() * sizeof(CHAR));
811 }
812 inline slice &assign(const char *c_str);
813#if defined(DOXYGEN) || \
814 (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
815 template <class CHAR, class T>
816 slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
817 return assign(view.begin(), view.end());
818 }
819 template <class CHAR, class T>
820 slice &assign(::std::basic_string_view<CHAR, T> &&view) {
821 assign(view);
822 view = {};
823 return *this;
824 }
825#endif /* __cpp_lib_string_view >= 201606L */
826
827 slice &operator=(const slice &) noexcept = default;
828 inline slice &operator=(slice &&src) noexcept;
829 inline slice &operator=(::MDBX_val &&src);
830 operator MDBX_val *() noexcept { return this; }
831 operator const MDBX_val *() const noexcept { return this; }
832
833#if defined(DOXYGEN) || \
834 (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
835 template <class CHAR, class T>
836 slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
837 return assign(view);
838 }
839
840 template <class CHAR, class T>
841 slice &operator=(::std::basic_string_view<CHAR, T> &&view) {
842 return assign(view);
843 }
844
846 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
847 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T>
848 string_view() const noexcept {
849 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
850 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
851 }
852
854 template <class CHAR, class T>
856 operator ::std::basic_string_view<CHAR, T>() const noexcept {
857 return this->string_view<CHAR, T>();
858 }
859#endif /* __cpp_lib_string_view >= 201606L */
860
861 template <class CHAR = char, class T = ::std::char_traits<CHAR>,
862 class ALLOCATOR = default_allocator>
863 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR>
864 as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
865 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
866 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(),
867 allocator);
868 }
869
870 template <class CHAR, class T, class ALLOCATOR>
872 operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
873 return as_string<CHAR, T, ALLOCATOR>();
874 }
875
877 template <class ALLOCATOR = default_allocator>
878 inline string<ALLOCATOR>
879 as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
880 const ALLOCATOR &allocator = ALLOCATOR()) const;
881
884 template <class ALLOCATOR = default_allocator>
885 inline string<ALLOCATOR>
886 as_base58_string(unsigned wrap_width = 0,
887 const ALLOCATOR &allocator = ALLOCATOR()) const;
888
891 template <class ALLOCATOR = default_allocator>
892 inline string<ALLOCATOR>
893 as_base64_string(unsigned wrap_width = 0,
894 const ALLOCATOR &allocator = ALLOCATOR()) const;
895
897 template <class ALLOCATOR = default_allocator,
898 class CAPACITY_POLICY = default_capacity_policy>
900 encode_hex(bool uppercase = false, unsigned wrap_width = 0,
901 const ALLOCATOR &allocator = ALLOCATOR()) const;
902
905 template <class ALLOCATOR = default_allocator,
906 class CAPACITY_POLICY = default_capacity_policy>
908 encode_base58(unsigned wrap_width = 0,
909 const ALLOCATOR &allocator = ALLOCATOR()) const;
910
913 template <class ALLOCATOR = default_allocator,
914 class CAPACITY_POLICY = default_capacity_policy>
916 encode_base64(unsigned wrap_width = 0,
917 const ALLOCATOR &allocator = ALLOCATOR()) const;
918
920 template <class ALLOCATOR = default_allocator,
921 class CAPACITY_POLICY = default_capacity_policy>
923 hex_decode(bool ignore_spaces = false,
924 const ALLOCATOR &allocator = ALLOCATOR()) const;
925
928 template <class ALLOCATOR = default_allocator,
929 class CAPACITY_POLICY = default_capacity_policy>
931 base58_decode(bool ignore_spaces = false,
932 const ALLOCATOR &allocator = ALLOCATOR()) const;
933
936 template <class ALLOCATOR = default_allocator,
937 class CAPACITY_POLICY = default_capacity_policy>
939 base64_decode(bool ignore_spaces = false,
940 const ALLOCATOR &allocator = ALLOCATOR()) const;
941
948 is_printable(bool disable_utf8 = false) const noexcept;
949
955 is_hex(bool ignore_spaces = false) const noexcept;
956
963 is_base58(bool ignore_spaces = false) const noexcept;
964
971 is_base64(bool ignore_spaces = false) const noexcept;
972
973 inline void swap(slice &other) noexcept;
974
975#if defined(DOXYGEN) || \
976 (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
977 template <class CHAR, class T>
978 void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
979 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
980 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
981 *this = view;
982 view = temp;
983 }
984#endif /* __cpp_lib_string_view >= 201606L */
985
987 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
988 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
989
991 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
992 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
993
995 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
996 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
997
999 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
1000 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
1001
1003 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
1004 MDBX_CXX11_CONSTEXPR void *data() noexcept;
1005
1007 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
1008 MDBX_CXX11_CONSTEXPR void *end() noexcept;
1009
1011 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
1012
1014 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
1015
1017 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
1018
1020 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
1021
1023 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
1024
1026 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
1027
1029 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
1030
1032 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
1033
1035 MDBX_CXX14_CONSTEXPR void clear() noexcept;
1036
1039 inline void remove_prefix(size_t n) noexcept;
1040
1043 inline void remove_suffix(size_t n) noexcept;
1044
1047 inline void safe_remove_prefix(size_t n);
1048
1051 inline void safe_remove_suffix(size_t n);
1052
1055 starts_with(const slice &prefix) const noexcept;
1056
1059 ends_with(const slice &suffix) const noexcept;
1060
1063 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
1064
1067 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
1068
1071 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
1072
1075 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
1076
1079 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
1080
1083 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
1084
1087 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
1088
1091 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
1092
1098 hash_value() const noexcept;
1099
1109 compare_fast(const slice &a, const slice &b) noexcept;
1110
1117 compare_lexicographically(const slice &a, const slice &b) noexcept;
1118 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a,
1119 const slice &b) noexcept;
1120 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a,
1121 const slice &b) noexcept;
1122 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a,
1123 const slice &b) noexcept;
1124 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a,
1125 const slice &b) noexcept;
1126 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a,
1127 const slice &b) noexcept;
1128 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a,
1129 const slice &b) noexcept;
1130
1132 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept {
1133 return !(iov_base == nullptr && iov_len != 0);
1134 }
1135
1139 return slice(size_t(-1));
1140 }
1141
1142 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1143 static_assert(::std::is_standard_layout<POD>::value &&
1144 !::std::is_pointer<POD>::value,
1145 "Must be a standard layout type!");
1146 if (MDBX_LIKELY(size() == sizeof(POD)))
1148 POD r;
1149 memcpy(&r, data(), sizeof(r));
1150 return r;
1151 }
1153 }
1154
1155#ifdef MDBX_U128_TYPE
1156 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const {
1157 return as_pod<MDBX_U128_TYPE>();
1158 }
1159#endif /* MDBX_U128_TYPE */
1160 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1161 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1162 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1163 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1164
1165#ifdef MDBX_I128_TYPE
1166 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const {
1167 return as_pod<MDBX_I128_TYPE>();
1168 }
1169#endif /* MDBX_I128_TYPE */
1170 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1171 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1172 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1173 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1174
1175#ifdef MDBX_U128_TYPE
1176 MDBX_U128_TYPE as_uint128_adapt() const;
1177#endif /* MDBX_U128_TYPE */
1178 uint64_t as_uint64_adapt() const;
1179 uint32_t as_uint32_adapt() const;
1180 uint16_t as_uint16_adapt() const;
1181 uint8_t as_uint8_adapt() const;
1182
1183#ifdef MDBX_I128_TYPE
1184 MDBX_I128_TYPE as_int128_adapt() const;
1185#endif /* MDBX_I128_TYPE */
1186 int64_t as_int64_adapt() const;
1187 int32_t as_int32_adapt() const;
1188 int16_t as_int16_adapt() const;
1189 int8_t as_int8_adapt() const;
1190
1191protected:
1192 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept
1193 : ::MDBX_val({nullptr, invalid_length}) {}
1194};
1195
1196//------------------------------------------------------------------------------
1197
1198namespace allocation_aware_details {
1199
1200template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1201#if defined(__cpp_lib_allocator_traits_is_always_equal) && \
1202 __cpp_lib_allocator_traits_is_always_equal >= 201411L
1203 return ::std::allocator_traits<A>::is_always_equal::value;
1204#else
1205 return ::std::is_empty<A>::value;
1206#endif /* __cpp_lib_allocator_traits_is_always_equal */
1207}
1208
1209template <typename T, typename A = typename T::allocator_type,
1210 bool PoCMA = ::std::allocator_traits<
1211 A>::propagate_on_container_move_assignment::value>
1213
1214template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1215 static constexpr bool is_nothrow() noexcept {
1216 return allocator_is_always_equal<A>();
1217 }
1218 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1219 return allocator_is_always_equal<A>() ||
1220 target->get_allocator() == source.get_allocator();
1221 }
1222 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1223 assert(target->get_allocator() != source.get_allocator());
1224 (void)target;
1225 (void)source;
1226 }
1227};
1228
1229template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1230 static constexpr bool is_nothrow() noexcept {
1231 return allocator_is_always_equal<A>() ||
1232 ::std::is_nothrow_move_assignable<A>::value;
1233 }
1234 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1235 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) {
1236 assert(target->get_allocator() != source.get_allocator());
1237 target->get_allocator() = ::std::move(source.get_allocator());
1238 }
1239};
1240
1241template <typename T, typename A = typename T::allocator_type,
1242 bool PoCCA = ::std::allocator_traits<
1243 A>::propagate_on_container_copy_assignment::value>
1245
1246template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1247 static constexpr bool is_nothrow() noexcept { return false; }
1248 static MDBX_CXX20_CONSTEXPR void propagate(T *target,
1249 const T &source) noexcept {
1250 assert(target->get_allocator() != source.get_allocator());
1251 (void)target;
1252 (void)source;
1253 }
1254};
1255
1256template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1257 static constexpr bool is_nothrow() noexcept {
1258 return allocator_is_always_equal<A>() ||
1259 ::std::is_nothrow_copy_assignable<A>::value;
1260 }
1261 static MDBX_CXX20_CONSTEXPR void
1262 propagate(T *target, const T &source) noexcept(is_nothrow()) {
1263 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1264 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1265 MDBX_CXX20_UNLIKELY target->get_allocator() =
1266 ::std::allocator_traits<A>::select_on_container_copy_construction(
1267 source.get_allocator());
1268 } else {
1269 /* gag for buggy compilers */
1270 (void)target;
1271 (void)source;
1272 }
1273 }
1274};
1275
1276template <typename T, typename A = typename T::allocator_type,
1277 bool PoCS =
1278 ::std::allocator_traits<A>::propagate_on_container_swap::value>
1280
1281template <typename T, typename A> struct swap_alloc<T, A, false> {
1282 static constexpr bool is_nothrow() noexcept {
1283 return allocator_is_always_equal<A>();
1284 }
1285 static MDBX_CXX20_CONSTEXPR void propagate(T *target,
1286 T &source) noexcept(is_nothrow()) {
1287 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1288 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1289 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1290 } else {
1291 /* gag for buggy compilers */
1292 (void)target;
1293 (void)source;
1294 }
1295 }
1296};
1297
1298template <typename T, typename A> struct swap_alloc<T, A, true> {
1299 static constexpr bool is_nothrow() noexcept {
1300 return allocator_is_always_equal<A>() ||
1301#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1302 ::std::is_nothrow_swappable<A>() ||
1303#endif /* __cpp_lib_is_swappable >= 201603L */
1304 (::std::is_nothrow_move_constructible<A>::value &&
1305 ::std::is_nothrow_move_assignable<A>::value);
1306 }
1307 static MDBX_CXX20_CONSTEXPR void propagate(T *target,
1308 T &source) noexcept(is_nothrow()) {
1309 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1310 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1311 MDBX_CXX20_UNLIKELY ::std::swap(*target, source);
1312 } else {
1313 /* gag for buggy compilers */
1314 (void)target;
1315 (void)source;
1316 }
1317 }
1318};
1319
1320} // namespace allocation_aware_details
1321
1323 enum : size_t {
1324 extra_inplace_storage = 0,
1325 pettiness_threshold = 64,
1326 max_reserve = 65536
1328
1329 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1330 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0,
1331 "pettiness_threshold must be a power of 2");
1332 static_assert(pettiness_threshold % 2 == 0,
1333 "pettiness_threshold must be even");
1334 static_assert(pettiness_threshold >= sizeof(uint64_t),
1335 "pettiness_threshold must be > 7");
1336 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1337 return (value + pettiness_threshold - 1) & pettiness_mask;
1338 }
1339
1340 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current,
1341 const size_t wanna) {
1342 static_assert(max_reserve % pettiness_threshold == 0,
1343 "max_reserve must be a multiple of pettiness_threshold");
1344 static_assert(max_reserve / 3 > pettiness_threshold,
1345 "max_reserve must be > pettiness_threshold * 3");
1346 if (wanna > current)
1347 /* doubling capacity, but don't made reserve more than max_reserve */
1348 return round(wanna + ::std::min(size_t(max_reserve), current));
1349
1350 if (current - wanna >
1351 /* shrink if reserve will more than half of current or max_reserve,
1352 * but not less than pettiness_threshold */
1353 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1354 return round(wanna);
1355
1356 /* keep unchanged */
1357 return current;
1358 }
1359};
1360
1364 const bool uppercase = false;
1365 const unsigned wrap_width = 0;
1366 MDBX_CXX11_CONSTEXPR to_hex(const slice &source, bool uppercase = false,
1367 unsigned wrap_width = 0) noexcept
1368 : source(source), uppercase(uppercase), wrap_width(wrap_width) {
1370 }
1371
1373 template <class ALLOCATOR = default_allocator>
1374 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1375 return make_string<ALLOCATOR>(*this, allocator);
1376 }
1377
1379 template <class ALLOCATOR = default_allocator,
1380 typename CAPACITY_POLICY = default_capacity_policy>
1382 as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1383 return make_buffer<ALLOCATOR>(*this, allocator);
1384 }
1385
1389 const size_t bytes = source.length() << 1;
1390 return wrap_width ? bytes + bytes / wrap_width : bytes;
1391 }
1392
1395 char *write_bytes(char *dest, size_t dest_size) const;
1396
1400 ::std::ostream &output(::std::ostream &out) const;
1401
1404 bool is_empty() const noexcept { return source.empty(); }
1405
1408 bool is_erroneous() const noexcept { return false; }
1409};
1410
1415 const unsigned wrap_width = 0;
1417 to_base58(const slice &source, unsigned wrap_width = 0) noexcept
1418 : source(source), wrap_width(wrap_width) {
1420 }
1421
1424 template <class ALLOCATOR = default_allocator>
1425 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1426 return make_string<ALLOCATOR>(*this, allocator);
1427 }
1428
1431 template <class ALLOCATOR = default_allocator,
1432 typename CAPACITY_POLICY = default_capacity_policy>
1434 as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1435 return make_buffer<ALLOCATOR>(*this, allocator);
1436 }
1437
1441 const size_t bytes = (source.length() * 11 + 7) / 8;
1442 return wrap_width ? bytes + bytes / wrap_width : bytes;
1443 }
1444
1448 char *write_bytes(char *dest, size_t dest_size) const;
1449
1454 ::std::ostream &output(::std::ostream &out) const;
1455
1458 bool is_empty() const noexcept { return source.empty(); }
1459
1462 bool is_erroneous() const noexcept { return false; }
1463};
1464
1469 const unsigned wrap_width = 0;
1471 to_base64(const slice &source, unsigned wrap_width = 0) noexcept
1472 : source(source), wrap_width(wrap_width) {
1474 }
1475
1478 template <class ALLOCATOR = default_allocator>
1479 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1480 return make_string<ALLOCATOR>(*this, allocator);
1481 }
1482
1485 template <class ALLOCATOR = default_allocator,
1486 typename CAPACITY_POLICY = default_capacity_policy>
1488 as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1489 return make_buffer<ALLOCATOR>(*this, allocator);
1490 }
1491
1495 const size_t bytes = (source.length() + 2) / 3 * 4;
1496 return wrap_width ? bytes + bytes / wrap_width : bytes;
1497 }
1498
1502 char *write_bytes(char *dest, size_t dest_size) const;
1503
1508 ::std::ostream &output(::std::ostream &out) const;
1509
1512 bool is_empty() const noexcept { return source.empty(); }
1513
1516 bool is_erroneous() const noexcept { return false; }
1517};
1518
1519inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) {
1520 return wrapper.output(out);
1521}
1522inline ::std::ostream &operator<<(::std::ostream &out,
1523 const to_base58 &wrapper) {
1524 return wrapper.output(out);
1525}
1526inline ::std::ostream &operator<<(::std::ostream &out,
1527 const to_base64 &wrapper) {
1528 return wrapper.output(out);
1529}
1530
1534 const bool ignore_spaces = false;
1536 bool ignore_spaces = false) noexcept
1537 : source(source), ignore_spaces(ignore_spaces) {
1539 }
1540
1542 template <class ALLOCATOR = default_allocator>
1543 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1544 return make_string<ALLOCATOR>(*this, allocator);
1545 }
1546
1548 template <class ALLOCATOR = default_allocator,
1549 typename CAPACITY_POLICY = default_capacity_policy>
1551 as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1552 return make_buffer<ALLOCATOR>(*this, allocator);
1553 }
1554
1558 return source.length() >> 1;
1559 }
1560
1564 char *write_bytes(char *dest, size_t dest_size) const;
1565
1568 bool is_empty() const noexcept { return source.empty(); }
1569
1572 bool is_erroneous() const noexcept;
1573};
1574
1579 const bool ignore_spaces = false;
1581 bool ignore_spaces = false) noexcept
1582 : source(source), ignore_spaces(ignore_spaces) {
1584 }
1585
1588 template <class ALLOCATOR = default_allocator>
1589 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1590 return make_string<ALLOCATOR>(*this, allocator);
1591 }
1592
1595 template <class ALLOCATOR = default_allocator,
1596 typename CAPACITY_POLICY = default_capacity_policy>
1598 as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1599 return make_buffer<ALLOCATOR>(*this, allocator);
1600 }
1601
1606 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1607 }
1608
1612 char *write_bytes(char *dest, size_t dest_size) const;
1613
1616 bool is_empty() const noexcept { return source.empty(); }
1617
1621 bool is_erroneous() const noexcept;
1622};
1623
1628 const bool ignore_spaces = false;
1630 bool ignore_spaces = false) noexcept
1631 : source(source), ignore_spaces(ignore_spaces) {
1633 }
1634
1637 template <class ALLOCATOR = default_allocator>
1638 string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1639 return make_string<ALLOCATOR>(*this, allocator);
1640 }
1641
1644 template <class ALLOCATOR = default_allocator,
1645 typename CAPACITY_POLICY = default_capacity_policy>
1647 as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1648 return make_buffer<ALLOCATOR>(*this, allocator);
1649 }
1650
1655 return (source.length() + 3) / 4 * 3;
1656 }
1657
1661 char *write_bytes(char *dest, size_t dest_size) const;
1662
1665 bool is_empty() const noexcept { return source.empty(); }
1666
1670 bool is_erroneous() const noexcept;
1671};
1672
1674template <class ALLOCATOR, typename CAPACITY_POLICY> class buffer {
1675public:
1676#if !defined(_MSC_VER) || _MSC_VER > 1900
1677 using allocator_type = typename ::std::allocator_traits<
1678 ALLOCATOR>::template rebind_alloc<uint64_t>;
1679#else
1680 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1681#endif /* MSVC is mad */
1682 using allocator_traits = ::std::allocator_traits<allocator_type>;
1683 using reservation_policy = CAPACITY_POLICY;
1684 enum : size_t {
1685 max_length = MDBX_MAXDATASIZE,
1686 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1687 extra_inplace_storage = reservation_policy::extra_inplace_storage,
1688 pettiness_threshold = reservation_policy::pettiness_threshold
1690
1691private:
1692 friend class txn;
1693 struct silo;
1695 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1696 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept {
1697 return *this;
1698 }
1699 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept {
1700 return *this;
1701 }
1702
1703 using allocator_pointer = typename allocator_traits::pointer;
1704 using allocator_const_pointer = typename allocator_traits::const_pointer;
1705
1706 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t>
1707 allocate_storage(size_t bytes) {
1708 assert(bytes >= sizeof(bin));
1709 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1710 static_assert((unit & (unit - 1)) == 0,
1711 "size of ALLOCATOR::value_type should be a power of 2");
1712 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1713 const size_t n = (bytes + unit - 1) / unit;
1714 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n),
1715 n * unit);
1716 }
1717 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr,
1718 size_t bytes) {
1719 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1720 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1721 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1722 }
1723
1724 static MDBX_CXX17_CONSTEXPR void *
1725 to_address(allocator_pointer ptr) noexcept {
1726#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1727 return static_cast<void *>(::std::to_address(ptr));
1728#else
1729 return static_cast<void *>(::std::addressof(*ptr));
1730#endif /* __cpp_lib_to_address */
1731 }
1732 static MDBX_CXX17_CONSTEXPR const void *
1733 to_address(allocator_const_pointer ptr) noexcept {
1734#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1735 return static_cast<const void *>(::std::to_address(ptr));
1736#else
1737 return static_cast<const void *>(::std::addressof(*ptr));
1738#endif /* __cpp_lib_to_address */
1739 }
1740
1741 union bin {
1742 struct allocated {
1743 allocator_pointer ptr_;
1745 constexpr allocated(allocator_pointer ptr, size_t bytes) noexcept
1746 : ptr_(ptr), capacity_bytes_(bytes) {}
1747 constexpr allocated(const allocated &) noexcept = default;
1748 constexpr allocated(allocated &&) noexcept = default;
1750 operator=(const allocated &) noexcept = default;
1752 operator=(allocated &&) noexcept = default;
1753 };
1754
1755 allocated allocated_;
1756 uint64_t align_hint_;
1757 byte inplace_[(sizeof(allocated) + extra_inplace_storage + 7u) &
1758 ~size_t(7)];
1759
1760 static constexpr bool
1761 is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1762 static_assert(sizeof(bin) == sizeof(inplace_), "WTF?");
1763 return capacity_bytes < sizeof(bin);
1764 }
1765
1766 enum : byte { lastbyte_inplace_signature = byte(~byte(0)) };
1767 enum : size_t {
1768 inplace_signature_limit =
1769 size_t(lastbyte_inplace_signature)
1770 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT
1772
1773 constexpr byte inplace_lastbyte() const noexcept {
1774 return inplace_[sizeof(bin) - 1];
1775 }
1777 return inplace_[sizeof(bin) - 1];
1778 }
1779
1780 constexpr bool is_inplace() const noexcept {
1781 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity),
1782 "WTF?");
1783 static_assert(
1784 std::numeric_limits<size_t>::max() -
1785 (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1786 inplace_signature_limit,
1787 "WTF?");
1788 return inplace_lastbyte() == lastbyte_inplace_signature;
1789 }
1790 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1791
1792 template <bool destroy_ptr>
1794 if (destroy_ptr) {
1795 MDBX_CONSTEXPR_ASSERT(is_allocated());
1796 /* properly destroy allocator::pointer */
1797 allocated_.~allocated();
1798 }
1799 if (::std::is_trivial<allocator_pointer>::value)
1800 /* workaround for "uninitialized" warning from some compilers */
1801 memset(&allocated_.ptr_, 0, sizeof(allocated_.ptr_));
1802 inplace_lastbyte() = lastbyte_inplace_signature;
1803 MDBX_CONSTEXPR_ASSERT(is_inplace() && address() == inplace_ &&
1804 is_suitable_for_inplace(capacity()));
1805 return address();
1806 }
1807
1808 template <bool construct_ptr>
1810 make_allocated(allocator_pointer ptr, size_t capacity_bytes) noexcept {
1811 MDBX_CONSTEXPR_ASSERT(inplace_signature_limit > capacity_bytes);
1812 if (construct_ptr)
1813 /* properly construct allocator::pointer */
1814 new (&allocated_) allocated(ptr, capacity_bytes);
1815 else {
1816 MDBX_CONSTEXPR_ASSERT(is_allocated());
1817 allocated_.ptr_ = ptr;
1818 allocated_.capacity_bytes_ = capacity_bytes;
1819 }
1820 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(ptr) &&
1821 capacity() == capacity_bytes);
1822 return address();
1823 }
1824
1825 MDBX_CXX20_CONSTEXPR bin(size_t capacity_bytes = 0) noexcept {
1826 MDBX_CONSTEXPR_ASSERT(is_suitable_for_inplace(capacity_bytes));
1827 make_inplace<false>();
1828 (void)capacity_bytes;
1829 }
1830 MDBX_CXX20_CONSTEXPR bin(allocator_pointer ptr,
1831 size_t capacity_bytes) noexcept {
1832 MDBX_CONSTEXPR_ASSERT(!is_suitable_for_inplace(capacity_bytes));
1833 make_allocated<true>(ptr, capacity_bytes);
1834 }
1836 if (is_allocated())
1837 /* properly destroy allocator::pointer */
1838 allocated_.~allocated();
1839 }
1840 MDBX_CXX20_CONSTEXPR bin(bin &&ditto) noexcept {
1841 if (ditto.is_inplace()) {
1842 // micro-optimization: don't use make_inplace<> here
1843 // since memcpy() will copy the flag.
1844 memcpy(inplace_, ditto.inplace_, sizeof(inplace_));
1845 MDBX_CONSTEXPR_ASSERT(is_inplace());
1846 } else {
1847 new (&allocated_) allocated(::std::move(ditto.allocated_));
1848 ditto.make_inplace<true>();
1849 MDBX_CONSTEXPR_ASSERT(is_allocated());
1850 }
1851 }
1852
1853 MDBX_CXX17_CONSTEXPR bin &operator=(const bin &ditto) noexcept {
1854 if (ditto.is_inplace()) {
1855 // micro-optimization: don't use make_inplace<> here
1856 // since memcpy() will copy the flag.
1857 if (is_allocated())
1858 /* properly destroy allocator::pointer */
1859 allocated_.~allocated();
1860 memcpy(inplace_, ditto.inplace_, sizeof(inplace_));
1861 MDBX_CONSTEXPR_ASSERT(is_inplace());
1862 } else if (is_inplace())
1863 make_allocated<true>(ditto.allocated_.ptr_,
1864 ditto.allocated_.capacity_bytes_);
1865 else
1866 make_allocated<false>(ditto.allocated_.ptr_,
1867 ditto.allocated_.capacity_bytes_);
1868 return *this;
1869 }
1870
1872 operator=(const_cast<const bin &>(ditto));
1873 if (ditto.is_allocated())
1874 ditto.make_inplace<true>();
1875 return *this;
1876 }
1877
1878 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current,
1879 const size_t wanna) {
1880 if (MDBX_UNLIKELY(wanna > max_capacity))
1881 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1882
1883 const size_t advised = reservation_policy::advise(current, wanna);
1884 assert(advised >= wanna);
1885 return ::std::min(size_t(max_capacity),
1886 ::std::max(sizeof(bin) - 1, advised));
1887 }
1888
1889 constexpr const byte *address() const noexcept {
1890 return is_inplace()
1891 ? inplace_
1892 : static_cast<const byte *>(to_address(allocated_.ptr_));
1893 }
1895 return is_inplace() ? inplace_
1896 : static_cast<byte *>(to_address(allocated_.ptr_));
1897 }
1898 constexpr size_t capacity() const noexcept {
1899 return is_inplace() ? sizeof(bin) - 1 : allocated_.capacity_bytes_;
1900 }
1901 } bin_;
1902
1903 MDBX_CXX20_CONSTEXPR void *init(size_t capacity) {
1904 capacity = bin::advise_capacity(0, capacity);
1905 if (bin_.is_suitable_for_inplace(capacity))
1906 new (&bin_) bin();
1907 else {
1908 const auto pair = allocate_storage(capacity);
1909 assert(pair.second >= capacity);
1910 new (&bin_) bin(pair.first, pair.second);
1911 }
1912 return bin_.address();
1913 }
1914
1915 MDBX_CXX20_CONSTEXPR void release() noexcept {
1916 if (bin_.is_allocated()) {
1917 deallocate_storage(bin_.allocated_.ptr_,
1918 bin_.allocated_.capacity_bytes_);
1919 bin_.template make_inplace<true>();
1920 }
1921 }
1922
1923 template <bool external_content>
1925 reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1926 const void *const content, const size_t length) {
1927 assert(wanna_capacity >= wanna_headroom + length);
1928 const size_t old_capacity = bin_.capacity();
1929 const size_t new_capacity =
1930 bin::advise_capacity(old_capacity, wanna_capacity);
1931 if (MDBX_LIKELY(new_capacity == old_capacity))
1933 assert(bin_.is_inplace() ==
1934 bin::is_suitable_for_inplace(new_capacity));
1935 byte *const new_place = bin_.address() + wanna_headroom;
1936 if (MDBX_LIKELY(length))
1938 if (external_content)
1939 memcpy(new_place, content, length);
1940 else {
1941 const size_t old_headroom =
1942 bin_.address() - static_cast<const byte *>(content);
1943 assert(old_capacity >= old_headroom + length);
1944 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1945 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content,
1946 length);
1947 }
1948 }
1949 return new_place;
1950 }
1951
1952 if (bin::is_suitable_for_inplace(new_capacity)) {
1953 assert(bin_.is_allocated());
1954 const auto old_allocated = ::std::move(bin_.allocated_.ptr_);
1955 byte *const new_place =
1956 bin_.template make_inplace<true>() + wanna_headroom;
1957 if (MDBX_LIKELY(length))
1958 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1959 deallocate_storage(old_allocated, old_capacity);
1960 return new_place;
1961 }
1962
1963 if (!bin_.is_allocated()) {
1964 const auto pair = allocate_storage(new_capacity);
1965 assert(pair.second >= new_capacity);
1966 byte *const new_place =
1967 static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1968 if (MDBX_LIKELY(length))
1969 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1970 bin_.template make_allocated<true>(pair.first, pair.second);
1971 return new_place;
1972 }
1973
1974 const auto old_allocated = ::std::move(bin_.allocated_.ptr_);
1975 if (external_content)
1976 deallocate_storage(old_allocated, old_capacity);
1977 const auto pair = allocate_storage(new_capacity);
1978 assert(pair.second >= new_capacity);
1979 byte *const new_place =
1980 bin_.template make_allocated<false>(pair.first, pair.second) +
1981 wanna_headroom;
1982 if (MDBX_LIKELY(length))
1983 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1984 if (!external_content)
1985 deallocate_storage(old_allocated, old_capacity);
1986 return new_place;
1987 }
1988
1989 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1990 assert(capacity() >= offset);
1991 return bin_.address() + offset;
1992 }
1993 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1994 assert(capacity() >= offset);
1995 return bin_.address() + offset;
1996 }
1997 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr,
1998 size_t length) {
1999 assert(capacity() >= offset + length);
2000 return static_cast<byte *>(memcpy(get(offset), ptr, length));
2001 }
2002
2003 //--------------------------------------------------------------------------
2004
2006 silo() noexcept : allocator_type() { init(0); }
2008 silo(const allocator_type &alloc) noexcept : allocator_type(alloc) {
2009 init(0);
2010 }
2011 MDBX_CXX20_CONSTEXPR silo(size_t capacity) { init(capacity); }
2012 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc)
2013 : silo(alloc) {
2014 init(capacity);
2015 }
2016
2017 MDBX_CXX20_CONSTEXPR silo(silo &&ditto) noexcept(
2018 ::std::is_nothrow_move_constructible<allocator_type>::value)
2019 : allocator_type(::std::move(ditto.get_allocator())),
2020 bin_(::std::move(ditto.bin_)) {}
2021
2022 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr,
2023 size_t length)
2024 : silo(capacity) {
2025 assert(capacity >= headroom + length);
2026 if (length)
2027 put(headroom, ptr, length);
2028 }
2029
2030 // select_on_container_copy_construction()
2031 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr,
2032 size_t length, const allocator_type &alloc)
2033 : silo(capacity, alloc) {
2034 assert(capacity >= headroom + length);
2035 if (length)
2036 put(headroom, ptr, length);
2037 }
2038
2039 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length)
2040 : silo(length, 0, ptr, length) {}
2041 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length,
2042 const allocator_type &alloc)
2043 : silo(length, 0, ptr, length, alloc) {}
2044
2045 ~silo() { release(); }
2046
2047 //--------------------------------------------------------------------------
2048
2049 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr,
2050 size_t length, size_t tailroom) {
2051 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
2052 }
2053 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) {
2054 return assign(0, ptr, length, 0);
2055 }
2056
2057 MDBX_CXX20_CONSTEXPR silo &assign(const silo &ditto, size_t headroom,
2058 slice &content) {
2059 assert(ditto.get() + headroom == content.byte_ptr());
2060 if MDBX_IF_CONSTEXPR (!allocation_aware_details::
2061 allocator_is_always_equal<allocator_type>()) {
2062 if (MDBX_UNLIKELY(get_allocator() != ditto.get_allocator()))
2063 MDBX_CXX20_UNLIKELY {
2064 release();
2065 allocation_aware_details::copy_assign_alloc<
2066 silo, allocator_type>::propagate(this, ditto);
2067 }
2068 }
2069 content.iov_base = reshape<true>(ditto.capacity(), headroom,
2070 content.data(), content.length());
2071 return *this;
2072 }
2073
2075 assign(silo &&ditto, size_t headroom, slice &content) noexcept(
2076 allocation_aware_details::move_assign_alloc<
2077 silo, allocator_type>::is_nothrow()) {
2078 assert(ditto.get() + headroom == content.byte_ptr());
2079 if (allocation_aware_details::move_assign_alloc<
2080 silo, allocator_type>::is_moveable(this, ditto)) {
2081 release();
2082 allocation_aware_details::move_assign_alloc<
2083 silo, allocator_type>::propagate(this, ditto);
2084 /* no reallocation nor copying required */
2085 bin_ = ::std::move(ditto.bin_);
2086 assert(get() + headroom == content.byte_ptr());
2087 } else {
2088 /* copy content since allocators are different */
2089 content.iov_base = reshape<true>(ditto.capacity(), headroom,
2090 content.data(), content.length());
2091 ditto.release();
2092 }
2093 return *this;
2094 }
2095
2096 MDBX_CXX20_CONSTEXPR void *clear() {
2097 return reshape<true>(0, 0, nullptr, 0);
2098 }
2099 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity,
2100 size_t headroom) {
2101 return reshape<false>(whole_capacity, headroom, nullptr, 0);
2102 }
2103 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom,
2104 slice &content) {
2105 content.iov_base =
2106 reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
2107 }
2108 MDBX_CXX20_CONSTEXPR void swap(silo &ditto) noexcept(
2109 allocation_aware_details::swap_alloc<silo,
2110 allocator_type>::is_nothrow()) {
2111 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(
2112 this, ditto);
2113 ::std::swap(bin_, ditto.bin_);
2114 }
2115
2116 /* MDBX_CXX20_CONSTEXPR void shrink_to_fit() { TODO } */
2117
2119 capacity() const noexcept {
2120 return bin_.capacity();
2121 }
2123 data(size_t offset = 0) const noexcept {
2124 return get(offset);
2125 }
2127 data(size_t offset = 0) noexcept {
2128 return get(offset);
2129 }
2130 };
2131
2132 silo silo_;
2133 ::mdbx::slice slice_;
2134
2135 void insulate() {
2136 assert(is_reference());
2137 silo_.assign(slice_.char_ptr(), slice_.length());
2138 slice_.iov_base = silo_.data();
2139 }
2140
2142 silo_begin() const noexcept {
2143 return static_cast<const byte *>(silo_.data());
2144 }
2145
2147 silo_end() const noexcept {
2148 return silo_begin() + silo_.capacity();
2149 }
2150
2151 struct data_preserver : public exception_thunk {
2152 buffer data;
2153 data_preserver(allocator_type &allocator) : data(allocator) {}
2154 static int callback(void *context, MDBX_val *target, const void *src,
2155 size_t bytes) noexcept {
2156 auto self = static_cast<data_preserver *>(context);
2157 assert(self->is_clean());
2158 assert(&self->data.slice_ == target);
2159 (void)target;
2160 try {
2161 self->data.assign(src, bytes, false);
2162 return MDBX_RESULT_FALSE;
2163 } catch (... /* capture any exception to rethrow it over C code */) {
2164 self->capture();
2165 return MDBX_RESULT_TRUE;
2166 }
2167 }
2168 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept {
2169 return callback;
2170 }
2171 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept {
2172 return data;
2173 }
2174 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
2175 };
2176
2177public:
2181
2186
2189 return silo_.get_allocator();
2190 }
2191
2195 is_freestanding() const noexcept {
2196 static_assert(size_t(-long(max_length)) > max_length, "WTF?");
2197 return size_t(byte_ptr() - silo_begin()) < silo_.capacity();
2198 }
2199
2203 is_reference() const noexcept {
2204 return !is_freestanding();
2205 }
2206
2210 capacity() const noexcept {
2211 return is_freestanding() ? silo_.capacity() : 0;
2212 }
2213
2217 headroom() const noexcept {
2218 return is_freestanding() ? slice_.byte_ptr() - silo_begin() : 0;
2219 }
2220
2224 tailroom() const noexcept {
2225 return is_freestanding() ? capacity() - headroom() - slice_.length() : 0;
2226 }
2227
2229 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept {
2230 return slice_.byte_ptr();
2231 }
2232
2234 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept {
2235 return slice_.end_byte_ptr();
2236 }
2237
2242 MDBX_CONSTEXPR_ASSERT(is_freestanding());
2243 return const_cast<byte *>(slice_.byte_ptr());
2244 }
2245
2250 MDBX_CONSTEXPR_ASSERT(is_freestanding());
2251 return const_cast<byte *>(slice_.end_byte_ptr());
2252 }
2253
2255 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept {
2256 return slice_.char_ptr();
2257 }
2258
2260 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept {
2261 return slice_.end_char_ptr();
2262 }
2263
2268 MDBX_CONSTEXPR_ASSERT(is_freestanding());
2269 return const_cast<char *>(slice_.char_ptr());
2270 }
2271
2276 MDBX_CONSTEXPR_ASSERT(is_freestanding());
2277 return const_cast<char *>(slice_.end_char_ptr());
2278 }
2279
2281 MDBX_CXX11_CONSTEXPR const void *data() const noexcept {
2282 return slice_.data();
2283 }
2284
2286 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return slice_.end(); }
2287
2291 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2292 MDBX_CONSTEXPR_ASSERT(is_freestanding());
2293 return const_cast<void *>(slice_.data());
2294 }
2295
2299 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2300 MDBX_CONSTEXPR_ASSERT(is_freestanding());
2301 return const_cast<void *>(slice_.end());
2302 }
2303
2306 length() const noexcept {
2307 return MDBX_CONSTEXPR_ASSERT(is_reference() ||
2308 slice_.length() + headroom() <=
2309 silo_.capacity()),
2310 slice_.length();
2311 }
2312
2315 MDBX_CONSTEXPR_ASSERT(is_reference() ||
2316 bytes + headroom() <= silo_.capacity());
2317 slice_.set_length(bytes);
2318 return *this;
2319 }
2320
2323 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2324 return set_length(static_cast<const char *>(ptr) - char_ptr());
2325 }
2326
2331 if (is_reference())
2332 insulate();
2333 }
2334
2335 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2336 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &allocator) noexcept
2337 : silo_(allocator) {}
2338
2339 buffer(const struct slice &src, bool make_reference,
2340 const allocator_type &allocator = allocator_type())
2341 : silo_(allocator), slice_(src) {
2342 if (!make_reference)
2343 insulate();
2344 }
2345
2346 buffer(const buffer &src, bool make_reference,
2347 const allocator_type &allocator = allocator_type())
2348 : buffer(src.slice_, make_reference, allocator) {}
2349
2350 buffer(const void *ptr, size_t bytes, bool make_reference,
2351 const allocator_type &allocator = allocator_type())
2352 : buffer(::mdbx::slice(ptr, bytes), make_reference, allocator) {}
2353
2354 template <class CHAR, class T, class A>
2355 buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2356 template <class CHAR, class T, class A>
2357 buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2358
2359 buffer(const char *c_str, bool make_reference,
2360 const allocator_type &allocator = allocator_type())
2361 : buffer(::mdbx::slice(c_str), make_reference, allocator){}
2362
2363#if defined(DOXYGEN) || \
2364 (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2365 template <class CHAR, class T>
2366 buffer(const ::std::basic_string_view<CHAR, T> &view,
2367 bool make_reference,
2368 const allocator_type &allocator = allocator_type())
2369 : buffer(::mdbx::slice(view), make_reference, allocator) {
2370 }
2371#endif /* __cpp_lib_string_view >= 201606L */
2372
2374 buffer(const struct slice &src,
2375 const allocator_type &allocator = allocator_type())
2376 : silo_(src.data(), src.length(), allocator),
2377 slice_(silo_.data(), src.length()) {}
2378
2380 buffer(const buffer &src, const allocator_type &allocator = allocator_type())
2381 : buffer(src.slice_, allocator) {}
2382
2384 buffer(const void *ptr, size_t bytes,
2385 const allocator_type &allocator = allocator_type())
2386 : buffer(::mdbx::slice(ptr, bytes), allocator) {}
2387
2388 template <class CHAR, class T, class A>
2390 buffer(const ::std::basic_string<CHAR, T, A> &str,
2391 const allocator_type &allocator = allocator_type())
2392 : buffer(::mdbx::slice(str), allocator) {}
2393
2395 buffer(const char *c_str, const allocator_type &allocator = allocator_type())
2396 : buffer(::mdbx::slice(c_str), allocator){}
2397
2398#if defined(DOXYGEN) || \
2399 (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2400 template <class CHAR, class T>
2402 buffer(const ::std::basic_string_view<CHAR, T> &view,
2403 const allocator_type &allocator = allocator_type())
2404 : buffer(::mdbx::slice(view), allocator) {
2405 }
2406#endif /* __cpp_lib_string_view >= 201606L */
2407
2408 buffer(size_t head_room, size_t tail_room,
2409 const allocator_type &allocator = allocator_type())
2410 : silo_(allocator) {
2411 slice_.iov_base = silo_.init(check_length(head_room, tail_room));
2412 assert(slice_.iov_len == 0);
2413 }
2414
2415 buffer(size_t capacity, const allocator_type &allocator = allocator_type())
2416 : silo_(allocator) {
2417 slice_.iov_base = silo_.init(check_length(capacity));
2418 assert(slice_.iov_len == 0);
2419 }
2420
2421 buffer(size_t head_room, const struct slice &src, size_t tail_room,
2422 const allocator_type &allocator = allocator_type())
2423 : silo_(allocator) {
2424 slice_.iov_base =
2425 silo_.init(check_length(head_room, src.length(), tail_room));
2426 slice_.iov_len = src.length();
2427 memcpy(slice_.iov_base, src.data(), src.length());
2428 }
2429
2430 buffer(size_t head_room, const buffer &src, size_t tail_room,
2431 const allocator_type &allocator = allocator_type())
2432 : buffer(head_room, src.slice_, tail_room, allocator) {}
2433
2434 inline buffer(const ::mdbx::txn &txn, const struct slice &src,
2435 const allocator_type &allocator = allocator_type());
2436
2437 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2438 : silo_(::std::move(src.silo_)), slice_(::std::move(src.slice_)) {}
2439
2440 MDBX_CXX11_CONSTEXPR const struct slice &slice() const noexcept {
2441 return slice_;
2442 }
2443
2444 MDBX_CXX11_CONSTEXPR operator const struct slice &() const noexcept {
2445 return slice_;
2446 }
2447
2448#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
2449 template <typename POD>
2450 MDBX_CXX14_CONSTEXPR buffer(const ::std::span<POD> &span)
2451 : buffer(span.begin(), span.end()) {
2452 static_assert(::std::is_standard_layout<POD>::value &&
2453 !::std::is_pointer<POD>::value,
2454 "Must be a standard layout type!");
2455 }
2456
2457 template <typename POD>
2458 MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
2459 return slice_.template as_span<const POD>();
2460 }
2461 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
2462 return slice_.template as_span<POD>();
2463 }
2464
2465 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const {
2466 return as_span<const byte>();
2467 }
2468 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
2469 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const {
2470 return as_span<const char>();
2471 }
2472 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
2473#endif /* __cpp_lib_span >= 202002L */
2474
2475 template <typename POD>
2476 static buffer wrap(const POD &pod, bool make_reference = false,
2477 const allocator_type &allocator = allocator_type()) {
2478 return buffer(::mdbx::slice::wrap(pod), make_reference, allocator);
2479 }
2480
2481 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
2482 return slice_.as_pod<POD>();
2483 }
2484
2485#ifdef MDBX_U128_TYPE
2486 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const {
2487 return slice().as_uint128();
2488 }
2489#endif /* MDBX_U128_TYPE */
2491 return slice().as_uint64();
2492 }
2494 return slice().as_uint32();
2495 }
2497 return slice().as_uint16();
2498 }
2499 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return slice().as_uint8(); }
2500
2501#ifdef MDBX_I128_TYPE
2502 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const {
2503 return slice().as_int128();
2504 }
2505#endif /* MDBX_I128_TYPE */
2506 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return slice().as_int64(); }
2507 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return slice().as_int32(); }
2508 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return slice().as_int16(); }
2509 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return slice().as_int8(); }
2510
2511#ifdef MDBX_U128_TYPE
2512 MDBX_U128_TYPE as_uint128_adapt() const { return slice().as_uint128_adapt(); }
2513#endif /* MDBX_U128_TYPE */
2514 uint64_t as_uint64_adapt() const { return slice().as_uint64_adapt(); }
2515 uint32_t as_uint32_adapt() const { return slice().as_uint32_adapt(); }
2516 uint16_t as_uint16_adapt() const { return slice().as_uint16_adapt(); }
2517 uint8_t as_uint8_adapt() const { return slice().as_uint8_adapt(); }
2518
2519#ifdef MDBX_I128_TYPE
2520 MDBX_I128_TYPE as_int128_adapt() const { return slice().as_int128_adapt(); }
2521#endif /* MDBX_I128_TYPE */
2522 int64_t as_int64_adapt() const { return slice().as_int64_adapt(); }
2523 int32_t as_int32_adapt() const { return slice().as_int32_adapt(); }
2524 int16_t as_int16_adapt() const { return slice().as_int16_adapt(); }
2525 int8_t as_int8_adapt() const { return slice().as_int8_adapt(); }
2526
2528 static buffer hex(const ::mdbx::slice &source, bool uppercase = false,
2529 unsigned wrap_width = 0,
2530 const allocator_type &allocator = allocator_type()) {
2531 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(
2532 uppercase, wrap_width, allocator);
2533 }
2534
2537 static buffer base58(const ::mdbx::slice &source, unsigned wrap_width = 0,
2538 const allocator_type &allocator = allocator_type()) {
2539 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width,
2540 allocator);
2541 }
2544 static buffer base64(const ::mdbx::slice &source, unsigned wrap_width = 0,
2545 const allocator_type &allocator = allocator_type()) {
2546 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width,
2547 allocator);
2548 }
2549
2551 template <typename POD>
2552 static buffer hex(const POD &pod, bool uppercase = false,
2553 unsigned wrap_width = 0,
2554 const allocator_type &allocator = allocator_type()) {
2555 return hex(mdbx::slice::wrap(pod), uppercase, wrap_width, allocator);
2556 }
2557
2560 template <typename POD>
2561 static buffer base58(const POD &pod, unsigned wrap_width = 0,
2562 const allocator_type &allocator = allocator_type()) {
2563 return base58(mdbx::slice::wrap(pod), wrap_width, allocator);
2564 }
2565
2568 template <typename POD>
2569 static buffer base64(const POD &pod, unsigned wrap_width = 0,
2570 const allocator_type &allocator = allocator_type()) {
2571 return base64(mdbx::slice::wrap(pod), wrap_width, allocator);
2572 }
2573
2575 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2576 const allocator_type &allocator = allocator_type()) const {
2577 return slice().template encode_hex<ALLOCATOR, CAPACITY_POLICY>(
2578 uppercase, wrap_width, allocator);
2579 }
2580
2583 buffer
2584 encode_base58(unsigned wrap_width = 0,
2585 const allocator_type &allocator = allocator_type()) const {
2586 return slice().template encode_base58<ALLOCATOR, CAPACITY_POLICY>(
2587 wrap_width, allocator);
2588 }
2591 buffer
2592 encode_base64(unsigned wrap_width = 0,
2593 const allocator_type &allocator = allocator_type()) const {
2594 return slice().template encode_base64<ALLOCATOR, CAPACITY_POLICY>(
2595 wrap_width, allocator);
2596 }
2597
2599 static buffer hex_decode(const ::mdbx::slice &source,
2600 bool ignore_spaces = false,
2601 const allocator_type &allocator = allocator_type()) {
2602 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces,
2603 allocator);
2604 }
2605
2608 static buffer
2609 base58_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2610 const allocator_type &allocator = allocator_type()) {
2611 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(
2612 ignore_spaces, allocator);
2613 }
2614
2617 static buffer
2618 base64_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2619 const allocator_type &allocator = allocator_type()) {
2620 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(
2621 ignore_spaces, allocator);
2622 }
2623
2626 buffer hex_decode(bool ignore_spaces = false,
2627 const allocator_type &allocator = allocator_type()) const {
2628 return hex_decode(slice(), ignore_spaces, allocator);
2629 }
2630
2633 buffer
2634 base58_decode(bool ignore_spaces = false,
2635 const allocator_type &allocator = allocator_type()) const {
2636 return base58_decode(slice(), ignore_spaces, allocator);
2637 }
2638
2641 buffer
2642 base64_decode(bool ignore_spaces = false,
2643 const allocator_type &allocator = allocator_type()) const {
2644 return base64_decode(slice(), ignore_spaces, allocator);
2645 }
2646
2648 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2649 wanna_headroom = ::std::min(::std::max(headroom(), wanna_headroom),
2650 wanna_headroom + pettiness_threshold);
2651 wanna_tailroom = ::std::min(::std::max(tailroom(), wanna_tailroom),
2652 wanna_tailroom + pettiness_threshold);
2653 const size_t wanna_capacity =
2654 check_length(wanna_headroom, slice_.length(), wanna_tailroom);
2655 silo_.resize(wanna_capacity, wanna_headroom, slice_);
2656 assert(headroom() >= wanna_headroom &&
2657 headroom() <= wanna_headroom + pettiness_threshold);
2658 assert(tailroom() >= wanna_tailroom &&
2659 tailroom() <= wanna_tailroom + pettiness_threshold);
2660 }
2661
2663 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2664
2666 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2667
2668 buffer &assign_reference(const void *ptr, size_t bytes) {
2669 silo_.clear();
2670 slice_.assign(ptr, bytes);
2671 return *this;
2672 }
2673
2674 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2675 silo_.assign(static_cast<const typename silo::value_type *>(ptr),
2676 check_length(bytes));
2677 slice_.assign(silo_.data(), bytes);
2678 return *this;
2679 }
2680
2682 swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2683 silo_.swap(other.silo_);
2684 slice_.swap(other.slice_);
2685 }
2686
2687 static buffer clone(const buffer &src,
2688 const allocator_type &allocator = allocator_type()) {
2689 return buffer(src.headroom(), src.slice_, src.tailroom(), allocator);
2690 }
2691
2692 buffer &assign(const buffer &src, bool make_reference = false) {
2693 return assign(src.slice_, make_reference);
2694 }
2695
2696 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2697 return make_reference ? assign_reference(ptr, bytes)
2698 : assign_freestanding(ptr, bytes);
2699 }
2700
2701 buffer &assign(const struct slice &src, bool make_reference = false) {
2702 return assign(src.data(), src.length(), make_reference);
2703 }
2704
2705 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2706 return assign(src.iov_base, src.iov_len, make_reference);
2707 }
2708
2709 buffer &assign(struct slice &&src, bool make_reference = false) {
2710 assign(src.data(), src.length(), make_reference);
2711 src.invalidate();
2712 return *this;
2713 }
2714
2715 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2716 assign(src.iov_base, src.iov_len, make_reference);
2717 src.iov_base = nullptr;
2718 return *this;
2719 }
2720
2721 buffer &assign(const void *begin, const void *end,
2722 bool make_reference = false) {
2723 return assign(begin,
2724 static_cast<const byte *>(end) -
2725 static_cast<const byte *>(begin),
2726 make_reference);
2727 }
2728
2729 template <class CHAR, class T, class A>
2730 buffer &assign(const ::std::basic_string<CHAR, T, A> &str,
2731 bool make_reference = false) {
2732 return assign(str.data(), str.length(), make_reference);
2733 }
2734
2735 buffer &assign(const char *c_str, bool make_reference = false) {
2736 return assign(c_str, ::mdbx::strlen(c_str), make_reference);
2737 }
2738
2739#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2740 template <class CHAR, class T>
2741 buffer &assign(const ::std::basic_string_view<CHAR, T> &view,
2742 bool make_reference = false) {
2743 return assign(view.data(), view.length(), make_reference);
2744 }
2745
2746 template <class CHAR, class T>
2747 buffer &assign(::std::basic_string_view<CHAR, T> &&view,
2748 bool make_reference = false) {
2749 assign(view.data(), view.length(), make_reference);
2750 view = {};
2751 return *this;
2752 }
2753#endif /* __cpp_lib_string_view >= 201606L */
2754
2755 buffer &operator=(const buffer &src) { return assign(src); }
2756
2757 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) {
2758 return assign(::std::move(src));
2759 }
2760
2761 buffer &operator=(const struct slice &src) { return assign(src); }
2762
2763 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2764
2765#if defined(DOXYGEN) || \
2766 (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2767 template <class CHAR, class T>
2768 buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2769 return assign(view);
2770 }
2771
2773 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
2774 ::std::basic_string_view<CHAR, T> string_view() const noexcept {
2775 return slice_.string_view<CHAR, T>();
2776 }
2777
2779 template <class CHAR, class T>
2780 operator ::std::basic_string_view<CHAR, T>() const noexcept {
2781 return string_view<CHAR, T>();
2782 }
2783#endif /* __cpp_lib_string_view >= 201606L */
2784
2787 return length() == 0;
2788 }
2789
2791 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept {
2792 return data() == nullptr;
2793 }
2794
2797 return length();
2798 }
2799
2805 hash_value() const noexcept {
2806 return slice_.hash_value();
2807 }
2808
2809 template <class CHAR = char, class T = ::std::char_traits<CHAR>,
2810 class A = legacy_allocator>
2811 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, A>
2812 as_string(const A &allocator = A()) const {
2813 return slice_.as_string<CHAR, T, A>(allocator);
2814 }
2815
2816 template <class CHAR, class T, class A>
2818 operator ::std::basic_string<CHAR, T, A>() const {
2819 return as_string<CHAR, T, A>();
2820 }
2821
2824 starts_with(const struct slice &prefix) const noexcept {
2825 return slice_.starts_with(prefix);
2826 }
2827
2830 ends_with(const struct slice &suffix) const noexcept {
2831 return slice_.ends_with(suffix);
2832 }
2833
2835 void clear() noexcept { slice_.assign(silo_.clear(), size_t(0)); }
2836
2838 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2839 slice_.assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2840 }
2841
2843 void shrink_to_fit() { reserve(0, 0); }
2844
2847 void remove_prefix(size_t n) noexcept { slice_.remove_prefix(n); }
2848
2851 void remove_suffix(size_t n) noexcept { slice_.remove_suffix(n); }
2852
2855 void safe_remove_prefix(size_t n) { slice_.safe_remove_prefix(n); }
2856
2859 void safe_remove_suffix(size_t n) { slice_.safe_remove_suffix(n); }
2860
2863 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept {
2864 MDBX_CONSTEXPR_ASSERT(n < size());
2865 return slice_[n];
2866 }
2867
2870 MDBX_CXX11_CONSTEXPR byte &operator[](size_t n) noexcept {
2871 MDBX_CONSTEXPR_ASSERT(n < size());
2872 return byte_ptr()[n];
2873 }
2874
2877 MDBX_CXX14_CONSTEXPR byte at(size_t n) const { return slice_.at(n); }
2878
2881 MDBX_CXX14_CONSTEXPR byte &at(size_t n) {
2882 if (MDBX_UNLIKELY(n >= size()))
2883 MDBX_CXX20_UNLIKELY throw_out_range();
2884 return byte_ptr()[n];
2885 }
2886
2889 MDBX_CXX14_CONSTEXPR struct slice head(size_t n) const noexcept {
2890 return slice_.head(n);
2891 }
2892
2895 MDBX_CXX14_CONSTEXPR struct slice tail(size_t n) const noexcept {
2896 return slice_.tail(n);
2897 }
2898
2901 MDBX_CXX14_CONSTEXPR struct slice middle(size_t from,
2902 size_t n) const noexcept {
2903 return slice_.middle(from, n);
2904 }
2905
2908 MDBX_CXX14_CONSTEXPR struct slice safe_head(size_t n) const {
2909 return slice_.safe_head(n);
2910 }
2911
2914 MDBX_CXX14_CONSTEXPR struct slice safe_tail(size_t n) const {
2915 return slice_.safe_tail(n);
2916 }
2917
2920 MDBX_CXX14_CONSTEXPR struct slice safe_middle(size_t from, size_t n) const {
2921 return slice_.safe_middle(from, n);
2922 }
2923
2924 buffer &append(const void *src, size_t bytes) {
2925 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2926 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2927 memcpy(end_byte_ptr(), src, bytes);
2928 slice_.iov_len += bytes;
2929 return *this;
2930 }
2931
2932 buffer &append(const struct slice &chunk) {
2933 return append(chunk.data(), chunk.size());
2934 }
2935
2936 buffer &add_header(const void *src, size_t bytes) {
2937 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2938 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2939 slice_.iov_base =
2940 memcpy(static_cast<char *>(slice_.iov_base) - bytes, src, bytes);
2941 slice_.iov_len += bytes;
2942 return *this;
2943 }
2944
2945 buffer &add_header(const struct slice &chunk) {
2946 return add_header(chunk.data(), chunk.size());
2947 }
2948
2949 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2950 buffer &append_producer(PRODUCER &producer) {
2951 const size_t wanna_bytes = producer.envisage_result_length();
2952 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2953 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2954 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2955 }
2956
2957 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2958 buffer &append_producer(const PRODUCER &producer) {
2959 const size_t wanna_bytes = producer.envisage_result_length();
2960 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2961 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2962 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2963 }
2964
2965 buffer &append_hex(const struct slice &data, bool uppercase = false,
2966 unsigned wrap_width = 0) {
2967 return append_producer(to_hex(data, uppercase, wrap_width));
2968 }
2969
2970 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2971 return append_producer(to_base58(data, wrap_width));
2972 }
2973
2974 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2975 return append_producer(to_base64(data, wrap_width));
2976 }
2977
2978 buffer &append_decoded_hex(const struct slice &data,
2979 bool ignore_spaces = false) {
2980 return append_producer(from_hex(data, ignore_spaces));
2981 }
2982
2984 bool ignore_spaces = false) {
2985 return append_producer(from_base58(data, ignore_spaces));
2986 }
2987
2989 bool ignore_spaces = false) {
2990 return append_producer(from_base64(data, ignore_spaces));
2991 }
2992
2993 buffer &append_u8(uint_fast8_t u8) {
2994 if (MDBX_UNLIKELY(tailroom() < 1))
2995 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2996 *slice_.end_byte_ptr() = uint8_t(u8);
2997 slice_.iov_len += 1;
2998 return *this;
2999 }
3000
3001 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
3002
3003 buffer &append_u16(uint_fast16_t u16) {
3004 if (MDBX_UNLIKELY(tailroom() < 2))
3005 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
3006 const auto ptr = slice_.end_byte_ptr();
3007 ptr[0] = uint8_t(u16);
3008 ptr[1] = uint8_t(u16 >> 8);
3009 slice_.iov_len += 2;
3010 return *this;
3011 }
3012
3013 buffer &append_u24(uint_fast32_t u24) {
3014 if (MDBX_UNLIKELY(tailroom() < 3))
3015 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
3016 const auto ptr = slice_.end_byte_ptr();
3017 ptr[0] = uint8_t(u24);
3018 ptr[1] = uint8_t(u24 >> 8);
3019 ptr[2] = uint8_t(u24 >> 16);
3020 slice_.iov_len += 3;
3021 return *this;
3022 }
3023
3024 buffer &append_u32(uint_fast32_t u32) {
3025 if (MDBX_UNLIKELY(tailroom() < 4))
3026 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
3027 const auto ptr = slice_.end_byte_ptr();
3028 ptr[0] = uint8_t(u32);
3029 ptr[1] = uint8_t(u32 >> 8);
3030 ptr[2] = uint8_t(u32 >> 16);
3031 ptr[3] = uint8_t(u32 >> 24);
3032 slice_.iov_len += 4;
3033 return *this;
3034 }
3035
3036 buffer &append_u48(uint_fast64_t u48) {
3037 if (MDBX_UNLIKELY(tailroom() < 6))
3038 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
3039 const auto ptr = slice_.end_byte_ptr();
3040 ptr[0] = uint8_t(u48);
3041 ptr[1] = uint8_t(u48 >> 8);
3042 ptr[2] = uint8_t(u48 >> 16);
3043 ptr[3] = uint8_t(u48 >> 24);
3044 ptr[4] = uint8_t(u48 >> 32);
3045 ptr[5] = uint8_t(u48 >> 40);
3046 slice_.iov_len += 6;
3047 return *this;
3048 }
3049
3050 buffer &append_u64(uint_fast64_t u64) {
3051 if (MDBX_UNLIKELY(tailroom() < 8))
3052 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
3053 const auto ptr = slice_.end_byte_ptr();
3054 ptr[0] = uint8_t(u64);
3055 ptr[1] = uint8_t(u64 >> 8);
3056 ptr[2] = uint8_t(u64 >> 16);
3057 ptr[3] = uint8_t(u64 >> 24);
3058 ptr[4] = uint8_t(u64 >> 32);
3059 ptr[5] = uint8_t(u64 >> 40);
3060 ptr[6] = uint8_t(u64 >> 48);
3061 ptr[7] = uint8_t(u64 >> 56);
3062 slice_.iov_len += 8;
3063 return *this;
3064 }
3065
3066 //----------------------------------------------------------------------------
3067
3068 template <size_t SIZE>
3069 static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
3070 return buffer(::mdbx::slice(text), make_reference);
3071 }
3072
3073#if defined(DOXYGEN) || \
3074 (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3075 template <class CHAR, class T>
3076 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src,
3077 bool make_reference = false) {
3078 return buffer(src, make_reference);
3079 }
3080#endif /* __cpp_lib_string_view >= 201606L */
3081
3082 static buffer key_from(const char *src, bool make_reference = false) {
3083 return buffer(src, make_reference);
3084 }
3085
3086 template <class CHAR, class T, class A>
3087 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src,
3088 bool make_reference = false) {
3089 return buffer(src, make_reference);
3090 }
3091
3092 static buffer key_from(silo &&src) noexcept {
3093 return buffer(::std::move(src));
3094 }
3095
3096 static buffer key_from_double(const double ieee754_64bit) {
3097 return wrap(::mdbx_key_from_double(ieee754_64bit));
3098 }
3099
3100 static buffer key_from(const double ieee754_64bit) {
3101 return key_from_double(ieee754_64bit);
3102 }
3103
3104 static buffer key_from(const double *ieee754_64bit) {
3105 return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit));
3106 }
3107
3108 static buffer key_from_u64(const uint64_t unsigned_int64) {
3109 return wrap(unsigned_int64);
3110 }
3111
3112 static buffer key_from(const uint64_t unsigned_int64) {
3113 return key_from_u64(unsigned_int64);
3114 }
3115
3116 static buffer key_from_i64(const int64_t signed_int64) {
3117 return wrap(::mdbx_key_from_int64(signed_int64));
3118 }
3119
3120 static buffer key_from(const int64_t signed_int64) {
3121 return key_from_i64(signed_int64);
3122 }
3123
3124 static buffer key_from_jsonInteger(const int64_t json_integer) {
3125 return wrap(::mdbx_key_from_jsonInteger(json_integer));
3126 }
3127
3128 static buffer key_from_float(const float ieee754_32bit) {
3129 return wrap(::mdbx_key_from_float(ieee754_32bit));
3130 }
3131
3132 static buffer key_from(const float ieee754_32bit) {
3133 return key_from_float(ieee754_32bit);
3134 }
3135
3136 static buffer key_from(const float *ieee754_32bit) {
3137 return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit));
3138 }
3139
3140 static buffer key_from_u32(const uint32_t unsigned_int32) {
3141 return wrap(unsigned_int32);
3142 }
3143
3144 static buffer key_from(const uint32_t unsigned_int32) {
3145 return key_from_u32(unsigned_int32);
3146 }
3147
3148 static buffer key_from_i32(const int32_t signed_int32) {
3149 return wrap(::mdbx_key_from_int32(signed_int32));
3150 }
3151
3152 static buffer key_from(const int32_t signed_int32) {
3153 return key_from_i32(signed_int32);
3154 }
3155};
3156
3157template <class ALLOCATOR, class CAPACITY_POLICY,
3158 MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
3159inline buffer<ALLOCATOR, CAPACITY_POLICY>
3160make_buffer(PRODUCER &producer, const ALLOCATOR &allocator) {
3161 if (MDBX_LIKELY(!producer.is_empty()))
3164 producer.envisage_result_length(), allocator);
3165 result.set_end(
3166 producer.write_bytes(result.end_char_ptr(), result.tailroom()));
3167 return result;
3168 }
3169 return buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
3170}
3171
3172template <class ALLOCATOR, class CAPACITY_POLICY,
3173 MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
3174inline buffer<ALLOCATOR, CAPACITY_POLICY>
3175make_buffer(const PRODUCER &producer, const ALLOCATOR &allocator) {
3176 if (MDBX_LIKELY(!producer.is_empty()))
3179 producer.envisage_result_length(), allocator);
3180 result.set_end(
3181 producer.write_bytes(result.end_char_ptr(), result.tailroom()));
3182 return result;
3183 }
3184 return buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
3185}
3186
3187template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
3188inline string<ALLOCATOR> make_string(PRODUCER &producer,
3189 const ALLOCATOR &allocator) {
3190 string<ALLOCATOR> result(allocator);
3191 if (MDBX_LIKELY(!producer.is_empty()))
3193 result.resize(producer.envisage_result_length());
3194 result.resize(producer.write_bytes(const_cast<char *>(result.data()),
3195 result.capacity()) -
3196 result.data());
3197 }
3198 return result;
3199}
3200
3201template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
3202inline string<ALLOCATOR> make_string(const PRODUCER &producer,
3203 const ALLOCATOR &allocator) {
3204 string<ALLOCATOR> result(allocator);
3205 if (MDBX_LIKELY(!producer.is_empty()))
3207 result.resize(producer.envisage_result_length());
3208 result.resize(producer.write_bytes(const_cast<char *>(result.data()),
3209 result.capacity()) -
3210 result.data());
3211 }
3212 return result;
3213}
3214
3219 bool done;
3220 value_result(const slice &value, bool done) noexcept
3221 : value(value), done(done) {}
3222 value_result(const value_result &) noexcept = default;
3223 value_result &operator=(const value_result &) noexcept = default;
3224 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
3225 assert(!done || bool(value));
3226 return done;
3227 }
3228};
3229
3232struct pair {
3233 using stl_pair = std::pair<slice, slice>;
3234 slice key, value;
3235 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept
3236 : key(key), value(value) {}
3237 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept
3238 : key(couple.first), value(couple.second) {}
3239 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept {
3240 return stl_pair(key, value);
3241 }
3242 pair(const pair &) noexcept = default;
3243 pair &operator=(const pair &) noexcept = default;
3244 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
3245 assert(bool(key) == bool(value));
3246 return key;
3247 }
3249 return pair(slice::invalid(), slice::invalid());
3250 }
3251
3254 compare_fast(const pair &a, const pair &b) noexcept;
3255
3258 compare_lexicographically(const pair &a, const pair &b) noexcept;
3259 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a,
3260 const pair &b) noexcept;
3261 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a,
3262 const pair &b) noexcept;
3263 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a,
3264 const pair &b) noexcept;
3265 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a,
3266 const pair &b) noexcept;
3267 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a,
3268 const pair &b) noexcept;
3269 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a,
3270 const pair &b) noexcept;
3271};
3272
3275struct pair_result : public pair {
3276 bool done;
3278 : pair(pair::invalid()), done(false) {}
3280 bool done) noexcept
3281 : pair(key, value), done(done) {}
3282 pair_result(const pair_result &) noexcept = default;
3283 pair_result &operator=(const pair_result &) noexcept = default;
3284 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
3285 assert(!done || (bool(key) && bool(value)));
3286 return done;
3287 }
3288};
3289
3290template <typename ALLOCATOR, typename CAPACITY_POLICY>
3295 using reservation_policy = CAPACITY_POLICY;
3296 using stl_pair = ::std::pair<buffer_type, buffer_type>;
3298
3301 buffer_pair_spec(const allocator_type &allocator) noexcept
3302 : key(allocator), value(allocator) {}
3303
3304 buffer_pair_spec(const buffer_type &key, const buffer_type &value,
3305 const allocator_type &allocator = allocator_type())
3306 : key(key, allocator), value(value, allocator) {}
3307 buffer_pair_spec(const buffer_type &key, const buffer_type &value,
3308 bool make_reference,
3309 const allocator_type &allocator = allocator_type())
3310 : key(key, make_reference, allocator),
3311 value(value, make_reference, allocator) {}
3312
3314 const allocator_type &allocator = allocator_type())
3315 : buffer_pair_spec(pair.first, pair.second, allocator) {}
3316 buffer_pair_spec(const stl_pair &pair, bool make_reference,
3317 const allocator_type &allocator = allocator_type())
3318 : buffer_pair_spec(pair.first, pair.second, make_reference, allocator) {}
3319
3320 buffer_pair_spec(const slice &key, const slice &value,
3321 const allocator_type &allocator = allocator_type())
3322 : key(key, allocator), value(value, allocator) {}
3323 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
3324 const allocator_type &allocator = allocator_type())
3325 : key(key, make_reference, allocator),
3326 value(value, make_reference, allocator) {}
3327
3329 const allocator_type &allocator = allocator_type())
3330 : buffer_pair_spec(pair.key, pair.value, allocator) {}
3331 buffer_pair_spec(const pair &pair, bool make_reference,
3332 const allocator_type &allocator = allocator_type())
3333 : buffer_pair_spec(pair.key, pair.value, make_reference, allocator) {}
3334
3335 buffer_pair_spec(const txn &txn, const slice &key, const slice &value,
3336 const allocator_type &allocator = allocator_type())
3337 : key(txn, key, allocator), value(txn, value, allocator) {}
3339 const allocator_type &allocator = allocator_type())
3340 : buffer_pair_spec(txn, pair.key, pair.value, allocator) {}
3341
3342 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(
3343 buffer_type::move_assign_alloc::is_nothrow())
3344 : key(::std::move(key)), value(::std::move(value)) {}
3346 buffer_type::move_assign_alloc::is_nothrow())
3347 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
3348
3352 is_freestanding() const noexcept {
3353 return key.is_freestanding() && value.is_freestanding();
3354 }
3358 is_reference() const noexcept {
3359 return key.is_reference() || value.is_reference();
3360 }
3365 key.make_freestanding();
3366 value.make_freestanding();
3367 }
3368
3369 operator pair() const noexcept { return pair(key, value); }
3370};
3371
3372template <typename BUFFER>
3373using buffer_pair = buffer_pair_spec<typename BUFFER::allocator_type,
3374 typename BUFFER::reservation_policy>;
3375
3377
3378//------------------------------------------------------------------------------
3379
3382enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
3383
3385enum class key_mode {
3396 msgpack = -1
3399};
3400
3402 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
3403}
3404
3406 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
3407}
3408
3410 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
3411}
3412
3414 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
3415}
3416
3418 return mode == key_mode::msgpack;
3419}
3420
3423enum class value_mode {
3426 multi =
3427 MDBX_DUPSORT,
3433#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
3435 MDBX_DUPSORT |
3445 MDBX_DUPSORT |
3473#else
3474 multi_reverse = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_REVERSEDUP),
3475 multi_samelength = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_DUPFIXED),
3476 multi_ordinal = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_DUPFIXED) |
3477 uint32_t(MDBX_INTEGERDUP),
3479 uint32_t(MDBX_REVERSEDUP) |
3480 uint32_t(MDBX_DUPFIXED),
3481#endif
3482 msgpack = -1
3489};
3490
3495
3497 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
3498}
3499
3501 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
3502}
3503
3505 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
3506}
3507
3509 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
3510}
3511
3513 return mode == value_mode::msgpack;
3514}
3515
3524 MDBX_dbi dbi{0};
3526 MDBX_CXX11_CONSTEXPR map_handle(MDBX_dbi dbi) noexcept : dbi(dbi) {}
3527 map_handle(const map_handle &) noexcept = default;
3528 map_handle &operator=(const map_handle &) noexcept = default;
3529 operator bool() const noexcept { return dbi != 0; }
3530 operator MDBX_dbi() const { return dbi; }
3531
3544};
3545
3547inline comparator default_comparator(key_mode mode) noexcept {
3548 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
3549}
3551 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
3552}
3553
3560
3571 friend class txn;
3572
3573protected:
3574 MDBX_env *handle_{nullptr};
3575 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
3576
3577public:
3578 MDBX_CXX11_CONSTEXPR env() noexcept = default;
3579 env(const env &) noexcept = default;
3580 inline env &operator=(env &&other) noexcept;
3581 inline env(env &&other) noexcept;
3582 inline ~env() noexcept;
3583
3584 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3585 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
3586 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
3587 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a,
3588 const env &b) noexcept;
3589 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a,
3590 const env &b) noexcept;
3591
3592 //----------------------------------------------------------------------------
3593
3598
3600 enum : intptr_t {
3601 default_value = -1,
3602 minimal_value = 0,
3603 maximal_value = INTPTR_MAX,
3604 kB = 1000,
3605 MB = kB * 1000,
3606 GB = MB * 1000,
3607#if INTPTR_MAX > 0x7fffFFFFl
3608 TB = GB * 1000,
3609 PB = TB * 1000,
3610 EB = PB * 1000,
3611#endif /* 64-bit intptr_t */
3612 KiB = 1024,
3613 MiB = KiB << 10,
3614 GiB = MiB << 10,
3615#if INTPTR_MAX > 0x7fffFFFFl
3616 TiB = GiB << 10,
3617 PiB = TiB << 10,
3618 EiB = PiB << 10,
3619#endif /* 64-bit intptr_t */
3620 };
3621
3623 struct size {
3624 intptr_t bytes;
3625 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3626 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3627 };
3628
3630 intptr_t size_lower{minimal_value};
3631
3635 intptr_t size_now{default_value};
3636
3647 intptr_t size_upper{maximal_value};
3648
3651 intptr_t growth_step{default_value};
3652
3655 intptr_t shrink_threshold{default_value};
3656
3661 intptr_t pagesize{default_value};
3662
3663 inline geometry &make_fixed(intptr_t size) noexcept;
3664 inline geometry &make_dynamic(intptr_t lower = minimal_value,
3665 intptr_t upper = maximal_value) noexcept;
3668 geometry(const geometry &) noexcept = default;
3669 MDBX_CXX11_CONSTEXPR geometry(intptr_t size_lower,
3670 intptr_t size_now = default_value,
3671 intptr_t size_upper = maximal_value,
3672 intptr_t growth_step = default_value,
3673 intptr_t shrink_threshold = default_value,
3674 intptr_t pagesize = default_value) noexcept
3675 : size_lower(size_lower), size_now(size_now), size_upper(size_upper),
3676 growth_step(growth_step), shrink_threshold(shrink_threshold),
3677 pagesize(pagesize) {}
3678 };
3679
3681 enum mode {
3683 write_file_io, // don't available on OpenBSD
3685 nested_transactions = write_file_io
3687
3695
3709
3713 bool no_sticky_threads{false};
3716 bool nested_write_transactions{false};
3718 bool exclusive{false};
3720 bool disable_readahead{false};
3722 bool disable_clear_memory{false};
3724 bool enable_validation{false};
3727 operate_options(const operate_options &) noexcept = default;
3729 operator=(const operate_options &) noexcept = default;
3731 };
3732
3737 unsigned max_maps{0};
3740 unsigned max_readers{0};
3741 env::mode mode{write_mapped_io};
3742 env::durability durability{robust_synchronous};
3745
3749 const unsigned max_maps, const unsigned max_readers = 0,
3750 const env::mode mode = env::mode::write_mapped_io,
3751 env::durability durability = env::durability::robust_synchronous,
3753 const env::operate_options &options = env::operate_options()) noexcept
3754 : max_maps(max_maps), max_readers(max_readers), mode(mode),
3755 durability(durability), reclaiming(reclaiming), options(options) {}
3757 operate_parameters(const operate_parameters &) noexcept = default;
3759 operator=(const operate_parameters &) noexcept = default;
3761 bool accede = true,
3764 bool use_subdirectory =
3765 false
3766 ) const;
3769 inline static env::reclaiming_options
3770 reclaiming_from_flags(MDBX_env_flags_t flags) noexcept;
3771 inline static env::operate_options
3772 options_from_flags(MDBX_env_flags_t flags) noexcept;
3773 };
3774
3776 inline env::operate_parameters get_operation_parameters() const;
3778 inline env::mode get_mode() const;
3780 inline env::durability get_durability() const;
3782 inline env::reclaiming_options get_reclaiming() const;
3784 inline env::operate_options get_options() const;
3785
3788 bool is_pristine() const;
3789
3791 bool is_empty() const;
3792
3794 static size_t default_pagesize() noexcept {
3795 return ::mdbx_default_pagesize();
3796 }
3797
3798 struct limits {
3799 limits() = delete;
3801 static inline size_t pagesize_min() noexcept;
3803 static inline size_t pagesize_max() noexcept;
3806 static inline size_t dbsize_min(intptr_t pagesize);
3809 static inline size_t dbsize_max(intptr_t pagesize);
3812 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3814 static inline size_t key_min(key_mode mode) noexcept;
3817 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3820 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3823 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3826 static inline size_t key_max(const env &, key_mode mode);
3829 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3832 static inline size_t value_min(value_mode) noexcept;
3833
3836 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3839 static inline size_t value_max(intptr_t pagesize, value_mode);
3842 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3845 static inline size_t value_max(const env &, value_mode);
3846
3849 static inline size_t pairsize4page_max(intptr_t pagesize,
3850 MDBX_db_flags_t flags);
3853 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3856 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3859 static inline size_t pairsize4page_max(const env &, value_mode);
3860
3863 static inline size_t valsize4page_max(intptr_t pagesize,
3864 MDBX_db_flags_t flags);
3867 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3870 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3873 static inline size_t valsize4page_max(const env &, value_mode);
3874
3877 static inline size_t transaction_size_max(intptr_t pagesize);
3878
3880 static inline size_t max_map_handles(void);
3881 };
3882
3884 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3886 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3888 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3890 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3892 size_t value_min(value_mode mode) const noexcept {
3893 return limits::value_min(mode);
3894 }
3896 size_t value_max(value_mode mode) const {
3897 return limits::value_max(*this, mode);
3898 }
3901 size_t transaction_size_max() const {
3902 return limits::transaction_size_max(this->get_pagesize());
3903 }
3904
3907#ifdef MDBX_STD_FILESYSTEM_PATH
3908 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify,
3909 bool force_dynamic_size = false);
3910#endif /* MDBX_STD_FILESYSTEM_PATH */
3911#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3912 env &copy(const ::std::wstring &destination, bool compactify,
3913 bool force_dynamic_size = false);
3914 env &copy(const wchar_t *destination, bool compactify,
3915 bool force_dynamic_size = false);
3916#endif /* Windows */
3917 env &copy(const ::std::string &destination, bool compactify,
3918 bool force_dynamic_size = false);
3919 env &copy(const char *destination, bool compactify,
3920 bool force_dynamic_size = false);
3921
3923 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3924
3936 ensure_unused = MDBX_ENV_ENSURE_UNUSED,
3939 wait_for_unused = MDBX_ENV_WAIT_FOR_UNUSED
3941
3944#ifdef MDBX_STD_FILESYSTEM_PATH
3945 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname,
3946 const remove_mode mode = just_remove);
3947#endif /* MDBX_STD_FILESYSTEM_PATH */
3948#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3949 static bool remove(const ::std::wstring &pathname,
3950 const remove_mode mode = just_remove);
3951 static bool remove(const wchar_t *pathname,
3952 const remove_mode mode = just_remove);
3953#endif /* Windows */
3954 static bool remove(const ::std::string &pathname,
3955 const remove_mode mode = just_remove);
3956 static bool remove(const char *pathname,
3957 const remove_mode mode = just_remove);
3958
3961
3964
3966 inline stat get_stat() const;
3967
3969 size_t get_pagesize() const { return get_stat().ms_psize; }
3970
3972 inline info get_info() const;
3973
3976 inline stat get_stat(const txn &) const;
3977
3980 inline info get_info(const txn &) const;
3981
3983 inline filehandle get_filehandle() const;
3984
3987
3989 inline MDBX_env_flags_t get_flags() const;
3990
3994 inline unsigned max_readers() const;
3995
3998 inline unsigned max_maps() const;
3999
4001 inline void *get_context() const noexcept;
4002
4004 inline env &set_context(void *your_context);
4005
4020 inline env &set_sync_threshold(size_t bytes);
4021
4027 inline size_t sync_threshold() const;
4028
4029#if __cplusplus >= 201103L || defined(DOXYGEN)
4049 inline env &set_sync_period(const duration &period);
4050
4056 inline duration sync_period() const;
4057#endif
4058
4062 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
4063
4066 inline unsigned sync_period__seconds_16dot16() const;
4067
4071 inline env &set_sync_period__seconds_double(double seconds);
4072
4075 inline double sync_period__seconds_double() const;
4076
4081 max_maps = MDBX_opt_max_db,
4084 max_readers = MDBX_opt_max_readers,
4087 sync_bytes = MDBX_opt_sync_bytes,
4090 sync_period = MDBX_opt_sync_period,
4092 rp_augment_limit = MDBX_opt_rp_augment_limit,
4094 loose_limit = MDBX_opt_loose_limit,
4096 dp_reserve_limit = MDBX_opt_dp_reserve_limit,
4098 dp_limit = MDBX_opt_txn_dp_limit,
4100 dp_initial = MDBX_opt_txn_dp_initial,
4102 spill_max_denominator = MDBX_opt_spill_max_denominator,
4104 spill_min_denominator = MDBX_opt_spill_min_denominator,
4106 spill_parent4child_denominator = MDBX_opt_spill_parent4child_denominator,
4108 merge_threshold_16dot16_percent = MDBX_opt_merge_threshold_16dot16_percent,
4110 writethrough_threshold = MDBX_opt_writethrough_threshold,
4112 prefault_write_enable = MDBX_opt_prefault_write_enable,
4113 };
4114
4116 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
4117
4119 inline uint64_t extra_option(extra_runtime_option option) const;
4120
4122 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
4123
4125 inline env &set_geometry(const geometry &size);
4126
4130 inline bool sync_to_disk(bool force = true, bool nonblock = false);
4131
4135 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
4136
4155 inline void close_map(const map_handle &);
4156
4159 int slot;
4168 size_t bytes_used;
4177
4179 mdbx_tid_t thread, uint64_t txnid,
4180 uint64_t lag, size_t used,
4181 size_t retained) noexcept;
4182 };
4183
4191 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
4192
4195 inline unsigned check_readers();
4196
4214 inline env &set_HandleSlowReaders(MDBX_hsr_func *);
4215
4220 inline MDBX_hsr_func *get_HandleSlowReaders() const noexcept;
4221
4223 inline txn_managed start_read() const;
4224
4226 inline txn_managed prepare_read() const;
4227
4229 inline txn_managed start_write(txn &parent);
4230
4232 inline txn_managed start_write(bool dont_wait = false);
4233
4235 inline txn_managed try_start_write();
4236};
4237
4247 using inherited = env;
4249 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
4250 void setup(unsigned max_maps, unsigned max_readers = 0);
4251
4252public:
4253 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
4254
4256#ifdef MDBX_STD_FILESYSTEM_PATH
4258 const operate_parameters &, bool accede = true);
4259#endif /* MDBX_STD_FILESYSTEM_PATH */
4260#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
4261 env_managed(const ::std::wstring &pathname, const operate_parameters &,
4262 bool accede = true);
4263 explicit env_managed(const wchar_t *pathname, const operate_parameters &,
4264 bool accede = true);
4265#endif /* Windows */
4266 env_managed(const ::std::string &pathname, const operate_parameters &,
4267 bool accede = true);
4268 explicit env_managed(const char *pathname, const operate_parameters &,
4269 bool accede = true);
4270
4276 mdbx_mode_t file_mode_bits{0640};
4277 bool use_subdirectory{false};
4279 create_parameters(const create_parameters &) noexcept = default;
4280 };
4281
4283#ifdef MDBX_STD_FILESYSTEM_PATH
4285 const create_parameters &, const operate_parameters &,
4286 bool accede = true);
4287#endif /* MDBX_STD_FILESYSTEM_PATH */
4288#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
4289 env_managed(const ::std::wstring &pathname, const create_parameters &,
4290 const operate_parameters &, bool accede = true);
4291 explicit env_managed(const wchar_t *pathname, const create_parameters &,
4292 const operate_parameters &, bool accede = true);
4293#endif /* Windows */
4294 env_managed(const ::std::string &pathname, const create_parameters &,
4295 const operate_parameters &, bool accede = true);
4296 explicit env_managed(const char *pathname, const create_parameters &,
4297 const operate_parameters &, bool accede = true);
4298
4312 void close(bool dont_sync = false);
4313
4315 env_managed &operator=(env_managed &&other) noexcept {
4316 if (MDBX_UNLIKELY(handle_))
4317 MDBX_CXX20_UNLIKELY {
4318 assert(handle_ != other.handle_);
4319 close();
4320 }
4321 inherited::operator=(std::move(other));
4322 return *this;
4323 }
4324 env_managed(const env_managed &) = delete;
4326 virtual ~env_managed() noexcept;
4327};
4328
4338protected:
4339 friend class cursor;
4340 MDBX_txn *handle_{nullptr};
4341 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
4342
4343public:
4344 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
4345 txn(const txn &) noexcept = default;
4346 inline txn &operator=(txn &&other) noexcept;
4347 inline txn(txn &&other) noexcept;
4348 inline ~txn() noexcept;
4349
4350 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4351 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
4352 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
4353 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a,
4354 const txn &b) noexcept;
4355 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a,
4356 const txn &b) noexcept;
4357
4359 inline ::mdbx::env env() const noexcept;
4361 inline MDBX_txn_flags_t flags() const;
4363 inline uint64_t id() const;
4364
4366 inline void *get_context() const noexcept;
4367
4369 inline txn &set_context(void *your_context);
4370
4372 inline bool is_dirty(const void *ptr) const;
4373
4375 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
4376
4378 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
4379
4382 inline info get_info(bool scan_reader_lock_table = false) const;
4383
4386 size_t size_max() const { return env().transaction_size_max(); }
4387
4390 size_t size_current() const {
4391 assert(is_readwrite());
4392 return size_t(get_info().txn_space_dirty);
4393 }
4394
4395 //----------------------------------------------------------------------------
4396
4398 inline void reset_reading();
4399
4401 inline void renew_reading();
4402
4404 inline void park_reading(bool autounpark = true);
4405
4408 inline bool unpark_reading(bool restart_if_ousted = true);
4409
4412
4414 inline cursor_managed open_cursor(map_handle map) const;
4415
4417 inline size_t release_all_cursors(bool unbind) const;
4418
4420 inline size_t close_all_cursors() const { return release_all_cursors(false); }
4421
4423 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
4424
4426 inline map_handle open_map(
4427 const char *name,
4428 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4429 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
4431 inline map_handle open_map(
4432 const ::std::string &name,
4433 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4434 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
4436 inline map_handle open_map(
4437 const ::mdbx::slice &name,
4438 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4439 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
4440
4442 inline map_handle open_map_accede(const char *name) const;
4444 inline map_handle open_map_accede(const ::std::string &name) const;
4446 inline map_handle open_map_accede(const ::mdbx::slice &name) const;
4447
4449 inline map_handle
4450 create_map(const char *name,
4451 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4452 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
4454 inline map_handle
4455 create_map(const ::std::string &name,
4456 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4457 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
4459 inline map_handle
4460 create_map(const ::mdbx::slice &name,
4461 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4462 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
4463
4465 inline void drop_map(map_handle map);
4469 bool drop_map(const char *name, bool throw_if_absent = false);
4473 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
4477 bool drop_map(const ::mdbx::slice &name, bool throw_if_absent = false);
4478
4480 inline void clear_map(map_handle map);
4483 bool clear_map(const char *name, bool throw_if_absent = false);
4486 inline bool clear_map(const ::std::string &name,
4487 bool throw_if_absent = false);
4490 bool clear_map(const ::mdbx::slice &name, bool throw_if_absent = false);
4491
4493 inline void rename_map(map_handle map, const char *new_name);
4495 inline void rename_map(map_handle map, const ::std::string &new_name);
4497 inline void rename_map(map_handle map, const ::mdbx::slice &new_name);
4501 bool rename_map(const char *old_name, const char *new_name,
4502 bool throw_if_absent = false);
4506 bool rename_map(const ::std::string &old_name, const ::std::string &new_name,
4507 bool throw_if_absent = false);
4511 bool rename_map(const ::mdbx::slice &old_name, const ::mdbx::slice &new_name,
4512 bool throw_if_absent = false);
4513
4514#if defined(DOXYGEN) || \
4515 (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
4516
4519 const ::std::string_view &name,
4520 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4521 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
4522 return open_map(::mdbx::slice(name), key_mode, value_mode);
4523 }
4525 inline map_handle open_map_accede(const ::std::string_view &name) const;
4527 inline map_handle
4528 create_map(const ::std::string_view &name,
4529 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4530 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
4531 return create_map(::mdbx::slice(name), key_mode, value_mode);
4532 }
4536 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
4537 return drop_map(::mdbx::slice(name), throw_if_absent);
4538 }
4541 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
4542 return clear_map(::mdbx::slice(name), throw_if_absent);
4543 }
4545 inline void rename_map(map_handle map, const ::std::string_view &new_name);
4549 bool rename_map(const ::std::string_view &old_name,
4550 const ::std::string_view &new_name,
4551 bool throw_if_absent = false) {
4552 return rename_map(::mdbx::slice(old_name), ::mdbx::slice(new_name),
4553 throw_if_absent);
4554 }
4555#endif /* __cpp_lib_string_view >= 201606L */
4556
4559 inline map_stat get_map_stat(map_handle map) const;
4562 inline uint32_t get_tree_deepmask(map_handle map) const;
4564 inline map_handle::info get_handle_info(map_handle map) const;
4565
4569 inline txn &put_canary(const canary &);
4572 inline canary get_canary() const;
4573
4576 inline uint64_t sequence(map_handle map) const;
4579 inline uint64_t sequence(map_handle map, uint64_t increment);
4580
4583 inline int compare_keys(map_handle map, const slice &a,
4584 const slice &b) const noexcept;
4587 inline int compare_values(map_handle map, const slice &a,
4588 const slice &b) const noexcept;
4591 inline int compare_keys(map_handle map, const pair &a,
4592 const pair &b) const noexcept;
4595 inline int compare_values(map_handle map, const pair &a,
4596 const pair &b) const noexcept;
4597
4599 inline slice get(map_handle map, const slice &key) const;
4602 inline slice get(map_handle map, slice key, size_t &values_count) const;
4604 inline slice get(map_handle map, const slice &key,
4605 const slice &value_at_absence) const;
4608 inline slice get(map_handle map, slice key, size_t &values_count,
4609 const slice &value_at_absence) const;
4613 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
4617 inline pair_result get_equal_or_great(map_handle map, const slice &key,
4618 const slice &value_at_absence) const;
4619
4620 inline MDBX_error_t put(map_handle map, const slice &key, slice *value,
4621 MDBX_put_flags_t flags) noexcept;
4622 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
4623 inline void insert(map_handle map, const slice &key, slice value);
4624 inline value_result try_insert(map_handle map, const slice &key, slice value);
4625 inline slice insert_reserve(map_handle map, const slice &key,
4626 size_t value_length);
4627 inline value_result try_insert_reserve(map_handle map, const slice &key,
4628 size_t value_length);
4629
4630 inline void upsert(map_handle map, const slice &key, const slice &value);
4631 inline slice upsert_reserve(map_handle map, const slice &key,
4632 size_t value_length);
4633
4634 inline void update(map_handle map, const slice &key, const slice &value);
4635 inline bool try_update(map_handle map, const slice &key, const slice &value);
4636 inline slice update_reserve(map_handle map, const slice &key,
4637 size_t value_length);
4638 inline value_result try_update_reserve(map_handle map, const slice &key,
4639 size_t value_length);
4640
4641 void put(map_handle map, const pair &kv, put_mode mode) {
4642 return put(map, kv.key, kv.value, mode);
4643 }
4644 void insert(map_handle map, const pair &kv) {
4645 return insert(map, kv.key, kv.value);
4646 }
4648 return try_insert(map, kv.key, kv.value);
4649 }
4650 void upsert(map_handle map, const pair &kv) {
4651 return upsert(map, kv.key, kv.value);
4652 }
4653
4655 inline bool erase(map_handle map, const slice &key);
4656
4658 inline bool erase(map_handle map, const slice &key, const slice &value);
4659
4661 inline void replace(map_handle map, const slice &key, slice old_value,
4662 const slice &new_value);
4663
4665 template <class ALLOCATOR, typename CAPACITY_POLICY>
4667 extract(map_handle map, const slice &key,
4670
4672 template <class ALLOCATOR, typename CAPACITY_POLICY>
4674 replace(map_handle map, const slice &key, const slice &new_value,
4677
4678 template <class ALLOCATOR, typename CAPACITY_POLICY>
4679 inline buffer<ALLOCATOR, CAPACITY_POLICY> replace_reserve(
4680 map_handle map, const slice &key, slice &new_value,
4683
4700 inline void append(map_handle map, const slice &key, const slice &value,
4701 bool multivalue_order_preserved = true);
4702 inline void append(map_handle map, const pair &kv,
4703 bool multivalue_order_preserved = true) {
4704 return append(map, kv.key, kv.value, multivalue_order_preserved);
4705 }
4706
4707 size_t put_multiple_samelength(map_handle map, const slice &key,
4708 const size_t value_length,
4709 const void *values_array, size_t values_count,
4710 put_mode mode, bool allow_partial = false);
4711 template <typename VALUE>
4713 const VALUE *values_array, size_t values_count,
4714 put_mode mode, bool allow_partial = false) {
4715 static_assert(::std::is_standard_layout<VALUE>::value &&
4716 !::std::is_pointer<VALUE>::value &&
4717 !::std::is_array<VALUE>::value,
4718 "Must be a standard layout type!");
4719 return put_multiple_samelength(map, key, sizeof(VALUE), values_array,
4720 values_count, mode, allow_partial);
4721 }
4722 template <typename VALUE>
4724 const ::std::vector<VALUE> &vector,
4725 put_mode mode) {
4726 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4727 }
4728
4729 inline ptrdiff_t estimate(map_handle map, const pair &from,
4730 const pair &to) const;
4731 inline ptrdiff_t estimate(map_handle map, const slice &from,
4732 const slice &to) const;
4733 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4734 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4735};
4736
4746 using inherited = txn;
4747 friend class env;
4748 friend class txn;
4750 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4751
4752public:
4753 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4755 txn_managed &operator=(txn_managed &&other) noexcept {
4756 if (MDBX_UNLIKELY(handle_))
4757 MDBX_CXX20_UNLIKELY {
4758 assert(handle_ != other.handle_);
4759 abort();
4760 }
4761 inherited::operator=(std::move(other));
4762 return *this;
4763 }
4764 txn_managed(const txn_managed &) = delete;
4766 ~txn_managed() noexcept;
4767
4768 //----------------------------------------------------------------------------
4769
4772 void abort();
4773
4775 void commit();
4776
4779 void commit_embark_read();
4780
4782
4785 void commit(commit_latency *);
4786
4789 void commit(commit_latency &latency) { return commit(&latency); }
4790
4795 commit_latency result;
4796 commit(&result);
4797 return result;
4798 }
4799};
4800
4809protected:
4810 MDBX_cursor *handle_{nullptr};
4812
4813public:
4814 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4815 cursor(const cursor &) noexcept = default;
4816 inline cursor &operator=(cursor &&other) noexcept;
4817 inline cursor(cursor &&other) noexcept;
4818 inline ~cursor() noexcept;
4819 inline cursor_managed clone(void *your_context = nullptr) const;
4820 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4821 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4822 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4823 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a,
4824 const cursor &b) noexcept;
4825 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a,
4826 const cursor &b) noexcept;
4827
4828 friend inline int compare_position_nothrow(const cursor &left,
4829 const cursor &right,
4830 bool ignore_nested) noexcept;
4831 friend inline int compare_position(const cursor &left, const cursor &right,
4832 bool ignore_nested);
4833
4834 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4835 return compare_position(*this, other, ignore_nested) < 0;
4836 }
4837
4839 bool ignore_nested = false) const {
4840 return compare_position(*this, other, ignore_nested) <= 0;
4841 }
4842
4843 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4844 return compare_position(*this, other, ignore_nested) == 0;
4845 }
4846
4847 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4848 return compare_position(*this, other, ignore_nested) > 0;
4849 }
4850
4852 bool ignore_nested = false) const {
4853 return compare_position(*this, other, ignore_nested) >= 0;
4854 }
4855
4857 inline void *get_context() const noexcept;
4858
4860 inline cursor &set_context(void *your_context);
4861
4863 first = MDBX_FIRST,
4866 previous = MDBX_PREV,
4867 get_current = MDBX_GET_CURRENT,
4868
4869 multi_prevkey_lastvalue = MDBX_PREV_NODUP,
4870 multi_currentkey_firstvalue = MDBX_FIRST_DUP,
4871 multi_currentkey_prevvalue = MDBX_PREV_DUP,
4872 multi_currentkey_nextvalue = MDBX_NEXT_DUP,
4873 multi_currentkey_lastvalue = MDBX_LAST_DUP,
4874 multi_nextkey_firstvalue = MDBX_NEXT_NODUP,
4875
4876 multi_find_pair = MDBX_GET_BOTH,
4877 multi_exactkey_lowerboundvalue = MDBX_GET_BOTH_RANGE,
4878
4879 seek_key = MDBX_SET,
4880 key_exact = MDBX_SET_KEY,
4881 key_lowerbound = MDBX_SET_RANGE,
4882
4883 /* Doubtless cursor positioning at a specified key. */
4884 key_lesser_than = MDBX_TO_KEY_LESSER_THAN,
4885 key_lesser_or_equal = MDBX_TO_KEY_LESSER_OR_EQUAL,
4887 key_greater_or_equal = MDBX_TO_KEY_GREATER_OR_EQUAL,
4888 key_greater_than = MDBX_TO_KEY_GREATER_THAN,
4889
4890 /* Doubtless cursor positioning at a specified key-value pair
4891 * for dupsort/multi-value hives. */
4892 multi_exactkey_value_lesser_than = MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN,
4893 multi_exactkey_value_lesser_or_equal =
4895 multi_exactkey_value_equal = MDBX_TO_EXACT_KEY_VALUE_EQUAL,
4896 multi_exactkey_value_greater_or_equal =
4898 multi_exactkey_value_greater = MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN,
4899
4900 pair_lesser_than = MDBX_TO_PAIR_LESSER_THAN,
4901 pair_lesser_or_equal = MDBX_TO_PAIR_LESSER_OR_EQUAL,
4903 pair_exact = pair_equal,
4904 pair_greater_or_equal = MDBX_TO_PAIR_GREATER_OR_EQUAL,
4905 pair_greater_than = MDBX_TO_PAIR_GREATER_THAN,
4906
4907 batch_samelength = MDBX_GET_MULTIPLE,
4908 batch_samelength_next = MDBX_NEXT_MULTIPLE,
4909 batch_samelength_previous = MDBX_PREV_MULTIPLE
4911
4912 struct move_result : public pair_result {
4913 inline move_result(const cursor &cursor, bool throw_notfound);
4914 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4915 : move_result(cursor, operation, slice::invalid(), slice::invalid(),
4916 throw_notfound) {}
4918 bool throw_notfound)
4919 : move_result(cursor, operation, key, slice::invalid(),
4920 throw_notfound) {}
4921 inline move_result(cursor &cursor, move_operation operation,
4922 const slice &key, const slice &value,
4923 bool throw_notfound);
4924 move_result(const move_result &) noexcept = default;
4925 move_result &operator=(const move_result &) noexcept = default;
4926 };
4927
4928 struct estimate_result : public pair {
4931 : estimate_result(cursor, operation, slice::invalid(),
4932 slice::invalid()) {}
4934 const slice &key)
4935 : estimate_result(cursor, operation, key, slice::invalid()) {}
4936 inline estimate_result(const cursor &cursor, move_operation operation,
4937 const slice &key, const slice &value);
4938 estimate_result(const estimate_result &) noexcept = default;
4939 estimate_result &operator=(const estimate_result &) noexcept = default;
4940 };
4941
4942protected:
4943 /* fake const, i.e. for some move/get operations */
4944 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value,
4945 bool throw_notfound) const;
4946
4947 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key,
4948 MDBX_val *value) const;
4949
4950public:
4951 template <typename CALLABLE_PREDICATE>
4952 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first,
4953 move_operation turn = next) {
4954 struct wrapper : public exception_thunk {
4955 static int probe(void *context, MDBX_val *key, MDBX_val *value,
4956 void *arg) noexcept {
4957 auto thunk = static_cast<wrapper *>(context);
4958 assert(thunk->is_clean());
4959 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4960 try {
4961 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE
4963 } catch (... /* capture any exception to rethrow it over C code */) {
4964 thunk->capture();
4965 return MDBX_RESULT_TRUE;
4966 }
4967 }
4968 } thunk;
4969 return error::boolean_or_throw(
4970 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk,
4971 MDBX_cursor_op(start), MDBX_cursor_op(turn),
4972 &predicate),
4973 thunk);
4974 }
4975
4976 template <typename CALLABLE_PREDICATE>
4977 bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4978 return scan(std::move(predicate), backward ? last : first,
4979 backward ? previous : next);
4980 }
4981
4982 template <typename CALLABLE_PREDICATE>
4983 bool scan_from(CALLABLE_PREDICATE predicate, slice &from,
4984 move_operation start = key_greater_or_equal,
4985 move_operation turn = next) {
4986 struct wrapper : public exception_thunk {
4987 static int probe(void *context, MDBX_val *key, MDBX_val *value,
4988 void *arg) noexcept {
4989 auto thunk = static_cast<wrapper *>(context);
4990 assert(thunk->is_clean());
4991 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4992 try {
4993 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE
4995 } catch (... /* capture any exception to rethrow it over C code */) {
4996 thunk->capture();
4997 return MDBX_RESULT_TRUE;
4998 }
4999 }
5000 } thunk;
5001 return error::boolean_or_throw(
5002 ::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk,
5003 MDBX_cursor_op(start), &from, nullptr,
5004 MDBX_cursor_op(turn), &predicate),
5005 thunk);
5006 }
5007
5008 template <typename CALLABLE_PREDICATE>
5009 bool scan_from(CALLABLE_PREDICATE predicate, pair &from,
5010 move_operation start = pair_greater_or_equal,
5011 move_operation turn = next) {
5012 struct wrapper : public exception_thunk {
5013 static int probe(void *context, MDBX_val *key, MDBX_val *value,
5014 void *arg) noexcept {
5015 auto thunk = static_cast<wrapper *>(context);
5016 assert(thunk->is_clean());
5017 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
5018 try {
5019 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE
5021 } catch (... /* capture any exception to rethrow it over C code */) {
5022 thunk->capture();
5023 return MDBX_RESULT_TRUE;
5024 }
5025 }
5026 } thunk;
5027 return error::boolean_or_throw(
5028 ::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk,
5029 MDBX_cursor_op(start), &from.key, &from.value,
5030 MDBX_cursor_op(turn), &predicate),
5031 thunk);
5032 }
5033
5034 move_result move(move_operation operation, bool throw_notfound) {
5035 return move_result(*this, operation, throw_notfound);
5036 }
5037 move_result move(move_operation operation, const slice &key,
5038 bool throw_notfound) {
5039 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
5040 }
5041 move_result move(move_operation operation, const slice &key,
5042 const slice &value, bool throw_notfound) {
5043 return move_result(*this, operation, key, value, throw_notfound);
5044 }
5045 bool move(move_operation operation, slice &key, slice &value,
5046 bool throw_notfound) {
5047 return move(operation, &key, &value, throw_notfound);
5048 }
5049
5050 move_result to_first(bool throw_notfound = true) {
5051 return move(first, throw_notfound);
5052 }
5053 move_result to_previous(bool throw_notfound = true) {
5054 return move(previous, throw_notfound);
5055 }
5056 move_result to_previous_last_multi(bool throw_notfound = true) {
5057 return move(multi_prevkey_lastvalue, throw_notfound);
5058 }
5059 move_result to_current_first_multi(bool throw_notfound = true) {
5060 return move(multi_currentkey_firstvalue, throw_notfound);
5061 }
5062 move_result to_current_prev_multi(bool throw_notfound = true) {
5063 return move(multi_currentkey_prevvalue, throw_notfound);
5064 }
5065 move_result current(bool throw_notfound = true) const {
5066 return move_result(*this, throw_notfound);
5067 }
5068 move_result to_current_next_multi(bool throw_notfound = true) {
5069 return move(multi_currentkey_nextvalue, throw_notfound);
5070 }
5071 move_result to_current_last_multi(bool throw_notfound = true) {
5072 return move(multi_currentkey_lastvalue, throw_notfound);
5073 }
5074 move_result to_next_first_multi(bool throw_notfound = true) {
5075 return move(multi_nextkey_firstvalue, throw_notfound);
5076 }
5077 move_result to_next(bool throw_notfound = true) {
5078 return move(next, throw_notfound);
5079 }
5080 move_result to_last(bool throw_notfound = true) {
5081 return move(last, throw_notfound);
5082 }
5083
5084 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
5085 return move(key_lesser_than, key, throw_notfound);
5086 }
5088 bool throw_notfound = true) {
5089 return move(key_lesser_or_equal, key, throw_notfound);
5090 }
5091 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
5092 return move(key_equal, key, throw_notfound);
5093 }
5094 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
5095 return move(key_exact, key, throw_notfound);
5096 }
5098 bool throw_notfound = true) {
5099 return move(key_greater_or_equal, key, throw_notfound);
5100 }
5102 bool throw_notfound = true) {
5103 return move(key_greater_than, key, throw_notfound);
5104 }
5105
5107 const slice &value,
5108 bool throw_notfound = true) {
5109 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
5110 }
5112 const slice &value,
5113 bool throw_notfound = true) {
5114 return move(multi_exactkey_value_lesser_or_equal, key, value,
5115 throw_notfound);
5116 }
5118 bool throw_notfound = true) {
5119 return move(multi_exactkey_value_equal, key, value, throw_notfound);
5120 }
5122 const slice &value,
5123 bool throw_notfound = true) {
5124 return move(multi_exactkey_value_greater_or_equal, key, value,
5125 throw_notfound);
5126 }
5128 const slice &value,
5129 bool throw_notfound = true) {
5130 return move(multi_exactkey_value_greater, key, value, throw_notfound);
5131 }
5132
5133 move_result to_pair_lesser_than(const slice &key, const slice &value,
5134 bool throw_notfound = true) {
5135 return move(pair_lesser_than, key, value, throw_notfound);
5136 }
5138 bool throw_notfound = true) {
5139 return move(pair_lesser_or_equal, key, value, throw_notfound);
5140 }
5141 move_result to_pair_equal(const slice &key, const slice &value,
5142 bool throw_notfound = true) {
5143 return move(pair_equal, key, value, throw_notfound);
5144 }
5145 move_result to_pair_exact(const slice &key, const slice &value,
5146 bool throw_notfound = true) {
5147 return move(pair_exact, key, value, throw_notfound);
5148 }
5150 bool throw_notfound = true) {
5151 return move(pair_greater_or_equal, key, value, throw_notfound);
5152 }
5154 bool throw_notfound = true) {
5155 return move(pair_greater_than, key, value, throw_notfound);
5156 }
5157
5158 inline bool seek(const slice &key);
5159 inline move_result find(const slice &key, bool throw_notfound = true);
5160 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
5161 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
5162
5164 inline size_t count_multivalue() const;
5165
5166 inline move_result find_multivalue(const slice &key, const slice &value,
5167 bool throw_notfound = true);
5168 inline move_result lower_bound_multivalue(const slice &key,
5169 const slice &value,
5170 bool throw_notfound = false);
5171 inline move_result upper_bound_multivalue(const slice &key,
5172 const slice &value,
5173 bool throw_notfound = false);
5174
5176 bool throw_notfound = true) {
5177 return move(batch_samelength, key, throw_notfound);
5178 }
5179
5180 inline move_result get_multiple_samelength(bool throw_notfound = false) {
5181 return move(batch_samelength, throw_notfound);
5182 }
5183
5184 inline move_result next_multiple_samelength(bool throw_notfound = false) {
5185 return move(batch_samelength_next, throw_notfound);
5186 }
5187
5188 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
5189 return move(batch_samelength_previous, throw_notfound);
5190 }
5191
5192 inline bool eof() const;
5193 inline bool on_first() const;
5194 inline bool on_last() const;
5195 inline bool on_first_multival() const;
5196 inline bool on_last_multival() const;
5197 inline estimate_result estimate(const slice &key, const slice &value) const;
5198 inline estimate_result estimate(const slice &key) const;
5199 inline estimate_result estimate(move_operation operation) const;
5200 inline estimate_result estimate(move_operation operation, slice &key) const;
5201
5202 //----------------------------------------------------------------------------
5203
5206 inline void renew(const ::mdbx::txn &txn);
5207
5210 inline void bind(const ::mdbx::txn &txn, ::mdbx::map_handle map_handle);
5211
5213 inline void unbind();
5214
5216 inline ::mdbx::txn txn() const;
5217 inline map_handle map() const;
5218
5219 inline operator ::mdbx::txn() const { return txn(); }
5220 inline operator ::mdbx::map_handle() const { return map(); }
5221
5222 inline MDBX_error_t put(const slice &key, slice *value,
5223 MDBX_put_flags_t flags) noexcept;
5224 inline void put(const slice &key, slice value, put_mode mode);
5225 inline void insert(const slice &key, slice value);
5226 inline value_result try_insert(const slice &key, slice value);
5227 inline slice insert_reserve(const slice &key, size_t value_length);
5228 inline value_result try_insert_reserve(const slice &key, size_t value_length);
5229
5230 inline void upsert(const slice &key, const slice &value);
5231 inline slice upsert_reserve(const slice &key, size_t value_length);
5232
5233 inline void update(const slice &key, const slice &value);
5234 inline bool try_update(const slice &key, const slice &value);
5235 inline slice update_reserve(const slice &key, size_t value_length);
5236 inline value_result try_update_reserve(const slice &key, size_t value_length);
5237
5238 void put(const pair &kv, put_mode mode) {
5239 return put(kv.key, kv.value, mode);
5240 }
5241 void insert(const pair &kv) { return insert(kv.key, kv.value); }
5243 return try_insert(kv.key, kv.value);
5244 }
5245 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
5246
5249 inline bool erase(bool whole_multivalue = false);
5250
5254 inline bool erase(const slice &key, bool whole_multivalue = true);
5255
5258 inline bool erase(const slice &key, const slice &value);
5259};
5260
5269 using inherited = cursor;
5270 friend class txn;
5273 : inherited(ptr) {}
5274
5275public:
5277 cursor_managed(void *your_context = nullptr)
5278 : cursor_managed(::mdbx_cursor_create(your_context)) {
5279 if (MDBX_UNLIKELY(!handle_))
5280 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
5281 }
5282
5284 void close();
5285
5288 if (MDBX_UNLIKELY(handle_))
5289 MDBX_CXX20_UNLIKELY {
5290 assert(handle_ != other.handle_);
5291 close();
5292 }
5293 inherited::operator=(std::move(other));
5294 return *this;
5295 }
5296
5299 ~cursor_managed() noexcept { ::mdbx_cursor_close(handle_); }
5300};
5301
5302//------------------------------------------------------------------------------
5303
5304LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
5305LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
5306LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
5307template <class ALLOCATOR, typename CAPACITY_POLICY>
5308inline ::std::ostream &
5309operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
5310 return (it.is_freestanding()
5311 ? out << "buf-" << it.headroom() << "." << it.tailroom()
5312 : out << "ref-")
5313 << it.slice();
5314}
5315LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5316 const env::geometry::size &);
5317LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
5318LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5319 const env::operate_parameters &);
5320LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
5321LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5322 const env::durability &);
5323LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5324 const env::reclaiming_options &);
5325LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5326 const env::operate_options &);
5327LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5329
5330LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5331 const MDBX_log_level_t &);
5332LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5333 const MDBX_debug_flags_t &);
5334LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
5335inline ::std::ostream &operator<<(::std::ostream &out,
5336 const MDBX_error_t &errcode) {
5337 return out << error(errcode);
5338}
5339
5340//==============================================================================
5341//
5342// Inline body of the libmdbx C++ API
5343//
5344
5346 return ::mdbx_version;
5347}
5349 return ::mdbx_build;
5350}
5351
5352static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
5353#if defined(__cpp_lib_is_constant_evaluated) && \
5354 __cpp_lib_is_constant_evaluated >= 201811L
5355 if (::std::is_constant_evaluated()) {
5356 for (size_t i = 0; c_str; ++i)
5357 if (!c_str[i])
5358 return i;
5359 return 0;
5360 }
5361#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
5362#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
5363 return c_str ? ::std::string_view(c_str).length() : 0;
5364#else
5365 return c_str ? ::std::strlen(c_str) : 0;
5366#endif
5367}
5368
5370memcpy(void *dest, const void *src, size_t bytes) noexcept {
5371#if defined(__cpp_lib_is_constant_evaluated) && \
5372 __cpp_lib_is_constant_evaluated >= 201811L
5373 if (::std::is_constant_evaluated()) {
5374 for (size_t i = 0; i < bytes; ++i)
5375 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
5376 return dest;
5377 } else
5378#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
5379 return ::std::memcpy(dest, src, bytes);
5380}
5381
5382static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b,
5383 size_t bytes) noexcept {
5384#if defined(__cpp_lib_is_constant_evaluated) && \
5385 __cpp_lib_is_constant_evaluated >= 201811L
5386 if (::std::is_constant_evaluated()) {
5387 for (size_t i = 0; i < bytes; ++i) {
5388 const int diff = int(static_cast<const byte *>(a)[i]) -
5389 int(static_cast<const byte *>(b)[i]);
5390 if (diff)
5391 return diff;
5392 }
5393 return 0;
5394 } else
5395#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
5396 return ::std::memcmp(a, b, bytes);
5397}
5398
5399static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
5400 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
5401 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
5402 return bytes;
5403}
5404
5405static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom,
5406 size_t payload) {
5407 return check_length(check_length(headroom) + check_length(payload));
5408}
5409
5411check_length(size_t headroom, size_t payload, size_t tailroom) {
5412 return check_length(check_length(headroom, payload) + check_length(tailroom));
5413}
5414
5415inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
5416
5417inline void exception_thunk::capture() noexcept {
5418 assert(is_clean());
5419 captured_ = ::std::current_exception();
5420}
5421
5422inline void exception_thunk::rethrow_captured() const {
5423 if (captured_)
5424 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
5425}
5426
5427//------------------------------------------------------------------------------
5428
5429MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept
5430 : code_(error_code) {}
5431
5432inline error &error::operator=(MDBX_error_t error_code) noexcept {
5433 code_ = error_code;
5434 return *this;
5435}
5436
5437MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept {
5438 return a.code_ == b.code_;
5439}
5440
5441MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept {
5442 return !(a == b);
5443}
5444
5445MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept {
5446 return code_ == MDBX_SUCCESS;
5447}
5448
5449MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept {
5450 return code_ == MDBX_RESULT_FALSE;
5451}
5452
5453MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept {
5454 return code_ == MDBX_RESULT_TRUE;
5455}
5456
5457MDBX_CXX11_CONSTEXPR bool error::is_failure() const noexcept {
5458 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
5459}
5460
5461MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
5462
5463MDBX_CXX11_CONSTEXPR bool error::is_mdbx_error() const noexcept {
5464 return (code() >= MDBX_FIRST_LMDB_ERRCODE &&
5465 code() <= MDBX_LAST_LMDB_ERRCODE) ||
5466 (code() >= MDBX_FIRST_ADDED_ERRCODE &&
5467 code() <= MDBX_LAST_ADDED_ERRCODE);
5468}
5469
5470inline void error::throw_exception(int error_code) {
5471 const error trouble(static_cast<MDBX_error_t>(error_code));
5472 trouble.throw_exception();
5473}
5474
5475inline void error::throw_on_failure() const {
5476 if (MDBX_UNLIKELY(is_failure()))
5477 MDBX_CXX20_UNLIKELY throw_exception();
5478}
5479
5480inline void error::success_or_throw() const {
5481 if (MDBX_UNLIKELY(!is_success()))
5482 MDBX_CXX20_UNLIKELY throw_exception();
5483}
5484
5485inline void error::success_or_throw(const exception_thunk &thunk) const {
5486 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
5487 if (MDBX_UNLIKELY(!is_success())) {
5488 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean()))
5489 thunk.rethrow_captured();
5490 else throw_exception();
5491 }
5492}
5493
5494inline void error::panic_on_failure(const char *context_where,
5495 const char *func_who) const noexcept {
5496 if (MDBX_UNLIKELY(is_failure()))
5497 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
5498}
5499
5500inline void error::success_or_panic(const char *context_where,
5501 const char *func_who) const noexcept {
5502 if (MDBX_UNLIKELY(!is_success()))
5503 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
5504}
5505
5506inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
5507 if (MDBX_UNLIKELY(ptr == nullptr))
5508 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
5509}
5510
5511inline void error::throw_on_failure(int error_code) {
5512 error rc(static_cast<MDBX_error_t>(error_code));
5513 rc.throw_on_failure();
5514}
5515
5516inline void error::success_or_throw(MDBX_error_t error_code) {
5517 error rc(error_code);
5518 rc.success_or_throw();
5519}
5520
5521inline bool error::boolean_or_throw(int error_code) {
5522 switch (error_code) {
5523 case MDBX_RESULT_FALSE:
5524 return false;
5525 case MDBX_RESULT_TRUE:
5526 return true;
5527 default:
5528 MDBX_CXX20_UNLIKELY throw_exception(error_code);
5529 }
5530}
5531
5532inline void error::success_or_throw(int error_code,
5533 const exception_thunk &thunk) {
5534 error rc(static_cast<MDBX_error_t>(error_code));
5535 rc.success_or_throw(thunk);
5536}
5537
5538inline void error::panic_on_failure(int error_code, const char *context_where,
5539 const char *func_who) noexcept {
5540 error rc(static_cast<MDBX_error_t>(error_code));
5541 rc.panic_on_failure(context_where, func_who);
5542}
5543
5544inline void error::success_or_panic(int error_code, const char *context_where,
5545 const char *func_who) noexcept {
5546 error rc(static_cast<MDBX_error_t>(error_code));
5547 rc.success_or_panic(context_where, func_who);
5548}
5549
5550inline bool error::boolean_or_throw(int error_code,
5551 const exception_thunk &thunk) {
5552 if (MDBX_UNLIKELY(!thunk.is_clean()))
5553 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
5554 return boolean_or_throw(error_code);
5555}
5556
5557//------------------------------------------------------------------------------
5558
5559MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
5560
5561MDBX_CXX14_CONSTEXPR slice::slice(const void *ptr, size_t bytes)
5562 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
5563
5564MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
5565 : slice(begin, static_cast<const byte *>(end) -
5566 static_cast<const byte *>(begin)) {}
5567
5569 : slice(c_str, ::mdbx::strlen(c_str)) {}
5570
5572 : slice(src.iov_base, src.iov_len) {}
5573
5575 src.iov_base = nullptr;
5576}
5577
5579 src.invalidate();
5580}
5581
5582inline slice &slice::assign(const void *ptr, size_t bytes) {
5583 iov_base = const_cast<void *>(ptr);
5584 iov_len = check_length(bytes);
5585 return *this;
5586}
5587
5588inline slice &slice::assign(const slice &src) noexcept {
5589 iov_base = src.iov_base;
5590 iov_len = src.iov_len;
5591 return *this;
5592}
5593
5594inline slice &slice::assign(const ::MDBX_val &src) {
5595 return assign(src.iov_base, src.iov_len);
5596}
5597
5598slice &slice::assign(slice &&src) noexcept {
5599 assign(src);
5600 src.invalidate();
5601 return *this;
5602}
5603
5605 assign(src.iov_base, src.iov_len);
5606 src.iov_base = nullptr;
5607 return *this;
5608}
5609
5610inline slice &slice::assign(const void *begin, const void *end) {
5611 return assign(begin, static_cast<const byte *>(end) -
5612 static_cast<const byte *>(begin));
5613}
5614
5615inline slice &slice::assign(const char *c_str) {
5616 return assign(c_str, ::mdbx::strlen(c_str));
5617}
5618
5619inline slice &slice::operator=(slice &&src) noexcept {
5620 return assign(::std::move(src));
5621}
5622
5624 return assign(::std::move(src));
5625}
5626
5627inline void slice::swap(slice &other) noexcept {
5628 const auto temp = *this;
5629 *this = other;
5630 other = temp;
5631}
5632
5633MDBX_CXX11_CONSTEXPR const ::mdbx::byte *slice::byte_ptr() const noexcept {
5634 return static_cast<const byte *>(iov_base);
5635}
5636
5637MDBX_CXX11_CONSTEXPR const ::mdbx::byte *slice::end_byte_ptr() const noexcept {
5638 return byte_ptr() + length();
5639}
5640
5641MDBX_CXX11_CONSTEXPR ::mdbx::byte *slice::byte_ptr() noexcept {
5642 return static_cast<byte *>(iov_base);
5643}
5644
5645MDBX_CXX11_CONSTEXPR ::mdbx::byte *slice::end_byte_ptr() noexcept {
5646 return byte_ptr() + length();
5647}
5648
5649MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept {
5650 return static_cast<const char *>(iov_base);
5651}
5652
5653MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept {
5654 return char_ptr() + length();
5655}
5656
5658 return static_cast<char *>(iov_base);
5659}
5660
5662 return char_ptr() + length();
5663}
5664
5665MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept {
5666 return iov_base;
5667}
5668
5669MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept {
5670 return static_cast<const void *>(end_byte_ptr());
5671}
5672
5673MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
5674
5676 return static_cast<void *>(end_byte_ptr());
5677}
5678
5679MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
5680
5682 iov_len = check_length(bytes);
5683 return *this;
5684}
5685
5687 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
5688 return set_length(static_cast<const char *>(ptr) - char_ptr());
5689}
5690
5691MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept {
5692 return length() == 0;
5693}
5694
5696 return data() == nullptr;
5697}
5698
5699MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
5700
5701MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept {
5702 return !is_null();
5703}
5704
5706
5708 iov_base = nullptr;
5709 iov_len = 0;
5710}
5711
5712inline void slice::remove_prefix(size_t n) noexcept {
5713 assert(n <= size());
5714 iov_base = static_cast<byte *>(iov_base) + n;
5715 iov_len -= n;
5716}
5717
5718inline void slice::safe_remove_prefix(size_t n) {
5719 if (MDBX_UNLIKELY(n > size()))
5722}
5723
5724inline void slice::remove_suffix(size_t n) noexcept {
5725 assert(n <= size());
5726 iov_len -= n;
5727}
5728
5729inline void slice::safe_remove_suffix(size_t n) {
5730 if (MDBX_UNLIKELY(n > size()))
5733}
5734
5736slice::starts_with(const slice &prefix) const noexcept {
5737 return length() >= prefix.length() &&
5738 memcmp(data(), prefix.data(), prefix.length()) == 0;
5739}
5740
5741MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
5742 return length() >= suffix.length() &&
5743 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(),
5744 suffix.length()) == 0;
5745}
5746
5748slice::hash_value() const noexcept {
5749 size_t h = length() * 3977471;
5750 for (size_t i = 0; i < length(); ++i)
5751 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
5752 return h ^ 3863194411 * (h >> 11);
5753}
5754
5755MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
5756 MDBX_CONSTEXPR_ASSERT(n < size());
5757 return byte_ptr()[n];
5758}
5759
5760MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
5761 if (MDBX_UNLIKELY(n >= size()))
5763 return byte_ptr()[n];
5764}
5765
5766MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
5767 MDBX_CONSTEXPR_ASSERT(n <= size());
5768 return slice(data(), n);
5769}
5770
5771MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
5772 MDBX_CONSTEXPR_ASSERT(n <= size());
5773 return slice(char_ptr() + size() - n, n);
5774}
5775
5776MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
5777 MDBX_CONSTEXPR_ASSERT(from + n <= size());
5778 return slice(char_ptr() + from, n);
5779}
5780
5782 if (MDBX_UNLIKELY(n > size()))
5784 return head(n);
5785}
5786
5788 if (MDBX_UNLIKELY(n > size()))
5790 return tail(n);
5791}
5792
5800
5802 const slice &b) noexcept {
5803 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
5804 return diff ? diff
5805 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data())
5806 ? 0
5807 : memcmp(a.data(), b.data(), a.length());
5808}
5809
5810MDBX_CXX14_CONSTEXPR intptr_t
5811slice::compare_lexicographically(const slice &a, const slice &b) noexcept {
5812 const size_t shortest = ::std::min(a.length(), b.length());
5813 if (MDBX_LIKELY(shortest > 0))
5815 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
5816 if (MDBX_LIKELY(diff != 0))
5817 MDBX_CXX20_LIKELY return diff;
5818 }
5819 return intptr_t(a.length()) - intptr_t(b.length());
5820}
5821
5823operator==(const slice &a, const slice &b) noexcept {
5824 return slice::compare_fast(a, b) == 0;
5825}
5826
5828operator<(const slice &a, const slice &b) noexcept {
5829 return slice::compare_lexicographically(a, b) < 0;
5830}
5831
5833operator>(const slice &a, const slice &b) noexcept {
5834 return slice::compare_lexicographically(a, b) > 0;
5835}
5836
5838operator<=(const slice &a, const slice &b) noexcept {
5839 return slice::compare_lexicographically(a, b) <= 0;
5840}
5841
5843operator>=(const slice &a, const slice &b) noexcept {
5844 return slice::compare_lexicographically(a, b) >= 0;
5845}
5846
5848operator!=(const slice &a, const slice &b) noexcept {
5849 return slice::compare_fast(a, b) != 0;
5850}
5851
5852template <class ALLOCATOR>
5853inline string<ALLOCATOR>
5854slice::as_hex_string(bool uppercase, unsigned wrap_width,
5855 const ALLOCATOR &allocator) const {
5856 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(allocator);
5857}
5858
5859template <class ALLOCATOR>
5860inline string<ALLOCATOR>
5861slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &allocator) const {
5862 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(allocator);
5863}
5864
5865template <class ALLOCATOR>
5866inline string<ALLOCATOR>
5867slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &allocator) const {
5868 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(allocator);
5869}
5870
5871template <class ALLOCATOR, class CAPACITY_POLICY>
5873slice::encode_hex(bool uppercase, unsigned wrap_width,
5874 const ALLOCATOR &allocator) const {
5875 return to_hex(*this, uppercase, wrap_width)
5876 .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5877}
5878
5879template <class ALLOCATOR, class CAPACITY_POLICY>
5881slice::encode_base58(unsigned wrap_width, const ALLOCATOR &allocator) const {
5882 return to_base58(*this, wrap_width)
5883 .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5884}
5885
5886template <class ALLOCATOR, class CAPACITY_POLICY>
5888slice::encode_base64(unsigned wrap_width, const ALLOCATOR &allocator) const {
5889 return to_base64(*this, wrap_width)
5890 .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5891}
5892
5893template <class ALLOCATOR, class CAPACITY_POLICY>
5895slice::hex_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5896 return from_hex(*this, ignore_spaces)
5897 .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5898}
5899
5900template <class ALLOCATOR, class CAPACITY_POLICY>
5902slice::base58_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5903 return from_base58(*this, ignore_spaces)
5904 .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5905}
5906
5907template <class ALLOCATOR, class CAPACITY_POLICY>
5909slice::base64_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5910 return from_base64(*this, ignore_spaces)
5911 .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5912}
5913
5915slice::is_hex(bool ignore_spaces) const noexcept {
5916 return !from_hex(*this, ignore_spaces).is_erroneous();
5917}
5918
5920slice::is_base58(bool ignore_spaces) const noexcept {
5921 return !from_base58(*this, ignore_spaces).is_erroneous();
5922}
5923
5925slice::is_base64(bool ignore_spaces) const noexcept {
5926 return !from_base64(*this, ignore_spaces).is_erroneous();
5927}
5928
5929//------------------------------------------------------------------------------
5930
5932 const pair &b) noexcept {
5933 const auto diff = slice::compare_fast(a.key, b.key);
5934 return diff ? diff : slice::compare_fast(a.value, b.value);
5935}
5936
5937MDBX_CXX14_CONSTEXPR intptr_t
5938pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5939 const auto diff = slice::compare_lexicographically(a.key, b.key);
5940 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5941}
5942
5944operator==(const pair &a, const pair &b) noexcept {
5945 return a.key.length() == b.key.length() &&
5946 a.value.length() == b.value.length() &&
5947 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5948 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5949}
5950
5952operator<(const pair &a, const pair &b) noexcept {
5953 return pair::compare_lexicographically(a, b) < 0;
5954}
5955
5957operator>(const pair &a, const pair &b) noexcept {
5958 return pair::compare_lexicographically(a, b) > 0;
5959}
5960
5962operator<=(const pair &a, const pair &b) noexcept {
5963 return pair::compare_lexicographically(a, b) <= 0;
5964}
5965
5967operator>=(const pair &a, const pair &b) noexcept {
5968 return pair::compare_lexicographically(a, b) >= 0;
5969}
5970
5972operator!=(const pair &a, const pair &b) noexcept {
5973 return a.key.length() != b.key.length() ||
5974 a.value.length() != b.value.length() ||
5975 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5976 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5977}
5978
5979//------------------------------------------------------------------------------
5980
5981template <class ALLOCATOR, typename CAPACITY_POLICY>
5983 const txn &txn, const struct slice &src, const allocator_type &allocator)
5984 : buffer(src, !txn.is_dirty(src.data()), allocator) {}
5985
5986//------------------------------------------------------------------------------
5987
5991
5994 return ::mdbx::key_mode(flags & (MDBX_REVERSEKEY | MDBX_INTEGERKEY));
5995}
5996
5999 return ::mdbx::value_mode(flags & (MDBX_DUPSORT | MDBX_REVERSEDUP |
6001}
6002
6003//------------------------------------------------------------------------------
6004
6005MDBX_CXX11_CONSTEXPR env::env(MDBX_env *ptr) noexcept : handle_(ptr) {}
6006
6007inline env &env::operator=(env &&other) noexcept {
6008 handle_ = other.handle_;
6009 other.handle_ = nullptr;
6010 return *this;
6011}
6012
6013inline env::env(env &&other) noexcept : handle_(other.handle_) {
6014 other.handle_ = nullptr;
6015}
6016
6017inline env::~env() noexcept {
6018#ifndef NDEBUG
6019 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
6020#endif
6021}
6022
6023MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept {
6024 return handle_ != nullptr;
6025}
6026
6027MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
6028
6029MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
6030
6031MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept {
6032 return a.handle_ == b.handle_;
6033}
6034
6035MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept {
6036 return a.handle_ != b.handle_;
6037}
6038
6040 size_lower = size_now = size_upper = size;
6041 growth_step = shrink_threshold = 0;
6042 return *this;
6043}
6044
6046 intptr_t upper) noexcept {
6047 size_now = size_lower = lower;
6048 size_upper = upper;
6049 growth_step = shrink_threshold = default_value;
6050 return *this;
6051}
6052
6057
6062
6063inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
6064
6065inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
6066
6067inline size_t env::limits::dbsize_min(intptr_t pagesize) {
6068 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
6069 if (result < 0)
6070 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6071 return static_cast<size_t>(result);
6072}
6073
6074inline size_t env::limits::dbsize_max(intptr_t pagesize) {
6075 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
6076 if (result < 0)
6077 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6078 return static_cast<size_t>(result);
6079}
6080
6082 return (flags & MDBX_INTEGERKEY) ? 4 : 0;
6083}
6084
6085inline size_t env::limits::key_min(key_mode mode) noexcept {
6086 return key_min(MDBX_db_flags_t(mode));
6087}
6088
6089inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
6090 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
6091 if (result < 0)
6092 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6093 return static_cast<size_t>(result);
6094}
6095
6096inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
6097 return key_max(pagesize, MDBX_db_flags_t(mode));
6098}
6099
6101 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
6102 if (result < 0)
6103 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6104 return static_cast<size_t>(result);
6105}
6106
6107inline size_t env::limits::key_max(const env &env, key_mode mode) {
6108 return key_max(env, MDBX_db_flags_t(mode));
6109}
6110
6112 return (flags & MDBX_INTEGERDUP) ? 4 : 0;
6113}
6114
6115inline size_t env::limits::value_min(value_mode mode) noexcept {
6116 return value_min(MDBX_db_flags_t(mode));
6117}
6118
6119inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
6120 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
6121 if (result < 0)
6122 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6123 return static_cast<size_t>(result);
6124}
6125
6126inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
6127 return value_max(pagesize, MDBX_db_flags_t(mode));
6128}
6129
6131 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
6132 if (result < 0)
6133 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6134 return static_cast<size_t>(result);
6135}
6136
6138 return value_max(env, MDBX_db_flags_t(mode));
6139}
6140
6141inline size_t env::limits::pairsize4page_max(intptr_t pagesize,
6143 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
6144 if (result < 0)
6145 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6146 return static_cast<size_t>(result);
6147}
6148
6149inline size_t env::limits::pairsize4page_max(intptr_t pagesize,
6150 value_mode mode) {
6151 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
6152}
6153
6156 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
6157 if (result < 0)
6158 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6159 return static_cast<size_t>(result);
6160}
6161
6163 return pairsize4page_max(env, MDBX_db_flags_t(mode));
6164}
6165
6166inline size_t env::limits::valsize4page_max(intptr_t pagesize,
6168 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
6169 if (result < 0)
6170 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6171 return static_cast<size_t>(result);
6172}
6173
6174inline size_t env::limits::valsize4page_max(intptr_t pagesize,
6175 value_mode mode) {
6176 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
6177}
6178
6181 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
6182 if (result < 0)
6183 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6184 return static_cast<size_t>(result);
6185}
6186
6188 return valsize4page_max(env, MDBX_db_flags_t(mode));
6189}
6190
6191inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
6192 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
6193 if (result < 0)
6194 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6195 return static_cast<size_t>(result);
6196}
6197
6198inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
6199
6201 const auto flags = get_flags();
6202 return operate_parameters(max_maps(), max_readers(),
6203 operate_parameters::mode_from_flags(flags),
6204 operate_parameters::durability_from_flags(flags),
6205 operate_parameters::reclaiming_from_flags(flags),
6206 operate_parameters::options_from_flags(flags));
6207}
6208
6209inline env::mode env::get_mode() const {
6210 return operate_parameters::mode_from_flags(get_flags());
6211}
6212
6216
6220
6224
6225inline env::stat env::get_stat() const {
6226 env::stat r;
6227 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
6228 return r;
6229}
6230
6231inline env::stat env::get_stat(const txn &txn) const {
6232 env::stat r;
6233 error::success_or_throw(::mdbx_env_stat_ex(handle_, txn, &r, sizeof(r)));
6234 return r;
6235}
6236
6237inline env::info env::get_info() const {
6238 env::info r;
6239 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
6240 return r;
6241}
6242
6243inline env::info env::get_info(const txn &txn) const {
6244 env::info r;
6245 error::success_or_throw(::mdbx_env_info_ex(handle_, txn, &r, sizeof(r)));
6246 return r;
6247}
6248
6250 filehandle fd;
6252 return fd;
6253}
6254
6256 unsigned bits = 0;
6258 return MDBX_env_flags_t(bits);
6259}
6260
6261inline unsigned env::max_readers() const {
6262 unsigned r;
6264 return r;
6265}
6266
6267inline unsigned env::max_maps() const {
6268 unsigned r;
6270 return r;
6271}
6272
6273inline void *env::get_context() const noexcept {
6274 return mdbx_env_get_userctx(handle_);
6275}
6276
6277inline env &env::set_context(void *ptr) {
6279 return *this;
6280}
6281
6282inline env &env::set_sync_threshold(size_t bytes) {
6284 return *this;
6285}
6286
6287inline size_t env::sync_threshold() const {
6288 size_t bytes;
6290 return bytes;
6291}
6292
6293inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
6294 error::success_or_throw(::mdbx_env_set_syncperiod(handle_, seconds_16dot16));
6295 return *this;
6296}
6297
6298inline unsigned env::sync_period__seconds_16dot16() const {
6299 unsigned seconds_16dot16;
6300 error::success_or_throw(::mdbx_env_get_syncperiod(handle_, &seconds_16dot16));
6301 return seconds_16dot16;
6302}
6303
6305 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
6306}
6307
6309 return sync_period__seconds_16dot16() / 65536.0;
6310}
6311
6312#if __cplusplus >= 201103L
6313inline env &env::set_sync_period(const duration &period) {
6314 return set_sync_period__seconds_16dot16(period.count());
6315}
6316
6317inline duration env::sync_period() const {
6318 return duration(sync_period__seconds_16dot16());
6319}
6320#endif
6321
6323 uint64_t value) {
6325 ::mdbx_env_set_option(handle_, ::MDBX_option_t(option), value));
6326 return *this;
6327}
6328
6329inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
6330 uint64_t value;
6332 ::mdbx_env_get_option(handle_, ::MDBX_option_t(option), &value));
6333 return value;
6334}
6335
6338 return *this;
6339}
6340
6341inline env &env::set_geometry(const geometry &geo) {
6343 handle_, geo.size_lower, geo.size_now, geo.size_upper, geo.growth_step,
6344 geo.shrink_threshold, geo.pagesize));
6345 return *this;
6346}
6347
6348inline bool env::sync_to_disk(bool force, bool nonblock) {
6349 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
6350 switch (err) {
6351 case MDBX_SUCCESS /* flush done */:
6352 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
6353 return true;
6354 case MDBX_BUSY /* the environment is used by other thread */:
6355 return false;
6356 default:
6357 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6358 }
6359}
6360
6361inline void env::close_map(const map_handle &handle) {
6363}
6364
6367 uint64_t txnid, uint64_t lag, size_t used,
6368 size_t retained) noexcept
6369 : slot(slot), pid(pid), thread(thread), transaction_id(txnid),
6370 transaction_lag(lag), bytes_used(used), bytes_retained(retained) {}
6371
6372template <typename VISITOR>
6373inline int env::enumerate_readers(VISITOR &visitor) {
6374 struct reader_visitor_thunk : public exception_thunk {
6375 VISITOR &visitor_;
6376 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid,
6377 mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
6378 size_t retained) noexcept {
6379 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
6380 assert(thunk->is_clean());
6381 try {
6382 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
6383 return loop_control(thunk->visitor_(info, number));
6384 } catch (... /* capture any exception to rethrow it over C code */) {
6385 thunk->capture();
6386 return loop_control::exit_loop;
6387 }
6388 }
6389 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept
6390 : visitor_(visitor) {}
6391 };
6392 reader_visitor_thunk thunk(visitor);
6393 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
6394 thunk.rethrow_captured();
6395 return rc;
6396}
6397
6398inline unsigned env::check_readers() {
6399 int dead_count;
6400 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
6401 assert(dead_count >= 0);
6402 return static_cast<unsigned>(dead_count);
6403}
6404
6407 return *this;
6408}
6409
6411 return ::mdbx_env_get_hsr(handle_);
6412}
6413
6415 ::MDBX_txn *ptr;
6417 ::mdbx_txn_begin(handle_, nullptr, MDBX_TXN_RDONLY, &ptr));
6418 assert(ptr != nullptr);
6419 return txn_managed(ptr);
6420}
6421
6423 ::MDBX_txn *ptr;
6425 ::mdbx_txn_begin(handle_, nullptr, MDBX_TXN_RDONLY_PREPARE, &ptr));
6426 assert(ptr != nullptr);
6427 return txn_managed(ptr);
6428}
6429
6430inline txn_managed env::start_write(bool dont_wait) {
6431 ::MDBX_txn *ptr;
6433 handle_, nullptr, dont_wait ? MDBX_TXN_TRY : MDBX_TXN_READWRITE, &ptr));
6434 assert(ptr != nullptr);
6435 return txn_managed(ptr);
6436}
6437
6439 ::MDBX_txn *ptr;
6441 ::mdbx_txn_begin(handle_, parent, MDBX_TXN_READWRITE, &ptr));
6442 assert(ptr != nullptr);
6443 return txn_managed(ptr);
6444}
6445
6446inline txn_managed env::try_start_write() { return start_write(true); }
6447
6448//------------------------------------------------------------------------------
6449
6450MDBX_CXX11_CONSTEXPR txn::txn(MDBX_txn *ptr) noexcept : handle_(ptr) {}
6451
6452inline txn &txn::operator=(txn &&other) noexcept {
6453 handle_ = other.handle_;
6454 other.handle_ = nullptr;
6455 return *this;
6456}
6457
6458inline txn::txn(txn &&other) noexcept : handle_(other.handle_) {
6459 other.handle_ = nullptr;
6460}
6461
6462inline txn::~txn() noexcept {
6463#ifndef NDEBUG
6464 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
6465#endif
6466}
6467
6468MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept {
6469 return handle_ != nullptr;
6470}
6471
6472MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
6473
6474MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
6475
6476MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept {
6477 return a.handle_ == b.handle_;
6478}
6479
6480MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept {
6481 return a.handle_ != b.handle_;
6482}
6483
6484inline void *txn::get_context() const noexcept {
6485 return mdbx_txn_get_userctx(handle_);
6486}
6487
6488inline txn &txn::set_context(void *ptr) {
6490 return *this;
6491}
6492
6493inline bool txn::is_dirty(const void *ptr) const {
6494 int err = ::mdbx_is_dirty(handle_, ptr);
6495 switch (err) {
6496 default:
6497 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6498 case MDBX_RESULT_TRUE:
6499 return true;
6500 case MDBX_RESULT_FALSE:
6501 return false;
6502 }
6503}
6504
6505inline ::mdbx::env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
6506
6508 const int bits = mdbx_txn_flags(handle_);
6510 return static_cast<MDBX_txn_flags_t>(bits);
6511}
6512
6513inline uint64_t txn::id() const {
6514 const uint64_t txnid = mdbx_txn_id(handle_);
6516 return txnid;
6517}
6518
6522
6526
6527inline void txn::park_reading(bool autounpark) {
6528 error::success_or_throw(::mdbx_txn_park(handle_, autounpark));
6529}
6530
6531inline bool txn::unpark_reading(bool restart_if_ousted) {
6532 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
6533}
6534
6535inline txn::info txn::get_info(bool scan_reader_lock_table) const {
6536 txn::info r;
6537 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
6538 return r;
6539}
6540
6542 MDBX_cursor *ptr;
6543 error::success_or_throw(::mdbx_cursor_open(handle_, map.dbi, &ptr));
6544 return cursor_managed(ptr);
6545}
6546
6547inline size_t txn::release_all_cursors(bool unbind) const {
6548 int err = ::mdbx_txn_release_all_cursors(handle_, unbind);
6549 if (MDBX_UNLIKELY(err < 0))
6550 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6551 return size_t(err);
6552}
6553
6554inline ::mdbx::map_handle
6555txn::open_map(const ::mdbx::slice &name, const ::mdbx::key_mode key_mode,
6556 const ::mdbx::value_mode value_mode) const {
6560 &map.dbi));
6561 assert(map.dbi != 0);
6562 return map;
6563}
6564
6565inline ::mdbx::map_handle
6566txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
6567 const ::mdbx::value_mode value_mode) const {
6571 &map.dbi));
6572 assert(map.dbi != 0);
6573 return map;
6574}
6575
6576inline ::mdbx::map_handle
6577txn::open_map_accede(const ::mdbx::slice &name) const {
6580 ::mdbx_dbi_open2(handle_, name, MDBX_DB_ACCEDE, &map.dbi));
6581 assert(map.dbi != 0);
6582 return map;
6583}
6584
6585inline ::mdbx::map_handle txn::open_map_accede(const char *name) const {
6588 ::mdbx_dbi_open(handle_, name, MDBX_DB_ACCEDE, &map.dbi));
6589 assert(map.dbi != 0);
6590 return map;
6591}
6592
6593inline ::mdbx::map_handle txn::create_map(const ::mdbx::slice &name,
6594 const ::mdbx::key_mode key_mode,
6595 const ::mdbx::value_mode value_mode) {
6598 handle_, name,
6600 &map.dbi));
6601 assert(map.dbi != 0);
6602 return map;
6603}
6604
6605inline ::mdbx::map_handle txn::create_map(const char *name,
6606 const ::mdbx::key_mode key_mode,
6607 const ::mdbx::value_mode value_mode) {
6610 handle_, name,
6612 &map.dbi));
6613 assert(map.dbi != 0);
6614 return map;
6615}
6616
6617inline void txn::drop_map(map_handle map) {
6618 error::success_or_throw(::mdbx_drop(handle_, map.dbi, true));
6619}
6620
6621inline void txn::clear_map(map_handle map) {
6622 error::success_or_throw(::mdbx_drop(handle_, map.dbi, false));
6623}
6624
6625inline void txn::rename_map(map_handle map, const char *new_name) {
6626 error::success_or_throw(::mdbx_dbi_rename(handle_, map, new_name));
6627}
6628
6629inline void txn::rename_map(map_handle map, const ::mdbx::slice &new_name) {
6630 error::success_or_throw(::mdbx_dbi_rename2(handle_, map, new_name));
6631}
6632
6633inline ::mdbx::map_handle
6634txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
6635 const ::mdbx::value_mode value_mode) const {
6636 return open_map(::mdbx::slice(name), key_mode, value_mode);
6637}
6638
6639inline ::mdbx::map_handle
6640txn::open_map_accede(const ::std::string &name) const {
6641 return open_map_accede(::mdbx::slice(name));
6642}
6643
6644inline ::mdbx::map_handle txn::create_map(const ::std::string &name,
6645 const ::mdbx::key_mode key_mode,
6646 const ::mdbx::value_mode value_mode) {
6647 return create_map(::mdbx::slice(name), key_mode, value_mode);
6648}
6649
6650inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
6651 return drop_map(::mdbx::slice(name), throw_if_absent);
6652}
6653
6654inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
6655 return clear_map(::mdbx::slice(name), throw_if_absent);
6656}
6657
6658inline void txn::rename_map(map_handle map, const ::std::string &new_name) {
6659 return rename_map(map, ::mdbx::slice(new_name));
6660}
6661
6663 txn::map_stat r;
6664 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
6665 return r;
6666}
6667
6668inline uint32_t txn::get_tree_deepmask(map_handle map) const {
6669 uint32_t r;
6671 return r;
6672}
6673
6680
6683 return *this;
6684}
6685
6687 txn::canary r;
6689 return r;
6690}
6691
6692inline uint64_t txn::sequence(map_handle map) const {
6693 uint64_t result;
6694 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, 0));
6695 return result;
6696}
6697
6698inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
6699 uint64_t result;
6701 ::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
6702 return result;
6703}
6704
6705inline int txn::compare_keys(map_handle map, const slice &a,
6706 const slice &b) const noexcept {
6707 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
6708}
6709
6710inline int txn::compare_values(map_handle map, const slice &a,
6711 const slice &b) const noexcept {
6712 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
6713}
6714
6715inline int txn::compare_keys(map_handle map, const pair &a,
6716 const pair &b) const noexcept {
6717 return compare_keys(map, a.key, b.key);
6718}
6719
6720inline int txn::compare_values(map_handle map, const pair &a,
6721 const pair &b) const noexcept {
6722 return compare_values(map, a.value, b.value);
6723}
6724
6725inline slice txn::get(map_handle map, const slice &key) const {
6726 slice result;
6727 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
6728 return result;
6729}
6730
6731inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
6732 slice result;
6734 ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
6735 return result;
6736}
6737
6738inline slice txn::get(map_handle map, const slice &key,
6739 const slice &value_at_absence) const {
6740 slice result;
6741 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
6742 switch (err) {
6743 case MDBX_SUCCESS:
6744 return result;
6745 case MDBX_NOTFOUND:
6746 return value_at_absence;
6747 default:
6748 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6749 }
6750}
6751
6752inline slice txn::get(map_handle map, slice key, size_t &values_count,
6753 const slice &value_at_absence) const {
6754 slice result;
6755 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
6756 switch (err) {
6757 case MDBX_SUCCESS:
6758 return result;
6759 case MDBX_NOTFOUND:
6760 return value_at_absence;
6761 default:
6762 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6763 }
6764}
6765
6767 const slice &key) const {
6768 pair result(key, slice());
6769 bool exact = !error::boolean_or_throw(
6770 ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
6771 return pair_result(result.key, result.value, exact);
6772}
6773
6774inline pair_result
6776 const slice &value_at_absence) const {
6777 pair result{key, slice()};
6778 const int err =
6779 ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
6780 switch (err) {
6781 case MDBX_SUCCESS:
6782 return pair_result{result.key, result.value, true};
6783 case MDBX_RESULT_TRUE:
6784 return pair_result{result.key, result.value, false};
6785 case MDBX_NOTFOUND:
6786 return pair_result{key, value_at_absence, false};
6787 default:
6788 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6789 }
6790}
6791
6792inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value,
6793 MDBX_put_flags_t flags) noexcept {
6794 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
6795}
6796
6797inline void txn::put(map_handle map, const slice &key, slice value,
6798 put_mode mode) {
6799 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
6800}
6801
6802inline void txn::insert(map_handle map, const slice &key, slice value) {
6804 put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
6806}
6807
6809 slice value) {
6810 const int err =
6811 put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
6813 switch (err) {
6814 case MDBX_SUCCESS:
6815 return value_result{slice(), true};
6816 case MDBX_KEYEXIST:
6817 return value_result{value, false};
6818 default:
6819 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6820 }
6821}
6822
6824 size_t value_length) {
6825 slice result(nullptr, value_length);
6827 put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
6829 return result;
6830}
6831
6833 size_t value_length) {
6834 slice result(nullptr, value_length);
6835 const int err =
6836 put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
6838 switch (err) {
6839 case MDBX_SUCCESS:
6840 return value_result{result, true};
6841 case MDBX_KEYEXIST:
6842 return value_result{result, false};
6843 default:
6844 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6845 }
6846}
6847
6848inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
6849 error::success_or_throw(put(map, key, const_cast<slice *>(&value),
6851}
6852
6854 size_t value_length) {
6855 slice result(nullptr, value_length);
6857 map, key, &result, MDBX_put_flags_t(put_mode::upsert) | MDBX_RESERVE));
6858 return result;
6859}
6860
6861inline void txn::update(map_handle map, const slice &key, const slice &value) {
6862 error::success_or_throw(put(map, key, const_cast<slice *>(&value),
6864}
6865
6866inline bool txn::try_update(map_handle map, const slice &key,
6867 const slice &value) {
6868 const int err = put(map, key, const_cast<slice *>(&value),
6870 switch (err) {
6871 case MDBX_SUCCESS:
6872 return true;
6873 case MDBX_NOTFOUND:
6874 return false;
6875 default:
6876 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6877 }
6878}
6879
6881 size_t value_length) {
6882 slice result(nullptr, value_length);
6884 map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE));
6885 return result;
6886}
6887
6889 size_t value_length) {
6890 slice result(nullptr, value_length);
6891 const int err =
6892 put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6893 switch (err) {
6894 case MDBX_SUCCESS:
6895 return value_result{result, true};
6896 case MDBX_NOTFOUND:
6897 return value_result{slice(), false};
6898 default:
6899 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6900 }
6901}
6902
6903inline bool txn::erase(map_handle map, const slice &key) {
6904 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6905 switch (err) {
6906 case MDBX_SUCCESS:
6907 return true;
6908 case MDBX_NOTFOUND:
6909 return false;
6910 default:
6911 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6912 }
6913}
6914
6915inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6916 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
6917 switch (err) {
6918 case MDBX_SUCCESS:
6919 return true;
6920 case MDBX_NOTFOUND:
6921 return false;
6922 default:
6923 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6924 }
6925}
6926
6927inline void txn::replace(map_handle map, const slice &key, slice old_value,
6928 const slice &new_value) {
6930 handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6931 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6932}
6933
6934template <class ALLOCATOR, typename CAPACITY_POLICY>
6938 &allocator) {
6939 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
6940 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, nullptr,
6941 &result.slice_, MDBX_CURRENT,
6942 result, &result),
6943 result);
6944 return result;
6945}
6946
6947template <class ALLOCATOR, typename CAPACITY_POLICY>
6949txn::replace(map_handle map, const slice &key, const slice &new_value,
6951 &allocator) {
6952 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
6954 ::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value),
6955 &result.slice_, MDBX_CURRENT, result, &result),
6956 result);
6957 return result;
6958}
6959
6960template <class ALLOCATOR, typename CAPACITY_POLICY>
6962 map_handle map, const slice &key, slice &new_value,
6964 &allocator) {
6965 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
6967 ::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6968 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6969 result);
6970 return result;
6971}
6972
6973inline void txn::append(map_handle map, const slice &key, const slice &value,
6974 bool multivalue_order_preserved) {
6976 handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6977 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP)
6978 : MDBX_APPEND));
6979}
6980
6981inline size_t txn::put_multiple_samelength(map_handle map, const slice &key,
6982 const size_t value_length,
6983 const void *values_array,
6984 size_t values_count, put_mode mode,
6985 bool allow_partial) {
6986 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length},
6987 {nullptr, values_count}};
6988 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args,
6990 switch (err) {
6991 case MDBX_SUCCESS:
6992 MDBX_CXX20_LIKELY break;
6993 case MDBX_KEYEXIST:
6994 if (allow_partial)
6995 break;
6996 mdbx_txn_break(handle_);
6997 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6998 default:
6999 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7000 }
7001 return args[1].iov_len /* done item count */;
7002}
7003
7004inline ptrdiff_t txn::estimate(map_handle map, const pair &from,
7005 const pair &to) const {
7006 ptrdiff_t result;
7008 handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
7009 return result;
7010}
7011
7012inline ptrdiff_t txn::estimate(map_handle map, const slice &from,
7013 const slice &to) const {
7014 ptrdiff_t result;
7015 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr,
7016 &to, nullptr, &result));
7017 return result;
7018}
7019
7021 const slice &to) const {
7022 ptrdiff_t result;
7023 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr,
7024 nullptr, &to, nullptr, &result));
7025 return result;
7026}
7027
7029 const slice &from) const {
7030 ptrdiff_t result;
7031 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr,
7032 nullptr, nullptr, &result));
7033 return result;
7034}
7035
7036//------------------------------------------------------------------------------
7037
7038MDBX_CXX11_CONSTEXPR cursor::cursor(MDBX_cursor *ptr) noexcept : handle_(ptr) {}
7039
7040inline cursor_managed cursor::clone(void *your_context) const {
7041 cursor_managed clone(your_context);
7043 return clone;
7044}
7045
7046inline void *cursor::get_context() const noexcept {
7047 return mdbx_cursor_get_userctx(handle_);
7048}
7049
7050inline cursor &cursor::set_context(void *ptr) {
7052 return *this;
7053}
7054
7055inline cursor &cursor::operator=(cursor &&other) noexcept {
7056 handle_ = other.handle_;
7057 other.handle_ = nullptr;
7058 return *this;
7059}
7060
7061inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) {
7062 other.handle_ = nullptr;
7063}
7064
7065inline cursor::~cursor() noexcept {
7066#ifndef NDEBUG
7067 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
7068#endif
7069}
7070
7071MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept {
7072 return handle_ != nullptr;
7073}
7074
7075MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const {
7076 return handle_;
7077}
7078
7079MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
7080
7082 const cursor &b) noexcept {
7083 return a.handle_ == b.handle_;
7084}
7085
7087 const cursor &b) noexcept {
7088 return a.handle_ != b.handle_;
7089}
7090
7091inline int compare_position_nothrow(const cursor &left, const cursor &right,
7092 bool ignore_nested = false) noexcept {
7093 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
7094}
7095
7096inline int compare_position(const cursor &left, const cursor &right,
7097 bool ignore_nested = false) {
7098 const auto diff = compare_position_nothrow(left, right, ignore_nested);
7099 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
7100 if (MDBX_LIKELY(int16_t(diff) == diff))
7101 MDBX_CXX20_LIKELY return int(diff);
7102 else
7104}
7105
7107 bool throw_notfound)
7108 : pair_result() {
7109 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
7110}
7111
7113 move_operation operation,
7114 const slice &key, const slice &value,
7115 bool throw_notfound)
7116 : pair_result(key, value, false) {
7117 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
7118}
7119
7120inline bool cursor::move(move_operation operation, MDBX_val *key,
7121 MDBX_val *value, bool throw_notfound) const {
7122 const int err =
7123 ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
7124 switch (err) {
7125 case MDBX_SUCCESS:
7126 MDBX_CXX20_LIKELY return true;
7127 case MDBX_RESULT_TRUE:
7128 return false;
7129 case MDBX_NOTFOUND:
7130 if (!throw_notfound)
7131 return false;
7132 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
7133 default:
7134 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7135 }
7136}
7137
7139 move_operation operation,
7140 const slice &key,
7141 const slice &value)
7142 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
7143 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
7144}
7145
7146inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key,
7147 MDBX_val *value) const {
7148 ptrdiff_t result;
7150 *this, key, value, MDBX_cursor_op(operation), &result));
7151 return result;
7152}
7153
7154inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
7155 ptrdiff_t result;
7157 return result;
7158}
7159
7160inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
7161 return move(key_exact, key, throw_notfound);
7162}
7163
7165 bool throw_notfound) {
7166 return move(key_lowerbound, key, throw_notfound);
7167}
7168
7170 bool throw_notfound) {
7171 return move(key_greater_than, key, throw_notfound);
7172}
7173
7175 const slice &value,
7176 bool throw_notfound) {
7177 return move(multi_find_pair, key, value, throw_notfound);
7178}
7179
7181 const slice &value,
7182 bool throw_notfound) {
7183 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
7184}
7185
7187 const slice &value,
7188 bool throw_notfound) {
7189 return move(multi_exactkey_value_greater, key, value, throw_notfound);
7190}
7191
7192inline bool cursor::seek(const slice &key) {
7193 return move(seek_key, const_cast<slice *>(&key), nullptr, false);
7194}
7195
7196inline size_t cursor::count_multivalue() const {
7197 size_t result;
7199 return result;
7200}
7201
7202inline bool cursor::eof() const {
7204}
7205
7206inline bool cursor::on_first() const {
7208}
7209
7210inline bool cursor::on_last() const {
7212}
7213
7217
7218inline bool cursor::on_last_multival() const {
7220}
7221
7223 const slice &value) const {
7224 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
7225}
7226
7228 return estimate_result(*this, key_lowerbound, key);
7229}
7230
7233 return estimate_result(*this, operation);
7234}
7235
7236inline void cursor::renew(const ::mdbx::txn &txn) {
7238}
7239
7244
7248
7249inline txn cursor::txn() const {
7252 return ::mdbx::txn(txn);
7253}
7254
7255inline map_handle cursor::map() const {
7256 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
7257 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
7259 return map_handle(dbi);
7260}
7261
7262inline MDBX_error_t cursor::put(const slice &key, slice *value,
7263 MDBX_put_flags_t flags) noexcept {
7264 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
7265}
7266
7267inline void cursor::put(const slice &key, slice value, put_mode mode) {
7268 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
7269}
7270
7271inline void cursor::insert(const slice &key, slice value) {
7273 put(key, &value /* takes the present value in case MDBX_KEYEXIST */,
7275}
7276
7277inline value_result cursor::try_insert(const slice &key, slice value) {
7278 const int err =
7279 put(key, &value /* takes the present value in case MDBX_KEYEXIST */,
7281 switch (err) {
7282 case MDBX_SUCCESS:
7283 return value_result{slice(), true};
7284 case MDBX_KEYEXIST:
7285 return value_result{value, false};
7286 default:
7287 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7288 }
7289}
7290
7291inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
7292 slice result(nullptr, value_length);
7294 put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
7296 return result;
7297}
7298
7300 size_t value_length) {
7301 slice result(nullptr, value_length);
7302 const int err =
7303 put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
7305 switch (err) {
7306 case MDBX_SUCCESS:
7307 return value_result{result, true};
7308 case MDBX_KEYEXIST:
7309 return value_result{result, false};
7310 default:
7311 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7312 }
7313}
7314
7315inline void cursor::upsert(const slice &key, const slice &value) {
7316 error::success_or_throw(put(key, const_cast<slice *>(&value),
7318}
7319
7320inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
7321 slice result(nullptr, value_length);
7324 return result;
7325}
7326
7327inline void cursor::update(const slice &key, const slice &value) {
7328 error::success_or_throw(put(key, const_cast<slice *>(&value),
7330}
7331
7332inline bool cursor::try_update(const slice &key, const slice &value) {
7333 const int err =
7334 put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
7335 switch (err) {
7336 case MDBX_SUCCESS:
7337 return true;
7338 case MDBX_NOTFOUND:
7339 return false;
7340 default:
7341 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7342 }
7343}
7344
7345inline slice cursor::update_reserve(const slice &key, size_t value_length) {
7346 slice result(nullptr, value_length);
7349 return result;
7350}
7351
7353 size_t value_length) {
7354 slice result(nullptr, value_length);
7355 const int err =
7357 switch (err) {
7358 case MDBX_SUCCESS:
7359 return value_result{result, true};
7360 case MDBX_NOTFOUND:
7361 return value_result{slice(), false};
7362 default:
7363 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7364 }
7365}
7366
7367inline bool cursor::erase(bool whole_multivalue) {
7368 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS
7369 : MDBX_CURRENT);
7370 switch (err) {
7371 case MDBX_SUCCESS:
7372 MDBX_CXX20_LIKELY return true;
7373 case MDBX_NOTFOUND:
7374 return false;
7375 default:
7376 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7377 }
7378}
7379
7380inline bool cursor::erase(const slice &key, bool whole_multivalue) {
7381 bool found = seek(key);
7382 return found ? erase(whole_multivalue) : found;
7383}
7384
7385inline bool cursor::erase(const slice &key, const slice &value) {
7386 move_result data = find_multivalue(key, value, false);
7387 return data.done && erase();
7388}
7389
7391} // namespace mdbx
7392
7393//------------------------------------------------------------------------------
7394
7397namespace std {
7398
7401
7402inline string to_string(const ::mdbx::slice &value) {
7403 ostringstream out;
7404 out << value;
7405 return out.str();
7406}
7407
7408template <class ALLOCATOR, typename CAPACITY_POLICY>
7409inline string
7410to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
7411 ostringstream out;
7412 out << buffer;
7413 return out.str();
7414}
7415
7416inline string to_string(const ::mdbx::pair &value) {
7417 ostringstream out;
7418 out << value;
7419 return out.str();
7420}
7421
7422inline string to_string(const ::mdbx::env::geometry &value) {
7423 ostringstream out;
7424 out << value;
7425 return out.str();
7426}
7427
7428inline string to_string(const ::mdbx::env::operate_parameters &value) {
7429 ostringstream out;
7430 out << value;
7431 return out.str();
7432}
7433
7434inline string to_string(const ::mdbx::env::mode &value) {
7435 ostringstream out;
7436 out << value;
7437 return out.str();
7438}
7439
7440inline string to_string(const ::mdbx::env::durability &value) {
7441 ostringstream out;
7442 out << value;
7443 return out.str();
7444}
7445
7446inline string to_string(const ::mdbx::env::reclaiming_options &value) {
7447 ostringstream out;
7448 out << value;
7449 return out.str();
7450}
7451
7452inline string to_string(const ::mdbx::env::operate_options &value) {
7453 ostringstream out;
7454 out << value;
7455 return out.str();
7456}
7457
7458inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
7459 ostringstream out;
7460 out << value;
7461 return out.str();
7462}
7463
7464inline string to_string(const ::MDBX_log_level_t &value) {
7465 ostringstream out;
7466 out << value;
7467 return out.str();
7468}
7469
7470inline string to_string(const ::MDBX_debug_flags_t &value) {
7471 ostringstream out;
7472 out << value;
7473 return out.str();
7474}
7475
7476inline string to_string(const ::mdbx::error &value) {
7477 ostringstream out;
7478 out << value;
7479 return out.str();
7480}
7481
7482inline string to_string(const ::MDBX_error_t &errcode) {
7483 return to_string(::mdbx::error(errcode));
7484}
7485
7486template <> struct hash<::mdbx::slice> {
7488 operator()(::mdbx::slice const &slice) const noexcept {
7489 return slice.hash_value();
7490 }
7491};
7492
7494} // namespace std
7495
7496#if defined(__LCC__) && __LCC__ >= 126
7497#pragma diagnostic pop
7498#endif
7499
7500#ifdef _MSC_VER
7501#pragma warning(pop)
7502#endif
Definition mdbx.h++:651
Definition mdbx.h++:641
Definition mdbx.h++:661
#define MDBX_CXX11_CONSTEXPR
Definition mdbx.h:454
#define MDBX_MAYBE_UNUSED
Definition mdbx.h:530
#define MDBX_CXX14_CONSTEXPR
Definition mdbx.h:476
#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:5178
#define LIBMDBX_API
Definition mdbx.h:638
#define LIBMDBX_API_TYPE
Definition mdbx.h:653
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:810
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:742
int mdbx_filehandle_t
Definition mdbx.h:171
pid_t mdbx_pid_t
Definition mdbx.h:172
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:824
@ MDBX_MAXDATASIZE
Definition mdbx.h:818
@ MDBX_MAX_DBI
Definition mdbx.h:815
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:821
libmdbx build information
Definition mdbx.h:680
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4526
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4182
Information about the environment.
Definition mdbx.h:2866
Statistics for a table in the environment.
Definition mdbx.h:2818
Information about the transaction.
Definition mdbx.h:4080
libmdbx version information
Definition mdbx.h:663
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:1686
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:4586
LIBMDBX_API int mdbx_cursor_scan_from(MDBX_cursor *cursor, MDBX_predicate_func *predicate, void *context, MDBX_cursor_op from_op, MDBX_val *from_key, MDBX_val *from_value, MDBX_cursor_op turn_op, void *arg)
LIBMDBX_API int mdbx_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_count(const MDBX_cursor *cursor, size_t *pcount)
Return count of duplicates for current 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:1723
@ MDBX_ALLDUPS
Definition mdbx.h:1706
@ MDBX_CURRENT
Definition mdbx.h:1701
@ MDBX_APPENDDUP
Definition mdbx.h:1719
@ MDBX_APPEND
Definition mdbx.h:1714
@ MDBX_UPSERT
Definition mdbx.h:1688
@ MDBX_RESERVE
Definition mdbx.h:1710
@ MDBX_NOOVERWRITE
Definition mdbx.h:1691
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:1763
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:772
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:1778
@ MDBX_GET_BOTH
Definition mdbx.h:1771
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1858
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1775
@ MDBX_SET_KEY
Definition mdbx.h:1818
@ MDBX_FIRST_DUP
Definition mdbx.h:1768
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1857
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1783
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1868
@ MDBX_NEXT_NODUP
Definition mdbx.h:1803
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1865
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1866
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1871
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1825
@ MDBX_SET_RANGE
Definition mdbx.h:1821
@ MDBX_LAST_DUP
Definition mdbx.h:1789
@ MDBX_PREV
Definition mdbx.h:1806
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1873
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1874
@ MDBX_LAST
Definition mdbx.h:1786
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1856
@ MDBX_PREV_DUP
Definition mdbx.h:1809
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1864
@ MDBX_SET
Definition mdbx.h:1815
@ MDBX_NEXT
Definition mdbx.h:1792
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1859
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1870
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1800
@ MDBX_PREV_NODUP
Definition mdbx.h:1812
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1872
@ MDBX_NEXT_DUP
Definition mdbx.h:1795
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1867
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1860
@ MDBX_FIRST
Definition mdbx.h:1765
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:765
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1636
@ MDBX_INTEGERDUP
Definition mdbx.h:1660
@ MDBX_DB_ACCEDE
Definition mdbx.h:1678
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1638
@ MDBX_REVERSEKEY
Definition mdbx.h:1641
@ MDBX_DUPFIXED
Definition mdbx.h:1655
@ MDBX_INTEGERKEY
Definition mdbx.h:1651
@ MDBX_REVERSEDUP
Definition mdbx.h:1663
@ MDBX_CREATE
Definition mdbx.h:1666
@ MDBX_DUPSORT
Definition mdbx.h:1644
MDBX_log_level_t
Definition mdbx.h:885
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:942
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:6358
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1882
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1896
@ MDBX_BAD_TXN
Definition mdbx.h:1962
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1976
@ MDBX_SUCCESS
Definition mdbx.h:1884
@ MDBX_NOTFOUND
Definition mdbx.h:1899
@ MDBX_RESULT_TRUE
Definition mdbx.h:1890
@ MDBX_BUSY
Definition mdbx.h:1980
@ MDBX_EINVAL
Definition mdbx.h:2054
@ MDBX_ENOMEM
Definition mdbx.h:2056
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1983
@ MDBX_RESULT_FALSE
Definition mdbx.h:1887
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:2033
@ MDBX_KEYEXIST
Definition mdbx.h:1893
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:2590
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2584
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2587
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1076
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:3118
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2158
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:3057
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:2262
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2258
@ 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:2362
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2167
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2329
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2190
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2294
@ 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:2317
@ 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:2230
@ 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:2217
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2184
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2278
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2196
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2244
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2357
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:3774
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:3138
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:3075
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:4872
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:3819
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:1537
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:4047
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:753
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:1548
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1557
@ MDBX_TXN_READWRITE
Definition mdbx.h:1542
@ MDBX_TXN_TRY
Definition mdbx.h:1563
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++:2721
buffer(size_t head_room, const struct slice &src, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2421
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++:2203
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:5277
~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++:4078
static buffer key_from(silo &&src) noexcept
Definition mdbx.h++:3092
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:4315
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2241
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2322
constexpr allocator_type get_allocator() const
Returns the associated allocator.
Definition mdbx.h++:2188
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:4536
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++:2666
::MDBX_db_flags_t flags
Definition mdbx.h++:3532
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++:2599
int64_t as_int64_adapt() const
Definition mdbx.h++:2522
constexpr ::std::basic_string< CHAR, T, A > as_string(const A &allocator=A()) const
Definition mdbx.h++:2812
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5111
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:5188
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++:2592
static buffer key_from(const double *ieee754_64bit)
Definition mdbx.h++:3104
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++:2561
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++:2260
constexpr byte & operator[](size_t n) noexcept
Accesses the specified byte of data chunk.
Definition mdbx.h++:2870
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2255
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2735
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2648
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++:2224
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2701
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2663
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2249
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:3525
durability
Durability level.
Definition mdbx.h++:3689
@ lazy_weak_tail
Definition mdbx.h++:3692
@ robust_synchronous
Definition mdbx.h++:3690
@ half_synchronous_weak_last
Definition mdbx.h++:3691
constexpr buffer(const buffer &src, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2380
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1682
constexpr byte operator[](size_t n) const noexcept
Accesses the specified byte of data chunk.
Definition mdbx.h++:2863
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++:2618
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2291
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2978
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++:2366
constexpr int32_t as_int32() const
Definition mdbx.h++:2507
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2286
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2674
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2682
buffer & operator=(const buffer &src)
Definition mdbx.h++:2755
estimate_result estimate(move_operation operation, slice &key) const
uint16_t as_uint16_adapt() const
Definition mdbx.h++:2516
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:3003
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++:2217
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5141
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++:2859
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from the data chunk.
Definition mdbx.h++:2855
bool is_readwrite() const
Checks whether the transaction is read-write.
Definition mdbx.h++:4378
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++:5041
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2281
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:3087
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++:5133
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++:2642
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++:2936
uint8_t as_uint8_adapt() const
Definition mdbx.h++:2517
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5145
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++:2584
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++:2796
env & copy(filehandle fd, bool compactify, bool force_dynamic_size=false)
Copy an environment to the specified file descriptor.
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1678
buffer(size_t head_room, const buffer &src, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2430
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2730
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++:2508
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:3124
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++:2552
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:3526
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:5238
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:5065
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++:5056
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:3132
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++:4851
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:4423
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++:2528
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:4650
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5097
constexpr bool empty() const noexcept
Checks whether the string is empty.
Definition mdbx.h++:2786
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4843
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:2468
buffer(const buffer &src, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2346
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4847
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++:2609
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2768
uint32_t as_uint32_adapt() const
Definition mdbx.h++:2515
buffer(size_t head_room, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2408
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:3096
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from the data chunk.
Definition mdbx.h++:2851
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++:4528
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2709
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3794
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:5074
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2696
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++:2838
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++:2569
MDBX_txn * handle_
Definition mdbx.h++:4340
bool starts_with(const struct slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:2824
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2306
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:3108
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:5037
mode
Operation mode.
Definition mdbx.h++:3681
@ write_mapped_io
Definition mdbx.h++:3684
@ readonly
Definition mdbx.h++:3682
@ write_file_io
Definition mdbx.h++:3683
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:5034
constexpr byte at(size_t n) const
Accesses the specified byte of data chunk with bounds checking.
Definition mdbx.h++:2877
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4983
operator::mdbx::txn() const
Definition mdbx.h++:5219
constexpr int8_t as_int8() const
Definition mdbx.h++:2509
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2974
MDBX_env * handle_
Definition mdbx.h++:3574
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:3076
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5121
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:3001
commit_latency commit_get_latency()
Commit all the operations of a transaction into the database and return latency information.
Definition mdbx.h++:4794
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++:2537
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4838
bool ends_with(const struct slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:2830
constexpr POD as_pod() const
Definition mdbx.h++:2481
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:3128
buffer(const struct slice &src, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2339
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:2465
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:5050
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++:2626
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:5080
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2761
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2384
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++:2390
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2970
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++:5094
constexpr txn_managed() noexcept=default
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2715
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++:2195
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:3136
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2402
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:3036
move_result next_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:5184
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++:4702
cursor_managed & operator=(const cursor_managed &)=delete
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1683
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3926
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:3120
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4952
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:5059
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2763
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2945
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:3024
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2983
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:5009
uint128_t as_uint128_adapt() const
Definition mdbx.h++:2512
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:5287
::MDBX_dbi_state_t state
Definition mdbx.h++:3533
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:2469
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:4135
constexpr uint32_t as_uint32() const
Definition mdbx.h++:2493
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++:4789
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++:3890
constexpr size_t hash_value() const noexcept
Returns the hash value of the data.
Definition mdbx.h++:2805
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5137
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++:3148
move_result get_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:5180
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5084
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:5077
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:5220
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3886
move_result get_multiple_samelength(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5175
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++:2575
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2476
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:3140
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from the data chunk.
Definition mdbx.h++:2847
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++:4420
static buffer key_from(const uint32_t unsigned_int32)
Definition mdbx.h++:3144
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2668
move_result to_key_greater_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5101
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:2461
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3969
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2330
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:4641
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++:2705
buffer(const char *c_str, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2359
constexpr buffer(const struct slice &src, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2374
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4723
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++:3901
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++:4518
int32_t as_int32_adapt() const
Definition mdbx.h++:2523
buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2692
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++:4712
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2267
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++:2350
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2932
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++:2988
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++:2881
move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5153
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2275
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4862
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4877
@ seek_key
Definition mdbx.h++:4879
@ key_lowerbound
Definition mdbx.h++:4881
@ key_greater_than
Definition mdbx.h++:4888
@ multi_find_pair
Definition mdbx.h++:4876
@ key_exact
Definition mdbx.h++:4880
@ get_current
Definition mdbx.h++:4867
@ multi_exactkey_value_greater
Definition mdbx.h++:4898
virtual ~env_managed() noexcept
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:5045
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:3069
void insert(const pair &kv)
Definition mdbx.h++:5241
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2924
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++:5245
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:5062
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2843
int16_t as_int16_adapt() const
Definition mdbx.h++:2524
txn_managed & operator=(const txn_managed &)=delete
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:3152
constexpr size_t operator()(::mdbx::slice const &slice) const noexcept
Definition mdbx.h++:7488
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2835
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++:2544
constexpr int64_t as_int64() const
Definition mdbx.h++:2506
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:4541
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5117
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:2458
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++:3100
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2229
move_result to_current_last_multi(bool throw_notfound=true)
Definition mdbx.h++:5071
value_result try_insert(const pair &kv)
Definition mdbx.h++:5242
constexpr uint128_t as_uint128() const
Definition mdbx.h++:2486
constexpr cursor() noexcept=default
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5087
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:3116
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2234
constexpr const struct slice & slice() const noexcept
Definition mdbx.h++:2440
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5149
uint64_t as_uint64_adapt() const
Definition mdbx.h++:2514
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3896
MDBX_cursor * handle_
Definition mdbx.h++:4810
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2993
~cursor_managed() noexcept
Definition mdbx.h++:5299
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:3013
constexpr uint8_t as_uint8() const
Definition mdbx.h++:2499
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2437
MDBX_dbi dbi
Definition mdbx.h++:3524
buffer(const ::std::basic_string< CHAR, T, A > &&)=delete
constexpr uint64_t as_uint64() const
Definition mdbx.h++:2490
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5106
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:3112
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:5068
constexpr int128_t as_int128() const
Definition mdbx.h++:2502
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:3050
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++:2965
constexpr uint16_t as_uint16() const
Definition mdbx.h++:2496
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:4386
constexpr bool is_null() const noexcept
Checks whether the data pointer of the buffer is nullptr.
Definition mdbx.h++:2791
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2757
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++:5127
txn_managed(const txn_managed &)=delete
constexpr ::std::span< char > chars()
Definition mdbx.h++:2472
static buffer clone(const buffer &src, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2687
buffer(size_t capacity, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2415
constexpr buffer(const ::std::span< POD > &span)
Definition mdbx.h++:2450
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3892
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2299
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:4647
buffer & append_producer(PRODUCER &producer)
Definition mdbx.h++:2950
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:4644
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2958
int128_t as_int128_adapt() const
Definition mdbx.h++:2520
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++:3082
bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:4549
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5091
move_result to_previous(bool throw_notfound=true)
Definition mdbx.h++:5053
constexpr buffer(const char *c_str, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2395
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3888
int8_t as_int8_adapt() const
Definition mdbx.h++:2525
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:2210
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:4390
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2314
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++:2634
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4977
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1674
Unmanaged cursor.
Definition mdbx.h++:4808
Managed cursor.
Definition mdbx.h++:5268
Unmanaged database environment.
Definition mdbx.h++:3570
Managed database environment.
Definition mdbx.h++:4246
Unmanaged database transaction.
Definition mdbx.h++:4337
Managed database transaction.
Definition mdbx.h++:4745
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++:6081
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5931
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:5686
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:5699
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:5787
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++:5881
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++:6405
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:6484
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++:6119
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5801
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++:6927
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:3423
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:5669
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:5993
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:5781
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:6519
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:5649
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:5500
void rethrow_captured() const
Definition mdbx.h++:5422
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:5665
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:7174
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:7146
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++:6605
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:6074
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:382
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6888
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6832
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:6361
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++:6282
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:7106
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:5441
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:5695
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:7020
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:5724
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:5582
env & operator=(env &&other) noexcept
Definition mdbx.h++:6007
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:7245
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6823
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++:5854
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:6625
void throw_on_failure() const
Definition mdbx.h++:5475
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:7332
void update(const slice &key, const slice &value)
Definition mdbx.h++:7327
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:5988
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++:6705
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:5681
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:6488
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:6438
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:6213
uint64_t sequence(map_handle map) const
Definition mdbx.h++:6692
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:7315
bool is_clean() const noexcept
Definition mdbx.h++:5415
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++:5861
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:388
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:3413
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:5521
void swap(slice &other) noexcept
Definition mdbx.h++:5627
::mdbx_filehandle_t filehandle
Definition mdbx.h++:413
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:6200
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++:7240
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:3417
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:6255
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:6067
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:5771
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:5345
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++:6366
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5833
void insert(const slice &key, slice value)
Definition mdbx.h++:7271
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:7180
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:3401
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++:6410
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:5559
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:7040
~cursor() noexcept
Definition mdbx.h++:7065
~txn() noexcept
Definition mdbx.h++:6462
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:6287
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:7169
constexpr void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition mdbx.h++:5705
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:7249
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7299
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:6059
map_handle map() const
Definition mdbx.h++:7255
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++:6298
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:5998
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:7160
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:7186
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:3496
void success_or_throw() const
Definition mdbx.h++:5480
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++:5888
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:6523
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++:5909
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:5741
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:6348
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:7096
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:5437
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:7196
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:5736
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:6065
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:5748
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:6493
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7320
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:6209
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:3409
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:6505
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++:6668
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6866
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:5718
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:3547
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7291
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++:6141
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++:6293
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:7004
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:6217
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:6617
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:7028
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++:6973
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5828
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:6221
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++:6936
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:6527
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:7050
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:6662
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:7120
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++:6111
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++:6710
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:6053
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++:5873
cursor & operator=(cursor &&other) noexcept
Definition mdbx.h++:7055
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:6681
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6853
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++:5895
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:5766
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:7402
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++:6304
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:5793
bool on_first() const
Definition mdbx.h++:7206
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:411
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:5691
bool eof() const
Definition mdbx.h++:7202
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:7091
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:6507
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:6273
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:7262
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:6585
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:6422
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:5729
bool seek(const slice &key)
Definition mdbx.h++:7192
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:6336
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:6277
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:5755
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++:6191
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:6621
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++:6322
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5925
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:5712
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:7277
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:5506
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++:5867
put_mode
Key-value pairs put mode.
Definition mdbx.h++:3555
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5938
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++:6308
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:5637
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++:6166
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:6686
txn & operator=(txn &&other) noexcept
Definition mdbx.h++:6452
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:7367
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++:6961
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:6225
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:6513
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:6808
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5843
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:7154
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5811
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6880
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5920
~env() noexcept
Definition mdbx.h++:6017
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:3382
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:6725
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:5707
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++:6981
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6861
geometry & make_dynamic(intptr_t lower=minimal_value, intptr_t upper=maximal_value) noexcept
Definition mdbx.h++:6045
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:5760
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:5633
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:3385
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:6414
bool on_last_multival() const
Definition mdbx.h++:7218
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:6267
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:6802
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:459
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:6261
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++:6089
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:6373
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:7046
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:6198
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:6541
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:3405
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:6531
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:6329
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:5348
char8_t byte
Definition mdbx.h++:340
bool on_first_multival() const
Definition mdbx.h++:7214
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6792
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:5494
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:5776
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:6237
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6848
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:6063
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5838
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7345
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:7164
::MDBX_cmp_func * comparator
Definition mdbx.h++:3546
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:5679
polymorphic_allocator default_allocator
Definition mdbx.h++:389
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:6398
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:6903
bool on_last() const
Definition mdbx.h++:7210
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:436
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++:5902
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:6249
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:6341
map_handle::info get_handle_info(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:6674
void renew(const ::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:7236
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:6039
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:6547
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7352
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++:6566
::mdbx::filesystem::path path
Definition mdbx.h++:440
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:6446
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5915
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:6535
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++:6766
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:5653
@ upsert
Insert or update.
Definition mdbx.h++:3557
@ update
Update existing, don't insert new.
Definition mdbx.h++:3558
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:3556
@ continue_loop
Definition mdbx.h++:3382
@ exit_loop
Definition mdbx.h++:3382
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:3523
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:769
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:790
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:737
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:1598
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++:1382
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:727
const slice source
Definition mdbx.h++:1468
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++:820
int8_t as_int8_adapt() const
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1162
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1440
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:841
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1161
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:3345
constexpr int64_t as_int64() const
Definition mdbx.h++:1170
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++:1434
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:978
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++:1589
constexpr int16_t as_int16() const
Definition mdbx.h++:1172
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:1638
slice value
Definition mdbx.h++:3218
::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++:3358
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1404
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:3320
slice value
Definition mdbx.h++:3234
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:3296
::std::ostream & output(::std::ostream &out) const
Output hexadecimal dump of passed slice to the std::ostream.
pair_result(const pair_result &) noexcept=default
const slice source
Definition mdbx.h++:1578
const slice source
Definition mdbx.h++:1363
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++:1557
buffer_pair_spec(const txn &txn, const pair &pair, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:3338
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:1551
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:809
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++:3352
constexpr POD as_pod() const
Definition mdbx.h++:1142
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++:3277
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++:1665
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1156
uint16_t as_uint16_adapt() const
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1366
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++:1488
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:3323
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:836
std::pair< slice, slice > stl_pair
Definition mdbx.h++:3233
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:756
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:1374
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1580
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:3316
buffer_type key
Definition mdbx.h++:3297
constexpr int8_t as_int8() const
Definition mdbx.h++:1173
constexpr ::std::span< char > chars()
Definition mdbx.h++:773
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1192
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1494
static constexpr size_t round(const size_t value)
Definition mdbx.h++:1329
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1458
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++:1654
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:3220
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1616
const slice source
Definition mdbx.h++:1414
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:3237
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:770
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1629
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++:1408
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++:1543
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:745
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++:1605
buffer_pair_spec(const txn &txn, const slice &key, const slice &value, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:3335
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:816
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++:848
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1568
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:703
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:1479
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:3279
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1535
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:3304
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++:3248
bool done
Definition mdbx.h++:3276
::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++:1462
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:3331
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:766
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:795
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:1647
void make_freestanding()
Makes buffers owning the data.
Definition mdbx.h++:3364
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1471
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++:1138
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++:1166
slice key
Definition mdbx.h++:3234
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:3235
const slice source
Definition mdbx.h++:1627
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++:1425
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1512
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:3294
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++:1340
constexpr int32_t as_int32() const
Definition mdbx.h++:1171
int64_t as_int64_adapt() const
buffer_pair_spec(const stl_pair &pair, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:3313
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Definition mdbx.h++:864
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1163
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:3295
constexpr operator::std::basic_string() const
Definition mdbx.h++:872
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1160
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++:3328
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++:3342
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++:780
int16_t as_int16_adapt() const
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:3293
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++:1516
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++:1417
buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:3307
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:784
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++:1388
bool done
Definition mdbx.h++:3219
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++:1533
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &allocator=ALLOCATOR())
Definition mdbx.h++:3160
inline ::std::ostream & operator<<(::std::ostream &out, const to_hex &wrapper)
Definition mdbx.h++:1519
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &allocator=ALLOCATOR())
Definition mdbx.h++:3188
ImmutableByteProducer C++20 concept.
MutableByteProducer C++20 concept.
Definition mdbx.h++:3291
Definition mdbx.h++:1322
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1577
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1626
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1532
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:3232
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:3275
References a data located outside the slice.
Definition mdbx.h++:698
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1413
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1467
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1362
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:3217
fatal(exception &&src) noexcept
Definition mdbx.h++:569
fatal(const ::mdbx::error &) noexcept
exception(const exception &)=default
void throw_exception() const
fatal(const exception &src) noexcept
Definition mdbx.h++:568
exception(exception &&)=default
error(const error &)=default
virtual ~fatal() noexcept
fatal & operator=(fatal &&)=default
fatal(const fatal &src) noexcept
Definition mdbx.h++:570
exception & operator=(exception &&)=default
error & operator=(error &&)=default
fatal(fatal &&src) noexcept
Definition mdbx.h++:571
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++:484
Base class for all libmdbx's exceptions that are corresponds to libmdbx errors.
Definition mdbx.h++:547
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:469
Fatal exception that lead termination anyway in dangerous unrecoverable cases.
Definition mdbx.h++:563
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:577
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++:582
Definition mdbx.h++:583
Definition mdbx.h++:584
Definition mdbx.h++:611
Definition mdbx.h++:585
Definition mdbx.h++:586
Definition mdbx.h++:587
Definition mdbx.h++:588
Definition mdbx.h++:589
Definition mdbx.h++:590
Definition mdbx.h++:591
Definition mdbx.h++:610
Definition mdbx.h++:592
Definition mdbx.h++:593
Definition mdbx.h++:594
Definition mdbx.h++:595
Definition mdbx.h++:596
Definition mdbx.h++:597
Definition mdbx.h++:598
Definition mdbx.h++:599
Definition mdbx.h++:613
Definition mdbx.h++:600
Definition mdbx.h++:601
Definition mdbx.h++:602
Definition mdbx.h++:604
Definition mdbx.h++:605
Definition mdbx.h++:606
Definition mdbx.h++:607
Definition mdbx.h++:608
Definition mdbx.h++:612
Definition mdbx.h++:609
uint64_t mdbx_key_from_int64(const int64_t i64)
Definition mdbx.h:4804
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:4808
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition mdbx.h++:182
#define MDBX_CXX17_FALLTHROUGH
Definition mdbx.h++:251
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:293
#define MDBX_LIKELY(cond)
Definition mdbx.h++:221
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:194
#define MDBX_UNLIKELY(cond)
Definition mdbx.h++:231
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:168
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:213
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:240
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:193
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:258
The libmdbx C API header file.
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1200
The libmdbx C++ API namespace.
Definition mdbx.h++:327
STL namespace.
Definition mdbx.h++:1742
constexpr allocated(allocator_pointer ptr, size_t bytes) noexcept
Definition mdbx.h++:1745
constexpr allocated(const allocated &) noexcept=default
constexpr allocated(allocated &&) noexcept=default
allocator_pointer ptr_
Definition mdbx.h++:1743
size_t capacity_bytes_
Definition mdbx.h++:1744
Definition mdbx.h++:4928
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4930
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4929
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4933
Definition mdbx.h++:4912
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++:4917
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4914
Tagged type for output to std::ostream.
Definition mdbx.h++:3623
intptr_t bytes
Definition mdbx.h++:3624
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3625
Database geometry for size management.
Definition mdbx.h++:3599
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++:3669
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3647
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3661
constexpr geometry() noexcept
Definition mdbx.h++:3666
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3651
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3635
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3655
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3630
Definition mdbx.h++:3798
Operate options.
Definition mdbx.h++:3711
constexpr operate_options() noexcept
Definition mdbx.h++:3725
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++:3734
env::operate_options options
Definition mdbx.h++:3744
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++:3748
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++:3743
static env::durability durability_from_flags(MDBX_env_flags_t) noexcept
constexpr operate_parameters() noexcept
Definition mdbx.h++:3746
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:4158
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:4161
uint64_t transaction_lag
Definition mdbx.h++:4164
size_t bytes_used
Definition mdbx.h++:4168
uint64_t transaction_id
Definition mdbx.h++:4162
int slot
The reader lock table slot number.
Definition mdbx.h++:4159
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:4160
size_t bytes_retained
Definition mdbx.h++:4171
Garbage reclaiming options.
Definition mdbx.h++:3697
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++:3702
Additional parameters for creating a new database.
Definition mdbx.h++:4274
constexpr create_parameters() noexcept=default
env::geometry geometry
Definition mdbx.h++:4275
Definition mdbx.h++:3534
map_handle::state state
Definition mdbx.h++:3536
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:3535
info & operator=(const info &) noexcept=default
Definition mdbx.h++:1741
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1780
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1878
constexpr bin & operator=(const bin &ditto) noexcept
Definition mdbx.h++:1853
constexpr bin(size_t capacity_bytes=0) noexcept
Definition mdbx.h++:1825
constexpr byte inplace_lastbyte() const noexcept
Definition mdbx.h++:1773
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1790
constexpr bin(bin &&ditto) noexcept
Definition mdbx.h++:1840
constexpr byte & inplace_lastbyte() noexcept
Definition mdbx.h++:1776
constexpr bin(allocator_pointer ptr, size_t capacity_bytes) noexcept
Definition mdbx.h++:1830
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1898
constexpr ~bin()
Definition mdbx.h++:1835
constexpr const byte * address() const noexcept
Definition mdbx.h++:1889
constexpr byte * make_allocated(allocator_pointer ptr, size_t capacity_bytes) noexcept
Definition mdbx.h++:1810
constexpr byte * address() noexcept
Definition mdbx.h++:1894
constexpr bin & operator=(bin &&ditto) noexcept
Definition mdbx.h++:1871
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1793