libmdbx 0.14.1.177 (2025-12-04T00:18:57+03:00)
One of the fastest compact embeddable key-value ACID storage engine without WAL.
Loading...
Searching...
No Matches
mdbx.h++
Go to the documentation of this file.
1
18
26
27#pragma once
28
29/* Workaround for modern libstdc++ with CLANG < 4.x */
30#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4
31#define __GLIBCXX_BITSIZE_INT_N_0 128
32#define __GLIBCXX_TYPE_INT_N_0 __int128
33#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
34
35#if !defined(__cplusplus) || __cplusplus < 201103L
36#if !defined(_MSC_VER) || _MSC_VER < 1900
37#error "C++11 compiler or better is required"
38#elif _MSC_VER >= 1910
39#error "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
40#endif /* MSVC is mad and don't define __cplusplus properly */
41#endif /* __cplusplus < 201103L */
42
43#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
44#error "CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
45#endif /* Windows */
46
47#ifndef __has_include
48#define __has_include(header) (0)
49#endif /* __has_include */
50
51#if __has_include(<version>)
52#include <version>
53#endif /* <version> */
54
55/* Disable min/max macros from C' headers */
56#ifndef NOMINMAX
57#define NOMINMAX
58#endif
59
60#include <algorithm> // for std::min/max
61#include <cassert> // for assert()
62#include <climits> // for CHAR_BIT
63#include <cstring> // for std::strlen, str:memcmp
64#include <exception> // for std::exception_ptr
65#include <ostream> // for std::ostream
66#include <sstream> // for std::ostringstream
67#include <stdexcept> // for std::invalid_argument
68#include <string> // for std::string
69#include <type_traits> // for std::is_pod<>, etc.
70#include <utility> // for std::make_pair
71#include <vector> // for std::vector<> as template args
72
73#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
74#include <memory_resource>
75#endif
76
77#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
78#include <string_view>
79#endif
80
81#ifndef MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
82#ifdef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
83#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
84#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && __cplusplus >= 201703L
85#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
86#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
87 (defined(_MSC_VER) && defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && __cplusplus >= 201403L))
88#if defined(__cpp_lib_experimental_filesystem) && __cpp_lib_experimental_filesystem >= 201406L
89#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
90#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && __has_include(<experimental/filesystem>)
91#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
92#else
93#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
94#endif
95#else
96#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
97#endif
98#endif /* MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM */
99
100#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
101#include <experimental/filesystem>
102#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
103#include <filesystem>
104#endif
105
106#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
107#include <span>
108#endif
109
110#if !defined(_MSC_VER) || defined(__clang__)
111/* adequate compilers */
112#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) extern template class API_ATTRIBUTES API_TYPENAME
113#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) template class API_TYPENAME
114#else
115/* stupid microsoft showing off */
116#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) extern template class API_TYPENAME
117#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) template class API_ATTRIBUTES API_TYPENAME
118#endif
119
120#if __cplusplus >= 201103L
121#include <chrono>
122#include <ratio>
123#endif
124
125#include "mdbx.h"
126
127#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
128 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
129 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
130 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
131#include <bit>
132#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
133#if 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#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
138#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
139#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
140#define __BYTE_ORDER__ _BYTE_ORDER
141#else
142#define __ORDER_LITTLE_ENDIAN__ 1234
143#define __ORDER_BIG_ENDIAN__ 4321
144#if defined(__LITTLE_ENDIAN__) || (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || defined(__ARMEL__) || \
145 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
146 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || defined(__elbrus_4c__) || defined(__elbrus_8c__) || \
147 defined(__bfin__) || defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
148 defined(__ia64) || defined(_M_IA64) || defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
149 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || defined(__WINDOWS__)
150#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
151#elif defined(__BIG_ENDIAN__) || (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || defined(__ARMEB__) || \
152 defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
153 defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
154 defined(__sparc__) || defined(__sparc) || defined(__370__) || defined(__THW_370__) || defined(__s390__) || \
155 defined(__s390x__) || defined(__SYSC_ZARCH__)
156#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
157#endif
158#endif
159#endif /* Byte Order */
160
162#if defined(DOXYGEN)
163#define MDBX_CXX17_CONSTEXPR constexpr
164#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
165 ((defined(_MSC_VER) && _MSC_VER >= 1915) || (defined(__clang__) && __clang_major__ > 5) || \
166 (defined(__GNUC__) && __GNUC__ > 7) || (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
167#define MDBX_CXX17_CONSTEXPR constexpr
168#else
169#define MDBX_CXX17_CONSTEXPR inline
170#endif /* MDBX_CXX17_CONSTEXPR */
171
173#if defined(DOXYGEN)
174#define MDBX_CXX20_CONSTEXPR constexpr
175#elif defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L && \
176 defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
177#define MDBX_CXX20_CONSTEXPR constexpr
178#else
179#define MDBX_CXX20_CONSTEXPR inline
180#endif /* MDBX_CXX20_CONSTEXPR */
181
182#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
183#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
184#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
185#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
186#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
187#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
188#else
189#define MDBX_CXX01_CONSTEXPR_ENUM inline
190#define MDBX_CXX11_CONSTEXPR_ENUM inline
191#define MDBX_CXX14_CONSTEXPR_ENUM inline
192#define MDBX_CXX17_CONSTEXPR_ENUM inline
193#define MDBX_CXX20_CONSTEXPR_ENUM inline
194#endif /* CONSTEXPR_ENUM_FLAGS_OPERATIONS */
195
197#if defined(CONSTEXPR_ASSERT)
198#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
199#elif defined NDEBUG
200#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
201#else
202#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
203#endif /* MDBX_CONSTEXPR_ASSERT */
204
205#ifndef MDBX_LIKELY
206#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
207#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
208#else
209#define MDBX_LIKELY(x) (x)
210#endif
211#endif /* MDBX_LIKELY */
212
213#ifndef MDBX_UNLIKELY
214#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
215#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
216#else
217#define MDBX_UNLIKELY(x) (x)
218#endif
219#endif /* MDBX_UNLIKELY */
220
222#if defined(DOXYGEN)
223#define MDBX_IF_CONSTEXPR constexpr
224#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
225#define MDBX_IF_CONSTEXPR constexpr
226#else
227#define MDBX_IF_CONSTEXPR
228#endif /* MDBX_IF_CONSTEXPR */
229
230#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
231 __cplusplus >= 201703L
232#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
233#else
234#define MDBX_CXX17_FALLTHROUGH
235#endif /* MDBX_CXX17_FALLTHROUGH */
236
237#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
238#define MDBX_CXX20_LIKELY [[likely]]
239#else
240#define MDBX_CXX20_LIKELY
241#endif /* MDBX_CXX20_LIKELY */
242
243#ifndef MDBX_CXX20_UNLIKELY
244#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
245#define MDBX_CXX20_UNLIKELY [[unlikely]]
246#else
247#define MDBX_CXX20_UNLIKELY
248#endif
249#endif /* MDBX_CXX20_UNLIKELY */
250
251#ifndef MDBX_HAVE_CXX20_CONCEPTS
252#if defined(__cpp_concepts) && __cpp_concepts >= 202002L && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
253#include <concepts>
254#define MDBX_HAVE_CXX20_CONCEPTS 1
255#elif defined(DOXYGEN)
256#define MDBX_HAVE_CXX20_CONCEPTS 1
257#else
258#define MDBX_HAVE_CXX20_CONCEPTS 0
259#endif /* <concepts> */
260#endif /* MDBX_HAVE_CXX20_CONCEPTS */
261
262#ifndef MDBX_CXX20_CONCEPT
263#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
264#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
265#else
266#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
267#endif
268#endif /* MDBX_CXX20_CONCEPT */
269
270#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
271#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
272#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
273#else
274#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
275 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
276#endif
277#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
278
279#ifdef _MSC_VER
280#pragma warning(push, 4)
281#pragma warning(disable : 4127) /* conditional expression is constant */
282#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
283 be used by clients of 'mdbx::BAR' */
284#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
285 base for dll-interface 'mdbx::BAR' */
286/* MSVC is mad and can generate this warning for its own intermediate
287 * automatically generated code, which becomes unreachable after some kinds of
288 * optimization (copy elision, etc). */
289#pragma warning(disable : 4702) /* unreachable code */
290#endif /* _MSC_VER (warnings) */
291
292#if defined(__LCC__) && __LCC__ >= 126
293#pragma diagnostic push
294#if __LCC__ < 127
295#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
296 appearing in a constant expression `true` */
297#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
298 appearing in a constant expression `false` */
299#endif
300#endif /* E2K LCC (warnings) */
301
302//------------------------------------------------------------------------------
305namespace mdbx {
306
309
310// Functions whose signature depends on the `mdbx::byte` type
311// must be strictly defined as inline!
312#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
313// To enable all kinds of an compiler optimizations we use a byte-like type
314// that don't presumes aliases for pointers as does the `char` type and its
315// derivatives/typedefs.
316// Please see https://libmdbx.dqdkfa.ru/dead-github/issues/263
317// for reasoning of the use of `char8_t` type and switching to `__restrict__`.
318using byte = char8_t;
319#else
320// Avoid `std::byte` since it doesn't add features but inconvenient
321// restrictions.
322using byte = unsigned char;
323#endif /* __cpp_char8_t >= 201811*/
324
325#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
326using endian = ::std::endian;
327#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
328enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
329#else
330#error "Please use a C++ compiler provides byte order information or C++20 support"
331#endif /* Byte Order enum */
332
341
343static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
344
346static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
348static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
349
352using legacy_allocator = ::std::string::allocator_type;
353
354#if defined(DOXYGEN) || \
355 (defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI)
357using polymorphic_allocator = ::std::pmr::string::allocator_type;
359#else
361#endif /* __cpp_lib_memory_resource >= 201603L */
362
363struct slice;
365template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy> class buffer;
366class env;
367class env_managed;
368class txn;
369class txn_managed;
370class cursor;
371class cursor_managed;
372
374using txnid = uint64_t;
375
378
380template <class ALLOCATOR = default_allocator>
381using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
382
384#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
385#ifdef _MSC_VER
386namespace filesystem = ::std::experimental::filesystem::v1;
387#else
388namespace filesystem = ::std::experimental::filesystem;
389#endif
390#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
391#elif defined(DOXYGEN) || \
392 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
393 __cpp_lib_string_view >= 201606L && \
394 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
395 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
396 (!defined(_MSC_VER) || __cplusplus >= 201703L)
397namespace filesystem = ::std::filesystem;
403#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
404#endif /* MDBX_STD_FILESYSTEM_PATH */
405
406#ifdef MDBX_STD_FILESYSTEM_PATH
408#elif defined(_WIN32) || defined(_WIN64)
409using path = ::std::wstring;
410#else
411using path = ::std::string;
412#endif /* mdbx::path */
413
414#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
415#ifndef MDBX_U128_TYPE
416#define MDBX_U128_TYPE __uint128_t
417#endif /* MDBX_U128_TYPE */
418#ifndef MDBX_I128_TYPE
419#define MDBX_I128_TYPE __int128_t
420#endif /* MDBX_I128_TYPE */
421#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
422
423#if __cplusplus >= 201103L || defined(DOXYGEN)
425using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
426#endif /* Duration for C++11 */
427
430
436 ::std::exception_ptr captured_;
437
438public:
439 exception_thunk() noexcept = default;
442 exception_thunk &operator=(const exception_thunk &) = delete;
443 exception_thunk &operator=(exception_thunk &&) = delete;
444 inline bool is_clean() const noexcept;
445 inline void capture() noexcept;
446 inline void rethrow_captured() const;
447};
448
451 MDBX_error_t code_;
452 inline error &operator=(MDBX_error_t error_code) noexcept;
453
454public:
455 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
456 error(const error &) = default;
457 error(error &&) = default;
458 error &operator=(const error &) = default;
459 error &operator=(error &&) = default;
460
461 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
462 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
463
464 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
465 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
466 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
467 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
468
470 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
471
473 const char *what() const noexcept;
474
476 ::std::string message() const;
477
479 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
481 [[noreturn]] void panic(const char *context_where_when, const char *func_who_what) const noexcept;
482 [[noreturn]] void throw_exception() const;
483 [[noreturn]] static inline void throw_exception(int error_code);
484 inline void throw_on_failure() const;
485 inline void success_or_throw() const;
486 inline void success_or_throw(const exception_thunk &) const;
487 inline void panic_on_failure(const char *context_where, const char *func_who) const noexcept;
488 inline void success_or_panic(const char *context_where, const char *func_who) const noexcept;
489 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
490 static inline void success_or_throw(MDBX_error_t error_code);
491 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
492 static inline void throw_on_failure(int error_code);
493 static inline bool boolean_or_throw(int error_code);
494 static inline void success_or_throw(int error_code, const exception_thunk &);
495 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
496 static inline void panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept;
497 static inline void success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept;
498};
499
502class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
503 using base = ::std::runtime_error;
504 ::mdbx::error error_;
505
506public:
507 exception(const ::mdbx::error &) noexcept;
508 exception(const exception &) = default;
509 exception(exception &&) = default;
510 exception &operator=(const exception &) = default;
512 virtual ~exception() noexcept;
513 const ::mdbx::error error() const noexcept { return error_; }
514};
515
518 using base = exception;
519
520public:
521 fatal(const ::mdbx::error &) noexcept;
522 fatal(const exception &src) noexcept : fatal(src.error()) {}
523 fatal(exception &&src) noexcept : fatal(src.error()) {}
524 fatal(const fatal &src) noexcept : fatal(src.error()) {}
525 fatal(fatal &&src) noexcept : fatal(src.error()) {}
526 fatal &operator=(fatal &&) = default;
527 fatal &operator=(const fatal &) = default;
528 virtual ~fatal() noexcept;
529};
530
531#define MDBX_DECLARE_EXCEPTION(NAME) \
532 struct LIBMDBX_API_TYPE NAME : public exception { \
533 NAME(const ::mdbx::error &); \
534 virtual ~NAME() noexcept; \
535 }
568#undef MDBX_DECLARE_EXCEPTION
569
572[[noreturn]] LIBMDBX_API void throw_out_range();
576static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes);
577static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload);
578static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom);
579
581
582//------------------------------------------------------------------------------
583
586
587#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
588
592template <typename T>
593concept MutableByteProducer = requires(T a, char array[42]) {
594 { a.is_empty() } -> std::same_as<bool>;
595 { a.envisage_result_length() } -> std::same_as<size_t>;
596 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
597};
598
602template <typename T>
603concept ImmutableByteProducer = requires(const T &a, char array[42]) {
604 { a.is_empty() } -> std::same_as<bool>;
605 { a.envisage_result_length() } -> std::same_as<size_t>;
606 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
607};
608
612template <typename T>
613concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
614 T(source);
615 { a.is_erroneous() } -> std::same_as<bool>;
616};
617
618#endif /* MDBX_HAVE_CXX20_CONCEPTS */
619
620template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy,
621 MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
622inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc = ALLOCATOR());
623
624template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy,
625 MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
626inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc = ALLOCATOR());
627
628template <class ALLOCATOR = default_allocator, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
629inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc = ALLOCATOR());
630
631template <class ALLOCATOR = default_allocator, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
632inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc = ALLOCATOR());
633
645
646 enum : size_t { max_length = MDBX_MAXDATASIZE };
647
649 MDBX_CXX11_CONSTEXPR slice() noexcept;
650
652 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
653
655 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
656
658 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
659 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
660 }
661
662 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
663
666 template <class CHAR, class T, class A>
667 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
668 : slice(str.data(), str.length() * sizeof(CHAR)) {}
669
671 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
673 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
674
675#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
676 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
677 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
678 "Must be a standard layout type!");
679 }
680
681 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
682 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
683 "Must be a standard layout type!");
684 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
686 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
688 }
689
690 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
691 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
692 "Must be a standard layout type!");
693 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
695 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
697 }
698
699 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
700 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
701 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
702 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
703#endif /* __cpp_lib_span >= 202002L */
704
705#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
707 template <class CHAR, class T>
708 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv) : slice(sv.data(), sv.data() + sv.length()) {}
709
710 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
711#endif /* __cpp_lib_string_view >= 201606L */
712
713 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
714
715 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
716 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
717 "Must be a standard layout type!");
718 return slice(&pod, sizeof(pod));
719 }
720
721 inline slice &assign(const void *ptr, size_t bytes);
722 inline slice &assign(const slice &src) noexcept;
723 inline slice &assign(const ::MDBX_val &src);
724 inline slice &assign(slice &&src) noexcept;
725 inline slice &assign(::MDBX_val &&src);
726 inline slice &assign(const void *begin, const void *end);
727 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
728 return assign(str.data(), str.length() * sizeof(CHAR));
729 }
730 inline slice &assign(const char *c_str);
731#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
732 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
733 return assign(view.begin(), view.end());
734 }
735 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
736 assign(view);
737 view = {};
738 return *this;
739 }
740#endif /* __cpp_lib_string_view >= 201606L */
741
742 slice &operator=(const slice &) noexcept = default;
743 inline slice &operator=(slice &&src) noexcept;
744 inline slice &operator=(::MDBX_val &&src);
745 operator MDBX_val *() noexcept { return this; }
746 operator const MDBX_val *() const noexcept { return this; }
747
748#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
749 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
750 return assign(view);
751 }
752
753 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
754
756 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
757 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
758 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
759 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
760 }
761
763 template <class CHAR, class T>
764 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
765 return this->string_view<CHAR, T>();
766 }
767#endif /* __cpp_lib_string_view >= 201606L */
768
769 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
770 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
771 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
772 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
773 }
774
775 template <class CHAR, class T, class ALLOCATOR>
776 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
778 }
779
781 template <class ALLOCATOR = default_allocator>
782 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
783 const ALLOCATOR &alloc = ALLOCATOR()) const;
784
787 template <class ALLOCATOR = default_allocator>
788 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
789
792 template <class ALLOCATOR = default_allocator>
793 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
794
796 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
797 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
798 const ALLOCATOR &alloc = ALLOCATOR()) const;
799
802 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
803 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
804 const ALLOCATOR &alloc = ALLOCATOR()) const;
805
808 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
809 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
810 const ALLOCATOR &alloc = ALLOCATOR()) const;
811
813 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
814 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
815 const ALLOCATOR &alloc = ALLOCATOR()) const;
816
819 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
820 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
821 const ALLOCATOR &alloc = ALLOCATOR()) const;
822
825 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
826 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
827 const ALLOCATOR &alloc = ALLOCATOR()) const;
828
834 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
835
840 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
841
847 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
848
854 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
855
856#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
857 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
858 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
859 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
860 *this = view;
861 view = temp;
862 }
863#endif /* __cpp_lib_string_view >= 201606L */
864
866 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
867 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
868
870 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
871 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
872
874 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
875 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
876
878 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
879 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
880
882 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
883 MDBX_CXX11_CONSTEXPR void *data() noexcept;
884
886 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
887 MDBX_CXX11_CONSTEXPR void *end() noexcept;
888
890 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
891
893 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
894
896 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
897
899 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
900
902 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
903
905 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
906
908 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
909
911 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
912
914 MDBX_CXX14_CONSTEXPR void clear() noexcept;
915
918 inline void remove_prefix(size_t n) noexcept;
919
922 inline void remove_suffix(size_t n) noexcept;
923
926 inline void safe_remove_prefix(size_t n);
927
930 inline void safe_remove_suffix(size_t n);
931
933 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
934
936 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
937
940 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
941
944 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
945
948 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
949
952 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
953
956 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
957
960 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
961
964 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
965
968 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
969
974 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
975
984 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
985
991 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
992 const slice &b) noexcept;
993 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
994 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
995 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
996 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
997 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
998 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
999#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1000 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
1001#endif /* __cpp_impl_three_way_comparison */
1002
1004 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1005
1008 return slice(/* using special constructor without length checking */ ~size_t(0));
1009 }
1010
1012 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1013
1014 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1015 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1016 "Must be a standard layout type!");
1017 if (MDBX_LIKELY(size() == sizeof(POD)))
1019 POD r;
1020 memcpy(&r, data(), sizeof(r));
1021 return r;
1022 }
1024 }
1025
1026#ifdef MDBX_U128_TYPE
1027 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1028#endif /* MDBX_U128_TYPE */
1029 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1030 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1031 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1032 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1033
1034#ifdef MDBX_I128_TYPE
1035 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1036#endif /* MDBX_I128_TYPE */
1037 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1038 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1039 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1040 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1041
1042#ifdef MDBX_U128_TYPE
1043 MDBX_U128_TYPE as_uint128_adapt() const;
1044#endif /* MDBX_U128_TYPE */
1045 uint64_t as_uint64_adapt() const;
1046 uint32_t as_uint32_adapt() const;
1047 uint16_t as_uint16_adapt() const;
1048 uint8_t as_uint8_adapt() const;
1049
1050#ifdef MDBX_I128_TYPE
1051 MDBX_I128_TYPE as_int128_adapt() const;
1052#endif /* MDBX_I128_TYPE */
1053 int64_t as_int64_adapt() const;
1054 int32_t as_int32_adapt() const;
1055 int16_t as_int16_adapt() const;
1056 int8_t as_int8_adapt() const;
1057
1058protected:
1059 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1060};
1061
1062//------------------------------------------------------------------------------
1063
1065
1066template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1067#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1068 return ::std::allocator_traits<A>::is_always_equal::value;
1069#else
1070 return ::std::is_empty<A>::value;
1071#endif /* __cpp_lib_allocator_traits_is_always_equal */
1072}
1073
1074template <typename T, typename A = typename T::allocator_type,
1075 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1077
1078template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1079 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1080 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1081 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1082 }
1083 static MDBX_CXX20_CONSTEXPR void propagate(T *, T &) noexcept {}
1084};
1085
1086template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1087 static constexpr bool is_nothrow() noexcept {
1088 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1089 }
1090 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1091 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1092 target->get_allocator() = ::std::move(source.get_allocator());
1093 }
1094};
1095
1096template <typename T, typename A = typename T::allocator_type,
1097 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1099
1100template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1101 static constexpr bool is_nothrow() noexcept { return false; }
1102 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1103};
1104
1105template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1106 static constexpr bool is_nothrow() noexcept {
1107 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1108 }
1109 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1110 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1111 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1112 MDBX_CXX20_UNLIKELY target->get_allocator() =
1113 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1114 } else {
1115 /* gag for buggy compilers */
1116 (void)target;
1117 (void)source;
1118 }
1119 }
1120};
1121
1122template <typename T, typename A = typename T::allocator_type,
1123 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1125
1126template <typename T, typename A> struct swap_alloc<T, A, false> {
1127 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1128 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1130 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1131 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1132 } else {
1133 /* gag for buggy compilers */
1134 (void)left;
1135 (void)right;
1136 }
1137 }
1138};
1139
1140template <typename T, typename A> struct swap_alloc<T, A, true> {
1141 static constexpr bool is_nothrow() noexcept {
1142 return allocator_is_always_equal<A>() ||
1143#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1144 ::std::is_nothrow_swappable<A>() ||
1145#endif /* __cpp_lib_is_swappable >= 201603L */
1146 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1147 }
1148 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1149 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1150 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1151 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1152 } else {
1153 /* gag for buggy compilers */
1154 (void)left;
1155 (void)right;
1156 }
1157 }
1158};
1159
1160} // namespace allocation_aware_details
1161
1163 enum : size_t {
1168 };
1169
1170 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1171 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1172 static_assert(pettiness_threshold % 2 == 0, "pettiness_threshold must be even");
1173 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1174 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1175 return (value + pettiness_threshold - 1) & pettiness_mask;
1176 }
1177
1178 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1179 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1180 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1181
1182 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1183 return inplace;
1184
1185 if (wanna > current)
1186 /* doubling capacity, but don't made reserve more than max_reserve */
1187 return round(wanna + ::std::min(size_t(max_reserve), current));
1188
1189 if (current - wanna >
1190 /* shrink if reserve will more than half of current or max_reserve,
1191 * but not less than pettiness_threshold */
1192 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1193 return round(wanna);
1194
1195 /* keep unchanged */
1196 return current;
1197 }
1198};
1199
1203 const bool uppercase = false;
1204 const unsigned wrap_width = 0;
1209
1211 template <class ALLOCATOR = default_allocator>
1212 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1213 return make_string<ALLOCATOR>(*this, alloc);
1214 }
1215
1217 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1218 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1219 return make_buffer<ALLOCATOR>(*this, alloc);
1220 }
1221
1225 const size_t bytes = source.length() << 1;
1226 return wrap_width ? bytes + bytes / wrap_width : bytes;
1227 }
1228
1231 char *write_bytes(char *dest, size_t dest_size) const;
1232
1235 ::std::ostream &output(::std::ostream &out) const;
1236
1239 bool is_empty() const noexcept { return source.empty(); }
1240
1243 bool is_erroneous() const noexcept { return false; }
1244};
1245
1250 const unsigned wrap_width = 0;
1255
1258 template <class ALLOCATOR = default_allocator>
1259 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1260 return make_string<ALLOCATOR>(*this, alloc);
1261 }
1262
1265 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1266 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1267 return make_buffer<ALLOCATOR>(*this, alloc);
1268 }
1269
1273 const size_t bytes = (source.length() * 11 + 7) / 8;
1274 return wrap_width ? bytes + bytes / wrap_width : bytes;
1275 }
1276
1279 char *write_bytes(char *dest, size_t dest_size) const;
1280
1283 ::std::ostream &output(::std::ostream &out) const;
1284
1286 bool is_empty() const noexcept { return source.empty(); }
1287
1289 bool is_erroneous() const noexcept { return false; }
1290};
1291
1296 const unsigned wrap_width = 0;
1301
1304 template <class ALLOCATOR = default_allocator>
1305 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1306 return make_string<ALLOCATOR>(*this, alloc);
1307 }
1308
1311 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1312 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1313 return make_buffer<ALLOCATOR>(*this, alloc);
1314 }
1315
1319 const size_t bytes = (source.length() + 2) / 3 * 4;
1320 return wrap_width ? bytes + bytes / wrap_width : bytes;
1321 }
1322
1326 char *write_bytes(char *dest, size_t dest_size) const;
1327
1331 ::std::ostream &output(::std::ostream &out) const;
1332
1335 bool is_empty() const noexcept { return source.empty(); }
1336
1339 bool is_erroneous() const noexcept { return false; }
1340};
1341
1342inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
1343inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
1344inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
1345
1349 const bool ignore_spaces = false;
1354
1356 template <class ALLOCATOR = default_allocator>
1357 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1358 return make_string<ALLOCATOR>(*this, alloc);
1359 }
1360
1362 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1363 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1364 return make_buffer<ALLOCATOR>(*this, alloc);
1365 }
1366
1369 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1370
1373 char *write_bytes(char *dest, size_t dest_size) const;
1374
1376 bool is_empty() const noexcept { return source.empty(); }
1377
1380 bool is_erroneous() const noexcept;
1381};
1382
1387 const bool ignore_spaces = false;
1392
1395 template <class ALLOCATOR = default_allocator>
1396 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1397 return make_string<ALLOCATOR>(*this, alloc);
1398 }
1399
1402 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1403 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1404 return make_buffer<ALLOCATOR>(*this, alloc);
1405 }
1406
1410 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1411 }
1412
1416 char *write_bytes(char *dest, size_t dest_size) const;
1417
1419 bool is_empty() const noexcept { return source.empty(); }
1420
1423 bool is_erroneous() const noexcept;
1424};
1425
1430 const bool ignore_spaces = false;
1435
1438 template <class ALLOCATOR = default_allocator>
1439 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1440 return make_string<ALLOCATOR>(*this, alloc);
1441 }
1442
1445 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1446 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1447 return make_buffer<ALLOCATOR>(*this, alloc);
1448 }
1449
1452 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1453
1457 char *write_bytes(char *dest, size_t dest_size) const;
1458
1461 bool is_empty() const noexcept { return source.empty(); }
1462
1466 bool is_erroneous() const noexcept;
1467};
1468
1470struct buffer_tag {};
1471
1473template <class ALLOCATOR, typename CAPACITY_POLICY> class buffer : public buffer_tag, public slice {
1474public:
1476#if !defined(_MSC_VER) || _MSC_VER > 1900
1477 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1478#else
1479 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1480#endif /* MSVC is mad */
1481 using allocator_traits = ::std::allocator_traits<allocator_type>;
1482 using reservation_policy = CAPACITY_POLICY;
1483 enum : size_t {
1485 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1488 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1489 ? alignof(max_align_t) * 2
1492 };
1493
1494private:
1495 friend class txn;
1496 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1497 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1498 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1499
1500 using allocator_pointer = typename allocator_traits::pointer;
1501 using allocator_const_pointer = typename allocator_traits::const_pointer;
1502
1503 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1504 assert(bytes >= sizeof(bin));
1505 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1506 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1507 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1508 const size_t n = (bytes + unit - 1) / unit;
1509 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1510 }
1511
1512 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1513 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1514 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1515 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1516 }
1517
1518 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1519 const size_t capacity = bin::advise_capacity(0, bytes);
1520 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1521 : allocate_storage(capacity);
1522 }
1523
1524 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1525#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1526 return static_cast<void *>(::std::to_address(ptr));
1527#else
1528 return static_cast<void *>(::std::addressof(*ptr));
1529#endif /* __cpp_lib_to_address */
1530 }
1531
1532 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1533#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1534 return static_cast<const void *>(::std::to_address(ptr));
1535#else
1536 return static_cast<const void *>(::std::addressof(*ptr));
1537#endif /* __cpp_lib_to_address */
1538 }
1539
1540 union alignas(max_align_t) bin {
1541 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1542 с учетом выравнивания */
1543 {
1544 allocator_pointer ptr_;
1546 };
1547
1549 enum : size_t {
1551 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1555 };
1556
1558 byte pad_[inplace_size - sizeof(allocator_pointer)];
1559 size_t bytes_;
1560 };
1561
1563 byte buffer_[inplace_size - sizeof(byte)];
1565 MDBX_CXX11_CONSTEXPR inplace_flag_holder(byte signature) : lastbyte_(signature) {};
1566 };
1567
1568 allocator_pointer allocated_ptr_;
1571
1572 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1573 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1574 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1575 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1576 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1577 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1578 return capacity_bytes <= inplace_capacity();
1579 }
1580
1581 constexpr bool is_inplace() const noexcept {
1582 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1583 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1585 "WTF?");
1586 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1587 }
1588 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1589
1590 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1591 if (destroy_ptr) {
1593 /* properly destroy allocator::pointer */
1594 allocated_ptr_.~allocator_pointer();
1595 }
1598 return address();
1599 }
1600
1601 template <bool construct_ptr>
1602 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1604 if (construct_ptr) {
1606 new (&allocated_ptr_) allocator_pointer(pair.first);
1607 } else {
1609 allocated_ptr_ = pair.first;
1610 }
1611 capacity_.bytes_ = pair.second;
1612 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1613 return address();
1614 }
1615
1617 if (::std::is_trivial<allocator_pointer>::value)
1618 /* workaround for "uninitialized" warning from some compilers */
1619 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1620 }
1621
1622 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1623 if (MDBX_UNLIKELY(wanna > max_capacity))
1624 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1625
1626 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1627 assert(advised >= wanna);
1628 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1629 }
1630
1631 constexpr bool is_inplace(const void *ptr) const noexcept {
1632 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1633 }
1634
1635 constexpr const byte *address() const noexcept {
1636 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1637 }
1639 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1640 }
1641 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1642 } bin_;
1643
1644 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1645
1646 MDBX_CXX20_CONSTEXPR void release() noexcept {
1647 if (bin_.is_allocated()) {
1648 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1649 /* properly destroy allocator::pointer */
1650 bin_.allocated_ptr_.~allocator_pointer();
1651 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1652 }
1653 }
1654
1655 template <bool external_content>
1656 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1657 const void *const content, const size_t length) {
1658 assert(wanna_capacity >= wanna_headroom + length);
1659 const size_t old_capacity = bin_.capacity();
1660 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1661 if (MDBX_LIKELY(new_capacity == old_capacity))
1663 assert(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1664 byte *const new_place = bin_.address() + wanna_headroom;
1665 if (MDBX_LIKELY(length))
1667 if (external_content)
1668 memcpy(new_place, content, length);
1669 else {
1670 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1671 assert(old_capacity >= old_headroom + length);
1672 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1673 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1674 }
1675 }
1676 return new_place;
1677 }
1678
1679 if (bin::is_suitable_for_inplace(new_capacity)) {
1680 assert(bin_.is_allocated());
1681 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1682 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1683 if (MDBX_LIKELY(length))
1684 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1685 deallocate_storage(old_allocated, old_capacity);
1686 return new_place;
1687 }
1688
1689 if (bin_.is_inplace()) {
1690 const auto pair = allocate_storage(new_capacity);
1691 assert(pair.second >= new_capacity);
1692 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1693 if (MDBX_LIKELY(length))
1694 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1695 bin_.template make_allocated<true>(pair);
1696 return new_place;
1697 }
1698
1699 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1700 if (external_content)
1701 deallocate_storage(old_allocated, old_capacity);
1702 const auto pair = allocate_storage(new_capacity);
1703 assert(pair.second >= new_capacity);
1704 byte *const new_place = bin_.template make_allocated<false>(pair) + wanna_headroom;
1705 if (MDBX_LIKELY(length))
1706 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1707 if (!external_content)
1708 deallocate_storage(old_allocated, old_capacity);
1709 return new_place;
1710 }
1711
1712 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1713 assert(capacity() >= offset);
1714 return bin_.address() + offset;
1715 }
1716 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1717 assert(capacity() >= offset);
1718 return bin_.address() + offset;
1719 }
1720 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1721 assert(capacity() >= offset + length);
1722 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1723 }
1724
1725 //--------------------------------------------------------------------------
1726
1727 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1728 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1729 if (!bin::is_suitable_for_inplace(capacity))
1730 bin_.template make_allocated<true>(provide_storage(capacity));
1731 }
1732
1733 silo(silo &&other) = delete;
1735 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1736 : allocator_type(::std::move(other.get_allocator())) {
1737 if (!is_reference) {
1738 if (other.bin_.is_inplace()) {
1739 memcpy(&bin_, &other.bin_, sizeof(bin));
1740 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1741 } else {
1742 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1743 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1744 /* properly destroy allocator::pointer.
1745 *
1746 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1747 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1748 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1749 * from the 11th). */
1750 /* coverity[use_after_move] */
1751 other.bin_.allocated_ptr_.~allocator_pointer();
1752 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1753 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1754 }
1755 }
1756 }
1757
1758 MDBX_CXX17_CONSTEXPR bool move(silo &&other) noexcept {
1759 if (other.bin_.is_inplace()) {
1760 memcpy(&bin_, &other.bin_, sizeof(bin));
1761 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1762 return /* buffer's slice fixup is needed */ true;
1763 }
1764 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1765 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1766 /* properly destroy allocator::pointer.
1767 *
1768 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1769 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1770 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1771 * from the 11th). */
1772 /* coverity[use_after_move] */
1773 other.bin_.allocated_ptr_.~allocator_pointer();
1774 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1775 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1776 return false;
1777 }
1778
1779 MDBX_CXX17_CONSTEXPR bool assign_move(silo &&other, bool is_reference) noexcept {
1780 release();
1781 if (!allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, other))
1782 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, other);
1783 return is_reference ? false : move(std::move(other));
1784 }
1785
1786 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1787 exchange(silo &left, const bool left_is_reference, silo &right, const bool right_is_reference) noexcept(
1788 allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1789 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(left, right);
1790 bool left_need_fixup = false, right_need_fixup = false;
1791 if (left_is_reference || right_is_reference) {
1792 left_need_fixup = !right_is_reference && left.move(std::move(right));
1793 right_need_fixup = !left_is_reference && right.move(std::move(left));
1794 } else {
1795 silo temp(std::move(left), false);
1796 left_need_fixup = left.move(std::move(right));
1797 right_need_fixup = right.move(std::move(temp));
1798 }
1799 return std::make_pair(left_need_fixup, right_need_fixup);
1800 }
1801
1802 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1803 const allocator_type &alloc = allocator_type())
1804 : silo(capacity, alloc) {
1805 assert(capacity >= headroom + length);
1806 if (length)
1807 put(headroom, ptr, length);
1808 }
1809
1810 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1811 : silo(length, 0, ptr, length, alloc) {}
1812
1813 ~silo() { release(); }
1814
1815 //--------------------------------------------------------------------------
1816
1817 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1818 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1819 }
1820
1821 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1822
1823 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1824 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1825 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1826 }
1827
1828 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1829 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1830 }
1831
1832 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1833 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1834 return get(offset);
1835 }
1836 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1837 };
1838
1839 MDBX_CXX14_CONSTEXPR void fixup_import(const typename silo::bin &src) noexcept {
1840 auto ptr = inherited::byte_ptr();
1841 if (src.is_inplace(ptr)) {
1842 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1843 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1844 iov_base = ptr + offset;
1845 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1846 }
1847 }
1848
1849 silo silo_;
1850
1851 void insulate() {
1852 assert(is_reference());
1853 iov_base = silo_.assign(iov_base, iov_len);
1854 }
1855
1856 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1857 return static_cast<const byte *>(silo_.data());
1858 }
1859
1860 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1861 return silo_begin() + silo_.capacity();
1862 }
1863
1864 struct data_preserver : public exception_thunk {
1865 buffer data;
1866 data_preserver(allocator_type &alloc) : data(alloc) {}
1867 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1868 auto self = static_cast<data_preserver *>(context);
1869 assert(self->is_clean());
1870 assert(&self->data == target);
1871 (void)target;
1872 try {
1873 self->data.assign(src, bytes, false);
1874 return MDBX_RESULT_FALSE;
1875 } catch (... /* capture any exception to rethrow it over C code */) {
1876 self->capture();
1877 return MDBX_RESULT_TRUE;
1878 }
1879 }
1880 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1881 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1882 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1883 };
1884
1885public:
1888
1892
1893 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1894
1896 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1897
1901 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1902 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1903 }
1904
1909 return silo_.is_inplace(inherited::data());
1910 }
1911
1915
1918 return is_freestanding() ? silo_.capacity() : 0;
1919 }
1920
1924 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
1925 }
1926
1930 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
1931 }
1932
1934 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
1935
1937 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
1938
1945
1950 return const_cast<byte *>(inherited::end_byte_ptr());
1951 }
1952
1954 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
1955
1957 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
1958
1963 return const_cast<char *>(inherited::char_ptr());
1964 }
1965
1970 return const_cast<char *>(inherited::end_char_ptr());
1971 }
1972
1974 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
1975
1977 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
1978
1981 MDBX_CXX11_CONSTEXPR void *data() noexcept {
1983 return const_cast<void *>(inherited::data());
1984 }
1985
1988 MDBX_CXX11_CONSTEXPR void *end() noexcept {
1990 return const_cast<void *>(inherited::end());
1991 }
1992
1997
2004
2007 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2008 return set_length(static_cast<const char *>(ptr) - char_ptr());
2009 }
2010
2015 if (is_reference())
2016 insulate();
2017 }
2018
2019 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2020 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2021
2023 buffer(const struct slice &src, bool make_reference, const allocator_type &alloc = allocator_type())
2024 : inherited(src), silo_(alloc) {
2025 if (!make_reference)
2026 insulate();
2027 }
2028
2030 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2031 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2032
2033 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2034 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2035
2036 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2037 : buffer(inherited(c_str), make_reference, alloc) {}
2038
2039#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2040 template <class CHAR, class T>
2041 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2042 const allocator_type &alloc = allocator_type())
2043 : buffer(inherited(view), make_reference, alloc) {}
2044#endif /* __cpp_lib_string_view >= 201606L */
2045
2047 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2048 : buffer(src, src.empty() || src.is_null(), alloc) {}
2049
2051 buffer(const buffer &src)
2052 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2053
2055 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2056 : buffer(inherited(ptr, bytes), alloc) {}
2057
2058 template <class CHAR, class T, class A>
2059 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2060 const allocator_type &alloc = allocator_type())
2061 : buffer(inherited(str), alloc) {}
2062
2064 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2065
2066#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2067 template <class CHAR, class T>
2068 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2069 const allocator_type &alloc = allocator_type())
2070 : buffer(inherited(view), alloc) {}
2071#endif /* __cpp_lib_string_view >= 201606L */
2072
2073 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2074 : silo_(check_length(head_room, tail_room), alloc) {
2075 iov_base = silo_.get();
2076 assert(iov_len == 0);
2077 }
2078
2079 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2080 iov_base = silo_.get();
2081 assert(iov_len == 0);
2082 }
2083
2084 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2085 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2086 iov_base = memcpy(silo_.get(), src.data(), iov_len = src.length());
2087 }
2088
2089 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2090
2091 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2092 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2093 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2094 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2095 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2096 * 11th). */
2097 /* coverity[use_after_move] */
2098 fixup_import(src.silo_.bin_);
2099 src.invalidate();
2100 }
2101
2103 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2104
2107
2108 template <typename POD>
2109 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2110 return buffer(inherited::wrap(pod), make_reference, alloc);
2111 }
2112
2114 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2115 const allocator_type &alloc = allocator_type()) {
2116 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2117 }
2118
2121 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2122 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2123 }
2124
2126 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2127 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2128 }
2129
2131 template <typename POD>
2132 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2133 const allocator_type &alloc = allocator_type()) {
2134 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2135 }
2136
2139 template <typename POD>
2140 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2141 return base58(inherited::wrap(pod), wrap_width, alloc);
2142 }
2143
2146 template <typename POD>
2147 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2148 return base64(inherited::wrap(pod), wrap_width, alloc);
2149 }
2150
2152 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2153 const allocator_type &alloc = allocator_type()) const {
2154 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2155 }
2156
2159 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2160 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2161 }
2162
2164 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2165 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2166 }
2167
2169 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2170 const allocator_type &alloc = allocator_type()) {
2171 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2172 }
2173
2176 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2177 const allocator_type &alloc = allocator_type()) {
2178 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2179 }
2180
2183 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2184 const allocator_type &alloc = allocator_type()) {
2185 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2186 }
2187
2190 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2191 return hex_decode(*this, ignore_spaces, alloc);
2192 }
2193
2196 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2197 return base58_decode(*this, ignore_spaces, alloc);
2198 }
2199
2202 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2203 return base64_decode(*this, ignore_spaces, alloc);
2204 }
2205
2207 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2208 wanna_headroom = ::std::min(
2209 ::std::max(headroom(), wanna_headroom),
2210 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2211 wanna_tailroom = ::std::min(
2212 ::std::max(tailroom(), wanna_tailroom),
2213 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2214 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2215 silo_.resize(wanna_capacity, wanna_headroom, *this);
2216 assert(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2217 assert(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2218 }
2219
2221 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2222
2224 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2225
2226 buffer &assign_reference(const void *ptr, size_t bytes) {
2227 silo_.clear();
2229 return *this;
2230 }
2231
2232 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2233 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2234 return *this;
2235 }
2236
2237 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2238 const auto pair = silo::exchange(silo_, is_reference(), other.silo_, other.is_reference());
2239 std::swap(iov_base, other.iov_base);
2240 std::swap(iov_len, other.iov_len);
2241 if (pair.first)
2242 fixup_import(other.silo_.bin_);
2243 if (pair.second)
2244 other.fixup_import(silo_.bin_);
2245 }
2246
2247 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2248 left.swap(right);
2249 }
2250
2251 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2252 return buffer(src.headroom(), src, src.tailroom(), alloc);
2253 }
2254
2256 return buffer(slice(), !is_inplace(), allocator_traits::select_on_container_copy_construction(get_allocator()));
2257 }
2258
2260 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2261 invalidate();
2262 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2263 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2264 MDBX_CXX20_UNLIKELY {
2265 silo_.release();
2267 }
2268 }
2269
2270 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2271 iov_len = src.length();
2272 return *this;
2273 }
2274
2275 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2276 invalidate();
2277 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2278 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2279 MDBX_CXX20_UNLIKELY {
2280 silo_.release();
2282 }
2283 }
2284
2285 if (make_reference) {
2286 silo_.release();
2287 iov_base = src.iov_base;
2288 } else {
2289 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2290 }
2291 iov_len = src.length();
2292 return *this;
2293 }
2294
2297 const bool is_reference = src.is_reference();
2298 inherited::assign(std::move(src));
2299 if (silo_.assign_move(std::move(src.silo_), is_reference))
2300 fixup_import(src.silo_.bin_);
2301 return *this;
2302 }
2303
2304 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2305 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2306 }
2307
2308 buffer &assign(const struct slice &src, bool make_reference = false) {
2309 return assign(src.data(), src.length(), make_reference);
2310 }
2311
2312 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2313 return assign(src.iov_base, src.iov_len, make_reference);
2314 }
2315
2316 buffer &assign(struct slice &&src, bool make_reference = false) {
2317 assign(src.data(), src.length(), make_reference);
2318 src.invalidate();
2319 return *this;
2320 }
2321
2322 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2323 assign(src.iov_base, src.iov_len, make_reference);
2324 src.iov_base = nullptr;
2325 return *this;
2326 }
2327
2328 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2329 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2330 }
2331
2332 template <class CHAR, class T, class A>
2333 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2334 return assign(str.data(), str.length(), make_reference);
2335 }
2336
2337 buffer &assign(const char *c_str, bool make_reference = false) {
2338 return assign(c_str, strlen(c_str), make_reference);
2339 }
2340
2341#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2342 template <class CHAR, class T>
2343 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2344 return assign(view.data(), view.length(), make_reference);
2345 }
2346
2347 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2348 assign(view.data(), view.length(), make_reference);
2349 view = {};
2350 return *this;
2351 }
2352#endif /* __cpp_lib_string_view >= 201606L */
2353
2354 buffer &operator=(const buffer &src) { return assign(src); }
2355
2356 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2357
2358 buffer &operator=(const struct slice &src) { return assign(src); }
2359
2360 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2361
2362#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2363 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2364 return assign(view.begin(), view.length());
2365 }
2366#endif /* __cpp_lib_string_view >= 201606L */
2367
2368 template <class CHAR, class T, class A>
2369 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2370 return as_string<CHAR, T, A>();
2371 }
2372
2374 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2375
2377 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2378 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2379 }
2380
2382 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2383
2384 buffer &append(const void *src, size_t bytes) {
2385 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2386 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2387 memcpy(end_byte_ptr(), src, bytes);
2388 iov_len += bytes;
2389 return *this;
2390 }
2391
2392 buffer &append(const byte c) {
2393 if (MDBX_UNLIKELY(tailroom() < 1))
2394 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2395 *end_byte_ptr() = c;
2396 iov_len += 1;
2397 return *this;
2398 }
2399
2400 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2401
2402 buffer &add_header(const void *src, size_t bytes) {
2403 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2404 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2405 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2406 iov_len += bytes;
2407 return *this;
2408 }
2409
2410 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2411
2412 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2413 const size_t wanna_bytes = producer.envisage_result_length();
2414 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2415 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2416 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2417 }
2418
2419 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2420 const size_t wanna_bytes = producer.envisage_result_length();
2421 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2422 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2423 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2424 }
2425
2426 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2427 return append_producer(to_hex(data, uppercase, wrap_width));
2428 }
2429
2430 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2431 return append_producer(to_base58(data, wrap_width));
2432 }
2433
2434 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2435 return append_producer(to_base64(data, wrap_width));
2436 }
2437
2438 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2439 return append_producer(from_hex(data, ignore_spaces));
2440 }
2441
2442 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2443 return append_producer(from_base58(data, ignore_spaces));
2444 }
2445
2446 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2447 return append_producer(from_base64(data, ignore_spaces));
2448 }
2449
2450 buffer &append_u8(uint_fast8_t u8) {
2451 if (MDBX_UNLIKELY(tailroom() < 1))
2452 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2453 *end_byte_ptr() = uint8_t(u8);
2454 iov_len += 1;
2455 return *this;
2456 }
2457
2458 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2459
2460 buffer &append_u16(uint_fast16_t u16) {
2461 if (MDBX_UNLIKELY(tailroom() < 2))
2462 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2463 const auto ptr = end_byte_ptr();
2464 ptr[0] = uint8_t(u16);
2465 ptr[1] = uint8_t(u16 >> 8);
2466 iov_len += 2;
2467 return *this;
2468 }
2469
2470 buffer &append_u24(uint_fast32_t u24) {
2471 if (MDBX_UNLIKELY(tailroom() < 3))
2472 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2473 const auto ptr = end_byte_ptr();
2474 ptr[0] = uint8_t(u24);
2475 ptr[1] = uint8_t(u24 >> 8);
2476 ptr[2] = uint8_t(u24 >> 16);
2477 iov_len += 3;
2478 return *this;
2479 }
2480
2481 buffer &append_u32(uint_fast32_t u32) {
2482 if (MDBX_UNLIKELY(tailroom() < 4))
2483 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2484 const auto ptr = end_byte_ptr();
2485 ptr[0] = uint8_t(u32);
2486 ptr[1] = uint8_t(u32 >> 8);
2487 ptr[2] = uint8_t(u32 >> 16);
2488 ptr[3] = uint8_t(u32 >> 24);
2489 iov_len += 4;
2490 return *this;
2491 }
2492
2493 buffer &append_u48(uint_fast64_t u48) {
2494 if (MDBX_UNLIKELY(tailroom() < 6))
2495 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2496 const auto ptr = end_byte_ptr();
2497 ptr[0] = uint8_t(u48);
2498 ptr[1] = uint8_t(u48 >> 8);
2499 ptr[2] = uint8_t(u48 >> 16);
2500 ptr[3] = uint8_t(u48 >> 24);
2501 ptr[4] = uint8_t(u48 >> 32);
2502 ptr[5] = uint8_t(u48 >> 40);
2503 iov_len += 6;
2504 return *this;
2505 }
2506
2507 buffer &append_u64(uint_fast64_t u64) {
2508 if (MDBX_UNLIKELY(tailroom() < 8))
2509 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2510 const auto ptr = end_byte_ptr();
2511 ptr[0] = uint8_t(u64);
2512 ptr[1] = uint8_t(u64 >> 8);
2513 ptr[2] = uint8_t(u64 >> 16);
2514 ptr[3] = uint8_t(u64 >> 24);
2515 ptr[4] = uint8_t(u64 >> 32);
2516 ptr[5] = uint8_t(u64 >> 40);
2517 ptr[6] = uint8_t(u64 >> 48);
2518 ptr[7] = uint8_t(u64 >> 56);
2519 iov_len += 8;
2520 return *this;
2521 }
2522
2523 //----------------------------------------------------------------------------
2524
2525 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2526 return buffer(inherited(text), make_reference);
2527 }
2528
2529#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2530 template <class CHAR, class T>
2531 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2532 return buffer(src, make_reference);
2533 }
2534#endif /* __cpp_lib_string_view >= 201606L */
2535
2536 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2537
2538 template <class CHAR, class T, class A>
2539 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2540 return buffer(src, make_reference);
2541 }
2542
2543 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2544
2545 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2546
2547 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2548
2549 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2550
2551 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2552
2553 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2554
2555 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2556
2557 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2558
2559 static buffer key_from_jsonInteger(const int64_t json_integer) {
2560 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2561 }
2562
2563 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2564
2565 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2566
2567 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2568
2569 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2570
2571 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2572
2573 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2574
2575 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2576
2577 const slice &slice() const noexcept { return *this; }
2578};
2579
2580template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2581inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
2582 if (MDBX_LIKELY(!producer.is_empty()))
2584 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
2585 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
2586 return result;
2587 }
2589}
2590
2591template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2592inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
2593 if (MDBX_LIKELY(!producer.is_empty()))
2595 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
2596 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
2597 return result;
2598 }
2600}
2601
2602template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2603inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
2604 string<ALLOCATOR> result(alloc);
2605 if (MDBX_LIKELY(!producer.is_empty()))
2607 result.resize(producer.envisage_result_length());
2608 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
2609 }
2610 return result;
2611}
2612
2613template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2614inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
2615 string<ALLOCATOR> result(alloc);
2616 if (MDBX_LIKELY(!producer.is_empty()))
2618 result.resize(producer.envisage_result_length());
2619 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
2620 }
2621 return result;
2622}
2623
2625
2626#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI
2628#endif /* __cpp_lib_memory_resource >= 201603L */
2629
2633 bool done;
2634 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
2635 value_result(const value_result &) noexcept = default;
2636 value_result &operator=(const value_result &) noexcept = default;
2637 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2638 assert(!done || bool(value));
2639 return done;
2640 }
2641};
2642
2644struct pair {
2645 using stl_pair = std::pair<slice, slice>;
2647 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
2648 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
2649 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
2650 pair(const pair &) noexcept = default;
2651 pair &operator=(const pair &) noexcept = default;
2652 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2653 assert(bool(key) == bool(value));
2654 return key;
2655 }
2657
2659 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
2660
2662 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
2663 const pair &b) noexcept;
2664 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
2665 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
2666 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
2667 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
2668 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
2669 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
2670#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2671 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
2672#endif /* __cpp_impl_three_way_comparison */
2673};
2674
2677struct pair_result : public pair {
2678 bool done;
2681 : pair(key, value), done(done) {}
2682 pair_result(const pair_result &) noexcept = default;
2683 pair_result &operator=(const pair_result &) noexcept = default;
2684 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2685 assert(!done || (bool(key) && bool(value)));
2686 return done;
2687 }
2688};
2689
2690template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2694 using reservation_policy = CAPACITY_POLICY;
2695 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2697
2700 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2701
2703 : key(key, alloc), value(value, alloc) {}
2704 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2705 const allocator_type &alloc = allocator_type())
2706 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2707
2709 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2710 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2711 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2712
2714 : key(key, alloc), value(value, alloc) {}
2715 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2716 const allocator_type &alloc = allocator_type())
2717 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2718
2721 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2722 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2723
2724 buffer_pair_spec(const txn &transacton, const slice &key, const slice &value,
2725 const allocator_type &alloc = allocator_type())
2726 : key(transacton, key, alloc), value(transacton, value, alloc) {}
2727 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2728 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2729
2730 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2731 : key(::std::move(key)), value(::std::move(value)) {}
2732 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2733 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2734
2738 return key.is_freestanding() && value.is_freestanding();
2739 }
2740
2743 return key.is_reference() || value.is_reference();
2744 }
2745
2749 key.make_freestanding();
2750 value.make_freestanding();
2751 }
2752
2753 operator pair() const noexcept { return pair(key, value); }
2754};
2755
2757template <typename BUFFER>
2759
2762
2764
2765//------------------------------------------------------------------------------
2766
2769enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2770
2787
2789 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2790}
2791
2793 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2794}
2795
2797 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2798}
2799
2801 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2802}
2803
2805
2863
2867
2869 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2870}
2871
2873 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2874}
2875
2877 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2878}
2879
2881 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2882}
2883
2885
2896 map_handle(const map_handle &) noexcept = default;
2897 map_handle &operator=(const map_handle &) noexcept = default;
2898 operator bool() const noexcept { return dbi != 0; }
2899 operator MDBX_dbi() const { return dbi; }
2900
2901#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2902 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2903 return a.dbi <=> b.dbi;
2904 }
2905#endif /* __cpp_impl_three_way_comparison */
2906 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2907 return a.dbi == b.dbi;
2908 }
2909 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2910 return a.dbi < b.dbi;
2911 }
2912 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2913 return a.dbi > b.dbi;
2914 }
2915 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2916 return a.dbi <= b.dbi;
2917 }
2918 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2919 return a.dbi >= b.dbi;
2920 }
2921 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2922 return a.dbi != b.dbi;
2923 }
2924
2936};
2937
2940 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2941}
2943 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2944}
2945
2952
2962 friend class txn;
2963
2964protected:
2966 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2967
2968public:
2969 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2970 env(const env &) noexcept = default;
2971 env &operator=(const env &) noexcept = default;
2972 inline env &operator=(env &&) noexcept;
2973 inline env(env &&) noexcept;
2974 inline ~env() noexcept;
2975
2976 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
2977 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
2978 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
2979 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
2980 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
2981
2982 //----------------------------------------------------------------------------
2983
2988
2990 enum : intptr_t {
2993 maximal_value = INTPTR_MAX,
2994 kB = 1000,
2995 MB = kB * 1000,
2996 GB = MB * 1000,
2997#if INTPTR_MAX > 0x7fffFFFFl
2998 TB = GB * 1000,
2999 PB = TB * 1000,
3000 EB = PB * 1000,
3001#endif /* 64-bit intptr_t */
3002 KiB = 1024,
3003 MiB = KiB << 10,
3004 GiB = MiB << 10,
3005#if INTPTR_MAX > 0x7fffFFFFl
3006 TiB = GiB << 10,
3007 PiB = TiB << 10,
3008 EiB = PiB << 10,
3009#endif /* 64-bit intptr_t */
3010 };
3011
3013 struct size {
3014 intptr_t bytes;
3015 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3016 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3017 };
3018
3021
3026
3038
3041
3044
3050
3051 inline geometry &make_fixed(intptr_t size) noexcept;
3052 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3055 geometry(const geometry &) noexcept = default;
3061 };
3062
3070
3078
3091
3113
3118 unsigned max_maps{0};
3121 unsigned max_readers{0};
3126
3137 operate_parameters(const operate_parameters &) noexcept = default;
3139 MDBX_env_flags_t make_flags(bool accede = true,
3142 bool use_subdirectory = false
3143 ) const;
3147 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3148 };
3149
3153 inline env::mode get_mode() const;
3155 inline env::durability get_durability() const;
3159 inline env::operate_options get_options() const;
3160
3163 bool is_pristine() const;
3164
3166 bool is_empty() const;
3167
3169 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3170
3171 struct limits {
3172 limits() = delete;
3174 static inline size_t pagesize_min() noexcept;
3176 static inline size_t pagesize_max() noexcept;
3178 static inline size_t dbsize_min(intptr_t pagesize);
3180 static inline size_t dbsize_max(intptr_t pagesize);
3182 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3184 static inline size_t key_min(key_mode mode) noexcept;
3186 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3188 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3190 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3192 static inline size_t key_max(const env &, key_mode mode);
3194 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3196 static inline size_t value_min(value_mode) noexcept;
3197
3199 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3201 static inline size_t value_max(intptr_t pagesize, value_mode);
3203 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3205 static inline size_t value_max(const env &, value_mode);
3206
3209 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3212 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3215 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3218 static inline size_t pairsize4page_max(const env &, value_mode);
3219
3222 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3225 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3228 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3231 static inline size_t valsize4page_max(const env &, value_mode);
3232
3235 static inline size_t transaction_size_max(intptr_t pagesize);
3236
3238 static inline size_t max_map_handles(void);
3239 };
3240
3242 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3244 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3246 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3248 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3250 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3252 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3256
3259#ifdef MDBX_STD_FILESYSTEM_PATH
3260 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3261#endif /* MDBX_STD_FILESYSTEM_PATH */
3262#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3263 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3264 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3265#endif /* Windows */
3266 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3267 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3268
3270 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3271
3287
3289#ifdef MDBX_STD_FILESYSTEM_PATH
3290 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3291#endif /* MDBX_STD_FILESYSTEM_PATH */
3292#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3293 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3294 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3295#endif /* Windows */
3296 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3297 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3298
3301
3304
3306 inline stat get_stat() const;
3307
3309 size_t get_pagesize() const { return get_stat().ms_psize; }
3310
3312 inline info get_info() const;
3313
3315 inline stat get_stat(const txn &) const;
3316
3318 inline info get_info(const txn &) const;
3319
3321 inline filehandle get_filehandle() const;
3322
3325
3327 inline MDBX_env_flags_t get_flags() const;
3328
3331 inline unsigned max_readers() const;
3332
3335 inline unsigned max_maps() const;
3336
3338 inline void *get_context() const noexcept;
3339
3341 inline env &set_context(void *your_context);
3342
3357 inline env &set_sync_threshold(size_t bytes);
3358
3364 inline size_t sync_threshold() const;
3365
3366#if __cplusplus >= 201103L || defined(DOXYGEN)
3386 inline env &set_sync_period(const duration &period);
3387
3393 inline duration sync_period() const;
3394#endif
3395
3399 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3400
3403 inline unsigned sync_period__seconds_16dot16() const;
3404
3408 inline env &set_sync_period__seconds_double(double seconds);
3409
3412 inline double sync_period__seconds_double() const;
3413
3451
3453 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3454
3456 inline uint64_t extra_option(extra_runtime_option option) const;
3457
3459 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3460
3462 inline env &set_geometry(const geometry &size);
3463
3467 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3468
3472 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3473
3492 inline void close_map(const map_handle &);
3493
3496 int slot;
3505 size_t bytes_used;
3514
3516 size_t used, size_t retained) noexcept;
3517 };
3518
3526 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3527
3530 inline unsigned check_readers();
3531
3550
3555 inline MDBX_hsr_func *get_HandleSlowReaders() const noexcept;
3556
3558 inline txn_managed start_read() const;
3559
3561 inline txn_managed prepare_read() const;
3562
3564 inline txn_managed start_write(txn &parent);
3565
3567 inline txn_managed start_write(bool dont_wait = false);
3568
3571};
3572
3581class LIBMDBX_API_TYPE env_managed : public env {
3582 using inherited = env;
3584 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3585 void setup(unsigned max_maps, unsigned max_readers = 0);
3586
3587public:
3588 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3589
3591#ifdef MDBX_STD_FILESYSTEM_PATH
3592 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3593#endif /* MDBX_STD_FILESYSTEM_PATH */
3594#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3595 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3596 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3597#endif /* Windows */
3598 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3599 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3600
3611
3613#ifdef MDBX_STD_FILESYSTEM_PATH
3615 bool accede = true);
3616#endif /* MDBX_STD_FILESYSTEM_PATH */
3617#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3618 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3619 bool accede = true);
3620 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3621 bool accede = true);
3622#endif /* Windows */
3623 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3624 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3625
3639 void close(bool dont_sync = false);
3640
3641 env_managed(env_managed &&) = default;
3642 env_managed &operator=(env_managed &&other) noexcept {
3644 MDBX_CXX20_UNLIKELY {
3645 assert(handle_ != other.handle_);
3646 close();
3647 }
3648 inherited::operator=(std::move(other));
3649 return *this;
3650 }
3651 env_managed(const env_managed &) = delete;
3652 env_managed &operator=(const env_managed &) = delete;
3653 virtual ~env_managed() noexcept;
3654};
3655
3664protected:
3665 friend class cursor;
3667 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3668
3669public:
3670 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3671 txn(const txn &) noexcept = default;
3672 txn &operator=(const txn &) noexcept = default;
3673 inline txn &operator=(txn &&) noexcept;
3674 inline txn(txn &&) noexcept;
3675 inline ~txn() noexcept;
3676
3677 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3678 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3679 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3680 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3681 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3682
3684 inline ::mdbx::env env() const noexcept;
3686 inline MDBX_txn_flags_t flags() const;
3688 inline uint64_t id() const;
3689
3691 inline void *get_context() const noexcept;
3692
3694 inline txn &set_context(void *your_context);
3695
3697 inline bool is_dirty(const void *ptr) const;
3698
3700 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3701
3703 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3704
3706 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3707
3710 inline info get_info(bool scan_reader_lock_table = false) const;
3711
3714 size_t size_max() const { return env().transaction_size_max(); }
3715
3717 size_t size_current() const {
3718 assert(is_readwrite());
3719 return size_t(get_info().txn_space_dirty);
3720 }
3721
3722 //----------------------------------------------------------------------------
3723
3725 inline void reset_reading();
3726
3728 inline void renew_reading();
3729
3731 inline void make_broken();
3732
3734 inline void park_reading(bool autounpark = true);
3735
3738 inline bool unpark_reading(bool restart_if_ousted = true);
3739
3742
3744 inline cursor_managed open_cursor(map_handle map) const;
3745
3747 inline size_t release_all_cursors(bool unbind) const;
3748
3750 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3751
3753 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3754
3756 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3757 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3759 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3760 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3762 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3763 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3764
3766 inline map_handle open_map_accede(const char *name) const;
3768 inline map_handle open_map_accede(const ::std::string &name) const;
3770 inline map_handle open_map_accede(const slice &name) const;
3771
3773 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3774 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3776 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3777 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3779 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3780 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3781
3783 inline void drop_map(map_handle map);
3787 bool drop_map(const char *name, bool throw_if_absent = false);
3791 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3795 bool drop_map(const slice &name, bool throw_if_absent = false);
3796
3798 inline void clear_map(map_handle map);
3801 bool clear_map(const char *name, bool throw_if_absent = false);
3804 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3807 bool clear_map(const slice &name, bool throw_if_absent = false);
3808
3810 inline void rename_map(map_handle map, const char *new_name);
3812 inline void rename_map(map_handle map, const ::std::string &new_name);
3814 inline void rename_map(map_handle map, const slice &new_name);
3818 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3822 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3826 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3827
3828#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3829
3831 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3832 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3833 return open_map(slice(name), key_mode, value_mode);
3834 }
3835
3836 inline map_handle open_map_accede(const ::std::string_view &name) const;
3838 inline map_handle create_map(const ::std::string_view &name,
3839 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3840 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3841 return create_map(slice(name), key_mode, value_mode);
3842 }
3843
3846 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3847 return drop_map(slice(name), throw_if_absent);
3848 }
3849
3851 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3852 return clear_map(slice(name), throw_if_absent);
3853 }
3854
3855 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3859 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3860 bool throw_if_absent = false) {
3861 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3862 }
3863#endif /* __cpp_lib_string_view >= 201606L */
3864
3867 inline map_stat get_map_stat(map_handle map) const;
3870 inline uint32_t get_tree_deepmask(map_handle map) const;
3873
3876 inline txn &put_canary(const canary &);
3878 inline canary get_canary() const;
3879
3881 inline uint64_t sequence(map_handle map) const;
3883 inline uint64_t sequence(map_handle map, uint64_t increment);
3884
3886 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3888 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3890 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3892 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3893
3895 inline slice get(map_handle map, const slice &key) const;
3897 inline slice get(map_handle map, slice key, size_t &values_count) const;
3899 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3901 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3905 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3909 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3910
3911 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3912 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3913 inline void insert(map_handle map, const slice &key, slice value);
3914 inline value_result try_insert(map_handle map, const slice &key, slice value);
3915 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3916 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3917
3918 inline void upsert(map_handle map, const slice &key, const slice &value);
3919 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3920
3921 inline void update(map_handle map, const slice &key, const slice &value);
3922 inline bool try_update(map_handle map, const slice &key, const slice &value);
3923 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3924 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3925
3926 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3927 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3928 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3929 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3930
3932 inline bool erase(map_handle map, const slice &key);
3933
3935 inline bool erase(map_handle map, const slice &key, const slice &value);
3936
3938 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3939
3941 template <class ALLOCATOR, typename CAPACITY_POLICY>
3943 extract(map_handle map, const slice &key,
3946
3948 template <class ALLOCATOR, typename CAPACITY_POLICY>
3950 replace(map_handle map, const slice &key, const slice &new_value,
3953
3954 template <class ALLOCATOR, typename CAPACITY_POLICY>
3956 replace_reserve(map_handle map, const slice &key, slice &new_value,
3959
3976 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
3977 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
3978 return append(map, kv.key, kv.value, multivalue_order_preserved);
3979 }
3980
3981 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
3982 const void *values_array, size_t values_count, put_mode mode,
3983 bool allow_partial = false);
3984 template <typename VALUE>
3985 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
3986 put_mode mode, bool allow_partial = false) {
3987 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
3988 !::std::is_array<VALUE>::value,
3989 "Must be a standard layout type!");
3990 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
3991 }
3992 template <typename VALUE>
3993 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
3994 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
3995 }
3996
3997 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
3998 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
3999 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4000 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4001};
4002
4011class LIBMDBX_API_TYPE txn_managed : public txn {
4012 using inherited = txn;
4013 friend class env;
4014 friend class txn;
4016 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4017
4018public:
4019 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4020 txn_managed(txn_managed &&) = default;
4021 txn_managed &operator=(txn_managed &&other) noexcept {
4023 MDBX_CXX20_UNLIKELY {
4024 assert(handle_ != other.handle_);
4025 abort();
4026 }
4027 inherited::operator=(std::move(other));
4028 return *this;
4029 }
4030 txn_managed(const txn_managed &) = delete;
4031 txn_managed &operator=(const txn_managed &) = delete;
4032 ~txn_managed() noexcept;
4033
4034 //----------------------------------------------------------------------------
4035
4038 void abort();
4039
4041 void commit();
4042
4046
4048
4052
4055 void commit(commit_latency &latency) { return commit(&latency); }
4056
4061 commit_latency result;
4062 commit(&result);
4063 return result;
4064 }
4065};
4066
4074protected:
4076
4077public:
4079 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4080 cursor(const cursor &) noexcept = default;
4081 cursor &operator=(const cursor &) noexcept = default;
4082 inline cursor &operator=(cursor &&) noexcept;
4083 inline cursor(cursor &&) noexcept;
4084 inline ~cursor() noexcept;
4085 inline cursor_managed clone(void *your_context = nullptr) const;
4086 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4087 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4088 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4089 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4090 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4091
4092 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4093 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4094
4095 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4096 return compare_position(*this, other, ignore_nested) < 0;
4097 }
4098
4099 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4100 return compare_position(*this, other, ignore_nested) <= 0;
4101 }
4102
4103 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4104 return compare_position(*this, other, ignore_nested) == 0;
4105 }
4106
4107 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4108 return compare_position(*this, other, ignore_nested) > 0;
4109 }
4110
4111 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4112 return compare_position(*this, other, ignore_nested) >= 0;
4113 }
4114
4116 inline void *get_context() const noexcept;
4117
4119 inline cursor &set_context(void *your_context);
4120
4127
4134
4137
4141
4142 /* Doubtless cursor positioning at a specified key. */
4148
4149 /* Doubtless cursor positioning at a specified key-value pair
4150 * for dupsort/multi-value hives. */
4156
4163
4168 };
4169
4170 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4171 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4172 // и других параметров в bool-throw_notfound.
4173
4174 struct move_result : public pair_result {
4175 inline move_result(const cursor &cursor, bool throw_notfound);
4176 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4177 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4178 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4179 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4180 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4181 bool throw_notfound);
4182 move_result(const move_result &) noexcept = default;
4183 move_result &operator=(const move_result &) noexcept = default;
4184 };
4185
4186 struct estimate_result : public pair {
4191 : estimate_result(cursor, operation, key, slice::invalid()) {}
4192 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4193 estimate_result(const estimate_result &) noexcept = default;
4194 estimate_result &operator=(const estimate_result &) noexcept = default;
4195 };
4196
4197protected:
4198 /* fake const, i.e. for some move/get operations */
4199 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4200
4201 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4202
4203public:
4204 template <typename CALLABLE_PREDICATE>
4205 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4206 struct wrapper : public exception_thunk {
4207 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4208 auto thunk = static_cast<wrapper *>(context);
4209 assert(thunk->is_clean());
4210 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4211 try {
4212 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4213 } catch (... /* capture any exception to rethrow it over C code */) {
4214 thunk->capture();
4215 return MDBX_RESULT_TRUE;
4216 }
4217 }
4218 } thunk;
4220 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4221 thunk);
4222 }
4223
4224 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4225 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4226 }
4227
4228 template <typename CALLABLE_PREDICATE>
4229 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4230 move_operation turn = next) {
4231 struct wrapper : public exception_thunk {
4232 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4233 auto thunk = static_cast<wrapper *>(context);
4234 assert(thunk->is_clean());
4235 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4236 try {
4237 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4238 } catch (... /* capture any exception to rethrow it over C code */) {
4239 thunk->capture();
4240 return MDBX_RESULT_TRUE;
4241 }
4242 }
4243 } thunk;
4244 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4245 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4246 thunk);
4247 }
4248
4249 template <typename CALLABLE_PREDICATE>
4250 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4251 move_operation turn = next) {
4252 struct wrapper : public exception_thunk {
4253 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4254 auto thunk = static_cast<wrapper *>(context);
4255 assert(thunk->is_clean());
4256 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4257 try {
4258 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4259 } catch (... /* capture any exception to rethrow it over C code */) {
4260 thunk->capture();
4261 return MDBX_RESULT_TRUE;
4262 }
4263 }
4264 } thunk;
4265 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4266 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4267 thunk);
4268 }
4269
4270 move_result move(move_operation operation, bool throw_notfound) {
4271 return move_result(*this, operation, throw_notfound);
4272 }
4273 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4274 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4275 }
4276 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4277 return move_result(*this, operation, key, value, throw_notfound);
4278 }
4279 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4280 return move(operation, &key, &value, throw_notfound);
4281 }
4282
4283 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4284 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4285 move_result to_previous_last_multi(bool throw_notfound = true) {
4286 return move(multi_prevkey_lastvalue, throw_notfound);
4287 }
4288 move_result to_current_first_multi(bool throw_notfound = true) {
4289 return move(multi_currentkey_firstvalue, throw_notfound);
4290 }
4291 move_result to_current_prev_multi(bool throw_notfound = true) {
4292 return move(multi_currentkey_prevvalue, throw_notfound);
4293 }
4294 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4295 move_result to_current_next_multi(bool throw_notfound = true) {
4296 return move(multi_currentkey_nextvalue, throw_notfound);
4297 }
4298 move_result to_current_last_multi(bool throw_notfound = true) {
4299 return move(multi_currentkey_lastvalue, throw_notfound);
4300 }
4301 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4302 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4303 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4304
4305 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4306 return move(key_lesser_than, key, throw_notfound);
4307 }
4308 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4309 return move(key_lesser_or_equal, key, throw_notfound);
4310 }
4311 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4312 return move(key_equal, key, throw_notfound);
4313 }
4314 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4315 return move(key_exact, key, throw_notfound);
4316 }
4317 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4318 return move(key_greater_or_equal, key, throw_notfound);
4319 }
4320 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4321 return move(key_greater_than, key, throw_notfound);
4322 }
4323
4324 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4325 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4326 }
4327 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4328 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4329 }
4330 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4331 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4332 }
4333 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4334 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4335 }
4336 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4337 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4338 }
4339
4340 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4341 return move(pair_lesser_than, key, value, throw_notfound);
4342 }
4343 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4344 return move(pair_lesser_or_equal, key, value, throw_notfound);
4345 }
4346 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4347 return move(pair_equal, key, value, throw_notfound);
4348 }
4349 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4350 return move(pair_exact, key, value, throw_notfound);
4351 }
4352 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4353 return move(pair_greater_or_equal, key, value, throw_notfound);
4354 }
4355 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4356 return move(pair_greater_than, key, value, throw_notfound);
4357 }
4358
4359 inline bool seek(const slice &key);
4360 inline move_result find(const slice &key, bool throw_notfound = true);
4361 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4362 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4363
4365 inline size_t count_multivalue() const;
4366
4367 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4368 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4369 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4370
4371 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4372 return move(seek_and_batch_samelength, key, throw_notfound);
4373 }
4374
4375 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4376 return move(batch_samelength, throw_notfound);
4377 }
4378
4379 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4380 return move(batch_samelength_next, throw_notfound);
4381 }
4382
4383 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4384 return move(batch_samelength_previous, throw_notfound);
4385 }
4386
4387 inline bool eof() const;
4388 inline bool on_first() const;
4389 inline bool on_last() const;
4390 inline bool on_first_multival() const;
4391 inline bool on_last_multival() const;
4392 inline estimate_result estimate(const slice &key, const slice &value) const;
4393 inline estimate_result estimate(const slice &key) const;
4394 inline estimate_result estimate(move_operation operation) const;
4395 inline estimate_result estimate(move_operation operation, slice &key) const;
4396
4397 //----------------------------------------------------------------------------
4398
4400 inline void renew(::mdbx::txn &txn);
4401
4404
4406 inline void unbind();
4407
4409 inline ::mdbx::txn txn() const;
4410 inline map_handle map() const;
4411
4412 inline operator ::mdbx::txn() const { return txn(); }
4413 inline operator ::mdbx::map_handle() const { return map(); }
4414
4415 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4416 inline void put(const slice &key, slice value, put_mode mode);
4417 inline void insert(const slice &key, slice value);
4418 inline value_result try_insert(const slice &key, slice value);
4419 inline slice insert_reserve(const slice &key, size_t value_length);
4420 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4421
4422 inline void upsert(const slice &key, const slice &value);
4423 inline slice upsert_reserve(const slice &key, size_t value_length);
4424
4426 void update_current(const slice &value);
4428 slice reverse_current(size_t value_length);
4429
4430 inline void update(const slice &key, const slice &value);
4431 inline bool try_update(const slice &key, const slice &value);
4432 inline slice update_reserve(const slice &key, size_t value_length);
4433 inline value_result try_update_reserve(const slice &key, size_t value_length);
4434
4435 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4436 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4437 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4438 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4439
4441 inline bool erase(bool whole_multivalue = false);
4442
4445 inline bool erase(const slice &key, bool whole_multivalue = true);
4446
4449 inline bool erase(const slice &key, const slice &value);
4450
4451 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4452 size_t values_count, put_mode mode, bool allow_partial = false);
4453 template <typename VALUE>
4454 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4455 bool allow_partial = false) {
4456 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4457 !::std::is_array<VALUE>::value,
4458 "Must be a standard layout type!");
4459 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4460 }
4461 template <typename VALUE>
4462 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4463 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4464 }
4465};
4466
4474class LIBMDBX_API_TYPE cursor_managed : public cursor {
4475 using inherited = cursor;
4476 friend class txn;
4478 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4479
4480public:
4482 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4483 if (MDBX_UNLIKELY(!handle_))
4484 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4485 }
4486
4488 inline void close() {
4490 handle_ = nullptr;
4491 }
4492
4493 cursor_managed(cursor_managed &&) = default;
4494 cursor_managed &operator=(cursor_managed &&other) noexcept {
4496 MDBX_CXX20_UNLIKELY {
4497 assert(handle_ != other.handle_);
4498 close();
4499 }
4500 inherited::operator=(std::move(other));
4501 return *this;
4502 }
4503
4504 inline MDBX_cursor *withdraw_handle() noexcept {
4505 MDBX_cursor *handle = handle_;
4506 handle_ = nullptr;
4507 return handle;
4508 }
4509
4510 cursor_managed(const cursor_managed &) = delete;
4511 cursor_managed &operator=(const cursor_managed &) = delete;
4513};
4514
4515//------------------------------------------------------------------------------
4516
4517LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
4518LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
4519LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
4520template <class ALLOCATOR, typename CAPACITY_POLICY>
4521inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
4522 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
4523}
4524LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
4525LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
4526LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
4527LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
4528LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
4529LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
4530LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
4531LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
4532
4533LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
4534LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
4535LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
4536inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
4537
4538//==============================================================================
4539//
4540// Inline body of the libmdbx C++ API
4541//
4542
4543MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4544MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4545
4546static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4547#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4548 if (::std::is_constant_evaluated()) {
4549 for (size_t i = 0; c_str; ++i)
4550 if (!c_str[i])
4551 return i;
4552 return 0;
4553 }
4554#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4555#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4556 return c_str ? ::std::string_view(c_str).length() : 0;
4557#else
4558 return c_str ? ::std::strlen(c_str) : 0;
4559#endif
4560}
4561
4562MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4563#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4564 if (::std::is_constant_evaluated()) {
4565 for (size_t i = 0; i < bytes; ++i)
4566 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4567 return dest;
4568 } else
4569#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4570 return ::std::memcpy(dest, src, bytes);
4571}
4572
4573static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4574#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4575 if (::std::is_constant_evaluated()) {
4576 for (size_t i = 0; i < bytes; ++i) {
4577 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4578 if (diff)
4579 return diff;
4580 }
4581 return 0;
4582 } else
4583#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4584 return ::std::memcmp(a, b, bytes);
4585}
4586
4587static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
4588 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
4589 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4590 return bytes;
4591}
4592
4593static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
4594 return check_length(check_length(headroom) + check_length(payload));
4595}
4596
4597MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
4598 return check_length(check_length(headroom, payload) + check_length(tailroom));
4599}
4600
4601inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4602
4603inline void exception_thunk::capture() noexcept {
4604 assert(is_clean());
4605 captured_ = ::std::current_exception();
4606}
4607
4609 if (captured_)
4610 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4611}
4612
4613//------------------------------------------------------------------------------
4614
4615MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4616
4617inline error &error::operator=(MDBX_error_t error_code) noexcept {
4618 code_ = error_code;
4619 return *this;
4620}
4621
4622MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4623
4624MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4625
4626MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4627
4628MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4629
4630MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4631
4633 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4634}
4635
4636MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4637
4642
4643inline void error::throw_exception(int error_code) {
4644 const error trouble(static_cast<MDBX_error_t>(error_code));
4645 trouble.throw_exception();
4646}
4647
4648inline void error::throw_on_failure() const {
4650 MDBX_CXX20_UNLIKELY throw_exception();
4651}
4652
4653inline void error::success_or_throw() const {
4654 if (MDBX_UNLIKELY(!is_success()))
4655 MDBX_CXX20_UNLIKELY throw_exception();
4656}
4657
4658inline void error::success_or_throw(const exception_thunk &thunk) const {
4659 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4660 if (MDBX_UNLIKELY(!is_success())) {
4661 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4662 else throw_exception();
4663 }
4664}
4665
4666inline void error::panic_on_failure(const char *context_where, const char *func_who) const noexcept {
4668 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4669}
4670
4671inline void error::success_or_panic(const char *context_where, const char *func_who) const noexcept {
4672 if (MDBX_UNLIKELY(!is_success()))
4673 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4674}
4675
4676inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4677 if (MDBX_UNLIKELY(ptr == nullptr))
4678 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4679}
4680
4681inline void error::throw_on_failure(int error_code) {
4682 error rc(static_cast<MDBX_error_t>(error_code));
4683 rc.throw_on_failure();
4684}
4685
4686inline void error::success_or_throw(MDBX_error_t error_code) {
4687 error rc(error_code);
4688 rc.success_or_throw();
4689}
4690
4691inline bool error::boolean_or_throw(int error_code) {
4692 switch (error_code) {
4693 case MDBX_RESULT_FALSE:
4694 return false;
4695 case MDBX_RESULT_TRUE:
4696 return true;
4697 default:
4698 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4699 }
4700}
4701
4702inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4703 error rc(static_cast<MDBX_error_t>(error_code));
4704 rc.success_or_throw(thunk);
4705}
4706
4707inline void error::panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept {
4708 error rc(static_cast<MDBX_error_t>(error_code));
4709 rc.panic_on_failure(context_where, func_who);
4710}
4711
4712inline void error::success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept {
4713 error rc(static_cast<MDBX_error_t>(error_code));
4714 rc.success_or_panic(context_where, func_who);
4715}
4716
4717inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4718 if (MDBX_UNLIKELY(!thunk.is_clean()))
4719 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4720 return boolean_or_throw(error_code);
4721}
4722
4723//------------------------------------------------------------------------------
4724
4725MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4726
4728 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4729
4730MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4731 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4732
4733MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4734
4735MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4736
4737MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4738
4739MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4740
4741inline slice &slice::assign(const void *ptr, size_t bytes) {
4742 iov_base = const_cast<void *>(ptr);
4743 iov_len = check_length(bytes);
4744 return *this;
4745}
4746
4747inline slice &slice::assign(const slice &src) noexcept {
4748 iov_base = src.iov_base;
4749 iov_len = src.iov_len;
4750 return *this;
4751}
4752
4753inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4754
4755slice &slice::assign(slice &&src) noexcept {
4756 assign(src);
4757 src.invalidate();
4758 return *this;
4759}
4760
4762 assign(src.iov_base, src.iov_len);
4763 src.iov_base = nullptr;
4764 return *this;
4765}
4766
4767inline slice &slice::assign(const void *begin, const void *end) {
4768 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4769}
4770
4771inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4772
4773inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4774
4775inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4776
4777MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4778
4779MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4780
4781MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4782
4784
4785MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4786
4787MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4788
4789MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4790
4792
4793MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4794
4795MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4796
4797MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4798
4799MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4800
4801MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4802
4804 iov_len = check_length(bytes);
4805 return *this;
4806}
4807
4809 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4810 return set_length(static_cast<const char *>(ptr) - char_ptr());
4811}
4812
4813MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4814
4815MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4816
4817MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4818
4819MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4820
4821MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4822
4824 iov_base = nullptr;
4825 iov_len = 0;
4826}
4827
4828inline void slice::remove_prefix(size_t n) noexcept {
4829 assert(n <= size());
4830 iov_base = static_cast<byte *>(iov_base) + n;
4831 iov_len -= n;
4832}
4833
4834inline void slice::safe_remove_prefix(size_t n) {
4835 if (MDBX_UNLIKELY(n > size()))
4836 MDBX_CXX20_UNLIKELY throw_out_range();
4837 remove_prefix(n);
4838}
4839
4840inline void slice::remove_suffix(size_t n) noexcept {
4841 assert(n <= size());
4842 iov_len -= n;
4843}
4844
4845inline void slice::safe_remove_suffix(size_t n) {
4846 if (MDBX_UNLIKELY(n > size()))
4847 MDBX_CXX20_UNLIKELY throw_out_range();
4848 remove_suffix(n);
4849}
4850
4851MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4852 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4853}
4854
4855MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4856 return length() >= suffix.length() &&
4857 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4858}
4859
4861 size_t h = length() * 3977471;
4862 for (size_t i = 0; i < length(); ++i)
4863 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4864 return h ^ 3863194411 * (h >> 11);
4865}
4866
4867MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4869 return byte_ptr()[n];
4870}
4871
4872MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4873 if (MDBX_UNLIKELY(n >= size()))
4874 MDBX_CXX20_UNLIKELY throw_out_range();
4875 return byte_ptr()[n];
4876}
4877
4878MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4880 return slice(data(), n);
4881}
4882
4883MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4885 return slice(char_ptr() + size() - n, n);
4886}
4887
4888MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4889 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4890 return slice(char_ptr() + from, n);
4891}
4892
4894 if (MDBX_UNLIKELY(n > size()))
4895 MDBX_CXX20_UNLIKELY throw_out_range();
4896 return head(n);
4897}
4898
4900 if (MDBX_UNLIKELY(n > size()))
4901 MDBX_CXX20_UNLIKELY throw_out_range();
4902 return tail(n);
4903}
4904
4905MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4906 if (MDBX_UNLIKELY(n > max_length))
4907 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4908 if (MDBX_UNLIKELY(from + n > size()))
4909 MDBX_CXX20_UNLIKELY throw_out_range();
4910 return middle(from, n);
4911}
4912
4913MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4914 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4915 return diff ? diff
4916 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4917 : memcmp(a.data(), b.data(), a.length());
4918}
4919
4921 const size_t shortest = ::std::min(a.length(), b.length());
4922 if (MDBX_LIKELY(shortest > 0))
4924 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4925 if (MDBX_LIKELY(diff != 0))
4926 MDBX_CXX20_LIKELY return diff;
4927 }
4928 return intptr_t(a.length()) - intptr_t(b.length());
4929}
4930
4932 return slice::compare_fast(a, b) == 0;
4933}
4934
4936 return slice::compare_lexicographically(a, b) < 0;
4937}
4938
4940 return slice::compare_lexicographically(a, b) > 0;
4941}
4942
4944 return slice::compare_lexicographically(a, b) <= 0;
4945}
4946
4948 return slice::compare_lexicographically(a, b) >= 0;
4949}
4950
4952 return slice::compare_fast(a, b) != 0;
4953}
4954
4955#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
4956MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
4958}
4959#endif /* __cpp_impl_three_way_comparison */
4960
4961template <class ALLOCATOR>
4962inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
4963 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
4964}
4965
4966template <class ALLOCATOR>
4967inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
4968 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
4969}
4970
4971template <class ALLOCATOR>
4972inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
4973 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
4974}
4975
4976template <class ALLOCATOR, class CAPACITY_POLICY>
4977inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
4978 const ALLOCATOR &alloc) const {
4979 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
4980}
4981
4982template <class ALLOCATOR, class CAPACITY_POLICY>
4983inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
4984 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
4985}
4986
4987template <class ALLOCATOR, class CAPACITY_POLICY>
4988inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
4989 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
4990}
4991
4992template <class ALLOCATOR, class CAPACITY_POLICY>
4993inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
4994 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
4995}
4996
4997template <class ALLOCATOR, class CAPACITY_POLICY>
4998inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
4999 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5000}
5001
5002template <class ALLOCATOR, class CAPACITY_POLICY>
5003inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5004 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5005}
5006
5007MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5008 return !from_hex(*this, ignore_spaces).is_erroneous();
5009}
5010
5011MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5012 return !from_base58(*this, ignore_spaces).is_erroneous();
5013}
5014
5015MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5016 return !from_base64(*this, ignore_spaces).is_erroneous();
5017}
5018
5019//------------------------------------------------------------------------------
5020
5021MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5022 const auto diff = slice::compare_fast(a.key, b.key);
5023 return diff ? diff : slice::compare_fast(a.value, b.value);
5024}
5025
5026MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5027 const auto diff = slice::compare_lexicographically(a.key, b.key);
5028 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5029}
5030
5032 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5033 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5034 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5035}
5036
5038 return pair::compare_lexicographically(a, b) < 0;
5039}
5040
5042 return pair::compare_lexicographically(a, b) > 0;
5043}
5044
5046 return pair::compare_lexicographically(a, b) <= 0;
5047}
5048
5050 return pair::compare_lexicographically(a, b) >= 0;
5051}
5052
5054 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5055 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5056 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5057}
5058
5059#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5060MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5062}
5063#endif /* __cpp_impl_three_way_comparison */
5064
5065//------------------------------------------------------------------------------
5066
5067template <class ALLOCATOR, typename CAPACITY_POLICY>
5068inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &txn, const struct slice &src, const allocator_type &alloc)
5069 : buffer(src, !txn.is_dirty(src.data()), alloc) {}
5070
5071//------------------------------------------------------------------------------
5072
5075
5079
5083
5084//------------------------------------------------------------------------------
5085
5087
5088inline env &env::operator=(env &&other) noexcept {
5089 handle_ = other.handle_;
5090 other.handle_ = nullptr;
5091 return *this;
5092}
5093
5094inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5095
5096inline env::~env() noexcept {
5097#ifndef NDEBUG
5098 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5099#endif
5100}
5101
5102MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5103
5104MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5105
5106MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5107
5108MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5109
5110MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5111
5115 return *this;
5116}
5117
5118inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5119 size_now = size_lower = lower;
5120 size_upper = upper;
5122 return *this;
5123}
5124
5128
5132
5133inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5134
5135inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5136
5137inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5138 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5139 if (result < 0)
5140 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5141 return static_cast<size_t>(result);
5142}
5143
5144inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5145 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5146 if (result < 0)
5147 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5148 return static_cast<size_t>(result);
5149}
5150
5151inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5152
5153inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5154
5155inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5156 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5157 if (result < 0)
5158 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5159 return static_cast<size_t>(result);
5160}
5161
5162inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5163 return key_max(pagesize, MDBX_db_flags_t(mode));
5164}
5165
5167 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5168 if (result < 0)
5169 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5170 return static_cast<size_t>(result);
5171}
5172
5174
5175inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5176
5178
5179inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5180 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5181 if (result < 0)
5182 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5183 return static_cast<size_t>(result);
5184}
5185
5186inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5187 return value_max(pagesize, MDBX_db_flags_t(mode));
5188}
5189
5191 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5192 if (result < 0)
5193 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5194 return static_cast<size_t>(result);
5195}
5196
5198
5199inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5200 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5201 if (result < 0)
5202 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5203 return static_cast<size_t>(result);
5204}
5205
5206inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5207 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5208}
5209
5211 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5212 if (result < 0)
5213 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5214 return static_cast<size_t>(result);
5215}
5216
5220
5221inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5222 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5223 if (result < 0)
5224 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5225 return static_cast<size_t>(result);
5226}
5227
5228inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5229 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5230}
5231
5233 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5234 if (result < 0)
5235 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5236 return static_cast<size_t>(result);
5237}
5238
5242
5243inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5244 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5245 if (result < 0)
5246 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5247 return static_cast<size_t>(result);
5248}
5249
5250inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5251
5259
5261
5265
5269
5273
5274inline env::stat env::get_stat() const {
5275 env::stat r;
5276 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5277 return r;
5278}
5279
5280inline env::stat env::get_stat(const txn &txn) const {
5281 env::stat r;
5283 return r;
5284}
5285
5286inline env::info env::get_info() const {
5287 env::info r;
5288 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5289 return r;
5290}
5291
5292inline env::info env::get_info(const txn &txn) const {
5293 env::info r;
5295 return r;
5296}
5297
5299 filehandle fd;
5301 return fd;
5302}
5303
5305 unsigned bits = 0;
5307 return MDBX_env_flags_t(bits);
5308}
5309
5310inline unsigned env::max_readers() const {
5311 unsigned r;
5313 return r;
5314}
5315
5316inline unsigned env::max_maps() const {
5317 unsigned r;
5319 return r;
5320}
5321
5322inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5323
5324inline env &env::set_context(void *ptr) {
5326 return *this;
5327}
5328
5329inline env &env::set_sync_threshold(size_t bytes) {
5331 return *this;
5332}
5333
5334inline size_t env::sync_threshold() const {
5335 size_t bytes;
5337 return bytes;
5338}
5339
5340inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5342 return *this;
5343}
5344
5345inline unsigned env::sync_period__seconds_16dot16() const {
5346 unsigned seconds_16dot16;
5348 return seconds_16dot16;
5349}
5350
5352 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5353}
5354
5355inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5356
5357#if __cplusplus >= 201103L
5358inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5359
5360inline duration env::sync_period() const { return duration(sync_period__seconds_16dot16()); }
5361#endif
5362
5363inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5365 return *this;
5366}
5367
5368inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5369 uint64_t value;
5371 return value;
5372}
5373
5376 return *this;
5377}
5378
5379inline env &env::set_geometry(const geometry &geo) {
5381 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5382 return *this;
5383}
5384
5385inline bool env::sync_to_disk(bool force, bool nonblock) {
5386 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5387 switch (err) {
5388 case MDBX_SUCCESS /* flush done */:
5389 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5390 return true;
5391 case MDBX_BUSY /* the environment is used by other thread */:
5392 return false;
5393 default:
5394 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5395 }
5396}
5397
5398inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5399
5401env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5402 size_t retained) noexcept
5404 bytes_retained(retained) {}
5405
5406template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5407 struct reader_visitor_thunk : public exception_thunk {
5408 VISITOR &visitor_;
5409 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5410 size_t used, size_t retained) noexcept {
5411 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5412 assert(thunk->is_clean());
5413 try {
5414 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5415 return loop_control(thunk->visitor_(info, number));
5416 } catch (... /* capture any exception to rethrow it over C code */) {
5417 thunk->capture();
5419 }
5420 }
5421 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5422 };
5423 reader_visitor_thunk thunk(visitor);
5424 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5425 thunk.rethrow_captured();
5426 return rc;
5427}
5428
5429inline unsigned env::check_readers() {
5430 int dead_count;
5431 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5432 assert(dead_count >= 0);
5433 return static_cast<unsigned>(dead_count);
5434}
5435
5440
5441inline MDBX_hsr_func *env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5442
5444 ::MDBX_txn *ptr;
5446 assert(ptr != nullptr);
5447 return txn_managed(ptr);
5448}
5449
5451 ::MDBX_txn *ptr;
5453 assert(ptr != nullptr);
5454 return txn_managed(ptr);
5455}
5456
5457inline txn_managed env::start_write(bool dont_wait) {
5458 ::MDBX_txn *ptr;
5460 assert(ptr != nullptr);
5461 return txn_managed(ptr);
5462}
5463
5465 ::MDBX_txn *ptr;
5467 assert(ptr != nullptr);
5468 return txn_managed(ptr);
5469}
5470
5472
5473//------------------------------------------------------------------------------
5474
5476
5477inline txn &txn::operator=(txn &&other) noexcept {
5478 handle_ = other.handle_;
5479 other.handle_ = nullptr;
5480 return *this;
5481}
5482
5483inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5484
5485inline txn::~txn() noexcept {
5486#ifndef NDEBUG
5487 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5488#endif
5489}
5490
5491MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5492
5493MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5494
5495MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5496
5497MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5498
5499MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5500
5501inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5502
5503inline txn &txn::set_context(void *ptr) {
5505 return *this;
5506}
5507
5508inline bool txn::is_dirty(const void *ptr) const {
5509 int err = ::mdbx_is_dirty(handle_, ptr);
5510 switch (err) {
5511 default:
5512 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5513 case MDBX_RESULT_TRUE:
5514 return true;
5515 case MDBX_RESULT_FALSE:
5516 return false;
5517 }
5518}
5519
5520inline ::mdbx::env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5521
5523 const int bits = mdbx_txn_flags(handle_);
5525 return static_cast<MDBX_txn_flags_t>(bits);
5526}
5527
5528inline uint64_t txn::id() const {
5529 const uint64_t txnid = mdbx_txn_id(handle_);
5531 return txnid;
5532}
5533
5535
5537
5539
5540inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5541
5542inline bool txn::unpark_reading(bool restart_if_ousted) {
5543 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5544}
5545
5546inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5547 txn::info r;
5548 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5549 return r;
5550}
5551
5553 MDBX_cursor *ptr;
5555 return cursor_managed(ptr);
5556}
5557
5558inline size_t txn::release_all_cursors(bool unbind) const {
5559 size_t count;
5561 return count;
5562}
5563
5564inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5565 const ::mdbx::value_mode value_mode) const {
5566 map_handle map;
5569 assert(map.dbi != 0);
5570 return map;
5571}
5572
5573inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5574 const ::mdbx::value_mode value_mode) const {
5575 map_handle map;
5578 assert(map.dbi != 0);
5579 return map;
5580}
5581
5582inline map_handle txn::open_map_accede(const slice &name) const {
5583 map_handle map;
5585 assert(map.dbi != 0);
5586 return map;
5587}
5588
5589inline map_handle txn::open_map_accede(const char *name) const {
5590 map_handle map;
5592 assert(map.dbi != 0);
5593 return map;
5594}
5595
5596inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5597 const ::mdbx::value_mode value_mode) {
5598 map_handle map;
5601 assert(map.dbi != 0);
5602 return map;
5603}
5604
5605inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5606 const ::mdbx::value_mode value_mode) {
5607 map_handle map;
5610 assert(map.dbi != 0);
5611 return map;
5612}
5613
5615
5617
5618inline void txn::rename_map(map_handle map, const char *new_name) {
5620}
5621
5622inline void txn::rename_map(map_handle map, const slice &new_name) {
5624}
5625
5626inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5627 const ::mdbx::value_mode value_mode) const {
5628 return open_map(slice(name), key_mode, value_mode);
5629}
5630
5631inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5632
5633inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5634 const ::mdbx::value_mode value_mode) {
5635 return create_map(slice(name), key_mode, value_mode);
5636}
5637
5638inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5639 return drop_map(slice(name), throw_if_absent);
5640}
5641
5642inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5643 return clear_map(slice(name), throw_if_absent);
5644}
5645
5646inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5647
5649 txn::map_stat r;
5650 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5651 return r;
5652}
5653
5654inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5655 uint32_t r;
5657 return r;
5658}
5659
5665
5670
5672 txn::canary r;
5674 return r;
5675}
5676
5677inline uint64_t txn::sequence(map_handle map) const {
5678 uint64_t result;
5680 return result;
5681}
5682
5683inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5684 uint64_t result;
5685 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5686 return result;
5687}
5688
5689inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5690 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5691}
5692
5693inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5694 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5695}
5696
5697inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5698 return compare_keys(map, a.key, b.key);
5699}
5700
5701inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5702 return compare_values(map, a.value, b.value);
5703}
5704
5705inline slice txn::get(map_handle map, const slice &key) const {
5706 slice result;
5707 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5708 return result;
5709}
5710
5711inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5712 slice result;
5713 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5714 return result;
5715}
5716
5717inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5718 slice result;
5719 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5720 switch (err) {
5721 case MDBX_SUCCESS:
5722 return result;
5723 case MDBX_NOTFOUND:
5724 return value_at_absence;
5725 default:
5726 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5727 }
5728}
5729
5730inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5731 slice result;
5732 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5733 switch (err) {
5734 case MDBX_SUCCESS:
5735 return result;
5736 case MDBX_NOTFOUND:
5737 return value_at_absence;
5738 default:
5739 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5740 }
5741}
5742
5744 pair result(key, slice());
5745 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5746 return pair_result(result.key, result.value, exact);
5747}
5748
5749inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5750 pair result{key, slice()};
5751 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5752 switch (err) {
5753 case MDBX_SUCCESS:
5754 return pair_result{result.key, result.value, true};
5755 case MDBX_RESULT_TRUE:
5756 return pair_result{result.key, result.value, false};
5757 case MDBX_NOTFOUND:
5758 return pair_result{key, value_at_absence, false};
5759 default:
5760 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5761 }
5762}
5763
5764inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5765 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5766}
5767
5768inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5769 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5770}
5771
5772inline void txn::insert(map_handle map, const slice &key, slice value) {
5773 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5775}
5776
5777inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5778 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5780 switch (err) {
5781 case MDBX_SUCCESS:
5782 return value_result{slice(), true};
5783 case MDBX_KEYEXIST:
5784 return value_result{value, false};
5785 default:
5786 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5787 }
5788}
5789
5790inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5791 slice result(nullptr, value_length);
5792 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5794 return result;
5795}
5796
5797inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5798 slice result(nullptr, value_length);
5799 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5801 switch (err) {
5802 case MDBX_SUCCESS:
5803 return value_result{result, true};
5804 case MDBX_KEYEXIST:
5805 return value_result{result, false};
5806 default:
5807 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5808 }
5809}
5810
5811inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5812 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5813}
5814
5815inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
5816 slice result(nullptr, value_length);
5818 return result;
5819}
5820
5821inline void txn::update(map_handle map, const slice &key, const slice &value) {
5822 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
5823}
5824
5825inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
5826 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
5827 switch (err) {
5828 case MDBX_SUCCESS:
5829 return true;
5830 case MDBX_NOTFOUND:
5831 return false;
5832 default:
5833 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5834 }
5835}
5836
5837inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
5838 slice result(nullptr, value_length);
5840 return result;
5841}
5842
5843inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
5844 slice result(nullptr, value_length);
5845 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
5846 switch (err) {
5847 case MDBX_SUCCESS:
5848 return value_result{result, true};
5849 case MDBX_NOTFOUND:
5850 return value_result{slice(), false};
5851 default:
5852 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5853 }
5854}
5855
5856inline bool txn::erase(map_handle map, const slice &key) {
5857 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
5858 switch (err) {
5859 case MDBX_SUCCESS:
5860 return true;
5861 case MDBX_NOTFOUND:
5862 return false;
5863 default:
5864 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5865 }
5866}
5867
5868inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
5869 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
5870 switch (err) {
5871 case MDBX_SUCCESS:
5872 return true;
5873 case MDBX_NOTFOUND:
5874 return false;
5875 default:
5876 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5877 }
5878}
5879
5880inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
5881 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
5882 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
5883}
5884
5885template <class ALLOCATOR, typename CAPACITY_POLICY>
5889 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
5891 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
5892 return result;
5893}
5894
5895template <class ALLOCATOR, typename CAPACITY_POLICY>
5897txn::replace(map_handle map, const slice &key, const slice &new_value,
5899 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
5900 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
5901 MDBX_CURRENT, result, &result),
5902 result);
5903 return result;
5904}
5905
5906template <class ALLOCATOR, typename CAPACITY_POLICY>
5908txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
5910 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
5911 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
5912 MDBX_CURRENT | MDBX_RESERVE, result, &result),
5913 result);
5914 return result;
5915}
5916
5917inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
5918 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
5919 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
5920}
5921
5922inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
5923 const void *values_array, size_t values_count, put_mode mode,
5924 bool allow_partial) {
5925 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
5926 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
5927 switch (err) {
5928 case MDBX_SUCCESS:
5929 MDBX_CXX20_LIKELY break;
5930 case MDBX_KEYEXIST:
5931 if (allow_partial)
5932 break;
5934 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
5935 default:
5936 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5937 }
5938 return args[1].iov_len /* done item count */;
5939}
5940
5941inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
5942 ptrdiff_t result;
5943 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
5944 return result;
5945}
5946
5947inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
5948 ptrdiff_t result;
5949 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
5950 return result;
5951}
5952
5953inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
5954 ptrdiff_t result;
5955 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
5956 return result;
5957}
5958
5959inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
5960 ptrdiff_t result;
5961 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
5962 return result;
5963}
5964
5965//------------------------------------------------------------------------------
5966
5968
5969inline cursor_managed cursor::clone(void *your_context) const {
5970 cursor_managed clone(your_context);
5972 return clone;
5973}
5974
5975inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
5976
5977inline cursor &cursor::set_context(void *ptr) {
5979 return *this;
5980}
5981
5982inline cursor &cursor::operator=(cursor &&other) noexcept {
5983 handle_ = other.handle_;
5984 other.handle_ = nullptr;
5985 return *this;
5986}
5987
5988inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5989
5990inline cursor::~cursor() noexcept {
5991#ifndef NDEBUG
5992 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
5993#endif
5994}
5995
5996MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
5997
5998MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
5999
6000MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6001
6002MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6003
6004MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6005
6006inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6007 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6008}
6009
6010inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6011 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6012 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6013 if (MDBX_LIKELY(int16_t(diff) == diff))
6014 MDBX_CXX20_LIKELY return int(diff);
6015 else
6017}
6018
6019inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6020 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6021}
6022
6024 bool throw_notfound)
6025 : pair_result(key, value, false) {
6026 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6027}
6028
6029inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6030 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6031 switch (err) {
6032 case MDBX_SUCCESS:
6033 MDBX_CXX20_LIKELY return true;
6034 case MDBX_RESULT_TRUE:
6035 return false;
6036 case MDBX_NOTFOUND:
6037 if (!throw_notfound)
6038 return false;
6039 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6040 default:
6041 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6042 }
6043}
6044
6046 const slice &value)
6047 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6048 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6049}
6050
6051inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6052 ptrdiff_t result;
6053 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6054 return result;
6055}
6056
6057inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6058 ptrdiff_t result;
6060 return result;
6061}
6062
6063inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6064 return move(key_exact, key, throw_notfound);
6065}
6066
6067inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6068 return move(key_lowerbound, key, throw_notfound);
6069}
6070
6071inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6072 return move(key_greater_than, key, throw_notfound);
6073}
6074
6075inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6076 return move(multi_find_pair, key, value, throw_notfound);
6077}
6078
6079inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6080 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6081}
6082
6083inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6084 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6085}
6086
6087inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6088
6089inline size_t cursor::count_multivalue() const {
6090 size_t result;
6092 return result;
6093}
6094
6095inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6096
6098
6100
6102
6104
6105inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6106 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6107}
6108
6110 return estimate_result(*this, key_lowerbound, key);
6111}
6112
6114 return estimate_result(*this, operation);
6115}
6116
6118
6122
6124
6125inline txn cursor::txn() const {
6127 return ::mdbx::txn(txn);
6128}
6129
6130inline map_handle cursor::map() const {
6131 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6132 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6134 return map_handle(dbi);
6135}
6136
6137inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6138 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6139}
6140
6141inline void cursor::put(const slice &key, slice value, put_mode mode) {
6142 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6143}
6144
6145inline void cursor::insert(const slice &key, slice value) {
6147 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6148}
6149
6150inline value_result cursor::try_insert(const slice &key, slice value) {
6151 const int err =
6152 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6153 switch (err) {
6154 case MDBX_SUCCESS:
6155 return value_result{slice(), true};
6156 case MDBX_KEYEXIST:
6157 return value_result{value, false};
6158 default:
6159 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6160 }
6161}
6162
6163inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6164 slice result(nullptr, value_length);
6165 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6167 return result;
6168}
6169
6170inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6171 slice result(nullptr, value_length);
6172 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6174 switch (err) {
6175 case MDBX_SUCCESS:
6176 return value_result{result, true};
6177 case MDBX_KEYEXIST:
6178 return value_result{result, false};
6179 default:
6180 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6181 }
6182}
6183
6184inline void cursor::upsert(const slice &key, const slice &value) {
6185 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6186}
6187
6188inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6189 slice result(nullptr, value_length);
6191 return result;
6192}
6193
6194inline void cursor::update(const slice &key, const slice &value) {
6195 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6196}
6197
6198inline bool cursor::try_update(const slice &key, const slice &value) {
6199 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6200 switch (err) {
6201 case MDBX_SUCCESS:
6202 return true;
6203 case MDBX_NOTFOUND:
6204 return false;
6205 default:
6206 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6207 }
6208}
6209
6210inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6211 slice result(nullptr, value_length);
6213 return result;
6214}
6215
6216inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6217 slice result(nullptr, value_length);
6218 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6219 switch (err) {
6220 case MDBX_SUCCESS:
6221 return value_result{result, true};
6222 case MDBX_NOTFOUND:
6223 return value_result{slice(), false};
6224 default:
6225 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6226 }
6227}
6228
6229inline bool cursor::erase(bool whole_multivalue) {
6230 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6231 switch (err) {
6232 case MDBX_SUCCESS:
6233 MDBX_CXX20_LIKELY return true;
6234 case MDBX_NOTFOUND:
6235 return false;
6236 default:
6237 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6238 }
6239}
6240
6241inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6242 bool found = seek(key);
6243 return found ? erase(whole_multivalue) : found;
6244}
6245
6246inline bool cursor::erase(const slice &key, const slice &value) {
6247 move_result data = find_multivalue(key, value, false);
6248 return data.done && erase();
6249}
6250
6251inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6252 size_t values_count, put_mode mode, bool allow_partial) {
6253 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6254 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6255 switch (err) {
6256 case MDBX_SUCCESS:
6257 MDBX_CXX20_LIKELY break;
6258 case MDBX_KEYEXIST:
6259 if (allow_partial)
6260 break;
6262 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6263 default:
6264 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6265 }
6266 return args[1].iov_len /* done item count */;
6267}
6268
6270} // namespace mdbx
6271
6272//------------------------------------------------------------------------------
6273
6276namespace std {
6277
6280
6281inline string to_string(const ::mdbx::slice &value) {
6282 ostringstream out;
6283 out << value;
6284 return out.str();
6285}
6286
6287template <class ALLOCATOR, typename CAPACITY_POLICY>
6288inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6289 ostringstream out;
6290 out << buffer;
6291 return out.str();
6292}
6293
6294inline string to_string(const ::mdbx::pair &value) {
6295 ostringstream out;
6296 out << value;
6297 return out.str();
6298}
6299
6300inline string to_string(const ::mdbx::env::geometry &value) {
6301 ostringstream out;
6302 out << value;
6303 return out.str();
6304}
6305
6306inline string to_string(const ::mdbx::env::operate_parameters &value) {
6307 ostringstream out;
6308 out << value;
6309 return out.str();
6310}
6311
6312inline string to_string(const ::mdbx::env::mode &value) {
6313 ostringstream out;
6314 out << value;
6315 return out.str();
6316}
6317
6318inline string to_string(const ::mdbx::env::durability &value) {
6319 ostringstream out;
6320 out << value;
6321 return out.str();
6322}
6323
6324inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6325 ostringstream out;
6326 out << value;
6327 return out.str();
6328}
6329
6330inline string to_string(const ::mdbx::env::operate_options &value) {
6331 ostringstream out;
6332 out << value;
6333 return out.str();
6334}
6335
6336inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6337 ostringstream out;
6338 out << value;
6339 return out.str();
6340}
6341
6342inline string to_string(const ::MDBX_log_level_t &value) {
6343 ostringstream out;
6344 out << value;
6345 return out.str();
6346}
6347
6348inline string to_string(const ::MDBX_debug_flags_t &value) {
6349 ostringstream out;
6350 out << value;
6351 return out.str();
6352}
6353
6354inline string to_string(const ::mdbx::error &value) {
6355 ostringstream out;
6356 out << value;
6357 return out.str();
6358}
6359
6360inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6361
6362template <> struct hash<::mdbx::slice> {
6363 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6364};
6365
6366template <> struct hash<::mdbx::map_handle> {
6367 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6368};
6369
6370template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6371 using inherited = std::hash<const MDBX_env *>;
6372 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6373};
6374
6375template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6376 using inherited = std::hash<const MDBX_txn *>;
6377 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6378};
6379
6380template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6381 using inherited = std::hash<const MDBX_cursor *>;
6382 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6383};
6384
6385template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6386 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6387 return buffer.hash_value();
6388 }
6389};
6390
6392} // namespace std
6393
6394#if defined(__LCC__) && __LCC__ >= 126
6395#pragma diagnostic pop
6396#endif
6397
6398#ifdef _MSC_VER
6399#pragma warning(pop)
6400#endif
Definition mdbx.h++:603
Definition mdbx.h++:593
Definition mdbx.h++:613
#define MDBX_CXX11_CONSTEXPR
Definition mdbx.h:443
#define MDBX_MAYBE_UNUSED
Definition mdbx.h:509
#define MDBX_CXX14_CONSTEXPR
Definition mdbx.h:462
#define MDBX_NOTHROW_PURE_FUNCTION
The 'pure nothrow' function attribute for optimization.
Definition mdbx.h:259
mode_t mdbx_mode_t
Definition mdbx.h:174
int(* MDBX_preserve_func)(void *context, MDBX_val *target, const void *src, size_t bytes)
Definition mdbx.h:5071
#define LIBMDBX_API
Definition mdbx.h:591
#define LIBMDBX_API_TYPE
Definition mdbx.h:606
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:766
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:698
int mdbx_filehandle_t
Definition mdbx.h:171
pid_t mdbx_pid_t
Definition mdbx.h:172
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:780
@ MDBX_MAXDATASIZE
Definition mdbx.h:774
@ MDBX_MAX_DBI
Definition mdbx.h:771
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:777
libmdbx build information
Definition mdbx.h:634
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4440
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4089
Information about the environment.
Definition mdbx.h:2812
Statistics for a table in the environment.
Definition mdbx.h:2766
Information about the transaction.
Definition mdbx.h:3991
libmdbx version information,
Definition mdbx.h:616
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:1634
LIBMDBX_API int mdbx_cursor_count(const MDBX_cursor *cursor, size_t *count)
Return count values (aka duplicates) for current key.
LIBMDBX_API int mdbx_cursor_scan_from(MDBX_cursor *cursor, MDBX_predicate_func *predicate, void *context, MDBX_cursor_op from_op, MDBX_val *from_key, MDBX_val *from_value, MDBX_cursor_op turn_op, void *arg)
int MDBX_cmp_func(const MDBX_val *a, const MDBX_val *b) noexcept
A callback function used to compare two keys in a table.
Definition mdbx.h:4500
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, const MDBX_val *data)
Delete items from a table.
LIBMDBX_API int mdbx_get_ex(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, size_t *values_count)
Get items from a table and optionally number of data items for a given key.
LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store by cursor.
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store items into a table.
LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del)
Empty or delete and close a table.
LIBMDBX_API int mdbx_cursor_get(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, MDBX_cursor_op op)
Retrieve by cursor.
LIBMDBX_API int mdbx_get(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data)
Get items from a table.
@ MDBX_MULTIPLE
Definition mdbx.h:1671
@ MDBX_ALLDUPS
Definition mdbx.h:1654
@ MDBX_CURRENT
Definition mdbx.h:1649
@ MDBX_APPENDDUP
Definition mdbx.h:1667
@ MDBX_APPEND
Definition mdbx.h:1662
@ MDBX_UPSERT
Definition mdbx.h:1636
@ MDBX_RESERVE
Definition mdbx.h:1658
@ MDBX_NOOVERWRITE
Definition mdbx.h:1639
LIBMDBX_API int mdbx_cursor_on_first_dup(const MDBX_cursor *cursor)
Определяет стоит ли курсор на первом или единственном мульти-значении соответствующем ключу.
LIBMDBX_API int mdbx_cursor_open(MDBX_txn *txn, MDBX_dbi dbi, MDBX_cursor **cursor)
Create a cursor handle for the specified transaction and DBI handle.
LIBMDBX_API int mdbx_cursor_unbind(MDBX_cursor *cursor)
Unbind cursor from a transaction.
LIBMDBX_API MDBX_cursor * mdbx_cursor_create(void *context)
Create a cursor handle but not bind it to transaction nor DBI-handle.
LIBMDBX_API MDBX_dbi mdbx_cursor_dbi(const MDBX_cursor *cursor)
Return the cursor's table handle.
MDBX_cursor_op
Cursor operationsThis is the set of all operations for retrieving data using a cursor.
Definition mdbx.h:1715
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.
LIBMDBX_API int mdbx_cursor_bind(MDBX_txn *txn, MDBX_cursor *cursor, MDBX_dbi dbi)
Bind cursor to specified transaction and DBI-handle.
LIBMDBX_API int mdbx_txn_release_all_cursors_ex(const MDBX_txn *txn, bool unbind, size_t *count)
Unbind or closes all cursors of a given transaction and of all its parent transactions if ones are.
struct MDBX_cursor MDBX_cursor
Opaque structure for navigating through a table.
Definition mdbx.h:728
LIBMDBX_API int mdbx_cursor_set_userctx(MDBX_cursor *cursor, void *ctx)
Set application information associated with the cursor.
LIBMDBX_API int mdbx_cursor_eof(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to a key-value pair or not, i.e. was not positioned or point...
LIBMDBX_API int mdbx_cursor_close2(MDBX_cursor *cursor)
Closes a cursor handle with returning error code.
LIBMDBX_API void * mdbx_cursor_get_userctx(const MDBX_cursor *cursor)
Get the application information associated with the MDBX_cursor.
LIBMDBX_API int mdbx_cursor_renew(MDBX_txn *txn, MDBX_cursor *cursor)
Renew a cursor handle for use within the given transaction.
LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor)
Closes a cursor handle without returning error code.
LIBMDBX_API MDBX_txn * mdbx_cursor_txn(const MDBX_cursor *cursor)
Return the cursor's transaction handle.
LIBMDBX_API int mdbx_cursor_on_last(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to the last key-value pair or not.
LIBMDBX_API int mdbx_cursor_copy(const MDBX_cursor *src, MDBX_cursor *dest)
Copy cursor position and state.
@ MDBX_SEEK_AND_GET_MULTIPLE
Definition mdbx.h:1834
@ MDBX_GET_CURRENT
Definition mdbx.h:1730
@ MDBX_GET_BOTH
Definition mdbx.h:1723
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1811
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1727
@ MDBX_SET_KEY
Definition mdbx.h:1770
@ MDBX_FIRST_DUP
Definition mdbx.h:1720
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1810
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1735
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1821
@ MDBX_NEXT_NODUP
Definition mdbx.h:1755
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1818
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1819
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1826
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1778
@ MDBX_SET_RANGE
Definition mdbx.h:1773
@ MDBX_LAST_DUP
Definition mdbx.h:1741
@ MDBX_PREV
Definition mdbx.h:1758
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1828
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1829
@ MDBX_LAST
Definition mdbx.h:1738
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1809
@ MDBX_PREV_DUP
Definition mdbx.h:1761
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1817
@ MDBX_SET
Definition mdbx.h:1767
@ MDBX_NEXT
Definition mdbx.h:1744
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1812
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1825
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1752
@ MDBX_PREV_NODUP
Definition mdbx.h:1764
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1827
@ MDBX_NEXT_DUP
Definition mdbx.h:1747
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1820
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1813
@ MDBX_FIRST
Definition mdbx.h:1717
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:721
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1584
@ MDBX_INTEGERDUP
Definition mdbx.h:1608
@ MDBX_DB_ACCEDE
Definition mdbx.h:1626
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1586
@ MDBX_REVERSEKEY
Definition mdbx.h:1589
@ MDBX_DUPFIXED
Definition mdbx.h:1603
@ MDBX_INTEGERKEY
Definition mdbx.h:1599
@ MDBX_REVERSEDUP
Definition mdbx.h:1611
@ MDBX_CREATE
Definition mdbx.h:1614
@ MDBX_DUPSORT
Definition mdbx.h:1592
MDBX_log_level_t
Definition mdbx.h:843
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:902
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:6298
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1842
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1856
@ MDBX_BAD_TXN
Definition mdbx.h:1921
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1935
@ MDBX_SUCCESS
Definition mdbx.h:1844
@ MDBX_NOTFOUND
Definition mdbx.h:1859
@ MDBX_RESULT_TRUE
Definition mdbx.h:1850
@ MDBX_BUSY
Definition mdbx.h:1939
@ MDBX_EINVAL
Definition mdbx.h:2012
@ MDBX_ENOMEM
Definition mdbx.h:2014
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1942
@ MDBX_RESULT_FALSE
Definition mdbx.h:1847
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:1991
@ MDBX_KEYEXIST
Definition mdbx.h:1853
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:2548
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2542
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2545
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1025
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:3059
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2122
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:2998
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:2227
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2223
@ 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:2327
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2131
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2294
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2154
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2259
@ 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:2282
@ 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:2194
@ 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:2181
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2148
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2243
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2160
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2208
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2322
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:3695
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:3079
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:3016
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:4771
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:3740
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 to prevent further operations.
LIBMDBX_API int mdbx_txn_set_userctx(MDBX_txn *txn, void *ctx)
Sets application information associated (a context pointer) with the transaction.
LIBMDBX_API int mdbx_txn_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:1486
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:3960
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:709
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:1497
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1506
@ MDBX_TXN_READWRITE
Definition mdbx.h:1491
@ MDBX_TXN_TRY
Definition mdbx.h:1512
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2328
friend class env
Definition mdbx.h++:4013
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2041
MDBX_commit_latency commit_latency
Definition mdbx.h++:4047
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++:1914
::MDBX_txn_info info
Definition mdbx.h++:3708
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4482
~txn_managed() noexcept
::MDBX_stat map_stat
Definition mdbx.h++:3865
bool drop_map(const slice &name, bool throw_if_absent=false)
Drop key-value map.
txn & operator=(const txn &) noexcept=default
env & set_sync_period(const duration &period)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
txn_managed start_nested()
Start nested write transaction.
extra_runtime_option
MDBX environment extra runtime options.
Definition mdbx.h++:3415
@ prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h++:3449
@ spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h++:3441
@ spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h++:3443
@ writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h++:3447
@ sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h++:3424
@ dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h++:3435
@ dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h++:3437
@ spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h++:3439
@ merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h++:3445
@ 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++:3429
@ loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h++:3431
@ dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h++:3433
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6386
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3642
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:1941
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2006
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1896
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3846
env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede=true)
map_handle(const map_handle &) noexcept=default
static buffer base64_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:2183
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2224
::MDBX_db_flags_t flags
Definition mdbx.h++:2925
path get_path() const
Return the path that was used for opening the environment.
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4327
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4383
static buffer key_from(const double *ieee754_64bit)
Definition mdbx.h++:2549
static buffer hex(const POD &pod, bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a hexadecimal dump of the given pod.
Definition mdbx.h++:2132
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++:1957
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2255
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:1954
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2337
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2207
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++:1929
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2068
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2308
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2221
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:1948
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2894
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2073
durability
Durability level.
Definition mdbx.h++:3072
@ lazy_weak_tail
Definition mdbx.h++:3075
@ robust_synchronous
Definition mdbx.h++:3073
@ whole_fragile
Definition mdbx.h++:3076
@ half_synchronous_weak_last
Definition mdbx.h++:3074
void commit_embark_read()
Commit all the operations of a transaction into the database and then start read transaction.
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1481
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2023
friend constexpr bool operator!=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2921
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2259
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:1981
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3242
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2438
map_handle & operator=(const map_handle &) noexcept=default
duration sync_period() const
Gets relative period since the last unsteady commit that used to force flush the data buffers to disk...
move_result seek_multiple_samelength(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4371
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:1977
buffer & append(const byte c)
Definition mdbx.h++:2392
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2232
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2237
buffer & operator=(const buffer &src)
Definition mdbx.h++:2354
estimate_result estimate(move_operation operation, slice &key) const
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2460
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3665
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:1923
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4346
::MDBX_canary canary
Definition mdbx.h++:3874
env & copy(const wchar_t *destination, bool compactify, bool force_dynamic_size=false)
bool is_readwrite() const
Checks whether the transaction is read-write.
Definition mdbx.h++:3706
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++:4276
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:1974
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2539
static buffer hex(const slice &source, bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:2114
void update_current(const slice &value)
Updates value associated with a key at the current cursor position.
env_managed(const wchar_t *pathname, const operate_parameters &, bool accede=true)
move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4340
buffer base58_decode(bool ignore_spaces=false, const allocator_type &alloc=allocator_type()) const
Decodes Base58 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2196
bool clear_map(const char *name, bool throw_if_absent=false)
buffer hex_decode(bool ignore_spaces=false, const allocator_type &alloc=allocator_type()) const
Decodes hexadecimal dump from the buffer content to new returned buffer.
Definition mdbx.h++:2190
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2109
constexpr env() noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2402
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2152
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4349
void rename_map(map_handle map, const ::std::string_view &new_name)
Переименовывает таблицу ключ-значение.
env & copy(filehandle fd, bool compactify, bool force_dynamic_size=false)
Copy an environment to the specified file descriptor.
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2333
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
static buffer base58_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:2176
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2915
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2559
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2895
buffer base64_decode(bool ignore_spaces=false, const allocator_type &alloc=allocator_type()) const
Decodes Base64 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2202
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4435
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2106
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4294
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++:4285
allocation_aware_details::swap_alloc< struct silo, allocator_type > swap_alloc
Definition mdbx.h++:1891
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2565
static bool remove(const ::mdbx::filesystem::path &pathname, const remove_mode mode=just_remove)
Removes the environment's files in a proper and multiprocess-safe way.
bool drop_map(const char *name, bool throw_if_absent=false)
Drops key-value map using name.
cursor & operator=(const cursor &) noexcept=default
bool is_same_or_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4111
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3753
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3929
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4317
static buffer base58(const POD &pod, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base58 dump of the given pod.
Definition mdbx.h++:2140
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4103
constexpr buffer & assign(buffer &&src) noexcept(allocation_aware_details::move_assign_alloc< silo, allocator_type >::is_nothrow())
Definition mdbx.h++:2296
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4107
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2363
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2545
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++:3838
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6382
const slice & slice() const noexcept
Definition mdbx.h++:2577
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2316
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3169
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6367
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4301
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2304
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4504
constexpr buffer(const buffer &src)
Definition mdbx.h++:2051
static buffer hex_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:2169
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2377
MDBX_txn * handle_
Definition mdbx.h++:3666
void abort()
Abandon all the operations of the transaction instead of saving ones.
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:1994
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2551
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4273
mode
Operation mode.
Definition mdbx.h++:3064
@ write_mapped_io
Definition mdbx.h++:3067
@ nested_transactions
Definition mdbx.h++:3068
@ readonly
Definition mdbx.h++:3065
@ write_file_io
Definition mdbx.h++:3066
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2247
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4270
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4229
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3303
operator::mdbx::txn() const
Definition mdbx.h++:4412
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2434
MDBX_env * handle_
Definition mdbx.h++:2965
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2531
slice reverse_current(size_t value_length)
Reserves and returns the space to storing a value associated with a key at the current cursor positio...
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2084
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4333
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2458
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:1908
commit_latency commit_get_latency()
Commit all the operations of a transaction into the database and return latency information.
Definition mdbx.h++:4060
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4099
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2563
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4283
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4303
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2358
void close()
Explicitly closes the cursor.
Definition mdbx.h++:4488
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2430
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2036
bool is_pristine() const
Returns true for a freshly created database, but false if at least one transaction was committed.
buffer(const txn &transaction, const slice &src, const allocator_type &alloc=allocator_type())
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6363
move_result to_key_exact(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4314
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2543
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3703
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2164
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2079
constexpr txn_managed() noexcept=default
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2322
bool clear_map(const slice &name, bool throw_if_absent=false)
constexpr bool is_freestanding() const noexcept
Checks whether data chunk stored inside the buffer, otherwise buffer just refers to data located outs...
Definition mdbx.h++:1900
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2567
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2493
move_result next_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4379
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++:3977
cursor_managed & operator=(const cursor_managed &)=delete
default_capacity_policy reservation_policy
Definition mdbx.h++:1482
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3273
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3283
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3285
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3280
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2557
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4205
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4288
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2030
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2360
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2410
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2481
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2442
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4250
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4494
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6376
::MDBX_dbi_state_t state
Definition mdbx.h++:2926
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3472
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4462
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++:4055
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++:3248
static buffer base64(const POD &pod, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base64 dump of the given pod.
Definition mdbx.h++:2147
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4343
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++:2573
move_result get_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4375
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4305
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4302
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4413
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3244
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2918
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2569
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3750
static buffer key_from(const uint32_t unsigned_int32)
Definition mdbx.h++:2571
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2226
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2909
void commit()
Commit all the operations of a transaction into the database.
move_result to_key_greater_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4320
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3309
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2014
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3926
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++:2312
friend int compare_position(const cursor &left, const cursor &right, bool ignore_nested)
Definition mdbx.h++:6010
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:3993
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++:3255
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++:3831
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2906
allocation_aware_details::move_assign_alloc< silo, allocator_type > move_assign_alloc
Definition mdbx.h++:1889
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++:3985
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1890
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:1961
friend constexpr bool operator>(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2912
bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2275
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2400
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++:2446
void close(bool dont_sync=false)
Explicitly closes the environment and release the memory map.
move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4355
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:1968
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4121
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4136
@ multi_exactkey_value_equal
Definition mdbx.h++:4153
@ pair_greater_or_equal
Definition mdbx.h++:4161
@ key_lesser_than
Definition mdbx.h++:4143
@ next
Definition mdbx.h++:4124
@ pair_exact
Definition mdbx.h++:4160
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4154
@ pair_lesser_or_equal
Definition mdbx.h++:4158
@ batch_samelength
Definition mdbx.h++:4164
@ seek_key
Definition mdbx.h++:4138
@ key_lowerbound
Definition mdbx.h++:4140
@ pair_lesser_than
Definition mdbx.h++:4157
@ pair_equal
Definition mdbx.h++:4159
@ key_greater_than
Definition mdbx.h++:4147
@ batch_samelength_next
Definition mdbx.h++:4165
@ multi_find_pair
Definition mdbx.h++:4135
@ key_greater_or_equal
Definition mdbx.h++:4146
@ key_exact
Definition mdbx.h++:4139
@ key_equal
Definition mdbx.h++:4145
@ multi_currentkey_prevvalue
Definition mdbx.h++:4130
@ key_lesser_or_equal
Definition mdbx.h++:4144
@ multi_nextkey_firstvalue
Definition mdbx.h++:4133
@ get_current
Definition mdbx.h++:4126
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4152
@ multi_prevkey_lastvalue
Definition mdbx.h++:4128
@ previous
Definition mdbx.h++:4125
@ last
Definition mdbx.h++:4123
@ pair_greater_than
Definition mdbx.h++:4162
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4151
@ multi_currentkey_firstvalue
Definition mdbx.h++:4129
@ first
Definition mdbx.h++:4122
@ batch_samelength_previous
Definition mdbx.h++:4166
@ multi_currentkey_nextvalue
Definition mdbx.h++:4131
@ seek_and_batch_samelength
Definition mdbx.h++:4167
@ multi_exactkey_value_greater
Definition mdbx.h++:4155
@ multi_currentkey_lastvalue
Definition mdbx.h++:4132
virtual ~env_managed() noexcept
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4279
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2525
void insert(const pair &kv)
Definition mdbx.h++:4436
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3700
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2384
cursor_managed(const cursor_managed &)=delete
env & operator=(const env &) noexcept=default
env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
void upsert(const pair &kv)
Definition mdbx.h++:4438
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4291
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2382
txn_managed & operator=(const txn_managed &)=delete
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2575
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2374
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3851
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4330
static buffer base64(const slice &source, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base64 dump of the slice content.
Definition mdbx.h++:2126
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2055
typename ::std::allocator_traits< default_allocator >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1477
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++:2547
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:1934
move_result to_current_last_multi(bool throw_notfound=true)
Definition mdbx.h++:4298
value_result try_insert(const pair &kv)
Definition mdbx.h++:4437
size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode, bool allow_partial=false)
Definition mdbx.h++:4454
constexpr cursor() noexcept=default
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4308
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6372
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2555
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:1937
static buffer base58(const slice &source, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base58 dump of the slice content.
Definition mdbx.h++:2121
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2251
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4352
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3252
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2064
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1893
MDBX_cursor * handle_
Definition mdbx.h++:4075
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2450
~cursor_managed() noexcept
Definition mdbx.h++:4512
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2470
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2091
MDBX_dbi dbi
Definition mdbx.h++:2893
buffer(const ::std::basic_string< CHAR, T, A > &&)=delete
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4324
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2553
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4295
buffer encode_base58(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2159
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2507
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6371
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++:2426
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2103
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3714
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2356
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++:4336
txn_managed(const txn_managed &)=delete
friend int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept
Definition mdbx.h++:6006
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6381
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3300
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3250
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:1988
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3928
buffer & append_producer(PRODUCER &producer)
Definition mdbx.h++:2412
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3927
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2419
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2059
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++:2536
bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:3859
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4311
bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
move_result to_previous(bool throw_notfound=true)
Definition mdbx.h++:4284
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4095
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2047
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3246
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6377
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:1917
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3717
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:1999
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4224
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1473
Unmanaged cursor.
Definition mdbx.h++:4073
Managed cursor.
Definition mdbx.h++:4474
Unmanaged database environment.
Definition mdbx.h++:2961
Managed database environment.
Definition mdbx.h++:3581
Unmanaged database transaction.
Definition mdbx.h++:3663
Managed database transaction.
Definition mdbx.h++:4011
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++:5151
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5021
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4808
polymorphic_allocator default_allocator
Definition mdbx.h++:358
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4817
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4899
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base58(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base58 dump of the slice content.
Definition mdbx.h++:4983
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++:5436
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5501
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++:5179
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4913
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4636
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++:5880
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6117
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2807
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4795
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:5076
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4893
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5534
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:4785
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4671
void rethrow_captured() const
Definition mdbx.h++:4608
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4793
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6075
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6051
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5144
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5118
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5843
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5797
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5398
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++:5329
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6019
string< ALLOCATOR > as_hex_string(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of the slice content.
Definition mdbx.h++:4962
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4815
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:5953
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base64(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base64 dump of the slice content.
Definition mdbx.h++:4988
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4840
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4741
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6123
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:425
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5790
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:5967
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5618
void throw_on_failure() const
Definition mdbx.h++:4648
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6198
void update(const slice &key, const slice &value)
Definition mdbx.h++:6194
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:5073
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++:5689
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4803
buffer< ALLOCATOR, CAPACITY_POLICY > encode_hex(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:4977
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5503
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5464
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6006
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4939
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5262
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5677
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6184
bool is_clean() const noexcept
Definition mdbx.h++:4601
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2800
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4691
string< ALLOCATOR > as_base58_string(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:4967
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5252
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2804
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:381
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:5304
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5137
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4883
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4615
buffer< ALLOCATOR, CAPACITY_POLICY > hex_decode(bool ignore_spaces=false, const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:4993
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4543
buffer< ALLOCATOR, CAPACITY_POLICY > replace_reserve(map_handle map, const slice &key, slice &new_value, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &alloc=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Definition mdbx.h++:5908
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++:5401
void insert(const slice &key, slice value)
Definition mdbx.h++:6145
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6079
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++:5573
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:357
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:2788
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++:5441
buffer< ALLOCATOR, CAPACITY_POLICY > base64_decode(bool ignore_spaces=false, const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:5003
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4725
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:5969
~cursor() noexcept
Definition mdbx.h++:5990
~txn() noexcept
Definition mdbx.h++:5485
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5334
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6071
uint64_t txnid
Transaction ID and MVCC-snapshot number.
Definition mdbx.h++:374
constexpr void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition mdbx.h++:4821
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6125
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6170
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5129
map_handle map() const
Definition mdbx.h++:6130
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++:5345
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:5080
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6063
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5589
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6083
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2868
void success_or_throw() const
Definition mdbx.h++:4653
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5538
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4855
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5385
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4943
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6010
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6089
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4851
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5135
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4860
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5508
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6188
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5260
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2796
void capture() noexcept
Definition mdbx.h++:4603
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5520
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++:5654
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5825
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4834
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2939
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6163
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++:5199
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++:5340
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:5941
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5266
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5614
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:5959
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++:5917
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5270
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5540
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4947
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:5977
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5648
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6029
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++:5175
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++:5693
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5125
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5666
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5815
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4878
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6281
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4630
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++:5351
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4905
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4777
bool on_first() const
Definition mdbx.h++:6097
::MDBX_version_info version_info
libmdbx version information,
Definition mdbx.h++:334
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:4813
bool eof() const
Definition mdbx.h++:6095
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5536
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5522
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5322
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6137
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5450
::MDBX_build_info build_info
libmdbx build information
Definition mdbx.h++:338
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5475
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4845
bool seek(const slice &key)
Definition mdbx.h++:6087
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5374
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5324
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4867
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++:5243
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5616
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++:5363
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5015
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4828
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6150
size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array, size_t values_count, put_mode mode, bool allow_partial=false)
Definition mdbx.h++:6251
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4676
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4624
::MDBX_cmp_func * comparator
Definition mdbx.h++:2938
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2947
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5026
buffer< ALLOCATOR, CAPACITY_POLICY > base58_decode(bool ignore_spaces=false, const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:4998
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++:5355
::mdbx_filehandle_t filehandle
Definition mdbx.h++:383
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++:5221
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5086
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4935
char8_t byte
Definition mdbx.h++:318
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5671
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6229
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5274
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5528
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5777
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:352
constexpr bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition mdbx.h++:4638
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6057
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4920
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5837
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5011
~env() noexcept
Definition mdbx.h++:5096
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2769
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5705
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4632
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4823
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++:5922
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5821
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4872
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2772
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5443
::mdbx::filesystem::path path
Definition mdbx.h++:407
bool on_last_multival() const
Definition mdbx.h++:6103
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5316
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5772
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5310
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++:5155
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5406
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:5975
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5250
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5552
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2792
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5542
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5368
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4544
bool on_first_multival() const
Definition mdbx.h++:6101
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5764
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4666
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4888
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5286
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5811
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5133
string< ALLOCATOR > as_base64_string(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:4972
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6210
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6067
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4779
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4801
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5429
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:5856
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4628
bool on_last() const
Definition mdbx.h++:6099
buffer< ALLOCATOR, CAPACITY_POLICY > extract(map_handle map, const slice &key, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &alloc=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Removes and return a value of the key.
Definition mdbx.h++:5887
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:403
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:5298
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5379
map_handle::info get_handle_info(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5660
void bind(::mdbx::txn &txn, ::mdbx::map_handle map_handle)
Bind/renew a cursor with a new transaction and specified key-value map handle.
Definition mdbx.h++:6119
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5112
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5558
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4622
constexpr bool is_success() const noexcept
Definition mdbx.h++:4626
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6216
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:377
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5471
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5007
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5546
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++:5605
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++:5743
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4787
@ multi_reverse_samelength
Definition mdbx.h++:2840
@ multi_samelength
Definition mdbx.h++:2825
@ multi_ordinal
Definition mdbx.h++:2832
@ msgpack
Definition mdbx.h++:2855
@ single
Definition mdbx.h++:2808
@ multi
Definition mdbx.h++:2810
@ multi_reverse
Definition mdbx.h++:2817
@ upsert
Insert or update.
Definition mdbx.h++:2949
@ update
Update existing, don't insert new.
Definition mdbx.h++:2950
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2948
@ continue_loop
Definition mdbx.h++:2769
@ exit_loop
Definition mdbx.h++:2769
@ usual
Definition mdbx.h++:2773
@ ordinal
Definition mdbx.h++:2778
@ reverse
Definition mdbx.h++:2775
@ msgpack
Definition mdbx.h++:2783
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2892
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base58 dump of a passed slice.
Definition mdbx.h++:1266
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of a passed slice.
Definition mdbx.h++:1218
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:700
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:713
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base64 dump of a passed slice.
Definition mdbx.h++:1312
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:676
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:667
buffer_pair_spec(const txn &transacton, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2724
const slice source
Definition mdbx.h++:1295
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++:735
int8_t as_int8_adapt() const
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2691
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1031
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1272
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:753
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1012
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1030
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2732
constexpr int64_t as_int64() const
Definition mdbx.h++:1037
const bool ignore_spaces
Definition mdbx.h++:1387
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:857
value_result & operator=(const value_result &) noexcept=default
bool is_printable(bool disable_utf8=false) const noexcept
Checks whether the content of the slice is printable.
int128_t as_int128_adapt() const
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from Base64 dump from a passed slice.
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Definition mdbx.h++:770
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2702
constexpr int16_t as_int16() const
Definition mdbx.h++:1039
slice value
Definition mdbx.h++:2632
::std::ostream & output(::std::ostream &out) const
Output Base64 dump of passed slice to the std::ostream.
buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2704
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1239
slice value
Definition mdbx.h++:2646
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2695
::std::ostream & output(::std::ostream &out) const
Output hexadecimal dump of passed slice to the std::ostream.
pair_result(const pair_result &) noexcept=default
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:1446
const slice source
Definition mdbx.h++:1386
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2713
const slice source
Definition mdbx.h++:1202
constexpr size_t envisage_result_length() const noexcept
Returns the number of bytes needed for conversion hexadecimal dump from a passed slice to decoded dat...
Definition mdbx.h++:1369
const unsigned wrap_width
Definition mdbx.h++:1204
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:727
const bool ignore_spaces
Definition mdbx.h++:1349
constexpr POD as_pod() const
Definition mdbx.h++:1014
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++:2679
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++:1461
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2708
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1027
uint16_t as_uint16_adapt() const
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:1363
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1205
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2710
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1178
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:749
std::pair< slice, slice > stl_pair
Definition mdbx.h++:2645
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
@ pettiness_threshold
Definition mdbx.h++:1166
@ extra_inplace_storage
Definition mdbx.h++:1164
@ max_reserve
Definition mdbx.h++:1167
@ inplace_storage_size_rounding
Definition mdbx.h++:1165
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:690
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1388
constexpr int8_t as_int8() const
Definition mdbx.h++:1040
constexpr ::std::span< char > chars()
Definition mdbx.h++:702
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1059
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1318
static constexpr size_t round(const size_t value)
Definition mdbx.h++:1170
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1286
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++:1452
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:2634
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1419
const slice source
Definition mdbx.h++:1249
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:2648
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:701
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1431
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++:1243
uint8_t as_uint8_adapt() const
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:681
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:1439
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++:1409
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:732
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++:757
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1376
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:646
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:2680
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1350
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++:2656
bool done
Definition mdbx.h++:2678
::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++:1289
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:699
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:715
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:1212
const bool uppercase
Definition mdbx.h++:1203
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:1357
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:1259
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:1305
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:1396
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2721
const bool ignore_spaces
Definition mdbx.h++:1430
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1298
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++:1007
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++:1035
slice key
Definition mdbx.h++:2646
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:2647
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2727
const slice source
Definition mdbx.h++:1429
pair_result & operator=(const pair_result &) 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++:1335
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2693
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from hexadecimal dump from a passed slice.
constexpr int32_t as_int32() const
Definition mdbx.h++:1038
int64_t as_int64_adapt() const
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2719
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1032
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2694
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1029
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2715
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid hexadecimal dump, and therefore there could b...
const unsigned wrap_width
Definition mdbx.h++:1250
const unsigned wrap_width
Definition mdbx.h++:1296
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:1403
uint32_t as_uint32_adapt() const
constexpr bool is_valid() const noexcept
Checks the slice is not refers to null address or has zero length.
Definition mdbx.h++:1004
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++:2730
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++:708
int16_t as_int16_adapt() const
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2692
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid data and could be encoded or unexpectedly not...
Definition mdbx.h++:1339
uint64_t as_uint64_adapt() const
constexpr buffer_pair_spec() noexcept=default
constexpr to_base58(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1252
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:710
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++:1224
bool done
Definition mdbx.h++:2633
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by Base58 dump of passed slice.
const slice source
Definition mdbx.h++:1348
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc=ALLOCATOR())
Definition mdbx.h++:2581
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc=ALLOCATOR())
Definition mdbx.h++:2603
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:2761
inline ::std::ostream & operator<<(::std::ostream &out, const to_hex &wrapper)
Definition mdbx.h++:1342
buffer_pair_spec< typename BUFFER::allocator_type, typename BUFFER::reservation_policy > buffer_pair
Combines pair of buffers for key and value to hold an operands for certain operations.
Definition mdbx.h++:2758
Definition mdbx.h++:2690
Type tag for delivered buffer template classes.
Definition mdbx.h++:1470
Definition mdbx.h++:1162
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1385
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1428
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1347
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:2644
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:2677
References a data located outside the slice.
Definition mdbx.h++:641
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1248
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1294
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1201
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:2631
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:523
remote_media(const ::mdbx::error &)
dangling_map_id(const ::mdbx::error &)
constexpr friend bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4624
fatal(const ::mdbx::error &) noexcept
reader_slot_busy(const ::mdbx::error &)
exception(const exception &)=default
::std::string message() const
Returns message for any errors.
not_found(const ::mdbx::error &)
operation_not_permitted(const ::mdbx::error &)
key_exists(const ::mdbx::error &)
permission_denied_or_not_writeable(const ::mdbx::error &)
void throw_exception() const
fatal(const exception &src) noexcept
Definition mdbx.h++:522
no_data(const ::mdbx::error &)
transaction_full(const ::mdbx::error &)
exception(exception &&)=default
db_too_large(const ::mdbx::error &)
bad_map_id(const ::mdbx::error &)
transaction_overlapping(const ::mdbx::error &)
void panic(const char *context_where_when, const char *func_who_what) const noexcept
Panics on unrecoverable errors inside destructors etc.
static void success_or_throw(int error_code)
Definition mdbx.h++:491
db_full(const ::mdbx::error &)
duplicated_lck_file(const ::mdbx::error &)
const ::mdbx::error error() const noexcept
Definition mdbx.h++:513
error(const error &)=default
virtual ~fatal() noexcept
something_busy(const ::mdbx::error &)
fatal & operator=(fatal &&)=default
const char * what() const noexcept
Returns message for MDBX's errors only and "SYSTEM" for others.
fatal(const fatal &src) noexcept
Definition mdbx.h++:524
transaction_ousted(const ::mdbx::error &)
key_mismatch(const ::mdbx::error &)
db_invalid(const ::mdbx::error &)
exception & operator=(exception &&)=default
db_wanna_write_for_recovery(const ::mdbx::error &)
error & operator=(error &&)=default
bad_transaction(const ::mdbx::error &)
internal_problem(const ::mdbx::error &)
multivalue(const ::mdbx::error &)
fatal(fatal &&src) noexcept
Definition mdbx.h++:525
fatal & operator=(const fatal &)=default
max_readers_reached(const ::mdbx::error &)
db_version_mismatch(const ::mdbx::error &)
exception_thunk() noexcept=default
exception & operator=(const exception &)=default
exception(const ::mdbx::error &) noexcept
db_unable_extend(const ::mdbx::error &)
constexpr friend bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4622
error & operator=(const error &)=default
virtual ~exception() noexcept
error(error &&)=default
thread_mismatch(const ::mdbx::error &)
db_corrupted(const ::mdbx::error &)
internal_page_full(const ::mdbx::error &)
mvcc_retarded(const ::mdbx::error &)
max_maps_reached(const ::mdbx::error &)
bad_value_size(const ::mdbx::error &)
Implements error information and throwing corresponding exceptions.
Definition mdbx.h++:450
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:435
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:531
LIBMDBX_API void throw_incomparable_cursors()
LIBMDBX_API void throw_out_range()
LIBMDBX_API void throw_bad_value_size()
LIBMDBX_API void throw_max_length_exceeded()
LIBMDBX_API void throw_too_small_target_buffer()
uint64_t mdbx_key_from_int64(const int64_t i64)
Definition mdbx.h:4710
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:4714
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition mdbx.h++:174
#define MDBX_CXX17_FALLTHROUGH
Definition mdbx.h++:232
#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME)
Definition mdbx.h++:112
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:272
#define MDBX_LIKELY(cond)
Definition mdbx.h++:207
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:184
#define MDBX_UNLIKELY(cond)
Definition mdbx.h++:215
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:163
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:202
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:223
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:183
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:238
The libmdbx C API header file.
Definition mdbx.h++:1064
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1066
The libmdbx C++ API namespace.
Definition mdbx.h++:305
STL namespace.
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1563
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1565
byte lastbyte_
Definition mdbx.h++:1564
Definition mdbx.h++:4186
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4188
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4187
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4190
Definition mdbx.h++:4174
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++:4178
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4176
Tagged type for output to std::ostream.
Definition mdbx.h++:3013
intptr_t bytes
Definition mdbx.h++:3014
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3015
Database geometry for size management.
Definition mdbx.h++:2989
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3037
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3049
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:2996
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:2992
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:2995
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3004
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:2993
@ default_value
Means "keep current or use default".
Definition mdbx.h++:2991
@ kB
bytes (0x03E8)
Definition mdbx.h++:2994
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3003
@ KiB
bytes (0x0400)
Definition mdbx.h++:3002
constexpr geometry() noexcept
Definition mdbx.h++:3053
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3040
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3025
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3043
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3020
constexpr geometry(intptr_t size_lower, intptr_t size_now=default_value, intptr_t size_upper=default_value, intptr_t growth_step=default_value, intptr_t shrink_threshold=default_value, intptr_t pagesize=default_value) noexcept
Definition mdbx.h++:3056
Operate options.
Definition mdbx.h++:3093
bool disable_readahead
Definition mdbx.h++:3102
bool enable_validation
Definition mdbx.h++:3106
bool no_sticky_threads
Definition mdbx.h++:3095
constexpr operate_options() noexcept
Definition mdbx.h++:3107
bool disable_clear_memory
Definition mdbx.h++:3104
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3100
constexpr operate_options(const operate_options &) noexcept=default
bool nested_write_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3098
operate_options(MDBX_env_flags_t) noexcept
Operate parameters.
Definition mdbx.h++:3115
env::durability durability
Definition mdbx.h++:3123
env::operate_options options
Definition mdbx.h++:3125
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++:3129
static env::mode mode_from_flags(MDBX_env_flags_t) noexcept
constexpr operate_parameters & operator=(const operate_parameters &) noexcept=default
unsigned max_readers
The maximum number of threads/reader slots for the environment. Zero means default value.
Definition mdbx.h++:3121
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3124
env::mode mode
Definition mdbx.h++:3122
static env::durability durability_from_flags(MDBX_env_flags_t) noexcept
unsigned max_maps
The maximum number of named tables/maps for the environment. Zero means default value.
Definition mdbx.h++:3118
constexpr operate_parameters() noexcept
Definition mdbx.h++:3127
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3495
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3498
uint64_t transaction_lag
Definition mdbx.h++:3501
size_t bytes_used
Definition mdbx.h++:3505
uint64_t transaction_id
Definition mdbx.h++:3499
int slot
The reader lock table slot number.
Definition mdbx.h++:3496
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3497
size_t bytes_retained
Definition mdbx.h++:3508
Garbage reclaiming options.
Definition mdbx.h++:3080
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
bool coalesce
Definition mdbx.h++:3084
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3085
bool lifo
Definition mdbx.h++:3082
Additional parameters for creating a new database.
Definition mdbx.h++:3604
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3606
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3607
env::geometry geometry
Definition mdbx.h++:3605
Definition mdbx.h++:2927
map_handle::state state
Definition mdbx.h++:2929
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2928
info & operator=(const info &) noexcept=default
capacity_holder capacity_
Definition mdbx.h++:1569
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1602
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1581
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1622
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1573
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1588
inplace_flag_holder inplace_
Definition mdbx.h++:1570
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1572
allocator_pointer allocated_ptr_
Definition mdbx.h++:1568
size_t stub_capacity_bytes_
Definition mdbx.h++:1545
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1641
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1558
size_t bytes_
Definition mdbx.h++:1559
constexpr const byte * address() const noexcept
Definition mdbx.h++:1635
constexpr bin() noexcept
Definition mdbx.h++:1616
@ inplace_size
Definition mdbx.h++:1553
@ inplace_signature_limit
Definition mdbx.h++:1550
@ inplace_size_rounding
Definition mdbx.h++:1552
constexpr byte * address() noexcept
Definition mdbx.h++:1638
@ lastbyte_poison
Definition mdbx.h++:1548
@ lastbyte_inplace_signature
Definition mdbx.h++:1548
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1631
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1590
allocator_pointer ptr_
Definition mdbx.h++:1544