libmdbx 0.14.1.191 (2025-12-18T19:20:08+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
24
25#pragma once
26
27/* Workaround for modern libstdc++ with CLANG < 4.x */
28#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4
29#define __GLIBCXX_BITSIZE_INT_N_0 128
30#define __GLIBCXX_TYPE_INT_N_0 __int128
31#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
32
33#if !defined(__cplusplus) || __cplusplus < 201103L
34#if !defined(_MSC_VER) || _MSC_VER < 1900
35#error "C++11 compiler or better is required"
36#elif _MSC_VER >= 1910
37#error "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
38#endif /* MSVC is mad and don't define __cplusplus properly */
39#endif /* __cplusplus < 201103L */
40
41#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
42#error "CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
43#endif /* Windows */
44
45#ifndef __has_include
46#define __has_include(header) (0)
47#endif /* __has_include */
48
49#if __has_include(<version>)
50#include <version>
51#endif /* <version> */
52
53/* Disable min/max macros from C' headers */
54#ifndef NOMINMAX
55#define NOMINMAX
56#endif
57
58#include <algorithm> // for std::min/max
59#include <cassert> // for assert()
60#include <climits> // for CHAR_BIT
61#include <cstring> // for std::strlen, str:memcmp
62#include <exception> // for std::exception_ptr
63#include <ostream> // for std::ostream
64#include <sstream> // for std::ostringstream
65#include <stdexcept> // for std::invalid_argument
66#include <string> // for std::string
67#include <type_traits> // for std::is_pod<>, etc.
68#include <utility> // for std::make_pair
69#include <vector> // for std::vector<> as template args
70
71#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
72#include <memory_resource>
73#endif
74
75#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
76#include <string_view>
77#endif
78
79#ifndef MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
80#ifdef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
81#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
82#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && __cplusplus >= 201703L
83#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
84#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
85 (defined(_MSC_VER) && defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && __cplusplus >= 201403L))
86#if defined(__cpp_lib_experimental_filesystem) && __cpp_lib_experimental_filesystem >= 201406L
87#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
88#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && __has_include(<experimental/filesystem>)
89#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
90#else
91#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
92#endif
93#else
94#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
95#endif
96#endif /* MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM */
97
98#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
99#include <experimental/filesystem>
100#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
101#include <filesystem>
102#endif
103
104#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
105#include <span>
106#endif
107
108#if !defined(_MSC_VER) || defined(__clang__)
109/* adequate compilers */
110#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) extern template class API_ATTRIBUTES API_TYPENAME
111#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) template class API_TYPENAME
112#else
113/* stupid microsoft showing off */
114#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) extern template class API_TYPENAME
115#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) template class API_ATTRIBUTES API_TYPENAME
116#endif
117
118#if __cplusplus >= 201103L
119#include <chrono>
120#include <ratio>
121#endif
122
123#include "mdbx.h"
124
125#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
126 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
127 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
128 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
129#include <bit>
130#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
131#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
132#define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
133#define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
134#define __BYTE_ORDER__ __BYTE_ORDER
135#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
136#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
137#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
138#define __BYTE_ORDER__ _BYTE_ORDER
139#else
140#define __ORDER_LITTLE_ENDIAN__ 1234
141#define __ORDER_BIG_ENDIAN__ 4321
142#if defined(__LITTLE_ENDIAN__) || (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || defined(__ARMEL__) || \
143 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
144 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || defined(__elbrus_4c__) || defined(__elbrus_8c__) || \
145 defined(__bfin__) || defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
146 defined(__ia64) || defined(_M_IA64) || defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
147 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || defined(__WINDOWS__)
148#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
149#elif defined(__BIG_ENDIAN__) || (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || defined(__ARMEB__) || \
150 defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
151 defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
152 defined(__sparc__) || defined(__sparc) || defined(__370__) || defined(__THW_370__) || defined(__s390__) || \
153 defined(__s390x__) || defined(__SYSC_ZARCH__)
154#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
155#endif
156#endif
157#endif /* Byte Order */
158
160#if defined(DOXYGEN)
161#define MDBX_CXX17_CONSTEXPR constexpr
162#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
163 ((defined(_MSC_VER) && _MSC_VER >= 1915) || (defined(__clang__) && __clang_major__ > 5) || \
164 (defined(__GNUC__) && __GNUC__ > 7) || (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
165#define MDBX_CXX17_CONSTEXPR constexpr
166#else
167#define MDBX_CXX17_CONSTEXPR inline
168#endif /* MDBX_CXX17_CONSTEXPR */
169
171#if defined(DOXYGEN)
172#define MDBX_CXX20_CONSTEXPR constexpr
173#elif defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L && \
174 defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
175#define MDBX_CXX20_CONSTEXPR constexpr
176#else
177#define MDBX_CXX20_CONSTEXPR inline
178#endif /* MDBX_CXX20_CONSTEXPR */
179
180#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
181#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
182#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
183#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
184#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
185#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
186#else
187#define MDBX_CXX01_CONSTEXPR_ENUM inline
188#define MDBX_CXX11_CONSTEXPR_ENUM inline
189#define MDBX_CXX14_CONSTEXPR_ENUM inline
190#define MDBX_CXX17_CONSTEXPR_ENUM inline
191#define MDBX_CXX20_CONSTEXPR_ENUM inline
192#endif /* CONSTEXPR_ENUM_FLAGS_OPERATIONS */
193
195#if defined(CONSTEXPR_ASSERT)
196#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
197#elif defined NDEBUG
198#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
199#else
200#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
201#endif /* MDBX_CONSTEXPR_ASSERT */
202
203#ifndef MDBX_LIKELY
204#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
205#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
206#else
207#define MDBX_LIKELY(x) (x)
208#endif
209#endif /* MDBX_LIKELY */
210
211#ifndef MDBX_UNLIKELY
212#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
213#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
214#else
215#define MDBX_UNLIKELY(x) (x)
216#endif
217#endif /* MDBX_UNLIKELY */
218
220#if defined(DOXYGEN)
221#define MDBX_IF_CONSTEXPR constexpr
222#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
223#define MDBX_IF_CONSTEXPR constexpr
224#else
225#define MDBX_IF_CONSTEXPR
226#endif /* MDBX_IF_CONSTEXPR */
227
228#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
229 __cplusplus >= 201703L
230#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
231#else
232#define MDBX_CXX17_FALLTHROUGH
233#endif /* MDBX_CXX17_FALLTHROUGH */
234
235#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
236#define MDBX_CXX20_LIKELY [[likely]]
237#else
238#define MDBX_CXX20_LIKELY
239#endif /* MDBX_CXX20_LIKELY */
240
241#ifndef MDBX_CXX20_UNLIKELY
242#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
243#define MDBX_CXX20_UNLIKELY [[unlikely]]
244#else
245#define MDBX_CXX20_UNLIKELY
246#endif
247#endif /* MDBX_CXX20_UNLIKELY */
248
249#ifndef MDBX_HAVE_CXX20_CONCEPTS
250#if defined(__cpp_concepts) && __cpp_concepts >= 202002L && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
251#include <concepts>
252#define MDBX_HAVE_CXX20_CONCEPTS 1
253#elif defined(DOXYGEN)
254#define MDBX_HAVE_CXX20_CONCEPTS 1
255#else
256#define MDBX_HAVE_CXX20_CONCEPTS 0
257#endif /* <concepts> */
258#endif /* MDBX_HAVE_CXX20_CONCEPTS */
259
260#ifndef MDBX_CXX20_CONCEPT
261#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
262#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
263#else
264#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
265#endif
266#endif /* MDBX_CXX20_CONCEPT */
267
268#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
269#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
270#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
271#else
272#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
273 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
274#endif
275#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
276
277#ifdef _MSC_VER
278#pragma warning(push, 4)
279#pragma warning(disable : 4127) /* conditional expression is constant */
280#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
281 be used by clients of 'mdbx::BAR' */
282#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
283 base for dll-interface 'mdbx::BAR' */
284/* MSVC is mad and can generate this warning for its own intermediate
285 * automatically generated code, which becomes unreachable after some kinds of
286 * optimization (copy elision, etc). */
287#pragma warning(disable : 4702) /* unreachable code */
288#endif /* _MSC_VER (warnings) */
289
290#if defined(__LCC__) && __LCC__ >= 126
291#pragma diagnostic push
292#if __LCC__ < 127
293#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
294 appearing in a constant expression `true` */
295#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
296 appearing in a constant expression `false` */
297#endif
298#endif /* E2K LCC (warnings) */
299
300//------------------------------------------------------------------------------
303namespace mdbx {
304
307
308// Functions whose signature depends on the `mdbx::byte` type
309// must be strictly defined as inline!
310#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
311// To enable all kinds of an compiler optimizations we use a byte-like type
312// that don't presumes aliases for pointers as does the `char` type and its
313// derivatives/typedefs.
314// Please see https://libmdbx.dqdkfa.ru/dead-github/issues/263
315// for reasoning of the use of `char8_t` type and switching to `__restrict__`.
316using byte = char8_t;
317#else
318// Avoid `std::byte` since it doesn't add features but inconvenient
319// restrictions.
320using byte = unsigned char;
321#endif /* __cpp_char8_t >= 201811*/
322
323#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
324using endian = ::std::endian;
325#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
326enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
327#else
328#error "Please use a C++ compiler provides byte order information or C++20 support"
329#endif /* Byte Order enum */
330
339
341static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
342
344static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
346static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
347
350using legacy_allocator = ::std::string::allocator_type;
351
352#if defined(DOXYGEN) || \
353 (defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI)
355using polymorphic_allocator = ::std::pmr::string::allocator_type;
357#else
359#endif /* __cpp_lib_memory_resource >= 201603L */
360
361struct slice;
363template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy> class buffer;
364class env;
365class env_managed;
366class txn;
367class txn_managed;
368class cursor;
369class cursor_managed;
370
372using txnid = uint64_t;
373
376
378template <class ALLOCATOR = default_allocator>
379using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
380
382#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
383#ifdef _MSC_VER
384namespace filesystem = ::std::experimental::filesystem::v1;
385#else
386namespace filesystem = ::std::experimental::filesystem;
387#endif
388#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
389#elif defined(DOXYGEN) || \
390 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
391 __cpp_lib_string_view >= 201606L && \
392 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
393 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
394 (!defined(_MSC_VER) || __cplusplus >= 201703L)
395namespace filesystem = ::std::filesystem;
401#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
402#endif /* MDBX_STD_FILESYSTEM_PATH */
403
404#ifdef MDBX_STD_FILESYSTEM_PATH
406#elif defined(_WIN32) || defined(_WIN64)
407using path = ::std::wstring;
408#else
409using path = ::std::string;
410#endif /* mdbx::path */
411
412#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
413#ifndef MDBX_U128_TYPE
414#define MDBX_U128_TYPE __uint128_t
415#endif /* MDBX_U128_TYPE */
416#ifndef MDBX_I128_TYPE
417#define MDBX_I128_TYPE __int128_t
418#endif /* MDBX_I128_TYPE */
419#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
420
421#if __cplusplus >= 201103L || defined(DOXYGEN)
423using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
424#endif /* Duration for C++11 */
425
428
434 ::std::exception_ptr captured_;
435
436public:
437 exception_thunk() noexcept = default;
440 exception_thunk &operator=(const exception_thunk &) = delete;
441 exception_thunk &operator=(exception_thunk &&) = delete;
442 inline bool is_clean() const noexcept;
443 inline void capture() noexcept;
444 inline void rethrow_captured() const;
445};
446
449 MDBX_error_t code_;
450 inline error &operator=(MDBX_error_t error_code) noexcept;
451
452public:
453 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
454 error(const error &) = default;
455 error(error &&) = default;
456 error &operator=(const error &) = default;
457 error &operator=(error &&) = default;
458
459 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
460 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
461
462 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
463 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
464 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
465 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
466
468 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
469
471 const char *what() const noexcept;
472
474 ::std::string message() const;
475
477 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
479 [[noreturn]] void panic(const char *context_where_when, const char *func_who_what) const noexcept;
480 [[noreturn]] void throw_exception() const;
481 [[noreturn]] static inline void throw_exception(int error_code);
482 inline void throw_on_failure() const;
483 inline void success_or_throw() const;
484 inline void success_or_throw(const exception_thunk &) const;
485 inline void panic_on_failure(const char *context_where, const char *func_who) const noexcept;
486 inline void success_or_panic(const char *context_where, const char *func_who) const noexcept;
487 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
488 static inline void success_or_throw(MDBX_error_t error_code);
489 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
490 static inline void throw_on_failure(int error_code);
491 static inline bool boolean_or_throw(int error_code);
492 static inline void success_or_throw(int error_code, const exception_thunk &);
493 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
494 static inline void panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept;
495 static inline void success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept;
496};
497
500class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
501 using base = ::std::runtime_error;
502 ::mdbx::error error_;
503
504public:
505 exception(const ::mdbx::error &) noexcept;
506 exception(const exception &) = default;
507 exception(exception &&) = default;
508 exception &operator=(const exception &) = default;
510 virtual ~exception() noexcept;
511 const ::mdbx::error error() const noexcept { return error_; }
512};
513
516 using base = exception;
517
518public:
519 fatal(const ::mdbx::error &) noexcept;
520 fatal(const exception &src) noexcept : fatal(src.error()) {}
521 fatal(exception &&src) noexcept : fatal(src.error()) {}
522 fatal(const fatal &src) noexcept : fatal(src.error()) {}
523 fatal(fatal &&src) noexcept : fatal(src.error()) {}
524 fatal &operator=(fatal &&) = default;
525 fatal &operator=(const fatal &) = default;
526 virtual ~fatal() noexcept;
527};
528
529#define MDBX_DECLARE_EXCEPTION(NAME) \
530 struct LIBMDBX_API_TYPE NAME : public exception { \
531 NAME(const ::mdbx::error &); \
532 virtual ~NAME() noexcept; \
533 }
566#undef MDBX_DECLARE_EXCEPTION
567
570[[noreturn]] LIBMDBX_API void throw_out_range();
574static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes);
575static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload);
576static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom);
577
579
580//------------------------------------------------------------------------------
581
584
585#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
586
590template <typename T>
591concept MutableByteProducer = requires(T a, char array[42]) {
592 { a.is_empty() } -> std::same_as<bool>;
593 { a.envisage_result_length() } -> std::same_as<size_t>;
594 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
595};
596
600template <typename T>
601concept ImmutableByteProducer = requires(const T &a, char array[42]) {
602 { a.is_empty() } -> std::same_as<bool>;
603 { a.envisage_result_length() } -> std::same_as<size_t>;
604 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
605};
606
610template <typename T>
611concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
612 T(source);
613 { a.is_erroneous() } -> std::same_as<bool>;
614};
615
616#endif /* MDBX_HAVE_CXX20_CONCEPTS */
617
618template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy,
619 MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
620inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc = ALLOCATOR());
621
622template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy,
623 MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
624inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc = ALLOCATOR());
625
626template <class ALLOCATOR = default_allocator, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
627inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc = ALLOCATOR());
628
629template <class ALLOCATOR = default_allocator, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
630inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc = ALLOCATOR());
631
643
644 enum : size_t { max_length = MDBX_MAXDATASIZE };
645
647 MDBX_CXX11_CONSTEXPR slice() noexcept;
648
650 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
651
653 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
654
656 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
657 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
658 }
659
660 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
661
664 template <class CHAR, class T, class A>
665 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
666 : slice(str.data(), str.length() * sizeof(CHAR)) {}
667
669 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
671 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
672
673#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
674 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
675 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
676 "Must be a standard layout type!");
677 }
678
679 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
680 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
681 "Must be a standard layout type!");
682 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
684 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
686 }
687
688 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
689 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
690 "Must be a standard layout type!");
691 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
693 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
695 }
696
697 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
698 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
699 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
700 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
701#endif /* __cpp_lib_span >= 202002L */
702
703#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
705 template <class CHAR, class T>
706 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv) : slice(sv.data(), sv.data() + sv.length()) {}
707
708 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
709#endif /* __cpp_lib_string_view >= 201606L */
710
711 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
712
713 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
714 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
715 "Must be a standard layout type!");
716 return slice(&pod, sizeof(pod));
717 }
718
719 inline slice &assign(const void *ptr, size_t bytes);
720 inline slice &assign(const slice &src) noexcept;
721 inline slice &assign(const ::MDBX_val &src);
722 inline slice &assign(slice &&src) noexcept;
723 inline slice &assign(::MDBX_val &&src);
724 inline slice &assign(const void *begin, const void *end);
725 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
726 return assign(str.data(), str.length() * sizeof(CHAR));
727 }
728 inline slice &assign(const char *c_str);
729#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
730 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
731 return assign(view.begin(), view.end());
732 }
733 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
734 assign(view);
735 view = {};
736 return *this;
737 }
738#endif /* __cpp_lib_string_view >= 201606L */
739
740 slice &operator=(const slice &) noexcept = default;
741 inline slice &operator=(slice &&src) noexcept;
742 inline slice &operator=(::MDBX_val &&src);
743 operator MDBX_val *() noexcept { return this; }
744 operator const MDBX_val *() const noexcept { return this; }
745
746#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
747 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
748 return assign(view);
749 }
750
751 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
752
754 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
755 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
756 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
757 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
758 }
759
761 template <class CHAR, class T>
762 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
763 return this->string_view<CHAR, T>();
764 }
765#endif /* __cpp_lib_string_view >= 201606L */
766
767 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
768 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
769 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
770 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
771 }
772
773 template <class CHAR, class T, class ALLOCATOR>
774 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
776 }
777
779 template <class ALLOCATOR = default_allocator>
780 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
781 const ALLOCATOR &alloc = ALLOCATOR()) const;
782
785 template <class ALLOCATOR = default_allocator>
786 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
787
790 template <class ALLOCATOR = default_allocator>
791 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
792
794 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
795 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
796 const ALLOCATOR &alloc = ALLOCATOR()) const;
797
800 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
801 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
802 const ALLOCATOR &alloc = ALLOCATOR()) const;
803
806 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
807 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
808 const ALLOCATOR &alloc = ALLOCATOR()) const;
809
811 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
812 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
813 const ALLOCATOR &alloc = ALLOCATOR()) const;
814
817 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
818 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
819 const ALLOCATOR &alloc = ALLOCATOR()) const;
820
823 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
824 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
825 const ALLOCATOR &alloc = ALLOCATOR()) const;
826
832 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
833
838 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
839
845 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
846
852 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
853
854#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
855 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
856 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
857 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
858 *this = view;
859 view = temp;
860 }
861#endif /* __cpp_lib_string_view >= 201606L */
862
864 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
865 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
866
868 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
869 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
870
872 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
873 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
874
876 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
877 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
878
880 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
881 MDBX_CXX11_CONSTEXPR void *data() noexcept;
882
884 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
885 MDBX_CXX11_CONSTEXPR void *end() noexcept;
886
888 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
889
891 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
892
894 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
895
897 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
898
900 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
901
903 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
904
906 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
907
909 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
910
912 MDBX_CXX14_CONSTEXPR void clear() noexcept;
913
916 inline void remove_prefix(size_t n) noexcept;
917
920 inline void remove_suffix(size_t n) noexcept;
921
924 inline void safe_remove_prefix(size_t n);
925
928 inline void safe_remove_suffix(size_t n);
929
931 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
932
934 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
935
938 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
939
942 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
943
946 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
947
950 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
951
954 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
955
958 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
959
962 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
963
966 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
967
972 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
973
982 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
983
989 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
990 const slice &b) noexcept;
991 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
992 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, 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#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
998 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
999#endif /* __cpp_impl_three_way_comparison */
1000
1002 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1003
1006 return slice(/* using special constructor without length checking */ ~size_t(0));
1007 }
1008
1010 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1011
1012 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1013 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1014 "Must be a standard layout type!");
1015 if (MDBX_LIKELY(size() == sizeof(POD)))
1017 POD r;
1018 memcpy(&r, data(), sizeof(r));
1019 return r;
1020 }
1022 }
1023
1024#ifdef MDBX_U128_TYPE
1025 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1026#endif /* MDBX_U128_TYPE */
1027 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1028 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1029 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1030 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1031
1032#ifdef MDBX_I128_TYPE
1033 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1034#endif /* MDBX_I128_TYPE */
1035 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1036 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1037 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1038 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1039
1040#ifdef MDBX_U128_TYPE
1041 MDBX_U128_TYPE as_uint128_adapt() const;
1042#endif /* MDBX_U128_TYPE */
1043 uint64_t as_uint64_adapt() const;
1044 uint32_t as_uint32_adapt() const;
1045 uint16_t as_uint16_adapt() const;
1046 uint8_t as_uint8_adapt() const;
1047
1048#ifdef MDBX_I128_TYPE
1049 MDBX_I128_TYPE as_int128_adapt() const;
1050#endif /* MDBX_I128_TYPE */
1051 int64_t as_int64_adapt() const;
1052 int32_t as_int32_adapt() const;
1053 int16_t as_int16_adapt() const;
1054 int8_t as_int8_adapt() const;
1055
1056protected:
1057 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1058};
1059
1060//------------------------------------------------------------------------------
1061
1063
1064template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1065#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1066 return ::std::allocator_traits<A>::is_always_equal::value;
1067#else
1068 return ::std::is_empty<A>::value;
1069#endif /* __cpp_lib_allocator_traits_is_always_equal */
1070}
1071
1072template <typename T, typename A = typename T::allocator_type,
1073 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1075
1076template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1077 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1078 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1079 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1080 }
1081 static MDBX_CXX20_CONSTEXPR void propagate(T *, T &) noexcept {}
1082};
1083
1084template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1085 static constexpr bool is_nothrow() noexcept {
1086 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1087 }
1088 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1089 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1090 target->get_allocator() = ::std::move(source.get_allocator());
1091 }
1092};
1093
1094template <typename T, typename A = typename T::allocator_type,
1095 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1097
1098template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1099 static constexpr bool is_nothrow() noexcept { return false; }
1100 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1101};
1102
1103template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1104 static constexpr bool is_nothrow() noexcept {
1105 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1106 }
1107 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1108 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1109 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1110 MDBX_CXX20_UNLIKELY target->get_allocator() =
1111 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1112 } else {
1113 /* gag for buggy compilers */
1114 (void)target;
1115 (void)source;
1116 }
1117 }
1118};
1119
1120template <typename T, typename A = typename T::allocator_type,
1121 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1123
1124template <typename T, typename A> struct swap_alloc<T, A, false> {
1125 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1126 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1128 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1129 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1130 } else {
1131 /* gag for buggy compilers */
1132 (void)left;
1133 (void)right;
1134 }
1135 }
1136};
1137
1138template <typename T, typename A> struct swap_alloc<T, A, true> {
1139 static constexpr bool is_nothrow() noexcept {
1140 return allocator_is_always_equal<A>() ||
1141#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1142 ::std::is_nothrow_swappable<A>() ||
1143#endif /* __cpp_lib_is_swappable >= 201603L */
1144 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1145 }
1146 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1147 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1148 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1149 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1150 } else {
1151 /* gag for buggy compilers */
1152 (void)left;
1153 (void)right;
1154 }
1155 }
1156};
1157
1158} // namespace allocation_aware_details
1159
1161 enum : size_t {
1166 };
1167
1168 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1169 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1170 static_assert(pettiness_threshold % 2 == 0, "pettiness_threshold must be even");
1171 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1172 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1173 return (value + pettiness_threshold - 1) & pettiness_mask;
1174 }
1175
1176 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1177 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1178 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1179
1180 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1181 return inplace;
1182
1183 if (wanna > current)
1184 /* doubling capacity, but don't made reserve more than max_reserve */
1185 return round(wanna + ::std::min(size_t(max_reserve), current));
1186
1187 if (current - wanna >
1188 /* shrink if reserve will more than half of current or max_reserve,
1189 * but not less than pettiness_threshold */
1190 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1191 return round(wanna);
1192
1193 /* keep unchanged */
1194 return current;
1195 }
1196};
1197
1201 const bool uppercase = false;
1202 const unsigned wrap_width = 0;
1207
1209 template <class ALLOCATOR = default_allocator>
1210 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1211 return make_string<ALLOCATOR>(*this, alloc);
1212 }
1213
1215 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1216 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1217 return make_buffer<ALLOCATOR>(*this, alloc);
1218 }
1219
1223 const size_t bytes = source.length() << 1;
1224 return wrap_width ? bytes + bytes / wrap_width : bytes;
1225 }
1226
1229 char *write_bytes(char *dest, size_t dest_size) const;
1230
1233 ::std::ostream &output(::std::ostream &out) const;
1234
1237 bool is_empty() const noexcept { return source.empty(); }
1238
1241 bool is_erroneous() const noexcept { return false; }
1242};
1243
1248 const unsigned wrap_width = 0;
1253
1256 template <class ALLOCATOR = default_allocator>
1257 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1258 return make_string<ALLOCATOR>(*this, alloc);
1259 }
1260
1263 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1264 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1265 return make_buffer<ALLOCATOR>(*this, alloc);
1266 }
1267
1271 const size_t bytes = (source.length() * 11 + 7) / 8;
1272 return wrap_width ? bytes + bytes / wrap_width : bytes;
1273 }
1274
1277 char *write_bytes(char *dest, size_t dest_size) const;
1278
1281 ::std::ostream &output(::std::ostream &out) const;
1282
1284 bool is_empty() const noexcept { return source.empty(); }
1285
1287 bool is_erroneous() const noexcept { return false; }
1288};
1289
1294 const unsigned wrap_width = 0;
1299
1302 template <class ALLOCATOR = default_allocator>
1303 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1304 return make_string<ALLOCATOR>(*this, alloc);
1305 }
1306
1309 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1310 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1311 return make_buffer<ALLOCATOR>(*this, alloc);
1312 }
1313
1317 const size_t bytes = (source.length() + 2) / 3 * 4;
1318 return wrap_width ? bytes + bytes / wrap_width : bytes;
1319 }
1320
1324 char *write_bytes(char *dest, size_t dest_size) const;
1325
1329 ::std::ostream &output(::std::ostream &out) const;
1330
1333 bool is_empty() const noexcept { return source.empty(); }
1334
1337 bool is_erroneous() const noexcept { return false; }
1338};
1339
1340inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
1341inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
1342inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
1343
1347 const bool ignore_spaces = false;
1352
1354 template <class ALLOCATOR = default_allocator>
1355 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1356 return make_string<ALLOCATOR>(*this, alloc);
1357 }
1358
1360 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1361 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1362 return make_buffer<ALLOCATOR>(*this, alloc);
1363 }
1364
1367 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1368
1371 char *write_bytes(char *dest, size_t dest_size) const;
1372
1374 bool is_empty() const noexcept { return source.empty(); }
1375
1378 bool is_erroneous() const noexcept;
1379};
1380
1385 const bool ignore_spaces = false;
1390
1393 template <class ALLOCATOR = default_allocator>
1394 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1395 return make_string<ALLOCATOR>(*this, alloc);
1396 }
1397
1400 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1401 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1402 return make_buffer<ALLOCATOR>(*this, alloc);
1403 }
1404
1408 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1409 }
1410
1414 char *write_bytes(char *dest, size_t dest_size) const;
1415
1417 bool is_empty() const noexcept { return source.empty(); }
1418
1421 bool is_erroneous() const noexcept;
1422};
1423
1428 const bool ignore_spaces = false;
1433
1436 template <class ALLOCATOR = default_allocator>
1437 string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
1438 return make_string<ALLOCATOR>(*this, alloc);
1439 }
1440
1443 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1444 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const {
1445 return make_buffer<ALLOCATOR>(*this, alloc);
1446 }
1447
1450 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1451
1455 char *write_bytes(char *dest, size_t dest_size) const;
1456
1459 bool is_empty() const noexcept { return source.empty(); }
1460
1464 bool is_erroneous() const noexcept;
1465};
1466
1468struct buffer_tag {};
1469
1471template <class ALLOCATOR, typename CAPACITY_POLICY> class buffer : public buffer_tag, public slice {
1472public:
1474#if !defined(_MSC_VER) || _MSC_VER > 1900
1475 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1476#else
1477 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1478#endif /* MSVC is mad */
1479 using allocator_traits = ::std::allocator_traits<allocator_type>;
1480 using reservation_policy = CAPACITY_POLICY;
1481 enum : size_t {
1483 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1486 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1487 ? alignof(max_align_t) * 2
1490 };
1491
1492private:
1493 friend class txn;
1494 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1495 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1496 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1497
1498 using allocator_pointer = typename allocator_traits::pointer;
1499 using allocator_const_pointer = typename allocator_traits::const_pointer;
1500
1501 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1502 assert(bytes >= sizeof(bin));
1503 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1504 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1505 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1506 const size_t n = (bytes + unit - 1) / unit;
1507 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1508 }
1509
1510 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1511 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1512 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1513 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1514 }
1515
1516 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1517 const size_t capacity = bin::advise_capacity(0, bytes);
1518 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1519 : allocate_storage(capacity);
1520 }
1521
1522 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1523#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1524 return static_cast<void *>(::std::to_address(ptr));
1525#else
1526 return static_cast<void *>(::std::addressof(*ptr));
1527#endif /* __cpp_lib_to_address */
1528 }
1529
1530 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1531#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1532 return static_cast<const void *>(::std::to_address(ptr));
1533#else
1534 return static_cast<const void *>(::std::addressof(*ptr));
1535#endif /* __cpp_lib_to_address */
1536 }
1537
1538 union alignas(max_align_t) bin {
1539 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1540 с учетом выравнивания */
1541 {
1542 allocator_pointer ptr_;
1544 };
1545
1547 enum : size_t {
1549 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1553 };
1554
1556 byte pad_[inplace_size - sizeof(allocator_pointer)];
1557 size_t bytes_;
1558 };
1559
1561 byte buffer_[inplace_size - sizeof(byte)];
1563 MDBX_CXX11_CONSTEXPR inplace_flag_holder(byte signature) : lastbyte_(signature) {};
1564 };
1565
1566 allocator_pointer allocated_ptr_;
1569
1570 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1571 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1572 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1573 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1574 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1575 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1576 return capacity_bytes <= inplace_capacity();
1577 }
1578
1579 constexpr bool is_inplace() const noexcept {
1580 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1581 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1583 "WTF?");
1584 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1585 }
1586 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1587
1588 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1589 if (destroy_ptr) {
1591 /* properly destroy allocator::pointer */
1592 allocated_ptr_.~allocator_pointer();
1593 }
1596 return address();
1597 }
1598
1599 template <bool construct_ptr>
1600 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1602 if (construct_ptr) {
1604 new (&allocated_ptr_) allocator_pointer(pair.first);
1605 } else {
1607 allocated_ptr_ = pair.first;
1608 }
1609 capacity_.bytes_ = pair.second;
1610 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1611 return address();
1612 }
1613
1615 if (::std::is_trivial<allocator_pointer>::value)
1616 /* workaround for "uninitialized" warning from some compilers */
1617 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1618 }
1619
1620 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1621 if (MDBX_UNLIKELY(wanna > max_capacity))
1622 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1623
1624 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1625 assert(advised >= wanna);
1626 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1627 }
1628
1629 constexpr bool is_inplace(const void *ptr) const noexcept {
1630 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1631 }
1632
1633 constexpr const byte *address() const noexcept {
1634 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1635 }
1637 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1638 }
1639 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1640 } bin_;
1641
1642 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1643
1644 MDBX_CXX20_CONSTEXPR void release() noexcept {
1645 if (bin_.is_allocated()) {
1646 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1647 /* properly destroy allocator::pointer */
1648 bin_.allocated_ptr_.~allocator_pointer();
1649 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1650 }
1651 }
1652
1653 template <bool external_content>
1654 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1655 const void *const content, const size_t length) {
1656 assert(wanna_capacity >= wanna_headroom + length);
1657 const size_t old_capacity = bin_.capacity();
1658 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1659 if (MDBX_LIKELY(new_capacity == old_capacity))
1661 assert(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1662 byte *const new_place = bin_.address() + wanna_headroom;
1663 if (MDBX_LIKELY(length))
1665 if (external_content)
1666 memcpy(new_place, content, length);
1667 else {
1668 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1669 assert(old_capacity >= old_headroom + length);
1670 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1671 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1672 }
1673 }
1674 return new_place;
1675 }
1676
1677 if (bin::is_suitable_for_inplace(new_capacity)) {
1678 assert(bin_.is_allocated());
1679 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1680 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1681 if (MDBX_LIKELY(length))
1682 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1683 deallocate_storage(old_allocated, old_capacity);
1684 return new_place;
1685 }
1686
1687 if (bin_.is_inplace()) {
1688 const auto pair = allocate_storage(new_capacity);
1689 assert(pair.second >= new_capacity);
1690 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1691 if (MDBX_LIKELY(length))
1692 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1693 bin_.template make_allocated<true>(pair);
1694 return new_place;
1695 }
1696
1697 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1698 if (external_content)
1699 deallocate_storage(old_allocated, old_capacity);
1700 const auto pair = allocate_storage(new_capacity);
1701 assert(pair.second >= new_capacity);
1702 byte *const new_place = bin_.template make_allocated<false>(pair) + wanna_headroom;
1703 if (MDBX_LIKELY(length))
1704 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1705 if (!external_content)
1706 deallocate_storage(old_allocated, old_capacity);
1707 return new_place;
1708 }
1709
1710 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1711 assert(capacity() >= offset);
1712 return bin_.address() + offset;
1713 }
1714 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1715 assert(capacity() >= offset);
1716 return bin_.address() + offset;
1717 }
1718 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1719 assert(capacity() >= offset + length);
1720 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1721 }
1722
1723 //--------------------------------------------------------------------------
1724
1725 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1726 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1727 if (!bin::is_suitable_for_inplace(capacity))
1728 bin_.template make_allocated<true>(provide_storage(capacity));
1729 }
1730
1731 silo(silo &&other) = delete;
1733 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1734 : allocator_type(::std::move(other.get_allocator())) {
1735 if (!is_reference) {
1736 if (other.bin_.is_inplace()) {
1737 memcpy(&bin_, &other.bin_, sizeof(bin));
1738 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1739 } else {
1740 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1741 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1742 /* properly destroy allocator::pointer.
1743 *
1744 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1745 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1746 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1747 * from the 11th). */
1748 /* coverity[use_after_move] */
1749 other.bin_.allocated_ptr_.~allocator_pointer();
1750 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1751 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1752 }
1753 }
1754 }
1755
1756 MDBX_CXX17_CONSTEXPR bool move(silo &&other) noexcept {
1757 if (other.bin_.is_inplace()) {
1758 memcpy(&bin_, &other.bin_, sizeof(bin));
1759 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1760 return /* buffer's slice fixup is needed */ true;
1761 }
1762 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1763 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1764 /* properly destroy allocator::pointer.
1765 *
1766 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1767 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1768 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1769 * from the 11th). */
1770 /* coverity[use_after_move] */
1771 other.bin_.allocated_ptr_.~allocator_pointer();
1772 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1773 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1774 return false;
1775 }
1776
1777 MDBX_CXX17_CONSTEXPR bool assign_move(silo &&other, bool is_reference) noexcept {
1778 release();
1779 if (!allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, other))
1780 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, other);
1781 return is_reference ? false : move(std::move(other));
1782 }
1783
1784 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1785 exchange(silo &left, const bool left_is_reference, silo &right, const bool right_is_reference) noexcept(
1786 allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1787 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(left, right);
1788 bool left_need_fixup = false, right_need_fixup = false;
1789 if (left_is_reference || right_is_reference) {
1790 left_need_fixup = !right_is_reference && left.move(std::move(right));
1791 right_need_fixup = !left_is_reference && right.move(std::move(left));
1792 } else {
1793 silo temp(std::move(left), false);
1794 left_need_fixup = left.move(std::move(right));
1795 right_need_fixup = right.move(std::move(temp));
1796 }
1797 return std::make_pair(left_need_fixup, right_need_fixup);
1798 }
1799
1800 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1801 const allocator_type &alloc = allocator_type())
1802 : silo(capacity, alloc) {
1803 assert(capacity >= headroom + length);
1804 if (length)
1805 put(headroom, ptr, length);
1806 }
1807
1808 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1809 : silo(length, 0, ptr, length, alloc) {}
1810
1811 ~silo() { release(); }
1812
1813 //--------------------------------------------------------------------------
1814
1815 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1816 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1817 }
1818
1819 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1820
1821 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1822 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1823 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1824 }
1825
1826 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1827 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1828 }
1829
1830 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1831 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1832 return get(offset);
1833 }
1834 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1835 };
1836
1837 MDBX_CXX14_CONSTEXPR void fixup_import(const typename silo::bin &src) noexcept {
1838 auto ptr = inherited::byte_ptr();
1839 if (src.is_inplace(ptr)) {
1840 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1841 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1842 iov_base = ptr + offset;
1843 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1844 }
1845 }
1846
1847 silo silo_;
1848
1849 void insulate() {
1850 assert(is_reference());
1851 iov_base = silo_.assign(iov_base, iov_len);
1852 }
1853
1854 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1855 return static_cast<const byte *>(silo_.data());
1856 }
1857
1858 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1859 return silo_begin() + silo_.capacity();
1860 }
1861
1862 struct data_preserver : public exception_thunk {
1863 buffer data;
1864 data_preserver(allocator_type &alloc) : data(alloc) {}
1865 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1866 auto self = static_cast<data_preserver *>(context);
1867 assert(self->is_clean());
1868 assert(&self->data == target);
1869 (void)target;
1870 try {
1871 self->data.assign(src, bytes, false);
1872 return MDBX_RESULT_FALSE;
1873 } catch (... /* capture any exception to rethrow it over C code */) {
1874 self->capture();
1875 return MDBX_RESULT_TRUE;
1876 }
1877 }
1878 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1879 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1880 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1881 };
1882
1883public:
1886
1890
1891 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1892
1894 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1895
1899 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1900 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1901 }
1902
1907 return silo_.is_inplace(inherited::data());
1908 }
1909
1913
1916 return is_freestanding() ? silo_.capacity() : 0;
1917 }
1918
1922 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
1923 }
1924
1928 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
1929 }
1930
1932 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
1933
1935 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
1936
1943
1948 return const_cast<byte *>(inherited::end_byte_ptr());
1949 }
1950
1952 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
1953
1955 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
1956
1961 return const_cast<char *>(inherited::char_ptr());
1962 }
1963
1968 return const_cast<char *>(inherited::end_char_ptr());
1969 }
1970
1972 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
1973
1975 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
1976
1979 MDBX_CXX11_CONSTEXPR void *data() noexcept {
1981 return const_cast<void *>(inherited::data());
1982 }
1983
1986 MDBX_CXX11_CONSTEXPR void *end() noexcept {
1988 return const_cast<void *>(inherited::end());
1989 }
1990
1995
2002
2005 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2006 return set_length(static_cast<const char *>(ptr) - char_ptr());
2007 }
2008
2013 if (is_reference())
2014 insulate();
2015 }
2016
2017 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2018 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2019
2021 buffer(const struct slice &src, bool make_reference, const allocator_type &alloc = allocator_type())
2022 : inherited(src), silo_(alloc) {
2023 if (!make_reference)
2024 insulate();
2025 }
2026
2028 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2029 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2030
2031 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2032 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2033
2034 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2035 : buffer(inherited(c_str), make_reference, alloc) {}
2036
2037#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2038 template <class CHAR, class T>
2039 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2040 const allocator_type &alloc = allocator_type())
2041 : buffer(inherited(view), make_reference, alloc) {}
2042#endif /* __cpp_lib_string_view >= 201606L */
2043
2045 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2046 : buffer(src, src.empty() || src.is_null(), alloc) {}
2047
2049 buffer(const buffer &src)
2050 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2051
2053 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2054 : buffer(inherited(ptr, bytes), alloc) {}
2055
2056 template <class CHAR, class T, class A>
2057 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2058 const allocator_type &alloc = allocator_type())
2059 : buffer(inherited(str), alloc) {}
2060
2062 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2063
2064#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2065 template <class CHAR, class T>
2066 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2067 const allocator_type &alloc = allocator_type())
2068 : buffer(inherited(view), alloc) {}
2069#endif /* __cpp_lib_string_view >= 201606L */
2070
2071 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2072 : silo_(check_length(head_room, tail_room), alloc) {
2073 iov_base = silo_.get();
2074 assert(iov_len == 0);
2075 }
2076
2077 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2078 iov_base = silo_.get();
2079 assert(iov_len == 0);
2080 }
2081
2082 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2083 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2084 iov_base = memcpy(silo_.get(), src.data(), iov_len = src.length());
2085 }
2086
2087 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2088
2089 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2090 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2091 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2092 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2093 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2094 * 11th). */
2095 /* coverity[use_after_move] */
2096 fixup_import(src.silo_.bin_);
2097 src.invalidate();
2098 }
2099
2101 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2102
2105
2106 template <typename POD>
2107 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2108 return buffer(inherited::wrap(pod), make_reference, alloc);
2109 }
2110
2112 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2113 const allocator_type &alloc = allocator_type()) {
2114 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2115 }
2116
2119 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2120 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2121 }
2122
2124 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2125 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2126 }
2127
2129 template <typename POD>
2130 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2131 const allocator_type &alloc = allocator_type()) {
2132 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2133 }
2134
2137 template <typename POD>
2138 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2139 return base58(inherited::wrap(pod), wrap_width, alloc);
2140 }
2141
2144 template <typename POD>
2145 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2146 return base64(inherited::wrap(pod), wrap_width, alloc);
2147 }
2148
2150 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2151 const allocator_type &alloc = allocator_type()) const {
2152 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2153 }
2154
2157 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2158 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2159 }
2160
2162 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2163 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2164 }
2165
2167 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2168 const allocator_type &alloc = allocator_type()) {
2169 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2170 }
2171
2174 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2175 const allocator_type &alloc = allocator_type()) {
2176 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2177 }
2178
2181 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2182 const allocator_type &alloc = allocator_type()) {
2183 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2184 }
2185
2188 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2189 return hex_decode(*this, ignore_spaces, alloc);
2190 }
2191
2194 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2195 return base58_decode(*this, ignore_spaces, alloc);
2196 }
2197
2200 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2201 return base64_decode(*this, ignore_spaces, alloc);
2202 }
2203
2205 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2206 wanna_headroom = ::std::min(
2207 ::std::max(headroom(), wanna_headroom),
2208 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2209 wanna_tailroom = ::std::min(
2210 ::std::max(tailroom(), wanna_tailroom),
2211 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2212 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2213 silo_.resize(wanna_capacity, wanna_headroom, *this);
2214 assert(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2215 assert(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2216 }
2217
2219 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2220
2222 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2223
2224 buffer &assign_reference(const void *ptr, size_t bytes) {
2225 silo_.clear();
2227 return *this;
2228 }
2229
2230 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2231 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2232 return *this;
2233 }
2234
2235 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2236 const auto pair = silo::exchange(silo_, is_reference(), other.silo_, other.is_reference());
2237 std::swap(iov_base, other.iov_base);
2238 std::swap(iov_len, other.iov_len);
2239 if (pair.first)
2240 fixup_import(other.silo_.bin_);
2241 if (pair.second)
2242 other.fixup_import(silo_.bin_);
2243 }
2244
2245 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2246 left.swap(right);
2247 }
2248
2249 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2250 return buffer(src.headroom(), src, src.tailroom(), alloc);
2251 }
2252
2254 return buffer(slice(), !is_inplace(), allocator_traits::select_on_container_copy_construction(get_allocator()));
2255 }
2256
2258 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2259 invalidate();
2260 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2261 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2262 MDBX_CXX20_UNLIKELY {
2263 silo_.release();
2265 }
2266 }
2267
2268 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2269 iov_len = src.length();
2270 return *this;
2271 }
2272
2273 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2274 invalidate();
2275 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2276 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2277 MDBX_CXX20_UNLIKELY {
2278 silo_.release();
2280 }
2281 }
2282
2283 if (make_reference) {
2284 silo_.release();
2285 iov_base = src.iov_base;
2286 } else {
2287 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2288 }
2289 iov_len = src.length();
2290 return *this;
2291 }
2292
2295 const bool is_reference = src.is_reference();
2296 inherited::assign(std::move(src));
2297 if (silo_.assign_move(std::move(src.silo_), is_reference))
2298 fixup_import(src.silo_.bin_);
2299 return *this;
2300 }
2301
2302 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2303 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2304 }
2305
2306 buffer &assign(const struct slice &src, bool make_reference = false) {
2307 return assign(src.data(), src.length(), make_reference);
2308 }
2309
2310 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2311 return assign(src.iov_base, src.iov_len, make_reference);
2312 }
2313
2314 buffer &assign(struct slice &&src, bool make_reference = false) {
2315 assign(src.data(), src.length(), make_reference);
2316 src.invalidate();
2317 return *this;
2318 }
2319
2320 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2321 assign(src.iov_base, src.iov_len, make_reference);
2322 src.iov_base = nullptr;
2323 return *this;
2324 }
2325
2326 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2327 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2328 }
2329
2330 template <class CHAR, class T, class A>
2331 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2332 return assign(str.data(), str.length(), make_reference);
2333 }
2334
2335 buffer &assign(const char *c_str, bool make_reference = false) {
2336 return assign(c_str, strlen(c_str), make_reference);
2337 }
2338
2339#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2340 template <class CHAR, class T>
2341 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2342 return assign(view.data(), view.length(), make_reference);
2343 }
2344
2345 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2346 assign(view.data(), view.length(), make_reference);
2347 view = {};
2348 return *this;
2349 }
2350#endif /* __cpp_lib_string_view >= 201606L */
2351
2352 buffer &operator=(const buffer &src) { return assign(src); }
2353
2354 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2355
2356 buffer &operator=(const struct slice &src) { return assign(src); }
2357
2358 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2359
2360#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2361 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2362 return assign(view.begin(), view.length());
2363 }
2364#endif /* __cpp_lib_string_view >= 201606L */
2365
2366 template <class CHAR, class T, class A>
2367 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2368 return as_string<CHAR, T, A>();
2369 }
2370
2372 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2373
2375 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2376 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2377 }
2378
2380 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2381
2382 buffer &append(const void *src, size_t bytes) {
2383 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2384 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2385 memcpy(end_byte_ptr(), src, bytes);
2386 iov_len += bytes;
2387 return *this;
2388 }
2389
2390 buffer &append(const byte c) {
2391 if (MDBX_UNLIKELY(tailroom() < 1))
2392 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2393 *end_byte_ptr() = c;
2394 iov_len += 1;
2395 return *this;
2396 }
2397
2398 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2399
2400 buffer &add_header(const void *src, size_t bytes) {
2401 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2402 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2403 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2404 iov_len += bytes;
2405 return *this;
2406 }
2407
2408 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2409
2410 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2411 const size_t wanna_bytes = producer.envisage_result_length();
2412 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2413 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2414 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2415 }
2416
2417 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2418 const size_t wanna_bytes = producer.envisage_result_length();
2419 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2420 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2421 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2422 }
2423
2424 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2425 return append_producer(to_hex(data, uppercase, wrap_width));
2426 }
2427
2428 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2429 return append_producer(to_base58(data, wrap_width));
2430 }
2431
2432 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2433 return append_producer(to_base64(data, wrap_width));
2434 }
2435
2436 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2437 return append_producer(from_hex(data, ignore_spaces));
2438 }
2439
2440 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2441 return append_producer(from_base58(data, ignore_spaces));
2442 }
2443
2444 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2445 return append_producer(from_base64(data, ignore_spaces));
2446 }
2447
2448 buffer &append_u8(uint_fast8_t u8) {
2449 if (MDBX_UNLIKELY(tailroom() < 1))
2450 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2451 *end_byte_ptr() = uint8_t(u8);
2452 iov_len += 1;
2453 return *this;
2454 }
2455
2456 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2457
2458 buffer &append_u16(uint_fast16_t u16) {
2459 if (MDBX_UNLIKELY(tailroom() < 2))
2460 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2461 const auto ptr = end_byte_ptr();
2462 ptr[0] = uint8_t(u16);
2463 ptr[1] = uint8_t(u16 >> 8);
2464 iov_len += 2;
2465 return *this;
2466 }
2467
2468 buffer &append_u24(uint_fast32_t u24) {
2469 if (MDBX_UNLIKELY(tailroom() < 3))
2470 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2471 const auto ptr = end_byte_ptr();
2472 ptr[0] = uint8_t(u24);
2473 ptr[1] = uint8_t(u24 >> 8);
2474 ptr[2] = uint8_t(u24 >> 16);
2475 iov_len += 3;
2476 return *this;
2477 }
2478
2479 buffer &append_u32(uint_fast32_t u32) {
2480 if (MDBX_UNLIKELY(tailroom() < 4))
2481 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2482 const auto ptr = end_byte_ptr();
2483 ptr[0] = uint8_t(u32);
2484 ptr[1] = uint8_t(u32 >> 8);
2485 ptr[2] = uint8_t(u32 >> 16);
2486 ptr[3] = uint8_t(u32 >> 24);
2487 iov_len += 4;
2488 return *this;
2489 }
2490
2491 buffer &append_u48(uint_fast64_t u48) {
2492 if (MDBX_UNLIKELY(tailroom() < 6))
2493 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2494 const auto ptr = end_byte_ptr();
2495 ptr[0] = uint8_t(u48);
2496 ptr[1] = uint8_t(u48 >> 8);
2497 ptr[2] = uint8_t(u48 >> 16);
2498 ptr[3] = uint8_t(u48 >> 24);
2499 ptr[4] = uint8_t(u48 >> 32);
2500 ptr[5] = uint8_t(u48 >> 40);
2501 iov_len += 6;
2502 return *this;
2503 }
2504
2505 buffer &append_u64(uint_fast64_t u64) {
2506 if (MDBX_UNLIKELY(tailroom() < 8))
2507 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2508 const auto ptr = end_byte_ptr();
2509 ptr[0] = uint8_t(u64);
2510 ptr[1] = uint8_t(u64 >> 8);
2511 ptr[2] = uint8_t(u64 >> 16);
2512 ptr[3] = uint8_t(u64 >> 24);
2513 ptr[4] = uint8_t(u64 >> 32);
2514 ptr[5] = uint8_t(u64 >> 40);
2515 ptr[6] = uint8_t(u64 >> 48);
2516 ptr[7] = uint8_t(u64 >> 56);
2517 iov_len += 8;
2518 return *this;
2519 }
2520
2521 //----------------------------------------------------------------------------
2522
2523 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2524 return buffer(inherited(text), make_reference);
2525 }
2526
2527#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2528 template <class CHAR, class T>
2529 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2530 return buffer(src, make_reference);
2531 }
2532#endif /* __cpp_lib_string_view >= 201606L */
2533
2534 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2535
2536 template <class CHAR, class T, class A>
2537 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2538 return buffer(src, make_reference);
2539 }
2540
2541 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2542
2543 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2544
2545 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2546
2547 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2548
2549 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2550
2551 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2552
2553 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2554
2555 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2556
2557 static buffer key_from_jsonInteger(const int64_t json_integer) {
2558 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2559 }
2560
2561 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2562
2563 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2564
2565 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2566
2567 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2568
2569 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2570
2571 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2572
2573 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2574
2575 const slice &slice() const noexcept { return *this; }
2576};
2577
2578template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2579inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
2580 if (MDBX_LIKELY(!producer.is_empty()))
2582 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
2583 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
2584 return result;
2585 }
2587}
2588
2589template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2590inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
2591 if (MDBX_LIKELY(!producer.is_empty()))
2593 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
2594 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
2595 return result;
2596 }
2598}
2599
2600template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2601inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
2602 string<ALLOCATOR> result(alloc);
2603 if (MDBX_LIKELY(!producer.is_empty()))
2605 result.resize(producer.envisage_result_length());
2606 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
2607 }
2608 return result;
2609}
2610
2611template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2612inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
2613 string<ALLOCATOR> result(alloc);
2614 if (MDBX_LIKELY(!producer.is_empty()))
2616 result.resize(producer.envisage_result_length());
2617 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
2618 }
2619 return result;
2620}
2621
2623
2624#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI
2626#endif /* __cpp_lib_memory_resource >= 201603L */
2627
2631 bool done;
2632 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
2633 value_result(const value_result &) noexcept = default;
2634 value_result &operator=(const value_result &) noexcept = default;
2635 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2636 assert(!done || bool(value));
2637 return done;
2638 }
2639};
2640
2642struct pair {
2643 using stl_pair = std::pair<slice, slice>;
2645 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
2646 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
2647 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
2648 pair(const pair &) noexcept = default;
2649 pair &operator=(const pair &) noexcept = default;
2650 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2651 assert(bool(key) == bool(value));
2652 return key;
2653 }
2655
2657 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
2658
2660 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
2661 const pair &b) noexcept;
2662 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
2663 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, 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#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2669 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
2670#endif /* __cpp_impl_three_way_comparison */
2671};
2672
2675struct pair_result : public pair {
2676 bool done;
2679 : pair(key, value), done(done) {}
2680 pair_result(const pair_result &) noexcept = default;
2681 pair_result &operator=(const pair_result &) noexcept = default;
2682 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2683 assert(!done || (bool(key) && bool(value)));
2684 return done;
2685 }
2686};
2687
2688template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2692 using reservation_policy = CAPACITY_POLICY;
2693 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2695
2698 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2699
2701 : key(key, alloc), value(value, alloc) {}
2702 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2703 const allocator_type &alloc = allocator_type())
2704 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2705
2707 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2708 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2709 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2710
2712 : key(key, alloc), value(value, alloc) {}
2713 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2714 const allocator_type &alloc = allocator_type())
2715 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2716
2719 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2720 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2721
2722 buffer_pair_spec(const txn &transacton, const slice &key, const slice &value,
2723 const allocator_type &alloc = allocator_type())
2724 : key(transacton, key, alloc), value(transacton, value, alloc) {}
2725 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2726 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2727
2728 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2729 : key(::std::move(key)), value(::std::move(value)) {}
2730 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2731 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2732
2736 return key.is_freestanding() && value.is_freestanding();
2737 }
2738
2741 return key.is_reference() || value.is_reference();
2742 }
2743
2747 key.make_freestanding();
2748 value.make_freestanding();
2749 }
2750
2751 operator pair() const noexcept { return pair(key, value); }
2752};
2753
2755template <typename BUFFER>
2757
2760
2762
2763//------------------------------------------------------------------------------
2764
2767enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2768
2785
2787 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2788}
2789
2791 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2792}
2793
2795 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2796}
2797
2799 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2800}
2801
2803
2861
2865
2867 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2868}
2869
2871 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2872}
2873
2875 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2876}
2877
2879 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2880}
2881
2883
2894 map_handle(const map_handle &) noexcept = default;
2895 map_handle &operator=(const map_handle &) noexcept = default;
2896 operator bool() const noexcept { return dbi != 0; }
2897 operator MDBX_dbi() const { return dbi; }
2898
2899#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2900 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2901 return a.dbi <=> b.dbi;
2902 }
2903#endif /* __cpp_impl_three_way_comparison */
2904 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2905 return a.dbi == b.dbi;
2906 }
2907 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2908 return a.dbi < b.dbi;
2909 }
2910 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2911 return a.dbi > b.dbi;
2912 }
2913 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2914 return a.dbi <= b.dbi;
2915 }
2916 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2917 return a.dbi >= b.dbi;
2918 }
2919 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2920 return a.dbi != b.dbi;
2921 }
2922
2934};
2935
2938 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2939}
2941 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2942}
2943
2950
2960 friend class txn;
2961
2962protected:
2964 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2965
2966public:
2967 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2968 env(const env &) noexcept = default;
2969 env &operator=(const env &) noexcept = default;
2970 inline env &operator=(env &&) noexcept;
2971 inline env(env &&) noexcept;
2972 inline ~env() noexcept;
2973
2974 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
2975 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
2976 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
2977 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
2978 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
2979
2980 //----------------------------------------------------------------------------
2981
2986
2988 enum : intptr_t {
2991 maximal_value = INTPTR_MAX,
2992 kB = 1000,
2993 MB = kB * 1000,
2994 GB = MB * 1000,
2995#if INTPTR_MAX > 0x7fffFFFFl
2996 TB = GB * 1000,
2997 PB = TB * 1000,
2998 EB = PB * 1000,
2999#endif /* 64-bit intptr_t */
3000 KiB = 1024,
3001 MiB = KiB << 10,
3002 GiB = MiB << 10,
3003#if INTPTR_MAX > 0x7fffFFFFl
3004 TiB = GiB << 10,
3005 PiB = TiB << 10,
3006 EiB = PiB << 10,
3007#endif /* 64-bit intptr_t */
3008 };
3009
3011 struct size {
3012 intptr_t bytes;
3013 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3014 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3015 };
3016
3019
3024
3036
3039
3042
3048
3049 inline geometry &make_fixed(intptr_t size) noexcept;
3050 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3053 geometry(const geometry &) noexcept = default;
3059 };
3060
3068
3076
3089
3111
3116 unsigned max_maps{0};
3119 unsigned max_readers{0};
3124
3135 operate_parameters(const operate_parameters &) noexcept = default;
3137 MDBX_env_flags_t make_flags(bool accede = true,
3140 bool use_subdirectory = false
3141 ) const;
3145 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3146 };
3147
3151 inline env::mode get_mode() const;
3153 inline env::durability get_durability() const;
3157 inline env::operate_options get_options() const;
3158
3161 bool is_pristine() const;
3162
3164 bool is_empty() const;
3165
3167 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3168
3169 struct limits {
3170 limits() = delete;
3172 static inline size_t pagesize_min() noexcept;
3174 static inline size_t pagesize_max() noexcept;
3176 static inline size_t dbsize_min(intptr_t pagesize);
3178 static inline size_t dbsize_max(intptr_t pagesize);
3180 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3182 static inline size_t key_min(key_mode mode) noexcept;
3184 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3186 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3188 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3190 static inline size_t key_max(const env &, key_mode mode);
3192 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3194 static inline size_t value_min(value_mode) noexcept;
3195
3197 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3199 static inline size_t value_max(intptr_t pagesize, value_mode);
3201 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3203 static inline size_t value_max(const env &, value_mode);
3204
3207 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3210 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3213 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3216 static inline size_t pairsize4page_max(const env &, value_mode);
3217
3220 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3223 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3226 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3229 static inline size_t valsize4page_max(const env &, value_mode);
3230
3233 static inline size_t transaction_size_max(intptr_t pagesize);
3234
3236 static inline size_t max_map_handles(void);
3237 };
3238
3240 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3242 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3244 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3246 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3248 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3250 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3254
3257#ifdef MDBX_STD_FILESYSTEM_PATH
3258 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3259#endif /* MDBX_STD_FILESYSTEM_PATH */
3260#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3261 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3262 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3263#endif /* Windows */
3264 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3265 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3266
3268 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3269
3285
3287#ifdef MDBX_STD_FILESYSTEM_PATH
3288 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3289#endif /* MDBX_STD_FILESYSTEM_PATH */
3290#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3291 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3292 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3293#endif /* Windows */
3294 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3295 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3296
3299
3302
3304 inline stat get_stat() const;
3305
3307 size_t get_pagesize() const { return get_stat().ms_psize; }
3308
3310 inline info get_info() const;
3311
3313 inline stat get_stat(const txn &) const;
3314
3316 inline info get_info(const txn &) const;
3317
3319 inline filehandle get_filehandle() const;
3320
3323
3325 inline MDBX_env_flags_t get_flags() const;
3326
3329 inline unsigned max_readers() const;
3330
3333 inline unsigned max_maps() const;
3334
3336 inline void *get_context() const noexcept;
3337
3339 inline env &set_context(void *your_context);
3340
3355 inline env &set_sync_threshold(size_t bytes);
3356
3362 inline size_t sync_threshold() const;
3363
3364#if __cplusplus >= 201103L || defined(DOXYGEN)
3384 inline env &set_sync_period(const duration &period);
3385
3391 inline duration sync_period() const;
3392#endif
3393
3397 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3398
3401 inline unsigned sync_period__seconds_16dot16() const;
3402
3406 inline env &set_sync_period__seconds_double(double seconds);
3407
3410 inline double sync_period__seconds_double() const;
3411
3449
3451 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3452
3454 inline uint64_t extra_option(extra_runtime_option option) const;
3455
3457 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3458
3460 inline env &set_geometry(const geometry &size);
3461
3465 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3466
3470 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3471
3490 inline void close_map(const map_handle &);
3491
3494 int slot;
3503 size_t bytes_used;
3512
3514 size_t used, size_t retained) noexcept;
3515 };
3516
3524 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3525
3528 inline unsigned check_readers();
3529
3548
3553 inline MDBX_hsr_func *get_HandleSlowReaders() const noexcept;
3554
3556 inline txn_managed start_read() const;
3557
3559 inline txn_managed prepare_read() const;
3560
3562 inline txn_managed start_write(txn &parent);
3563
3565 inline txn_managed start_write(bool dont_wait = false);
3566
3569};
3570
3579class LIBMDBX_API_TYPE env_managed : public env {
3580 using inherited = env;
3582 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3583 void setup(unsigned max_maps, unsigned max_readers = 0);
3584
3585public:
3586 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3587
3589#ifdef MDBX_STD_FILESYSTEM_PATH
3590 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3591#endif /* MDBX_STD_FILESYSTEM_PATH */
3592#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3593 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3594 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3595#endif /* Windows */
3596 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3597 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3598
3609
3611#ifdef MDBX_STD_FILESYSTEM_PATH
3613 bool accede = true);
3614#endif /* MDBX_STD_FILESYSTEM_PATH */
3615#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3616 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3617 bool accede = true);
3618 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3619 bool accede = true);
3620#endif /* Windows */
3621 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3622 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3623
3637 void close(bool dont_sync = false);
3638
3639 env_managed(env_managed &&) = default;
3640 env_managed &operator=(env_managed &&other) noexcept {
3642 MDBX_CXX20_UNLIKELY {
3643 assert(handle_ != other.handle_);
3644 close();
3645 }
3646 inherited::operator=(std::move(other));
3647 return *this;
3648 }
3649 env_managed(const env_managed &) = delete;
3650 env_managed &operator=(const env_managed &) = delete;
3651 virtual ~env_managed() noexcept;
3652};
3653
3662protected:
3663 friend class cursor;
3665 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3666
3667public:
3668 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3669 txn(const txn &) noexcept = default;
3670 txn &operator=(const txn &) noexcept = default;
3671 inline txn &operator=(txn &&) noexcept;
3672 inline txn(txn &&) noexcept;
3673 inline ~txn() noexcept;
3674
3675 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3676 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3677 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3678 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3679 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3680
3682 inline ::mdbx::env env() const noexcept;
3684 inline MDBX_txn_flags_t flags() const;
3686 inline uint64_t id() const;
3687
3689 inline void *get_context() const noexcept;
3690
3692 inline txn &set_context(void *your_context);
3693
3695 inline bool is_dirty(const void *ptr) const;
3696
3698 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3699
3701 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3702
3704 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3705
3708 inline info get_info(bool scan_reader_lock_table = false) const;
3709
3712 size_t size_max() const { return env().transaction_size_max(); }
3713
3715 size_t size_current() const {
3716 assert(is_readwrite());
3717 return size_t(get_info().txn_space_dirty);
3718 }
3719
3720 //----------------------------------------------------------------------------
3721
3723 inline void reset_reading();
3724
3726 inline void renew_reading();
3727
3729 inline void make_broken();
3730
3732 inline void park_reading(bool autounpark = true);
3733
3736 inline bool unpark_reading(bool restart_if_ousted = true);
3737
3740
3742 inline cursor_managed open_cursor(map_handle map) const;
3743
3745 inline size_t release_all_cursors(bool unbind) const;
3746
3748 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3749
3751 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3752
3754 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3755 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3757 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3758 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3760 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3761 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3762
3764 inline map_handle open_map_accede(const char *name) const;
3766 inline map_handle open_map_accede(const ::std::string &name) const;
3768 inline map_handle open_map_accede(const slice &name) const;
3769
3771 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3772 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3774 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3775 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3777 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3778 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3779
3781 inline void drop_map(map_handle map);
3785 bool drop_map(const char *name, bool throw_if_absent = false);
3789 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3793 bool drop_map(const slice &name, bool throw_if_absent = false);
3794
3796 inline void clear_map(map_handle map);
3799 bool clear_map(const char *name, bool throw_if_absent = false);
3802 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3805 bool clear_map(const slice &name, bool throw_if_absent = false);
3806
3808 inline void rename_map(map_handle map, const char *new_name);
3810 inline void rename_map(map_handle map, const ::std::string &new_name);
3812 inline void rename_map(map_handle map, const slice &new_name);
3816 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3820 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3824 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3825
3826#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3827
3829 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3830 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3831 return open_map(slice(name), key_mode, value_mode);
3832 }
3833
3834 inline map_handle open_map_accede(const ::std::string_view &name) const;
3836 inline map_handle create_map(const ::std::string_view &name,
3837 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3838 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3839 return create_map(slice(name), key_mode, value_mode);
3840 }
3841
3844 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3845 return drop_map(slice(name), throw_if_absent);
3846 }
3847
3849 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3850 return clear_map(slice(name), throw_if_absent);
3851 }
3852
3853 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3857 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3858 bool throw_if_absent = false) {
3859 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3860 }
3861#endif /* __cpp_lib_string_view >= 201606L */
3862
3865 inline map_stat get_map_stat(map_handle map) const;
3868 inline uint32_t get_tree_deepmask(map_handle map) const;
3871
3874 inline txn &put_canary(const canary &);
3876 inline canary get_canary() const;
3877
3879 inline uint64_t sequence(map_handle map) const;
3881 inline uint64_t sequence(map_handle map, uint64_t increment);
3882
3884 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3886 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3888 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3890 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3891
3893 inline slice get(map_handle map, const slice &key) const;
3895 inline slice get(map_handle map, slice key, size_t &values_count) const;
3897 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3899 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3903 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3907 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3908
3909 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3910 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3911 inline void insert(map_handle map, const slice &key, slice value);
3912 inline value_result try_insert(map_handle map, const slice &key, slice value);
3913 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3914 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3915
3916 inline void upsert(map_handle map, const slice &key, const slice &value);
3917 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3918
3919 inline void update(map_handle map, const slice &key, const slice &value);
3920 inline bool try_update(map_handle map, const slice &key, const slice &value);
3921 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3922 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3923
3924 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3925 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3926 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3927 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3928
3930 inline bool erase(map_handle map, const slice &key);
3931
3933 inline bool erase(map_handle map, const slice &key, const slice &value);
3934
3936 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3937
3939 template <class ALLOCATOR, typename CAPACITY_POLICY>
3941 extract(map_handle map, const slice &key,
3944
3946 template <class ALLOCATOR, typename CAPACITY_POLICY>
3948 replace(map_handle map, const slice &key, const slice &new_value,
3951
3952 template <class ALLOCATOR, typename CAPACITY_POLICY>
3954 replace_reserve(map_handle map, const slice &key, slice &new_value,
3957
3974 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
3975 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
3976 return append(map, kv.key, kv.value, multivalue_order_preserved);
3977 }
3978
3979 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
3980 const void *values_array, size_t values_count, put_mode mode,
3981 bool allow_partial = false);
3982 template <typename VALUE>
3983 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
3984 put_mode mode, bool allow_partial = false) {
3985 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
3986 !::std::is_array<VALUE>::value,
3987 "Must be a standard layout type!");
3988 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
3989 }
3990 template <typename VALUE>
3991 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
3992 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
3993 }
3994
3995 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
3996 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
3997 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
3998 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
3999};
4000
4009class LIBMDBX_API_TYPE txn_managed : public txn {
4010 using inherited = txn;
4011 friend class env;
4012 friend class txn;
4014 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4015
4016public:
4017 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4018 txn_managed(txn_managed &&) = default;
4019 txn_managed &operator=(txn_managed &&other) noexcept {
4021 MDBX_CXX20_UNLIKELY {
4022 assert(handle_ != other.handle_);
4023 abort();
4024 }
4025 inherited::operator=(std::move(other));
4026 return *this;
4027 }
4028 txn_managed(const txn_managed &) = delete;
4029 txn_managed &operator=(const txn_managed &) = delete;
4030 ~txn_managed() noexcept;
4031
4032 //----------------------------------------------------------------------------
4033
4036 void abort();
4037
4039 void commit();
4040
4044
4046
4050
4053 void commit(commit_latency &latency) { return commit(&latency); }
4054
4059 commit_latency result;
4060 commit(&result);
4061 return result;
4062 }
4063};
4064
4072protected:
4074
4075public:
4077 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4078 cursor(const cursor &) noexcept = default;
4079 cursor &operator=(const cursor &) noexcept = default;
4080 inline cursor &operator=(cursor &&) noexcept;
4081 inline cursor(cursor &&) noexcept;
4082 inline ~cursor() noexcept;
4083 inline cursor_managed clone(void *your_context = nullptr) const;
4084 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4085 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4086 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4087 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4088 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4089
4090 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4091 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4092
4093 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4094 return compare_position(*this, other, ignore_nested) < 0;
4095 }
4096
4097 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4098 return compare_position(*this, other, ignore_nested) <= 0;
4099 }
4100
4101 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4102 return compare_position(*this, other, ignore_nested) == 0;
4103 }
4104
4105 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4106 return compare_position(*this, other, ignore_nested) > 0;
4107 }
4108
4109 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4110 return compare_position(*this, other, ignore_nested) >= 0;
4111 }
4112
4114 inline void *get_context() const noexcept;
4115
4117 inline cursor &set_context(void *your_context);
4118
4125
4132
4135
4139
4140 /* Doubtless cursor positioning at a specified key. */
4146
4147 /* Doubtless cursor positioning at a specified key-value pair
4148 * for dupsort/multi-value hives. */
4154
4161
4166 };
4167
4168 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4169 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4170 // и других параметров в bool-throw_notfound.
4171
4172 struct move_result : public pair_result {
4173 inline move_result(const cursor &cursor, bool throw_notfound);
4174 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4175 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4176 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4177 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4178 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4179 bool throw_notfound);
4180 move_result(const move_result &) noexcept = default;
4181 move_result &operator=(const move_result &) noexcept = default;
4182 };
4183
4184 struct estimate_result : public pair {
4189 : estimate_result(cursor, operation, key, slice::invalid()) {}
4190 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4191 estimate_result(const estimate_result &) noexcept = default;
4192 estimate_result &operator=(const estimate_result &) noexcept = default;
4193 };
4194
4195protected:
4196 /* fake const, i.e. for some move/get operations */
4197 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4198
4199 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4200
4201public:
4202 template <typename CALLABLE_PREDICATE>
4203 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4204 struct wrapper : public exception_thunk {
4205 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4206 auto thunk = static_cast<wrapper *>(context);
4207 assert(thunk->is_clean());
4208 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4209 try {
4210 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4211 } catch (... /* capture any exception to rethrow it over C code */) {
4212 thunk->capture();
4213 return MDBX_RESULT_TRUE;
4214 }
4215 }
4216 } thunk;
4218 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4219 thunk);
4220 }
4221
4222 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4223 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4224 }
4225
4226 template <typename CALLABLE_PREDICATE>
4227 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4228 move_operation turn = next) {
4229 struct wrapper : public exception_thunk {
4230 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4231 auto thunk = static_cast<wrapper *>(context);
4232 assert(thunk->is_clean());
4233 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4234 try {
4235 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4236 } catch (... /* capture any exception to rethrow it over C code */) {
4237 thunk->capture();
4238 return MDBX_RESULT_TRUE;
4239 }
4240 }
4241 } thunk;
4242 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4243 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4244 thunk);
4245 }
4246
4247 template <typename CALLABLE_PREDICATE>
4248 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4249 move_operation turn = next) {
4250 struct wrapper : public exception_thunk {
4251 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4252 auto thunk = static_cast<wrapper *>(context);
4253 assert(thunk->is_clean());
4254 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4255 try {
4256 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4257 } catch (... /* capture any exception to rethrow it over C code */) {
4258 thunk->capture();
4259 return MDBX_RESULT_TRUE;
4260 }
4261 }
4262 } thunk;
4263 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4264 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4265 thunk);
4266 }
4267
4268 move_result move(move_operation operation, bool throw_notfound) {
4269 return move_result(*this, operation, throw_notfound);
4270 }
4271 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4272 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4273 }
4274 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4275 return move_result(*this, operation, key, value, throw_notfound);
4276 }
4277 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4278 return move(operation, &key, &value, throw_notfound);
4279 }
4280
4281 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4282 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4283 move_result to_previous_last_multi(bool throw_notfound = true) {
4284 return move(multi_prevkey_lastvalue, throw_notfound);
4285 }
4286 move_result to_current_first_multi(bool throw_notfound = true) {
4287 return move(multi_currentkey_firstvalue, throw_notfound);
4288 }
4289 move_result to_current_prev_multi(bool throw_notfound = true) {
4290 return move(multi_currentkey_prevvalue, throw_notfound);
4291 }
4292 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4293 move_result to_current_next_multi(bool throw_notfound = true) {
4294 return move(multi_currentkey_nextvalue, throw_notfound);
4295 }
4296 move_result to_current_last_multi(bool throw_notfound = true) {
4297 return move(multi_currentkey_lastvalue, throw_notfound);
4298 }
4299 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4300 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4301 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4302
4303 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4304 return move(key_lesser_than, key, throw_notfound);
4305 }
4306 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4307 return move(key_lesser_or_equal, key, throw_notfound);
4308 }
4309 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4310 return move(key_equal, key, throw_notfound);
4311 }
4312 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4313 return move(key_exact, key, throw_notfound);
4314 }
4315 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4316 return move(key_greater_or_equal, key, throw_notfound);
4317 }
4318 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4319 return move(key_greater_than, key, throw_notfound);
4320 }
4321
4322 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4323 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4324 }
4325 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4326 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4327 }
4328 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4329 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4330 }
4331 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4332 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4333 }
4334 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4335 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4336 }
4337
4338 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4339 return move(pair_lesser_than, key, value, throw_notfound);
4340 }
4341 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4342 return move(pair_lesser_or_equal, key, value, throw_notfound);
4343 }
4344 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4345 return move(pair_equal, key, value, throw_notfound);
4346 }
4347 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4348 return move(pair_exact, key, value, throw_notfound);
4349 }
4350 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4351 return move(pair_greater_or_equal, key, value, throw_notfound);
4352 }
4353 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4354 return move(pair_greater_than, key, value, throw_notfound);
4355 }
4356
4357 inline bool seek(const slice &key);
4358 inline move_result find(const slice &key, bool throw_notfound = true);
4359 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4360 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4361
4363 inline size_t count_multivalue() const;
4364
4365 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4366 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4367 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4368
4369 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4370 return move(seek_and_batch_samelength, key, throw_notfound);
4371 }
4372
4373 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4374 return move(batch_samelength, throw_notfound);
4375 }
4376
4377 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4378 return move(batch_samelength_next, throw_notfound);
4379 }
4380
4381 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4382 return move(batch_samelength_previous, throw_notfound);
4383 }
4384
4385 inline bool eof() const;
4386 inline bool on_first() const;
4387 inline bool on_last() const;
4388 inline bool on_first_multival() const;
4389 inline bool on_last_multival() const;
4390 inline estimate_result estimate(const slice &key, const slice &value) const;
4391 inline estimate_result estimate(const slice &key) const;
4392 inline estimate_result estimate(move_operation operation) const;
4393 inline estimate_result estimate(move_operation operation, slice &key) const;
4394
4395 //----------------------------------------------------------------------------
4396
4398 inline void renew(::mdbx::txn &txn);
4399
4402
4404 inline void unbind();
4405
4407 inline ::mdbx::txn txn() const;
4408 inline map_handle map() const;
4409
4410 inline operator ::mdbx::txn() const { return txn(); }
4411 inline operator ::mdbx::map_handle() const { return map(); }
4412
4413 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4414 inline void put(const slice &key, slice value, put_mode mode);
4415 inline void insert(const slice &key, slice value);
4416 inline value_result try_insert(const slice &key, slice value);
4417 inline slice insert_reserve(const slice &key, size_t value_length);
4418 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4419
4420 inline void upsert(const slice &key, const slice &value);
4421 inline slice upsert_reserve(const slice &key, size_t value_length);
4422
4424 void update_current(const slice &value);
4426 slice reverse_current(size_t value_length);
4427
4428 inline void update(const slice &key, const slice &value);
4429 inline bool try_update(const slice &key, const slice &value);
4430 inline slice update_reserve(const slice &key, size_t value_length);
4431 inline value_result try_update_reserve(const slice &key, size_t value_length);
4432
4433 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4434 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4435 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4436 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4437
4439 inline bool erase(bool whole_multivalue = false);
4440
4443 inline bool erase(const slice &key, bool whole_multivalue = true);
4444
4447 inline bool erase(const slice &key, const slice &value);
4448
4449 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4450 size_t values_count, put_mode mode, bool allow_partial = false);
4451 template <typename VALUE>
4452 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4453 bool allow_partial = false) {
4454 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4455 !::std::is_array<VALUE>::value,
4456 "Must be a standard layout type!");
4457 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4458 }
4459 template <typename VALUE>
4460 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4461 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4462 }
4463};
4464
4472class LIBMDBX_API_TYPE cursor_managed : public cursor {
4473 using inherited = cursor;
4474 friend class txn;
4476 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4477
4478public:
4480 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4481 if (MDBX_UNLIKELY(!handle_))
4482 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4483 }
4484
4486 inline void close() {
4488 handle_ = nullptr;
4489 }
4490
4491 cursor_managed(cursor_managed &&) = default;
4492 cursor_managed &operator=(cursor_managed &&other) noexcept {
4494 MDBX_CXX20_UNLIKELY {
4495 assert(handle_ != other.handle_);
4496 close();
4497 }
4498 inherited::operator=(std::move(other));
4499 return *this;
4500 }
4501
4502 inline MDBX_cursor *withdraw_handle() noexcept {
4503 MDBX_cursor *handle = handle_;
4504 handle_ = nullptr;
4505 return handle;
4506 }
4507
4508 cursor_managed(const cursor_managed &) = delete;
4509 cursor_managed &operator=(const cursor_managed &) = delete;
4511};
4512
4513//------------------------------------------------------------------------------
4514
4515LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
4516LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
4517LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
4518template <class ALLOCATOR, typename CAPACITY_POLICY>
4519inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
4520 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
4521}
4522LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
4523LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
4524LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
4525LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
4526LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
4527LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
4528LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
4529LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
4530
4531LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
4532LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
4533LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
4534inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
4535
4536//==============================================================================
4537//
4538// Inline body of the libmdbx C++ API
4539//
4540
4541MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4542MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4543
4544static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4545#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4546 if (::std::is_constant_evaluated()) {
4547 for (size_t i = 0; c_str; ++i)
4548 if (!c_str[i])
4549 return i;
4550 return 0;
4551 }
4552#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4553#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4554 return c_str ? ::std::string_view(c_str).length() : 0;
4555#else
4556 return c_str ? ::std::strlen(c_str) : 0;
4557#endif
4558}
4559
4560MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4561#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4562 if (::std::is_constant_evaluated()) {
4563 for (size_t i = 0; i < bytes; ++i)
4564 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4565 return dest;
4566 } else
4567#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4568 return ::std::memcpy(dest, src, bytes);
4569}
4570
4571static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4572#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4573 if (::std::is_constant_evaluated()) {
4574 for (size_t i = 0; i < bytes; ++i) {
4575 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4576 if (diff)
4577 return diff;
4578 }
4579 return 0;
4580 } else
4581#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4582 return ::std::memcmp(a, b, bytes);
4583}
4584
4585static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
4586 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
4587 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4588 return bytes;
4589}
4590
4591static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
4592 return check_length(check_length(headroom) + check_length(payload));
4593}
4594
4595MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
4596 return check_length(check_length(headroom, payload) + check_length(tailroom));
4597}
4598
4599inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4600
4601inline void exception_thunk::capture() noexcept {
4602 assert(is_clean());
4603 captured_ = ::std::current_exception();
4604}
4605
4607 if (captured_)
4608 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4609}
4610
4611//------------------------------------------------------------------------------
4612
4613MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4614
4615inline error &error::operator=(MDBX_error_t error_code) noexcept {
4616 code_ = error_code;
4617 return *this;
4618}
4619
4620MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4621
4622MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4623
4624MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4625
4626MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4627
4628MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4629
4631 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4632}
4633
4634MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4635
4640
4641inline void error::throw_exception(int error_code) {
4642 const error trouble(static_cast<MDBX_error_t>(error_code));
4643 trouble.throw_exception();
4644}
4645
4646inline void error::throw_on_failure() const {
4648 MDBX_CXX20_UNLIKELY throw_exception();
4649}
4650
4651inline void error::success_or_throw() const {
4652 if (MDBX_UNLIKELY(!is_success()))
4653 MDBX_CXX20_UNLIKELY throw_exception();
4654}
4655
4656inline void error::success_or_throw(const exception_thunk &thunk) const {
4657 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4658 if (MDBX_UNLIKELY(!is_success())) {
4659 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4660 else throw_exception();
4661 }
4662}
4663
4664inline void error::panic_on_failure(const char *context_where, const char *func_who) const noexcept {
4666 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4667}
4668
4669inline void error::success_or_panic(const char *context_where, const char *func_who) const noexcept {
4670 if (MDBX_UNLIKELY(!is_success()))
4671 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4672}
4673
4674inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4675 if (MDBX_UNLIKELY(ptr == nullptr))
4676 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4677}
4678
4679inline void error::throw_on_failure(int error_code) {
4680 error rc(static_cast<MDBX_error_t>(error_code));
4681 rc.throw_on_failure();
4682}
4683
4684inline void error::success_or_throw(MDBX_error_t error_code) {
4685 error rc(error_code);
4686 rc.success_or_throw();
4687}
4688
4689inline bool error::boolean_or_throw(int error_code) {
4690 switch (error_code) {
4691 case MDBX_RESULT_FALSE:
4692 return false;
4693 case MDBX_RESULT_TRUE:
4694 return true;
4695 default:
4696 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4697 }
4698}
4699
4700inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4701 error rc(static_cast<MDBX_error_t>(error_code));
4702 rc.success_or_throw(thunk);
4703}
4704
4705inline void error::panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept {
4706 error rc(static_cast<MDBX_error_t>(error_code));
4707 rc.panic_on_failure(context_where, func_who);
4708}
4709
4710inline void error::success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept {
4711 error rc(static_cast<MDBX_error_t>(error_code));
4712 rc.success_or_panic(context_where, func_who);
4713}
4714
4715inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4716 if (MDBX_UNLIKELY(!thunk.is_clean()))
4717 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4718 return boolean_or_throw(error_code);
4719}
4720
4721//------------------------------------------------------------------------------
4722
4723MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4724
4726 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4727
4728MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4729 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4730
4731MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4732
4733MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4734
4735MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4736
4737MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4738
4739inline slice &slice::assign(const void *ptr, size_t bytes) {
4740 iov_base = const_cast<void *>(ptr);
4741 iov_len = check_length(bytes);
4742 return *this;
4743}
4744
4745inline slice &slice::assign(const slice &src) noexcept {
4746 iov_base = src.iov_base;
4747 iov_len = src.iov_len;
4748 return *this;
4749}
4750
4751inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4752
4753slice &slice::assign(slice &&src) noexcept {
4754 assign(src);
4755 src.invalidate();
4756 return *this;
4757}
4758
4760 assign(src.iov_base, src.iov_len);
4761 src.iov_base = nullptr;
4762 return *this;
4763}
4764
4765inline slice &slice::assign(const void *begin, const void *end) {
4766 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4767}
4768
4769inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4770
4771inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4772
4773inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4774
4775MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4776
4777MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4778
4779MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4780
4782
4783MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4784
4785MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4786
4787MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4788
4790
4791MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4792
4793MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4794
4795MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4796
4797MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4798
4799MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4800
4802 iov_len = check_length(bytes);
4803 return *this;
4804}
4805
4807 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4808 return set_length(static_cast<const char *>(ptr) - char_ptr());
4809}
4810
4811MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4812
4813MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4814
4815MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4816
4817MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4818
4819MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4820
4822 iov_base = nullptr;
4823 iov_len = 0;
4824}
4825
4826inline void slice::remove_prefix(size_t n) noexcept {
4827 assert(n <= size());
4828 iov_base = static_cast<byte *>(iov_base) + n;
4829 iov_len -= n;
4830}
4831
4832inline void slice::safe_remove_prefix(size_t n) {
4833 if (MDBX_UNLIKELY(n > size()))
4834 MDBX_CXX20_UNLIKELY throw_out_range();
4835 remove_prefix(n);
4836}
4837
4838inline void slice::remove_suffix(size_t n) noexcept {
4839 assert(n <= size());
4840 iov_len -= n;
4841}
4842
4843inline void slice::safe_remove_suffix(size_t n) {
4844 if (MDBX_UNLIKELY(n > size()))
4845 MDBX_CXX20_UNLIKELY throw_out_range();
4846 remove_suffix(n);
4847}
4848
4849MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4850 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4851}
4852
4853MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4854 return length() >= suffix.length() &&
4855 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4856}
4857
4859 size_t h = length() * 3977471;
4860 for (size_t i = 0; i < length(); ++i)
4861 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4862 return h ^ 3863194411 * (h >> 11);
4863}
4864
4865MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4867 return byte_ptr()[n];
4868}
4869
4870MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4871 if (MDBX_UNLIKELY(n >= size()))
4872 MDBX_CXX20_UNLIKELY throw_out_range();
4873 return byte_ptr()[n];
4874}
4875
4876MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4878 return slice(data(), n);
4879}
4880
4881MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4883 return slice(char_ptr() + size() - n, n);
4884}
4885
4886MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4887 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4888 return slice(char_ptr() + from, n);
4889}
4890
4892 if (MDBX_UNLIKELY(n > size()))
4893 MDBX_CXX20_UNLIKELY throw_out_range();
4894 return head(n);
4895}
4896
4898 if (MDBX_UNLIKELY(n > size()))
4899 MDBX_CXX20_UNLIKELY throw_out_range();
4900 return tail(n);
4901}
4902
4903MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4904 if (MDBX_UNLIKELY(n > max_length))
4905 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4906 if (MDBX_UNLIKELY(from + n > size()))
4907 MDBX_CXX20_UNLIKELY throw_out_range();
4908 return middle(from, n);
4909}
4910
4911MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4912 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4913 return diff ? diff
4914 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4915 : memcmp(a.data(), b.data(), a.length());
4916}
4917
4919 const size_t shortest = ::std::min(a.length(), b.length());
4920 if (MDBX_LIKELY(shortest > 0))
4922 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4923 if (MDBX_LIKELY(diff != 0))
4924 MDBX_CXX20_LIKELY return diff;
4925 }
4926 return intptr_t(a.length()) - intptr_t(b.length());
4927}
4928
4930 return slice::compare_fast(a, b) == 0;
4931}
4932
4934 return slice::compare_lexicographically(a, b) < 0;
4935}
4936
4938 return slice::compare_lexicographically(a, b) > 0;
4939}
4940
4942 return slice::compare_lexicographically(a, b) <= 0;
4943}
4944
4946 return slice::compare_lexicographically(a, b) >= 0;
4947}
4948
4950 return slice::compare_fast(a, b) != 0;
4951}
4952
4953#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
4954MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
4956}
4957#endif /* __cpp_impl_three_way_comparison */
4958
4959template <class ALLOCATOR>
4960inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
4961 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
4962}
4963
4964template <class ALLOCATOR>
4965inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
4966 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
4967}
4968
4969template <class ALLOCATOR>
4970inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
4971 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
4972}
4973
4974template <class ALLOCATOR, class CAPACITY_POLICY>
4975inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
4976 const ALLOCATOR &alloc) const {
4977 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
4978}
4979
4980template <class ALLOCATOR, class CAPACITY_POLICY>
4981inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
4982 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
4983}
4984
4985template <class ALLOCATOR, class CAPACITY_POLICY>
4986inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
4987 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
4988}
4989
4990template <class ALLOCATOR, class CAPACITY_POLICY>
4991inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
4992 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
4993}
4994
4995template <class ALLOCATOR, class CAPACITY_POLICY>
4996inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
4997 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
4998}
4999
5000template <class ALLOCATOR, class CAPACITY_POLICY>
5001inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5002 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5003}
5004
5005MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5006 return !from_hex(*this, ignore_spaces).is_erroneous();
5007}
5008
5009MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5010 return !from_base58(*this, ignore_spaces).is_erroneous();
5011}
5012
5013MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5014 return !from_base64(*this, ignore_spaces).is_erroneous();
5015}
5016
5017//------------------------------------------------------------------------------
5018
5019MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5020 const auto diff = slice::compare_fast(a.key, b.key);
5021 return diff ? diff : slice::compare_fast(a.value, b.value);
5022}
5023
5024MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5025 const auto diff = slice::compare_lexicographically(a.key, b.key);
5026 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5027}
5028
5030 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5031 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5032 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5033}
5034
5036 return pair::compare_lexicographically(a, b) < 0;
5037}
5038
5040 return pair::compare_lexicographically(a, b) > 0;
5041}
5042
5044 return pair::compare_lexicographically(a, b) <= 0;
5045}
5046
5048 return pair::compare_lexicographically(a, b) >= 0;
5049}
5050
5052 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5053 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5054 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5055}
5056
5057#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5058MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5060}
5061#endif /* __cpp_impl_three_way_comparison */
5062
5063//------------------------------------------------------------------------------
5064
5065template <class ALLOCATOR, typename CAPACITY_POLICY>
5066inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &txn, const struct slice &src, const allocator_type &alloc)
5067 : buffer(src, !txn.is_dirty(src.data()), alloc) {}
5068
5069//------------------------------------------------------------------------------
5070
5073
5077
5081
5082//------------------------------------------------------------------------------
5083
5085
5086inline env &env::operator=(env &&other) noexcept {
5087 handle_ = other.handle_;
5088 other.handle_ = nullptr;
5089 return *this;
5090}
5091
5092inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5093
5094inline env::~env() noexcept {
5095#ifndef NDEBUG
5096 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5097#endif
5098}
5099
5100MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5101
5102MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5103
5104MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5105
5106MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5107
5108MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5109
5113 return *this;
5114}
5115
5116inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5117 size_now = size_lower = lower;
5118 size_upper = upper;
5120 return *this;
5121}
5122
5126
5130
5131inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5132
5133inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5134
5135inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5136 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5137 if (result < 0)
5138 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5139 return static_cast<size_t>(result);
5140}
5141
5142inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5143 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5144 if (result < 0)
5145 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5146 return static_cast<size_t>(result);
5147}
5148
5149inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5150
5151inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5152
5153inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5154 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5155 if (result < 0)
5156 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5157 return static_cast<size_t>(result);
5158}
5159
5160inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5161 return key_max(pagesize, MDBX_db_flags_t(mode));
5162}
5163
5165 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5166 if (result < 0)
5167 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5168 return static_cast<size_t>(result);
5169}
5170
5172
5173inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5174
5176
5177inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5178 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5179 if (result < 0)
5180 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5181 return static_cast<size_t>(result);
5182}
5183
5184inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5185 return value_max(pagesize, MDBX_db_flags_t(mode));
5186}
5187
5189 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5190 if (result < 0)
5191 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5192 return static_cast<size_t>(result);
5193}
5194
5196
5197inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5198 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5199 if (result < 0)
5200 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5201 return static_cast<size_t>(result);
5202}
5203
5204inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5205 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5206}
5207
5209 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5210 if (result < 0)
5211 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5212 return static_cast<size_t>(result);
5213}
5214
5218
5219inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5220 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5221 if (result < 0)
5222 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5223 return static_cast<size_t>(result);
5224}
5225
5226inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5227 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5228}
5229
5231 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5232 if (result < 0)
5233 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5234 return static_cast<size_t>(result);
5235}
5236
5240
5241inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5242 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5243 if (result < 0)
5244 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5245 return static_cast<size_t>(result);
5246}
5247
5248inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5249
5257
5259
5263
5267
5271
5272inline env::stat env::get_stat() const {
5273 env::stat r;
5274 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5275 return r;
5276}
5277
5278inline env::stat env::get_stat(const txn &txn) const {
5279 env::stat r;
5281 return r;
5282}
5283
5284inline env::info env::get_info() const {
5285 env::info r;
5286 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5287 return r;
5288}
5289
5290inline env::info env::get_info(const txn &txn) const {
5291 env::info r;
5293 return r;
5294}
5295
5297 filehandle fd;
5299 return fd;
5300}
5301
5303 unsigned bits = 0;
5305 return MDBX_env_flags_t(bits);
5306}
5307
5308inline unsigned env::max_readers() const {
5309 unsigned r;
5311 return r;
5312}
5313
5314inline unsigned env::max_maps() const {
5315 unsigned r;
5317 return r;
5318}
5319
5320inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5321
5322inline env &env::set_context(void *ptr) {
5324 return *this;
5325}
5326
5327inline env &env::set_sync_threshold(size_t bytes) {
5329 return *this;
5330}
5331
5332inline size_t env::sync_threshold() const {
5333 size_t bytes;
5335 return bytes;
5336}
5337
5338inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5340 return *this;
5341}
5342
5343inline unsigned env::sync_period__seconds_16dot16() const {
5344 unsigned seconds_16dot16;
5346 return seconds_16dot16;
5347}
5348
5350 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5351}
5352
5353inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5354
5355#if __cplusplus >= 201103L
5356inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5357
5358inline duration env::sync_period() const { return duration(sync_period__seconds_16dot16()); }
5359#endif
5360
5361inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5363 return *this;
5364}
5365
5366inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5367 uint64_t value;
5369 return value;
5370}
5371
5374 return *this;
5375}
5376
5377inline env &env::set_geometry(const geometry &geo) {
5379 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5380 return *this;
5381}
5382
5383inline bool env::sync_to_disk(bool force, bool nonblock) {
5384 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5385 switch (err) {
5386 case MDBX_SUCCESS /* flush done */:
5387 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5388 return true;
5389 case MDBX_BUSY /* the environment is used by other thread */:
5390 return false;
5391 default:
5392 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5393 }
5394}
5395
5396inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5397
5399env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5400 size_t retained) noexcept
5402 bytes_retained(retained) {}
5403
5404template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5405 struct reader_visitor_thunk : public exception_thunk {
5406 VISITOR &visitor_;
5407 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5408 size_t used, size_t retained) noexcept {
5409 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5410 assert(thunk->is_clean());
5411 try {
5412 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5413 return loop_control(thunk->visitor_(info, number));
5414 } catch (... /* capture any exception to rethrow it over C code */) {
5415 thunk->capture();
5417 }
5418 }
5419 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5420 };
5421 reader_visitor_thunk thunk(visitor);
5422 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5423 thunk.rethrow_captured();
5424 return rc;
5425}
5426
5427inline unsigned env::check_readers() {
5428 int dead_count;
5429 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5430 assert(dead_count >= 0);
5431 return static_cast<unsigned>(dead_count);
5432}
5433
5438
5439inline MDBX_hsr_func *env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5440
5442 ::MDBX_txn *ptr;
5444 assert(ptr != nullptr);
5445 return txn_managed(ptr);
5446}
5447
5449 ::MDBX_txn *ptr;
5451 assert(ptr != nullptr);
5452 return txn_managed(ptr);
5453}
5454
5455inline txn_managed env::start_write(bool dont_wait) {
5456 ::MDBX_txn *ptr;
5458 assert(ptr != nullptr);
5459 return txn_managed(ptr);
5460}
5461
5463 ::MDBX_txn *ptr;
5465 assert(ptr != nullptr);
5466 return txn_managed(ptr);
5467}
5468
5470
5471//------------------------------------------------------------------------------
5472
5474
5475inline txn &txn::operator=(txn &&other) noexcept {
5476 handle_ = other.handle_;
5477 other.handle_ = nullptr;
5478 return *this;
5479}
5480
5481inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5482
5483inline txn::~txn() noexcept {
5484#ifndef NDEBUG
5485 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5486#endif
5487}
5488
5489MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5490
5491MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5492
5493MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5494
5495MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5496
5497MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5498
5499inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5500
5501inline txn &txn::set_context(void *ptr) {
5503 return *this;
5504}
5505
5506inline bool txn::is_dirty(const void *ptr) const {
5507 int err = ::mdbx_is_dirty(handle_, ptr);
5508 switch (err) {
5509 default:
5510 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5511 case MDBX_RESULT_TRUE:
5512 return true;
5513 case MDBX_RESULT_FALSE:
5514 return false;
5515 }
5516}
5517
5518inline ::mdbx::env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5519
5521 const int bits = mdbx_txn_flags(handle_);
5523 return static_cast<MDBX_txn_flags_t>(bits);
5524}
5525
5526inline uint64_t txn::id() const {
5527 const uint64_t txnid = mdbx_txn_id(handle_);
5529 return txnid;
5530}
5531
5533
5535
5537
5538inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5539
5540inline bool txn::unpark_reading(bool restart_if_ousted) {
5541 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5542}
5543
5544inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5545 txn::info r;
5546 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5547 return r;
5548}
5549
5551 MDBX_cursor *ptr;
5553 return cursor_managed(ptr);
5554}
5555
5556inline size_t txn::release_all_cursors(bool unbind) const {
5557 size_t count;
5559 return count;
5560}
5561
5562inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5563 const ::mdbx::value_mode value_mode) const {
5564 map_handle map;
5567 assert(map.dbi != 0);
5568 return map;
5569}
5570
5571inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5572 const ::mdbx::value_mode value_mode) const {
5573 map_handle map;
5576 assert(map.dbi != 0);
5577 return map;
5578}
5579
5580inline map_handle txn::open_map_accede(const slice &name) const {
5581 map_handle map;
5583 assert(map.dbi != 0);
5584 return map;
5585}
5586
5587inline map_handle txn::open_map_accede(const char *name) const {
5588 map_handle map;
5590 assert(map.dbi != 0);
5591 return map;
5592}
5593
5594inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5595 const ::mdbx::value_mode value_mode) {
5596 map_handle map;
5599 assert(map.dbi != 0);
5600 return map;
5601}
5602
5603inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5604 const ::mdbx::value_mode value_mode) {
5605 map_handle map;
5608 assert(map.dbi != 0);
5609 return map;
5610}
5611
5613
5615
5616inline void txn::rename_map(map_handle map, const char *new_name) {
5618}
5619
5620inline void txn::rename_map(map_handle map, const slice &new_name) {
5622}
5623
5624inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5625 const ::mdbx::value_mode value_mode) const {
5626 return open_map(slice(name), key_mode, value_mode);
5627}
5628
5629inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5630
5631inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5632 const ::mdbx::value_mode value_mode) {
5633 return create_map(slice(name), key_mode, value_mode);
5634}
5635
5636inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5637 return drop_map(slice(name), throw_if_absent);
5638}
5639
5640inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5641 return clear_map(slice(name), throw_if_absent);
5642}
5643
5644inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5645
5647 txn::map_stat r;
5648 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5649 return r;
5650}
5651
5652inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5653 uint32_t r;
5655 return r;
5656}
5657
5663
5668
5670 txn::canary r;
5672 return r;
5673}
5674
5675inline uint64_t txn::sequence(map_handle map) const {
5676 uint64_t result;
5678 return result;
5679}
5680
5681inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5682 uint64_t result;
5683 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5684 return result;
5685}
5686
5687inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5688 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5689}
5690
5691inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5692 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5693}
5694
5695inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5696 return compare_keys(map, a.key, b.key);
5697}
5698
5699inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5700 return compare_values(map, a.value, b.value);
5701}
5702
5703inline slice txn::get(map_handle map, const slice &key) const {
5704 slice result;
5705 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5706 return result;
5707}
5708
5709inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5710 slice result;
5711 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5712 return result;
5713}
5714
5715inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5716 slice result;
5717 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5718 switch (err) {
5719 case MDBX_SUCCESS:
5720 return result;
5721 case MDBX_NOTFOUND:
5722 return value_at_absence;
5723 default:
5724 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5725 }
5726}
5727
5728inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5729 slice result;
5730 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5731 switch (err) {
5732 case MDBX_SUCCESS:
5733 return result;
5734 case MDBX_NOTFOUND:
5735 return value_at_absence;
5736 default:
5737 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5738 }
5739}
5740
5742 pair result(key, slice());
5743 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5744 return pair_result(result.key, result.value, exact);
5745}
5746
5747inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5748 pair result{key, slice()};
5749 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5750 switch (err) {
5751 case MDBX_SUCCESS:
5752 return pair_result{result.key, result.value, true};
5753 case MDBX_RESULT_TRUE:
5754 return pair_result{result.key, result.value, false};
5755 case MDBX_NOTFOUND:
5756 return pair_result{key, value_at_absence, false};
5757 default:
5758 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5759 }
5760}
5761
5762inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5763 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5764}
5765
5766inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5767 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5768}
5769
5770inline void txn::insert(map_handle map, const slice &key, slice value) {
5771 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5773}
5774
5775inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5776 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5778 switch (err) {
5779 case MDBX_SUCCESS:
5780 return value_result{slice(), true};
5781 case MDBX_KEYEXIST:
5782 return value_result{value, false};
5783 default:
5784 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5785 }
5786}
5787
5788inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5789 slice result(nullptr, value_length);
5790 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5792 return result;
5793}
5794
5795inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5796 slice result(nullptr, value_length);
5797 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5799 switch (err) {
5800 case MDBX_SUCCESS:
5801 return value_result{result, true};
5802 case MDBX_KEYEXIST:
5803 return value_result{result, false};
5804 default:
5805 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5806 }
5807}
5808
5809inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5810 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5811}
5812
5813inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
5814 slice result(nullptr, value_length);
5816 return result;
5817}
5818
5819inline void txn::update(map_handle map, const slice &key, const slice &value) {
5820 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
5821}
5822
5823inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
5824 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
5825 switch (err) {
5826 case MDBX_SUCCESS:
5827 return true;
5828 case MDBX_NOTFOUND:
5829 return false;
5830 default:
5831 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5832 }
5833}
5834
5835inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
5836 slice result(nullptr, value_length);
5838 return result;
5839}
5840
5841inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
5842 slice result(nullptr, value_length);
5843 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
5844 switch (err) {
5845 case MDBX_SUCCESS:
5846 return value_result{result, true};
5847 case MDBX_NOTFOUND:
5848 return value_result{slice(), false};
5849 default:
5850 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5851 }
5852}
5853
5854inline bool txn::erase(map_handle map, const slice &key) {
5855 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
5856 switch (err) {
5857 case MDBX_SUCCESS:
5858 return true;
5859 case MDBX_NOTFOUND:
5860 return false;
5861 default:
5862 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5863 }
5864}
5865
5866inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
5867 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
5868 switch (err) {
5869 case MDBX_SUCCESS:
5870 return true;
5871 case MDBX_NOTFOUND:
5872 return false;
5873 default:
5874 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5875 }
5876}
5877
5878inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
5879 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
5880 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
5881}
5882
5883template <class ALLOCATOR, typename CAPACITY_POLICY>
5887 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
5889 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
5890 return result;
5891}
5892
5893template <class ALLOCATOR, typename CAPACITY_POLICY>
5895txn::replace(map_handle map, const slice &key, const slice &new_value,
5897 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
5898 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
5899 MDBX_CURRENT, result, &result),
5900 result);
5901 return result;
5902}
5903
5904template <class ALLOCATOR, typename CAPACITY_POLICY>
5906txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
5908 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
5909 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
5910 MDBX_CURRENT | MDBX_RESERVE, result, &result),
5911 result);
5912 return result;
5913}
5914
5915inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
5916 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
5917 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
5918}
5919
5920inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
5921 const void *values_array, size_t values_count, put_mode mode,
5922 bool allow_partial) {
5923 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
5924 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
5925 switch (err) {
5926 case MDBX_SUCCESS:
5927 MDBX_CXX20_LIKELY break;
5928 case MDBX_KEYEXIST:
5929 if (allow_partial)
5930 break;
5932 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
5933 default:
5934 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5935 }
5936 return args[1].iov_len /* done item count */;
5937}
5938
5939inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
5940 ptrdiff_t result;
5941 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
5942 return result;
5943}
5944
5945inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
5946 ptrdiff_t result;
5947 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
5948 return result;
5949}
5950
5951inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
5952 ptrdiff_t result;
5953 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
5954 return result;
5955}
5956
5957inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
5958 ptrdiff_t result;
5959 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
5960 return result;
5961}
5962
5963//------------------------------------------------------------------------------
5964
5966
5967inline cursor_managed cursor::clone(void *your_context) const {
5968 cursor_managed clone(your_context);
5970 return clone;
5971}
5972
5973inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
5974
5975inline cursor &cursor::set_context(void *ptr) {
5977 return *this;
5978}
5979
5980inline cursor &cursor::operator=(cursor &&other) noexcept {
5981 handle_ = other.handle_;
5982 other.handle_ = nullptr;
5983 return *this;
5984}
5985
5986inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5987
5988inline cursor::~cursor() noexcept {
5989#ifndef NDEBUG
5990 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
5991#endif
5992}
5993
5994MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
5995
5996MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
5997
5998MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
5999
6000MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6001
6002MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6003
6004inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6005 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6006}
6007
6008inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6009 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6010 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6011 if (MDBX_LIKELY(int16_t(diff) == diff))
6012 MDBX_CXX20_LIKELY return int(diff);
6013 else
6015}
6016
6017inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6018 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6019}
6020
6022 bool throw_notfound)
6023 : pair_result(key, value, false) {
6024 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6025}
6026
6027inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6028 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6029 switch (err) {
6030 case MDBX_SUCCESS:
6031 MDBX_CXX20_LIKELY return true;
6032 case MDBX_RESULT_TRUE:
6033 return false;
6034 case MDBX_NOTFOUND:
6035 if (!throw_notfound)
6036 return false;
6037 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6038 default:
6039 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6040 }
6041}
6042
6044 const slice &value)
6045 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6046 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6047}
6048
6049inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6050 ptrdiff_t result;
6051 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6052 return result;
6053}
6054
6055inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6056 ptrdiff_t result;
6058 return result;
6059}
6060
6061inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6062 return move(key_exact, key, throw_notfound);
6063}
6064
6065inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6066 return move(key_lowerbound, key, throw_notfound);
6067}
6068
6069inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6070 return move(key_greater_than, key, throw_notfound);
6071}
6072
6073inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6074 return move(multi_find_pair, key, value, throw_notfound);
6075}
6076
6077inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6078 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6079}
6080
6081inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6082 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6083}
6084
6085inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6086
6087inline size_t cursor::count_multivalue() const {
6088 size_t result;
6090 return result;
6091}
6092
6093inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6094
6096
6098
6100
6102
6103inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6104 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6105}
6106
6108 return estimate_result(*this, key_lowerbound, key);
6109}
6110
6112 return estimate_result(*this, operation);
6113}
6114
6116
6120
6122
6123inline txn cursor::txn() const {
6125 return ::mdbx::txn(txn);
6126}
6127
6128inline map_handle cursor::map() const {
6129 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6130 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6132 return map_handle(dbi);
6133}
6134
6135inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6136 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6137}
6138
6139inline void cursor::put(const slice &key, slice value, put_mode mode) {
6140 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6141}
6142
6143inline void cursor::insert(const slice &key, slice value) {
6145 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6146}
6147
6148inline value_result cursor::try_insert(const slice &key, slice value) {
6149 const int err =
6150 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6151 switch (err) {
6152 case MDBX_SUCCESS:
6153 return value_result{slice(), true};
6154 case MDBX_KEYEXIST:
6155 return value_result{value, false};
6156 default:
6157 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6158 }
6159}
6160
6161inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6162 slice result(nullptr, value_length);
6163 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6165 return result;
6166}
6167
6168inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6169 slice result(nullptr, value_length);
6170 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6172 switch (err) {
6173 case MDBX_SUCCESS:
6174 return value_result{result, true};
6175 case MDBX_KEYEXIST:
6176 return value_result{result, false};
6177 default:
6178 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6179 }
6180}
6181
6182inline void cursor::upsert(const slice &key, const slice &value) {
6183 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6184}
6185
6186inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6187 slice result(nullptr, value_length);
6189 return result;
6190}
6191
6192inline void cursor::update(const slice &key, const slice &value) {
6193 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6194}
6195
6196inline bool cursor::try_update(const slice &key, const slice &value) {
6197 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6198 switch (err) {
6199 case MDBX_SUCCESS:
6200 return true;
6201 case MDBX_NOTFOUND:
6202 return false;
6203 default:
6204 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6205 }
6206}
6207
6208inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6209 slice result(nullptr, value_length);
6211 return result;
6212}
6213
6214inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6215 slice result(nullptr, value_length);
6216 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6217 switch (err) {
6218 case MDBX_SUCCESS:
6219 return value_result{result, true};
6220 case MDBX_NOTFOUND:
6221 return value_result{slice(), false};
6222 default:
6223 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6224 }
6225}
6226
6227inline bool cursor::erase(bool whole_multivalue) {
6228 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6229 switch (err) {
6230 case MDBX_SUCCESS:
6231 MDBX_CXX20_LIKELY return true;
6232 case MDBX_NOTFOUND:
6233 return false;
6234 default:
6235 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6236 }
6237}
6238
6239inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6240 bool found = seek(key);
6241 return found ? erase(whole_multivalue) : found;
6242}
6243
6244inline bool cursor::erase(const slice &key, const slice &value) {
6245 move_result data = find_multivalue(key, value, false);
6246 return data.done && erase();
6247}
6248
6249inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6250 size_t values_count, put_mode mode, bool allow_partial) {
6251 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6252 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6253 switch (err) {
6254 case MDBX_SUCCESS:
6255 MDBX_CXX20_LIKELY break;
6256 case MDBX_KEYEXIST:
6257 if (allow_partial)
6258 break;
6260 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6261 default:
6262 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6263 }
6264 return args[1].iov_len /* done item count */;
6265}
6266
6268} // namespace mdbx
6269
6270//------------------------------------------------------------------------------
6271
6274namespace std {
6275
6278
6279inline string to_string(const ::mdbx::slice &value) {
6280 ostringstream out;
6281 out << value;
6282 return out.str();
6283}
6284
6285template <class ALLOCATOR, typename CAPACITY_POLICY>
6286inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6287 ostringstream out;
6288 out << buffer;
6289 return out.str();
6290}
6291
6292inline string to_string(const ::mdbx::pair &value) {
6293 ostringstream out;
6294 out << value;
6295 return out.str();
6296}
6297
6298inline string to_string(const ::mdbx::env::geometry &value) {
6299 ostringstream out;
6300 out << value;
6301 return out.str();
6302}
6303
6304inline string to_string(const ::mdbx::env::operate_parameters &value) {
6305 ostringstream out;
6306 out << value;
6307 return out.str();
6308}
6309
6310inline string to_string(const ::mdbx::env::mode &value) {
6311 ostringstream out;
6312 out << value;
6313 return out.str();
6314}
6315
6316inline string to_string(const ::mdbx::env::durability &value) {
6317 ostringstream out;
6318 out << value;
6319 return out.str();
6320}
6321
6322inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6323 ostringstream out;
6324 out << value;
6325 return out.str();
6326}
6327
6328inline string to_string(const ::mdbx::env::operate_options &value) {
6329 ostringstream out;
6330 out << value;
6331 return out.str();
6332}
6333
6334inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6335 ostringstream out;
6336 out << value;
6337 return out.str();
6338}
6339
6340inline string to_string(const ::MDBX_log_level_t &value) {
6341 ostringstream out;
6342 out << value;
6343 return out.str();
6344}
6345
6346inline string to_string(const ::MDBX_debug_flags_t &value) {
6347 ostringstream out;
6348 out << value;
6349 return out.str();
6350}
6351
6352inline string to_string(const ::mdbx::error &value) {
6353 ostringstream out;
6354 out << value;
6355 return out.str();
6356}
6357
6358inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6359
6360template <> struct hash<::mdbx::slice> {
6361 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6362};
6363
6364template <> struct hash<::mdbx::map_handle> {
6365 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6366};
6367
6368template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6369 using inherited = std::hash<const MDBX_env *>;
6370 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6371};
6372
6373template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6374 using inherited = std::hash<const MDBX_txn *>;
6375 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6376};
6377
6378template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6379 using inherited = std::hash<const MDBX_cursor *>;
6380 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6381};
6382
6383template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6384 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6385 return buffer.hash_value();
6386 }
6387};
6388
6390} // namespace std
6391
6392#if defined(__LCC__) && __LCC__ >= 126
6393#pragma diagnostic pop
6394#endif
6395
6396#ifdef _MSC_VER
6397#pragma warning(pop)
6398#endif
Definition mdbx.h++:601
Definition mdbx.h++:591
Definition mdbx.h++:611
#define MDBX_CXX11_CONSTEXPR
Definition mdbx.h:439
#define MDBX_MAYBE_UNUSED
Definition mdbx.h:505
#define MDBX_CXX14_CONSTEXPR
Definition mdbx.h:458
#define MDBX_NOTHROW_PURE_FUNCTION
The 'pure nothrow' function attribute for optimization.
Definition mdbx.h:255
mode_t mdbx_mode_t
Definition mdbx.h:170
int(* MDBX_preserve_func)(void *context, MDBX_val *target, const void *src, size_t bytes)
Definition mdbx.h:5067
#define LIBMDBX_API
Definition mdbx.h:587
#define LIBMDBX_API_TYPE
Definition mdbx.h:602
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:762
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:169
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition mdbx.h:694
int mdbx_filehandle_t
Definition mdbx.h:167
pid_t mdbx_pid_t
Definition mdbx.h:168
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:776
@ MDBX_MAXDATASIZE
Definition mdbx.h:770
@ MDBX_MAX_DBI
Definition mdbx.h:767
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:773
libmdbx build information
Definition mdbx.h:630
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4436
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4085
Information about the environment.
Definition mdbx.h:2808
Statistics for a table in the environment.
Definition mdbx.h:2762
Information about the transaction.
Definition mdbx.h:3987
libmdbx version information,
Definition mdbx.h:612
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:1630
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:4496
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:1667
@ MDBX_ALLDUPS
Definition mdbx.h:1650
@ MDBX_CURRENT
Definition mdbx.h:1645
@ MDBX_APPENDDUP
Definition mdbx.h:1663
@ MDBX_APPEND
Definition mdbx.h:1658
@ MDBX_UPSERT
Definition mdbx.h:1632
@ MDBX_RESERVE
Definition mdbx.h:1654
@ MDBX_NOOVERWRITE
Definition mdbx.h:1635
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:1711
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:724
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:1830
@ MDBX_GET_CURRENT
Definition mdbx.h:1726
@ MDBX_GET_BOTH
Definition mdbx.h:1719
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1807
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1723
@ MDBX_SET_KEY
Definition mdbx.h:1766
@ MDBX_FIRST_DUP
Definition mdbx.h:1716
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1806
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1731
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1817
@ MDBX_NEXT_NODUP
Definition mdbx.h:1751
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1814
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1815
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1822
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1774
@ MDBX_SET_RANGE
Definition mdbx.h:1769
@ MDBX_LAST_DUP
Definition mdbx.h:1737
@ MDBX_PREV
Definition mdbx.h:1754
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1824
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1825
@ MDBX_LAST
Definition mdbx.h:1734
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1805
@ MDBX_PREV_DUP
Definition mdbx.h:1757
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1813
@ MDBX_SET
Definition mdbx.h:1763
@ MDBX_NEXT
Definition mdbx.h:1740
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1808
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1821
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1748
@ MDBX_PREV_NODUP
Definition mdbx.h:1760
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1823
@ MDBX_NEXT_DUP
Definition mdbx.h:1743
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1816
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1809
@ MDBX_FIRST
Definition mdbx.h:1713
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:717
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1580
@ MDBX_INTEGERDUP
Definition mdbx.h:1604
@ MDBX_DB_ACCEDE
Definition mdbx.h:1622
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1582
@ MDBX_REVERSEKEY
Definition mdbx.h:1585
@ MDBX_DUPFIXED
Definition mdbx.h:1599
@ MDBX_INTEGERKEY
Definition mdbx.h:1595
@ MDBX_REVERSEDUP
Definition mdbx.h:1607
@ MDBX_CREATE
Definition mdbx.h:1610
@ MDBX_DUPSORT
Definition mdbx.h:1588
MDBX_log_level_t
Definition mdbx.h:839
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:898
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:6294
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1838
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1852
@ MDBX_BAD_TXN
Definition mdbx.h:1917
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1931
@ MDBX_SUCCESS
Definition mdbx.h:1840
@ MDBX_NOTFOUND
Definition mdbx.h:1855
@ MDBX_RESULT_TRUE
Definition mdbx.h:1846
@ MDBX_BUSY
Definition mdbx.h:1935
@ MDBX_EINVAL
Definition mdbx.h:2008
@ MDBX_ENOMEM
Definition mdbx.h:2010
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1938
@ MDBX_RESULT_FALSE
Definition mdbx.h:1843
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:1987
@ MDBX_KEYEXIST
Definition mdbx.h:1849
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:2544
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2538
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2541
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1021
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:3055
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2118
LIBMDBX_API int mdbx_env_set_geometry(MDBX_env *env, intptr_t size_lower, intptr_t size_now, intptr_t size_upper, intptr_t growth_step, intptr_t shrink_threshold, intptr_t pagesize)
Set all size-related parameters of environment, including page size and the min/max size of the memor...
int mdbx_env_set_syncbytes(MDBX_env *env, size_t threshold)
Sets threshold to force flush the data buffers to disk, even any of MDBX_SAFE_NOSYNC flag in the envi...
Definition mdbx.h:2994
LIBMDBX_API int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option, uint64_t value)
Sets the value of a extra runtime options for an environment.
LIBMDBX_API int mdbx_env_set_userctx(MDBX_env *env, void *ctx)
Sets application information (a context pointer) associated with the environment.
LIBMDBX_API int mdbx_env_set_flags(MDBX_env *env, MDBX_env_flags_t flags, bool onoff)
Set environment flags.
@ MDBX_opt_txn_dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h:2223
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2219
@ MDBX_opt_prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h:2323
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2127
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2290
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2150
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2255
@ MDBX_opt_spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h:2278
@ MDBX_opt_loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h:2190
@ MDBX_opt_rp_augment_limit
Controls the in-process limit to grow a list of reclaimed/recycled page's numbers for finding a seque...
Definition mdbx.h:2177
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2144
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2239
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2156
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2204
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2318
LIBMDBX_API int mdbx_dbi_stat(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_stat *stat, size_t bytes)
Retrieve statistics for a table.
LIBMDBX_API uint64_t mdbx_txn_id(const MDBX_txn *txn)
Return the transaction's ID.
LIBMDBX_API intptr_t mdbx_limits_valsize_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal data size in bytes for given page size and table flags, or -1 if pagesize is invalid.
LIBMDBX_API int mdbx_env_info_ex(const MDBX_env *env, const MDBX_txn *txn, MDBX_envinfo *info, size_t bytes)
Return information about the MDBX environment.
int mdbx_env_get_maxreaders(const MDBX_env *env, unsigned *readers)
Get the maximum number of threads/reader slots for the environment.
Definition mdbx.h:3691
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:3075
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:3012
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:4767
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:3736
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:1482
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:3956
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:705
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:1493
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1502
@ MDBX_TXN_READWRITE
Definition mdbx.h:1487
@ MDBX_TXN_TRY
Definition mdbx.h:1508
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2326
friend class env
Definition mdbx.h++:4011
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2039
MDBX_commit_latency commit_latency
Definition mdbx.h++:4045
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++:1912
::MDBX_txn_info info
Definition mdbx.h++:3706
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4480
~txn_managed() noexcept
::MDBX_stat map_stat
Definition mdbx.h++:3863
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++:3413
@ prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h++:3447
@ spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h++:3439
@ spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h++:3441
@ writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h++:3445
@ sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h++:3422
@ dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h++:3433
@ dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h++:3435
@ spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h++:3437
@ merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h++:3443
@ 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++:3427
@ loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h++:3429
@ dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h++:3431
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6384
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3640
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:1939
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2004
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1894
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3844
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++:2181
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2222
::MDBX_db_flags_t flags
Definition mdbx.h++:2923
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++:4325
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4381
static buffer key_from(const double *ieee754_64bit)
Definition mdbx.h++:2547
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++:2130
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++:1955
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2253
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:1952
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2335
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2205
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++:1927
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2066
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2306
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2219
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:1946
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2892
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2071
durability
Durability level.
Definition mdbx.h++:3070
@ lazy_weak_tail
Definition mdbx.h++:3073
@ robust_synchronous
Definition mdbx.h++:3071
@ whole_fragile
Definition mdbx.h++:3074
@ half_synchronous_weak_last
Definition mdbx.h++:3072
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++:1479
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2021
friend constexpr bool operator!=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2919
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2257
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:1979
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3240
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2436
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++:4369
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:1975
buffer & append(const byte c)
Definition mdbx.h++:2390
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2230
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2235
buffer & operator=(const buffer &src)
Definition mdbx.h++:2352
estimate_result estimate(move_operation operation, slice &key) const
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2458
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3663
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:1921
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4344
::MDBX_canary canary
Definition mdbx.h++:3872
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++:3704
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++:4274
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:1972
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2537
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++:2112
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++:4338
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++:2194
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++:2188
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2107
constexpr env() noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2400
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2150
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4347
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++:2331
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++:2174
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2913
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2557
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2893
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++:2200
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4433
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2104
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4292
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++:4283
allocation_aware_details::swap_alloc< struct silo, allocator_type > swap_alloc
Definition mdbx.h++:1889
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2563
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++:4109
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3751
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3927
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4315
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++:2138
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4101
constexpr buffer & assign(buffer &&src) noexcept(allocation_aware_details::move_assign_alloc< silo, allocator_type >::is_nothrow())
Definition mdbx.h++:2294
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4105
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2361
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2543
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++:3836
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6380
const slice & slice() const noexcept
Definition mdbx.h++:2575
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2314
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3167
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6365
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4299
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2302
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4502
constexpr buffer(const buffer &src)
Definition mdbx.h++:2049
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++:2167
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2375
MDBX_txn * handle_
Definition mdbx.h++:3664
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++:1992
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2549
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4271
mode
Operation mode.
Definition mdbx.h++:3062
@ write_mapped_io
Definition mdbx.h++:3065
@ nested_transactions
Definition mdbx.h++:3066
@ readonly
Definition mdbx.h++:3063
@ write_file_io
Definition mdbx.h++:3064
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2245
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4268
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4227
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3301
operator::mdbx::txn() const
Definition mdbx.h++:4410
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2432
MDBX_env * handle_
Definition mdbx.h++:2963
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2529
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++:2082
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4331
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2456
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:1906
commit_latency commit_get_latency()
Commit all the operations of a transaction into the database and return latency information.
Definition mdbx.h++:4058
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4097
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2561
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4281
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4301
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2356
void close()
Explicitly closes the cursor.
Definition mdbx.h++:4486
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2428
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2034
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++:6361
move_result to_key_exact(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4312
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2541
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3701
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2162
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2077
constexpr txn_managed() noexcept=default
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2320
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++:1898
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2565
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2491
move_result next_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4377
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++:3975
cursor_managed & operator=(const cursor_managed &)=delete
default_capacity_policy reservation_policy
Definition mdbx.h++:1480
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3271
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3281
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3283
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3278
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2555
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4203
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4286
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2028
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2358
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2408
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2479
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2440
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4248
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4492
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6374
::MDBX_dbi_state_t state
Definition mdbx.h++:2924
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3470
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4460
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++:4053
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++:3246
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++:2145
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4341
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++:2571
move_result get_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4373
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4303
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4300
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4411
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3242
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2916
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2567
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3748
static buffer key_from(const uint32_t unsigned_int32)
Definition mdbx.h++:2569
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2224
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2907
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++:4318
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3307
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2012
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3924
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++:2310
friend int compare_position(const cursor &left, const cursor &right, bool ignore_nested)
Definition mdbx.h++:6008
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:3991
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++:3253
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++:3829
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2904
allocation_aware_details::move_assign_alloc< silo, allocator_type > move_assign_alloc
Definition mdbx.h++:1887
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++:3983
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1888
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:1959
friend constexpr bool operator>(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2910
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++:2273
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2398
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++:2444
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++:4353
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:1966
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4119
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4134
@ multi_exactkey_value_equal
Definition mdbx.h++:4151
@ pair_greater_or_equal
Definition mdbx.h++:4159
@ key_lesser_than
Definition mdbx.h++:4141
@ next
Definition mdbx.h++:4122
@ pair_exact
Definition mdbx.h++:4158
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4152
@ pair_lesser_or_equal
Definition mdbx.h++:4156
@ batch_samelength
Definition mdbx.h++:4162
@ seek_key
Definition mdbx.h++:4136
@ key_lowerbound
Definition mdbx.h++:4138
@ pair_lesser_than
Definition mdbx.h++:4155
@ pair_equal
Definition mdbx.h++:4157
@ key_greater_than
Definition mdbx.h++:4145
@ batch_samelength_next
Definition mdbx.h++:4163
@ multi_find_pair
Definition mdbx.h++:4133
@ key_greater_or_equal
Definition mdbx.h++:4144
@ key_exact
Definition mdbx.h++:4137
@ key_equal
Definition mdbx.h++:4143
@ multi_currentkey_prevvalue
Definition mdbx.h++:4128
@ key_lesser_or_equal
Definition mdbx.h++:4142
@ multi_nextkey_firstvalue
Definition mdbx.h++:4131
@ get_current
Definition mdbx.h++:4124
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4150
@ multi_prevkey_lastvalue
Definition mdbx.h++:4126
@ previous
Definition mdbx.h++:4123
@ last
Definition mdbx.h++:4121
@ pair_greater_than
Definition mdbx.h++:4160
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4149
@ multi_currentkey_firstvalue
Definition mdbx.h++:4127
@ first
Definition mdbx.h++:4120
@ batch_samelength_previous
Definition mdbx.h++:4164
@ multi_currentkey_nextvalue
Definition mdbx.h++:4129
@ seek_and_batch_samelength
Definition mdbx.h++:4165
@ multi_exactkey_value_greater
Definition mdbx.h++:4153
@ multi_currentkey_lastvalue
Definition mdbx.h++:4130
virtual ~env_managed() noexcept
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4277
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2523
void insert(const pair &kv)
Definition mdbx.h++:4434
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3698
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2382
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++:4436
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4289
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2380
txn_managed & operator=(const txn_managed &)=delete
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2573
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2372
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3849
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4328
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++:2124
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2053
typename ::std::allocator_traits< default_allocator >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1475
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++:2545
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:1932
move_result to_current_last_multi(bool throw_notfound=true)
Definition mdbx.h++:4296
value_result try_insert(const pair &kv)
Definition mdbx.h++:4435
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++:4452
constexpr cursor() noexcept=default
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4306
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6370
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2553
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:1935
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++:2119
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2249
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4350
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3250
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2062
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1891
MDBX_cursor * handle_
Definition mdbx.h++:4073
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2448
~cursor_managed() noexcept
Definition mdbx.h++:4510
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2468
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2089
MDBX_dbi dbi
Definition mdbx.h++:2891
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++:4322
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2551
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4293
buffer encode_base58(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2157
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2505
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6369
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++:2424
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2101
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3712
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2354
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++:4334
txn_managed(const txn_managed &)=delete
friend int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept
Definition mdbx.h++:6004
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6379
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3298
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3248
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:1986
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3926
buffer & append_producer(PRODUCER &producer)
Definition mdbx.h++:2410
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3925
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2417
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2057
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++:2534
bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:3857
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4309
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++:4282
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4093
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2045
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3244
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6375
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:1915
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3715
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:1997
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4222
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1471
Unmanaged cursor.
Definition mdbx.h++:4071
Managed cursor.
Definition mdbx.h++:4472
Unmanaged database environment.
Definition mdbx.h++:2959
Managed database environment.
Definition mdbx.h++:3579
Unmanaged database transaction.
Definition mdbx.h++:3661
Managed database transaction.
Definition mdbx.h++:4009
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++:5149
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5019
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4806
polymorphic_allocator default_allocator
Definition mdbx.h++:356
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4815
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4897
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++:4981
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++:5434
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5499
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++:5177
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4911
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4634
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++:5878
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6115
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2805
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4793
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:5074
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4891
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5532
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:4783
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4669
void rethrow_captured() const
Definition mdbx.h++:4606
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4791
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6073
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6049
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5142
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5116
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5841
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5795
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5396
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++:5327
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6017
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++:4960
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4813
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:5951
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++:4986
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4838
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4739
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6121
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:423
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5788
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:5965
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5616
void throw_on_failure() const
Definition mdbx.h++:4646
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6196
void update(const slice &key, const slice &value)
Definition mdbx.h++:6192
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:5071
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++:5687
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4801
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++:4975
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5501
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5462
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6004
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4937
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5260
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5675
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6182
bool is_clean() const noexcept
Definition mdbx.h++:4599
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2798
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4689
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++:4965
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5250
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2802
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:379
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:5302
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5135
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4881
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4613
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++:4991
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4541
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++:5906
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++:5399
void insert(const slice &key, slice value)
Definition mdbx.h++:6143
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6077
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++:5571
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:355
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:2786
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++:5439
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++:5001
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4723
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:5967
~cursor() noexcept
Definition mdbx.h++:5988
~txn() noexcept
Definition mdbx.h++:5483
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5332
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6069
uint64_t txnid
Transaction ID and MVCC-snapshot number.
Definition mdbx.h++:372
constexpr void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition mdbx.h++:4819
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6123
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6168
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5127
map_handle map() const
Definition mdbx.h++:6128
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++:5343
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:5078
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6061
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5587
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6081
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2866
void success_or_throw() const
Definition mdbx.h++:4651
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5536
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4853
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5383
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4941
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6008
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6087
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4849
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5133
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4858
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5506
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6186
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5258
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2794
void capture() noexcept
Definition mdbx.h++:4601
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5518
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++:5652
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5823
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4832
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2937
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6161
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++:5197
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++:5338
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:5939
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5264
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5612
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:5957
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++:5915
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5268
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5538
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4945
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:5975
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5646
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6027
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++:5173
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++:5691
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5123
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5664
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5813
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4876
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6279
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4628
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++:5349
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4903
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4775
bool on_first() const
Definition mdbx.h++:6095
::MDBX_version_info version_info
libmdbx version information,
Definition mdbx.h++:332
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:4811
bool eof() const
Definition mdbx.h++:6093
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5534
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5520
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5320
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6135
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5448
::MDBX_build_info build_info
libmdbx build information
Definition mdbx.h++:336
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5473
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4843
bool seek(const slice &key)
Definition mdbx.h++:6085
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5372
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5322
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4865
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++:5241
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5614
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++:5361
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5013
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4826
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6148
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++:6249
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4674
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4622
::MDBX_cmp_func * comparator
Definition mdbx.h++:2936
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2945
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5024
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++:4996
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++:5353
::mdbx_filehandle_t filehandle
Definition mdbx.h++:381
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++:5219
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5084
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4933
char8_t byte
Definition mdbx.h++:316
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5669
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6227
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5272
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5526
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5775
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:350
constexpr bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition mdbx.h++:4636
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6055
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4918
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5835
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5009
~env() noexcept
Definition mdbx.h++:5094
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2767
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5703
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4630
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4821
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++:5920
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5819
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4870
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2770
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5441
::mdbx::filesystem::path path
Definition mdbx.h++:405
bool on_last_multival() const
Definition mdbx.h++:6101
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5314
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5770
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5308
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++:5153
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5404
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:5973
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5248
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5550
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2790
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5540
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5366
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4542
bool on_first_multival() const
Definition mdbx.h++:6099
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5762
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4664
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4886
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5284
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5809
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5131
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++:4970
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6208
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6065
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4777
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4799
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5427
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:5854
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4626
bool on_last() const
Definition mdbx.h++:6097
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++:5885
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:401
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:5296
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5377
map_handle::info get_handle_info(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5658
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++:6117
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5110
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5556
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4620
constexpr bool is_success() const noexcept
Definition mdbx.h++:4624
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6214
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:375
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5469
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5005
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5544
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++:5603
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++:5741
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4785
@ multi_reverse_samelength
Definition mdbx.h++:2838
@ multi_samelength
Definition mdbx.h++:2823
@ multi_ordinal
Definition mdbx.h++:2830
@ msgpack
Definition mdbx.h++:2853
@ single
Definition mdbx.h++:2806
@ multi
Definition mdbx.h++:2808
@ multi_reverse
Definition mdbx.h++:2815
@ upsert
Insert or update.
Definition mdbx.h++:2947
@ update
Update existing, don't insert new.
Definition mdbx.h++:2948
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2946
@ continue_loop
Definition mdbx.h++:2767
@ exit_loop
Definition mdbx.h++:2767
@ usual
Definition mdbx.h++:2771
@ ordinal
Definition mdbx.h++:2776
@ reverse
Definition mdbx.h++:2773
@ msgpack
Definition mdbx.h++:2781
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2890
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++:1264
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++:1216
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:698
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:711
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++:1310
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:674
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:665
buffer_pair_spec(const txn &transacton, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2722
const slice source
Definition mdbx.h++:1293
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++:733
int8_t as_int8_adapt() const
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2689
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1029
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1270
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:751
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1010
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1028
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2730
constexpr int64_t as_int64() const
Definition mdbx.h++:1035
const bool ignore_spaces
Definition mdbx.h++:1385
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:855
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++:768
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2700
constexpr int16_t as_int16() const
Definition mdbx.h++:1037
slice value
Definition mdbx.h++:2630
::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++:2702
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1237
slice value
Definition mdbx.h++:2644
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2693
::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++:1444
const slice source
Definition mdbx.h++:1384
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2711
const slice source
Definition mdbx.h++:1200
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++:1367
const unsigned wrap_width
Definition mdbx.h++:1202
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:725
const bool ignore_spaces
Definition mdbx.h++:1347
constexpr POD as_pod() const
Definition mdbx.h++:1012
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++:2677
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++:1459
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2706
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1025
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++:1361
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1203
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2708
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1176
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:747
std::pair< slice, slice > stl_pair
Definition mdbx.h++:2643
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
@ pettiness_threshold
Definition mdbx.h++:1164
@ extra_inplace_storage
Definition mdbx.h++:1162
@ max_reserve
Definition mdbx.h++:1165
@ inplace_storage_size_rounding
Definition mdbx.h++:1163
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:688
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1386
constexpr int8_t as_int8() const
Definition mdbx.h++:1038
constexpr ::std::span< char > chars()
Definition mdbx.h++:700
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1057
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1316
static constexpr size_t round(const size_t value)
Definition mdbx.h++:1168
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1284
constexpr size_t envisage_result_length() const noexcept
Returns the number of bytes needed for conversion Base64 dump from a passed slice to decoded data.
Definition mdbx.h++:1450
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:2632
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1417
const slice source
Definition mdbx.h++:1247
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:2646
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:699
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1429
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++:1241
uint8_t as_uint8_adapt() const
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:679
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:1437
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++:1407
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:730
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++:755
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1374
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:644
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:2678
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1348
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++:2654
bool done
Definition mdbx.h++:2676
::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++:1287
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:697
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:713
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:1210
const bool uppercase
Definition mdbx.h++:1201
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:1355
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:1257
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:1303
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:1394
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2719
const bool ignore_spaces
Definition mdbx.h++:1428
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1296
pair(const pair &) noexcept=default
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:1005
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base64 dump, and therefore there could be dec...
slice & operator=(const slice &) noexcept=default
uint128_t as_uint128_adapt() const
constexpr int128_t as_int128() const
Definition mdbx.h++:1033
slice key
Definition mdbx.h++:2644
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:2645
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2725
const slice source
Definition mdbx.h++:1427
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++:1333
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2691
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++:1036
int64_t as_int64_adapt() const
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2717
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1030
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2692
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1027
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2713
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++:1248
const unsigned wrap_width
Definition mdbx.h++:1294
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:1401
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++:1002
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++:2728
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++:706
int16_t as_int16_adapt() const
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2690
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++:1337
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++:1250
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:708
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++:1222
bool done
Definition mdbx.h++:2631
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++:1346
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc=ALLOCATOR())
Definition mdbx.h++:2579
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc=ALLOCATOR())
Definition mdbx.h++:2601
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:2759
inline ::std::ostream & operator<<(::std::ostream &out, const to_hex &wrapper)
Definition mdbx.h++:1340
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++:2756
Definition mdbx.h++:2688
Type tag for delivered buffer template classes.
Definition mdbx.h++:1468
Definition mdbx.h++:1160
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1383
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1426
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1345
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:2642
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:2675
References a data located outside the slice.
Definition mdbx.h++:639
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1246
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1292
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1199
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:2629
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:521
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++:4622
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++:520
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++:489
db_full(const ::mdbx::error &)
duplicated_lck_file(const ::mdbx::error &)
const ::mdbx::error error() const noexcept
Definition mdbx.h++:511
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++:522
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++:523
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++:4620
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++:448
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:433
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:529
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:4706
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:4710
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition mdbx.h++:172
#define MDBX_CXX17_FALLTHROUGH
Definition mdbx.h++:230
#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME)
Definition mdbx.h++:110
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:270
#define MDBX_LIKELY(cond)
Definition mdbx.h++:205
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:182
#define MDBX_UNLIKELY(cond)
Definition mdbx.h++:213
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:161
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:200
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:221
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:181
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:236
The libmdbx C API header file.
Definition mdbx.h++:1062
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1064
The libmdbx C++ API namespace.
Definition mdbx.h++:303
STL namespace.
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1561
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1563
byte lastbyte_
Definition mdbx.h++:1562
Definition mdbx.h++:4184
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4186
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4185
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4188
Definition mdbx.h++:4172
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++:4176
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4174
Tagged type for output to std::ostream.
Definition mdbx.h++:3011
intptr_t bytes
Definition mdbx.h++:3012
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3013
Database geometry for size management.
Definition mdbx.h++:2987
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3035
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3047
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:2994
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:2990
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:2993
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3002
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:2991
@ default_value
Means "keep current or use default".
Definition mdbx.h++:2989
@ kB
bytes (0x03E8)
Definition mdbx.h++:2992
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3001
@ KiB
bytes (0x0400)
Definition mdbx.h++:3000
constexpr geometry() noexcept
Definition mdbx.h++:3051
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3038
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3023
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3041
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3018
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++:3054
Operate options.
Definition mdbx.h++:3091
bool disable_readahead
Definition mdbx.h++:3100
bool enable_validation
Definition mdbx.h++:3104
bool no_sticky_threads
Definition mdbx.h++:3093
constexpr operate_options() noexcept
Definition mdbx.h++:3105
bool disable_clear_memory
Definition mdbx.h++:3102
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3098
constexpr operate_options(const operate_options &) noexcept=default
bool nested_write_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3096
operate_options(MDBX_env_flags_t) noexcept
Operate parameters.
Definition mdbx.h++:3113
env::durability durability
Definition mdbx.h++:3121
env::operate_options options
Definition mdbx.h++:3123
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++:3127
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++:3119
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3122
env::mode mode
Definition mdbx.h++:3120
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++:3116
constexpr operate_parameters() noexcept
Definition mdbx.h++:3125
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3493
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3496
uint64_t transaction_lag
Definition mdbx.h++:3499
size_t bytes_used
Definition mdbx.h++:3503
uint64_t transaction_id
Definition mdbx.h++:3497
int slot
The reader lock table slot number.
Definition mdbx.h++:3494
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3495
size_t bytes_retained
Definition mdbx.h++:3506
Garbage reclaiming options.
Definition mdbx.h++:3078
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
bool coalesce
Definition mdbx.h++:3082
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3083
bool lifo
Definition mdbx.h++:3080
Additional parameters for creating a new database.
Definition mdbx.h++:3602
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3604
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3605
env::geometry geometry
Definition mdbx.h++:3603
Definition mdbx.h++:2925
map_handle::state state
Definition mdbx.h++:2927
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2926
info & operator=(const info &) noexcept=default
capacity_holder capacity_
Definition mdbx.h++:1567
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1600
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1579
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1620
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1571
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1586
inplace_flag_holder inplace_
Definition mdbx.h++:1568
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1570
allocator_pointer allocated_ptr_
Definition mdbx.h++:1566
size_t stub_capacity_bytes_
Definition mdbx.h++:1543
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1639
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1556
size_t bytes_
Definition mdbx.h++:1557
constexpr const byte * address() const noexcept
Definition mdbx.h++:1633
constexpr bin() noexcept
Definition mdbx.h++:1614
@ inplace_size
Definition mdbx.h++:1551
@ inplace_signature_limit
Definition mdbx.h++:1548
@ inplace_size_rounding
Definition mdbx.h++:1550
constexpr byte * address() noexcept
Definition mdbx.h++:1636
@ lastbyte_poison
Definition mdbx.h++:1546
@ lastbyte_inplace_signature
Definition mdbx.h++:1546
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1629
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1588
allocator_pointer ptr_
Definition mdbx.h++:1542