libmdbx 0.14.1.49 (2025-07-25T14:15:23+03:00)
One of the fastest compact embeddable key-value ACID storage engine without WAL.
 
Loading...
Searching...
No Matches
mdbx.h++
Go to the documentation of this file.
1
18
26
27#pragma once
28
29/* Workaround for modern libstdc++ with CLANG < 4.x */
30#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4
31#define __GLIBCXX_BITSIZE_INT_N_0 128
32#define __GLIBCXX_TYPE_INT_N_0 __int128
33#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
34
35#if !defined(__cplusplus) || __cplusplus < 201103L
36#if !defined(_MSC_VER) || _MSC_VER < 1900
37#error "C++11 compiler or better is required"
38#elif _MSC_VER >= 1910
39#error "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
40#endif /* MSVC is mad and don't define __cplusplus properly */
41#endif /* __cplusplus < 201103L */
42
43#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
44#error "CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
45#endif /* Windows */
46
47#ifndef __has_include
48#define __has_include(header) (0)
49#endif /* __has_include */
50
51#if __has_include(<version>)
52#include <version>
53#endif /* <version> */
54
55/* Disable min/max macros from C' headers */
56#ifndef NOMINMAX
57#define NOMINMAX
58#endif
59
60#include <algorithm> // for std::min/max
61#include <cassert> // for assert()
62#include <climits> // for CHAR_BIT
63#include <cstring> // for std::strlen, str:memcmp
64#include <exception> // for std::exception_ptr
65#include <ostream> // for std::ostream
66#include <sstream> // for std::ostringstream
67#include <stdexcept> // for std::invalid_argument
68#include <string> // for std::string
69#include <type_traits> // for std::is_pod<>, etc.
70#include <utility> // for std::make_pair
71#include <vector> // for std::vector<> as template args
72
73#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
74#include <memory_resource>
75#endif
76
77#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
78#include <string_view>
79#endif
80
81#ifndef MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
82#ifdef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
83#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
84#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && __cplusplus >= 201703L
85#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
86#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
87 (defined(_MSC_VER) && defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && __cplusplus >= 201403L))
88#if defined(__cpp_lib_experimental_filesystem) && __cpp_lib_experimental_filesystem >= 201406L
89#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
90#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && __has_include(<experimental/filesystem>)
91#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
92#else
93#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
94#endif
95#else
96#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
97#endif
98#endif /* MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM */
99
100#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
101#include <experimental/filesystem>
102#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
103#include <filesystem>
104#endif
105
106#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
107#include <span>
108#endif
109
110#if !defined(_MSC_VER) || defined(__clang__)
111/* adequate compilers */
112#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) extern template class API_ATTRIBUTES API_TYPENAME
113#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) template class API_TYPENAME
114#else
115/* stupid microsoft showing off */
116#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) extern template class API_TYPENAME
117#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME) template class API_ATTRIBUTES API_TYPENAME
118#endif
119
120#if __cplusplus >= 201103L
121#include <chrono>
122#include <ratio>
123#endif
124
125#include "mdbx.h"
126
127#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
128 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
129 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
130 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
131#include <bit>
132#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
133#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
134#define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
135#define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
136#define __BYTE_ORDER__ __BYTE_ORDER
137#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
138#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
139#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
140#define __BYTE_ORDER__ _BYTE_ORDER
141#else
142#define __ORDER_LITTLE_ENDIAN__ 1234
143#define __ORDER_BIG_ENDIAN__ 4321
144#if defined(__LITTLE_ENDIAN__) || (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || defined(__ARMEL__) || \
145 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
146 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || defined(__elbrus_4c__) || defined(__elbrus_8c__) || \
147 defined(__bfin__) || defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
148 defined(__ia64) || defined(_M_IA64) || defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
149 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || defined(__WINDOWS__)
150#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
151#elif defined(__BIG_ENDIAN__) || (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || defined(__ARMEB__) || \
152 defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
153 defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
154 defined(__sparc__) || defined(__sparc) || defined(__370__) || defined(__THW_370__) || defined(__s390__) || \
155 defined(__s390x__) || defined(__SYSC_ZARCH__)
156#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
157#endif
158#endif
159#endif /* Byte Order */
160
162#if defined(DOXYGEN)
163#define MDBX_CXX17_CONSTEXPR constexpr
164#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
165 ((defined(_MSC_VER) && _MSC_VER >= 1915) || (defined(__clang__) && __clang_major__ > 5) || \
166 (defined(__GNUC__) && __GNUC__ > 7) || (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
167#define MDBX_CXX17_CONSTEXPR constexpr
168#else
169#define MDBX_CXX17_CONSTEXPR inline
170#endif /* MDBX_CXX17_CONSTEXPR */
171
173#if defined(DOXYGEN)
174#define MDBX_CXX20_CONSTEXPR constexpr
175#elif defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L && \
176 defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
177#define MDBX_CXX20_CONSTEXPR constexpr
178#else
179#define MDBX_CXX20_CONSTEXPR inline
180#endif /* MDBX_CXX20_CONSTEXPR */
181
182#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
183#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
184#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
185#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
186#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
187#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
188#else
189#define MDBX_CXX01_CONSTEXPR_ENUM inline
190#define MDBX_CXX11_CONSTEXPR_ENUM inline
191#define MDBX_CXX14_CONSTEXPR_ENUM inline
192#define MDBX_CXX17_CONSTEXPR_ENUM inline
193#define MDBX_CXX20_CONSTEXPR_ENUM inline
194#endif /* CONSTEXPR_ENUM_FLAGS_OPERATIONS */
195
197#if defined(CONSTEXPR_ASSERT)
198#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
199#elif defined NDEBUG
200#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
201#else
202#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
203#endif /* MDBX_CONSTEXPR_ASSERT */
204
205#ifndef MDBX_LIKELY
206#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
207#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
208#else
209#define MDBX_LIKELY(x) (x)
210#endif
211#endif /* MDBX_LIKELY */
212
213#ifndef MDBX_UNLIKELY
214#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
215#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
216#else
217#define MDBX_UNLIKELY(x) (x)
218#endif
219#endif /* MDBX_UNLIKELY */
220
222#if defined(DOXYGEN)
223#define MDBX_IF_CONSTEXPR constexpr
224#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
225#define MDBX_IF_CONSTEXPR constexpr
226#else
227#define MDBX_IF_CONSTEXPR
228#endif /* MDBX_IF_CONSTEXPR */
229
230#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
231 __cplusplus >= 201703L
232#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
233#else
234#define MDBX_CXX17_FALLTHROUGH
235#endif /* MDBX_CXX17_FALLTHROUGH */
236
237#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
238#define MDBX_CXX20_LIKELY [[likely]]
239#else
240#define MDBX_CXX20_LIKELY
241#endif /* MDBX_CXX20_LIKELY */
242
243#ifndef MDBX_CXX20_UNLIKELY
244#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
245#define MDBX_CXX20_UNLIKELY [[unlikely]]
246#else
247#define MDBX_CXX20_UNLIKELY
248#endif
249#endif /* MDBX_CXX20_UNLIKELY */
250
251#ifndef MDBX_HAVE_CXX20_CONCEPTS
252#if defined(__cpp_concepts) && __cpp_concepts >= 202002L && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
253#include <concepts>
254#define MDBX_HAVE_CXX20_CONCEPTS 1
255#elif defined(DOXYGEN)
256#define MDBX_HAVE_CXX20_CONCEPTS 1
257#else
258#define MDBX_HAVE_CXX20_CONCEPTS 0
259#endif /* <concepts> */
260#endif /* MDBX_HAVE_CXX20_CONCEPTS */
261
262#ifndef MDBX_CXX20_CONCEPT
263#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
264#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
265#else
266#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
267#endif
268#endif /* MDBX_CXX20_CONCEPT */
269
270#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
271#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
272#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
273#else
274#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
275 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
276#endif
277#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
278
279#ifdef _MSC_VER
280#pragma warning(push, 4)
281#pragma warning(disable : 4127) /* conditional expression is constant */
282#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
283 be used by clients of 'mdbx::BAR' */
284#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
285 base for dll-interface 'mdbx::BAR' */
286/* MSVC is mad and can generate this warning for its own intermediate
287 * automatically generated code, which becomes unreachable after some kinds of
288 * optimization (copy elision, etc). */
289#pragma warning(disable : 4702) /* unreachable code */
290#endif /* _MSC_VER (warnings) */
291
292#if defined(__LCC__) && __LCC__ >= 126
293#pragma diagnostic push
294#if __LCC__ < 127
295#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
296 appearing in a constant expression `true` */
297#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
298 appearing in a constant expression `false` */
299#endif
300#endif /* E2K LCC (warnings) */
301
302//------------------------------------------------------------------------------
305namespace mdbx {
306
309
310// Functions whose signature depends on the `mdbx::byte` type
311// must be strictly defined as inline!
312#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
313// To enable all kinds of an compiler optimizations we use a byte-like type
314// that don't presumes aliases for pointers as does the `char` type and its
315// derivatives/typedefs.
316// Please see https://libmdbx.dqdkfa.ru/dead-github/issues/263
317// for reasoning of the use of `char8_t` type and switching to `__restrict__`.
318using byte = char8_t;
319#else
320// Avoid `std::byte` since it doesn't add features but inconvenient
321// restrictions.
322using byte = unsigned char;
323#endif /* __cpp_char8_t >= 201811*/
324
325#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
326using endian = ::std::endian;
327#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
328enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
329#else
330#error "Please use a C++ compiler provides byte order information or C++20 support"
331#endif /* Byte Order enum */
332
341
343static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
344
346static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
348static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
349
352using legacy_allocator = ::std::string::allocator_type;
353
354#if defined(DOXYGEN) || \
355 (defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI)
357using polymorphic_allocator = ::std::pmr::string::allocator_type;
359#else
361#endif /* __cpp_lib_memory_resource >= 201603L */
362
363struct slice;
365template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy> class buffer;
366class env;
367class env_managed;
368class txn;
369class txn_managed;
370class cursor;
371class cursor_managed;
372
375
377template <class ALLOCATOR = default_allocator>
378using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
379
381#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
382#ifdef _MSC_VER
383namespace filesystem = ::std::experimental::filesystem::v1;
384#else
385namespace filesystem = ::std::experimental::filesystem;
386#endif
387#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
388#elif defined(DOXYGEN) || \
389 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
390 __cpp_lib_string_view >= 201606L && \
391 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
392 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
393 (!defined(_MSC_VER) || __cplusplus >= 201703L)
394namespace filesystem = ::std::filesystem;
400#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
401#endif /* MDBX_STD_FILESYSTEM_PATH */
402
403#ifdef MDBX_STD_FILESYSTEM_PATH
405#elif defined(_WIN32) || defined(_WIN64)
406using path = ::std::wstring;
407#else
408using path = ::std::string;
409#endif /* mdbx::path */
410
411#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
412#ifndef MDBX_U128_TYPE
413#define MDBX_U128_TYPE __uint128_t
414#endif /* MDBX_U128_TYPE */
415#ifndef MDBX_I128_TYPE
416#define MDBX_I128_TYPE __int128_t
417#endif /* MDBX_I128_TYPE */
418#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
419
420#if __cplusplus >= 201103L || defined(DOXYGEN)
422using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
423#endif /* Duration for C++11 */
424
427
433 ::std::exception_ptr captured_;
434
435public:
436 exception_thunk() noexcept = default;
439 exception_thunk &operator=(const exception_thunk &) = delete;
440 exception_thunk &operator=(exception_thunk &&) = delete;
441 inline bool is_clean() const noexcept;
442 inline void capture() noexcept;
443 inline void rethrow_captured() const;
444};
445
448 MDBX_error_t code_;
449 inline error &operator=(MDBX_error_t error_code) noexcept;
450
451public:
452 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
453 error(const error &) = default;
454 error(error &&) = default;
455 error &operator=(const error &) = default;
456 error &operator=(error &&) = default;
457
458 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
459 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
460
461 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
462 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
463 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
464 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
465
467 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
468
470 const char *what() const noexcept;
471
473 ::std::string message() const;
474
476 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
478 [[noreturn]] void panic(const char *context_where_when, const char *func_who_what) const noexcept;
479 [[noreturn]] void throw_exception() const;
480 [[noreturn]] static inline void throw_exception(int error_code);
481 inline void throw_on_failure() const;
482 inline void success_or_throw() const;
483 inline void success_or_throw(const exception_thunk &) const;
484 inline void panic_on_failure(const char *context_where, const char *func_who) const noexcept;
485 inline void success_or_panic(const char *context_where, const char *func_who) const noexcept;
486 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
487 static inline void success_or_throw(MDBX_error_t error_code);
488 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
489 static inline void throw_on_failure(int error_code);
490 static inline bool boolean_or_throw(int error_code);
491 static inline void success_or_throw(int error_code, const exception_thunk &);
492 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
493 static inline void panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept;
494 static inline void success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept;
495};
496
499class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
500 using base = ::std::runtime_error;
501 ::mdbx::error error_;
502
503public:
504 exception(const ::mdbx::error &) noexcept;
505 exception(const exception &) = default;
506 exception(exception &&) = default;
507 exception &operator=(const exception &) = default;
509 virtual ~exception() noexcept;
510 const ::mdbx::error error() const noexcept { return error_; }
511};
512
515 using base = exception;
516
517public:
518 fatal(const ::mdbx::error &) noexcept;
519 fatal(const exception &src) noexcept : fatal(src.error()) {}
520 fatal(exception &&src) noexcept : fatal(src.error()) {}
521 fatal(const fatal &src) noexcept : fatal(src.error()) {}
522 fatal(fatal &&src) noexcept : fatal(src.error()) {}
523 fatal &operator=(fatal &&) = default;
524 fatal &operator=(const fatal &) = default;
525 virtual ~fatal() noexcept;
526};
527
528#define MDBX_DECLARE_EXCEPTION(NAME) \
529 struct LIBMDBX_API_TYPE NAME : public exception { \
530 NAME(const ::mdbx::error &); \
531 virtual ~NAME() noexcept; \
532 }
565#undef MDBX_DECLARE_EXCEPTION
566
569[[noreturn]] LIBMDBX_API void throw_out_range();
573static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes);
574static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload);
575static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom);
576
578
579//------------------------------------------------------------------------------
580
583
584#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
585
589template <typename T>
590concept MutableByteProducer = requires(T a, char array[42]) {
591 { a.is_empty() } -> std::same_as<bool>;
592 { a.envisage_result_length() } -> std::same_as<size_t>;
593 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
594};
595
599template <typename T>
600concept ImmutableByteProducer = requires(const T &a, char array[42]) {
601 { a.is_empty() } -> std::same_as<bool>;
602 { a.envisage_result_length() } -> std::same_as<size_t>;
603 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
604};
605
609template <typename T>
610concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
611 T(source);
612 { a.is_erroneous() } -> std::same_as<bool>;
613};
614
615#endif /* MDBX_HAVE_CXX20_CONCEPTS */
616
617template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy,
618 MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
619inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
620
621template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy,
622 MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
623inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer,
624 const ALLOCATOR &allocator = ALLOCATOR());
625
626template <class ALLOCATOR = default_allocator, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
627inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
628
629template <class ALLOCATOR = default_allocator, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
630inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
631
643
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>
769 as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
770 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
771 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), allocator);
772 }
773
774 template <class CHAR, class T, class ALLOCATOR>
775 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
777 }
778
780 template <class ALLOCATOR = default_allocator>
781 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
782 const ALLOCATOR &allocator = ALLOCATOR()) const;
783
786 template <class ALLOCATOR = default_allocator>
787 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &allocator = ALLOCATOR()) const;
788
791 template <class ALLOCATOR = default_allocator>
792 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &allocator = ALLOCATOR()) const;
793
795 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
796 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
797 const ALLOCATOR &allocator = ALLOCATOR()) const;
798
801 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
802 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
803 const ALLOCATOR &allocator = ALLOCATOR()) const;
804
807 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
808 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
809 const ALLOCATOR &allocator = ALLOCATOR()) const;
810
812 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
813 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
814 const ALLOCATOR &allocator = ALLOCATOR()) const;
815
818 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
819 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
820 const ALLOCATOR &allocator = ALLOCATOR()) const;
821
824 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
825 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
826 const ALLOCATOR &allocator = ALLOCATOR()) const;
827
833 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
834
839 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
840
846 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
847
853 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
854
855 inline void swap(slice &other) noexcept;
856
857#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
858 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
859 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
860 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
861 *this = view;
862 view = temp;
863 }
864#endif /* __cpp_lib_string_view >= 201606L */
865
867 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
868 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
869
871 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
872 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
873
875 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
876 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
877
879 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
880 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
881
883 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
884 MDBX_CXX11_CONSTEXPR void *data() noexcept;
885
887 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
888 MDBX_CXX11_CONSTEXPR void *end() noexcept;
889
891 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
892
894 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
895
897 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
898
900 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
901
903 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
904
906 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
907
909 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
910
912 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
913
915 MDBX_CXX14_CONSTEXPR void clear() noexcept;
916
919 inline void remove_prefix(size_t n) noexcept;
920
923 inline void remove_suffix(size_t n) noexcept;
924
927 inline void safe_remove_prefix(size_t n);
928
931 inline void safe_remove_suffix(size_t n);
932
934 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
935
937 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
938
941 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
942
945 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
946
949 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
950
953 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
954
957 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
958
961 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
962
965 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
966
969 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
970
975 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
976
985 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
986
992 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
993 const slice &b) noexcept;
994 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
995 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
996 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
997 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
998 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
999 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
1000
1002 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1003
1005 MDBX_CXX14_CONSTEXPR static slice invalid() noexcept { return slice(size_t(-1)); }
1006
1007 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1008 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1009 "Must be a standard layout type!");
1010 if (MDBX_LIKELY(size() == sizeof(POD)))
1012 POD r;
1013 memcpy(&r, data(), sizeof(r));
1014 return r;
1015 }
1017 }
1018
1019#ifdef MDBX_U128_TYPE
1020 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1021#endif /* MDBX_U128_TYPE */
1022 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1023 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1024 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1025 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1026
1027#ifdef MDBX_I128_TYPE
1028 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1029#endif /* MDBX_I128_TYPE */
1030 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1031 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1032 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1033 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1034
1035#ifdef MDBX_U128_TYPE
1036 MDBX_U128_TYPE as_uint128_adapt() const;
1037#endif /* MDBX_U128_TYPE */
1038 uint64_t as_uint64_adapt() const;
1039 uint32_t as_uint32_adapt() const;
1040 uint16_t as_uint16_adapt() const;
1041 uint8_t as_uint8_adapt() const;
1042
1043#ifdef MDBX_I128_TYPE
1044 MDBX_I128_TYPE as_int128_adapt() const;
1045#endif /* MDBX_I128_TYPE */
1046 int64_t as_int64_adapt() const;
1047 int32_t as_int32_adapt() const;
1048 int16_t as_int16_adapt() const;
1049 int8_t as_int8_adapt() const;
1050
1051protected:
1052 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1053};
1054
1055//------------------------------------------------------------------------------
1056
1058
1059template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1060#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1061 return ::std::allocator_traits<A>::is_always_equal::value;
1062#else
1063 return ::std::is_empty<A>::value;
1064#endif /* __cpp_lib_allocator_traits_is_always_equal */
1065}
1066
1067template <typename T, typename A = typename T::allocator_type,
1068 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1070
1071template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1072 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1073 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1074 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1075 }
1076 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1077 assert(target->get_allocator() != source.get_allocator());
1078 (void)target;
1079 (void)source;
1080 }
1081};
1082
1083template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1084 static constexpr bool is_nothrow() noexcept {
1085 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1086 }
1087 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1088 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) {
1089 assert(target->get_allocator() != source.get_allocator());
1090 target->get_allocator() = ::std::move(source.get_allocator());
1091 }
1092};
1093
1094template <typename T, typename A = typename T::allocator_type,
1095 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1097
1098template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1099 static constexpr bool is_nothrow() noexcept { return false; }
1100 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept {
1101 assert(target->get_allocator() != source.get_allocator());
1102 (void)target;
1103 (void)source;
1104 }
1105};
1106
1107template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1108 static constexpr bool is_nothrow() noexcept {
1109 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1110 }
1111 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1112 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1113 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1114 MDBX_CXX20_UNLIKELY target->get_allocator() =
1115 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1116 } else {
1117 /* gag for buggy compilers */
1118 (void)target;
1119 (void)source;
1120 }
1121 }
1122};
1123
1124template <typename T, typename A = typename T::allocator_type,
1125 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1127
1128template <typename T, typename A> struct swap_alloc<T, A, false> {
1129 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1130 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept(is_nothrow()) {
1132 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1133 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1134 } else {
1135 /* gag for buggy compilers */
1136 (void)target;
1137 (void)source;
1138 }
1139 }
1140};
1141
1142template <typename T, typename A> struct swap_alloc<T, A, true> {
1143 static constexpr bool is_nothrow() noexcept {
1144 return allocator_is_always_equal<A>() ||
1145#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1146 ::std::is_nothrow_swappable<A>() ||
1147#endif /* __cpp_lib_is_swappable >= 201603L */
1148 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1149 }
1150 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept(is_nothrow()) {
1151 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1152 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1153 MDBX_CXX20_UNLIKELY ::std::swap(*target, source);
1154 } else {
1155 /* gag for buggy compilers */
1156 (void)target;
1157 (void)source;
1158 }
1159 }
1160};
1161
1162} // namespace allocation_aware_details
1163
1165 enum : size_t {
1170 };
1171
1172 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1173 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1174 static_assert(pettiness_threshold % 2 == 0, "pettiness_threshold must be even");
1175 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1176 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1177 return (value + pettiness_threshold - 1) & pettiness_mask;
1178 }
1179
1180 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna) {
1181 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1182 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
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 &allocator = ALLOCATOR()) const {
1211 return make_string<ALLOCATOR>(*this, allocator);
1212 }
1213
1215 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1216 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1217 return make_buffer<ALLOCATOR>(*this, allocator);
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 &allocator = ALLOCATOR()) const {
1258 return make_string<ALLOCATOR>(*this, allocator);
1259 }
1260
1263 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1264 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1265 return make_buffer<ALLOCATOR>(*this, allocator);
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 &allocator = ALLOCATOR()) const {
1304 return make_string<ALLOCATOR>(*this, allocator);
1305 }
1306
1309 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1310 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1311 return make_buffer<ALLOCATOR>(*this, allocator);
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 &allocator = ALLOCATOR()) const {
1356 return make_string<ALLOCATOR>(*this, allocator);
1357 }
1358
1360 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1361 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1362 return make_buffer<ALLOCATOR>(*this, allocator);
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 &allocator = ALLOCATOR()) const {
1395 return make_string<ALLOCATOR>(*this, allocator);
1396 }
1397
1400 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1401 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1402 return make_buffer<ALLOCATOR>(*this, allocator);
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 &allocator = ALLOCATOR()) const {
1438 return make_string<ALLOCATOR>(*this, allocator);
1439 }
1440
1443 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1444 buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1445 return make_buffer<ALLOCATOR>(*this, allocator);
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
1468template <class ALLOCATOR, typename CAPACITY_POLICY> class buffer {
1469public:
1470#if !defined(_MSC_VER) || _MSC_VER > 1900
1471 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1472#else
1473 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1474#endif /* MSVC is mad */
1475 using allocator_traits = ::std::allocator_traits<allocator_type>;
1476 using reservation_policy = CAPACITY_POLICY;
1477 enum : size_t {
1479 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1482 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1483 ? alignof(max_align_t) * 2
1486 };
1487
1488private:
1489 friend class txn;
1491 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1492 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1493 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1494
1495 using allocator_pointer = typename allocator_traits::pointer;
1496 using allocator_const_pointer = typename allocator_traits::const_pointer;
1497
1498 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1499 assert(bytes >= sizeof(bin));
1500 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1501 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1502 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1503 const size_t n = (bytes + unit - 1) / unit;
1504 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1505 }
1506 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1507 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1508 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1509 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1510 }
1511
1512 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1513#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1514 return static_cast<void *>(::std::to_address(ptr));
1515#else
1516 return static_cast<void *>(::std::addressof(*ptr));
1517#endif /* __cpp_lib_to_address */
1518 }
1519 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1520#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1521 return static_cast<const void *>(::std::to_address(ptr));
1522#else
1523 return static_cast<const void *>(::std::addressof(*ptr));
1524#endif /* __cpp_lib_to_address */
1525 }
1526
1527 union alignas(max_align_t) bin {
1528 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1529 с учетом выравнивания */
1530 {
1531 allocator_pointer ptr_;
1533 };
1534
1536 enum : size_t {
1538 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1542 };
1543
1545 byte pad_[inplace_size - sizeof(allocator_pointer)];
1546 size_t bytes_;
1547 };
1548
1550 byte buffer_[inplace_size - sizeof(byte)];
1552 };
1553
1554 allocator_pointer allocated_ptr_;
1557
1558 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1559 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1560 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1561 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1562 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1563 return capacity_bytes < sizeof(bin);
1564 }
1565
1566 constexpr bool is_inplace() const noexcept {
1567 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1568 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1570 "WTF?");
1571 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1572 }
1573 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1574
1575 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1576 if (destroy_ptr) {
1578 /* properly destroy allocator::pointer */
1579 allocated_ptr_.~allocator_pointer();
1580 }
1581 if (::std::is_trivial<allocator_pointer>::value)
1582 /* workaround for "uninitialized" warning from some compilers */
1583 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1586 return address();
1587 }
1588
1589 template <bool construct_ptr>
1590 MDBX_CXX17_CONSTEXPR byte *make_allocated(allocator_pointer ptr, size_t capacity_bytes) noexcept {
1592 if (construct_ptr) {
1593 /* properly construct allocator::pointer */
1594 new (&allocated_ptr_) allocator_pointer(ptr);
1595 capacity_.bytes_ = capacity_bytes;
1596 } else {
1598 allocated_ptr_ = ptr;
1599 capacity_.bytes_ = capacity_bytes;
1600 }
1601 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(ptr) && capacity() == capacity_bytes);
1602 return address();
1603 }
1604
1605 MDBX_CXX20_CONSTEXPR bin(size_t capacity_bytes = 0) noexcept {
1608 (void)capacity_bytes;
1609 }
1610 MDBX_CXX20_CONSTEXPR bin(allocator_pointer ptr, size_t capacity_bytes) noexcept {
1612 make_allocated<true>(ptr, capacity_bytes);
1613 }
1615 if (is_allocated())
1616 /* properly destroy allocator::pointer */
1617 allocated_ptr_.~allocator_pointer();
1618 }
1619 MDBX_CXX20_CONSTEXPR bin(bin &&ditto) noexcept {
1620 if (ditto.is_inplace()) {
1621 // micro-optimization: don't use make_inplace<> here
1622 // since memcpy() will copy the flag.
1623 memcpy(&inplace_, &ditto.inplace_, sizeof(inplace_));
1625 } else {
1626 new (&allocated_ptr_) allocator_pointer(::std::move(ditto.allocated_ptr_));
1627 capacity_.bytes_ = ditto.capacity_.bytes_;
1628 ditto.make_inplace<true>();
1630 }
1631 }
1632
1633 MDBX_CXX17_CONSTEXPR bin &operator=(const bin &ditto) noexcept {
1634 if (ditto.is_inplace()) {
1635 // micro-optimization: don't use make_inplace<> here
1636 // since memcpy() will copy the flag.
1637 if (is_allocated())
1638 /* properly destroy allocator::pointer */
1639 allocated_ptr_.~allocator_pointer();
1640 memcpy(&inplace_, &ditto.inplace_, sizeof(inplace_));
1642 } else if (is_inplace())
1643 make_allocated<true>(ditto.allocated_ptr_, ditto.capacity_.bytes_);
1644 else
1645 make_allocated<false>(ditto.allocated_ptr_, ditto.capacity_.bytes_);
1646 return *this;
1647 }
1648
1650 operator=(const_cast<const bin &>(ditto));
1651 if (ditto.is_allocated())
1652 ditto.make_inplace<true>();
1653 return *this;
1654 }
1655
1656 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1657 if (MDBX_UNLIKELY(wanna > max_capacity))
1658 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1659
1660 const size_t advised = reservation_policy::advise(current, wanna);
1661 assert(advised >= wanna);
1662 return ::std::min(size_t(max_capacity), ::std::max(sizeof(bin) - 1, advised));
1663 }
1664
1665 constexpr const byte *address() const noexcept {
1666 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1667 }
1669 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1670 }
1671 constexpr size_t capacity() const noexcept { return is_inplace() ? sizeof(bin) - 1 : capacity_.bytes_; }
1672 } bin_;
1673
1674 MDBX_CXX20_CONSTEXPR void *init(size_t capacity) {
1675 capacity = bin::advise_capacity(0, capacity);
1676 if (bin_.is_suitable_for_inplace(capacity))
1677 new (&bin_) bin();
1678 else {
1679 const auto pair = allocate_storage(capacity);
1680 assert(pair.second >= capacity);
1681 new (&bin_) bin(pair.first, pair.second);
1682 }
1683 return bin_.address();
1684 }
1685
1686 MDBX_CXX20_CONSTEXPR void release() noexcept {
1687 if (bin_.is_allocated()) {
1688 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1689 bin_.template make_inplace<true>();
1690 }
1691 }
1692
1693 template <bool external_content>
1694 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1695 const void *const content, const size_t length) {
1696 assert(wanna_capacity >= wanna_headroom + length);
1697 const size_t old_capacity = bin_.capacity();
1698 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1699 if (MDBX_LIKELY(new_capacity == old_capacity))
1701 assert(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1702 byte *const new_place = bin_.address() + wanna_headroom;
1703 if (MDBX_LIKELY(length))
1705 if (external_content)
1706 memcpy(new_place, content, length);
1707 else {
1708 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1709 assert(old_capacity >= old_headroom + length);
1710 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1711 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1712 }
1713 }
1714 return new_place;
1715 }
1716
1717 if (bin::is_suitable_for_inplace(new_capacity)) {
1718 assert(bin_.is_allocated());
1719 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1720 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1721 if (MDBX_LIKELY(length))
1722 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1723 deallocate_storage(old_allocated, old_capacity);
1724 return new_place;
1725 }
1726
1727 if (!bin_.is_allocated()) {
1728 const auto pair = allocate_storage(new_capacity);
1729 assert(pair.second >= new_capacity);
1730 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1731 if (MDBX_LIKELY(length))
1732 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1733 bin_.template make_allocated<true>(pair.first, pair.second);
1734 return new_place;
1735 }
1736
1737 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1738 if (external_content)
1739 deallocate_storage(old_allocated, old_capacity);
1740 const auto pair = allocate_storage(new_capacity);
1741 assert(pair.second >= new_capacity);
1742 byte *const new_place = bin_.template make_allocated<false>(pair.first, pair.second) + wanna_headroom;
1743 if (MDBX_LIKELY(length))
1744 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1745 if (!external_content)
1746 deallocate_storage(old_allocated, old_capacity);
1747 return new_place;
1748 }
1749
1750 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1751 assert(capacity() >= offset);
1752 return bin_.address() + offset;
1753 }
1754 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1755 assert(capacity() >= offset);
1756 return bin_.address() + offset;
1757 }
1758 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1759 assert(capacity() >= offset + length);
1760 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1761 }
1762
1763 //--------------------------------------------------------------------------
1764
1766 silo() noexcept : allocator_type() { init(0); }
1768 silo(const allocator_type &alloc) noexcept : allocator_type(alloc) { init(0); }
1769 MDBX_CXX20_CONSTEXPR silo(size_t capacity) : allocator_type() { init(capacity); }
1770 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc) : allocator_type(alloc) { init(capacity); }
1771
1772 MDBX_CXX20_CONSTEXPR silo(silo &&ditto) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1773 : allocator_type(::std::move(ditto.get_allocator())), bin_(::std::move(ditto.bin_)) {}
1774
1775 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length) : silo(capacity) {
1776 assert(capacity >= headroom + length);
1777 if (length)
1778 put(headroom, ptr, length);
1779 }
1780
1781 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1782 const allocator_type &alloc)
1783 : silo(capacity, alloc) {
1784 assert(capacity >= headroom + length);
1785 if (length)
1786 put(headroom, ptr, length);
1787 }
1788
1789 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length) : silo(length, 0, ptr, length) {}
1790 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc)
1791 : silo(length, 0, ptr, length, alloc) {}
1792
1793 ~silo() { release(); }
1794
1795 //--------------------------------------------------------------------------
1796
1797 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1798 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1799 }
1800 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1801
1802 MDBX_CXX20_CONSTEXPR silo &assign(const silo &ditto, size_t headroom, slice &content) {
1803 assert(ditto.get() + headroom == content.byte_ptr());
1804 if MDBX_IF_CONSTEXPR (!allocation_aware_details::allocator_is_always_equal<allocator_type>()) {
1805 if (MDBX_UNLIKELY(get_allocator() != ditto.get_allocator()))
1806 MDBX_CXX20_UNLIKELY {
1807 release();
1808 allocation_aware_details::copy_assign_alloc<silo, allocator_type>::propagate(this, ditto);
1809 }
1810 }
1811 content.iov_base = reshape<true>(ditto.capacity(), headroom, content.data(), content.length());
1812 return *this;
1813 }
1814
1816 assign(silo &&ditto, size_t headroom,
1817 slice &content) noexcept(allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_nothrow()) {
1818 assert(ditto.get() + headroom == content.byte_ptr());
1819 if (allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, ditto)) {
1820 release();
1821 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, ditto);
1822 /* no reallocation nor copying required */
1823 bin_ = ::std::move(ditto.bin_);
1824 assert(get() + headroom == content.byte_ptr());
1825 } else {
1826 /* copy content since allocators are different */
1827 content.iov_base = reshape<true>(ditto.capacity(), headroom, content.data(), content.length());
1828 ditto.release();
1829 }
1830 return *this;
1831 }
1832
1833 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1834 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1835 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1836 }
1837 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1838 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1839 }
1841 swap(silo &ditto) noexcept(allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1842 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(this, ditto);
1843 ::std::swap(bin_, ditto.bin_);
1844 }
1845
1846 /* MDBX_CXX20_CONSTEXPR void shrink_to_fit() { TODO } */
1847
1848 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1849 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1850 return get(offset);
1851 }
1852 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1853 };
1854
1855 silo silo_;
1856 ::mdbx::slice slice_;
1857
1858 void insulate() {
1859 assert(is_reference());
1860 silo_.assign(slice_.char_ptr(), slice_.length());
1861 slice_.iov_base = silo_.data();
1862 }
1863
1864 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1865 return static_cast<const byte *>(silo_.data());
1866 }
1867
1868 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1869 return silo_begin() + silo_.capacity();
1870 }
1871
1872 struct data_preserver : public exception_thunk {
1873 buffer data;
1874 data_preserver(allocator_type &allocator) : data(allocator) {}
1875 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1876 auto self = static_cast<data_preserver *>(context);
1877 assert(self->is_clean());
1878 assert(&self->data.slice_ == target);
1879 (void)target;
1880 try {
1881 self->data.assign(src, bytes, false);
1882 return MDBX_RESULT_FALSE;
1883 } catch (... /* capture any exception to rethrow it over C code */) {
1884 self->capture();
1885 return MDBX_RESULT_TRUE;
1886 }
1887 }
1888 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1889 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1890 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1891 };
1892
1893public:
1897
1900
1902 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1903
1907 static_assert(size_t(-long(max_length)) > max_length, "WTF?");
1908 return size_t(byte_ptr() - silo_begin()) < silo_.capacity();
1909 }
1910
1914
1917 return is_freestanding() ? silo_.capacity() : 0;
1918 }
1919
1923 return is_freestanding() ? slice_.byte_ptr() - silo_begin() : 0;
1924 }
1925
1929 return is_freestanding() ? capacity() - headroom() - slice_.length() : 0;
1930 }
1931
1933 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return slice_.byte_ptr(); }
1934
1936 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return slice_.end_byte_ptr(); }
1937
1942 return const_cast<byte *>(slice_.byte_ptr());
1943 }
1944
1949 return const_cast<byte *>(slice_.end_byte_ptr());
1950 }
1951
1953 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return slice_.char_ptr(); }
1954
1956 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return slice_.end_char_ptr(); }
1957
1962 return const_cast<char *>(slice_.char_ptr());
1963 }
1964
1969 return const_cast<char *>(slice_.end_char_ptr());
1970 }
1971
1973 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return slice_.data(); }
1974
1976 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return slice_.end(); }
1977
1980 MDBX_CXX11_CONSTEXPR void *data() noexcept {
1982 return const_cast<void *>(slice_.data());
1983 }
1984
1987 MDBX_CXX11_CONSTEXPR void *end() noexcept {
1989 return const_cast<void *>(slice_.end());
1990 }
1991
1994 return MDBX_CONSTEXPR_ASSERT(is_reference() || slice_.length() + headroom() <= silo_.capacity()), slice_.length();
1995 }
1996
1999 MDBX_CONSTEXPR_ASSERT(is_reference() || bytes + headroom() <= silo_.capacity());
2000 slice_.set_length(bytes);
2001 return *this;
2002 }
2003
2006 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2007 return set_length(static_cast<const char *>(ptr) - char_ptr());
2008 }
2009
2014 if (is_reference())
2015 insulate();
2016 }
2017
2018 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2019 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &allocator) noexcept : silo_(allocator) {}
2020
2021 buffer(const struct slice &src, bool make_reference, const allocator_type &allocator = allocator_type())
2022 : silo_(allocator), slice_(src) {
2023 if (!make_reference)
2024 insulate();
2025 }
2026
2027 buffer(const buffer &src, bool make_reference, const allocator_type &allocator = allocator_type())
2028 : buffer(src.slice_, make_reference, allocator) {}
2029
2030 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &allocator = allocator_type())
2031 : buffer(::mdbx::slice(ptr, bytes), make_reference, allocator) {}
2032
2033 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2034 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2035
2036 buffer(const char *c_str, bool make_reference, const allocator_type &allocator = allocator_type())
2037 : buffer(::mdbx::slice(c_str), make_reference, allocator) {}
2038
2039#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2040 template <class CHAR, class T>
2041 buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2042 const allocator_type &allocator = allocator_type())
2043 : buffer(::mdbx::slice(view), make_reference, allocator) {}
2044#endif /* __cpp_lib_string_view >= 201606L */
2045
2047 buffer(const struct slice &src, const allocator_type &allocator = allocator_type())
2048 : silo_(src.data(), src.length(), allocator), slice_(silo_.data(), src.length()) {}
2049
2051 buffer(const buffer &src, const allocator_type &allocator = allocator_type()) : buffer(src.slice_, allocator) {}
2052
2054 buffer(const void *ptr, size_t bytes, const allocator_type &allocator = allocator_type())
2055 : buffer(::mdbx::slice(ptr, bytes), allocator) {}
2056
2057 template <class CHAR, class T, class A>
2058 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2059 const allocator_type &allocator = allocator_type())
2060 : buffer(::mdbx::slice(str), allocator) {}
2061
2063 buffer(const char *c_str, const allocator_type &allocator = allocator_type())
2064 : buffer(::mdbx::slice(c_str), allocator) {}
2065
2066#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2067 template <class CHAR, class T>
2068 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2069 const allocator_type &allocator = allocator_type())
2070 : buffer(::mdbx::slice(view), allocator) {}
2071#endif /* __cpp_lib_string_view >= 201606L */
2072
2073 buffer(size_t head_room, size_t tail_room, const allocator_type &allocator = allocator_type()) : silo_(allocator) {
2074 slice_.iov_base = silo_.init(check_length(head_room, tail_room));
2075 assert(slice_.iov_len == 0);
2076 }
2077
2078 buffer(size_t capacity, const allocator_type &allocator = allocator_type()) : silo_(allocator) {
2079 slice_.iov_base = silo_.init(check_length(capacity));
2080 assert(slice_.iov_len == 0);
2081 }
2082
2083 buffer(size_t head_room, const struct slice &src, size_t tail_room,
2084 const allocator_type &allocator = allocator_type())
2085 : silo_(allocator) {
2086 slice_.iov_base = silo_.init(check_length(head_room, src.length(), tail_room));
2087 slice_.iov_len = src.length();
2088 memcpy(slice_.iov_base, src.data(), src.length());
2089 }
2090
2091 buffer(size_t head_room, const buffer &src, size_t tail_room, const allocator_type &allocator = allocator_type())
2092 : buffer(head_room, src.slice_, tail_room, allocator) {}
2093
2094 inline buffer(const ::mdbx::txn &txn, const struct slice &src, const allocator_type &allocator = allocator_type());
2095
2096 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2097 : silo_(::std::move(src.silo_)), slice_(::std::move(src.slice_)) {}
2098
2099 MDBX_CXX11_CONSTEXPR const struct slice &slice() const noexcept { return slice_; }
2100
2101 MDBX_CXX11_CONSTEXPR operator const struct slice &() const noexcept { return slice_; }
2102
2103#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
2104 template <typename POD> MDBX_CXX14_CONSTEXPR buffer(const ::std::span<POD> &span) : buffer(span.begin(), span.end()) {
2105 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
2106 "Must be a standard layout type!");
2107 }
2108
2109 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
2110 return slice_.template as_span<const POD>();
2111 }
2112 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() { return slice_.template as_span<POD>(); }
2113
2114 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
2115 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
2116 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
2117 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
2118#endif /* __cpp_lib_span >= 202002L */
2119
2120 template <typename POD>
2121 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &allocator = allocator_type()) {
2122 return buffer(::mdbx::slice::wrap(pod), make_reference, allocator);
2123 }
2124
2125 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const { return slice_.as_pod<POD>(); }
2126
2127#ifdef MDBX_U128_TYPE
2128 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return slice().as_uint128(); }
2129#endif /* MDBX_U128_TYPE */
2130 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return slice().as_uint64(); }
2131 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return slice().as_uint32(); }
2132 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return slice().as_uint16(); }
2133 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return slice().as_uint8(); }
2134
2135#ifdef MDBX_I128_TYPE
2136 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return slice().as_int128(); }
2137#endif /* MDBX_I128_TYPE */
2138 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return slice().as_int64(); }
2139 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return slice().as_int32(); }
2140 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return slice().as_int16(); }
2141 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return slice().as_int8(); }
2142
2143#ifdef MDBX_U128_TYPE
2144 MDBX_U128_TYPE as_uint128_adapt() const { return slice().as_uint128_adapt(); }
2145#endif /* MDBX_U128_TYPE */
2146 uint64_t as_uint64_adapt() const { return slice().as_uint64_adapt(); }
2147 uint32_t as_uint32_adapt() const { return slice().as_uint32_adapt(); }
2148 uint16_t as_uint16_adapt() const { return slice().as_uint16_adapt(); }
2149 uint8_t as_uint8_adapt() const { return slice().as_uint8_adapt(); }
2150
2151#ifdef MDBX_I128_TYPE
2152 MDBX_I128_TYPE as_int128_adapt() const { return slice().as_int128_adapt(); }
2153#endif /* MDBX_I128_TYPE */
2154 int64_t as_int64_adapt() const { return slice().as_int64_adapt(); }
2155 int32_t as_int32_adapt() const { return slice().as_int32_adapt(); }
2156 int16_t as_int16_adapt() const { return slice().as_int16_adapt(); }
2157 int8_t as_int8_adapt() const { return slice().as_int8_adapt(); }
2158
2160 static buffer hex(const ::mdbx::slice &source, bool uppercase = false, unsigned wrap_width = 0,
2161 const allocator_type &allocator = allocator_type()) {
2162 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, allocator);
2163 }
2164
2167 static buffer base58(const ::mdbx::slice &source, unsigned wrap_width = 0,
2168 const allocator_type &allocator = allocator_type()) {
2169 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, allocator);
2170 }
2171
2173 static buffer base64(const ::mdbx::slice &source, unsigned wrap_width = 0,
2174 const allocator_type &allocator = allocator_type()) {
2175 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, allocator);
2176 }
2177
2179 template <typename POD>
2180 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2181 const allocator_type &allocator = allocator_type()) {
2182 return hex(mdbx::slice::wrap(pod), uppercase, wrap_width, allocator);
2183 }
2184
2187 template <typename POD>
2188 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &allocator = allocator_type()) {
2189 return base58(mdbx::slice::wrap(pod), wrap_width, allocator);
2190 }
2191
2194 template <typename POD>
2195 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &allocator = allocator_type()) {
2196 return base64(mdbx::slice::wrap(pod), wrap_width, allocator);
2197 }
2198
2200 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2201 const allocator_type &allocator = allocator_type()) const {
2202 return slice().template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, allocator);
2203 }
2204
2207 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &allocator = allocator_type()) const {
2208 return slice().template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, allocator);
2209 }
2210
2212 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &allocator = allocator_type()) const {
2213 return slice().template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, allocator);
2214 }
2215
2217 static buffer hex_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2218 const allocator_type &allocator = allocator_type()) {
2219 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, allocator);
2220 }
2221
2224 static buffer base58_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2225 const allocator_type &allocator = allocator_type()) {
2226 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, allocator);
2227 }
2228
2231 static buffer base64_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2232 const allocator_type &allocator = allocator_type()) {
2233 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, allocator);
2234 }
2235
2238 buffer hex_decode(bool ignore_spaces = false, const allocator_type &allocator = allocator_type()) const {
2239 return hex_decode(slice(), ignore_spaces, allocator);
2240 }
2241
2244 buffer base58_decode(bool ignore_spaces = false, const allocator_type &allocator = allocator_type()) const {
2245 return base58_decode(slice(), ignore_spaces, allocator);
2246 }
2247
2250 buffer base64_decode(bool ignore_spaces = false, const allocator_type &allocator = allocator_type()) const {
2251 return base64_decode(slice(), ignore_spaces, allocator);
2252 }
2253
2255 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2256 wanna_headroom = ::std::min(::std::max(headroom(), wanna_headroom), wanna_headroom + pettiness_threshold);
2257 wanna_tailroom = ::std::min(::std::max(tailroom(), wanna_tailroom), wanna_tailroom + pettiness_threshold);
2258 const size_t wanna_capacity = check_length(wanna_headroom, slice_.length(), wanna_tailroom);
2259 silo_.resize(wanna_capacity, wanna_headroom, slice_);
2260 assert(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2261 assert(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2262 }
2263
2265 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2266
2268 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2269
2270 buffer &assign_reference(const void *ptr, size_t bytes) {
2271 silo_.clear();
2272 slice_.assign(ptr, bytes);
2273 return *this;
2274 }
2275
2276 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2277 silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes));
2278 slice_.assign(silo_.data(), bytes);
2279 return *this;
2280 }
2281
2282 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2283 silo_.swap(other.silo_);
2284 slice_.swap(other.slice_);
2285 }
2286
2287 static buffer clone(const buffer &src, const allocator_type &allocator = allocator_type()) {
2288 return buffer(src.headroom(), src.slice_, src.tailroom(), allocator);
2289 }
2290
2291 buffer &assign(const buffer &src, bool make_reference = false) { return assign(src.slice_, make_reference); }
2292
2293 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2294 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2295 }
2296
2297 buffer &assign(const struct slice &src, bool make_reference = false) {
2298 return assign(src.data(), src.length(), make_reference);
2299 }
2300
2301 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2302 return assign(src.iov_base, src.iov_len, make_reference);
2303 }
2304
2305 buffer &assign(struct slice &&src, bool make_reference = false) {
2306 assign(src.data(), src.length(), make_reference);
2307 src.invalidate();
2308 return *this;
2309 }
2310
2311 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2312 assign(src.iov_base, src.iov_len, make_reference);
2313 src.iov_base = nullptr;
2314 return *this;
2315 }
2316
2317 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2318 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2319 }
2320
2321 template <class CHAR, class T, class A>
2322 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2323 return assign(str.data(), str.length(), make_reference);
2324 }
2325
2326 buffer &assign(const char *c_str, bool make_reference = false) {
2327 return assign(c_str, ::mdbx::strlen(c_str), make_reference);
2328 }
2329
2330#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2331 template <class CHAR, class T>
2332 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2333 return assign(view.data(), view.length(), make_reference);
2334 }
2335
2336 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2337 assign(view.data(), view.length(), make_reference);
2338 view = {};
2339 return *this;
2340 }
2341#endif /* __cpp_lib_string_view >= 201606L */
2342
2343 buffer &operator=(const buffer &src) { return assign(src); }
2344
2345 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2346
2347 buffer &operator=(const struct slice &src) { return assign(src); }
2348
2349 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2350
2351#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2352 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2353 return assign(view);
2354 }
2355
2357 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
2358 ::std::basic_string_view<CHAR, T> string_view() const noexcept {
2359 return slice_.string_view<CHAR, T>();
2360 }
2361
2363 template <class CHAR, class T> operator ::std::basic_string_view<CHAR, T>() const noexcept {
2364 return string_view<CHAR, T>();
2365 }
2366#endif /* __cpp_lib_string_view >= 201606L */
2367
2369 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR bool empty() const noexcept { return length() == 0; }
2370
2372 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept { return data() == nullptr; }
2373
2375 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR size_t size() const noexcept { return length(); }
2376
2381 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept { return slice_.hash_value(); }
2382
2383 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class A = legacy_allocator>
2384 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, A> as_string(const A &allocator = A()) const {
2385 return slice_.as_string<CHAR, T, A>(allocator);
2386 }
2387
2388 template <class CHAR, class T, class A>
2389 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2390 return as_string<CHAR, T, A>();
2391 }
2392
2394 MDBX_NOTHROW_PURE_FUNCTION bool starts_with(const struct slice &prefix) const noexcept {
2395 return slice_.starts_with(prefix);
2396 }
2397
2399 MDBX_NOTHROW_PURE_FUNCTION bool ends_with(const struct slice &suffix) const noexcept {
2400 return slice_.ends_with(suffix);
2401 }
2402
2404 void clear() noexcept { slice_.assign(silo_.clear(), size_t(0)); }
2405
2407 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2408 slice_.assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2409 }
2410
2412 void shrink_to_fit() { reserve(0, 0); }
2413
2416 void remove_prefix(size_t n) noexcept { slice_.remove_prefix(n); }
2417
2420 void remove_suffix(size_t n) noexcept { slice_.remove_suffix(n); }
2421
2424 void safe_remove_prefix(size_t n) { slice_.safe_remove_prefix(n); }
2425
2428 void safe_remove_suffix(size_t n) { slice_.safe_remove_suffix(n); }
2429
2432 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept {
2434 return slice_[n];
2435 }
2436
2439 MDBX_CXX11_CONSTEXPR byte &operator[](size_t n) noexcept {
2441 return byte_ptr()[n];
2442 }
2443
2446 MDBX_CXX14_CONSTEXPR byte at(size_t n) const { return slice_.at(n); }
2447
2450 MDBX_CXX14_CONSTEXPR byte &at(size_t n) {
2451 if (MDBX_UNLIKELY(n >= size()))
2452 MDBX_CXX20_UNLIKELY throw_out_range();
2453 return byte_ptr()[n];
2454 }
2455
2458 MDBX_CXX14_CONSTEXPR struct slice head(size_t n) const noexcept { return slice_.head(n); }
2459
2462 MDBX_CXX14_CONSTEXPR struct slice tail(size_t n) const noexcept { return slice_.tail(n); }
2463
2466 MDBX_CXX14_CONSTEXPR struct slice middle(size_t from, size_t n) const noexcept { return slice_.middle(from, n); }
2467
2470 MDBX_CXX14_CONSTEXPR struct slice safe_head(size_t n) const { return slice_.safe_head(n); }
2471
2474 MDBX_CXX14_CONSTEXPR struct slice safe_tail(size_t n) const { return slice_.safe_tail(n); }
2475
2478 MDBX_CXX14_CONSTEXPR struct slice safe_middle(size_t from, size_t n) const { return slice_.safe_middle(from, n); }
2479
2480 buffer &append(const void *src, size_t bytes) {
2481 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2482 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2483 memcpy(end_byte_ptr(), src, bytes);
2484 slice_.iov_len += bytes;
2485 return *this;
2486 }
2487
2488 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2489
2490 buffer &add_header(const void *src, size_t bytes) {
2491 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2492 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2493 slice_.iov_base = memcpy(static_cast<char *>(slice_.iov_base) - bytes, src, bytes);
2494 slice_.iov_len += bytes;
2495 return *this;
2496 }
2497
2498 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2499
2500 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2501 const size_t wanna_bytes = producer.envisage_result_length();
2502 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2503 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2504 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2505 }
2506
2507 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2508 const size_t wanna_bytes = producer.envisage_result_length();
2509 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2510 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2511 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2512 }
2513
2514 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2515 return append_producer(to_hex(data, uppercase, wrap_width));
2516 }
2517
2518 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2519 return append_producer(to_base58(data, wrap_width));
2520 }
2521
2522 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2523 return append_producer(to_base64(data, wrap_width));
2524 }
2525
2526 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2527 return append_producer(from_hex(data, ignore_spaces));
2528 }
2529
2530 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2531 return append_producer(from_base58(data, ignore_spaces));
2532 }
2533
2534 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2535 return append_producer(from_base64(data, ignore_spaces));
2536 }
2537
2538 buffer &append_u8(uint_fast8_t u8) {
2539 if (MDBX_UNLIKELY(tailroom() < 1))
2540 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2541 *slice_.end_byte_ptr() = uint8_t(u8);
2542 slice_.iov_len += 1;
2543 return *this;
2544 }
2545
2546 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2547
2548 buffer &append_u16(uint_fast16_t u16) {
2549 if (MDBX_UNLIKELY(tailroom() < 2))
2550 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2551 const auto ptr = slice_.end_byte_ptr();
2552 ptr[0] = uint8_t(u16);
2553 ptr[1] = uint8_t(u16 >> 8);
2554 slice_.iov_len += 2;
2555 return *this;
2556 }
2557
2558 buffer &append_u24(uint_fast32_t u24) {
2559 if (MDBX_UNLIKELY(tailroom() < 3))
2560 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2561 const auto ptr = slice_.end_byte_ptr();
2562 ptr[0] = uint8_t(u24);
2563 ptr[1] = uint8_t(u24 >> 8);
2564 ptr[2] = uint8_t(u24 >> 16);
2565 slice_.iov_len += 3;
2566 return *this;
2567 }
2568
2569 buffer &append_u32(uint_fast32_t u32) {
2570 if (MDBX_UNLIKELY(tailroom() < 4))
2571 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2572 const auto ptr = slice_.end_byte_ptr();
2573 ptr[0] = uint8_t(u32);
2574 ptr[1] = uint8_t(u32 >> 8);
2575 ptr[2] = uint8_t(u32 >> 16);
2576 ptr[3] = uint8_t(u32 >> 24);
2577 slice_.iov_len += 4;
2578 return *this;
2579 }
2580
2581 buffer &append_u48(uint_fast64_t u48) {
2582 if (MDBX_UNLIKELY(tailroom() < 6))
2583 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2584 const auto ptr = slice_.end_byte_ptr();
2585 ptr[0] = uint8_t(u48);
2586 ptr[1] = uint8_t(u48 >> 8);
2587 ptr[2] = uint8_t(u48 >> 16);
2588 ptr[3] = uint8_t(u48 >> 24);
2589 ptr[4] = uint8_t(u48 >> 32);
2590 ptr[5] = uint8_t(u48 >> 40);
2591 slice_.iov_len += 6;
2592 return *this;
2593 }
2594
2595 buffer &append_u64(uint_fast64_t u64) {
2596 if (MDBX_UNLIKELY(tailroom() < 8))
2597 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2598 const auto ptr = slice_.end_byte_ptr();
2599 ptr[0] = uint8_t(u64);
2600 ptr[1] = uint8_t(u64 >> 8);
2601 ptr[2] = uint8_t(u64 >> 16);
2602 ptr[3] = uint8_t(u64 >> 24);
2603 ptr[4] = uint8_t(u64 >> 32);
2604 ptr[5] = uint8_t(u64 >> 40);
2605 ptr[6] = uint8_t(u64 >> 48);
2606 ptr[7] = uint8_t(u64 >> 56);
2607 slice_.iov_len += 8;
2608 return *this;
2609 }
2610
2611 //----------------------------------------------------------------------------
2612
2613 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2614 return buffer(::mdbx::slice(text), make_reference);
2615 }
2616
2617#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2618 template <class CHAR, class T>
2619 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2620 return buffer(src, make_reference);
2621 }
2622#endif /* __cpp_lib_string_view >= 201606L */
2623
2624 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2625
2626 template <class CHAR, class T, class A>
2627 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2628 return buffer(src, make_reference);
2629 }
2630
2631 static buffer key_from(silo &&src) noexcept { return buffer(::std::move(src)); }
2632
2633 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2634
2635 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2636
2637 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2638
2639 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2640
2641 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2642
2643 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2644
2645 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2646
2647 static buffer key_from_jsonInteger(const int64_t json_integer) {
2648 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2649 }
2650
2651 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2652
2653 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2654
2655 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2656
2657 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2658
2659 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2660
2661 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2662
2663 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2664};
2665
2666template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2667inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &allocator) {
2668 if (MDBX_LIKELY(!producer.is_empty()))
2670 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), allocator);
2671 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
2672 return result;
2673 }
2674 return buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
2675}
2676
2677template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2678inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &allocator) {
2679 if (MDBX_LIKELY(!producer.is_empty()))
2681 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), allocator);
2682 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
2683 return result;
2684 }
2685 return buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
2686}
2687
2688template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2689inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &allocator) {
2690 string<ALLOCATOR> result(allocator);
2691 if (MDBX_LIKELY(!producer.is_empty()))
2693 result.resize(producer.envisage_result_length());
2694 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
2695 }
2696 return result;
2697}
2698
2699template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2700inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &allocator) {
2701 string<ALLOCATOR> result(allocator);
2702 if (MDBX_LIKELY(!producer.is_empty()))
2704 result.resize(producer.envisage_result_length());
2705 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
2706 }
2707 return result;
2708}
2709
2711
2712#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI
2714#endif /* __cpp_lib_memory_resource >= 201603L */
2715
2719 bool done;
2720 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
2721 value_result(const value_result &) noexcept = default;
2722 value_result &operator=(const value_result &) noexcept = default;
2723 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2724 assert(!done || bool(value));
2725 return done;
2726 }
2727};
2728
2730struct pair {
2731 using stl_pair = std::pair<slice, slice>;
2733 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
2734 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
2735 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
2736 pair(const pair &) noexcept = default;
2737 pair &operator=(const pair &) noexcept = default;
2738 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2739 assert(bool(key) == bool(value));
2740 return key;
2741 }
2743
2745 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
2746
2748 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
2749 const pair &b) noexcept;
2750 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
2751 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
2752 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
2753 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
2754 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
2755 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
2756};
2757
2760struct pair_result : public pair {
2761 bool done;
2764 : pair(key, value), done(done) {}
2765 pair_result(const pair_result &) noexcept = default;
2766 pair_result &operator=(const pair_result &) noexcept = default;
2767 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
2768 assert(!done || (bool(key) && bool(value)));
2769 return done;
2770 }
2771};
2772
2773template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2777 using reservation_policy = CAPACITY_POLICY;
2778 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2780
2783 buffer_pair_spec(const allocator_type &allocator) noexcept : key(allocator), value(allocator) {}
2784
2786 : key(key, allocator), value(value, allocator) {}
2787 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2788 const allocator_type &allocator = allocator_type())
2789 : key(key, make_reference, allocator), value(value, make_reference, allocator) {}
2790
2792 : buffer_pair_spec(pair.first, pair.second, allocator) {}
2793 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &allocator = allocator_type())
2794 : buffer_pair_spec(pair.first, pair.second, make_reference, allocator) {}
2795
2796 buffer_pair_spec(const slice &key, const slice &value, const allocator_type &allocator = allocator_type())
2797 : key(key, allocator), value(value, allocator) {}
2798 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2799 const allocator_type &allocator = allocator_type())
2800 : key(key, make_reference, allocator), value(value, make_reference, allocator) {}
2801
2803 : buffer_pair_spec(pair.key, pair.value, allocator) {}
2804 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &allocator = allocator_type())
2805 : buffer_pair_spec(pair.key, pair.value, make_reference, allocator) {}
2806
2807 buffer_pair_spec(const txn &txn, const slice &key, const slice &value,
2808 const allocator_type &allocator = allocator_type())
2809 : key(txn, key, allocator), value(txn, value, allocator) {}
2810 buffer_pair_spec(const txn &txn, const pair &pair, const allocator_type &allocator = allocator_type())
2811 : buffer_pair_spec(txn, pair.key, pair.value, allocator) {}
2812
2813 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2814 : key(::std::move(key)), value(::std::move(value)) {}
2815 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2816 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2817
2821 return key.is_freestanding() && value.is_freestanding();
2822 }
2823
2826 return key.is_reference() || value.is_reference();
2827 }
2828
2832 key.make_freestanding();
2833 value.make_freestanding();
2834 }
2835
2836 operator pair() const noexcept { return pair(key, value); }
2837};
2838
2840template <typename BUFFER>
2842
2845
2847
2848//------------------------------------------------------------------------------
2849
2852enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2853
2870
2872 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2873}
2874
2876 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2877}
2878
2880 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2881}
2882
2884 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2885}
2886
2888
2946
2950
2952 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2953}
2954
2956 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2957}
2958
2960 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2961}
2962
2964 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2965}
2966
2968
2979 map_handle(const map_handle &) noexcept = default;
2980 map_handle &operator=(const map_handle &) noexcept = default;
2981 operator bool() const noexcept { return dbi != 0; }
2982 operator MDBX_dbi() const { return dbi; }
2983
2995};
2996
2999 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
3000}
3002 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
3003}
3004
3011
3022 friend class txn;
3023
3024protected:
3026 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
3027
3028public:
3029 MDBX_CXX11_CONSTEXPR env() noexcept = default;
3030 env(const env &) noexcept = default;
3031 inline env &operator=(env &&other) noexcept;
3032 inline env(env &&other) noexcept;
3033 inline ~env() noexcept;
3034
3035 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3036 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
3037 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
3038 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
3039 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
3040
3041 //----------------------------------------------------------------------------
3042
3047
3049 enum : intptr_t {
3052 maximal_value = INTPTR_MAX,
3053 kB = 1000,
3054 MB = kB * 1000,
3055 GB = MB * 1000,
3056#if INTPTR_MAX > 0x7fffFFFFl
3057 TB = GB * 1000,
3058 PB = TB * 1000,
3059 EB = PB * 1000,
3060#endif /* 64-bit intptr_t */
3061 KiB = 1024,
3062 MiB = KiB << 10,
3063 GiB = MiB << 10,
3064#if INTPTR_MAX > 0x7fffFFFFl
3065 TiB = GiB << 10,
3066 PiB = TiB << 10,
3067 EiB = PiB << 10,
3068#endif /* 64-bit intptr_t */
3069 };
3070
3072 struct size {
3073 intptr_t bytes;
3074 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3075 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3076 };
3077
3080
3085
3097
3100
3103
3109
3110 inline geometry &make_fixed(intptr_t size) noexcept;
3111 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3114 geometry(const geometry &) noexcept = default;
3120 };
3121
3129
3137
3150
3172
3177 unsigned max_maps{0};
3180 unsigned max_readers{0};
3185
3196 operate_parameters(const operate_parameters &) noexcept = default;
3198 MDBX_env_flags_t make_flags(bool accede = true,
3201 bool use_subdirectory = false
3202 ) const;
3206 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3207 };
3208
3212 inline env::mode get_mode() const;
3214 inline env::durability get_durability() const;
3218 inline env::operate_options get_options() const;
3219
3222 bool is_pristine() const;
3223
3225 bool is_empty() const;
3226
3228 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3229
3230 struct limits {
3231 limits() = delete;
3233 static inline size_t pagesize_min() noexcept;
3235 static inline size_t pagesize_max() noexcept;
3237 static inline size_t dbsize_min(intptr_t pagesize);
3239 static inline size_t dbsize_max(intptr_t pagesize);
3241 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3243 static inline size_t key_min(key_mode mode) noexcept;
3245 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3247 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3249 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3251 static inline size_t key_max(const env &, key_mode mode);
3253 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3255 static inline size_t value_min(value_mode) noexcept;
3256
3258 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3260 static inline size_t value_max(intptr_t pagesize, value_mode);
3262 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3264 static inline size_t value_max(const env &, value_mode);
3265
3268 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3271 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3274 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3277 static inline size_t pairsize4page_max(const env &, value_mode);
3278
3281 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3284 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3287 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3290 static inline size_t valsize4page_max(const env &, value_mode);
3291
3294 static inline size_t transaction_size_max(intptr_t pagesize);
3295
3297 static inline size_t max_map_handles(void);
3298 };
3299
3301 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3303 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3305 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3307 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3309 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3311 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3315
3318#ifdef MDBX_STD_FILESYSTEM_PATH
3319 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3320#endif /* MDBX_STD_FILESYSTEM_PATH */
3321#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3322 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3323 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3324#endif /* Windows */
3325 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3326 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3327
3329 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3330
3346
3348#ifdef MDBX_STD_FILESYSTEM_PATH
3349 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3350#endif /* MDBX_STD_FILESYSTEM_PATH */
3351#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3352 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3353 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3354#endif /* Windows */
3355 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3356 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3357
3360
3363
3365 inline stat get_stat() const;
3366
3368 size_t get_pagesize() const { return get_stat().ms_psize; }
3369
3371 inline info get_info() const;
3372
3374 inline stat get_stat(const txn &) const;
3375
3377 inline info get_info(const txn &) const;
3378
3380 inline filehandle get_filehandle() const;
3381
3384
3386 inline MDBX_env_flags_t get_flags() const;
3387
3390 inline unsigned max_readers() const;
3391
3394 inline unsigned max_maps() const;
3395
3397 inline void *get_context() const noexcept;
3398
3400 inline env &set_context(void *your_context);
3401
3416 inline env &set_sync_threshold(size_t bytes);
3417
3423 inline size_t sync_threshold() const;
3424
3425#if __cplusplus >= 201103L || defined(DOXYGEN)
3445 inline env &set_sync_period(const duration &period);
3446
3452 inline duration sync_period() const;
3453#endif
3454
3458 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3459
3462 inline unsigned sync_period__seconds_16dot16() const;
3463
3467 inline env &set_sync_period__seconds_double(double seconds);
3468
3471 inline double sync_period__seconds_double() const;
3472
3510
3512 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3513
3515 inline uint64_t extra_option(extra_runtime_option option) const;
3516
3518 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3519
3521 inline env &set_geometry(const geometry &size);
3522
3526 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3527
3531 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3532
3551 inline void close_map(const map_handle &);
3552
3555 int slot;
3564 size_t bytes_used;
3573
3574 MDBX_CXX11_CONSTEXPR reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
3575 size_t used, size_t retained) noexcept;
3576 };
3577
3585 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3586
3589 inline unsigned check_readers();
3590
3609
3614 inline MDBX_hsr_func *get_HandleSlowReaders() const noexcept;
3615
3617 inline txn_managed start_read() const;
3618
3620 inline txn_managed prepare_read() const;
3621
3623 inline txn_managed start_write(txn &parent);
3624
3626 inline txn_managed start_write(bool dont_wait = false);
3627
3630};
3631
3640class LIBMDBX_API_TYPE env_managed : public env {
3641 using inherited = env;
3643 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3644 void setup(unsigned max_maps, unsigned max_readers = 0);
3645
3646public:
3647 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3648
3650#ifdef MDBX_STD_FILESYSTEM_PATH
3651 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3652#endif /* MDBX_STD_FILESYSTEM_PATH */
3653#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3654 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3655 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3656#endif /* Windows */
3657 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3658 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3659
3670
3672#ifdef MDBX_STD_FILESYSTEM_PATH
3674 bool accede = true);
3675#endif /* MDBX_STD_FILESYSTEM_PATH */
3676#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3677 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3678 bool accede = true);
3679 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3680 bool accede = true);
3681#endif /* Windows */
3682 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3683 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3684
3698 void close(bool dont_sync = false);
3699
3700 env_managed(env_managed &&) = default;
3701 env_managed &operator=(env_managed &&other) noexcept {
3703 MDBX_CXX20_UNLIKELY {
3704 assert(handle_ != other.handle_);
3705 close();
3706 }
3707 inherited::operator=(std::move(other));
3708 return *this;
3709 }
3710 env_managed(const env_managed &) = delete;
3711 env_managed &operator=(const env_managed &) = delete;
3712 virtual ~env_managed() noexcept;
3713};
3714
3724protected:
3725 friend class cursor;
3727 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3728
3729public:
3730 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3731 txn(const txn &) noexcept = default;
3732 inline txn &operator=(txn &&other) noexcept;
3733 inline txn(txn &&other) noexcept;
3734 inline ~txn() noexcept;
3735
3736 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3737 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3738 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3739 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3740 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3741
3743 inline ::mdbx::env env() const noexcept;
3745 inline MDBX_txn_flags_t flags() const;
3747 inline uint64_t id() const;
3748
3750 inline void *get_context() const noexcept;
3751
3753 inline txn &set_context(void *your_context);
3754
3756 inline bool is_dirty(const void *ptr) const;
3757
3759 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3760
3762 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3763
3766 inline info get_info(bool scan_reader_lock_table = false) const;
3767
3770 size_t size_max() const { return env().transaction_size_max(); }
3771
3773 size_t size_current() const {
3774 assert(is_readwrite());
3775 return size_t(get_info().txn_space_dirty);
3776 }
3777
3778 //----------------------------------------------------------------------------
3779
3781 inline void reset_reading();
3782
3784 inline void renew_reading();
3785
3787 inline void make_broken();
3788
3790 inline void park_reading(bool autounpark = true);
3791
3794 inline bool unpark_reading(bool restart_if_ousted = true);
3795
3798
3800 inline cursor_managed open_cursor(map_handle map) const;
3801
3803 inline size_t release_all_cursors(bool unbind) const;
3804
3806 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3807
3809 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3810
3812 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3813 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3815 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3816 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3818 inline map_handle open_map(const ::mdbx::slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3819 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3820
3822 inline map_handle open_map_accede(const char *name) const;
3824 inline map_handle open_map_accede(const ::std::string &name) const;
3826 inline map_handle open_map_accede(const ::mdbx::slice &name) const;
3827
3829 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3830 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3832 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3833 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3835 inline map_handle create_map(const ::mdbx::slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3836 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3837
3839 inline void drop_map(map_handle map);
3843 bool drop_map(const char *name, bool throw_if_absent = false);
3847 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3851 bool drop_map(const ::mdbx::slice &name, bool throw_if_absent = false);
3852
3854 inline void clear_map(map_handle map);
3857 bool clear_map(const char *name, bool throw_if_absent = false);
3860 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3863 bool clear_map(const ::mdbx::slice &name, bool throw_if_absent = false);
3864
3866 inline void rename_map(map_handle map, const char *new_name);
3868 inline void rename_map(map_handle map, const ::std::string &new_name);
3870 inline void rename_map(map_handle map, const ::mdbx::slice &new_name);
3874 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3878 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3882 bool rename_map(const ::mdbx::slice &old_name, const ::mdbx::slice &new_name, bool throw_if_absent = false);
3883
3884#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3885
3887 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3888 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3889 return open_map(::mdbx::slice(name), key_mode, value_mode);
3890 }
3891
3892 inline map_handle open_map_accede(const ::std::string_view &name) const;
3894 inline map_handle create_map(const ::std::string_view &name,
3895 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3896 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3898 }
3899
3902 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3903 return drop_map(::mdbx::slice(name), throw_if_absent);
3904 }
3905
3907 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3908 return clear_map(::mdbx::slice(name), throw_if_absent);
3909 }
3910
3911 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3915 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3916 bool throw_if_absent = false) {
3917 return rename_map(::mdbx::slice(old_name), ::mdbx::slice(new_name), throw_if_absent);
3918 }
3919#endif /* __cpp_lib_string_view >= 201606L */
3920
3923 inline map_stat get_map_stat(map_handle map) const;
3926 inline uint32_t get_tree_deepmask(map_handle map) const;
3929
3932 inline txn &put_canary(const canary &);
3934 inline canary get_canary() const;
3935
3937 inline uint64_t sequence(map_handle map) const;
3939 inline uint64_t sequence(map_handle map, uint64_t increment);
3940
3942 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3944 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3946 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3948 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3949
3951 inline slice get(map_handle map, const slice &key) const;
3953 inline slice get(map_handle map, slice key, size_t &values_count) const;
3955 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3957 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3961 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3965 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3966
3967 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3968 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3969 inline void insert(map_handle map, const slice &key, slice value);
3970 inline value_result try_insert(map_handle map, const slice &key, slice value);
3971 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3972 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3973
3974 inline void upsert(map_handle map, const slice &key, const slice &value);
3975 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3976
3977 inline void update(map_handle map, const slice &key, const slice &value);
3978 inline bool try_update(map_handle map, const slice &key, const slice &value);
3979 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3980 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3981
3982 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3983 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3984 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3985 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3986
3988 inline bool erase(map_handle map, const slice &key);
3989
3991 inline bool erase(map_handle map, const slice &key, const slice &value);
3992
3994 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3995
3997 template <class ALLOCATOR, typename CAPACITY_POLICY>
3999 extract(map_handle map, const slice &key,
4000 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator =
4002
4004 template <class ALLOCATOR, typename CAPACITY_POLICY>
4006 replace(map_handle map, const slice &key, const slice &new_value,
4007 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator =
4009
4010 template <class ALLOCATOR, typename CAPACITY_POLICY>
4012 replace_reserve(map_handle map, const slice &key, slice &new_value,
4013 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator =
4015
4032 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4033 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4034 return append(map, kv.key, kv.value, multivalue_order_preserved);
4035 }
4036
4037 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4038 const void *values_array, size_t values_count, put_mode mode,
4039 bool allow_partial = false);
4040 template <typename VALUE>
4041 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4042 put_mode mode, bool allow_partial = false) {
4043 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4044 !::std::is_array<VALUE>::value,
4045 "Must be a standard layout type!");
4046 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4047 }
4048 template <typename VALUE>
4049 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4050 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4051 }
4052
4053 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4054 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4055 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4056 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4057};
4058
4067class LIBMDBX_API_TYPE txn_managed : public txn {
4068 using inherited = txn;
4069 friend class env;
4070 friend class txn;
4072 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4073
4074public:
4075 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4076 txn_managed(txn_managed &&) = default;
4077 txn_managed &operator=(txn_managed &&other) noexcept {
4079 MDBX_CXX20_UNLIKELY {
4080 assert(handle_ != other.handle_);
4081 abort();
4082 }
4083 inherited::operator=(std::move(other));
4084 return *this;
4085 }
4086 txn_managed(const txn_managed &) = delete;
4087 txn_managed &operator=(const txn_managed &) = delete;
4088 ~txn_managed() noexcept;
4089
4090 //----------------------------------------------------------------------------
4091
4094 void abort();
4095
4097 void commit();
4098
4102
4104
4108
4111 void commit(commit_latency &latency) { return commit(&latency); }
4112
4117 commit_latency result;
4118 commit(&result);
4119 return result;
4120 }
4121};
4122
4131protected:
4133
4134public:
4136 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4137 cursor(const cursor &) noexcept = default;
4138 inline cursor &operator=(cursor &&other) noexcept;
4139 inline cursor(cursor &&other) noexcept;
4140 inline ~cursor() noexcept;
4141 inline cursor_managed clone(void *your_context = nullptr) const;
4142 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4143 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4144 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4145 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4146 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4147
4148 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4149 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4150
4151 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4152 return compare_position(*this, other, ignore_nested) < 0;
4153 }
4154
4155 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4156 return compare_position(*this, other, ignore_nested) <= 0;
4157 }
4158
4159 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4160 return compare_position(*this, other, ignore_nested) == 0;
4161 }
4162
4163 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4164 return compare_position(*this, other, ignore_nested) > 0;
4165 }
4166
4167 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4168 return compare_position(*this, other, ignore_nested) >= 0;
4169 }
4170
4172 inline void *get_context() const noexcept;
4173
4175 inline cursor &set_context(void *your_context);
4176
4183
4190
4193
4197
4198 /* Doubtless cursor positioning at a specified key. */
4204
4205 /* Doubtless cursor positioning at a specified key-value pair
4206 * for dupsort/multi-value hives. */
4212
4219
4224 };
4225
4226 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4227 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4228 // и других параметров в bool-throw_notfound.
4229
4230 struct move_result : public pair_result {
4231 inline move_result(const cursor &cursor, bool throw_notfound);
4232 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4233 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4234 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4235 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4236 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4237 bool throw_notfound);
4238 move_result(const move_result &) noexcept = default;
4239 move_result &operator=(const move_result &) noexcept = default;
4240 };
4241
4242 struct estimate_result : public pair {
4247 : estimate_result(cursor, operation, key, slice::invalid()) {}
4248 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4249 estimate_result(const estimate_result &) noexcept = default;
4250 estimate_result &operator=(const estimate_result &) noexcept = default;
4251 };
4252
4253protected:
4254 /* fake const, i.e. for some move/get operations */
4255 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4256
4257 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4258
4259public:
4260 template <typename CALLABLE_PREDICATE>
4261 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4262 struct wrapper : public exception_thunk {
4263 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4264 auto thunk = static_cast<wrapper *>(context);
4265 assert(thunk->is_clean());
4266 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4267 try {
4268 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4269 } catch (... /* capture any exception to rethrow it over C code */) {
4270 thunk->capture();
4271 return MDBX_RESULT_TRUE;
4272 }
4273 }
4274 } thunk;
4276 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4277 thunk);
4278 }
4279
4280 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4281 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4282 }
4283
4284 template <typename CALLABLE_PREDICATE>
4285 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4286 move_operation turn = next) {
4287 struct wrapper : public exception_thunk {
4288 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4289 auto thunk = static_cast<wrapper *>(context);
4290 assert(thunk->is_clean());
4291 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4292 try {
4293 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4294 } catch (... /* capture any exception to rethrow it over C code */) {
4295 thunk->capture();
4296 return MDBX_RESULT_TRUE;
4297 }
4298 }
4299 } thunk;
4300 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4301 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4302 thunk);
4303 }
4304
4305 template <typename CALLABLE_PREDICATE>
4306 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4307 move_operation turn = next) {
4308 struct wrapper : public exception_thunk {
4309 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4310 auto thunk = static_cast<wrapper *>(context);
4311 assert(thunk->is_clean());
4312 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4313 try {
4314 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4315 } catch (... /* capture any exception to rethrow it over C code */) {
4316 thunk->capture();
4317 return MDBX_RESULT_TRUE;
4318 }
4319 }
4320 } thunk;
4321 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4322 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4323 thunk);
4324 }
4325
4326 move_result move(move_operation operation, bool throw_notfound) {
4327 return move_result(*this, operation, throw_notfound);
4328 }
4329 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4330 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4331 }
4332 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4333 return move_result(*this, operation, key, value, throw_notfound);
4334 }
4335 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4336 return move(operation, &key, &value, throw_notfound);
4337 }
4338
4339 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4340 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4341 move_result to_previous_last_multi(bool throw_notfound = true) {
4342 return move(multi_prevkey_lastvalue, throw_notfound);
4343 }
4344 move_result to_current_first_multi(bool throw_notfound = true) {
4345 return move(multi_currentkey_firstvalue, throw_notfound);
4346 }
4347 move_result to_current_prev_multi(bool throw_notfound = true) {
4348 return move(multi_currentkey_prevvalue, throw_notfound);
4349 }
4350 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4351 move_result to_current_next_multi(bool throw_notfound = true) {
4352 return move(multi_currentkey_nextvalue, throw_notfound);
4353 }
4354 move_result to_current_last_multi(bool throw_notfound = true) {
4355 return move(multi_currentkey_lastvalue, throw_notfound);
4356 }
4357 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4358 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4359 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4360
4361 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4362 return move(key_lesser_than, key, throw_notfound);
4363 }
4364 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4365 return move(key_lesser_or_equal, key, throw_notfound);
4366 }
4367 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4368 return move(key_equal, key, throw_notfound);
4369 }
4370 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4371 return move(key_exact, key, throw_notfound);
4372 }
4373 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4374 return move(key_greater_or_equal, key, throw_notfound);
4375 }
4376 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4377 return move(key_greater_than, key, throw_notfound);
4378 }
4379
4380 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4381 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4382 }
4383 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4384 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4385 }
4386 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4387 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4388 }
4389 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4390 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4391 }
4392 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4393 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4394 }
4395
4396 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4397 return move(pair_lesser_than, key, value, throw_notfound);
4398 }
4399 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4400 return move(pair_lesser_or_equal, key, value, throw_notfound);
4401 }
4402 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4403 return move(pair_equal, key, value, throw_notfound);
4404 }
4405 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4406 return move(pair_exact, key, value, throw_notfound);
4407 }
4408 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4409 return move(pair_greater_or_equal, key, value, throw_notfound);
4410 }
4411 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4412 return move(pair_greater_than, key, value, throw_notfound);
4413 }
4414
4415 inline bool seek(const slice &key);
4416 inline move_result find(const slice &key, bool throw_notfound = true);
4417 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4418 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4419
4421 inline size_t count_multivalue() const;
4422
4423 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4424 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4425 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4426
4427 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4428 return move(seek_and_batch_samelength, key, throw_notfound);
4429 }
4430
4431 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4432 return move(batch_samelength, throw_notfound);
4433 }
4434
4435 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4436 return move(batch_samelength_next, throw_notfound);
4437 }
4438
4439 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4440 return move(batch_samelength_previous, throw_notfound);
4441 }
4442
4443 inline bool eof() const;
4444 inline bool on_first() const;
4445 inline bool on_last() const;
4446 inline bool on_first_multival() const;
4447 inline bool on_last_multival() const;
4448 inline estimate_result estimate(const slice &key, const slice &value) const;
4449 inline estimate_result estimate(const slice &key) const;
4450 inline estimate_result estimate(move_operation operation) const;
4451 inline estimate_result estimate(move_operation operation, slice &key) const;
4452
4453 //----------------------------------------------------------------------------
4454
4456 inline void renew(::mdbx::txn &txn);
4457
4460
4462 inline void unbind();
4463
4465 inline ::mdbx::txn txn() const;
4466 inline map_handle map() const;
4467
4468 inline operator ::mdbx::txn() const { return txn(); }
4469 inline operator ::mdbx::map_handle() const { return map(); }
4470
4471 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4472 inline void put(const slice &key, slice value, put_mode mode);
4473 inline void insert(const slice &key, slice value);
4474 inline value_result try_insert(const slice &key, slice value);
4475 inline slice insert_reserve(const slice &key, size_t value_length);
4476 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4477
4478 inline void upsert(const slice &key, const slice &value);
4479 inline slice upsert_reserve(const slice &key, size_t value_length);
4480
4481 inline void update(const slice &key, const slice &value);
4482 inline bool try_update(const slice &key, const slice &value);
4483 inline slice update_reserve(const slice &key, size_t value_length);
4484 inline value_result try_update_reserve(const slice &key, size_t value_length);
4485
4486 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4487 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4488 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4489 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4490
4492 inline bool erase(bool whole_multivalue = false);
4493
4496 inline bool erase(const slice &key, bool whole_multivalue = true);
4497
4500 inline bool erase(const slice &key, const slice &value);
4501
4502 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4503 size_t values_count, put_mode mode, bool allow_partial = false);
4504 template <typename VALUE>
4505 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4506 bool allow_partial = false) {
4507 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4508 !::std::is_array<VALUE>::value,
4509 "Must be a standard layout type!");
4510 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4511 }
4512 template <typename VALUE>
4513 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4514 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4515 }
4516};
4517
4525class LIBMDBX_API_TYPE cursor_managed : public cursor {
4526 using inherited = cursor;
4527 friend class txn;
4529 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4530
4531public:
4533 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4534 if (MDBX_UNLIKELY(!handle_))
4535 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4536 }
4537
4539 inline void close() {
4541 handle_ = nullptr;
4542 }
4543
4544 cursor_managed(cursor_managed &&) = default;
4545 cursor_managed &operator=(cursor_managed &&other) noexcept {
4547 MDBX_CXX20_UNLIKELY {
4548 assert(handle_ != other.handle_);
4549 close();
4550 }
4551 inherited::operator=(std::move(other));
4552 return *this;
4553 }
4554
4555 inline MDBX_cursor *withdraw_handle() noexcept {
4556 MDBX_cursor *handle = handle_;
4557 handle_ = nullptr;
4558 return handle;
4559 }
4560
4561 cursor_managed(const cursor_managed &) = delete;
4562 cursor_managed &operator=(const cursor_managed &) = delete;
4564};
4565
4566//------------------------------------------------------------------------------
4567
4568LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
4569LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
4570LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
4571template <class ALLOCATOR, typename CAPACITY_POLICY>
4572inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
4573 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
4574}
4575LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
4576LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
4577LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
4578LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
4579LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
4580LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
4581LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
4582LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
4583
4584LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
4585LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
4586LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
4587inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
4588
4589//==============================================================================
4590//
4591// Inline body of the libmdbx C++ API
4592//
4593
4594MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4595MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4596
4597static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4598#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4599 if (::std::is_constant_evaluated()) {
4600 for (size_t i = 0; c_str; ++i)
4601 if (!c_str[i])
4602 return i;
4603 return 0;
4604 }
4605#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4606#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4607 return c_str ? ::std::string_view(c_str).length() : 0;
4608#else
4609 return c_str ? ::std::strlen(c_str) : 0;
4610#endif
4611}
4612
4613MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4614#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4615 if (::std::is_constant_evaluated()) {
4616 for (size_t i = 0; i < bytes; ++i)
4617 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4618 return dest;
4619 } else
4620#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4621 return ::std::memcpy(dest, src, bytes);
4622}
4623
4624static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4625#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4626 if (::std::is_constant_evaluated()) {
4627 for (size_t i = 0; i < bytes; ++i) {
4628 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4629 if (diff)
4630 return diff;
4631 }
4632 return 0;
4633 } else
4634#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4635 return ::std::memcmp(a, b, bytes);
4636}
4637
4638static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
4639 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
4640 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4641 return bytes;
4642}
4643
4644static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
4645 return check_length(check_length(headroom) + check_length(payload));
4646}
4647
4648MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
4649 return check_length(check_length(headroom, payload) + check_length(tailroom));
4650}
4651
4652inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4653
4654inline void exception_thunk::capture() noexcept {
4655 assert(is_clean());
4656 captured_ = ::std::current_exception();
4657}
4658
4660 if (captured_)
4661 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4662}
4663
4664//------------------------------------------------------------------------------
4665
4666MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4667
4668inline error &error::operator=(MDBX_error_t error_code) noexcept {
4669 code_ = error_code;
4670 return *this;
4671}
4672
4673MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4674
4675MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4676
4677MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4678
4679MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4680
4681MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4682
4684 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4685}
4686
4687MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4688
4693
4694inline void error::throw_exception(int error_code) {
4695 const error trouble(static_cast<MDBX_error_t>(error_code));
4696 trouble.throw_exception();
4697}
4698
4699inline void error::throw_on_failure() const {
4701 MDBX_CXX20_UNLIKELY throw_exception();
4702}
4703
4704inline void error::success_or_throw() const {
4705 if (MDBX_UNLIKELY(!is_success()))
4706 MDBX_CXX20_UNLIKELY throw_exception();
4707}
4708
4709inline void error::success_or_throw(const exception_thunk &thunk) const {
4710 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4711 if (MDBX_UNLIKELY(!is_success())) {
4712 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4713 else throw_exception();
4714 }
4715}
4716
4717inline void error::panic_on_failure(const char *context_where, const char *func_who) const noexcept {
4719 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4720}
4721
4722inline void error::success_or_panic(const char *context_where, const char *func_who) const noexcept {
4723 if (MDBX_UNLIKELY(!is_success()))
4724 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4725}
4726
4727inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4728 if (MDBX_UNLIKELY(ptr == nullptr))
4729 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4730}
4731
4732inline void error::throw_on_failure(int error_code) {
4733 error rc(static_cast<MDBX_error_t>(error_code));
4734 rc.throw_on_failure();
4735}
4736
4737inline void error::success_or_throw(MDBX_error_t error_code) {
4738 error rc(error_code);
4739 rc.success_or_throw();
4740}
4741
4742inline bool error::boolean_or_throw(int error_code) {
4743 switch (error_code) {
4744 case MDBX_RESULT_FALSE:
4745 return false;
4746 case MDBX_RESULT_TRUE:
4747 return true;
4748 default:
4749 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4750 }
4751}
4752
4753inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4754 error rc(static_cast<MDBX_error_t>(error_code));
4755 rc.success_or_throw(thunk);
4756}
4757
4758inline void error::panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept {
4759 error rc(static_cast<MDBX_error_t>(error_code));
4760 rc.panic_on_failure(context_where, func_who);
4761}
4762
4763inline void error::success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept {
4764 error rc(static_cast<MDBX_error_t>(error_code));
4765 rc.success_or_panic(context_where, func_who);
4766}
4767
4768inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4769 if (MDBX_UNLIKELY(!thunk.is_clean()))
4770 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4771 return boolean_or_throw(error_code);
4772}
4773
4774//------------------------------------------------------------------------------
4775
4776MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4777
4779 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4780
4781MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4782 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4783
4784MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, ::mdbx::strlen(c_str)) {}
4785
4786MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4787
4788MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4789
4790MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4791
4792inline slice &slice::assign(const void *ptr, size_t bytes) {
4793 iov_base = const_cast<void *>(ptr);
4794 iov_len = check_length(bytes);
4795 return *this;
4796}
4797
4798inline slice &slice::assign(const slice &src) noexcept {
4799 iov_base = src.iov_base;
4800 iov_len = src.iov_len;
4801 return *this;
4802}
4803
4804inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4805
4806slice &slice::assign(slice &&src) noexcept {
4807 assign(src);
4808 src.invalidate();
4809 return *this;
4810}
4811
4813 assign(src.iov_base, src.iov_len);
4814 src.iov_base = nullptr;
4815 return *this;
4816}
4817
4818inline slice &slice::assign(const void *begin, const void *end) {
4819 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4820}
4821
4822inline slice &slice::assign(const char *c_str) { return assign(c_str, ::mdbx::strlen(c_str)); }
4823
4824inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4825
4826inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4827
4828inline void slice::swap(slice &other) noexcept {
4829 const auto temp = *this;
4830 *this = other;
4831 other = temp;
4832}
4833
4834MDBX_CXX11_CONSTEXPR const ::mdbx::byte *slice::byte_ptr() const noexcept {
4835 return static_cast<const byte *>(iov_base);
4836}
4837
4838MDBX_CXX11_CONSTEXPR const ::mdbx::byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4839
4840MDBX_CXX11_CONSTEXPR ::mdbx::byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4841
4842MDBX_CXX11_CONSTEXPR ::mdbx::byte *slice::end_byte_ptr() noexcept { return byte_ptr() + length(); }
4843
4844MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4845
4846MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4847
4848MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4849
4851
4852MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4853
4854MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4855
4856MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4857
4858MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4859
4860MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4861
4863 iov_len = check_length(bytes);
4864 return *this;
4865}
4866
4868 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4869 return set_length(static_cast<const char *>(ptr) - char_ptr());
4870}
4871
4872MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4873
4874MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4875
4876MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4877
4878MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4879
4880MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4881
4883 iov_base = nullptr;
4884 iov_len = 0;
4885}
4886
4887inline void slice::remove_prefix(size_t n) noexcept {
4888 assert(n <= size());
4889 iov_base = static_cast<byte *>(iov_base) + n;
4890 iov_len -= n;
4891}
4892
4893inline void slice::safe_remove_prefix(size_t n) {
4894 if (MDBX_UNLIKELY(n > size()))
4895 MDBX_CXX20_UNLIKELY throw_out_range();
4896 remove_prefix(n);
4897}
4898
4899inline void slice::remove_suffix(size_t n) noexcept {
4900 assert(n <= size());
4901 iov_len -= n;
4902}
4903
4904inline void slice::safe_remove_suffix(size_t n) {
4905 if (MDBX_UNLIKELY(n > size()))
4906 MDBX_CXX20_UNLIKELY throw_out_range();
4907 remove_suffix(n);
4908}
4909
4910MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4911 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4912}
4913
4914MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4915 return length() >= suffix.length() &&
4916 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4917}
4918
4920 size_t h = length() * 3977471;
4921 for (size_t i = 0; i < length(); ++i)
4922 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4923 return h ^ 3863194411 * (h >> 11);
4924}
4925
4926MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4928 return byte_ptr()[n];
4929}
4930
4931MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4932 if (MDBX_UNLIKELY(n >= size()))
4933 MDBX_CXX20_UNLIKELY throw_out_range();
4934 return byte_ptr()[n];
4935}
4936
4937MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4939 return slice(data(), n);
4940}
4941
4942MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4944 return slice(char_ptr() + size() - n, n);
4945}
4946
4947MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4948 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4949 return slice(char_ptr() + from, n);
4950}
4951
4953 if (MDBX_UNLIKELY(n > size()))
4954 MDBX_CXX20_UNLIKELY throw_out_range();
4955 return head(n);
4956}
4957
4959 if (MDBX_UNLIKELY(n > size()))
4960 MDBX_CXX20_UNLIKELY throw_out_range();
4961 return tail(n);
4962}
4963
4964MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4965 if (MDBX_UNLIKELY(n > max_length))
4966 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4967 if (MDBX_UNLIKELY(from + n > size()))
4968 MDBX_CXX20_UNLIKELY throw_out_range();
4969 return middle(from, n);
4970}
4971
4972MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4973 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4974 return diff ? diff
4975 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4976 : memcmp(a.data(), b.data(), a.length());
4977}
4978
4980 const size_t shortest = ::std::min(a.length(), b.length());
4981 if (MDBX_LIKELY(shortest > 0))
4983 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4984 if (MDBX_LIKELY(diff != 0))
4985 MDBX_CXX20_LIKELY return diff;
4986 }
4987 return intptr_t(a.length()) - intptr_t(b.length());
4988}
4989
4991 return slice::compare_fast(a, b) == 0;
4992}
4993
4995 return slice::compare_lexicographically(a, b) < 0;
4996}
4997
4999 return slice::compare_lexicographically(a, b) > 0;
5000}
5001
5003 return slice::compare_lexicographically(a, b) <= 0;
5004}
5005
5007 return slice::compare_lexicographically(a, b) >= 0;
5008}
5009
5011 return slice::compare_fast(a, b) != 0;
5012}
5013
5014template <class ALLOCATOR>
5015inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &allocator) const {
5016 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(allocator);
5017}
5018
5019template <class ALLOCATOR>
5020inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &allocator) const {
5021 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(allocator);
5022}
5023
5024template <class ALLOCATOR>
5025inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &allocator) const {
5026 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(allocator);
5027}
5028
5029template <class ALLOCATOR, class CAPACITY_POLICY>
5030inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5031 const ALLOCATOR &allocator) const {
5032 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5033}
5034
5035template <class ALLOCATOR, class CAPACITY_POLICY>
5036inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &allocator) const {
5037 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5038}
5039
5040template <class ALLOCATOR, class CAPACITY_POLICY>
5041inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &allocator) const {
5042 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5043}
5044
5045template <class ALLOCATOR, class CAPACITY_POLICY>
5046inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5047 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5048}
5049
5050template <class ALLOCATOR, class CAPACITY_POLICY>
5051inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5052 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5053}
5054
5055template <class ALLOCATOR, class CAPACITY_POLICY>
5056inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5057 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5058}
5059
5060MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5061 return !from_hex(*this, ignore_spaces).is_erroneous();
5062}
5063
5064MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5065 return !from_base58(*this, ignore_spaces).is_erroneous();
5066}
5067
5068MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5069 return !from_base64(*this, ignore_spaces).is_erroneous();
5070}
5071
5072//------------------------------------------------------------------------------
5073
5074MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5075 const auto diff = slice::compare_fast(a.key, b.key);
5076 return diff ? diff : slice::compare_fast(a.value, b.value);
5077}
5078
5079MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5080 const auto diff = slice::compare_lexicographically(a.key, b.key);
5081 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5082}
5083
5085 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5086 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5087 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5088}
5089
5091 return pair::compare_lexicographically(a, b) < 0;
5092}
5093
5095 return pair::compare_lexicographically(a, b) > 0;
5096}
5097
5099 return pair::compare_lexicographically(a, b) <= 0;
5100}
5101
5103 return pair::compare_lexicographically(a, b) >= 0;
5104}
5105
5107 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5108 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5109 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5110}
5111
5112//------------------------------------------------------------------------------
5113
5114template <class ALLOCATOR, typename CAPACITY_POLICY>
5116 const allocator_type &allocator)
5117 : buffer(src, !txn.is_dirty(src.data()), allocator) {}
5118
5119//------------------------------------------------------------------------------
5120
5123
5127
5131
5132//------------------------------------------------------------------------------
5133
5135
5136inline env &env::operator=(env &&other) noexcept {
5137 handle_ = other.handle_;
5138 other.handle_ = nullptr;
5139 return *this;
5140}
5141
5142inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5143
5144inline env::~env() noexcept {
5145#ifndef NDEBUG
5146 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5147#endif
5148}
5149
5150MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5151
5152MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5153
5154MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5155
5156MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5157
5158MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5159
5163 return *this;
5164}
5165
5166inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5167 size_now = size_lower = lower;
5168 size_upper = upper;
5170 return *this;
5171}
5172
5176
5180
5181inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5182
5183inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5184
5185inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5186 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5187 if (result < 0)
5188 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5189 return static_cast<size_t>(result);
5190}
5191
5192inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5193 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5194 if (result < 0)
5195 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5196 return static_cast<size_t>(result);
5197}
5198
5199inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5200
5201inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5202
5203inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5204 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5205 if (result < 0)
5206 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5207 return static_cast<size_t>(result);
5208}
5209
5210inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5211 return key_max(pagesize, MDBX_db_flags_t(mode));
5212}
5213
5215 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5216 if (result < 0)
5217 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5218 return static_cast<size_t>(result);
5219}
5220
5222
5223inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5224
5226
5227inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5228 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5229 if (result < 0)
5230 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5231 return static_cast<size_t>(result);
5232}
5233
5234inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5235 return value_max(pagesize, MDBX_db_flags_t(mode));
5236}
5237
5239 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5240 if (result < 0)
5241 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5242 return static_cast<size_t>(result);
5243}
5244
5246
5247inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5248 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5249 if (result < 0)
5250 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5251 return static_cast<size_t>(result);
5252}
5253
5254inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5255 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5256}
5257
5259 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5260 if (result < 0)
5261 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5262 return static_cast<size_t>(result);
5263}
5264
5268
5269inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5270 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5271 if (result < 0)
5272 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5273 return static_cast<size_t>(result);
5274}
5275
5276inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5277 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5278}
5279
5281 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5282 if (result < 0)
5283 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5284 return static_cast<size_t>(result);
5285}
5286
5290
5291inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5292 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5293 if (result < 0)
5294 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5295 return static_cast<size_t>(result);
5296}
5297
5298inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5299
5307
5309
5313
5317
5321
5322inline env::stat env::get_stat() const {
5323 env::stat r;
5324 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5325 return r;
5326}
5327
5328inline env::stat env::get_stat(const txn &txn) const {
5329 env::stat r;
5331 return r;
5332}
5333
5334inline env::info env::get_info() const {
5335 env::info r;
5336 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5337 return r;
5338}
5339
5340inline env::info env::get_info(const txn &txn) const {
5341 env::info r;
5343 return r;
5344}
5345
5347 filehandle fd;
5349 return fd;
5350}
5351
5353 unsigned bits = 0;
5355 return MDBX_env_flags_t(bits);
5356}
5357
5358inline unsigned env::max_readers() const {
5359 unsigned r;
5361 return r;
5362}
5363
5364inline unsigned env::max_maps() const {
5365 unsigned r;
5367 return r;
5368}
5369
5370inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5371
5372inline env &env::set_context(void *ptr) {
5374 return *this;
5375}
5376
5377inline env &env::set_sync_threshold(size_t bytes) {
5379 return *this;
5380}
5381
5382inline size_t env::sync_threshold() const {
5383 size_t bytes;
5385 return bytes;
5386}
5387
5388inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5390 return *this;
5391}
5392
5393inline unsigned env::sync_period__seconds_16dot16() const {
5394 unsigned seconds_16dot16;
5396 return seconds_16dot16;
5397}
5398
5400 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5401}
5402
5403inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5404
5405#if __cplusplus >= 201103L
5406inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5407
5408inline duration env::sync_period() const { return duration(sync_period__seconds_16dot16()); }
5409#endif
5410
5411inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5413 return *this;
5414}
5415
5416inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5417 uint64_t value;
5419 return value;
5420}
5421
5424 return *this;
5425}
5426
5427inline env &env::set_geometry(const geometry &geo) {
5429 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5430 return *this;
5431}
5432
5433inline bool env::sync_to_disk(bool force, bool nonblock) {
5434 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5435 switch (err) {
5436 case MDBX_SUCCESS /* flush done */:
5437 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5438 return true;
5439 case MDBX_BUSY /* the environment is used by other thread */:
5440 return false;
5441 default:
5442 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5443 }
5444}
5445
5446inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5447
5449env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5450 size_t retained) noexcept
5452 bytes_retained(retained) {}
5453
5454template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5455 struct reader_visitor_thunk : public exception_thunk {
5456 VISITOR &visitor_;
5457 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5458 size_t used, size_t retained) noexcept {
5459 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5460 assert(thunk->is_clean());
5461 try {
5462 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5463 return loop_control(thunk->visitor_(info, number));
5464 } catch (... /* capture any exception to rethrow it over C code */) {
5465 thunk->capture();
5467 }
5468 }
5469 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5470 };
5471 reader_visitor_thunk thunk(visitor);
5472 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5473 thunk.rethrow_captured();
5474 return rc;
5475}
5476
5477inline unsigned env::check_readers() {
5478 int dead_count;
5479 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5480 assert(dead_count >= 0);
5481 return static_cast<unsigned>(dead_count);
5482}
5483
5488
5489inline MDBX_hsr_func *env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5490
5492 ::MDBX_txn *ptr;
5494 assert(ptr != nullptr);
5495 return txn_managed(ptr);
5496}
5497
5499 ::MDBX_txn *ptr;
5501 assert(ptr != nullptr);
5502 return txn_managed(ptr);
5503}
5504
5505inline txn_managed env::start_write(bool dont_wait) {
5506 ::MDBX_txn *ptr;
5508 assert(ptr != nullptr);
5509 return txn_managed(ptr);
5510}
5511
5513 ::MDBX_txn *ptr;
5515 assert(ptr != nullptr);
5516 return txn_managed(ptr);
5517}
5518
5520
5521//------------------------------------------------------------------------------
5522
5524
5525inline txn &txn::operator=(txn &&other) noexcept {
5526 handle_ = other.handle_;
5527 other.handle_ = nullptr;
5528 return *this;
5529}
5530
5531inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5532
5533inline txn::~txn() noexcept {
5534#ifndef NDEBUG
5535 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5536#endif
5537}
5538
5539MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5540
5541MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5542
5543MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5544
5545MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5546
5547MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5548
5549inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5550
5551inline txn &txn::set_context(void *ptr) {
5553 return *this;
5554}
5555
5556inline bool txn::is_dirty(const void *ptr) const {
5557 int err = ::mdbx_is_dirty(handle_, ptr);
5558 switch (err) {
5559 default:
5560 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5561 case MDBX_RESULT_TRUE:
5562 return true;
5563 case MDBX_RESULT_FALSE:
5564 return false;
5565 }
5566}
5567
5568inline ::mdbx::env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5569
5571 const int bits = mdbx_txn_flags(handle_);
5573 return static_cast<MDBX_txn_flags_t>(bits);
5574}
5575
5576inline uint64_t txn::id() const {
5577 const uint64_t txnid = mdbx_txn_id(handle_);
5579 return txnid;
5580}
5581
5583
5585
5587
5588inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5589
5590inline bool txn::unpark_reading(bool restart_if_ousted) {
5591 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5592}
5593
5594inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5595 txn::info r;
5596 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5597 return r;
5598}
5599
5601 MDBX_cursor *ptr;
5603 return cursor_managed(ptr);
5604}
5605
5606inline size_t txn::release_all_cursors(bool unbind) const {
5607 size_t count;
5609 return count;
5610}
5611
5612inline ::mdbx::map_handle txn::open_map(const ::mdbx::slice &name, const ::mdbx::key_mode key_mode,
5613 const ::mdbx::value_mode value_mode) const {
5617 assert(map.dbi != 0);
5618 return map;
5619}
5620
5621inline ::mdbx::map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5622 const ::mdbx::value_mode value_mode) const {
5626 assert(map.dbi != 0);
5627 return map;
5628}
5629
5630inline ::mdbx::map_handle txn::open_map_accede(const ::mdbx::slice &name) const {
5633 assert(map.dbi != 0);
5634 return map;
5635}
5636
5637inline ::mdbx::map_handle txn::open_map_accede(const char *name) const {
5640 assert(map.dbi != 0);
5641 return map;
5642}
5643
5644inline ::mdbx::map_handle txn::create_map(const ::mdbx::slice &name, const ::mdbx::key_mode key_mode,
5645 const ::mdbx::value_mode value_mode) {
5649 assert(map.dbi != 0);
5650 return map;
5651}
5652
5653inline ::mdbx::map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5654 const ::mdbx::value_mode value_mode) {
5658 assert(map.dbi != 0);
5659 return map;
5660}
5661
5663
5665
5666inline void txn::rename_map(map_handle map, const char *new_name) {
5668}
5669
5670inline void txn::rename_map(map_handle map, const ::mdbx::slice &new_name) {
5672}
5673
5674inline ::mdbx::map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5675 const ::mdbx::value_mode value_mode) const {
5676 return open_map(::mdbx::slice(name), key_mode, value_mode);
5677}
5678
5679inline ::mdbx::map_handle txn::open_map_accede(const ::std::string &name) const {
5680 return open_map_accede(::mdbx::slice(name));
5681}
5682
5683inline ::mdbx::map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5684 const ::mdbx::value_mode value_mode) {
5686}
5687
5688inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5689 return drop_map(::mdbx::slice(name), throw_if_absent);
5690}
5691
5692inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5693 return clear_map(::mdbx::slice(name), throw_if_absent);
5694}
5695
5696inline void txn::rename_map(map_handle map, const ::std::string &new_name) {
5697 return rename_map(map, ::mdbx::slice(new_name));
5698}
5699
5701 txn::map_stat r;
5702 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5703 return r;
5704}
5705
5706inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5707 uint32_t r;
5709 return r;
5710}
5711
5717
5722
5724 txn::canary r;
5726 return r;
5727}
5728
5729inline uint64_t txn::sequence(map_handle map) const {
5730 uint64_t result;
5732 return result;
5733}
5734
5735inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5736 uint64_t result;
5737 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5738 return result;
5739}
5740
5741inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5742 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5743}
5744
5745inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5746 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5747}
5748
5749inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5750 return compare_keys(map, a.key, b.key);
5751}
5752
5753inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5754 return compare_values(map, a.value, b.value);
5755}
5756
5757inline slice txn::get(map_handle map, const slice &key) const {
5758 slice result;
5759 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5760 return result;
5761}
5762
5763inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5764 slice result;
5765 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5766 return result;
5767}
5768
5769inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5770 slice result;
5771 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5772 switch (err) {
5773 case MDBX_SUCCESS:
5774 return result;
5775 case MDBX_NOTFOUND:
5776 return value_at_absence;
5777 default:
5778 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5779 }
5780}
5781
5782inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5783 slice result;
5784 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5785 switch (err) {
5786 case MDBX_SUCCESS:
5787 return result;
5788 case MDBX_NOTFOUND:
5789 return value_at_absence;
5790 default:
5791 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5792 }
5793}
5794
5796 pair result(key, slice());
5797 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5798 return pair_result(result.key, result.value, exact);
5799}
5800
5801inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5802 pair result{key, slice()};
5803 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5804 switch (err) {
5805 case MDBX_SUCCESS:
5806 return pair_result{result.key, result.value, true};
5807 case MDBX_RESULT_TRUE:
5808 return pair_result{result.key, result.value, false};
5809 case MDBX_NOTFOUND:
5810 return pair_result{key, value_at_absence, false};
5811 default:
5812 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5813 }
5814}
5815
5816inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5817 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5818}
5819
5820inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5821 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5822}
5823
5824inline void txn::insert(map_handle map, const slice &key, slice value) {
5825 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5827}
5828
5829inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5830 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5832 switch (err) {
5833 case MDBX_SUCCESS:
5834 return value_result{slice(), true};
5835 case MDBX_KEYEXIST:
5836 return value_result{value, false};
5837 default:
5838 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5839 }
5840}
5841
5842inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5843 slice result(nullptr, value_length);
5844 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5846 return result;
5847}
5848
5849inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5850 slice result(nullptr, value_length);
5851 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5853 switch (err) {
5854 case MDBX_SUCCESS:
5855 return value_result{result, true};
5856 case MDBX_KEYEXIST:
5857 return value_result{result, false};
5858 default:
5859 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5860 }
5861}
5862
5863inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5864 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5865}
5866
5867inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
5868 slice result(nullptr, value_length);
5870 return result;
5871}
5872
5873inline void txn::update(map_handle map, const slice &key, const slice &value) {
5874 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
5875}
5876
5877inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
5878 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
5879 switch (err) {
5880 case MDBX_SUCCESS:
5881 return true;
5882 case MDBX_NOTFOUND:
5883 return false;
5884 default:
5885 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5886 }
5887}
5888
5889inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
5890 slice result(nullptr, value_length);
5892 return result;
5893}
5894
5895inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
5896 slice result(nullptr, value_length);
5897 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
5898 switch (err) {
5899 case MDBX_SUCCESS:
5900 return value_result{result, true};
5901 case MDBX_NOTFOUND:
5902 return value_result{slice(), false};
5903 default:
5904 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5905 }
5906}
5907
5908inline bool txn::erase(map_handle map, const slice &key) {
5909 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
5910 switch (err) {
5911 case MDBX_SUCCESS:
5912 return true;
5913 case MDBX_NOTFOUND:
5914 return false;
5915 default:
5916 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5917 }
5918}
5919
5920inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
5921 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
5922 switch (err) {
5923 case MDBX_SUCCESS:
5924 return true;
5925 case MDBX_NOTFOUND:
5926 return false;
5927 default:
5928 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5929 }
5930}
5931
5932inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
5933 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
5934 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
5935}
5936
5937template <class ALLOCATOR, typename CAPACITY_POLICY>
5940 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator) {
5941 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
5943 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
5944 return result;
5945}
5946
5947template <class ALLOCATOR, typename CAPACITY_POLICY>
5949txn::replace(map_handle map, const slice &key, const slice &new_value,
5950 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator) {
5951 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
5952 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
5953 MDBX_CURRENT, result, &result),
5954 result);
5955 return result;
5956}
5957
5958template <class ALLOCATOR, typename CAPACITY_POLICY>
5960txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
5961 const typename buffer<ALLOCATOR, CAPACITY_POLICY>::allocator_type &allocator) {
5962 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
5963 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
5964 MDBX_CURRENT | MDBX_RESERVE, result, &result),
5965 result);
5966 return result;
5967}
5968
5969inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
5970 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
5971 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
5972}
5973
5974inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
5975 const void *values_array, size_t values_count, put_mode mode,
5976 bool allow_partial) {
5977 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
5978 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
5979 switch (err) {
5980 case MDBX_SUCCESS:
5981 MDBX_CXX20_LIKELY break;
5982 case MDBX_KEYEXIST:
5983 if (allow_partial)
5984 break;
5986 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
5987 default:
5988 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5989 }
5990 return args[1].iov_len /* done item count */;
5991}
5992
5993inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
5994 ptrdiff_t result;
5995 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
5996 return result;
5997}
5998
5999inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6000 ptrdiff_t result;
6001 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6002 return result;
6003}
6004
6005inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6006 ptrdiff_t result;
6007 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6008 return result;
6009}
6010
6011inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6012 ptrdiff_t result;
6013 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6014 return result;
6015}
6016
6017//------------------------------------------------------------------------------
6018
6020
6021inline cursor_managed cursor::clone(void *your_context) const {
6022 cursor_managed clone(your_context);
6024 return clone;
6025}
6026
6027inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6028
6029inline cursor &cursor::set_context(void *ptr) {
6031 return *this;
6032}
6033
6034inline cursor &cursor::operator=(cursor &&other) noexcept {
6035 handle_ = other.handle_;
6036 other.handle_ = nullptr;
6037 return *this;
6038}
6039
6040inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6041
6042inline cursor::~cursor() noexcept {
6043#ifndef NDEBUG
6044 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6045#endif
6046}
6047
6048MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
6049
6050MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
6051
6052MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6053
6054MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6055
6056MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6057
6058inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6059 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6060}
6061
6062inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6063 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6064 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6065 if (MDBX_LIKELY(int16_t(diff) == diff))
6066 MDBX_CXX20_LIKELY return int(diff);
6067 else
6069}
6070
6071inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6072 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6073}
6074
6076 bool throw_notfound)
6077 : pair_result(key, value, false) {
6078 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6079}
6080
6081inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6082 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6083 switch (err) {
6084 case MDBX_SUCCESS:
6085 MDBX_CXX20_LIKELY return true;
6086 case MDBX_RESULT_TRUE:
6087 return false;
6088 case MDBX_NOTFOUND:
6089 if (!throw_notfound)
6090 return false;
6091 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6092 default:
6093 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6094 }
6095}
6096
6098 const slice &value)
6099 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6100 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6101}
6102
6103inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6104 ptrdiff_t result;
6105 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6106 return result;
6107}
6108
6109inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6110 ptrdiff_t result;
6112 return result;
6113}
6114
6115inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6116 return move(key_exact, key, throw_notfound);
6117}
6118
6119inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6120 return move(key_lowerbound, key, throw_notfound);
6121}
6122
6123inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6124 return move(key_greater_than, key, throw_notfound);
6125}
6126
6127inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6128 return move(multi_find_pair, key, value, throw_notfound);
6129}
6130
6131inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6132 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6133}
6134
6135inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6136 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6137}
6138
6139inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6140
6141inline size_t cursor::count_multivalue() const {
6142 size_t result;
6144 return result;
6145}
6146
6147inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6148
6150
6152
6154
6156
6157inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6158 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6159}
6160
6162 return estimate_result(*this, key_lowerbound, key);
6163}
6164
6166 return estimate_result(*this, operation);
6167}
6168
6170
6174
6176
6177inline txn cursor::txn() const {
6179 return ::mdbx::txn(txn);
6180}
6181
6182inline map_handle cursor::map() const {
6183 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6184 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6186 return map_handle(dbi);
6187}
6188
6189inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6190 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6191}
6192
6193inline void cursor::put(const slice &key, slice value, put_mode mode) {
6194 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6195}
6196
6197inline void cursor::insert(const slice &key, slice value) {
6199 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6200}
6201
6202inline value_result cursor::try_insert(const slice &key, slice value) {
6203 const int err =
6204 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6205 switch (err) {
6206 case MDBX_SUCCESS:
6207 return value_result{slice(), true};
6208 case MDBX_KEYEXIST:
6209 return value_result{value, false};
6210 default:
6211 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6212 }
6213}
6214
6215inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6216 slice result(nullptr, value_length);
6217 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6219 return result;
6220}
6221
6222inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6223 slice result(nullptr, value_length);
6224 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6226 switch (err) {
6227 case MDBX_SUCCESS:
6228 return value_result{result, true};
6229 case MDBX_KEYEXIST:
6230 return value_result{result, false};
6231 default:
6232 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6233 }
6234}
6235
6236inline void cursor::upsert(const slice &key, const slice &value) {
6237 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6238}
6239
6240inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6241 slice result(nullptr, value_length);
6243 return result;
6244}
6245
6246inline void cursor::update(const slice &key, const slice &value) {
6247 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6248}
6249
6250inline bool cursor::try_update(const slice &key, const slice &value) {
6251 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6252 switch (err) {
6253 case MDBX_SUCCESS:
6254 return true;
6255 case MDBX_NOTFOUND:
6256 return false;
6257 default:
6258 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6259 }
6260}
6261
6262inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6263 slice result(nullptr, value_length);
6265 return result;
6266}
6267
6268inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6269 slice result(nullptr, value_length);
6270 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6271 switch (err) {
6272 case MDBX_SUCCESS:
6273 return value_result{result, true};
6274 case MDBX_NOTFOUND:
6275 return value_result{slice(), false};
6276 default:
6277 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6278 }
6279}
6280
6281inline bool cursor::erase(bool whole_multivalue) {
6282 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6283 switch (err) {
6284 case MDBX_SUCCESS:
6285 MDBX_CXX20_LIKELY return true;
6286 case MDBX_NOTFOUND:
6287 return false;
6288 default:
6289 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6290 }
6291}
6292
6293inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6294 bool found = seek(key);
6295 return found ? erase(whole_multivalue) : found;
6296}
6297
6298inline bool cursor::erase(const slice &key, const slice &value) {
6299 move_result data = find_multivalue(key, value, false);
6300 return data.done && erase();
6301}
6302
6303inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6304 size_t values_count, put_mode mode, bool allow_partial) {
6305 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6306 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6307 switch (err) {
6308 case MDBX_SUCCESS:
6309 MDBX_CXX20_LIKELY break;
6310 case MDBX_KEYEXIST:
6311 if (allow_partial)
6312 break;
6314 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6315 default:
6316 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6317 }
6318 return args[1].iov_len /* done item count */;
6319}
6320
6322} // namespace mdbx
6323
6324//------------------------------------------------------------------------------
6325
6328namespace std {
6329
6332
6333inline string to_string(const ::mdbx::slice &value) {
6334 ostringstream out;
6335 out << value;
6336 return out.str();
6337}
6338
6339template <class ALLOCATOR, typename CAPACITY_POLICY>
6340inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6341 ostringstream out;
6342 out << buffer;
6343 return out.str();
6344}
6345
6346inline string to_string(const ::mdbx::pair &value) {
6347 ostringstream out;
6348 out << value;
6349 return out.str();
6350}
6351
6352inline string to_string(const ::mdbx::env::geometry &value) {
6353 ostringstream out;
6354 out << value;
6355 return out.str();
6356}
6357
6358inline string to_string(const ::mdbx::env::operate_parameters &value) {
6359 ostringstream out;
6360 out << value;
6361 return out.str();
6362}
6363
6364inline string to_string(const ::mdbx::env::mode &value) {
6365 ostringstream out;
6366 out << value;
6367 return out.str();
6368}
6369
6370inline string to_string(const ::mdbx::env::durability &value) {
6371 ostringstream out;
6372 out << value;
6373 return out.str();
6374}
6375
6376inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6377 ostringstream out;
6378 out << value;
6379 return out.str();
6380}
6381
6382inline string to_string(const ::mdbx::env::operate_options &value) {
6383 ostringstream out;
6384 out << value;
6385 return out.str();
6386}
6387
6388inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6389 ostringstream out;
6390 out << value;
6391 return out.str();
6392}
6393
6394inline string to_string(const ::MDBX_log_level_t &value) {
6395 ostringstream out;
6396 out << value;
6397 return out.str();
6398}
6399
6400inline string to_string(const ::MDBX_debug_flags_t &value) {
6401 ostringstream out;
6402 out << value;
6403 return out.str();
6404}
6405
6406inline string to_string(const ::mdbx::error &value) {
6407 ostringstream out;
6408 out << value;
6409 return out.str();
6410}
6411
6412inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6413
6414template <> struct hash<::mdbx::slice> {
6415 MDBX_CXX14_CONSTEXPR size_t operator()(::mdbx::slice const &slice) const noexcept { return slice.hash_value(); }
6416};
6417
6419} // namespace std
6420
6421#if defined(__LCC__) && __LCC__ >= 126
6422#pragma diagnostic pop
6423#endif
6424
6425#ifdef _MSC_VER
6426#pragma warning(pop)
6427#endif
Definition mdbx.h++:600
Definition mdbx.h++:590
Definition mdbx.h++:610
#define MDBX_CXX11_CONSTEXPR
Definition mdbx.h:443
#define MDBX_MAYBE_UNUSED
Definition mdbx.h:509
#define MDBX_CXX14_CONSTEXPR
Definition mdbx.h:462
#define MDBX_NOTHROW_PURE_FUNCTION
The 'pure nothrow' function attribute for optimization.
Definition mdbx.h:259
mode_t mdbx_mode_t
Definition mdbx.h:174
int(* MDBX_preserve_func)(void *context, MDBX_val *target, const void *src, size_t bytes)
Definition mdbx.h:5055
#define LIBMDBX_API
Definition mdbx.h:591
#define LIBMDBX_API_TYPE
Definition mdbx.h:606
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:766
LIBMDBX_API int mdbx_replace_ex(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *new_data, MDBX_val *old_data, MDBX_put_flags_t flags, MDBX_preserve_func preserver, void *preserver_context)
pthread_t mdbx_tid_t
Definition mdbx.h:173
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition mdbx.h:698
int mdbx_filehandle_t
Definition mdbx.h:171
pid_t mdbx_pid_t
Definition mdbx.h:172
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:780
@ MDBX_MAXDATASIZE
Definition mdbx.h:774
@ MDBX_MAX_DBI
Definition mdbx.h:771
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:777
libmdbx build information
Definition mdbx.h:634
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4430
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4079
Information about the environment.
Definition mdbx.h:2805
Statistics for a table in the environment.
Definition mdbx.h:2759
Information about the transaction.
Definition mdbx.h:3981
libmdbx version information,
Definition mdbx.h:616
LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, MDBX_put_flags_t flags)
Delete current key/data pair.
LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result, uint64_t increment)
Sequence generation for a table.
LIBMDBX_API int mdbx_get_equal_or_great(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data)
Get equal or great item from a table.
LIBMDBX_API int mdbx_cursor_scan(MDBX_cursor *cursor, MDBX_predicate_func *predicate, void *context, MDBX_cursor_op start_op, MDBX_cursor_op turn_op, void *arg)
Сканирует таблицу с использованием передаваемого предиката, с уменьшением сопутствующих накладных рас...
LIBMDBX_API int mdbx_canary_put(MDBX_txn *txn, const MDBX_canary *canary)
Set integers markers (aka "canary") associated with the environment.
LIBMDBX_API int mdbx_canary_get(const MDBX_txn *txn, MDBX_canary *canary)
Returns fours integers markers (aka "canary") associated with the environment.
MDBX_put_flags_t
Data changing flags.
Definition mdbx.h:1626
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:4490
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:1663
@ MDBX_ALLDUPS
Definition mdbx.h:1646
@ MDBX_CURRENT
Definition mdbx.h:1641
@ MDBX_APPENDDUP
Definition mdbx.h:1659
@ MDBX_APPEND
Definition mdbx.h:1654
@ MDBX_UPSERT
Definition mdbx.h:1628
@ MDBX_RESERVE
Definition mdbx.h:1650
@ MDBX_NOOVERWRITE
Definition mdbx.h:1631
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:1707
LIBMDBX_API int mdbx_cursor_compare(const MDBX_cursor *left, const MDBX_cursor *right, bool ignore_multival)
Сравнивает позицию курсоров.
LIBMDBX_API int mdbx_cursor_on_last_dup(const MDBX_cursor *cursor)
Определяет стоит ли курсор на последнем или единственном мульти-значении соответствующем ключу.
LIBMDBX_API int mdbx_cursor_on_first(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to the first key-value pair or not.
LIBMDBX_API int mdbx_cursor_bind(MDBX_txn *txn, MDBX_cursor *cursor, MDBX_dbi dbi)
Bind cursor to specified transaction and DBI-handle.
LIBMDBX_API int mdbx_txn_release_all_cursors_ex(const MDBX_txn *txn, bool unbind, size_t *count)
Unbind or closes all cursors of a given transaction and of all its parent transactions if ones are.
struct MDBX_cursor MDBX_cursor
Opaque structure for navigating through a table.
Definition mdbx.h:728
LIBMDBX_API int mdbx_cursor_set_userctx(MDBX_cursor *cursor, void *ctx)
Set application information associated with the cursor.
LIBMDBX_API int mdbx_cursor_eof(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to a key-value pair or not, i.e. was not positioned or point...
LIBMDBX_API int mdbx_cursor_close2(MDBX_cursor *cursor)
Closes a cursor handle with returning error code.
LIBMDBX_API void * mdbx_cursor_get_userctx(const MDBX_cursor *cursor)
Get the application information associated with the MDBX_cursor.
LIBMDBX_API int mdbx_cursor_renew(MDBX_txn *txn, MDBX_cursor *cursor)
Renew a cursor handle for use within the given transaction.
LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor)
Closes a cursor handle without returning error code.
LIBMDBX_API MDBX_txn * mdbx_cursor_txn(const MDBX_cursor *cursor)
Return the cursor's transaction handle.
LIBMDBX_API int mdbx_cursor_on_last(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to the last key-value pair or not.
LIBMDBX_API int mdbx_cursor_copy(const MDBX_cursor *src, MDBX_cursor *dest)
Copy cursor position and state.
@ MDBX_SEEK_AND_GET_MULTIPLE
Definition mdbx.h:1826
@ MDBX_GET_CURRENT
Definition mdbx.h:1722
@ MDBX_GET_BOTH
Definition mdbx.h:1715
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1803
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1719
@ MDBX_SET_KEY
Definition mdbx.h:1762
@ MDBX_FIRST_DUP
Definition mdbx.h:1712
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1802
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1727
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1813
@ MDBX_NEXT_NODUP
Definition mdbx.h:1747
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1810
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1811
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1818
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1770
@ MDBX_SET_RANGE
Definition mdbx.h:1765
@ MDBX_LAST_DUP
Definition mdbx.h:1733
@ MDBX_PREV
Definition mdbx.h:1750
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1820
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1821
@ MDBX_LAST
Definition mdbx.h:1730
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1801
@ MDBX_PREV_DUP
Definition mdbx.h:1753
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1809
@ MDBX_SET
Definition mdbx.h:1759
@ MDBX_NEXT
Definition mdbx.h:1736
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1804
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1817
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1744
@ MDBX_PREV_NODUP
Definition mdbx.h:1756
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1819
@ MDBX_NEXT_DUP
Definition mdbx.h:1739
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1812
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1805
@ MDBX_FIRST
Definition mdbx.h:1709
LIBMDBX_API int mdbx_dbi_rename(MDBX_txn *txn, MDBX_dbi dbi, const char *name)
Переименовает таблицу по DBI-дескриптору
LIBMDBX_API int mdbx_dbi_rename2(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *name)
Переименовает таблицу по DBI-дескриптору
LIBMDBX_API int mdbx_dbi_close(MDBX_env *env, MDBX_dbi dbi)
Close a table handle. Normally unnecessary.
LIBMDBX_API int mdbx_dbi_open(MDBX_txn *txn, const char *name, MDBX_db_flags_t flags, MDBX_dbi *dbi)
Open or Create a named table in the environment.
LIBMDBX_API int mdbx_dbi_open2(MDBX_txn *txn, const MDBX_val *name, MDBX_db_flags_t flags, MDBX_dbi *dbi)
Open or Create a named table in the environment.
uint32_t MDBX_dbi
A handle for an individual table (key-value spaces) in the environment.
Definition mdbx.h:721
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1576
@ MDBX_INTEGERDUP
Definition mdbx.h:1600
@ MDBX_DB_ACCEDE
Definition mdbx.h:1618
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1578
@ MDBX_REVERSEKEY
Definition mdbx.h:1581
@ MDBX_DUPFIXED
Definition mdbx.h:1595
@ MDBX_INTEGERKEY
Definition mdbx.h:1591
@ MDBX_REVERSEDUP
Definition mdbx.h:1603
@ MDBX_CREATE
Definition mdbx.h:1606
@ MDBX_DUPSORT
Definition mdbx.h:1584
MDBX_log_level_t
Definition mdbx.h:841
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:6283
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1834
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1848
@ MDBX_BAD_TXN
Definition mdbx.h:1914
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1928
@ MDBX_SUCCESS
Definition mdbx.h:1836
@ MDBX_NOTFOUND
Definition mdbx.h:1851
@ MDBX_RESULT_TRUE
Definition mdbx.h:1842
@ MDBX_BUSY
Definition mdbx.h:1932
@ MDBX_EINVAL
Definition mdbx.h:2005
@ MDBX_ENOMEM
Definition mdbx.h:2007
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1935
@ MDBX_RESULT_FALSE
Definition mdbx.h:1839
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:1984
@ MDBX_KEYEXIST
Definition mdbx.h:1845
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:2541
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2535
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2538
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1017
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:3049
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2115
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:2988
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:2220
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2216
@ 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:2320
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2124
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2287
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2147
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2252
@ 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:2275
@ 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:2187
@ 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:2174
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2141
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2236
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2153
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2201
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2315
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:3685
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:3069
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:3006
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:4755
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:3730
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:1478
LIBMDBX_API void * mdbx_txn_get_userctx(const MDBX_txn *txn)
Returns an application information (a context pointer) associated with the transaction.
int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, MDBX_txn_flags_t flags, MDBX_txn **txn)
Create a transaction for use with the environment.
Definition mdbx.h:3950
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:709
LIBMDBX_API int mdbx_txn_reset(MDBX_txn *txn)
Reset a read-only transaction.
LIBMDBX_API int mdbx_txn_renew(MDBX_txn *txn)
Renew a read-only transaction.
LIBMDBX_API MDBX_txn_flags_t mdbx_txn_flags(const MDBX_txn *txn)
Return the transaction's flags.
@ MDBX_TXN_RDONLY
Definition mdbx.h:1489
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1498
@ MDBX_TXN_READWRITE
Definition mdbx.h:1483
@ MDBX_TXN_TRY
Definition mdbx.h:1504
bool rename_map(const ::mdbx::slice &old_name, const ::mdbx::slice &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
MDBX_NOTHROW_PURE_FUNCTION 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++:1913
MDBX_CXX14_CONSTEXPR struct slice tail(size_t n) const noexcept
Definition mdbx.h++:2462
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2317
buffer(size_t head_room, const struct slice &src, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2083
friend class env
Definition mdbx.h++:4069
MDBX_commit_latency commit_latency
Definition mdbx.h++:4103
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
MDBX_CXX14_CONSTEXPR struct slice middle(size_t from, size_t n) const noexcept
Definition mdbx.h++:2466
::MDBX_txn_info info
Definition mdbx.h++:3764
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4533
~txn_managed() noexcept
::MDBX_stat map_stat
Definition mdbx.h++:3921
env & set_sync_period(const duration &period)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
MDBX_NOTHROW_PURE_FUNCTION constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2375
txn_managed start_nested()
Start nested write transaction.
extra_runtime_option
MDBX environment extra runtime options.
Definition mdbx.h++:3474
@ prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h++:3508
@ spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h++:3500
@ spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h++:3502
@ writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h++:3506
@ sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h++:3483
@ dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h++:3494
@ dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h++:3496
@ spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h++:3498
@ merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h++:3504
@ 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++:3488
@ loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h++:3490
@ dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h++:3492
static buffer key_from(silo &&src) noexcept
Definition mdbx.h++:2631
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3701
MDBX_CXX14_CONSTEXPR struct slice safe_middle(size_t from, size_t n) const
Definition mdbx.h++:2478
MDBX_CXX14_CONSTEXPR int64_t as_int64() const
Definition mdbx.h++:2138
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1902
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3902
env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede=true)
map_handle(const map_handle &) noexcept=default
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2268
::MDBX_db_flags_t flags
Definition mdbx.h++:2984
path get_path() const
Return the path that was used for opening the environment.
static buffer hex_decode(const ::mdbx::slice &source, bool ignore_spaces=false, const allocator_type &allocator=allocator_type())
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:2217
int64_t as_int64_adapt() const
Definition mdbx.h++:2154
constexpr ::std::basic_string< CHAR, T, A > as_string(const A &allocator=A()) const
Definition mdbx.h++:2384
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4383
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4439
buffer encode_base64(unsigned wrap_width=0, const allocator_type &allocator=allocator_type()) const
Definition mdbx.h++:2212
static buffer key_from(const double *ieee754_64bit)
Definition mdbx.h++:2637
static buffer base58(const POD &pod, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base58 dump of the given pod.
Definition mdbx.h++:2188
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:1993
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
MDBX_CXX14_CONSTEXPR ::std::span< const POD > as_span() const
Definition mdbx.h++:2109
MDBX_CXX11_CONSTEXPR map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2978
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2326
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2255
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2297
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2265
durability
Durability level.
Definition mdbx.h++:3131
@ lazy_weak_tail
Definition mdbx.h++:3134
@ robust_synchronous
Definition mdbx.h++:3132
@ whole_fragile
Definition mdbx.h++:3135
@ half_synchronous_weak_last
Definition mdbx.h++:3133
void commit_embark_read()
Commit all the operations of a transaction into the database and then start read transaction.
constexpr buffer(const buffer &src, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2051
MDBX_CXX11_CONSTEXPR txn_managed() noexcept=default
MDBX_CXX11_CONSTEXPR bool is_null() const noexcept
Checks whether the data pointer of the buffer is nullptr.
Definition mdbx.h++:2372
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1475
static buffer base64_decode(const ::mdbx::slice &source, bool ignore_spaces=false, const allocator_type &allocator=allocator_type())
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:2231
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3301
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2526
map_handle & operator=(const map_handle &) noexcept=default
duration sync_period() const
Gets relative period since the last unsteady commit that used to force flush the data buffers to disk...
buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2041
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept
Returns the hash value of the data.
Definition mdbx.h++:2381
MDBX_NOTHROW_PURE_FUNCTION 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++:1928
move_result seek_multiple_samelength(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4427
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2276
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2282
buffer & operator=(const buffer &src)
Definition mdbx.h++:2343
estimate_result estimate(move_operation operation, slice &key) const
uint16_t as_uint16_adapt() const
Definition mdbx.h++:2148
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2548
MDBX_NOTHROW_PURE_FUNCTION 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++:1906
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3725
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4402
::MDBX_canary canary
Definition mdbx.h++:3930
env & copy(const wchar_t *destination, bool compactify, bool force_dynamic_size=false)
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from the data chunk.
Definition mdbx.h++:2428
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from the data chunk.
Definition mdbx.h++:2424
bool is_readwrite() const
Checks whether the transaction is read-write.
Definition mdbx.h++:3762
MDBX_CXX11_CONSTEXPR void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:1987
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++:4332
MDBX_CXX11_CONSTEXPR const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:1973
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2627
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++:4396
buffer base64_decode(bool ignore_spaces=false, const allocator_type &allocator=allocator_type()) const
Decodes Base64 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2250
bool clear_map(const char *name, bool throw_if_absent=false)
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2490
uint8_t as_uint8_adapt() const
Definition mdbx.h++:2149
MDBX_NOTHROW_PURE_FUNCTION bool starts_with(const struct slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:2394
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4405
buffer encode_base58(unsigned wrap_width=0, const allocator_type &allocator=allocator_type()) const
Definition mdbx.h++:2207
MDBX_CXX14_CONSTEXPR struct slice safe_tail(size_t n) const
Definition mdbx.h++:2474
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.
::std::basic_string_view< CHAR, T > string_view() const noexcept
Definition mdbx.h++:2358
buffer(size_t head_room, const buffer &src, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2091
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2322
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2647
static buffer hex(const POD &pod, bool uppercase=false, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a hexadecimal dump of the given pod.
Definition mdbx.h++:2180
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4486
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4350
MDBX_CXX14_CONSTEXPR uint128_t as_uint128() const
Definition mdbx.h++:2128
MDBX_CXX14_CONSTEXPR ::std::span< POD > as_span()
Definition mdbx.h++:2112
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++:4341
MDBX_CXX14_CONSTEXPR buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2005
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2653
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.
MDBX_CXX11_CONSTEXPR map_handle() noexcept
Definition mdbx.h++:2977
bool is_same_or_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4167
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3809
static buffer hex(const ::mdbx::slice &source, bool uppercase=false, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:2160
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3985
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4373
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4159
buffer(const buffer &src, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2027
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4163
static buffer base58_decode(const ::mdbx::slice &source, bool ignore_spaces=false, const allocator_type &allocator=allocator_type())
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:2224
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2352
uint32_t as_uint32_adapt() const
Definition mdbx.h++:2147
buffer(size_t head_room, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2073
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2633
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from the data chunk.
Definition mdbx.h++:2420
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++:3894
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2305
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3228
MDBX_CXX11_CONSTEXPR cursor() noexcept=default
MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const
Definition mdbx.h++:2131
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4357
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2293
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4555
bool clear_map(const ::mdbx::slice &name, bool throw_if_absent=false)
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2407
static buffer base64(const POD &pod, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base64 dump of the given pod.
Definition mdbx.h++:2195
MDBX_txn * handle_
Definition mdbx.h++:3726
void abort()
Abandon all the operations of the transaction instead of saving ones.
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2639
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4329
mode
Operation mode.
Definition mdbx.h++:3123
@ write_mapped_io
Definition mdbx.h++:3126
@ nested_transactions
Definition mdbx.h++:3127
@ readonly
Definition mdbx.h++:3124
@ write_file_io
Definition mdbx.h++:3125
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4326
MDBX_CXX14_CONSTEXPR ::std::span< const byte > bytes() const
Definition mdbx.h++:2114
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4285
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3362
operator::mdbx::txn() const
Definition mdbx.h++:4468
MDBX_NOTHROW_PURE_FUNCTION constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:1922
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2522
MDBX_env * handle_
Definition mdbx.h++:3025
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2619
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4389
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2546
commit_latency commit_get_latency()
Commit all the operations of a transaction into the database and return latency information.
Definition mdbx.h++:4116
static buffer base58(const ::mdbx::slice &source, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base58 dump of the slice content.
Definition mdbx.h++:2167
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4155
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2651
buffer(const struct slice &src, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2021
MDBX_CXX14_CONSTEXPR int128_t as_int128() const
Definition mdbx.h++:2136
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4339
buffer hex_decode(bool ignore_spaces=false, const allocator_type &allocator=allocator_type()) const
Decodes hexadecimal dump from the buffer content to new returned buffer.
Definition mdbx.h++:2238
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4359
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2347
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2054
buffer(const ::mdbx::txn &txn, const struct slice &src, const allocator_type &allocator=allocator_type())
void close()
Explicitly closes the cursor.
Definition mdbx.h++:4539
MDBX_NOTHROW_PURE_FUNCTION constexpr bool empty() const noexcept
Checks whether the string is empty.
Definition mdbx.h++:2369
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2058
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2518
MDBX_CXX11_CONSTEXPR void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:1980
MDBX_CXX11_CONSTEXPR const struct slice & slice() const noexcept
Definition mdbx.h++:2099
bool is_pristine() const
Returns true for a freshly created database, but false if at least one transaction was committed.
move_result to_key_exact(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4370
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3759
MDBX_CXX11_CONSTEXPR const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:1953
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2311
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2655
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2068
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2581
move_result next_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4435
env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede=true)
MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const
Definition mdbx.h++:2133
MDBX_CXX14_CONSTEXPR int16_t as_int16() const
Definition mdbx.h++:2140
void append(map_handle map, const pair &kv, bool multivalue_order_preserved=true)
Definition mdbx.h++:4033
cursor_managed & operator=(const cursor_managed &)=delete
default_capacity_policy reservation_policy
Definition mdbx.h++:1476
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3332
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3342
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3344
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3339
MDBX_CXX14_CONSTEXPR byte & at(size_t n)
Accesses the specified byte of data chunk with bounds checking.
Definition mdbx.h++:2450
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2645
MDBX_CXX11_CONSTEXPR byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:1940
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4261
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4344
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2349
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2498
MDBX_CXX14_CONSTEXPR ::std::span< const char > chars() const
Definition mdbx.h++:2116
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2569
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2530
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4306
uint128_t as_uint128_adapt() const
Definition mdbx.h++:2144
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4545
::MDBX_dbi_state_t state
Definition mdbx.h++:2985
MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const
Definition mdbx.h++:2132
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3531
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4513
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++:4111
MDBX_CXX14_CONSTEXPR byte at(size_t n) const
Accesses the specified byte of data chunk with bounds checking.
Definition mdbx.h++:2446
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++:3307
MDBX_CXX14_CONSTEXPR POD as_pod() const
Definition mdbx.h++:2125
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4399
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++:2661
move_result get_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4431
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4361
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4358
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
MDBX_CXX14_CONSTEXPR size_t operator()(::mdbx::slice const &slice) const noexcept
Definition mdbx.h++:6415
operator::mdbx::map_handle() const
Definition mdbx.h++:4469
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3303
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &allocator=allocator_type()) const
Definition mdbx.h++:2200
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2121
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2657
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from the data chunk.
Definition mdbx.h++:2416
bool drop_map(const ::mdbx::slice &name, bool throw_if_absent=false)
Drop key-value map.
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3806
static buffer key_from(const uint32_t unsigned_int32)
Definition mdbx.h++:2659
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2270
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++:4376
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3368
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2013
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3982
MDBX_CXX14_CONSTEXPR buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:1998
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++:2301
MDBX_CXX14_CONSTEXPR int32_t as_int32() const
Definition mdbx.h++:2139
friend int compare_position(const cursor &left, const cursor &right, bool ignore_nested)
Definition mdbx.h++:6062
buffer(const char *c_str, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2036
constexpr buffer(const struct slice &src, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2047
MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept
Accesses the specified byte of data chunk.
Definition mdbx.h++:2432
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4049
MDBX_CXX14_CONSTEXPR struct slice safe_head(size_t n) const
Definition mdbx.h++:2470
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++:3314
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++:3887
allocation_aware_details::move_assign_alloc< silo, allocator_type > move_assign_alloc
Definition mdbx.h++:1898
int32_t as_int32_adapt() const
Definition mdbx.h++:2155
buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2291
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++:4041
MDBX_CXX11_CONSTEXPR char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:1967
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1899
bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2030
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2488
MDBX_CXX14_CONSTEXPR int8_t as_int8() const
Definition mdbx.h++:2141
bool is_empty() const
Checks whether the database is empty.
MDBX_CXX11_CONSTEXPR const byte * byte_ptr() const noexcept
Definition mdbx.h++:1933
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2534
void close(bool dont_sync=false)
Explicitly closes the environment and release the memory map.
MDBX_NOTHROW_PURE_FUNCTION bool ends_with(const struct slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:2399
move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4411
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4177
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4192
@ multi_exactkey_value_equal
Definition mdbx.h++:4209
@ pair_greater_or_equal
Definition mdbx.h++:4217
@ key_lesser_than
Definition mdbx.h++:4199
@ next
Definition mdbx.h++:4180
@ pair_exact
Definition mdbx.h++:4216
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4210
@ pair_lesser_or_equal
Definition mdbx.h++:4214
@ batch_samelength
Definition mdbx.h++:4220
@ seek_key
Definition mdbx.h++:4194
@ key_lowerbound
Definition mdbx.h++:4196
@ pair_lesser_than
Definition mdbx.h++:4213
@ pair_equal
Definition mdbx.h++:4215
@ key_greater_than
Definition mdbx.h++:4203
@ batch_samelength_next
Definition mdbx.h++:4221
@ multi_find_pair
Definition mdbx.h++:4191
@ key_greater_or_equal
Definition mdbx.h++:4202
@ key_exact
Definition mdbx.h++:4195
@ key_equal
Definition mdbx.h++:4201
@ multi_currentkey_prevvalue
Definition mdbx.h++:4186
@ key_lesser_or_equal
Definition mdbx.h++:4200
@ multi_nextkey_firstvalue
Definition mdbx.h++:4189
@ get_current
Definition mdbx.h++:4182
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4208
@ multi_prevkey_lastvalue
Definition mdbx.h++:4184
@ previous
Definition mdbx.h++:4181
@ last
Definition mdbx.h++:4179
@ pair_greater_than
Definition mdbx.h++:4218
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4207
@ multi_currentkey_firstvalue
Definition mdbx.h++:4185
@ first
Definition mdbx.h++:4178
@ batch_samelength_previous
Definition mdbx.h++:4222
@ multi_currentkey_nextvalue
Definition mdbx.h++:4187
@ seek_and_batch_samelength
Definition mdbx.h++:4223
@ multi_exactkey_value_greater
Definition mdbx.h++:4211
@ multi_currentkey_lastvalue
Definition mdbx.h++:4188
virtual ~env_managed() noexcept
MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const
Definition mdbx.h++:2130
MDBX_CXX14_CONSTEXPR struct slice head(size_t n) const noexcept
Definition mdbx.h++:2458
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4335
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2613
void insert(const pair &kv)
Definition mdbx.h++:4487
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2480
cursor_managed(const cursor_managed &)=delete
env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
MDBX_CXX14_CONSTEXPR ::std::span< char > chars()
Definition mdbx.h++:2117
void upsert(const pair &kv)
Definition mdbx.h++:4489
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4347
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2412
MDBX_CXX11_CONSTEXPR const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:1956
int16_t as_int16_adapt() const
Definition mdbx.h++:2156
txn_managed & operator=(const txn_managed &)=delete
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2663
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2404
static buffer base64(const ::mdbx::slice &source, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base64 dump of the slice content.
Definition mdbx.h++:2173
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3907
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4386
MDBX_CXX11_CONSTEXPR const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:1976
typename ::std::allocator_traits< default_allocator >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1471
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++:2635
move_result to_current_last_multi(bool throw_notfound=true)
Definition mdbx.h++:4354
MDBX_CXX11_CONSTEXPR char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:1960
value_result try_insert(const pair &kv)
Definition mdbx.h++:4488
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++:4505
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4364
MDBX_CXX11_CONSTEXPR env_managed() noexcept=default
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2643
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4408
uint64_t as_uint64_adapt() const
Definition mdbx.h++:2146
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3311
MDBX_cursor * handle_
Definition mdbx.h++:4132
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2538
~cursor_managed() noexcept
Definition mdbx.h++:4563
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2558
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2096
MDBX_dbi dbi
Definition mdbx.h++:2976
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++:4380
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2641
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4351
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2595
MDBX_NOTHROW_PURE_FUNCTION constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:1916
MDBX_CXX11_CONSTEXPR env() noexcept=default
MDBX_CXX11_CONSTEXPR const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:1936
MDBX_CXX11_CONSTEXPR byte & operator[](size_t n) noexcept
Accesses the specified byte of data chunk.
Definition mdbx.h++:2439
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++:2514
MDBX_CXX14_CONSTEXPR buffer(const ::std::span< POD > &span)
Definition mdbx.h++:2104
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3770
MDBX_CXX11_CONSTEXPR byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:1947
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2345
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++:4392
txn_managed(const txn_managed &)=delete
friend int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept
Definition mdbx.h++:6058
static buffer clone(const buffer &src, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2287
buffer(size_t capacity, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2078
MDBX_CXX14_CONSTEXPR ::std::span< byte > bytes()
Definition mdbx.h++:2115
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3359
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3309
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3984
buffer & append_producer(PRODUCER &producer)
Definition mdbx.h++:2500
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3983
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2507
MDBX_CXX11_CONSTEXPR txn() noexcept=default
int128_t as_int128_adapt() const
Definition mdbx.h++:2152
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++:2624
bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:3915
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4367
move_result to_previous(bool throw_notfound=true)
Definition mdbx.h++:4340
constexpr buffer(const char *c_str, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2063
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4151
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3305
int8_t as_int8_adapt() const
Definition mdbx.h++:2157
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3773
buffer base58_decode(bool ignore_spaces=false, const allocator_type &allocator=allocator_type()) const
Decodes Base58 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2244
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4280
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1468
Unmanaged cursor.
Definition mdbx.h++:4130
Managed cursor.
Definition mdbx.h++:4525
Unmanaged database environment.
Definition mdbx.h++:3021
Managed database environment.
Definition mdbx.h++:3640
Unmanaged database transaction.
Definition mdbx.h++:3723
Managed database transaction.
Definition mdbx.h++:4067
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++:5199
polymorphic_allocator default_allocator
Definition mdbx.h++:358
MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5523
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base58(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base58 dump of the slice content.
Definition mdbx.h++:5036
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++:5484
MDBX_CXX11_CONSTEXPR bool is_success() const noexcept
Definition mdbx.h++:4677
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5549
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++:5227
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++:5932
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6169
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2890
MDBX_CXX14_CONSTEXPR void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4882
MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4926
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:5124
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5582
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4722
void rethrow_captured() const
Definition mdbx.h++:4659
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6127
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6103
MDBX_CXX14_CONSTEXPR void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition mdbx.h++:4880
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++:5653
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5192
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5166
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5895
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5849
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5446
MDBX_CXX11_CONSTEXPR byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4931
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++:5377
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6071
MDBX_CXX11_CONSTEXPR const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4594
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6005
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4899
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4792
env & operator=(env &&other) noexcept
Definition mdbx.h++:5136
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6175
MDBX_CXX11_CONSTEXPR const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4854
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:422
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5842
string< ALLOCATOR > as_hex_string(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a hexadecimal dump of the slice content.
Definition mdbx.h++:5015
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5666
void throw_on_failure() const
Definition mdbx.h++:4699
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6250
void update(const slice &key, const slice &value)
Definition mdbx.h++:6246
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++:5741
MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4687
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5551
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5512
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6058
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5310
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5729
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6236
MDBX_CXX11_CONSTEXPR const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4834
MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition mdbx.h++:4689
bool is_clean() const noexcept
Definition mdbx.h++:4652
string< ALLOCATOR > as_base58_string(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:5020
MDBX_CXX11_CONSTEXPR const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4846
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2883
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4742
MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4958
void swap(slice &other) noexcept
Definition mdbx.h++:4828
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5300
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2887
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:378
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4910
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:5352
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5185
MDBX_CXX11_CONSTEXPR slice() noexcept
Create an empty slice.
Definition mdbx.h++:4776
static MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4972
MDBX_CXX11_CONSTEXPR size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4876
void insert(const slice &key, slice value)
Definition mdbx.h++:6197
MDBX_CXX11_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++:5449
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6131
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:357
MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4952
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:2871
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++:5489
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:6021
~cursor() noexcept
Definition mdbx.h++:6042
~txn() noexcept
Definition mdbx.h++:5533
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5382
MDBX_CXX11_CONSTEXPR bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4874
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6123
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6177
MDBX_CXX11_CONSTEXPR const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4852
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6222
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5177
map_handle map() const
Definition mdbx.h++:6182
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++:5393
MDBX_CXX11_CONSTEXPR info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:5121
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:5128
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6115
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6135
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2951
MDBX_NOTHROW_PURE_FUNCTION bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5068
void success_or_throw() const
Definition mdbx.h++:4704
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base64(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base64 dump of the slice content.
Definition mdbx.h++:5041
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5586
buffer< ALLOCATOR, CAPACITY_POLICY > base64_decode(bool ignore_spaces=false, const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:5056
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5433
MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5134
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6062
static MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5079
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6141
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5183
MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4666
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5556
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6240
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5308
MDBX_NOTHROW_PURE_FUNCTION bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5060
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2879
void capture() noexcept
Definition mdbx.h++:4654
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5568
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++:5706
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5877
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4893
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2998
MDBX_NOTHROW_PURE_FUNCTION bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5064
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6215
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++:5247
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++:5388
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:5993
MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4942
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5314
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5662
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6011
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++:5969
MDBX_CXX11_CONSTEXPR bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:4872
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5318
buffer< ALLOCATOR, CAPACITY_POLICY > extract(map_handle map, const slice &key, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &allocator=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Removes and return a value of the key.
Definition mdbx.h++:5939
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5588
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6029
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5700
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6081
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++:5223
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++:5745
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5173
buffer< ALLOCATOR, CAPACITY_POLICY > encode_hex(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:5030
cursor & operator=(cursor &&other) noexcept
Definition mdbx.h++:6034
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5718
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5867
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4994
buffer< ALLOCATOR, CAPACITY_POLICY > hex_decode(bool ignore_spaces=false, const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:5046
MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4937
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6333
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++:5399
bool on_first() const
Definition mdbx.h++:6149
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4919
::MDBX_version_info version_info
libmdbx version information,
Definition mdbx.h++:334
bool eof() const
Definition mdbx.h++:6147
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5584
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5570
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5370
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6189
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5637
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5498
::MDBX_build_info build_info
libmdbx build information
Definition mdbx.h++:338
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4904
bool seek(const slice &key)
Definition mdbx.h++:6139
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5422
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5372
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++:5291
MDBX_CXX11_CONSTEXPR size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4860
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5664
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++:5411
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4887
MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept
Definition mdbx.h++:4679
MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4673
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6202
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++:6303
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4727
string< ALLOCATOR > as_base64_string(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:5025
::MDBX_cmp_func * comparator
Definition mdbx.h++:2997
put_mode
Key-value pairs put mode.
Definition mdbx.h++:3006
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++:5403
::mdbx_filehandle_t filehandle
Definition mdbx.h++:380
MDBX_CXX14_CONSTEXPR slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4867
static MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5074
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++:5269
MDBX_CXX11_CONSTEXPR cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6019
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5002
char8_t byte
Definition mdbx.h++:318
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5723
txn & operator=(txn &&other) noexcept
Definition mdbx.h++:5525
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6281
buffer< ALLOCATOR, CAPACITY_POLICY > replace_reserve(map_handle map, const slice &key, slice &new_value, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &allocator=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Definition mdbx.h++:5960
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5322
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5576
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5829
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:352
MDBX_CXX11_CONSTEXPR const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4838
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6109
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5889
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4914
MDBX_CXX14_CONSTEXPR slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4862
~env() noexcept
Definition mdbx.h++:5144
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2852
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5757
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++:5974
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5873
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2855
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5491
::mdbx::filesystem::path path
Definition mdbx.h++:404
bool on_last_multival() const
Definition mdbx.h++:6155
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5364
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5824
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5358
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++:5203
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5454
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6027
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5298
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5600
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2875
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5590
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5416
bool on_first_multival() const
Definition mdbx.h++:6153
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5816
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4717
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5334
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5863
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5181
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4998
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6262
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6119
MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4947
MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4675
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5477
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:5908
MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4964
bool on_last() const
Definition mdbx.h++:6151
MDBX_CXX11_CONSTEXPR const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:4844
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:400
static MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4979
buffer< ALLOCATOR, CAPACITY_POLICY > base58_decode(bool ignore_spaces=false, const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:5051
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:5346
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5427
map_handle::info get_handle_info(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5712
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++:6171
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5160
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5606
MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept
Definition mdbx.h++:4683
MDBX_CXX11_CONSTEXPR const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4595
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6268
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++:5621
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:374
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5519
MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept
Definition mdbx.h++:4681
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5594
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++:5795
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5006
@ multi_reverse_samelength
Definition mdbx.h++:2923
@ multi_samelength
Definition mdbx.h++:2908
@ multi_ordinal
Definition mdbx.h++:2915
@ msgpack
Definition mdbx.h++:2938
@ single
Definition mdbx.h++:2891
@ multi
Definition mdbx.h++:2893
@ multi_reverse
Definition mdbx.h++:2900
@ upsert
Insert or update.
Definition mdbx.h++:3008
@ update
Update existing, don't insert new.
Definition mdbx.h++:3009
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:3007
@ continue_loop
Definition mdbx.h++:2852
@ exit_loop
Definition mdbx.h++:2852
@ usual
Definition mdbx.h++:2856
@ ordinal
Definition mdbx.h++:2861
@ reverse
Definition mdbx.h++:2858
@ msgpack
Definition mdbx.h++:2866
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2975
MDBX_CXX11_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
MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept
Checks the slice is not refers to null address or has zero length.
Definition mdbx.h++:1002
MDBX_CXX14_CONSTEXPR ::std::span< const char > chars() const
Definition mdbx.h++:699
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:1401
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of a passed slice.
Definition mdbx.h++:1216
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:665
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
MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept=default
int8_t as_int8_adapt() const
MDBX_NOTHROW_PURE_FUNCTION constexpr bool is_reference() const noexcept
Definition mdbx.h++:2825
static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna)
Definition mdbx.h++:1180
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2774
@ max_length
Definition mdbx.h++:644
MDBX_NOTHROW_PURE_FUNCTION constexpr bool is_freestanding() const noexcept
Definition mdbx.h++:2820
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:751
MDBX_CXX14_CONSTEXPR ::std::span< const POD > as_span() const
Definition mdbx.h++:679
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2815
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base58 dump of a passed slice.
Definition mdbx.h++:1264
const bool ignore_spaces
Definition mdbx.h++:1385
MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8=false) const noexcept
Checks whether the content of the slice is printable.
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:858
MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const
Definition mdbx.h++:1025
value_result & operator=(const value_result &) noexcept=default
MDBX_CXX11_CONSTEXPR to_base58(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1250
MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const
Definition mdbx.h++:1022
int128_t as_int128_adapt() const
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from Base64 dump from a passed slice.
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:1394
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:1437
slice value
Definition mdbx.h++:2718
::std::ostream & output(::std::ostream &out) const
Output Base64 dump of passed slice to the std::ostream.
MDBX_CXX11_CONSTEXPR pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:2763
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1237
static MDBX_CXX14_CONSTEXPR slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:711
MDBX_CXX14_CONSTEXPR slice(const ::std::span< POD > &span)
Definition mdbx.h++:674
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2796
slice value
Definition mdbx.h++:2732
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2778
::std::ostream & output(::std::ostream &out) const
Output hexadecimal dump of passed slice to the std::ostream.
pair_result(const pair_result &) noexcept=default
MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept
Definition mdbx.h++:1052
const slice source
Definition mdbx.h++:1384
const slice source
Definition mdbx.h++:1200
const unsigned wrap_width
Definition mdbx.h++:1202
buffer_pair_spec(const txn &txn, const pair &pair, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2810
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:1361
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:725
const bool ignore_spaces
Definition mdbx.h++:1347
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from Base58 dump from a passed slice.
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
uint16_t as_uint16_adapt() const
static MDBX_CXX14_CONSTEXPR slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:1005
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base64 dump of a passed slice.
Definition mdbx.h++:1310
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2798
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:747
std::pair< slice, slice > stl_pair
Definition mdbx.h++:2731
value_result(const value_result &) noexcept=default
MDBX_CXX11_CONSTEXPR pair_result() noexcept
Definition mdbx.h++:2762
@ pettiness_threshold
Definition mdbx.h++:1168
@ extra_inplace_storage
Definition mdbx.h++:1166
@ max_reserve
Definition mdbx.h++:1169
@ inplace_storage_size_rounding
Definition mdbx.h++:1167
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:1210
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2793
MDBX_CXX14_CONSTEXPR ::std::span< const byte > bytes() const
Definition mdbx.h++:697
MDBX_CXX14_CONSTEXPR int16_t as_int16() const
Definition mdbx.h++:1032
MDBX_CXX14_CONSTEXPR ::std::span< char > chars()
Definition mdbx.h++:700
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1284
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:2720
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
MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept
Definition mdbx.h++:2734
MDBX_CXX14_CONSTEXPR ::std::span< byte > bytes()
Definition mdbx.h++:698
MDBX_CXX14_CONSTEXPR ::std::span< POD > as_span()
Definition mdbx.h++:688
MDBX_CXX11_CONSTEXPR from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1348
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
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:1355
buffer_pair_spec(const txn &txn, const slice &key, const slice &value, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2807
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:730
MDBX_CXX14_CONSTEXPR uint128_t as_uint128() const
Definition mdbx.h++:1020
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
MDBX_CXX11_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
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:1303
MDBX_CXX11_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
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2785
MDBX_CXX11_CONSTEXPR to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1203
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by hexadecimal dump of a passed slice.
MDBX_CXX11_CONSTEXPR to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1296
MDBX_CXX11_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
MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const
Definition mdbx.h++:1023
bool done
Definition mdbx.h++:2761
::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
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2804
MDBX_CXX14_CONSTEXPR int8_t as_int8() const
Definition mdbx.h++:1033
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:1444
MDBX_CXX11_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
const bool uppercase
Definition mdbx.h++:1201
static MDBX_CXX11_CONSTEXPR size_t round(const size_t value)
Definition mdbx.h++:1172
MDBX_CXX14_CONSTEXPR int64_t as_int64() const
Definition mdbx.h++:1030
const bool ignore_spaces
Definition mdbx.h++:1428
pair(const pair &) noexcept=default
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
slice key
Definition mdbx.h++:2732
const slice source
Definition mdbx.h++:1427
pair_result & operator=(const pair_result &) noexcept=default
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:1257
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1333
MDBX_CXX14_CONSTEXPR int32_t as_int32() const
Definition mdbx.h++:1031
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2776
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from hexadecimal dump from a passed slice.
MDBX_CXX11_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
MDBX_CXX14_CONSTEXPR POD as_pod() const
Definition mdbx.h++:1007
static MDBX_CXX14_CONSTEXPR pair invalid() noexcept
Definition mdbx.h++:2742
int64_t as_int64_adapt() const
buffer_pair_spec(const stl_pair &pair, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2791
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Definition mdbx.h++:769
MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:2733
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2777
MDBX_CXX14_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
MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const
Definition mdbx.h++:1024
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid hexadecimal dump, and therefore there could b...
MDBX_CXX11_CONSTEXPR from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1429
const unsigned wrap_width
Definition mdbx.h++:1248
MDBX_CXX11_CONSTEXPR from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1386
const unsigned wrap_width
Definition mdbx.h++:1294
uint32_t as_uint32_adapt() const
buffer_pair_spec(const pair &pair, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2802
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++:2813
static MDBX_CXX14_CONSTEXPR slice wrap(const POD &pod)
Definition mdbx.h++:713
MDBX_CXX11_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
int16_t as_int16_adapt() const
MDBX_CXX14_CONSTEXPR int128_t as_int128() const
Definition mdbx.h++:1028
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2775
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
buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference, const allocator_type &allocator=allocator_type())
Definition mdbx.h++:2787
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:708
bool done
Definition mdbx.h++:2719
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 &allocator=ALLOCATOR())
Definition mdbx.h++:2667
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:2844
inline ::std::ostream & operator<<(::std::ostream &out, const to_hex &wrapper)
Definition mdbx.h++:1340
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &allocator=ALLOCATOR())
Definition mdbx.h++:2689
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++:2841
Definition mdbx.h++:2773
Definition mdbx.h++:1164
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++:2730
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:2760
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++:2717
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:520
remote_media(const ::mdbx::error &)
dangling_map_id(const ::mdbx::error &)
fatal(const ::mdbx::error &) noexcept
reader_slot_busy(const ::mdbx::error &)
exception(const exception &)=default
MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4675
::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++:519
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++:488
db_full(const ::mdbx::error &)
duplicated_lck_file(const ::mdbx::error &)
const ::mdbx::error error() const noexcept
Definition mdbx.h++:510
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++:521
MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4673
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++:522
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 &)
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++:447
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:432
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:528
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:4694
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:4698
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition mdbx.h++:174
#define MDBX_CXX17_FALLTHROUGH
Definition mdbx.h++:232
#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, API_TYPENAME)
Definition mdbx.h++:112
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:272
#define MDBX_LIKELY(cond)
Definition mdbx.h++:207
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:184
#define MDBX_UNLIKELY(cond)
Definition mdbx.h++:215
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:163
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:202
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:223
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:183
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:238
The libmdbx C API header file.
Definition mdbx.h++:1057
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1059
The libmdbx C++ API namespace.
Definition mdbx.h++:305
STL namespace.
Definition mdbx.h++:4242
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4244
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4243
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4246
Definition mdbx.h++:4230
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++:4234
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4232
Tagged type for output to std::ostream.
Definition mdbx.h++:3072
MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept
Definition mdbx.h++:3074
intptr_t bytes
Definition mdbx.h++:3073
Database geometry for size management.
Definition mdbx.h++:3048
MDBX_CXX11_CONSTEXPR geometry() noexcept
Definition mdbx.h++:3112
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3096
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3108
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3055
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3051
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3054
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3063
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3052
@ default_value
Means "keep current or use default".
Definition mdbx.h++:3050
@ kB
bytes (0x03E8)
Definition mdbx.h++:3053
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3062
@ KiB
bytes (0x0400)
Definition mdbx.h++:3061
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3099
MDBX_CXX11_CONSTEXPR geometry(const geometry &) noexcept=default
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3084
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3102
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3079
MDBX_CXX11_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++:3115
Operate options.
Definition mdbx.h++:3152
bool disable_readahead
Definition mdbx.h++:3161
bool enable_validation
Definition mdbx.h++:3165
bool no_sticky_threads
Definition mdbx.h++:3154
bool disable_clear_memory
Definition mdbx.h++:3163
bool exclusive
Definition mdbx.h++:3159
bool nested_write_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3157
operate_options(MDBX_env_flags_t) noexcept
MDBX_CXX14_CONSTEXPR operate_options & operator=(const operate_options &) noexcept=default
MDBX_CXX11_CONSTEXPR operate_options() noexcept
Definition mdbx.h++:3166
MDBX_CXX11_CONSTEXPR operate_options(const operate_options &) noexcept=default
Operate parameters.
Definition mdbx.h++:3174
env::durability durability
Definition mdbx.h++:3182
MDBX_CXX14_CONSTEXPR operate_parameters & operator=(const operate_parameters &) noexcept=default
env::operate_options options
Definition mdbx.h++:3184
static env::mode mode_from_flags(MDBX_env_flags_t) noexcept
MDBX_CXX11_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++:3188
MDBX_CXX11_CONSTEXPR operate_parameters(const operate_parameters &) noexcept=default
MDBX_CXX11_CONSTEXPR operate_parameters() noexcept
Definition mdbx.h++:3186
unsigned max_readers
The maximum number of threads/reader slots for the environment. Zero means default value.
Definition mdbx.h++:3180
env::reclaiming_options reclaiming
Definition mdbx.h++:3183
env::mode mode
Definition mdbx.h++:3181
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++:3177
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3554
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3557
uint64_t transaction_lag
Definition mdbx.h++:3560
size_t bytes_used
Definition mdbx.h++:3564
uint64_t transaction_id
Definition mdbx.h++:3558
int slot
The reader lock table slot number.
Definition mdbx.h++:3555
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3556
size_t bytes_retained
Definition mdbx.h++:3567
Garbage reclaiming options.
Definition mdbx.h++:3139
MDBX_CXX11_CONSTEXPR reclaiming_options(const reclaiming_options &) noexcept=default
bool coalesce
Definition mdbx.h++:3143
reclaiming_options(MDBX_env_flags_t) noexcept
MDBX_CXX11_CONSTEXPR reclaiming_options() noexcept
Definition mdbx.h++:3144
MDBX_CXX14_CONSTEXPR reclaiming_options & operator=(const reclaiming_options &) noexcept=default
bool lifo
Definition mdbx.h++:3141
Additional parameters for creating a new database.
Definition mdbx.h++:3663
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3665
MDBX_CXX11_CONSTEXPR create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3666
env::geometry geometry
Definition mdbx.h++:3664
Definition mdbx.h++:2986
map_handle::state state
Definition mdbx.h++:2988
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2987
info & operator=(const info &) noexcept=default
capacity_holder capacity_
Definition mdbx.h++:1555
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1566
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1656
constexpr bin & operator=(const bin &ditto) noexcept
Definition mdbx.h++:1633
constexpr bin(size_t capacity_bytes=0) noexcept
Definition mdbx.h++:1605
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1558
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1550
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1573
inplace_flag_holder inplace_
Definition mdbx.h++:1556
constexpr bin(bin &&ditto) noexcept
Definition mdbx.h++:1619
allocator_pointer allocated_ptr_
Definition mdbx.h++:1554
constexpr bin(allocator_pointer ptr, size_t capacity_bytes) noexcept
Definition mdbx.h++:1610
size_t stub_capacity_bytes_
Definition mdbx.h++:1532
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1671
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1545
size_t bytes_
Definition mdbx.h++:1546
constexpr ~bin()
Definition mdbx.h++:1614
constexpr const byte * address() const noexcept
Definition mdbx.h++:1665
constexpr byte * make_allocated(allocator_pointer ptr, size_t capacity_bytes) noexcept
Definition mdbx.h++:1590
@ inplace_size
Definition mdbx.h++:1540
@ inplace_signature_limit
Definition mdbx.h++:1537
@ inplace_size_rounding
Definition mdbx.h++:1539
constexpr byte * address() noexcept
Definition mdbx.h++:1668
constexpr bin & operator=(bin &&ditto) noexcept
Definition mdbx.h++:1649
@ lastbyte_poison
Definition mdbx.h++:1535
@ lastbyte_inplace_signature
Definition mdbx.h++:1535
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1575
byte lastbyte_
Definition mdbx.h++:1551
allocator_pointer ptr_
Definition mdbx.h++:1531