libmdbx 0.14.1.273 (2026-01-14T13:23:59+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
24
25#pragma once
26
27//
28// Tested with, since 2026:
29// - Elbrus LCC >= 1.28 (http://www.mcst.ru/lcc);
30// - GNU C++ >= 11.3;
31// - CLANG >= 14.0;
32// - MSVC >= 19.44 (Visual Studio 2022 toolchain v143),
33// before 2026:
34// - Elbrus LCC >= 1.23 (http://www.mcst.ru/lcc);
35// - GNU C++ >= 4.8;
36// - CLANG >= 3.9;
37// - MSVC >= 14.0 (Visual Studio 2015),
38// but 19.2x could hang due optimizer bug;
39// - AppleClang, but without C++20 concepts.
40//
41
42/* Workaround for modern libstdc++ with CLANG < 4.x */
43#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4
44#define __GLIBCXX_BITSIZE_INT_N_0 128
45#define __GLIBCXX_TYPE_INT_N_0 __int128
46#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
47
48#if !defined(__cplusplus) || __cplusplus < 201103L
49#if !defined(_MSC_VER) || _MSC_VER < 1900
50#error "C++11 compiler or better is required"
51#elif _MSC_VER >= 1910
52#error "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
53#endif /* MSVC is mad and don't define __cplusplus properly */
54#endif /* __cplusplus < 201103L */
55
56#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
57#error "CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
58#endif /* Windows */
59
60#ifndef __has_include
61#define __has_include(header) (0)
62#endif /* __has_include */
63
64#if __has_include(<version>)
65#include <version>
66#endif /* <version> */
67
68/* Disable min/max macros from C' headers */
69#ifndef NOMINMAX
70#define NOMINMAX
71#endif
72
73#include <algorithm> // for std::min/max
74#include <cassert> // for assert()
75#include <climits> // for CHAR_BIT
76#include <cstring> // for std::strlen, str:memcmp
77#include <exception> // for std::exception_ptr
78#include <ostream> // for std::ostream
79#include <sstream> // for std::ostringstream
80#include <stdexcept> // for std::invalid_argument
81#include <string> // for std::string
82#include <type_traits> // for std::is_pod<>, etc.
83#include <utility> // for std::make_pair
84#include <vector> // for std::vector<> as template args
85
86#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
87#include <memory_resource>
88#endif
89
90#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
91#include <string_view>
92#endif
93
94#ifndef MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
95#ifdef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
96#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
97#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && __cplusplus >= 201703L
98#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
99#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
100 (defined(_MSC_VER) && defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && __cplusplus >= 201403L))
101#if defined(__cpp_lib_experimental_filesystem) && __cpp_lib_experimental_filesystem >= 201406L
102#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
103#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && __has_include(<experimental/filesystem>)
104#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
105#else
106#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
107#endif
108#else
109#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
110#endif
111#endif /* MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM */
112
113#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
114#include <experimental/filesystem>
115#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
116#include <filesystem>
117#endif
118
119#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
120#include <span>
121#endif
122
123#if !defined(_MSC_VER) || defined(__clang__)
124#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class API_ATTRIBUTES __VA_ARGS__
125#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class __VA_ARGS__
126#else
127#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class __VA_ARGS__
128#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class API_ATTRIBUTES __VA_ARGS__
129#endif
130
131#if defined(_MSC_VER) && _MSC_VER >= 1900
132#define MDBX_MSVC_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
133#else
134#define MDBX_MSVC_DECLSPEC_EMPTY_BASES /* nope */
135#endif /* _MSC_VER >= 1900 */
136
137#if __cplusplus >= 201103L
138#include <chrono>
139#include <ratio>
140#endif
141
142#include "mdbx.h"
143
144#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
145 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
146 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
147 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
148#include <bit>
149#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
150#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
151#define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
152#define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
153#define __BYTE_ORDER__ __BYTE_ORDER
154#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
155#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
156#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
157#define __BYTE_ORDER__ _BYTE_ORDER
158#else
159#define __ORDER_LITTLE_ENDIAN__ 1234
160#define __ORDER_BIG_ENDIAN__ 4321
161#if defined(__LITTLE_ENDIAN__) || (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || defined(__ARMEL__) || \
162 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
163 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || defined(__elbrus_4c__) || defined(__elbrus_8c__) || \
164 defined(__bfin__) || defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
165 defined(__ia64) || defined(_M_IA64) || defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
166 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || defined(__WINDOWS__)
167#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
168#elif defined(__BIG_ENDIAN__) || (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || defined(__ARMEB__) || \
169 defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
170 defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
171 defined(__sparc__) || defined(__sparc) || defined(__370__) || defined(__THW_370__) || defined(__s390__) || \
172 defined(__s390x__) || defined(__SYSC_ZARCH__)
173#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
174#endif
175#endif
176#endif /* Byte Order */
177
179#if defined(DOXYGEN)
180#define MDBX_CXX17_CONSTEXPR constexpr
181#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
182 ((defined(_MSC_VER) && _MSC_VER >= 1915) || (defined(__clang__) && __clang_major__ > 5) || \
183 (defined(__GNUC__) && __GNUC__ > 7) || (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
184#define MDBX_CXX17_CONSTEXPR constexpr
185#else
186#define MDBX_CXX17_CONSTEXPR inline
187#endif /* MDBX_CXX17_CONSTEXPR */
188
190#if defined(DOXYGEN)
191#define MDBX_CXX20_CONSTEXPR constexpr
192#elif defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L && \
193 defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
194#define MDBX_CXX20_CONSTEXPR constexpr
195#else
196#define MDBX_CXX20_CONSTEXPR inline
197#endif /* MDBX_CXX20_CONSTEXPR */
198
199#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
200#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
201#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
202#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
203#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
204#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
205#else
206#define MDBX_CXX01_CONSTEXPR_ENUM inline
207#define MDBX_CXX11_CONSTEXPR_ENUM inline
208#define MDBX_CXX14_CONSTEXPR_ENUM inline
209#define MDBX_CXX17_CONSTEXPR_ENUM inline
210#define MDBX_CXX20_CONSTEXPR_ENUM inline
211#endif /* CONSTEXPR_ENUM_FLAGS_OPERATIONS */
212
214#if defined(CONSTEXPR_ASSERT)
215#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
216#elif defined NDEBUG
217#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
218#else
219#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
220#endif /* MDBX_CONSTEXPR_ASSERT */
221
222#ifndef MDBX_LIKELY
223#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
224#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
225#else
226#define MDBX_LIKELY(x) (x)
227#endif
228#endif /* MDBX_LIKELY */
229
230#ifndef MDBX_UNLIKELY
231#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
232#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
233#else
234#define MDBX_UNLIKELY(x) (x)
235#endif
236#endif /* MDBX_UNLIKELY */
237
239#if defined(DOXYGEN)
240#define MDBX_IF_CONSTEXPR constexpr
241#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
242#define MDBX_IF_CONSTEXPR constexpr
243#else
244#define MDBX_IF_CONSTEXPR
245#endif /* MDBX_IF_CONSTEXPR */
246
247#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
248 __cplusplus >= 201703L
249#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
250#else
251#define MDBX_CXX17_FALLTHROUGH
252#endif /* MDBX_CXX17_FALLTHROUGH */
253
254#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
255#define MDBX_CXX20_LIKELY [[likely]]
256#else
257#define MDBX_CXX20_LIKELY
258#endif /* MDBX_CXX20_LIKELY */
259
260#ifndef MDBX_CXX20_UNLIKELY
261#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
262#define MDBX_CXX20_UNLIKELY [[unlikely]]
263#else
264#define MDBX_CXX20_UNLIKELY
265#endif
266#endif /* MDBX_CXX20_UNLIKELY */
267
268#ifndef MDBX_HAVE_CXX20_CONCEPTS
269#if defined(__cpp_concepts) && __cpp_concepts >= 202002L && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
270#include <concepts>
271#define MDBX_HAVE_CXX20_CONCEPTS 1
272#elif defined(DOXYGEN)
273#define MDBX_HAVE_CXX20_CONCEPTS 1
274#else
275#define MDBX_HAVE_CXX20_CONCEPTS 0
276#endif /* <concepts> */
277#endif /* MDBX_HAVE_CXX20_CONCEPTS */
278
279#ifndef MDBX_CXX20_CONCEPT
280#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
281#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
282#else
283#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
284#endif
285#endif /* MDBX_CXX20_CONCEPT */
286
287#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
288#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
289#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
290#else
291#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
292 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
293#endif
294#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
295
296#ifdef _MSC_VER
297#pragma warning(push, 4)
298#pragma warning(disable : 4127) /* conditional expression is constant */
299#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
300 be used by clients of 'mdbx::BAR' */
301#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
302 base for dll-interface 'mdbx::BAR' */
303/* MSVC is mad and can generate this warning for its own intermediate
304 * automatically generated code, which becomes unreachable after some kinds of
305 * optimization (copy elision, etc). */
306#pragma warning(disable : 4702) /* unreachable code */
307#endif /* _MSC_VER (warnings) */
308
309#if defined(__LCC__) && __LCC__ >= 126
310#pragma diagnostic push
311#if __LCC__ < 127
312#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
313 appearing in a constant expression `true` */
314#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
315 appearing in a constant expression `false` */
316#endif
317#endif /* E2K LCC (warnings) */
318
319//------------------------------------------------------------------------------
322namespace mdbx {
323
326
344#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
345using byte = char8_t;
346#else
347// Avoid `std::byte` since it doesn't add features but inconvenient restrictions.
348using byte = unsigned char;
349#endif /* __cpp_char8_t >= 201811*/
350
351#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
352using endian = ::std::endian;
353#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
354enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
355#else
356#error "Please use a C++ compiler provides byte order information or C++20 support"
357#endif /* Byte Order enum */
358
367
369static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
370
372static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
374static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
375
378using legacy_allocator = ::std::string::allocator_type;
379
382#if defined(DOXYGEN)
383#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
384#elif !defined(MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR)
385#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && \
386 (!defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI)
387#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
388#else
389#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 0
390#endif
391#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
392
393#if defined(DOXYGEN) || MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
395using polymorphic_allocator = ::std::pmr::string::allocator_type;
397#else
399#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
400
401struct slice;
403template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
405class env;
406class env_managed;
407class txn;
408class txn_managed;
409class cursor;
410class cursor_managed;
411
413using txnid = uint64_t;
414
416template <class ALLOCATOR = default_allocator>
417using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
418
420#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
421#ifdef _MSC_VER
422namespace filesystem = ::std::experimental::filesystem::v1;
423#else
424namespace filesystem = ::std::experimental::filesystem;
425#endif
426#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
427#elif defined(DOXYGEN) || \
428 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
429 __cpp_lib_string_view >= 201606L && \
430 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
431 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
432 (!defined(_MSC_VER) || __cplusplus >= 201703L)
433namespace filesystem = ::std::filesystem;
439#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
440#endif /* MDBX_STD_FILESYSTEM_PATH */
441
442#ifdef MDBX_STD_FILESYSTEM_PATH
444#elif defined(_WIN32) || defined(_WIN64)
445using path = ::std::wstring;
446#else
447using path = ::std::string;
448#endif /* mdbx::path */
449
450#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
451#ifndef MDBX_U128_TYPE
452#define MDBX_U128_TYPE __uint128_t
453#endif /* MDBX_U128_TYPE */
454#ifndef MDBX_I128_TYPE
455#define MDBX_I128_TYPE __int128_t
456#endif /* MDBX_I128_TYPE */
457#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
458
459#if __cplusplus >= 201103L || defined(DOXYGEN)
461using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
462#endif /* Duration for C++11 */
463
466
472 ::std::exception_ptr captured_;
473
474public:
475 exception_thunk() noexcept = default;
478 exception_thunk &operator=(const exception_thunk &) = delete;
479 exception_thunk &operator=(exception_thunk &&) = delete;
480 inline bool is_clean() const noexcept;
481 inline void capture() noexcept;
482 inline void rethrow_captured() const;
483};
484
487 MDBX_error_t code_;
488 inline error &operator=(MDBX_error_t error_code) noexcept;
489
490public:
491 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
492 error(const error &) = default;
493 error(error &&) = default;
494 error &operator=(const error &) = default;
495 error &operator=(error &&) = default;
496
497 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
498 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
499
500 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
501 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
502 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
503 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
504
506 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
507
509 const char *what() const noexcept;
510
512 ::std::string message() const;
513
515 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
517 [[noreturn]] void panic(const char *context_where_when, const char *func_who_what) const noexcept;
518 [[noreturn]] void throw_exception() const;
519 [[noreturn]] static inline void throw_exception(int error_code);
520 inline void throw_on_failure() const;
521 inline void success_or_throw() const;
522 inline void success_or_throw(const exception_thunk &) const;
523 inline void panic_on_failure(const char *context_where, const char *func_who) const noexcept;
524 inline void success_or_panic(const char *context_where, const char *func_who) const noexcept;
525 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
526 static inline void success_or_throw(MDBX_error_t error_code);
527 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
528 static inline void throw_on_failure(int error_code);
529 static inline bool boolean_or_throw(int error_code);
530 static inline void success_or_throw(int error_code, const exception_thunk &);
531 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
532 static inline void panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept;
533 static inline void success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept;
534};
535
538class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
539 using base = ::std::runtime_error;
540 ::mdbx::error error_;
541
542public:
543 exception(const ::mdbx::error &) noexcept;
544 exception(const exception &) = default;
545 exception(exception &&) = default;
546 exception &operator=(const exception &) = default;
548 virtual ~exception() noexcept;
549 const ::mdbx::error error() const noexcept { return error_; }
550};
551
554 using base = exception;
555
556public:
557 fatal(const ::mdbx::error &) noexcept;
558 fatal(const exception &src) noexcept : fatal(src.error()) {}
559 fatal(exception &&src) noexcept : fatal(src.error()) {}
560 fatal(const fatal &src) noexcept : fatal(src.error()) {}
561 fatal(fatal &&src) noexcept : fatal(src.error()) {}
562 fatal &operator=(fatal &&) = default;
563 fatal &operator=(const fatal &) = default;
564 virtual ~fatal() noexcept;
565};
566
567#define MDBX_DECLARE_EXCEPTION(NAME) \
568 struct LIBMDBX_API_TYPE NAME : public exception { \
569 NAME(const ::mdbx::error &); \
570 virtual ~NAME() noexcept; \
571 }
604#undef MDBX_DECLARE_EXCEPTION
605
608[[noreturn]] LIBMDBX_API void throw_out_range();
612
613static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
614 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
615 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
616 return bytes;
617}
618
619static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
620 return check_length(check_length(headroom) + check_length(payload));
621}
622
623MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
624 return check_length(check_length(headroom, payload) + check_length(tailroom));
625}
626
628
629//------------------------------------------------------------------------------
630
633
645
646 enum : size_t { max_length = MDBX_MAXDATASIZE };
647
649 MDBX_CXX11_CONSTEXPR slice() noexcept;
650
652 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
653
655 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
656
658 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
659 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
660 }
661
662 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
663
666 template <class CHAR, class T, class A>
667 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
668 : slice(str.data(), str.length() * sizeof(CHAR)) {}
669
671 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
673 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
674
675#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
676 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
677 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
678 "Must be a standard layout type!");
679 }
680
681 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
682 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
683 "Must be a standard layout type!");
684 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
686 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
688 }
689
690 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
691 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
692 "Must be a standard layout type!");
693 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
695 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
697 }
698
699 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
700 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
701 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
702 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
703#endif /* __cpp_lib_span >= 202002L */
704
705#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
707 template <class CHAR, class T>
708 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv) : slice(sv.data(), sv.data() + sv.length()) {}
709
710 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
711#endif /* __cpp_lib_string_view >= 201606L */
712
713 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
714
715 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
716 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
717 "Must be a standard layout type!");
718 return slice(&pod, sizeof(pod));
719 }
720
721 inline slice &assign(const void *ptr, size_t bytes);
722 inline slice &assign(const slice &src) noexcept;
723 inline slice &assign(const ::MDBX_val &src);
724 inline slice &assign(slice &&src) noexcept;
725 inline slice &assign(::MDBX_val &&src);
726 inline slice &assign(const void *begin, const void *end);
727 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
728 return assign(str.data(), str.length() * sizeof(CHAR));
729 }
730 inline slice &assign(const char *c_str);
731#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
732 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
733 return assign(view.begin(), view.end());
734 }
735 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
736 assign(view);
737 view = {};
738 return *this;
739 }
740#endif /* __cpp_lib_string_view >= 201606L */
741
742 slice &operator=(const slice &) noexcept = default;
743 inline slice &operator=(slice &&src) noexcept;
744 inline slice &operator=(::MDBX_val &&src);
745 operator MDBX_val *() noexcept { return this; }
746 operator const MDBX_val *() const noexcept { return this; }
747
748#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
749 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
750 return assign(view);
751 }
752
753 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
754
756 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
757 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
758 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
759 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
760 }
761
763 template <class CHAR, class T>
764 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
765 return this->string_view<CHAR, T>();
766 }
767#endif /* __cpp_lib_string_view >= 201606L */
768
769 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
770 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
771 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
772 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
773 }
774
775 template <class CHAR, class T, class ALLOCATOR>
776 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
778 }
779
781 template <class ALLOCATOR = default_allocator>
782 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
783 const ALLOCATOR &alloc = ALLOCATOR()) const;
784
787 template <class ALLOCATOR = default_allocator>
788 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
789
792 template <class ALLOCATOR = default_allocator>
793 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
794
796 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
797 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
798 const ALLOCATOR &alloc = ALLOCATOR()) const;
799
802 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
803 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
804 const ALLOCATOR &alloc = ALLOCATOR()) const;
805
808 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
809 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
810 const ALLOCATOR &alloc = ALLOCATOR()) const;
811
813 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
814 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
815 const ALLOCATOR &alloc = ALLOCATOR()) const;
816
819 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
820 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
821 const ALLOCATOR &alloc = ALLOCATOR()) const;
822
825 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
826 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
827 const ALLOCATOR &alloc = ALLOCATOR()) const;
828
834 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
835
840 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
841
847 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
848
854 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
855
856#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
857 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
858 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
859 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
860 *this = view;
861 view = temp;
862 }
863#endif /* __cpp_lib_string_view >= 201606L */
864
866 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
867 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
868
870 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
871 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
872
874 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
875 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
876
878 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
879 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
880
882 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
883 MDBX_CXX11_CONSTEXPR void *data() noexcept;
884
886 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
887 MDBX_CXX11_CONSTEXPR void *end() noexcept;
888
890 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
891
893 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
894
896 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
897
899 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
900
902 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
903
905 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
906
908 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
909
911 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
912
914 MDBX_CXX14_CONSTEXPR void clear() noexcept;
915
918 inline void remove_prefix(size_t n) noexcept;
919
922 inline void remove_suffix(size_t n) noexcept;
923
926 inline void safe_remove_prefix(size_t n);
927
930 inline void safe_remove_suffix(size_t n);
931
933 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
934
936 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
937
940 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
941
944 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
945
948 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
949
952 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
953
956 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
957
960 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
961
964 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
965
968 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
969
974 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
975
984 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
985
991 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
992 const slice &b) noexcept;
993 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
994 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
995 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
996 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
997 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
998 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
999#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1000 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
1001#endif /* __cpp_impl_three_way_comparison */
1002
1004 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1005
1008 return slice(/* using special constructor without length checking */ ~size_t(0));
1009 }
1010
1012 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1013
1014 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1015 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1016 "Must be a standard layout type!");
1017 if (MDBX_LIKELY(size() == sizeof(POD)))
1019 POD r;
1020 memcpy(&r, data(), sizeof(r));
1021 return r;
1022 }
1024 }
1025
1026#ifdef MDBX_U128_TYPE
1027 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1028#endif /* MDBX_U128_TYPE */
1029 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1030 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1031 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1032 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1033
1034#ifdef MDBX_I128_TYPE
1035 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1036#endif /* MDBX_I128_TYPE */
1037 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1038 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1039 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1040 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1041
1042#ifdef MDBX_U128_TYPE
1043 MDBX_U128_TYPE as_uint128_adapt() const;
1044#endif /* MDBX_U128_TYPE */
1045 uint64_t as_uint64_adapt() const;
1046 uint32_t as_uint32_adapt() const;
1047 uint16_t as_uint16_adapt() const;
1048 uint8_t as_uint8_adapt() const;
1049
1050#ifdef MDBX_I128_TYPE
1051 MDBX_I128_TYPE as_int128_adapt() const;
1052#endif /* MDBX_I128_TYPE */
1053 int64_t as_int64_adapt() const;
1054 int32_t as_int32_adapt() const;
1055 int16_t as_int16_adapt() const;
1056 int8_t as_int8_adapt() const;
1057
1058protected:
1059 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1060};
1061
1065 bool done;
1066 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
1067 value_result(const value_result &) noexcept = default;
1068 value_result &operator=(const value_result &) noexcept = default;
1069 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1070 assert(!done || bool(value));
1071 return done;
1072 }
1073};
1074
1076struct pair {
1077 using stl_pair = std::pair<slice, slice>;
1079 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
1080 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
1081 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
1082 pair(const pair &) noexcept = default;
1083 pair &operator=(const pair &) noexcept = default;
1084 pair &operator=(pair &&couple) {
1085 key.assign(std::move(couple.key));
1086 value.assign(std::move(couple.value));
1087 return *this;
1088 }
1089 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1090 assert(bool(key) == bool(value));
1091 return key;
1092 }
1094
1095 pair &operator=(const stl_pair &couple) {
1096 key.assign(couple.first);
1097 value.assign(couple.second);
1098 return *this;
1099 }
1101 key.assign(std::move(couple.first));
1102 value.assign(std::move(couple.second));
1103 return *this;
1104 }
1105
1107 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
1108
1110 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
1111 const pair &b) noexcept;
1112 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
1113 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
1114 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
1115 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
1116 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
1117 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
1118#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1119 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
1120#endif /* __cpp_impl_three_way_comparison */
1121};
1122
1125struct pair_result : public pair {
1126 bool done;
1129 : pair(key, value), done(done) {}
1130 pair_result(const pair_result &) noexcept = default;
1131 pair_result &operator=(const pair_result &) noexcept = default;
1132 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1133 assert(!done || (bool(key) && bool(value)));
1134 return done;
1135 }
1136};
1137
1138#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
1139
1143template <typename T>
1144concept MutableByteProducer = requires(T a, char array[42]) {
1145 { a.is_empty() } -> std::same_as<bool>;
1146 { a.envisage_result_length() } -> std::same_as<size_t>;
1147 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1148};
1149
1153template <typename T>
1154concept ImmutableByteProducer = requires(const T &a, char array[42]) {
1155 { a.is_empty() } -> std::same_as<bool>;
1156 { a.envisage_result_length() } -> std::same_as<size_t>;
1157 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1158};
1159
1163template <typename T>
1164concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
1165 T(source);
1166 { a.is_erroneous() } -> std::same_as<bool>;
1167};
1168
1169#endif /* MDBX_HAVE_CXX20_CONCEPTS */
1170
1174 const bool uppercase = false;
1175 const unsigned wrap_width = 0;
1180
1182 template <class ALLOCATOR = default_allocator>
1183 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1184
1186 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1187 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1188
1192 const size_t bytes = source.length() << 1;
1193 return wrap_width ? bytes + bytes / wrap_width : bytes;
1194 }
1195
1198 char *write_bytes(char *dest, size_t dest_size) const;
1199
1202 ::std::ostream &output(::std::ostream &out) const;
1203
1206 bool is_empty() const noexcept { return source.empty(); }
1207
1210 bool is_erroneous() const noexcept { return false; }
1211};
1212
1217 const unsigned wrap_width = 0;
1222
1225 template <class ALLOCATOR = default_allocator>
1226 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1227
1230 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1231 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1232
1236 const size_t bytes = (source.length() * 11 + 7) / 8;
1237 return wrap_width ? bytes + bytes / wrap_width : bytes;
1238 }
1239
1242 char *write_bytes(char *dest, size_t dest_size) const;
1243
1246 ::std::ostream &output(::std::ostream &out) const;
1247
1249 bool is_empty() const noexcept { return source.empty(); }
1250
1252 bool is_erroneous() const noexcept { return false; }
1253};
1254
1259 const unsigned wrap_width = 0;
1264
1267 template <class ALLOCATOR = default_allocator>
1268 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1269
1272 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1273 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1274
1278 const size_t bytes = (source.length() + 2) / 3 * 4;
1279 return wrap_width ? bytes + bytes / wrap_width : bytes;
1280 }
1281
1285 char *write_bytes(char *dest, size_t dest_size) const;
1286
1290 ::std::ostream &output(::std::ostream &out) const;
1291
1294 bool is_empty() const noexcept { return source.empty(); }
1295
1298 bool is_erroneous() const noexcept { return false; }
1299};
1300
1304 const bool ignore_spaces = false;
1309
1311 template <class ALLOCATOR = default_allocator>
1312 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1313
1315 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1316 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1317
1320 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1321
1324 char *write_bytes(char *dest, size_t dest_size) const;
1325
1327 bool is_empty() const noexcept { return source.empty(); }
1328
1331 bool is_erroneous() const noexcept;
1332};
1333
1338 const bool ignore_spaces = false;
1343
1346 template <class ALLOCATOR = default_allocator>
1347 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1348
1351 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1352 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1353
1357 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1358 }
1359
1363 char *write_bytes(char *dest, size_t dest_size) const;
1364
1366 bool is_empty() const noexcept { return source.empty(); }
1367
1370 bool is_erroneous() const noexcept;
1371};
1372
1377 const bool ignore_spaces = false;
1382
1385 template <class ALLOCATOR = default_allocator>
1386 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1387
1390 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1391 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1392
1395 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1396
1400 char *write_bytes(char *dest, size_t dest_size) const;
1401
1404 bool is_empty() const noexcept { return source.empty(); }
1405
1409 bool is_erroneous() const noexcept;
1410};
1411
1413
1414template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1415#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1416 return ::std::allocator_traits<A>::is_always_equal::value;
1417#else
1418 return ::std::is_empty<A>::value;
1419#endif /* __cpp_lib_allocator_traits_is_always_equal */
1420}
1421
1422template <typename T, typename A = typename T::allocator_type,
1423 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1425
1426template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1427 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1428 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1429 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1430 }
1431 static MDBX_CXX20_CONSTEXPR void propagate(T *, T &) noexcept {}
1432};
1433
1434template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1435 static constexpr bool is_nothrow() noexcept {
1436 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1437 }
1438 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1439 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1440 target->get_allocator() = ::std::move(source.get_allocator());
1441 }
1442};
1443
1444template <typename T, typename A = typename T::allocator_type,
1445 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1447
1448template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1449 static constexpr bool is_nothrow() noexcept { return false; }
1450 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1451};
1452
1453template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1454 static constexpr bool is_nothrow() noexcept {
1455 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1456 }
1457 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1458 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1459 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1460 MDBX_CXX20_UNLIKELY target->get_allocator() =
1461 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1462 } else {
1463 /* gag for buggy compilers */
1464 (void)target;
1465 (void)source;
1466 }
1467 }
1468};
1469
1470template <typename T, typename A = typename T::allocator_type,
1471 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1473
1474template <typename T, typename A> struct swap_alloc<T, A, false> {
1475 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1476 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1478 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1479 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1480 } else {
1481 /* gag for buggy compilers */
1482 (void)left;
1483 (void)right;
1484 }
1485 }
1486};
1487
1488template <typename T, typename A> struct swap_alloc<T, A, true> {
1489 static constexpr bool is_nothrow() noexcept {
1490 return allocator_is_always_equal<A>() ||
1491#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1492 ::std::is_nothrow_swappable<A>() ||
1493#endif /* __cpp_lib_is_swappable >= 201603L */
1494 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1495 }
1496 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1497 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1498 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1499 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1500 } else {
1501 /* gag for buggy compilers */
1502 (void)left;
1503 (void)right;
1504 }
1505 }
1506};
1507
1508} // namespace allocation_aware_details
1509
1511 enum : size_t {
1516 };
1517
1518 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1519 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1520 static_assert(pettiness_threshold % 2 == 0, "pettiness_threshold must be even");
1521 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1522 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1523 return (value + pettiness_threshold - 1) & pettiness_mask;
1524 }
1525
1526 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1527 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1528 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1529
1530 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1531 return inplace;
1532
1533 if (wanna > current)
1534 /* doubling capacity, but don't made reserve more than max_reserve */
1535 return round(wanna + ::std::min(size_t(max_reserve), current));
1536
1537 if (current - wanna >
1538 /* shrink if reserve will more than half of current or max_reserve,
1539 * but not less than pettiness_threshold */
1540 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1541 return round(wanna);
1542
1543 /* keep unchanged */
1544 return current;
1545 }
1546};
1547
1549struct buffer_tag {};
1550
1552template <class ALLOCATOR, typename CAPACITY_POLICY>
1554public:
1556#if !defined(_MSC_VER) || _MSC_VER > 1900
1557 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1558#else
1559 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1560#endif /* MSVC is mad */
1561 using allocator_traits = ::std::allocator_traits<allocator_type>;
1562 using reservation_policy = CAPACITY_POLICY;
1563 enum : size_t {
1565 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1568 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1569 ? alignof(max_align_t) * 2
1572 };
1573
1574private:
1575 friend class txn;
1576 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1577 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1578 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1579
1580 using allocator_pointer = typename allocator_traits::pointer;
1581 using allocator_const_pointer = typename allocator_traits::const_pointer;
1582
1583 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1584 assert(bytes >= sizeof(bin));
1585 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1586 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1587 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1588 const size_t n = (bytes + unit - 1) / unit;
1589 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1590 }
1591
1592 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1593 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1594 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1595 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1596 }
1597
1598 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1599 const size_t capacity = bin::advise_capacity(0, bytes);
1600 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1601 : allocate_storage(capacity);
1602 }
1603
1604 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1605#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1606 return static_cast<void *>(::std::to_address(ptr));
1607#else
1608 return static_cast<void *>(::std::addressof(*ptr));
1609#endif /* __cpp_lib_to_address */
1610 }
1611
1612 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1613#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1614 return static_cast<const void *>(::std::to_address(ptr));
1615#else
1616 return static_cast<const void *>(::std::addressof(*ptr));
1617#endif /* __cpp_lib_to_address */
1618 }
1619
1620#ifdef _MSC_VER
1621#pragma warning(push)
1622#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1623#endif /* _MSC_VER */
1624
1625 union alignas(max_align_t) bin {
1626 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1627 с учетом выравнивания */
1628 {
1629 allocator_pointer stub_ptr_;
1631 };
1632
1634 enum : size_t {
1636 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1640 };
1641
1643 byte pad_[inplace_size - sizeof(allocator_pointer)];
1644 size_t bytes_;
1645 };
1646
1648 byte buffer_[inplace_size - sizeof(byte)];
1650 MDBX_CXX11_CONSTEXPR inplace_flag_holder(byte signature) : lastbyte_(signature) {};
1651 };
1652
1653 allocator_pointer allocated_ptr_;
1656
1657 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1658 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1659 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1660 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1661 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1662 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1663 return capacity_bytes <= inplace_capacity();
1664 }
1665
1666 constexpr bool is_inplace() const noexcept {
1667 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1668 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1670 "WTF?");
1671 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1672 }
1673 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1674
1675 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1676 if (destroy_ptr) {
1678 /* properly destroy allocator::pointer */
1679 allocated_ptr_.~allocator_pointer();
1680 }
1683 return address();
1684 }
1685
1686 template <bool construct_ptr>
1687 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1689 if (construct_ptr) {
1691 new (&allocated_ptr_) allocator_pointer(pair.first);
1692 } else {
1694 allocated_ptr_ = pair.first;
1695 }
1696 capacity_.bytes_ = pair.second;
1697 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1698 return address();
1699 }
1700
1702 if (::std::is_trivial<allocator_pointer>::value)
1703 /* workaround for "uninitialized" warning from some compilers */
1704 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1705 }
1706
1707 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1708 if (MDBX_UNLIKELY(wanna > max_capacity))
1709 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1710
1711 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1712 assert(advised >= wanna);
1713 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1714 }
1715
1716 constexpr bool is_inplace(const void *ptr) const noexcept {
1717 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1718 }
1719
1720 constexpr const byte *address() const noexcept {
1721 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1722 }
1724 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1725 }
1726 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1727 } bin_;
1728
1729#ifdef _MSC_VER
1730#pragma warning(pop)
1731#endif /* _MSC_VER */
1732
1733 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1734
1735 MDBX_CXX20_CONSTEXPR void release() noexcept {
1736 if (bin_.is_allocated()) {
1737 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1738 /* properly destroy allocator::pointer */
1739 bin_.allocated_ptr_.~allocator_pointer();
1740 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1741 }
1742 }
1743
1744 template <bool external_content>
1745 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1746 const void *const content, const size_t length) {
1747 assert(wanna_capacity >= wanna_headroom + length);
1748 const size_t old_capacity = bin_.capacity();
1749 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1750 if (MDBX_LIKELY(new_capacity == old_capacity))
1752 assert(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1753 byte *const new_place = bin_.address() + wanna_headroom;
1754 if (MDBX_LIKELY(length))
1756 if (external_content)
1757 memcpy(new_place, content, length);
1758 else {
1759 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1760 assert(old_capacity >= old_headroom + length);
1761 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1762 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1763 }
1764 }
1765 return new_place;
1766 }
1767
1768 if (bin::is_suitable_for_inplace(new_capacity)) {
1769 assert(bin_.is_allocated());
1770 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1771 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1772 if (MDBX_LIKELY(length))
1773 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1774 deallocate_storage(old_allocated, old_capacity);
1775 return new_place;
1776 }
1777
1778 if (bin_.is_inplace()) {
1779 const auto pair = allocate_storage(new_capacity);
1780 assert(pair.second >= new_capacity);
1781 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1782 if (MDBX_LIKELY(length))
1783 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1784 bin_.template make_allocated<true>(pair);
1785 return new_place;
1786 }
1787
1788 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1789 if (external_content)
1790 deallocate_storage(old_allocated, old_capacity);
1791 const auto pair = allocate_storage(new_capacity);
1792 assert(pair.second >= new_capacity);
1793 byte *const new_place = bin_.template make_allocated<false>(pair) + wanna_headroom;
1794 if (MDBX_LIKELY(length))
1795 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1796 if (!external_content)
1797 deallocate_storage(old_allocated, old_capacity);
1798 return new_place;
1799 }
1800
1801 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1802 assert(capacity() >= offset);
1803 return bin_.address() + offset;
1804 }
1805 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1806 assert(capacity() >= offset);
1807 return bin_.address() + offset;
1808 }
1809 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1810 assert(capacity() >= offset + length);
1811 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1812 }
1813
1814 //--------------------------------------------------------------------------
1815
1816 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1817 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1818 if (!bin::is_suitable_for_inplace(capacity))
1819 bin_.template make_allocated<true>(provide_storage(capacity));
1820 }
1821
1822 silo(silo &&other) = delete;
1824 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1825 : allocator_type(::std::move(other.get_allocator())) {
1826 if (!is_reference) {
1827 if (other.bin_.is_inplace()) {
1828 memcpy(&bin_, &other.bin_, sizeof(bin));
1829 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1830 } else {
1831 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1832 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1833 /* properly destroy allocator::pointer.
1834 *
1835 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1836 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1837 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1838 * from the 11th). */
1839 /* coverity[use_after_move] */
1840 other.bin_.allocated_ptr_.~allocator_pointer();
1841 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1842 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1843 }
1844 }
1845 }
1846
1847 MDBX_CXX17_CONSTEXPR bool move(silo &&other) noexcept {
1848 if (other.bin_.is_inplace()) {
1849 memcpy(&bin_, &other.bin_, sizeof(bin));
1850 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1851 return /* buffer's slice fixup is needed */ true;
1852 }
1853 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1854 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1855 /* properly destroy allocator::pointer.
1856 *
1857 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1858 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1859 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1860 * from the 11th). */
1861 /* coverity[use_after_move] */
1862 other.bin_.allocated_ptr_.~allocator_pointer();
1863 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1864 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1865 return false;
1866 }
1867
1868 MDBX_CXX17_CONSTEXPR bool assign_move(silo &&other, bool is_reference) noexcept {
1869 release();
1870 if (!allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, other))
1871 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, other);
1872 return is_reference ? false : move(std::move(other));
1873 }
1874
1875 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1876 exchange(silo &left, const bool left_is_reference, silo &right, const bool right_is_reference) noexcept(
1877 allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1878 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(left, right);
1879 bool left_need_fixup = false, right_need_fixup = false;
1880 if (left_is_reference || right_is_reference) {
1881 left_need_fixup = !right_is_reference && left.move(std::move(right));
1882 right_need_fixup = !left_is_reference && right.move(std::move(left));
1883 } else {
1884 silo temp(std::move(left), false);
1885 left_need_fixup = left.move(std::move(right));
1886 right_need_fixup = right.move(std::move(temp));
1887 }
1888 return std::make_pair(left_need_fixup, right_need_fixup);
1889 }
1890
1891 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1892 const allocator_type &alloc = allocator_type())
1893 : silo(capacity, alloc) {
1894 assert(capacity >= headroom + length);
1895 if (length)
1896 put(headroom, ptr, length);
1897 }
1898
1899 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1900 : silo(length, 0, ptr, length, alloc) {}
1901
1902 ~silo() { release(); }
1903
1904 //--------------------------------------------------------------------------
1905
1906 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1907 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1908 }
1909
1910 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1911
1912 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1913 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1914 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1915 }
1916
1917 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1918 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1919 }
1920
1921 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1922 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1923 return get(offset);
1924 }
1925 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1926 };
1927
1928 MDBX_CXX14_CONSTEXPR void fixup_import(const typename silo::bin &src) noexcept {
1929 auto ptr = inherited::byte_ptr();
1930 if (src.is_inplace(ptr)) {
1931 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1932 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1933 iov_base = ptr + offset;
1934 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1935 }
1936 }
1937
1938 silo silo_;
1939
1940 void insulate() {
1941 assert(is_reference());
1942 iov_base = silo_.assign(iov_base, iov_len);
1943 }
1944
1945 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1946 return static_cast<const byte *>(silo_.data());
1947 }
1948
1949 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1950 return silo_begin() + silo_.capacity();
1951 }
1952
1953 struct data_preserver : public exception_thunk {
1954 buffer data;
1955 data_preserver(allocator_type &alloc) : data(alloc) {}
1956 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1957 auto self = static_cast<data_preserver *>(context);
1958 assert(self->is_clean());
1959 assert(&self->data == target);
1960 (void)target;
1961 try {
1962 self->data.assign(src, bytes, false);
1963 return MDBX_RESULT_FALSE;
1964 } catch (... /* capture any exception to rethrow it over C code */) {
1965 self->capture();
1966 return MDBX_RESULT_TRUE;
1967 }
1968 }
1969 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1970 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1971 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1972 };
1973
1974public:
1977
1981
1982 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1983
1985 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1986
1990 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1991 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1992 }
1993
1998 return silo_.is_inplace(inherited::data());
1999 }
2000
2004
2007 return is_freestanding() ? silo_.capacity() : 0;
2008 }
2009
2013 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
2014 }
2015
2019 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2020 }
2021
2023 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2024
2026 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2027
2034
2039 return const_cast<byte *>(inherited::end_byte_ptr());
2040 }
2041
2043 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2044
2046 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2047
2052 return const_cast<char *>(inherited::char_ptr());
2053 }
2054
2059 return const_cast<char *>(inherited::end_char_ptr());
2060 }
2061
2063 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
2064
2066 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
2067
2070 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2072 return const_cast<void *>(inherited::data());
2073 }
2074
2077 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2079 return const_cast<void *>(inherited::end());
2080 }
2081
2086
2093
2096 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2097 return set_length(static_cast<const char *>(ptr) - char_ptr());
2098 }
2099
2104 if (is_reference())
2105 insulate();
2106 }
2107
2108 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2109 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2110 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2111 const allocator_type &alloc = allocator_type());
2112
2114 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2115 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2116
2117 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2118 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2119
2120 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2121 : buffer(inherited(c_str), make_reference, alloc) {}
2122
2123#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2124 template <class CHAR, class T>
2125 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2126 const allocator_type &alloc = allocator_type())
2127 : buffer(inherited(view), make_reference, alloc) {}
2128#endif /* __cpp_lib_string_view >= 201606L */
2129
2131 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2132 : buffer(src, src.empty() || src.is_null(), alloc) {}
2133
2135 buffer(const buffer &src)
2136 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2137
2139 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2140 : buffer(inherited(ptr, bytes), alloc) {}
2141
2142 template <class CHAR, class T, class A>
2143 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2144 const allocator_type &alloc = allocator_type())
2145 : buffer(inherited(str), alloc) {}
2146
2148 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2149
2150#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2151 template <class CHAR, class T>
2152 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2153 const allocator_type &alloc = allocator_type())
2154 : buffer(inherited(view), alloc) {}
2155#endif /* __cpp_lib_string_view >= 201606L */
2156
2157 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2158 : silo_(check_length(head_room, tail_room), alloc) {
2159 iov_base = silo_.get();
2160 assert(iov_len == 0);
2161 }
2162
2163 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2164 iov_base = silo_.get();
2165 assert(iov_len == 0);
2166 }
2167
2168 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2169 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2170 iov_base = memcpy(silo_.get(), src.data(), iov_len = src.length());
2171 }
2172
2173 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2174
2175 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2176 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2177 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2178 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2179 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2180 * 11th). */
2181 /* coverity[use_after_move] */
2182 fixup_import(src.silo_.bin_);
2183 src.invalidate();
2184 }
2185
2187 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2188
2191
2192 template <typename POD>
2193 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2194 return buffer(inherited::wrap(pod), make_reference, alloc);
2195 }
2196
2198 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2199 const allocator_type &alloc = allocator_type()) {
2200 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2201 }
2202
2205 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2206 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2207 }
2208
2210 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2211 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2212 }
2213
2215 template <typename POD>
2216 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2217 const allocator_type &alloc = allocator_type()) {
2218 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2219 }
2220
2223 template <typename POD>
2224 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2225 return base58(inherited::wrap(pod), wrap_width, alloc);
2226 }
2227
2230 template <typename POD>
2231 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2232 return base64(inherited::wrap(pod), wrap_width, alloc);
2233 }
2234
2236 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2237 const allocator_type &alloc = allocator_type()) const {
2238 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2239 }
2240
2243 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2244 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2245 }
2246
2248 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2249 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2250 }
2251
2253 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2254 const allocator_type &alloc = allocator_type()) {
2255 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2256 }
2257
2260 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2261 const allocator_type &alloc = allocator_type()) {
2262 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2263 }
2264
2267 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2268 const allocator_type &alloc = allocator_type()) {
2269 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2270 }
2271
2274 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2275 return hex_decode(*this, ignore_spaces, alloc);
2276 }
2277
2280 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2281 return base58_decode(*this, ignore_spaces, alloc);
2282 }
2283
2286 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2287 return base64_decode(*this, ignore_spaces, alloc);
2288 }
2289
2291 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2292 wanna_headroom = ::std::min(
2293 ::std::max(headroom(), wanna_headroom),
2294 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2295 wanna_tailroom = ::std::min(
2296 ::std::max(tailroom(), wanna_tailroom),
2297 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2298 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2299 silo_.resize(wanna_capacity, wanna_headroom, *this);
2300 assert(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2301 assert(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2302 }
2303
2305 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2306
2308 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2309
2310 buffer &assign_reference(const void *ptr, size_t bytes) {
2311 silo_.clear();
2313 return *this;
2314 }
2315
2316 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2317 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2318 return *this;
2319 }
2320
2321 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2322 const auto pair = silo::exchange(silo_, is_reference(), other.silo_, other.is_reference());
2323 std::swap(iov_base, other.iov_base);
2324 std::swap(iov_len, other.iov_len);
2325 if (pair.first)
2326 fixup_import(other.silo_.bin_);
2327 if (pair.second)
2328 other.fixup_import(silo_.bin_);
2329 }
2330
2331 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2332 left.swap(right);
2333 }
2334
2335 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2336 return buffer(src.headroom(), src, src.tailroom(), alloc);
2337 }
2338
2340 return buffer(slice(), !is_inplace(), allocator_traits::select_on_container_copy_construction(get_allocator()));
2341 }
2342
2344 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2345 invalidate();
2346 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2347 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2348 MDBX_CXX20_UNLIKELY {
2349 silo_.release();
2351 }
2352 }
2353
2354 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2355 iov_len = src.length();
2356 return *this;
2357 }
2358
2359 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2360 invalidate();
2361 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2362 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2363 MDBX_CXX20_UNLIKELY {
2364 silo_.release();
2366 }
2367 }
2368
2369 if (make_reference) {
2370 silo_.release();
2371 iov_base = src.iov_base;
2372 } else {
2373 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2374 }
2375 iov_len = src.length();
2376 return *this;
2377 }
2378
2381 const bool is_reference = src.is_reference();
2382 inherited::assign(std::move(src));
2383 if (silo_.assign_move(std::move(src.silo_), is_reference))
2384 fixup_import(src.silo_.bin_);
2385 return *this;
2386 }
2387
2388 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2389 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2390 }
2391
2392 buffer &assign(const struct slice &src, bool make_reference = false) {
2393 return assign(src.data(), src.length(), make_reference);
2394 }
2395
2396 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2397 return assign(src.iov_base, src.iov_len, make_reference);
2398 }
2399
2400 buffer &assign(struct slice &&src, bool make_reference = false) {
2401 assign(src.data(), src.length(), make_reference);
2402 src.invalidate();
2403 return *this;
2404 }
2405
2406 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2407 assign(src.iov_base, src.iov_len, make_reference);
2408 src.iov_base = nullptr;
2409 return *this;
2410 }
2411
2412 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2413 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2414 }
2415
2416 template <class CHAR, class T, class A>
2417 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2418 return assign(str.data(), str.length(), make_reference);
2419 }
2420
2421 buffer &assign(const char *c_str, bool make_reference = false) {
2422 return assign(c_str, strlen(c_str), make_reference);
2423 }
2424
2425#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2426 template <class CHAR, class T>
2427 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2428 return assign(view.data(), view.length(), make_reference);
2429 }
2430
2431 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2432 assign(view.data(), view.length(), make_reference);
2433 view = {};
2434 return *this;
2435 }
2436#endif /* __cpp_lib_string_view >= 201606L */
2437
2438 buffer &operator=(const buffer &src) { return assign(src); }
2439
2440 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2441
2442 buffer &operator=(const struct slice &src) { return assign(src); }
2443
2444 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2445
2446#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2447 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2448 return assign(view.begin(), view.length());
2449 }
2450#endif /* __cpp_lib_string_view >= 201606L */
2451
2452 template <class CHAR, class T, class A>
2453 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2454 return as_string<CHAR, T, A>();
2455 }
2456
2458 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2459
2461 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2462 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2463 }
2464
2466 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2467
2468 buffer &append(const void *src, size_t bytes) {
2469 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2470 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2471 memcpy(end_byte_ptr(), src, bytes);
2472 iov_len += bytes;
2473 return *this;
2474 }
2475
2476 buffer &append(const byte c) {
2477 if (MDBX_UNLIKELY(tailroom() < 1))
2478 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2479 *end_byte_ptr() = c;
2480 iov_len += 1;
2481 return *this;
2482 }
2483
2484 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2485
2486 buffer &add_header(const void *src, size_t bytes) {
2487 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2488 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2489 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2490 iov_len += bytes;
2491 return *this;
2492 }
2493
2494 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2495
2496 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2497 const size_t wanna_bytes = producer.envisage_result_length();
2498 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2499 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2500 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2501 }
2502
2503 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2504 const size_t wanna_bytes = producer.envisage_result_length();
2505 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2506 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2507 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2508 }
2509
2510 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2511 return append_producer(to_hex(data, uppercase, wrap_width));
2512 }
2513
2514 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2515 return append_producer(to_base58(data, wrap_width));
2516 }
2517
2518 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2519 return append_producer(to_base64(data, wrap_width));
2520 }
2521
2522 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2523 return append_producer(from_hex(data, ignore_spaces));
2524 }
2525
2526 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2527 return append_producer(from_base58(data, ignore_spaces));
2528 }
2529
2530 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2531 return append_producer(from_base64(data, ignore_spaces));
2532 }
2533
2534 buffer &append_u8(uint_fast8_t u8) {
2535 if (MDBX_UNLIKELY(tailroom() < 1))
2536 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2537 *end_byte_ptr() = uint8_t(u8);
2538 iov_len += 1;
2539 return *this;
2540 }
2541
2542 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2543
2544 buffer &append_u16(uint_fast16_t u16) {
2545 if (MDBX_UNLIKELY(tailroom() < 2))
2546 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2547 const auto ptr = end_byte_ptr();
2548 ptr[0] = uint8_t(u16);
2549 ptr[1] = uint8_t(u16 >> 8);
2550 iov_len += 2;
2551 return *this;
2552 }
2553
2554 buffer &append_u24(uint_fast32_t u24) {
2555 if (MDBX_UNLIKELY(tailroom() < 3))
2556 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2557 const auto ptr = end_byte_ptr();
2558 ptr[0] = uint8_t(u24);
2559 ptr[1] = uint8_t(u24 >> 8);
2560 ptr[2] = uint8_t(u24 >> 16);
2561 iov_len += 3;
2562 return *this;
2563 }
2564
2565 buffer &append_u32(uint_fast32_t u32) {
2566 if (MDBX_UNLIKELY(tailroom() < 4))
2567 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2568 const auto ptr = end_byte_ptr();
2569 ptr[0] = uint8_t(u32);
2570 ptr[1] = uint8_t(u32 >> 8);
2571 ptr[2] = uint8_t(u32 >> 16);
2572 ptr[3] = uint8_t(u32 >> 24);
2573 iov_len += 4;
2574 return *this;
2575 }
2576
2577 buffer &append_u48(uint_fast64_t u48) {
2578 if (MDBX_UNLIKELY(tailroom() < 6))
2579 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2580 const auto ptr = end_byte_ptr();
2581 ptr[0] = uint8_t(u48);
2582 ptr[1] = uint8_t(u48 >> 8);
2583 ptr[2] = uint8_t(u48 >> 16);
2584 ptr[3] = uint8_t(u48 >> 24);
2585 ptr[4] = uint8_t(u48 >> 32);
2586 ptr[5] = uint8_t(u48 >> 40);
2587 iov_len += 6;
2588 return *this;
2589 }
2590
2591 buffer &append_u64(uint_fast64_t u64) {
2592 if (MDBX_UNLIKELY(tailroom() < 8))
2593 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2594 const auto ptr = end_byte_ptr();
2595 ptr[0] = uint8_t(u64);
2596 ptr[1] = uint8_t(u64 >> 8);
2597 ptr[2] = uint8_t(u64 >> 16);
2598 ptr[3] = uint8_t(u64 >> 24);
2599 ptr[4] = uint8_t(u64 >> 32);
2600 ptr[5] = uint8_t(u64 >> 40);
2601 ptr[6] = uint8_t(u64 >> 48);
2602 ptr[7] = uint8_t(u64 >> 56);
2603 iov_len += 8;
2604 return *this;
2605 }
2606
2607 //----------------------------------------------------------------------------
2608
2609 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2610 return buffer(inherited(text), make_reference);
2611 }
2612
2613#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2614 template <class CHAR, class T>
2615 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2616 return buffer(src, make_reference);
2617 }
2618#endif /* __cpp_lib_string_view >= 201606L */
2619
2620 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2621
2622 template <class CHAR, class T, class A>
2623 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2624 return buffer(src, make_reference);
2625 }
2626
2627 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2628
2629 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2630
2631 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2632
2633 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2634
2635 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2636
2637 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2638
2639 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2640
2641 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2642
2643 static buffer key_from_jsonInteger(const int64_t json_integer) {
2644 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2645 }
2646
2647 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2648
2649 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2650
2651 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2652
2653 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2654
2655 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2656
2657 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2658
2659 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2660
2661 const slice &slice() const noexcept { return *this; }
2662};
2663
2664template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2668 using reservation_policy = CAPACITY_POLICY;
2669 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2671
2674 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2675
2677 : key(key, alloc), value(value, alloc) {}
2678 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2679 const allocator_type &alloc = allocator_type())
2680 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2681
2683 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2684 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2685 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2686
2688 : key(key, alloc), value(value, alloc) {}
2689 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2690 const allocator_type &alloc = allocator_type())
2691 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2692
2695 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2696 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2697
2698 buffer_pair_spec(const txn &transacton, const slice &key, const slice &value,
2699 const allocator_type &alloc = allocator_type())
2700 : key(transacton, key, alloc), value(transacton, value, alloc) {}
2701 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2702 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2703
2704 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2705 : key(::std::move(key)), value(::std::move(value)) {}
2707 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2708 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2709
2712 key.assign(std::move(src.key));
2713 value.assign(std::move(src.value));
2714 return *this;
2715 }
2716
2718 key.assign(src.key);
2719 value.assign(src.value);
2720 return *this;
2721 }
2723 key.assign(std::move(src.key));
2724 value.assign(std::move(src.value));
2725 return *this;
2726 }
2728 key.assign(src.first);
2729 value.assign(src.second);
2730 return *this;
2731 }
2733 key.assign(std::move(src.first));
2734 value.assign(std::move(src.second));
2735 return *this;
2736 }
2737
2741 return key.is_freestanding() && value.is_freestanding();
2742 }
2743
2746 return key.is_reference() || value.is_reference();
2747 }
2748
2752 key.make_freestanding();
2753 value.make_freestanding();
2754 }
2755
2756 operator pair() const noexcept { return pair(key, value); }
2757};
2758
2760
2763public:
2764 cache_entry() noexcept { reset(); }
2765 cache_entry(const cache_entry &) noexcept = default;
2766 cache_entry &operator=(const cache_entry &) noexcept = default;
2767 cache_entry(cache_entry &&other) noexcept {
2768 *this = other;
2769 other.reset();
2770 }
2771 void reset() noexcept { mdbx_cache_init(this); }
2772};
2773
2774//------------------------------------------------------------------------------
2775
2778enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2779
2796
2798 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2799}
2800
2802 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2803}
2804
2806 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2807}
2808
2810 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2811}
2812
2814
2872
2876
2878 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2879}
2880
2882 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2883}
2884
2886 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2887}
2888
2890 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2891}
2892
2894
2905 map_handle(const map_handle &) noexcept = default;
2906 map_handle &operator=(const map_handle &) noexcept = default;
2907 operator bool() const noexcept { return dbi != 0; }
2908 operator MDBX_dbi() const { return dbi; }
2909
2910#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2911 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2912 return a.dbi <=> b.dbi;
2913 }
2914#endif /* __cpp_impl_three_way_comparison */
2915 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2916 return a.dbi == b.dbi;
2917 }
2918 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2919 return a.dbi < b.dbi;
2920 }
2921 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2922 return a.dbi > b.dbi;
2923 }
2924 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2925 return a.dbi <= b.dbi;
2926 }
2927 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2928 return a.dbi >= b.dbi;
2929 }
2930 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2931 return a.dbi != b.dbi;
2932 }
2933
2945};
2946
2949 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2950}
2952 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2953}
2954
2961
2970 friend class txn;
2971
2972protected:
2974 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2975
2976public:
2977 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2978 env(const env &) noexcept = default;
2979 env &operator=(const env &) noexcept = default;
2980 inline env &operator=(env &&) noexcept;
2981 inline env(env &&) noexcept;
2982 inline ~env() noexcept;
2983
2984 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
2985 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
2986 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
2987 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
2988 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
2989
2990 //----------------------------------------------------------------------------
2991
2996
2998 enum : intptr_t {
3001 maximal_value = INTPTR_MAX,
3002 kB = 1000,
3003 MB = kB * 1000,
3004 GB = MB * 1000,
3005#if INTPTR_MAX > 0x7fffFFFFl
3006 TB = GB * 1000,
3007 PB = TB * 1000,
3008 EB = PB * 1000,
3009#endif /* 64-bit intptr_t */
3010 KiB = 1024,
3011 MiB = KiB << 10,
3012 GiB = MiB << 10,
3013#if INTPTR_MAX > 0x7fffFFFFl
3014 TiB = GiB << 10,
3015 PiB = TiB << 10,
3016 EiB = PiB << 10,
3017#endif /* 64-bit intptr_t */
3018 };
3019
3021 struct size {
3022 intptr_t bytes;
3023 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3024 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3025 };
3026
3029
3034
3046
3049
3052
3058
3059 inline geometry &make_fixed(intptr_t size) noexcept;
3060 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3063 geometry(const geometry &) noexcept = default;
3069 };
3070
3078
3086
3099
3121
3126 unsigned max_maps{0};
3129 unsigned max_readers{0};
3134
3145 operate_parameters(const operate_parameters &) noexcept = default;
3147 MDBX_env_flags_t make_flags(bool accede = true,
3150 bool use_subdirectory = false
3151 ) const;
3155 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3156 };
3157
3161 inline env::mode get_mode() const;
3163 inline env::durability get_durability() const;
3167 inline env::operate_options get_options() const;
3168
3171 bool is_pristine() const;
3172
3174 bool is_empty() const;
3175
3177 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3178
3179 struct limits {
3180 limits() = delete;
3182 static inline size_t pagesize_min() noexcept;
3184 static inline size_t pagesize_max() noexcept;
3186 static inline size_t dbsize_min(intptr_t pagesize);
3188 static inline size_t dbsize_max(intptr_t pagesize);
3190 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3192 static inline size_t key_min(key_mode mode) noexcept;
3194 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3196 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3198 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3200 static inline size_t key_max(const env &, key_mode mode);
3202 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3204 static inline size_t value_min(value_mode) noexcept;
3205
3207 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3209 static inline size_t value_max(intptr_t pagesize, value_mode);
3211 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3213 static inline size_t value_max(const env &, value_mode);
3214
3217 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3220 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3223 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3226 static inline size_t pairsize4page_max(const env &, value_mode);
3227
3230 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3233 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3236 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3239 static inline size_t valsize4page_max(const env &, value_mode);
3240
3243 static inline size_t transaction_size_max(intptr_t pagesize);
3244
3246 static inline size_t max_map_handles(void);
3247 };
3248
3250 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3252 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3254 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3256 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3258 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3260 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3264
3267#ifdef MDBX_STD_FILESYSTEM_PATH
3268 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3269#endif /* MDBX_STD_FILESYSTEM_PATH */
3270#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3271 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3272 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3273#endif /* Windows */
3274 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3275 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3276
3278 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3279
3295
3297#ifdef MDBX_STD_FILESYSTEM_PATH
3298 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3299#endif /* MDBX_STD_FILESYSTEM_PATH */
3300#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3301 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3302 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3303#endif /* Windows */
3304 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3305 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3306
3309
3312
3314 inline stat get_stat() const;
3315
3317 size_t get_pagesize() const { return get_stat().ms_psize; }
3318
3320 inline info get_info() const;
3321
3323 inline stat get_stat(const txn &) const;
3324
3326 inline info get_info(const txn &) const;
3327
3329 inline filehandle get_filehandle() const;
3330
3333
3335 inline MDBX_env_flags_t get_flags() const;
3336
3339 inline unsigned max_readers() const;
3340
3343 inline unsigned max_maps() const;
3344
3346 inline void *get_context() const noexcept;
3347
3349 inline env &set_context(void *your_context);
3350
3365 inline env &set_sync_threshold(size_t bytes);
3366
3372 inline size_t sync_threshold() const;
3373
3374#if __cplusplus >= 201103L || defined(DOXYGEN)
3394 inline env &set_sync_period(const duration &period);
3395
3401 inline duration sync_period() const;
3402#endif
3403
3407 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3408
3411 inline unsigned sync_period__seconds_16dot16() const;
3412
3416 inline env &set_sync_period__seconds_double(double seconds);
3417
3420 inline double sync_period__seconds_double() const;
3421
3459
3461 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3462
3464 inline uint64_t extra_option(extra_runtime_option option) const;
3465
3467 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3468
3470 inline env &set_geometry(const geometry &size);
3471
3475 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3476
3480 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3481
3500 inline void close_map(const map_handle &);
3501
3504 int slot;
3513 size_t bytes_used;
3522
3524 size_t used, size_t retained) noexcept;
3525 };
3526
3534 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3535
3538 inline unsigned check_readers();
3539
3558
3563 inline MDBX_hsr_func *get_HandleSlowReaders() const noexcept;
3564
3566 inline txn_managed start_read() const;
3567
3569 inline txn_managed prepare_read() const;
3570
3572 inline txn_managed start_write(txn &parent);
3573
3575 inline txn_managed start_write(bool dont_wait = false);
3576
3579};
3580
3589class LIBMDBX_API_TYPE env_managed : public env {
3590 using inherited = env;
3592 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3593 void setup(unsigned max_maps, unsigned max_readers = 0);
3594
3595public:
3596 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3597
3599#ifdef MDBX_STD_FILESYSTEM_PATH
3600 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3601#endif /* MDBX_STD_FILESYSTEM_PATH */
3602#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3603 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3604 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3605#endif /* Windows */
3606 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3607 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3608
3619
3621#ifdef MDBX_STD_FILESYSTEM_PATH
3623 bool accede = true);
3624#endif /* MDBX_STD_FILESYSTEM_PATH */
3625#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3626 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3627 bool accede = true);
3628 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3629 bool accede = true);
3630#endif /* Windows */
3631 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3632 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3633
3647 void close(bool dont_sync = false);
3648
3649 env_managed(env_managed &&) = default;
3650 env_managed &operator=(env_managed &&other) noexcept {
3652 MDBX_CXX20_UNLIKELY {
3653 assert(handle_ != other.handle_);
3654 close();
3655 }
3656 inherited::operator=(std::move(other));
3657 return *this;
3658 }
3659 env_managed(const env_managed &) = delete;
3660 env_managed &operator=(const env_managed &) = delete;
3661 virtual ~env_managed() noexcept;
3662};
3663
3672protected:
3673 friend class cursor;
3675 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3676
3677public:
3678 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3679 txn(const txn &) noexcept = default;
3680 txn &operator=(const txn &) noexcept = default;
3681 inline txn &operator=(txn &&) noexcept;
3682 inline txn(txn &&) noexcept;
3683 inline ~txn() noexcept;
3684
3685 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3686 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3687 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3688 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3689 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3690
3692 inline ::mdbx::env env() const noexcept;
3694 inline MDBX_txn_flags_t flags() const;
3696 inline uint64_t id() const;
3697
3699 inline void *get_context() const noexcept;
3700
3702 inline txn &set_context(void *your_context);
3703
3705 inline bool is_dirty(const void *ptr) const;
3706
3708 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3709
3711 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3712
3714 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3715
3718 inline info get_info(bool scan_reader_lock_table = false) const;
3719
3722 size_t size_max() const { return env().transaction_size_max(); }
3723
3725 size_t size_current() const {
3726 assert(is_readwrite());
3727 return size_t(get_info().txn_space_dirty);
3728 }
3729
3730 //----------------------------------------------------------------------------
3731
3733 inline void reset_reading();
3734
3736 inline void renew_reading();
3737
3739 inline txn_managed clone(void *context = nullptr) const;
3740
3742 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
3743
3745 inline void make_broken();
3746
3748 inline void park_reading(bool autounpark = true);
3749
3752 inline bool unpark_reading(bool restart_if_ousted = true);
3753
3756
3758 inline cursor_managed open_cursor(map_handle map) const;
3759
3761 inline size_t release_all_cursors(bool unbind) const;
3762
3764 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3765
3767 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3768
3770 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3771 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3773 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3774 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3776 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3777 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3778
3780 inline map_handle open_map_accede(const char *name) const;
3782 inline map_handle open_map_accede(const ::std::string &name) const;
3784 inline map_handle open_map_accede(const slice &name) const;
3785
3787 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3788 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3790 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3791 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3793 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3794 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3795
3797 inline void drop_map(map_handle map);
3801 bool drop_map(const char *name, bool throw_if_absent = false);
3805 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3809 bool drop_map(const slice &name, bool throw_if_absent = false);
3810
3812 inline void clear_map(map_handle map);
3815 bool clear_map(const char *name, bool throw_if_absent = false);
3818 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3821 bool clear_map(const slice &name, bool throw_if_absent = false);
3822
3824 inline void rename_map(map_handle map, const char *new_name);
3826 inline void rename_map(map_handle map, const ::std::string &new_name);
3828 inline void rename_map(map_handle map, const slice &new_name);
3832 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3836 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3840 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3841
3842#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3843
3845 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3846 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3847 return open_map(slice(name), key_mode, value_mode);
3848 }
3849
3850 inline map_handle open_map_accede(const ::std::string_view &name) const;
3852 inline map_handle create_map(const ::std::string_view &name,
3853 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3854 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3855 return create_map(slice(name), key_mode, value_mode);
3856 }
3857
3860 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3861 return drop_map(slice(name), throw_if_absent);
3862 }
3863
3865 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3866 return clear_map(slice(name), throw_if_absent);
3867 }
3868
3869 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3873 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3874 bool throw_if_absent = false) {
3875 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3876 }
3877#endif /* __cpp_lib_string_view >= 201606L */
3878
3881 inline map_stat get_map_stat(map_handle map) const;
3884 inline uint32_t get_tree_deepmask(map_handle map) const;
3886 inline map_handle::info get_map_flags(map_handle map) const;
3887
3890 inline txn &put_canary(const canary &);
3892 inline canary get_canary() const;
3893
3895 inline uint64_t sequence(map_handle map) const;
3897 inline uint64_t sequence(map_handle map, uint64_t increment);
3898
3900 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3902 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3904 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3906 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3907
3909 inline slice get(map_handle map, const slice &key) const;
3911 inline slice get(map_handle map, slice key, size_t &values_count) const;
3913 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3915 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3919 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3923 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3924
3925 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3926 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3927 inline void insert(map_handle map, const slice &key, slice value);
3928 inline value_result try_insert(map_handle map, const slice &key, slice value);
3929 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3930 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3931
3932 inline void upsert(map_handle map, const slice &key, const slice &value);
3933 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3934
3935 inline void update(map_handle map, const slice &key, const slice &value);
3936 inline bool try_update(map_handle map, const slice &key, const slice &value);
3937 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3938 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3939
3940 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3941 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3942 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3943 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3944
3946 inline bool erase(map_handle map, const slice &key);
3947
3949 inline bool erase(map_handle map, const slice &key, const slice &value);
3950
3952 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3953
3955 template <class ALLOCATOR, typename CAPACITY_POLICY>
3957 extract(map_handle map, const slice &key,
3960
3962 template <class ALLOCATOR, typename CAPACITY_POLICY>
3964 replace(map_handle map, const slice &key, const slice &new_value,
3967
3968 template <class ALLOCATOR, typename CAPACITY_POLICY>
3970 replace_reserve(map_handle map, const slice &key, slice &new_value,
3973
3990 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
3991 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
3992 return append(map, kv.key, kv.value, multivalue_order_preserved);
3993 }
3994
3995 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
3996 const void *values_array, size_t values_count, put_mode mode,
3997 bool allow_partial = false);
3998 template <typename VALUE>
3999 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4000 put_mode mode, bool allow_partial = false) {
4001 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4002 !::std::is_array<VALUE>::value,
4003 "Must be a standard layout type!");
4004 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4005 }
4006 template <typename VALUE>
4007 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4008 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4009 }
4010
4011 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4012 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4013 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4014 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4015};
4016
4025class LIBMDBX_API_TYPE txn_managed : public txn {
4026 using inherited = txn;
4027 friend class env;
4028 friend class txn;
4030 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4031
4032public:
4033 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4034 txn_managed(txn_managed &&) = default;
4035 txn_managed &operator=(txn_managed &&other) noexcept {
4037 MDBX_CXX20_UNLIKELY {
4038 assert(handle_ != other.handle_);
4039 abort();
4040 }
4041 inherited::operator=(std::move(other));
4042 return *this;
4043 }
4044 txn_managed(const txn_managed &) = delete;
4045 txn_managed &operator=(const txn_managed &) = delete;
4046 ~txn_managed() noexcept;
4047
4048 //----------------------------------------------------------------------------
4049
4052 void abort();
4053
4055 void commit();
4056
4060
4062
4066
4069 void commit(commit_latency &latency) { return commit(&latency); }
4070
4075 commit_latency result;
4076 commit(&result);
4077 return result;
4078 }
4079};
4080
4088protected:
4090
4091public:
4093 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4094 cursor(const cursor &) noexcept = default;
4095 cursor &operator=(const cursor &) noexcept = default;
4096 inline cursor &operator=(cursor &&) noexcept;
4097 inline cursor(cursor &&) noexcept;
4098 inline ~cursor() noexcept;
4099 inline cursor_managed clone(void *your_context = nullptr) const;
4100 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4101 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4102 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4103 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4104 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4105
4106 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4107 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4108
4109 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4110 return compare_position(*this, other, ignore_nested) < 0;
4111 }
4112
4113 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4114 return compare_position(*this, other, ignore_nested) <= 0;
4115 }
4116
4117 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4118 return compare_position(*this, other, ignore_nested) == 0;
4119 }
4120
4121 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4122 return compare_position(*this, other, ignore_nested) > 0;
4123 }
4124
4125 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4126 return compare_position(*this, other, ignore_nested) >= 0;
4127 }
4128
4130 inline void *get_context() const noexcept;
4131
4133 inline cursor &set_context(void *your_context);
4134
4141
4148
4151
4155
4156 /* Doubtless cursor positioning at a specified key. */
4162
4163 /* Doubtless cursor positioning at a specified key-value pair
4164 * for dupsort/multi-value hives. */
4170
4177
4182 };
4183
4184 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4185 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4186 // и других параметров в bool-throw_notfound.
4187
4188 struct move_result : public pair_result {
4189 inline move_result(const cursor &cursor, bool throw_notfound);
4190 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4191 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4192 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4193 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4194 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4195 bool throw_notfound);
4196 move_result(const move_result &) noexcept = default;
4197 move_result &operator=(const move_result &) noexcept = default;
4198 };
4199
4200 struct estimate_result : public pair {
4205 : estimate_result(cursor, operation, key, slice::invalid()) {}
4206 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4207 estimate_result(const estimate_result &) noexcept = default;
4208 estimate_result &operator=(const estimate_result &) noexcept = default;
4209 };
4210
4211protected:
4212 /* fake const, i.e. for some move/get operations */
4213 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4214
4215 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4216
4217public:
4218 template <typename CALLABLE_PREDICATE>
4219 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4220 struct wrapper : public exception_thunk {
4221 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4222 auto thunk = static_cast<wrapper *>(context);
4223 assert(thunk->is_clean());
4224 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4225 try {
4226 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4227 } catch (... /* capture any exception to rethrow it over C code */) {
4228 thunk->capture();
4229 return MDBX_RESULT_TRUE;
4230 }
4231 }
4232 } thunk;
4234 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4235 thunk);
4236 }
4237
4238 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4239 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4240 }
4241
4242 template <typename CALLABLE_PREDICATE>
4243 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4244 move_operation turn = next) {
4245 struct wrapper : public exception_thunk {
4246 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4247 auto thunk = static_cast<wrapper *>(context);
4248 assert(thunk->is_clean());
4249 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4250 try {
4251 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4252 } catch (... /* capture any exception to rethrow it over C code */) {
4253 thunk->capture();
4254 return MDBX_RESULT_TRUE;
4255 }
4256 }
4257 } thunk;
4258 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4259 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4260 thunk);
4261 }
4262
4263 template <typename CALLABLE_PREDICATE>
4264 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4265 move_operation turn = next) {
4266 struct wrapper : public exception_thunk {
4267 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4268 auto thunk = static_cast<wrapper *>(context);
4269 assert(thunk->is_clean());
4270 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4271 try {
4272 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4273 } catch (... /* capture any exception to rethrow it over C code */) {
4274 thunk->capture();
4275 return MDBX_RESULT_TRUE;
4276 }
4277 }
4278 } thunk;
4279 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4280 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4281 thunk);
4282 }
4283
4284 move_result move(move_operation operation, bool throw_notfound) {
4285 return move_result(*this, operation, throw_notfound);
4286 }
4287 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4288 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4289 }
4290 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4291 return move_result(*this, operation, key, value, throw_notfound);
4292 }
4293 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4294 return move(operation, &key, &value, throw_notfound);
4295 }
4296
4297 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4298 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4299 move_result to_previous_last_multi(bool throw_notfound = true) {
4300 return move(multi_prevkey_lastvalue, throw_notfound);
4301 }
4302 move_result to_current_first_multi(bool throw_notfound = true) {
4303 return move(multi_currentkey_firstvalue, throw_notfound);
4304 }
4305 move_result to_current_prev_multi(bool throw_notfound = true) {
4306 return move(multi_currentkey_prevvalue, throw_notfound);
4307 }
4308 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4309 move_result to_current_next_multi(bool throw_notfound = true) {
4310 return move(multi_currentkey_nextvalue, throw_notfound);
4311 }
4312 move_result to_current_last_multi(bool throw_notfound = true) {
4313 return move(multi_currentkey_lastvalue, throw_notfound);
4314 }
4315 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4316 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4317 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4318
4319 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4320 return move(key_lesser_than, key, throw_notfound);
4321 }
4322 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4323 return move(key_lesser_or_equal, key, throw_notfound);
4324 }
4325 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4326 return move(key_equal, key, throw_notfound);
4327 }
4328 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4329 return move(key_exact, key, throw_notfound);
4330 }
4331 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4332 return move(key_greater_or_equal, key, throw_notfound);
4333 }
4334 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4335 return move(key_greater_than, key, throw_notfound);
4336 }
4337
4338 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4339 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4340 }
4341 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4342 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4343 }
4344 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4345 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4346 }
4347 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4348 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4349 }
4350 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4351 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4352 }
4353
4354 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4355 return move(pair_lesser_than, key, value, throw_notfound);
4356 }
4357 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4358 return move(pair_lesser_or_equal, key, value, throw_notfound);
4359 }
4360 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4361 return move(pair_equal, key, value, throw_notfound);
4362 }
4363 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4364 return move(pair_exact, key, value, throw_notfound);
4365 }
4366 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4367 return move(pair_greater_or_equal, key, value, throw_notfound);
4368 }
4369 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4370 return move(pair_greater_than, key, value, throw_notfound);
4371 }
4372
4373 inline bool seek(const slice &key);
4374 inline move_result find(const slice &key, bool throw_notfound = true);
4375 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4376 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4377
4379 inline size_t count_multivalue() const;
4380
4381 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4382 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4383 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4384
4385 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4386 return move(seek_and_batch_samelength, key, throw_notfound);
4387 }
4388
4389 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4390 return move(batch_samelength, throw_notfound);
4391 }
4392
4393 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4394 return move(batch_samelength_next, throw_notfound);
4395 }
4396
4397 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4398 return move(batch_samelength_previous, throw_notfound);
4399 }
4400
4401 inline bool eof() const;
4402 inline bool on_first() const;
4403 inline bool on_last() const;
4404 inline bool on_first_multival() const;
4405 inline bool on_last_multival() const;
4406 inline estimate_result estimate(const slice &key, const slice &value) const;
4407 inline estimate_result estimate(const slice &key) const;
4408 inline estimate_result estimate(move_operation operation) const;
4409 inline estimate_result estimate(move_operation operation, slice &key) const;
4410
4411 //----------------------------------------------------------------------------
4412
4414 inline void renew(::mdbx::txn &txn);
4415
4418
4420 inline void unbind();
4421
4423 inline ::mdbx::txn txn() const;
4424 inline map_handle map() const;
4425
4426 inline operator ::mdbx::txn() const { return txn(); }
4427 inline operator ::mdbx::map_handle() const { return map(); }
4428
4429 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4430 inline void put(const slice &key, slice value, put_mode mode);
4431 inline void insert(const slice &key, slice value);
4432 inline value_result try_insert(const slice &key, slice value);
4433 inline slice insert_reserve(const slice &key, size_t value_length);
4434 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4435
4436 inline void upsert(const slice &key, const slice &value);
4437 inline slice upsert_reserve(const slice &key, size_t value_length);
4438
4440 void update_current(const slice &value);
4442 slice reverse_current(size_t value_length);
4443
4444 inline void update(const slice &key, const slice &value);
4445 inline bool try_update(const slice &key, const slice &value);
4446 inline slice update_reserve(const slice &key, size_t value_length);
4447 inline value_result try_update_reserve(const slice &key, size_t value_length);
4448
4449 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4450 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4451 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4452 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4453
4455 inline bool erase(bool whole_multivalue = false);
4456
4459 inline bool erase(const slice &key, bool whole_multivalue = true);
4460
4463 inline bool erase(const slice &key, const slice &value);
4464
4465 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4466 size_t values_count, put_mode mode, bool allow_partial = false);
4467 template <typename VALUE>
4468 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4469 bool allow_partial = false) {
4470 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4471 !::std::is_array<VALUE>::value,
4472 "Must be a standard layout type!");
4473 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4474 }
4475 template <typename VALUE>
4476 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4477 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4478 }
4479};
4480
4488class LIBMDBX_API_TYPE cursor_managed : public cursor {
4489 using inherited = cursor;
4490 friend class txn;
4492 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4493
4494public:
4496 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4497 if (MDBX_UNLIKELY(!handle_))
4498 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4499 }
4500
4502 inline void close() {
4504 handle_ = nullptr;
4505 }
4506
4507 cursor_managed(cursor_managed &&) = default;
4508 cursor_managed &operator=(cursor_managed &&other) noexcept {
4510 MDBX_CXX20_UNLIKELY {
4511 assert(handle_ != other.handle_);
4512 close();
4513 }
4514 inherited::operator=(std::move(other));
4515 return *this;
4516 }
4517
4518 inline MDBX_cursor *withdraw_handle() noexcept {
4519 MDBX_cursor *handle = handle_;
4520 handle_ = nullptr;
4521 return handle;
4522 }
4523
4524 cursor_managed(const cursor_managed &) = delete;
4525 cursor_managed &operator=(const cursor_managed &) = delete;
4527};
4528
4529//==============================================================================
4530//
4531// Inline body of the libmdbx C++ API
4532//
4533
4534MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4535MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4536
4537static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4538#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4539 if (::std::is_constant_evaluated()) {
4540 for (size_t i = 0; c_str; ++i)
4541 if (!c_str[i])
4542 return i;
4543 return 0;
4544 }
4545#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4546#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4547 return c_str ? ::std::string_view(c_str).length() : 0;
4548#else
4549 return c_str ? ::std::strlen(c_str) : 0;
4550#endif
4551}
4552
4553MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4554#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4555 if (::std::is_constant_evaluated()) {
4556 for (size_t i = 0; i < bytes; ++i)
4557 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4558 return dest;
4559 } else
4560#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4561 return ::std::memcpy(dest, src, bytes);
4562}
4563
4564static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4565#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4566 if (::std::is_constant_evaluated()) {
4567 for (size_t i = 0; i < bytes; ++i) {
4568 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4569 if (diff)
4570 return diff;
4571 }
4572 return 0;
4573 } else
4574#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4575 return ::std::memcmp(a, b, bytes);
4576}
4577
4578//------------------------------------------------------------------------------
4579
4582
4586
4590
4591inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4592
4593inline void exception_thunk::capture() noexcept {
4594 assert(is_clean());
4595 captured_ = ::std::current_exception();
4596}
4597
4599 if (captured_)
4600 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4601}
4602
4603//------------------------------------------------------------------------------
4604
4605MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4606
4607inline error &error::operator=(MDBX_error_t error_code) noexcept {
4608 code_ = error_code;
4609 return *this;
4610}
4611
4612MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4613
4614MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4615
4616MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4617
4618MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4619
4620MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4621
4623 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4624}
4625
4626MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4627
4632
4633inline void error::throw_exception(int error_code) {
4634 const error trouble(static_cast<MDBX_error_t>(error_code));
4635 trouble.throw_exception();
4636}
4637
4638inline void error::throw_on_failure() const {
4640 MDBX_CXX20_UNLIKELY throw_exception();
4641}
4642
4643inline void error::success_or_throw() const {
4644 if (MDBX_UNLIKELY(!is_success()))
4645 MDBX_CXX20_UNLIKELY throw_exception();
4646}
4647
4648inline void error::success_or_throw(const exception_thunk &thunk) const {
4649 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4650 if (MDBX_UNLIKELY(!is_success())) {
4651 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4652 else throw_exception();
4653 }
4654}
4655
4656inline void error::panic_on_failure(const char *context_where, const char *func_who) const noexcept {
4658 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4659}
4660
4661inline void error::success_or_panic(const char *context_where, const char *func_who) const noexcept {
4662 if (MDBX_UNLIKELY(!is_success()))
4663 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4664}
4665
4666inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4667 if (MDBX_UNLIKELY(ptr == nullptr))
4668 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4669}
4670
4671inline void error::throw_on_failure(int error_code) {
4672 error rc(static_cast<MDBX_error_t>(error_code));
4673 rc.throw_on_failure();
4674}
4675
4676inline void error::success_or_throw(MDBX_error_t error_code) {
4677 error rc(error_code);
4678 rc.success_or_throw();
4679}
4680
4681inline bool error::boolean_or_throw(int error_code) {
4682 switch (error_code) {
4683 case MDBX_RESULT_FALSE:
4684 return false;
4685 case MDBX_RESULT_TRUE:
4686 return true;
4687 default:
4688 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4689 }
4690}
4691
4692inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4693 error rc(static_cast<MDBX_error_t>(error_code));
4694 rc.success_or_throw(thunk);
4695}
4696
4697inline void error::panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept {
4698 error rc(static_cast<MDBX_error_t>(error_code));
4699 rc.panic_on_failure(context_where, func_who);
4700}
4701
4702inline void error::success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept {
4703 error rc(static_cast<MDBX_error_t>(error_code));
4704 rc.success_or_panic(context_where, func_who);
4705}
4706
4707inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4708 if (MDBX_UNLIKELY(!thunk.is_clean()))
4709 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4710 return boolean_or_throw(error_code);
4711}
4712
4713MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4714
4716 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4717
4718MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4719 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4720
4721MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4722
4723MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4724
4725MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4726
4727MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4728
4729inline slice &slice::assign(const void *ptr, size_t bytes) {
4730 iov_base = const_cast<void *>(ptr);
4731 iov_len = check_length(bytes);
4732 return *this;
4733}
4734
4735inline slice &slice::assign(const slice &src) noexcept {
4736 iov_base = src.iov_base;
4737 iov_len = src.iov_len;
4738 return *this;
4739}
4740
4741inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4742
4743slice &slice::assign(slice &&src) noexcept {
4744 assign(src);
4745 src.invalidate();
4746 return *this;
4747}
4748
4750 assign(src.iov_base, src.iov_len);
4751 src.iov_base = nullptr;
4752 return *this;
4753}
4754
4755inline slice &slice::assign(const void *begin, const void *end) {
4756 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4757}
4758
4759inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4760
4761inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4762
4763inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4764
4765MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4766
4767MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4768
4769MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4770
4772
4773MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4774
4775MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4776
4777MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4778
4780
4781MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4782
4783MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4784
4785MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4786
4787MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4788
4789MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4790
4792 iov_len = check_length(bytes);
4793 return *this;
4794}
4795
4797 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4798 return set_length(static_cast<const char *>(ptr) - char_ptr());
4799}
4800
4801MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4802
4803MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4804
4805MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4806
4807MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4808
4809MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4810
4812 iov_base = nullptr;
4813 iov_len = 0;
4814}
4815
4816inline void slice::remove_prefix(size_t n) noexcept {
4817 assert(n <= size());
4818 iov_base = static_cast<byte *>(iov_base) + n;
4819 iov_len -= n;
4820}
4821
4822inline void slice::safe_remove_prefix(size_t n) {
4823 if (MDBX_UNLIKELY(n > size()))
4824 MDBX_CXX20_UNLIKELY throw_out_range();
4825 remove_prefix(n);
4826}
4827
4828inline void slice::remove_suffix(size_t n) noexcept {
4829 assert(n <= size());
4830 iov_len -= n;
4831}
4832
4833inline void slice::safe_remove_suffix(size_t n) {
4834 if (MDBX_UNLIKELY(n > size()))
4835 MDBX_CXX20_UNLIKELY throw_out_range();
4836 remove_suffix(n);
4837}
4838
4839MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4840 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4841}
4842
4843MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4844 return length() >= suffix.length() &&
4845 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4846}
4847
4849 size_t h = length() * 3977471;
4850 for (size_t i = 0; i < length(); ++i)
4851 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4852 return h ^ 3863194411 * (h >> 11);
4853}
4854
4855MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4857 return byte_ptr()[n];
4858}
4859
4860MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4861 if (MDBX_UNLIKELY(n >= size()))
4862 MDBX_CXX20_UNLIKELY throw_out_range();
4863 return byte_ptr()[n];
4864}
4865
4866MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4868 return slice(data(), n);
4869}
4870
4871MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4873 return slice(char_ptr() + size() - n, n);
4874}
4875
4876MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4877 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4878 return slice(char_ptr() + from, n);
4879}
4880
4882 if (MDBX_UNLIKELY(n > size()))
4883 MDBX_CXX20_UNLIKELY throw_out_range();
4884 return head(n);
4885}
4886
4888 if (MDBX_UNLIKELY(n > size()))
4889 MDBX_CXX20_UNLIKELY throw_out_range();
4890 return tail(n);
4891}
4892
4893MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4894 if (MDBX_UNLIKELY(n > max_length))
4895 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4896 if (MDBX_UNLIKELY(from + n > size()))
4897 MDBX_CXX20_UNLIKELY throw_out_range();
4898 return middle(from, n);
4899}
4900
4901MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4902 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4903 return diff ? diff
4904 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4905 : memcmp(a.data(), b.data(), a.length());
4906}
4907
4909 const size_t shortest = ::std::min(a.length(), b.length());
4910 if (MDBX_LIKELY(shortest > 0))
4912 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4913 if (MDBX_LIKELY(diff != 0))
4914 MDBX_CXX20_LIKELY return diff;
4915 }
4916 return intptr_t(a.length()) - intptr_t(b.length());
4917}
4918
4920 return slice::compare_fast(a, b) == 0;
4921}
4922
4924 return slice::compare_lexicographically(a, b) < 0;
4925}
4926
4928 return slice::compare_lexicographically(a, b) > 0;
4929}
4930
4932 return slice::compare_lexicographically(a, b) <= 0;
4933}
4934
4936 return slice::compare_lexicographically(a, b) >= 0;
4937}
4938
4940 return slice::compare_fast(a, b) != 0;
4941}
4942
4943#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
4944MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
4946}
4947#endif /* __cpp_impl_three_way_comparison */
4948
4949template <class ALLOCATOR, typename CAPACITY_POLICY>
4951 const allocator_type &alloc)
4952 : inherited(src), silo_(alloc) {
4953 if (!make_reference)
4954 insulate();
4955}
4956
4957template <class ALLOCATOR, typename CAPACITY_POLICY>
4958inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
4959 const allocator_type &alloc)
4960 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
4961
4962template <class ALLOCATOR, typename CAPACITY_POLICY>
4963inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
4964 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
4965}
4966
4967#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
4969
4970#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
4972#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
4973#endif /* !MinGW || MDBX_EXPORTS */
4974
4977
4978//------------------------------------------------------------------------------
4979
4980template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
4981inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
4982 if (MDBX_LIKELY(!producer.is_empty()))
4984 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
4985 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
4986 return result;
4987 }
4989}
4990
4991template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
4992inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
4993 if (MDBX_LIKELY(!producer.is_empty()))
4995 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
4996 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
4997 return result;
4998 }
5000}
5001
5002template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5003inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
5004 string<ALLOCATOR> result(alloc);
5005 if (MDBX_LIKELY(!producer.is_empty()))
5007 result.resize(producer.envisage_result_length());
5008 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5009 }
5010 return result;
5011}
5012
5013template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5014inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
5015 string<ALLOCATOR> result(alloc);
5016 if (MDBX_LIKELY(!producer.is_empty()))
5018 result.resize(producer.envisage_result_length());
5019 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5020 }
5021 return result;
5022}
5023
5024template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
5025 return make_string<ALLOCATOR>(*this, alloc);
5026}
5027
5028template <class ALLOCATOR, typename CAPACITY_POLICY>
5030 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5031}
5032
5033template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
5034 return make_string<ALLOCATOR>(*this, alloc);
5035}
5036
5037template <class ALLOCATOR, typename CAPACITY_POLICY>
5039 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5040}
5041
5042template <class ALLOCATOR> string<ALLOCATOR> to_base64::as_string(const ALLOCATOR &alloc) const {
5043 return make_string<ALLOCATOR>(*this, alloc);
5044}
5045
5046template <class ALLOCATOR, typename CAPACITY_POLICY>
5048 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5049}
5050
5051template <class ALLOCATOR> string<ALLOCATOR> from_hex::as_string(const ALLOCATOR &alloc) const {
5052 return make_string<ALLOCATOR>(*this, alloc);
5053}
5054
5055template <class ALLOCATOR, typename CAPACITY_POLICY>
5057 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5058}
5059
5060template <class ALLOCATOR> string<ALLOCATOR> from_base58::as_string(const ALLOCATOR &alloc) const {
5061 return make_string<ALLOCATOR>(*this, alloc);
5062}
5063
5064template <class ALLOCATOR, typename CAPACITY_POLICY>
5066 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5067}
5068
5069template <class ALLOCATOR> string<ALLOCATOR> from_base64::as_string(const ALLOCATOR &alloc) const {
5070 return make_string<ALLOCATOR>(*this, alloc);
5071}
5072
5073template <class ALLOCATOR, typename CAPACITY_POLICY>
5075 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5076}
5077
5078template <class ALLOCATOR>
5079inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
5080 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
5081}
5082
5083template <class ALLOCATOR>
5084inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5085 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5086}
5087
5088template <class ALLOCATOR>
5089inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5090 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5091}
5092
5093template <class ALLOCATOR, class CAPACITY_POLICY>
5094inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5095 const ALLOCATOR &alloc) const {
5096 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5097}
5098
5099template <class ALLOCATOR, class CAPACITY_POLICY>
5100inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
5101 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5102}
5103
5104template <class ALLOCATOR, class CAPACITY_POLICY>
5105inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
5106 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5107}
5108
5109template <class ALLOCATOR, class CAPACITY_POLICY>
5110inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5111 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5112}
5113
5114template <class ALLOCATOR, class CAPACITY_POLICY>
5115inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5116 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5117}
5118
5119template <class ALLOCATOR, class CAPACITY_POLICY>
5120inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5121 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5122}
5123
5124//------------------------------------------------------------------------------
5125
5126MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5127 const auto diff = slice::compare_fast(a.key, b.key);
5128 return diff ? diff : slice::compare_fast(a.value, b.value);
5129}
5130
5131MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5132 const auto diff = slice::compare_lexicographically(a.key, b.key);
5133 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5134}
5135
5137 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5138 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5139 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5140}
5141
5143 return pair::compare_lexicographically(a, b) < 0;
5144}
5145
5147 return pair::compare_lexicographically(a, b) > 0;
5148}
5149
5151 return pair::compare_lexicographically(a, b) <= 0;
5152}
5153
5155 return pair::compare_lexicographically(a, b) >= 0;
5156}
5157
5159 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5160 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5161 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5162}
5163
5164#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5165MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5167}
5168#endif /* __cpp_impl_three_way_comparison */
5169
5171template <typename BUFFER>
5173
5176
5177//------------------------------------------------------------------------------
5178
5179inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
5180inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
5181inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
5182
5183MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5184 return !from_hex(*this, ignore_spaces).is_erroneous();
5185}
5186
5187MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5188 return !from_base58(*this, ignore_spaces).is_erroneous();
5189}
5190
5191MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5192 return !from_base64(*this, ignore_spaces).is_erroneous();
5193}
5194
5195//------------------------------------------------------------------------------
5196
5198
5199inline env &env::operator=(env &&other) noexcept {
5200 handle_ = other.handle_;
5201 other.handle_ = nullptr;
5202 return *this;
5203}
5204
5205inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5206
5207inline env::~env() noexcept {
5208#ifndef NDEBUG
5209 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5210#endif
5211}
5212
5213MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5214
5215MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5216
5217MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5218
5219MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5220
5221MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5222
5226 return *this;
5227}
5228
5229inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5230 size_now = size_lower = lower;
5231 size_upper = upper;
5233 return *this;
5234}
5235
5239
5243
5244inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5245
5246inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5247
5248inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5249 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5250 if (result < 0)
5251 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5252 return static_cast<size_t>(result);
5253}
5254
5255inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5256 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5257 if (result < 0)
5258 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5259 return static_cast<size_t>(result);
5260}
5261
5262inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5263
5264inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5265
5266inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5267 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5268 if (result < 0)
5269 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5270 return static_cast<size_t>(result);
5271}
5272
5273inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5274 return key_max(pagesize, MDBX_db_flags_t(mode));
5275}
5276
5277inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
5278 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5279 if (result < 0)
5280 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5281 return static_cast<size_t>(result);
5282}
5283
5285
5286inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5287
5289
5290inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5291 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5292 if (result < 0)
5293 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5294 return static_cast<size_t>(result);
5295}
5296
5297inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5298 return value_max(pagesize, MDBX_db_flags_t(mode));
5299}
5300
5301inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
5302 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5303 if (result < 0)
5304 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5305 return static_cast<size_t>(result);
5306}
5307
5309
5310inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5311 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5312 if (result < 0)
5313 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5314 return static_cast<size_t>(result);
5315}
5316
5317inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5318 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5319}
5320
5322 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5323 if (result < 0)
5324 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5325 return static_cast<size_t>(result);
5326}
5327
5331
5332inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5333 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5334 if (result < 0)
5335 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5336 return static_cast<size_t>(result);
5337}
5338
5339inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5340 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5341}
5342
5344 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5345 if (result < 0)
5346 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5347 return static_cast<size_t>(result);
5348}
5349
5353
5354inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5355 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5356 if (result < 0)
5357 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5358 return static_cast<size_t>(result);
5359}
5360
5361inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5362
5370
5372
5376
5380
5384
5385inline env::stat env::get_stat() const {
5386 env::stat r;
5387 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5388 return r;
5389}
5390
5391inline env::stat env::get_stat(const txn &txn) const {
5392 env::stat r;
5394 return r;
5395}
5396
5397inline env::info env::get_info() const {
5398 env::info r;
5399 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5400 return r;
5401}
5402
5403inline env::info env::get_info(const txn &txn) const {
5404 env::info r;
5406 return r;
5407}
5408
5410 filehandle fd;
5412 return fd;
5413}
5414
5416 unsigned bits = 0;
5418 return MDBX_env_flags_t(bits);
5419}
5420
5421inline unsigned env::max_readers() const {
5422 unsigned r;
5424 return r;
5425}
5426
5427inline unsigned env::max_maps() const {
5428 unsigned r;
5430 return r;
5431}
5432
5433inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5434
5435inline env &env::set_context(void *ptr) {
5437 return *this;
5438}
5439
5440inline env &env::set_sync_threshold(size_t bytes) {
5442 return *this;
5443}
5444
5445inline size_t env::sync_threshold() const {
5446 size_t bytes;
5448 return bytes;
5449}
5450
5451inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5453 return *this;
5454}
5455
5456inline unsigned env::sync_period__seconds_16dot16() const {
5457 unsigned seconds_16dot16;
5459 return seconds_16dot16;
5460}
5461
5463 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5464}
5465
5466inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5467
5468#if __cplusplus >= 201103L
5469inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5470
5472#endif
5473
5474inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5476 return *this;
5477}
5478
5479inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5480 uint64_t value;
5482 return value;
5483}
5484
5485inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
5487 return *this;
5488}
5489
5490inline env &env::set_geometry(const geometry &geo) {
5492 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5493 return *this;
5494}
5495
5496inline bool env::sync_to_disk(bool force, bool nonblock) {
5497 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5498 switch (err) {
5499 case MDBX_SUCCESS /* flush done */:
5500 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5501 return true;
5502 case MDBX_BUSY /* the environment is used by other thread */:
5503 return false;
5504 default:
5505 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5506 }
5507}
5508
5509inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5510
5512env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5513 size_t retained) noexcept
5515 bytes_retained(retained) {}
5516
5517template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5518 struct reader_visitor_thunk : public exception_thunk {
5519 VISITOR &visitor_;
5520 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5521 size_t used, size_t retained) noexcept {
5522 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5523 assert(thunk->is_clean());
5524 try {
5525 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5526 return loop_control(thunk->visitor_(info, number));
5527 } catch (... /* capture any exception to rethrow it over C code */) {
5528 thunk->capture();
5530 }
5531 }
5532 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5533 };
5534 reader_visitor_thunk thunk(visitor);
5535 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5536 thunk.rethrow_captured();
5537 return rc;
5538}
5539
5540inline unsigned env::check_readers() {
5541 int dead_count;
5542 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5543 assert(dead_count >= 0);
5544 return static_cast<unsigned>(dead_count);
5545}
5546
5551
5552inline MDBX_hsr_func *env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5553
5555 ::MDBX_txn *ptr;
5557 assert(ptr != nullptr);
5558 return txn_managed(ptr);
5559}
5560
5562 ::MDBX_txn *ptr;
5564 assert(ptr != nullptr);
5565 return txn_managed(ptr);
5566}
5567
5568inline txn_managed env::start_write(bool dont_wait) {
5569 ::MDBX_txn *ptr;
5571 assert(ptr != nullptr);
5572 return txn_managed(ptr);
5573}
5574
5576 ::MDBX_txn *ptr;
5578 assert(ptr != nullptr);
5579 return txn_managed(ptr);
5580}
5581
5583
5585
5586inline txn &txn::operator=(txn &&other) noexcept {
5587 handle_ = other.handle_;
5588 other.handle_ = nullptr;
5589 return *this;
5590}
5591
5592inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5593
5594inline txn::~txn() noexcept {
5595#ifndef NDEBUG
5596 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5597#endif
5598}
5599
5600MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5601
5602MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5603
5604MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5605
5606MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5607
5608MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5609
5610inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5611
5612inline txn &txn::set_context(void *ptr) {
5614 return *this;
5615}
5616
5617inline bool txn::is_dirty(const void *ptr) const {
5618 int err = ::mdbx_is_dirty(handle_, ptr);
5619 switch (err) {
5620 default:
5621 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5622 case MDBX_RESULT_TRUE:
5623 return true;
5624 case MDBX_RESULT_FALSE:
5625 return false;
5626 }
5627}
5628
5629inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5630
5632 const int bits = mdbx_txn_flags(handle_);
5634 return static_cast<MDBX_txn_flags_t>(bits);
5635}
5636
5637inline uint64_t txn::id() const {
5638 const uint64_t txnid = mdbx_txn_id(handle_);
5640 return txnid;
5641}
5642
5644
5646
5648
5649inline txn_managed txn::clone(void *context) const {
5650 MDBX_txn *ptr = nullptr;
5652 assert(ptr != nullptr);
5653 return txn_managed(ptr);
5654}
5655
5656inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
5657 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
5658 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
5659 assert(txn_for_renew_into_clone.handle_ != nullptr);
5660}
5661
5662inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5663
5664inline bool txn::unpark_reading(bool restart_if_ousted) {
5665 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5666}
5667
5668inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5669 txn::info r;
5670 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5671 return r;
5672}
5673
5675 MDBX_cursor *ptr;
5677 return cursor_managed(ptr);
5678}
5679
5680inline size_t txn::release_all_cursors(bool unbind) const {
5681 size_t count;
5683 return count;
5684}
5685
5686inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5687 const ::mdbx::value_mode value_mode) const {
5688 map_handle map;
5691 assert(map.dbi != 0);
5692 return map;
5693}
5694
5695inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5696 const ::mdbx::value_mode value_mode) const {
5697 map_handle map;
5700 assert(map.dbi != 0);
5701 return map;
5702}
5703
5704inline map_handle txn::open_map_accede(const slice &name) const {
5705 map_handle map;
5707 assert(map.dbi != 0);
5708 return map;
5709}
5710
5711inline map_handle txn::open_map_accede(const char *name) const {
5712 map_handle map;
5714 assert(map.dbi != 0);
5715 return map;
5716}
5717
5718inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5719 const ::mdbx::value_mode value_mode) {
5720 map_handle map;
5723 assert(map.dbi != 0);
5724 return map;
5725}
5726
5727inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5728 const ::mdbx::value_mode value_mode) {
5729 map_handle map;
5732 assert(map.dbi != 0);
5733 return map;
5734}
5735
5737
5739
5740inline void txn::rename_map(map_handle map, const char *new_name) {
5742}
5743
5744inline void txn::rename_map(map_handle map, const slice &new_name) {
5746}
5747
5748inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5749 const ::mdbx::value_mode value_mode) const {
5750 return open_map(slice(name), key_mode, value_mode);
5751}
5752
5753inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5754
5755inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5756 const ::mdbx::value_mode value_mode) {
5757 return create_map(slice(name), key_mode, value_mode);
5758}
5759
5760inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5761 return drop_map(slice(name), throw_if_absent);
5762}
5763
5764inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5765 return clear_map(slice(name), throw_if_absent);
5766}
5767
5768inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5769
5771 txn::map_stat r;
5772 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5773 return r;
5774}
5775
5776inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5777 uint32_t r;
5779 return r;
5780}
5781
5787
5792
5794 txn::canary r;
5796 return r;
5797}
5798
5799inline uint64_t txn::sequence(map_handle map) const {
5800 uint64_t result;
5802 return result;
5803}
5804
5805inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5806 uint64_t result;
5807 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5808 return result;
5809}
5810
5811inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5812 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5813}
5814
5815inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5816 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5817}
5818
5819inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5820 return compare_keys(map, a.key, b.key);
5821}
5822
5823inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5824 return compare_values(map, a.value, b.value);
5825}
5826
5827inline slice txn::get(map_handle map, const slice &key) const {
5828 slice result;
5829 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5830 return result;
5831}
5832
5833inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5834 slice result;
5835 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5836 return result;
5837}
5838
5839inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5840 slice result;
5841 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5842 switch (err) {
5843 case MDBX_SUCCESS:
5844 return result;
5845 case MDBX_NOTFOUND:
5846 return value_at_absence;
5847 default:
5848 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5849 }
5850}
5851
5852inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5853 slice result;
5854 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5855 switch (err) {
5856 case MDBX_SUCCESS:
5857 return result;
5858 case MDBX_NOTFOUND:
5859 return value_at_absence;
5860 default:
5861 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5862 }
5863}
5864
5866 pair result(key, slice());
5867 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5868 return pair_result(result.key, result.value, exact);
5869}
5870
5871inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5872 pair result{key, slice()};
5873 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5874 switch (err) {
5875 case MDBX_SUCCESS:
5876 return pair_result{result.key, result.value, true};
5877 case MDBX_RESULT_TRUE:
5878 return pair_result{result.key, result.value, false};
5879 case MDBX_NOTFOUND:
5880 return pair_result{key, value_at_absence, false};
5881 default:
5882 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5883 }
5884}
5885
5886inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5887 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5888}
5889
5890inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5891 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5892}
5893
5894inline void txn::insert(map_handle map, const slice &key, slice value) {
5895 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5897}
5898
5899inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5900 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5902 switch (err) {
5903 case MDBX_SUCCESS:
5904 return value_result{slice(), true};
5905 case MDBX_KEYEXIST:
5906 return value_result{value, false};
5907 default:
5908 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5909 }
5910}
5911
5912inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5913 slice result(nullptr, value_length);
5914 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5916 return result;
5917}
5918
5919inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5920 slice result(nullptr, value_length);
5921 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5923 switch (err) {
5924 case MDBX_SUCCESS:
5925 return value_result{result, true};
5926 case MDBX_KEYEXIST:
5927 return value_result{result, false};
5928 default:
5929 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5930 }
5931}
5932
5933inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5934 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5935}
5936
5937inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
5938 slice result(nullptr, value_length);
5940 return result;
5941}
5942
5943inline void txn::update(map_handle map, const slice &key, const slice &value) {
5944 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
5945}
5946
5947inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
5948 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
5949 switch (err) {
5950 case MDBX_SUCCESS:
5951 return true;
5952 case MDBX_NOTFOUND:
5953 return false;
5954 default:
5955 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5956 }
5957}
5958
5959inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
5960 slice result(nullptr, value_length);
5962 return result;
5963}
5964
5965inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
5966 slice result(nullptr, value_length);
5967 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
5968 switch (err) {
5969 case MDBX_SUCCESS:
5970 return value_result{result, true};
5971 case MDBX_NOTFOUND:
5972 return value_result{slice(), false};
5973 default:
5974 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5975 }
5976}
5977
5978inline bool txn::erase(map_handle map, const slice &key) {
5979 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
5980 switch (err) {
5981 case MDBX_SUCCESS:
5982 return true;
5983 case MDBX_NOTFOUND:
5984 return false;
5985 default:
5986 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5987 }
5988}
5989
5990inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
5991 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
5992 switch (err) {
5993 case MDBX_SUCCESS:
5994 return true;
5995 case MDBX_NOTFOUND:
5996 return false;
5997 default:
5998 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5999 }
6000}
6001
6002inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
6003 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6004 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6005}
6006
6007template <class ALLOCATOR, typename CAPACITY_POLICY>
6011 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6013 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
6014 return result;
6015}
6016
6017template <class ALLOCATOR, typename CAPACITY_POLICY>
6019txn::replace(map_handle map, const slice &key, const slice &new_value,
6021 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6022 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
6023 MDBX_CURRENT, result, &result),
6024 result);
6025 return result;
6026}
6027
6028template <class ALLOCATOR, typename CAPACITY_POLICY>
6030txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
6032 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6033 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6034 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6035 result);
6036 return result;
6037}
6038
6039inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
6040 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6041 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
6042}
6043
6044inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
6045 const void *values_array, size_t values_count, put_mode mode,
6046 bool allow_partial) {
6047 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6048 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6049 switch (err) {
6050 case MDBX_SUCCESS:
6051 MDBX_CXX20_LIKELY break;
6052 case MDBX_KEYEXIST:
6053 if (allow_partial)
6054 break;
6056 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6057 default:
6058 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6059 }
6060 return args[1].iov_len /* done item count */;
6061}
6062
6063inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
6064 ptrdiff_t result;
6065 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6066 return result;
6067}
6068
6069inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6070 ptrdiff_t result;
6071 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6072 return result;
6073}
6074
6075inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6076 ptrdiff_t result;
6077 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6078 return result;
6079}
6080
6081inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6082 ptrdiff_t result;
6083 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6084 return result;
6085}
6086
6088
6089inline cursor_managed cursor::clone(void *your_context) const {
6090 cursor_managed clone(your_context);
6092 return clone;
6093}
6094
6095inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6096
6097inline cursor &cursor::set_context(void *ptr) {
6099 return *this;
6100}
6101
6102inline cursor &cursor::operator=(cursor &&other) noexcept {
6103 handle_ = other.handle_;
6104 other.handle_ = nullptr;
6105 return *this;
6106}
6107
6108inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6109
6110inline cursor::~cursor() noexcept {
6111#ifndef NDEBUG
6112 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6113#endif
6114}
6115
6116MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
6117
6118MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
6119
6120MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6121
6122MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6123
6124MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6125
6126inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6127 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6128}
6129
6130inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6131 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6132 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6133 if (MDBX_LIKELY(int16_t(diff) == diff))
6134 MDBX_CXX20_LIKELY return int(diff);
6135 else
6137}
6138
6139inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6140 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6141}
6142
6144 bool throw_notfound)
6145 : pair_result(key, value, false) {
6146 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6147}
6148
6149inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6150 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6151 switch (err) {
6152 case MDBX_SUCCESS:
6153 MDBX_CXX20_LIKELY return true;
6154 case MDBX_RESULT_TRUE:
6155 return false;
6156 case MDBX_NOTFOUND:
6157 if (!throw_notfound)
6158 return false;
6159 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6160 default:
6161 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6162 }
6163}
6164
6166 const slice &value)
6167 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6168 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6169}
6170
6171inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6172 ptrdiff_t result;
6173 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6174 return result;
6175}
6176
6177inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6178 ptrdiff_t result;
6180 return result;
6181}
6182
6183inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6184 return move(key_exact, key, throw_notfound);
6185}
6186
6187inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6188 return move(key_lowerbound, key, throw_notfound);
6189}
6190
6191inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6192 return move(key_greater_than, key, throw_notfound);
6193}
6194
6195inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6196 return move(multi_find_pair, key, value, throw_notfound);
6197}
6198
6199inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6200 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6201}
6202
6203inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6204 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6205}
6206
6207inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6208
6209inline size_t cursor::count_multivalue() const {
6210 size_t result;
6212 return result;
6213}
6214
6215inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6216
6218
6220
6222
6224
6225inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6226 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6227}
6228
6230 return estimate_result(*this, key_lowerbound, key);
6231}
6232
6234 return estimate_result(*this, operation);
6235}
6236
6238
6242
6244
6245inline txn cursor::txn() const {
6247 return ::mdbx::txn(txn);
6248}
6249
6250inline map_handle cursor::map() const {
6251 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6252 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6254 return map_handle(dbi);
6255}
6256
6257inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6258 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6259}
6260
6261inline void cursor::put(const slice &key, slice value, put_mode mode) {
6262 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6263}
6264
6265inline void cursor::insert(const slice &key, slice value) {
6267 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6268}
6269
6270inline value_result cursor::try_insert(const slice &key, slice value) {
6271 const int err =
6272 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6273 switch (err) {
6274 case MDBX_SUCCESS:
6275 return value_result{slice(), true};
6276 case MDBX_KEYEXIST:
6277 return value_result{value, false};
6278 default:
6279 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6280 }
6281}
6282
6283inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6284 slice result(nullptr, value_length);
6285 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6287 return result;
6288}
6289
6290inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6291 slice result(nullptr, value_length);
6292 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6294 switch (err) {
6295 case MDBX_SUCCESS:
6296 return value_result{result, true};
6297 case MDBX_KEYEXIST:
6298 return value_result{result, false};
6299 default:
6300 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6301 }
6302}
6303
6304inline void cursor::upsert(const slice &key, const slice &value) {
6305 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6306}
6307
6308inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6309 slice result(nullptr, value_length);
6311 return result;
6312}
6313
6314inline void cursor::update(const slice &key, const slice &value) {
6315 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6316}
6317
6318inline bool cursor::try_update(const slice &key, const slice &value) {
6319 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6320 switch (err) {
6321 case MDBX_SUCCESS:
6322 return true;
6323 case MDBX_NOTFOUND:
6324 return false;
6325 default:
6326 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6327 }
6328}
6329
6330inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6331 slice result(nullptr, value_length);
6333 return result;
6334}
6335
6336inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6337 slice result(nullptr, value_length);
6338 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6339 switch (err) {
6340 case MDBX_SUCCESS:
6341 return value_result{result, true};
6342 case MDBX_NOTFOUND:
6343 return value_result{slice(), false};
6344 default:
6345 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6346 }
6347}
6348
6349inline bool cursor::erase(bool whole_multivalue) {
6350 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6351 switch (err) {
6352 case MDBX_SUCCESS:
6353 MDBX_CXX20_LIKELY return true;
6354 case MDBX_NOTFOUND:
6355 return false;
6356 default:
6357 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6358 }
6359}
6360
6361inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6362 bool found = seek(key);
6363 return found ? erase(whole_multivalue) : found;
6364}
6365
6366inline bool cursor::erase(const slice &key, const slice &value) {
6367 move_result data = find_multivalue(key, value, false);
6368 return data.done && erase();
6369}
6370
6371inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6372 size_t values_count, put_mode mode, bool allow_partial) {
6373 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6374 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6375 switch (err) {
6376 case MDBX_SUCCESS:
6377 MDBX_CXX20_LIKELY break;
6378 case MDBX_KEYEXIST:
6379 if (allow_partial)
6380 break;
6382 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6383 default:
6384 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6385 }
6386 return args[1].iov_len /* done item count */;
6387}
6388
6389//------------------------------------------------------------------------------
6390
6391LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
6392LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
6393LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
6394LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
6395LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
6396LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
6397LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
6398LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
6399LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
6400LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
6401LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
6402
6403LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
6404LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
6405LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
6406
6407inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
6408
6410
6411} // namespace mdbx
6412
6413//------------------------------------------------------------------------------
6414
6417namespace std {
6418
6419inline string to_string(const ::mdbx::slice &value) {
6420 ostringstream out;
6421 out << value;
6422 return out.str();
6423}
6424
6425template <class ALLOCATOR, typename CAPACITY_POLICY>
6426inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6427 ostringstream out;
6428 out << buffer;
6429 return out.str();
6430}
6431
6432inline string to_string(const ::mdbx::pair &value) {
6433 ostringstream out;
6434 out << value;
6435 return out.str();
6436}
6437
6438inline string to_string(const ::mdbx::env::geometry &value) {
6439 ostringstream out;
6440 out << value;
6441 return out.str();
6442}
6443
6444inline string to_string(const ::mdbx::env::operate_parameters &value) {
6445 ostringstream out;
6446 out << value;
6447 return out.str();
6448}
6449
6450inline string to_string(const ::mdbx::env::mode &value) {
6451 ostringstream out;
6452 out << value;
6453 return out.str();
6454}
6455
6456inline string to_string(const ::mdbx::env::durability &value) {
6457 ostringstream out;
6458 out << value;
6459 return out.str();
6460}
6461
6462inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6463 ostringstream out;
6464 out << value;
6465 return out.str();
6466}
6467
6468inline string to_string(const ::mdbx::env::operate_options &value) {
6469 ostringstream out;
6470 out << value;
6471 return out.str();
6472}
6473
6474inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6475 ostringstream out;
6476 out << value;
6477 return out.str();
6478}
6479
6480inline string to_string(const ::MDBX_log_level_t &value) {
6481 ostringstream out;
6482 out << value;
6483 return out.str();
6484}
6485
6486inline string to_string(const ::MDBX_debug_flags_t &value) {
6487 ostringstream out;
6488 out << value;
6489 return out.str();
6490}
6491
6492inline string to_string(const ::mdbx::error &value) {
6493 ostringstream out;
6494 out << value;
6495 return out.str();
6496}
6497
6498inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6499
6500template <> struct hash<::mdbx::slice> {
6501 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6502};
6503
6504template <> struct hash<::mdbx::map_handle> {
6505 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6506};
6507
6508template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6509 using inherited = std::hash<const MDBX_env *>;
6510 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6511};
6512
6513template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6514 using inherited = std::hash<const MDBX_txn *>;
6515 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6516};
6517
6518template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6519 using inherited = std::hash<const MDBX_cursor *>;
6520 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6521};
6522
6523template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6524 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6525 return buffer.hash_value();
6526 }
6527};
6528
6529} // namespace std
6530
6531#if defined(__LCC__) && __LCC__ >= 126
6532#pragma diagnostic pop
6533#endif
6534
6535#ifdef _MSC_VER
6536#pragma warning(pop)
6537#endif
Definition mdbx.h++:1154
Definition mdbx.h++:1144
Definition mdbx.h++:1164
#define MDBX_CXX11_CONSTEXPR
Definition mdbx.h:458
#define MDBX_MAYBE_UNUSED
Definition mdbx.h:524
#define MDBX_CXX14_CONSTEXPR
Definition mdbx.h:477
#define MDBX_NOTHROW_PURE_FUNCTION
The 'pure nothrow' function attribute for optimization.
Definition mdbx.h:274
mode_t mdbx_mode_t
Definition mdbx.h:187
#define LIBMDBX_API
Definition mdbx.h:606
#define LIBMDBX_API_TYPE
Definition mdbx.h:621
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:781
pthread_t mdbx_tid_t
Definition mdbx.h:186
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition mdbx.h:713
int mdbx_filehandle_t
Definition mdbx.h:184
pid_t mdbx_pid_t
Definition mdbx.h:185
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:795
@ MDBX_MAXDATASIZE
Definition mdbx.h:789
@ MDBX_MAX_DBI
Definition mdbx.h:786
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:792
libmdbx build information
Definition mdbx.h:649
Lightweight transparent cache entry structure used by mdbx_cache_get().
Definition mdbx.h:5024
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4507
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4156
Information about the environment.
Definition mdbx.h:2826
Statistics for a table in the environment.
Definition mdbx.h:2780
Information about the transaction.
Definition mdbx.h:4058
libmdbx version information,
Definition mdbx.h:631
LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, MDBX_put_flags_t flags)
Delete current key/data pair.
int(* MDBX_preserve_func)(void *context, MDBX_val *target, const void *src, size_t bytes)
A data preservation callback for using within mdbx_replace_ex().
Definition mdbx.h:5317
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:1649
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)
Replaces item in a table using preservation callback for an original data.
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)
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5038
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:4567
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:1686
@ MDBX_ALLDUPS
Definition mdbx.h:1669
@ MDBX_CURRENT
Definition mdbx.h:1664
@ MDBX_APPENDDUP
Definition mdbx.h:1682
@ MDBX_APPEND
Definition mdbx.h:1677
@ MDBX_UPSERT
Definition mdbx.h:1651
@ MDBX_RESERVE
Definition mdbx.h:1673
@ MDBX_NOOVERWRITE
Definition mdbx.h:1654
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:1730
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:743
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:1849
@ MDBX_GET_CURRENT
Definition mdbx.h:1745
@ MDBX_GET_BOTH
Definition mdbx.h:1738
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1826
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1742
@ MDBX_SET_KEY
Definition mdbx.h:1785
@ MDBX_FIRST_DUP
Definition mdbx.h:1735
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1825
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1750
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1836
@ MDBX_NEXT_NODUP
Definition mdbx.h:1770
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1833
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1834
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1841
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1793
@ MDBX_SET_RANGE
Definition mdbx.h:1788
@ MDBX_LAST_DUP
Definition mdbx.h:1756
@ MDBX_PREV
Definition mdbx.h:1773
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1843
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1844
@ MDBX_LAST
Definition mdbx.h:1753
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1824
@ MDBX_PREV_DUP
Definition mdbx.h:1776
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1832
@ MDBX_SET
Definition mdbx.h:1782
@ MDBX_NEXT
Definition mdbx.h:1759
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1827
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1840
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1767
@ MDBX_PREV_NODUP
Definition mdbx.h:1779
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1842
@ MDBX_NEXT_DUP
Definition mdbx.h:1762
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1835
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1828
@ MDBX_FIRST
Definition mdbx.h:1732
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:736
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1599
@ MDBX_INTEGERDUP
Definition mdbx.h:1623
@ MDBX_DB_ACCEDE
Definition mdbx.h:1641
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1601
@ MDBX_REVERSEKEY
Definition mdbx.h:1604
@ MDBX_DUPFIXED
Definition mdbx.h:1618
@ MDBX_INTEGERKEY
Definition mdbx.h:1614
@ MDBX_REVERSEDUP
Definition mdbx.h:1626
@ MDBX_CREATE
Definition mdbx.h:1629
@ MDBX_DUPSORT
Definition mdbx.h:1607
MDBX_log_level_t
Definition mdbx.h:858
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:917
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:6647
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1857
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1871
@ MDBX_BAD_TXN
Definition mdbx.h:1936
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1950
@ MDBX_SUCCESS
Definition mdbx.h:1859
@ MDBX_NOTFOUND
Definition mdbx.h:1874
@ MDBX_RESULT_TRUE
Definition mdbx.h:1865
@ MDBX_BUSY
Definition mdbx.h:1954
@ MDBX_EINVAL
Definition mdbx.h:2027
@ MDBX_ENOMEM
Definition mdbx.h:2029
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1957
@ MDBX_RESULT_FALSE
Definition mdbx.h:1862
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:2006
@ MDBX_KEYEXIST
Definition mdbx.h:1868
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:2562
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2557
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2560
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1040
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:3073
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2137
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:3012
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:2242
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2238
@ 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:2342
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2146
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2309
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2169
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2274
@ 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:2297
@ 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:2209
@ 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:2196
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2163
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2258
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2175
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2223
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2337
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:3709
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:3093
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:3030
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:4838
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:3754
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_clone(const MDBX_txn *origin, MDBX_txn **in_out_clone, void *context)
Starts a read-only clone of a given 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:1501
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:3974
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:724
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:1512
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1521
@ MDBX_TXN_READWRITE
Definition mdbx.h:1506
@ MDBX_TXN_TRY
Definition mdbx.h:1527
friend class env
Definition mdbx.h++:4027
MDBX_commit_latency commit_latency
Definition mdbx.h++:4061
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:3716
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4496
~txn_managed() noexcept
::MDBX_stat map_stat
Definition mdbx.h++:3879
bool drop_map(const slice &name, bool throw_if_absent=false)
Drop key-value map.
txn & operator=(const txn &) noexcept=default
env & set_sync_period(const duration &period)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
txn_managed start_nested()
Start nested write transaction.
extra_runtime_option
MDBX environment extra runtime options.
Definition mdbx.h++:3423
@ prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h++:3457
@ spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h++:3449
@ spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h++:3451
@ writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h++:3455
@ sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h++:3432
@ dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h++:3443
@ dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h++:3445
@ spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h++:3447
@ merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h++:3453
@ 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++:3437
@ loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h++:3439
@ dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h++:3441
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3650
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3860
env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede=true)
map_handle(const map_handle &) noexcept=default
::MDBX_db_flags_t flags
Definition mdbx.h++:2934
path get_path() const
Return the path that was used for opening the environment.
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4341
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4397
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2903
durability
Durability level.
Definition mdbx.h++:3080
@ lazy_weak_tail
Definition mdbx.h++:3083
@ robust_synchronous
Definition mdbx.h++:3081
@ whole_fragile
Definition mdbx.h++:3084
@ half_synchronous_weak_last
Definition mdbx.h++:3082
void commit_embark_read()
Commit all the operations of a transaction into the database and then start read transaction.
friend constexpr bool operator!=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2930
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3250
map_handle & operator=(const map_handle &) noexcept=default
duration sync_period() const
Gets relative period since the last unsteady commit that used to force flush the data buffers to disk...
move_result seek_multiple_samelength(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4385
estimate_result estimate(move_operation operation, slice &key) const
cache_entry() noexcept
Definition mdbx.h++:2764
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3673
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4360
::MDBX_canary canary
Definition mdbx.h++:3888
env & copy(const wchar_t *destination, bool compactify, bool force_dynamic_size=false)
bool is_readwrite() const
Checks whether the transaction is read-write.
Definition mdbx.h++:3714
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++:4290
void update_current(const slice &value)
Updates value associated with a key at the current cursor position.
env_managed(const wchar_t *pathname, const operate_parameters &, bool accede=true)
move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4354
bool clear_map(const char *name, bool throw_if_absent=false)
constexpr env() noexcept=default
friend constexpr bool operator!=(const env &a, const env &b) noexcept
Definition mdbx.h++:5221
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4363
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.
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
void reset() noexcept
Definition mdbx.h++:2771
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2924
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2904
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4449
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4308
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++:4299
static bool remove(const ::mdbx::filesystem::path &pathname, const remove_mode mode=just_remove)
Removes the environment's files in a proper and multiprocess-safe way.
bool drop_map(const char *name, bool throw_if_absent=false)
Drops key-value map using name.
cursor & operator=(const cursor &) noexcept=default
bool is_same_or_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4125
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3767
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3943
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4331
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4117
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4121
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++:3852
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3177
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4315
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4518
MDBX_txn * handle_
Definition mdbx.h++:3674
void abort()
Abandon all the operations of the transaction instead of saving ones.
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4287
mode
Operation mode.
Definition mdbx.h++:3072
@ write_mapped_io
Definition mdbx.h++:3075
@ nested_transactions
Definition mdbx.h++:3076
@ readonly
Definition mdbx.h++:3073
@ write_file_io
Definition mdbx.h++:3074
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4284
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4243
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3311
operator::mdbx::txn() const
Definition mdbx.h++:4426
MDBX_env * handle_
Definition mdbx.h++:2973
slice reverse_current(size_t value_length)
Reserves and returns the space to storing a value associated with a key at the current cursor positio...
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4347
commit_latency commit_get_latency()
Commit all the operations of a transaction into the database and return latency information.
Definition mdbx.h++:4074
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4113
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4297
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4317
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:2767
void close()
Explicitly closes the cursor.
Definition mdbx.h++:4502
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++:4328
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3711
constexpr txn_managed() noexcept=default
bool clear_map(const slice &name, bool throw_if_absent=false)
move_result next_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4393
env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede=true)
void append(map_handle map, const pair &kv, bool multivalue_order_preserved=true)
Definition mdbx.h++:3991
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3281
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3291
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3293
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3288
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4219
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4302
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4264
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4508
::MDBX_dbi_state_t state
Definition mdbx.h++:2935
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3480
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4476
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++:4069
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++:3256
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4357
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.
move_result get_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4389
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4319
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4316
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4427
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3252
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2927
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3764
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2918
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++:4334
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3317
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3940
env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
friend int compare_position(const cursor &left, const cursor &right, bool ignore_nested)
Definition mdbx.h++:6130
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4007
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++:3263
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++:3845
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2915
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++:3999
friend constexpr bool operator>(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2921
bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
bool is_empty() const
Checks whether the database is empty.
void close(bool dont_sync=false)
Explicitly closes the environment and release the memory map.
move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4369
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4135
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4150
@ multi_exactkey_value_equal
Definition mdbx.h++:4167
@ pair_greater_or_equal
Definition mdbx.h++:4175
@ key_lesser_than
Definition mdbx.h++:4157
@ next
Definition mdbx.h++:4138
@ pair_exact
Definition mdbx.h++:4174
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4168
@ pair_lesser_or_equal
Definition mdbx.h++:4172
@ batch_samelength
Definition mdbx.h++:4178
@ seek_key
Definition mdbx.h++:4152
@ key_lowerbound
Definition mdbx.h++:4154
@ pair_lesser_than
Definition mdbx.h++:4171
@ pair_equal
Definition mdbx.h++:4173
@ key_greater_than
Definition mdbx.h++:4161
@ batch_samelength_next
Definition mdbx.h++:4179
@ multi_find_pair
Definition mdbx.h++:4149
@ key_greater_or_equal
Definition mdbx.h++:4160
@ key_exact
Definition mdbx.h++:4153
@ key_equal
Definition mdbx.h++:4159
@ multi_currentkey_prevvalue
Definition mdbx.h++:4144
@ key_lesser_or_equal
Definition mdbx.h++:4158
@ multi_nextkey_firstvalue
Definition mdbx.h++:4147
@ get_current
Definition mdbx.h++:4140
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4166
@ multi_prevkey_lastvalue
Definition mdbx.h++:4142
@ previous
Definition mdbx.h++:4139
@ last
Definition mdbx.h++:4137
@ pair_greater_than
Definition mdbx.h++:4176
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4165
@ multi_currentkey_firstvalue
Definition mdbx.h++:4143
@ first
Definition mdbx.h++:4136
@ batch_samelength_previous
Definition mdbx.h++:4180
@ multi_currentkey_nextvalue
Definition mdbx.h++:4145
@ seek_and_batch_samelength
Definition mdbx.h++:4181
@ multi_exactkey_value_greater
Definition mdbx.h++:4169
@ multi_currentkey_lastvalue
Definition mdbx.h++:4146
virtual ~env_managed() noexcept
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4293
void insert(const pair &kv)
Definition mdbx.h++:4450
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3708
cursor_managed(const cursor_managed &)=delete
env & operator=(const env &) noexcept=default
env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
void upsert(const pair &kv)
Definition mdbx.h++:4452
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4305
txn_managed & operator=(const txn_managed &)=delete
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3865
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:5219
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4344
bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
env_managed(const env_managed &)=delete
move_result to_current_last_multi(bool throw_notfound=true)
Definition mdbx.h++:4312
value_result try_insert(const pair &kv)
Definition mdbx.h++:4451
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++:4468
constexpr cursor() noexcept=default
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4322
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4366
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3260
MDBX_cursor * handle_
Definition mdbx.h++:4089
~cursor_managed() noexcept
Definition mdbx.h++:4526
MDBX_dbi dbi
Definition mdbx.h++:2902
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4338
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4309
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3722
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++:4350
txn_managed(const txn_managed &)=delete
friend int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept
Definition mdbx.h++:6126
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3308
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3258
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3942
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3941
env_managed(const ::mdbx::filesystem::path &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
Create new or open existing database.
cache_entry & operator=(const cache_entry &) noexcept=default
bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:3873
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4325
bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
move_result to_previous(bool throw_notfound=true)
Definition mdbx.h++:4298
friend class txn
Definition mdbx.h++:2970
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4109
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3254
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3725
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4238
Unmanaged cursor.
Definition mdbx.h++:4087
Managed cursor.
Definition mdbx.h++:4488
Unmanaged database environment.
Definition mdbx.h++:2969
Managed database environment.
Definition mdbx.h++:3589
Unmanaged database transaction.
Definition mdbx.h++:3671
Managed database transaction.
Definition mdbx.h++:4025
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++:5262
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5126
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4796
polymorphic_allocator default_allocator
Definition mdbx.h++:396
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4805
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4887
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base58(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base58 dump of the slice content.
Definition mdbx.h++:5100
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++:5547
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base58 dump of a passed slice.
Definition mdbx.h++:5038
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5029
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5610
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++:5290
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4901
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4626
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++:6002
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6237
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2816
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4783
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:4583
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4881
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5643
class MDBX_MSVC_DECLSPEC_EMPTY_BASES buffer
Definition mdbx.h++:404
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:4773
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4661
void rethrow_captured() const
Definition mdbx.h++:4598
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4781
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6195
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6171
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5255
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5229
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base64 dump of a passed slice.
Definition mdbx.h++:5047
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5965
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5919
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5509
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++:5440
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6139
string< ALLOCATOR > as_hex_string(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of the slice content.
Definition mdbx.h++:5079
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4803
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6075
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base64(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a Base64 dump of the slice content.
Definition mdbx.h++:5105
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4828
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4729
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6243
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:461
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5912
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6087
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5740
void throw_on_failure() const
Definition mdbx.h++:4638
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6318
void update(const slice &key, const slice &value)
Definition mdbx.h++:6314
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:4580
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++:5811
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:4950
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4791
buffer< ALLOCATOR, CAPACITY_POLICY > encode_hex(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:5094
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5612
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5575
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6126
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4927
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5373
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5799
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6304
bool is_clean() const noexcept
Definition mdbx.h++:4591
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2809
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4681
string< ALLOCATOR > as_base58_string(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:5084
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5363
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2813
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:417
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:5415
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5248
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4871
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4605
buffer< ALLOCATOR, CAPACITY_POLICY > hex_decode(bool ignore_spaces=false, const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:5110
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4534
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:4981
buffer< ALLOCATOR, CAPACITY_POLICY > replace_reserve(map_handle map, const slice &key, slice &new_value, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &alloc=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Definition mdbx.h++:6030
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++:5512
void insert(const slice &key, slice value)
Definition mdbx.h++:6265
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6199
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++:5695
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:5175
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:395
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:2797
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++:5552
buffer< ALLOCATOR, CAPACITY_POLICY > base64_decode(bool ignore_spaces=false, const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:5120
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4713
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:6089
~cursor() noexcept
Definition mdbx.h++:6110
~txn() noexcept
Definition mdbx.h++:5594
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5445
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:5074
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6191
uint64_t txnid
Transaction ID and MVCC-snapshot number.
Definition mdbx.h++:413
constexpr void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition mdbx.h++:4809
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6245
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6290
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5240
map_handle map() const
Definition mdbx.h++:6250
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++:5456
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:4587
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6183
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5711
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6203
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2877
void success_or_throw() const
Definition mdbx.h++:4643
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5647
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4843
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5496
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4931
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6130
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6209
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4839
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5246
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4848
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5617
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6308
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5371
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2805
void capture() noexcept
Definition mdbx.h++:4593
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:5056
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++:5776
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5947
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4822
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2948
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6283
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++:5310
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++:5451
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:6063
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5377
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5736
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6081
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++:6039
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5381
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5662
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4935
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6097
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5770
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6149
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++:5286
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++:5815
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5236
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5788
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5937
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4866
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4620
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++:5462
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4893
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4765
bool on_first() const
Definition mdbx.h++:6217
::MDBX_version_info version_info
libmdbx version information,
Definition mdbx.h++:360
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:4801
bool eof() const
Definition mdbx.h++:6215
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5645
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5631
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5433
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6257
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5561
::MDBX_build_info build_info
libmdbx build information
Definition mdbx.h++:364
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:5069
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5584
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4833
bool seek(const slice &key)
Definition mdbx.h++:6207
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5485
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5435
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4855
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++:5354
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5738
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++:5474
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5191
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4816
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6270
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++:6371
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4666
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4614
::MDBX_cmp_func * comparator
Definition mdbx.h++:2947
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5629
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2956
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5131
buffer< ALLOCATOR, CAPACITY_POLICY > base58_decode(bool ignore_spaces=false, const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:5115
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++:5466
::mdbx_filehandle_t filehandle
Definition mdbx.h++:419
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++:5332
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5197
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4923
char8_t byte
The byte-like type that don't presumes aliases for pointers as does the char.
Definition mdbx.h++:345
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5793
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6349
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5385
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5024
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5637
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5899
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:378
constexpr bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition mdbx.h++:4628
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:5051
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:5033
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6177
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4908
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:5042
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:5060
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5959
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5187
~env() noexcept
Definition mdbx.h++:5207
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2778
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5827
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4622
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4811
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++:6044
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5943
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4860
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2781
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5554
::mdbx::filesystem::path path
Definition mdbx.h++:443
bool on_last_multival() const
Definition mdbx.h++:6223
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5427
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5894
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5421
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++:5266
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5517
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6095
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5361
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5674
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2801
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5664
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5479
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4535
bool on_first_multival() const
Definition mdbx.h++:6221
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5886
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4656
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:4963
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4876
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5397
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5933
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5244
string< ALLOCATOR > as_base64_string(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:5089
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6330
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:5649
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6187
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4767
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4789
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++:5172
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5540
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:5978
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4618
bool on_last() const
Definition mdbx.h++:6219
buffer< ALLOCATOR, CAPACITY_POLICY > extract(map_handle map, const slice &key, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &alloc=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Removes and return a value of the key.
Definition mdbx.h++:6009
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:439
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:5409
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5490
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++:6239
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:5065
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5223
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5680
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4612
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5003
constexpr bool is_success() const noexcept
Definition mdbx.h++:4616
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6336
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:4976
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5582
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5183
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5668
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++:5727
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++:5865
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5782
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4775
@ multi_reverse_samelength
Definition mdbx.h++:2849
@ multi_samelength
Definition mdbx.h++:2834
@ multi_ordinal
Definition mdbx.h++:2841
@ msgpack
Definition mdbx.h++:2864
@ single
Definition mdbx.h++:2817
@ multi
Definition mdbx.h++:2819
@ multi_reverse
Definition mdbx.h++:2826
@ upsert
Insert or update.
Definition mdbx.h++:2958
@ update
Update existing, don't insert new.
Definition mdbx.h++:2959
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2957
@ continue_loop
Definition mdbx.h++:2778
@ exit_loop
Definition mdbx.h++:2778
@ usual
Definition mdbx.h++:2782
@ ordinal
Definition mdbx.h++:2787
@ reverse
Definition mdbx.h++:2784
@ msgpack
Definition mdbx.h++:2792
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2901
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2412
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2125
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++:2003
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2030
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:700
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2095
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1985
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:713
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:676
static buffer base64_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes Base64 dump from the slice content to returned buffer.
Definition mdbx.h++:2267
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2308
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:667
buffer_pair_spec(const txn &transacton, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2698
const slice source
Definition mdbx.h++:1258
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base58 dump, and therefore there could be dec...
static buffer key_from(const double *ieee754_64bit)
Definition mdbx.h++:2633
static buffer hex(const POD &pod, bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a hexadecimal dump of the given pod.
Definition mdbx.h++:2216
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:735
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:2046
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2339
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2043
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2421
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2291
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++:2018
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2152
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2392
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2305
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2037
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2157
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2665
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1561
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1031
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1235
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2343
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2070
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2522
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2066
buffer & append(const byte c)
Definition mdbx.h++:2476
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2316
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:753
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1012
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2321
buffer & operator=(const buffer &src)
Definition mdbx.h++:2438
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1030
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2544
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:2012
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2707
constexpr int64_t as_int64() const
Definition mdbx.h++:1037
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2063
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2623
static buffer hex(const slice &source, bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a hexadecimal dump of the slice content.
Definition mdbx.h++:2198
const bool ignore_spaces
Definition mdbx.h++:1338
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:857
buffer base58_decode(bool ignore_spaces=false, const allocator_type &alloc=allocator_type()) const
Decodes Base58 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2280
buffer hex_decode(bool ignore_spaces=false, const allocator_type &alloc=allocator_type()) const
Decodes hexadecimal dump from the buffer content to new returned buffer.
Definition mdbx.h++:2274
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2193
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2486
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2236
bool is_printable(bool disable_utf8=false) const noexcept
Checks whether the content of the slice is printable.
int128_t as_int128_adapt() const
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from Base64 dump from a passed slice.
pair & operator=(stl_pair &&couple)
Definition mdbx.h++:1100
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Definition mdbx.h++:770
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2676
constexpr int16_t as_int16() const
Definition mdbx.h++:1039
slice value
Definition mdbx.h++:1064
::std::ostream & output(::std::ostream &out) const
Output Base64 dump of passed slice to the std::ostream.
buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2678
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2417
static buffer base58_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:2260
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2643
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1206
buffer base64_decode(bool ignore_spaces=false, const allocator_type &alloc=allocator_type()) const
Decodes Base64 dump from the buffer content to new returned buffer.
Definition mdbx.h++:2286
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2190
slice value
Definition mdbx.h++:1078
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2669
::std::ostream & output(::std::ostream &out) const
Output hexadecimal dump of passed slice to the std::ostream.
pair_result(const pair_result &) noexcept=default
allocation_aware_details::swap_alloc< struct silo, allocator_type > swap_alloc
Definition mdbx.h++:1980
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2649
const slice source
Definition mdbx.h++:1337
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2687
const slice source
Definition mdbx.h++:1173
static buffer base58(const POD &pod, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base58 dump of the given pod.
Definition mdbx.h++:2224
constexpr buffer & assign(buffer &&src) noexcept(allocation_aware_details::move_assign_alloc< silo, allocator_type >::is_nothrow())
Definition mdbx.h++:2380
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++:1320
const unsigned wrap_width
Definition mdbx.h++:1175
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2447
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2629
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:727
const slice & slice() const noexcept
Definition mdbx.h++:2661
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2400
const bool ignore_spaces
Definition mdbx.h++:1304
constexpr POD as_pod() const
Definition mdbx.h++:1014
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from Base58 dump from a passed slice.
constexpr pair_result() noexcept
Definition mdbx.h++:1127
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++:1404
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2682
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2388
constexpr buffer(const buffer &src)
Definition mdbx.h++:2135
static buffer hex_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes hexadecimal dump from the slice content to returned buffer.
Definition mdbx.h++:2253
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1027
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2461
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2083
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2635
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2331
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1176
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2684
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2518
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2615
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1526
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2168
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:749
std::pair< slice, slice > stl_pair
Definition mdbx.h++:1077
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2542
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:1997
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
@ pettiness_threshold
Definition mdbx.h++:1514
@ extra_inplace_storage
Definition mdbx.h++:1512
@ max_reserve
Definition mdbx.h++:1515
@ inplace_storage_size_rounding
Definition mdbx.h++:1513
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2647
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:690
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1339
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2442
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2514
constexpr int8_t as_int8() const
Definition mdbx.h++:1040
constexpr ::std::span< char > chars()
Definition mdbx.h++:702
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1059
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1277
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2120
buffer(const txn &transaction, const slice &src, const allocator_type &alloc=allocator_type())
static constexpr size_t round(const size_t value)
Definition mdbx.h++:1518
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1249
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++:1395
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:1066
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2627
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1366
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2248
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2163
const slice source
Definition mdbx.h++:1216
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:1080
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2406
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++:1989
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2651
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:701
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1378
buffer_pair_spec & operator=(buffer_pair_spec &&src)
Definition mdbx.h++:2711
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2577
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++:1210
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1562
uint8_t as_uint8_adapt() const
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:681
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2641
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2114
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2444
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2727
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2494
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2565
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2526
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++:1356
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:732
constexpr ::std::basic_string_view< CHAR, T > string_view() const noexcept
Return a string_view that references the same data as this slice.
Definition mdbx.h++:757
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1327
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:646
static buffer base64(const POD &pod, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base64 dump of the given pod.
Definition mdbx.h++:2231
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2657
slice inherited
Definition mdbx.h++:1555
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:1128
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1305
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2653
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by hexadecimal dump of a passed slice.
static buffer key_from(const uint32_t unsigned_int32)
Definition mdbx.h++:2655
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2310
static constexpr pair invalid() noexcept
Definition mdbx.h++:1093
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2103
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2396
bool done
Definition mdbx.h++:1126
::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++:1252
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:699
pair & operator=(pair &&couple)
Definition mdbx.h++:1084
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:715
allocation_aware_details::move_assign_alloc< silo, allocator_type > move_assign_alloc
Definition mdbx.h++:1978
const bool uppercase
Definition mdbx.h++:1174
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1979
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2050
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2359
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2484
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2530
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2695
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2057
const bool ignore_spaces
Definition mdbx.h++:1377
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1261
pair(const pair &) noexcept=default
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2609
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:1007
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base64 dump, and therefore there could be dec...
slice & operator=(const slice &) noexcept=default
uint128_t as_uint128_adapt() const
constexpr int128_t as_int128() const
Definition mdbx.h++:1035
slice key
Definition mdbx.h++:1078
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2468
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:1079
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2701
const slice source
Definition mdbx.h++:1376
pair_result & operator=(const pair_result &) noexcept=default
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2466
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1294
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2659
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2458
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2667
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from hexadecimal dump from a passed slice.
constexpr int32_t as_int32() const
Definition mdbx.h++:1038
static buffer base64(const slice &source, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base64 dump of the slice content.
Definition mdbx.h++:2210
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2139
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1557
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2631
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2023
pair & operator=(const stl_pair &couple)
Definition mdbx.h++:1095
int64_t as_int64_adapt() const
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2639
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2026
static buffer base58(const slice &source, unsigned wrap_width=0, const allocator_type &alloc=allocator_type())
Returns a new buffer with a Base58 dump of the slice content.
Definition mdbx.h++:2205
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2335
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2693
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1032
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2668
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2148
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1982
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2534
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2554
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1029
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2175
buffer(const ::std::basic_string< CHAR, T, A > &&)=delete
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2689
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2637
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid hexadecimal dump, and therefore there could b...
buffer encode_base58(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2243
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2591
const unsigned wrap_width
Definition mdbx.h++:1217
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++:2510
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2187
const unsigned wrap_width
Definition mdbx.h++:1259
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2440
uint32_t as_uint32_adapt() const
constexpr bool is_valid() const noexcept
Checks the slice is not refers to null address or has zero length.
Definition mdbx.h++:1004
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2077
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by Base64 dump of passed slice.
buffer & append_producer(PRODUCER &producer)
Definition mdbx.h++:2496
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2704
constexpr slice(const ::std::basic_string_view< CHAR, T > &sv)
Create a slice that refers to the same contents as "string_view".
Definition mdbx.h++:708
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2503
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2143
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2620
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2666
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++:1298
uint64_t as_uint64_adapt() const
constexpr buffer_pair_spec() noexcept=default
constexpr to_base58(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1219
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2131
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:710
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for hexadecimal dump of a passed slice.
Definition mdbx.h++:1191
bool done
Definition mdbx.h++:1065
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++:1303
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:2006
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2088
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1553
Definition mdbx.h++:2664
Type tag for delivered buffer template classes.
Definition mdbx.h++:1549
Definition mdbx.h++:1510
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1336
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1375
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1302
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:1076
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:1125
References a data located outside the slice.
Definition mdbx.h++:641
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1215
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1257
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1172
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:1063
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:559
remote_media(const ::mdbx::error &)
dangling_map_id(const ::mdbx::error &)
constexpr friend bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4614
fatal(const ::mdbx::error &) noexcept
reader_slot_busy(const ::mdbx::error &)
exception(const exception &)=default
::std::string message() const
Returns message for any errors.
not_found(const ::mdbx::error &)
operation_not_permitted(const ::mdbx::error &)
key_exists(const ::mdbx::error &)
permission_denied_or_not_writeable(const ::mdbx::error &)
void throw_exception() const
fatal(const exception &src) noexcept
Definition mdbx.h++:558
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++:527
db_full(const ::mdbx::error &)
duplicated_lck_file(const ::mdbx::error &)
const ::mdbx::error error() const noexcept
Definition mdbx.h++:549
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++:560
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++:561
fatal & operator=(const fatal &)=default
max_readers_reached(const ::mdbx::error &)
db_version_mismatch(const ::mdbx::error &)
exception_thunk() noexcept=default
exception & operator=(const exception &)=default
exception(const ::mdbx::error &) noexcept
db_unable_extend(const ::mdbx::error &)
constexpr friend bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4612
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++:486
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:471
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:567
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:4777
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:4781
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition mdbx.h++:191
#define MDBX_MSVC_DECLSPEC_EMPTY_BASES
Definition mdbx.h++:134
#define MDBX_CXX17_FALLTHROUGH
Definition mdbx.h++:249
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:289
#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES,...)
Definition mdbx.h++:124
#define MDBX_LIKELY(cond)
Definition mdbx.h++:224
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:201
#define MDBX_UNLIKELY(cond)
Definition mdbx.h++:232
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:180
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:219
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:240
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:200
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:255
The libmdbx C API header file.
Definition mdbx.h++:1412
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1414
The libmdbx C++ API namespace.
Definition mdbx.h++:322
STL namespace.
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6419
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1648
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1650
byte lastbyte_
Definition mdbx.h++:1649
Definition mdbx.h++:4200
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4202
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4201
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4204
Definition mdbx.h++:4188
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++:4192
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4190
Tagged type for output to std::ostream.
Definition mdbx.h++:3021
intptr_t bytes
Definition mdbx.h++:3022
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3023
Database geometry for size management.
Definition mdbx.h++:2997
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3045
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3057
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3004
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3000
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3003
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3012
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3001
@ default_value
Means "keep current or use default".
Definition mdbx.h++:2999
@ kB
bytes (0x03E8)
Definition mdbx.h++:3002
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3011
@ KiB
bytes (0x0400)
Definition mdbx.h++:3010
constexpr geometry() noexcept
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++:3048
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3033
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3051
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3028
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++:3064
Operate options.
Definition mdbx.h++:3101
bool disable_readahead
Definition mdbx.h++:3110
bool enable_validation
Definition mdbx.h++:3114
bool no_sticky_threads
Definition mdbx.h++:3103
constexpr operate_options() noexcept
Definition mdbx.h++:3115
bool disable_clear_memory
Definition mdbx.h++:3112
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3108
constexpr operate_options(const operate_options &) noexcept=default
bool nested_write_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3106
operate_options(MDBX_env_flags_t) noexcept
Operate parameters.
Definition mdbx.h++:3123
env::durability durability
Definition mdbx.h++:3131
env::operate_options options
Definition mdbx.h++:3133
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++:3137
static env::mode mode_from_flags(MDBX_env_flags_t) noexcept
constexpr operate_parameters & operator=(const operate_parameters &) noexcept=default
unsigned max_readers
The maximum number of threads/reader slots for the environment. Zero means default value.
Definition mdbx.h++:3129
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3132
env::mode mode
Definition mdbx.h++:3130
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++:3126
constexpr operate_parameters() noexcept
Definition mdbx.h++:3135
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3503
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3506
uint64_t transaction_lag
Definition mdbx.h++:3509
size_t bytes_used
Definition mdbx.h++:3513
uint64_t transaction_id
Definition mdbx.h++:3507
int slot
The reader lock table slot number.
Definition mdbx.h++:3504
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3505
size_t bytes_retained
Definition mdbx.h++:3516
Garbage reclaiming options.
Definition mdbx.h++:3088
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
bool coalesce
Definition mdbx.h++:3092
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3093
bool lifo
Definition mdbx.h++:3090
Additional parameters for creating a new database.
Definition mdbx.h++:3612
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3614
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3615
env::geometry geometry
Definition mdbx.h++:3613
Definition mdbx.h++:2936
map_handle::state state
Definition mdbx.h++:2938
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2937
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6524
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6520
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6519
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6510
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6509
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6505
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6501
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6514
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6515
capacity_holder capacity_
Definition mdbx.h++:1654
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1687
allocator_pointer stub_ptr_
Definition mdbx.h++:1629
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1666
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1707
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1658
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1673
inplace_flag_holder inplace_
Definition mdbx.h++:1655
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1657
allocator_pointer allocated_ptr_
Definition mdbx.h++:1653
size_t stub_capacity_bytes_
Definition mdbx.h++:1630
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1726
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1643
size_t bytes_
Definition mdbx.h++:1644
constexpr const byte * address() const noexcept
Definition mdbx.h++:1720
constexpr bin() noexcept
Definition mdbx.h++:1701
@ inplace_size
Definition mdbx.h++:1638
@ inplace_signature_limit
Definition mdbx.h++:1635
@ inplace_size_rounding
Definition mdbx.h++:1637
constexpr byte * address() noexcept
Definition mdbx.h++:1723
@ lastbyte_poison
Definition mdbx.h++:1633
@ lastbyte_inplace_signature
Definition mdbx.h++:1633
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1716
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1675