A fast and reliable embedded key-value ACID storage engine without WAL.
Version 0.15.0.98 (2026-09-30T12:43:01Z)
Loading...
Searching...
No Matches
mdbx.h++
Go to the documentation of this file.
1
25
26#pragma once
27
28//
29// Tested with, since 2026:
30// - Elbrus LCC >= 1.28 (http://www.mcst.ru/lcc);
31// - GNU C++ >= 11.3;
32// - CLANG >= 14.0;
33// - MSVC >= 19.44 (Visual Studio 2022 toolchain v143),
34// before 2026:
35// - Elbrus LCC >= 1.23 (http://www.mcst.ru/lcc);
36// - GNU C++ >= 4.8;
37// - CLANG >= 3.9;
38// - MSVC >= 14.0 (Visual Studio 2015),
39// but 19.2x could hang due optimizer bug;
40// - AppleClang, but without C++20 concepts.
41//
42
43/* Workaround for modern libstdc++ with CLANG < 4.x */
44#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4
45#define __GLIBCXX_BITSIZE_INT_N_0 128
46#define __GLIBCXX_TYPE_INT_N_0 __int128
47#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
48
49#if !defined(__cplusplus) || __cplusplus < 201103L
50#if !defined(_MSC_VER) || _MSC_VER < 1900
51#error "C++11 compiler or better is required"
52#elif _MSC_VER >= 1910
53#error "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
54#endif /* MSVC is mad and don't define __cplusplus properly */
55#endif /* __cplusplus < 201103L */
56
57#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT && !defined(__CODEGEARC__)
58#error "CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
59#endif /* Windows */
60
61#ifndef __has_include
62#define __has_include(header) (0)
63#endif /* __has_include */
64
65#if __has_include(<version>)
66#include <version>
67#endif /* <version> */
68
69/* Disable min/max macros from C' headers */
70#ifndef NOMINMAX
71#define NOMINMAX
72#endif
73
74#include <algorithm> // for std::min/max
75#include <cassert> // for assert()
76#include <climits> // for CHAR_BIT
77#include <cstring> // for std::strlen, str:memcmp
78#include <exception> // for std::exception_ptr
79#include <ostream> // for std::ostream
80#include <sstream> // for std::ostringstream
81#include <stdexcept> // for std::invalid_argument
82#include <string> // for std::string
83#include <type_traits> // for std::is_pod<>, etc.
84#include <utility> // for std::make_pair
85#include <vector> // for std::vector<> as template args
86
87#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
88#include <memory_resource>
89#endif
90
91#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
92#include <string_view>
93#endif
94
95#ifndef MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM
96#ifdef MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
97/* backward compatibility with the old misspelled name */
98#define MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
99#elif defined(INCLUDE_STD_FILESYSTEM_EXPERIMENTAL)
100#define MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM 1
101#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && __cplusplus >= 201703L
102#define MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM 0
103#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
104 (defined(_MSC_VER) && defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && __cplusplus >= 201403L))
105#if defined(__cpp_lib_experimental_filesystem) && __cpp_lib_experimental_filesystem >= 201406L
106#define MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM 1
107#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && __has_include(<experimental/filesystem>)
108#define MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM 1
109#else
110#define MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM 0
111#endif
112#else
113#define MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM 0
114#endif
115#endif /* MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM */
116
117#if MDBX_USING_CXX_EXPERIMENTAL_FILESYSTEM
118#include <experimental/filesystem>
119#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
120#include <filesystem>
121#endif
122
123#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
124#include <span>
125#endif
126
127#if !defined(_MSC_VER)
128#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class API_ATTRIBUTES __VA_ARGS__
129#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class __VA_ARGS__
130#else
131#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class __VA_ARGS__
132#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class API_ATTRIBUTES __VA_ARGS__
133#endif
134
135#if defined(_MSC_VER) && _MSC_VER >= 1900
136#define MDBX_MSVC_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
137#else
138#define MDBX_MSVC_DECLSPEC_EMPTY_BASES /* nope */
139#endif /* _MSC_VER >= 1900 */
140
141#if __cplusplus >= 201103L
142#include <chrono>
143#include <ratio>
144#endif
145
146#include "mdbx.h"
147
148#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
149 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
150 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
151 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
152#include <bit>
153#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
154#if 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#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
159#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
160#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
161#define __BYTE_ORDER__ _BYTE_ORDER
162#else
163#define __ORDER_LITTLE_ENDIAN__ 1234
164#define __ORDER_BIG_ENDIAN__ 4321
165#if defined(__LITTLE_ENDIAN__) || (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || defined(__ARMEL__) || \
166 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
167 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || defined(__elbrus_4c__) || defined(__elbrus_8c__) || \
168 defined(__bfin__) || defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
169 defined(__ia64) || defined(_M_IA64) || defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
170 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || defined(__WINDOWS__)
171#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
172#elif defined(__BIG_ENDIAN__) || (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || defined(__ARMEB__) || \
173 defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
174 defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
175 defined(__sparc__) || defined(__sparc) || defined(__370__) || defined(__THW_370__) || defined(__s390__) || \
176 defined(__s390x__) || defined(__SYSC_ZARCH__)
177#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
178#endif
179#endif
180#endif /* Byte Order */
181
183#if defined(DOXYGEN)
184#define MDBX_CXX17_CONSTEXPR constexpr
185#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
186 ((defined(_MSC_VER) && _MSC_VER >= 1915) || (defined(__clang__) && __clang_major__ > 5) || \
187 (defined(__GNUC__) && __GNUC__ > 7) || (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
188#define MDBX_CXX17_CONSTEXPR constexpr
189#else
190#define MDBX_CXX17_CONSTEXPR inline
191#endif /* MDBX_CXX17_CONSTEXPR */
192
194#if defined(DOXYGEN)
195#define MDBX_CXX20_CONSTEXPR constexpr
196#elif defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L && \
197 defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
198#define MDBX_CXX20_CONSTEXPR constexpr
199#else
200#define MDBX_CXX20_CONSTEXPR inline
201#endif /* MDBX_CXX20_CONSTEXPR */
202
203#if MDBX_CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
204#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
205#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
206#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
207#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
208#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
209#else
210#define MDBX_CXX01_CONSTEXPR_ENUM inline
211#define MDBX_CXX11_CONSTEXPR_ENUM inline
212#define MDBX_CXX14_CONSTEXPR_ENUM inline
213#define MDBX_CXX17_CONSTEXPR_ENUM inline
214#define MDBX_CXX20_CONSTEXPR_ENUM inline
215#endif /* MDBX_CONSTEXPR_ENUM_FLAGS_OPERATIONS */
216
218#if defined(CONSTEXPR_ASSERT)
219#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
220#elif defined(NDEBUG) && (!defined(MDBX_CHECKING) || !MDBX_CHECKING) && (!defined(MDBX_DEBUG) || !MDBX_DEBUG)
221#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
222#else
223#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
224#endif /* MDBX_CONSTEXPR_ASSERT */
225
227#if defined(DOXYGEN)
228#define MDBX_IF_CONSTEXPR constexpr
229#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
230#define MDBX_IF_CONSTEXPR constexpr
231#else
232#define MDBX_IF_CONSTEXPR
233#endif /* MDBX_IF_CONSTEXPR */
234
235#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
236 __cplusplus >= 201703L
237#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
238#else
239#define MDBX_CXX17_FALLTHROUGH
240#endif /* MDBX_CXX17_FALLTHROUGH */
241
242#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
243#define MDBX_CXX20_LIKELY [[likely]]
244#else
245#define MDBX_CXX20_LIKELY
246#endif /* MDBX_CXX20_LIKELY */
247
248#ifndef MDBX_CXX20_UNLIKELY
249#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
250#define MDBX_CXX20_UNLIKELY [[unlikely]]
251#else
252#define MDBX_CXX20_UNLIKELY
253#endif
254#endif /* MDBX_CXX20_UNLIKELY */
255
257#ifndef MDBX_NODISCARD
258#if defined(DOXYGEN) || __cplusplus >= 201703L
259#define MDBX_NODISCARD [[nodiscard]]
260#else
261#define MDBX_NODISCARD /* nope */
262#endif
263#endif /* MDBX_NODISCARD */
264
265#ifndef MDBX_HAVE_CXX20_CONCEPTS
266#if defined(__cpp_concepts) && __cpp_concepts >= 202002L && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
267#include <concepts>
268#define MDBX_HAVE_CXX20_CONCEPTS 1
269#elif defined(DOXYGEN)
270#define MDBX_HAVE_CXX20_CONCEPTS 1
271#else
272#define MDBX_HAVE_CXX20_CONCEPTS 0
273#endif /* <concepts> */
274#endif /* MDBX_HAVE_CXX20_CONCEPTS */
275
276#ifndef MDBX_CXX20_CONCEPT
277#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
278#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
279#else
280#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
281#endif
282#endif /* MDBX_CXX20_CONCEPT */
283
284#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
285#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
286#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
287#else
288#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
289 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
290#endif
291#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
292
293#ifdef _MSC_VER
294#pragma warning(push, 4)
295#pragma warning(disable : 4127) /* conditional expression is constant */
296#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
297 be used by clients of 'mdbx::BAR' */
298#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
299 base for dll-interface 'mdbx::BAR' */
300/* MSVC is mad and can generate this warning for its own intermediate
301 * automatically generated code, which becomes unreachable after some kinds of
302 * optimization (copy elision, etc). */
303#pragma warning(disable : 4702) /* unreachable code */
304#endif /* _MSC_VER (warnings) */
305
306#if defined(__LCC__) && __LCC__ >= 126
307#pragma diagnostic push
308#if __LCC__ < 127
309#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
310 appearing in a constant expression `true` */
311#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
312 appearing in a constant expression `false` */
313#endif
314#endif /* E2K LCC (warnings) */
315
316//------------------------------------------------------------------------------
319namespace mdbx {
320
323
341#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
342using byte = char8_t;
343#else
344// Avoid `std::byte` since it doesn't add features but inconvenient restrictions.
345using byte = unsigned char;
346#endif /* __cpp_char8_t >= 201811*/
347
348#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
349using endian = ::std::endian;
350#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
351enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
352#else
353#error "Please use a C++ compiler provides byte order information or C++20 support"
354#endif /* Byte Order enum */
355
364
366static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
367
369static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
371static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
372
375using legacy_allocator = ::std::string::allocator_type;
376
379#if defined(DOXYGEN)
380#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
381#elif !defined(MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR)
382#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && \
383 (!defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI)
384#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
385#else
386#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 0
387#endif
388#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
389
390#if defined(DOXYGEN) || MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
392using polymorphic_allocator = ::std::pmr::string::allocator_type;
394#else
396#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
397
398struct slice;
400template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
402class env;
403class env_managed;
404class txn;
405class txn_managed;
406class cursor;
407class cursor_managed;
408
410using txnid = uint64_t;
411
413template <class ALLOCATOR = default_allocator>
414using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
415
417#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
418#ifdef _MSC_VER
419namespace filesystem = ::std::experimental::filesystem::v1;
420#else
421namespace filesystem = ::std::experimental::filesystem;
422#endif
423#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
424#elif defined(DOXYGEN) || \
425 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
426 __cpp_lib_string_view >= 201606L && \
427 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
428 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
429 (!defined(_MSC_VER) || __cplusplus >= 201703L)
430namespace filesystem = ::std::filesystem;
436#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
437#endif /* MDBX_STD_FILESYSTEM_PATH */
438
439#ifdef MDBX_STD_FILESYSTEM_PATH
441using path_string = MDBX_STD_FILESYSTEM_PATH::string_type;
442#elif defined(_WIN32) || defined(_WIN64)
443using path = ::std::wstring;
444using path_string = path;
445#else
446using path = ::std::string;
447using path_string = path;
448#endif /* mdbx::path */
449using path_char = path_string::value_type;
450
451#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
452#ifndef MDBX_U128_TYPE
453#define MDBX_U128_TYPE __uint128_t
454#endif /* MDBX_U128_TYPE */
455#ifndef MDBX_I128_TYPE
456#define MDBX_I128_TYPE __int128_t
457#endif /* MDBX_I128_TYPE */
458#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
459
460#if __cplusplus >= 201103L || defined(DOXYGEN)
462using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
463#endif /* Duration for C++11 */
464
467
473 ::std::exception_ptr captured_;
474
475public:
476 exception_thunk() noexcept = default;
479 exception_thunk &operator=(const exception_thunk &) = delete;
480 exception_thunk &operator=(exception_thunk &&) = delete;
481 inline bool is_clean() const noexcept;
482 inline void capture() noexcept;
483 inline void rethrow_captured() const;
484};
485
488 MDBX_error_t code_;
489 inline error &operator=(MDBX_error_t error_code) noexcept;
490
491public:
492 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
493 error(const error &) = default;
494 error(error &&) = default;
495 error &operator=(const error &) = default;
496 error &operator=(error &&) = default;
497
498 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
499 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
500
501 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
502 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
503 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
504 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
505
507 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
508
510 const char *what() const noexcept;
511
513 ::std::string message() const;
514
516 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() 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 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
524 static inline void success_or_throw(MDBX_error_t error_code);
525 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
526 static inline void throw_on_failure(int error_code);
527 static inline bool boolean_or_throw(int error_code);
528 static inline void success_or_throw(int error_code, const exception_thunk &);
529 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
530};
531
534class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
535 using base = ::std::runtime_error;
536 ::mdbx::error error_;
537
538public:
539 exception(const ::mdbx::error &) noexcept;
540 exception(const exception &) = default;
541 exception(exception &&) = default;
542 exception &operator=(const exception &) = default;
544 virtual ~exception() noexcept;
545 const ::mdbx::error error() const noexcept { return error_; }
546};
547
550 using base = exception;
551
552public:
553 fatal(const ::mdbx::error &) noexcept;
554 fatal(const exception &src) noexcept : fatal(src.error()) {}
555 fatal(exception &&src) noexcept : fatal(src.error()) {}
556 fatal(const fatal &src) noexcept : fatal(src.error()) {}
557 fatal(fatal &&src) noexcept : fatal(src.error()) {}
558 fatal &operator=(fatal &&) = default;
559 fatal &operator=(const fatal &) = default;
560 virtual ~fatal() noexcept;
561};
562
563#define MDBX_DECLARE_EXCEPTION(NAME) \
564 struct LIBMDBX_API_TYPE NAME : public exception { \
565 NAME(const ::mdbx::error &); \
566 virtual ~NAME() noexcept; \
567 }
601#undef MDBX_DECLARE_EXCEPTION
602
605[[noreturn]] LIBMDBX_API void throw_out_range();
609
610static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
611 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
612 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
613 return bytes;
614}
615
616static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
617 return check_length(check_length(headroom) + check_length(payload));
618}
619
620MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
621 return check_length(check_length(headroom, payload) + check_length(tailroom));
622}
623
625
626//------------------------------------------------------------------------------
627
630
642
643 enum : size_t { max_length = MDBX_MAXDATASIZE, npos = size_t(-1) };
644
646 MDBX_CXX11_CONSTEXPR slice() noexcept;
647
649 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
650
652 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
653
655 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
656 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
657 }
658
659 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
660
663 template <class CHAR, class T, class A>
664 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
665 : slice(str.data(), str.length() * sizeof(CHAR)) {}
666
668 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
670 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
671
672#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
673 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
674 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
675 "Must be a standard layout type!");
676 }
677
678 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
679 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
680 "Must be a standard layout type!");
681 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
683 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
685 }
686
687 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
688 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
689 "Must be a standard layout type!");
690 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
692 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
694 }
695
696 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
697 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
698 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
699 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
700#endif /* __cpp_lib_span >= 202002L */
701
702#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
704 template <class CHAR, class T>
705 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv)
706 : slice(sv.data(), sv.size() * sizeof(CHAR)) {}
707
708 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
709#endif /* __cpp_lib_string_view >= 201606L */
710
711 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
712
713 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
714 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
715 "Must be a standard layout type!");
716 return slice(&pod, sizeof(pod));
717 }
718
719 inline slice &assign(const void *ptr, size_t bytes);
720 inline slice &assign(const slice &src) noexcept;
721 inline slice &assign(const ::MDBX_val &src);
722 inline slice &assign(slice &&src) noexcept;
723 inline slice &assign(::MDBX_val &&src);
724 inline slice &assign(const void *begin, const void *end);
725 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
726 return assign(str.data(), str.size() * sizeof(CHAR));
727 }
728 inline slice &assign(const char *c_str);
729#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
730 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
731 return assign(view.data(), view.size() * sizeof(CHAR));
732 }
733 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
734 assign(view);
735 view = {};
736 return *this;
737 }
738#endif /* __cpp_lib_string_view >= 201606L */
739
740 slice &operator=(const slice &) noexcept = default;
741 inline slice &operator=(slice &&src) noexcept;
742 inline slice &operator=(::MDBX_val &&src);
743 operator MDBX_val *() noexcept { return this; }
744 operator const MDBX_val *() const noexcept { return this; }
745
746#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
747 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
748 return assign(view);
749 }
750
751 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
752
754 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
755 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
756 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
757 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
758 }
759
761 template <class CHAR, class T>
762 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
763 return this->string_view<CHAR, T>();
764 }
765#endif /* __cpp_lib_string_view >= 201606L */
766
767 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
768 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
769 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
770 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
771 }
772
773 template <class CHAR, class T, class ALLOCATOR>
774 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
776 }
777
779 template <class ALLOCATOR = default_allocator>
780 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
781 const ALLOCATOR &alloc = ALLOCATOR()) const;
782
785 template <class ALLOCATOR = default_allocator>
786 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
787
790 template <class ALLOCATOR = default_allocator>
791 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
792
794 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
795 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
796 const ALLOCATOR &alloc = ALLOCATOR()) const;
797
800 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
801 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
802 const ALLOCATOR &alloc = ALLOCATOR()) const;
803
806 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
807 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
808 const ALLOCATOR &alloc = ALLOCATOR()) const;
809
811 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
812 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
813 const ALLOCATOR &alloc = ALLOCATOR()) const;
814
817 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
818 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
819 const ALLOCATOR &alloc = ALLOCATOR()) const;
820
823 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
824 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
825 const ALLOCATOR &alloc = ALLOCATOR()) const;
826
832 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
833
838 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
839
845 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
846
852 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
853
854#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
855 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
856 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
857 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
858 *this = view;
859 view = temp;
860 }
861#endif /* __cpp_lib_string_view >= 201606L */
862
863 MDBX_CXX20_CONSTEXPR void swap(slice &other) noexcept {
864 auto temp = other;
865 other = *this;
866 *this = temp;
867 }
868
870 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
871 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
872
874 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
875 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
876
878 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
879 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
880
882 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
883 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
884
886 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
887 MDBX_CXX11_CONSTEXPR void *data() noexcept;
888
891 MDBX_CXX11_CONSTEXPR const byte *end() const noexcept;
893 MDBX_CXX11_CONSTEXPR byte *end() noexcept;
894
896 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
897
899 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
900
902 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
903
905 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
906
908 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
909
911 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
912
914 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
915
919 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
920
922 MDBX_CXX14_CONSTEXPR void clear() noexcept;
923
926 inline void remove_prefix(size_t n) noexcept;
927
930 inline void remove_suffix(size_t n) noexcept;
931
934 inline void safe_remove_prefix(size_t n);
935
938 inline void safe_remove_suffix(size_t n);
939
941 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
942
944 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
945
948 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
949
952 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
953
956 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
957
960 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
961
964 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
965
967 MDBX_CXX11_CONSTEXPR const byte *begin() const noexcept;
969 MDBX_CXX11_CONSTEXPR byte *begin() noexcept;
970
973 MDBX_CXX11_CONSTEXPR byte front() const noexcept { return byte_ptr()[0]; }
974
977 MDBX_CXX11_CONSTEXPR byte back() const noexcept { return byte_ptr()[size() - 1]; }
978
981 MDBX_CXX14_CONSTEXPR slice substr(size_t pos, size_t count = npos) const {
982 if (MDBX_UNLIKELY(pos > size()))
983 MDBX_CXX20_UNLIKELY throw_out_range();
984 return middle(pos, (::std::min)(count, size() - pos));
985 }
986
989 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find(const slice &needle, size_t pos = 0) const noexcept;
991 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find(byte c, size_t pos = 0) const noexcept;
992
995 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t rfind(const slice &needle, size_t pos = npos) const noexcept;
997 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t rfind(byte c, size_t pos = npos) const noexcept;
998
1001 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find_first_of(const slice &chars,
1002 size_t pos = 0) const noexcept;
1004 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find_first_of(byte c, size_t pos = 0) const noexcept;
1005
1008 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find_last_of(const slice &chars,
1009 size_t pos = npos) const noexcept;
1011 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find_last_of(byte c, size_t pos = npos) const noexcept;
1012
1015 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find_first_not_of(const slice &chars,
1016 size_t pos = 0) const noexcept;
1018 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find_first_not_of(byte c, size_t pos = 0) const noexcept;
1019
1022 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find_last_not_of(const slice &chars,
1023 size_t pos = npos) const noexcept;
1025 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t find_last_not_of(byte c, size_t pos = npos) const noexcept;
1026
1029 return find(needle) != npos;
1030 }
1031
1033 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR intptr_t compare(const slice &other) const noexcept {
1034 return compare_lexicographically(*this, other);
1035 }
1036
1039 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
1040
1043 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
1044
1047 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
1048
1054 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
1055
1064 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
1065
1071 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
1072 const slice &b) noexcept;
1073 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
1074 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
1075 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
1076 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
1077 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
1078 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
1079#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1080 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
1081#endif /* __cpp_impl_three_way_comparison */
1082
1085 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1086
1090 return slice(/* using special constructor without length checking */ ~size_t(0));
1091 }
1092
1094 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1095
1096 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1097 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1098 "Must be a standard layout type!");
1099 if (MDBX_LIKELY(size() == sizeof(POD)))
1101 POD _as_pod_local;
1102 memcpy(&_as_pod_local, data(), sizeof(_as_pod_local));
1103 return _as_pod_local;
1104 }
1106 }
1107
1108#ifdef MDBX_U128_TYPE
1109 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1110#endif /* MDBX_U128_TYPE */
1111 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1112 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1113 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1114 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1115
1116#ifdef MDBX_I128_TYPE
1117 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1118#endif /* MDBX_I128_TYPE */
1119 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1120 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1121 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1122 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1123
1124#ifdef MDBX_U128_TYPE
1125 MDBX_U128_TYPE as_uint128_adapt() const;
1126#endif /* MDBX_U128_TYPE */
1127 uint64_t as_uint64_adapt() const;
1128 uint32_t as_uint32_adapt() const;
1129 uint16_t as_uint16_adapt() const;
1130 uint8_t as_uint8_adapt() const;
1131
1132#ifdef MDBX_I128_TYPE
1133 MDBX_I128_TYPE as_int128_adapt() const;
1134#endif /* MDBX_I128_TYPE */
1135 int64_t as_int64_adapt() const;
1136 int32_t as_int32_adapt() const;
1137 int16_t as_int16_adapt() const;
1138 int8_t as_int8_adapt() const;
1139
1140protected:
1141 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1142};
1143
1147 bool done;
1148 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
1149 value_result(const value_result &) noexcept = default;
1150 value_result &operator=(const value_result &) noexcept = default;
1151 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1152 MDBX_INLINE_API_ASSERT(!done || value.is_valid());
1153 return done;
1154 }
1155};
1156
1158struct pair {
1159 using stl_pair = std::pair<slice, slice>;
1161 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
1162 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
1163 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
1164 pair(const pair &) noexcept = default;
1165 pair &operator=(const pair &) noexcept = default;
1166 pair &operator=(pair &&couple) noexcept {
1167 key.assign(std::move(couple.key));
1168 value.assign(std::move(couple.value));
1169 return *this;
1170 }
1171 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1172 MDBX_INLINE_API_ASSERT(bool(key) == bool(value));
1173 return key;
1174 }
1176
1177 pair &operator=(const stl_pair &couple) {
1178 key.assign(couple.first);
1179 value.assign(couple.second);
1180 return *this;
1181 }
1183 key.assign(std::move(couple.first));
1184 value.assign(std::move(couple.second));
1185 return *this;
1186 }
1187
1189 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
1190
1192 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
1193 const pair &b) noexcept;
1194 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
1195 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
1196 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
1197 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
1198 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
1199 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
1200#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1201 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
1202#endif /* __cpp_impl_three_way_comparison */
1203};
1204
1207struct pair_result : public pair {
1208 bool done;
1211 : pair(key, value), done(done) {}
1212 pair_result(const pair_result &) noexcept = default;
1213 pair_result &operator=(const pair_result &) noexcept = default;
1214 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1215 MDBX_INLINE_API_ASSERT(!done || (bool(key) && bool(value)));
1216 return done;
1217 }
1218};
1219
1226inline uint64_t key_from_jsonInteger(int64_t json_integer) noexcept {
1227 return ::mdbx_key_from_jsonInteger(json_integer);
1228}
1229
1230inline uint64_t key_from_double(double ieee754_64bit) noexcept { return ::mdbx_key_from_double(ieee754_64bit); }
1232inline uint64_t key_from_ptrdouble(const double *const ieee754_64bit) noexcept {
1233 return ::mdbx_key_from_ptrdouble(ieee754_64bit);
1234}
1235
1236inline uint32_t key_from_float(float ieee754_32bit) noexcept { return ::mdbx_key_from_float(ieee754_32bit); }
1238inline uint32_t key_from_ptrfloat(const float *const ieee754_32bit) noexcept {
1239 return ::mdbx_key_from_ptrfloat(ieee754_32bit);
1240}
1241
1242inline uint64_t key_from_int64(int64_t i64) noexcept { return ::mdbx_key_from_int64(i64); }
1244inline uint32_t key_from_int32(int32_t i32) noexcept { return ::mdbx_key_from_int32(i32); }
1245
1248inline double double_from_key(const slice &key) noexcept { return ::mdbx_double_from_key(key); }
1250inline float float_from_key(const slice &key) noexcept { return ::mdbx_float_from_key(key); }
1252inline int32_t int32_from_key(const slice &key) noexcept { return ::mdbx_int32_from_key(key); }
1254inline int64_t int64_from_key(const slice &key) noexcept { return ::mdbx_int64_from_key(key); }
1256inline int64_t jsonInteger_from_key(const slice &key) noexcept { return ::mdbx_jsonInteger_from_key(key); }
1257
1263inline ::std::string dump_val(const slice &value) {
1264 if (value.empty())
1265 return "<empty>";
1266 ::std::string result(value.length() * 2 + 4, '\0');
1267 const char *const ptr = ::mdbx_dump_val(&value, &result[0], result.size());
1268 if (!ptr)
1269 return result;
1270 result.assign(ptr);
1271 return result;
1272}
1273
1274#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
1275
1279template <typename T>
1280concept MutableByteProducer = requires(T a, char array[42]) {
1281 { a.is_empty() } -> std::same_as<bool>;
1282 { a.envisage_result_length() } -> std::same_as<size_t>;
1283 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1284};
1285
1289template <typename T>
1290concept ImmutableByteProducer = requires(const T &a, char array[42]) {
1291 { a.is_empty() } -> std::same_as<bool>;
1292 { a.envisage_result_length() } -> std::same_as<size_t>;
1293 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1294};
1295
1299template <typename T>
1300concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
1301 T(source);
1302 { a.is_erroneous() } -> std::same_as<bool>;
1303};
1304
1305#endif /* MDBX_HAVE_CXX20_CONCEPTS */
1306
1310 const bool uppercase = false;
1311 const unsigned wrap_width = 0;
1316
1318 template <class ALLOCATOR = default_allocator>
1319 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1320
1322 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1323 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1324
1328 const size_t bytes = source.length() << 1;
1329 return wrap_width ? bytes + bytes / wrap_width : bytes;
1330 }
1331
1334 char *write_bytes(char *dest, size_t dest_size) const;
1335
1338 ::std::ostream &output(::std::ostream &out) const;
1339
1342 bool is_empty() const noexcept { return source.empty(); }
1343
1346 bool is_erroneous() const noexcept { return false; }
1347};
1348
1353 const unsigned wrap_width = 0;
1358
1361 template <class ALLOCATOR = default_allocator>
1362 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1363
1366 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1367 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1368
1372 const size_t bytes = (source.length() * 11 + 7) / 8;
1373 return wrap_width ? bytes + bytes / wrap_width : bytes;
1374 }
1375
1378 char *write_bytes(char *dest, size_t dest_size) const;
1379
1382 ::std::ostream &output(::std::ostream &out) const;
1383
1385 bool is_empty() const noexcept { return source.empty(); }
1386
1389 bool is_erroneous() const noexcept { return false; }
1390};
1391
1396 const unsigned wrap_width = 0;
1401
1404 template <class ALLOCATOR = default_allocator>
1405 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1406
1409 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1410 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1411
1415 const size_t bytes = (source.length() + 2) / 3 * 4;
1416 return wrap_width ? bytes + bytes / wrap_width : bytes;
1417 }
1418
1422 char *write_bytes(char *dest, size_t dest_size) const;
1423
1427 ::std::ostream &output(::std::ostream &out) const;
1428
1431 bool is_empty() const noexcept { return source.empty(); }
1432
1435 bool is_erroneous() const noexcept { return false; }
1436};
1437
1441 const bool ignore_spaces = false;
1446
1448 template <class ALLOCATOR = default_allocator>
1449 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1450
1452 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1453 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1454
1457 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1458
1461 char *write_bytes(char *dest, size_t dest_size) const;
1462
1464 bool is_empty() const noexcept { return source.empty(); }
1465
1468 bool is_erroneous() const noexcept;
1469};
1470
1475 const bool ignore_spaces = false;
1480
1483 template <class ALLOCATOR = default_allocator>
1484 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1485
1488 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1489 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1490
1494 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1495 }
1496
1500 char *write_bytes(char *dest, size_t dest_size) const;
1501
1503 bool is_empty() const noexcept { return source.empty(); }
1504
1508 bool is_erroneous() const noexcept;
1509};
1510
1515 const bool ignore_spaces = false;
1520
1523 template <class ALLOCATOR = default_allocator>
1524 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1525
1528 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1529 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1530
1533 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1534
1538 char *write_bytes(char *dest, size_t dest_size) const;
1539
1542 bool is_empty() const noexcept { return source.empty(); }
1543
1547 bool is_erroneous() const noexcept;
1548};
1549
1551
1552template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1553#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1554 return ::std::allocator_traits<A>::is_always_equal::value;
1555#else
1556 return ::std::is_empty<A>::value;
1557#endif /* __cpp_lib_allocator_traits_is_always_equal */
1558}
1559
1560template <typename T, typename A = typename T::allocator_type,
1561 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1563
1564template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1565 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1566 static constexpr bool is_nothrow() noexcept { return is_always_equal(); }
1567 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1568 if MDBX_IF_CONSTEXPR (is_always_equal())
1569 return true;
1570 else
1571 return target->get_allocator() == source.get_allocator();
1572 }
1573 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &) noexcept { target->release(); }
1574};
1575
1576template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1577 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1578 static constexpr bool is_nothrow() noexcept { return ::std::is_nothrow_move_assignable<A>::value; }
1579 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1580 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1581 target->release();
1582 target->get_allocator() = ::std::move(source.get_allocator());
1583 }
1584};
1585
1586template <typename T, typename A = typename T::allocator_type,
1587 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1589
1590template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1591 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1592 static constexpr bool is_nothrow() noexcept { return false; }
1593 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1594};
1595
1596template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1597 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1598 static constexpr bool is_nothrow() noexcept {
1599 return is_always_equal() || ::std::is_nothrow_copy_assignable<A>::value;
1600 }
1601 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1602 if MDBX_IF_CONSTEXPR (!is_always_equal()) {
1603 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator())) {
1604 target->release();
1605 MDBX_CXX20_UNLIKELY target->get_allocator() = source.get_allocator();
1606 }
1607 } else {
1608 /* gag for buggy compilers */
1609 (void)target;
1610 (void)source;
1611 }
1612 }
1613};
1614
1615template <typename T, typename A = typename T::allocator_type,
1616 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1618
1619template <typename T, typename A> struct swap_alloc<T, A, false> {
1620 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1621 static constexpr bool is_nothrow() noexcept { return is_always_equal(); }
1622 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1623 if MDBX_IF_CONSTEXPR (!is_always_equal()) {
1624 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1625 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1626 } else {
1627 /* gag for buggy compilers */
1628 (void)left;
1629 (void)right;
1630 }
1631 }
1632};
1633
1634template <typename T, typename A> struct swap_alloc<T, A, true> {
1635 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1636 static constexpr bool is_nothrow() noexcept {
1637 return is_always_equal() ||
1638#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1639 ::std::is_nothrow_swappable<A>() ||
1640#endif /* __cpp_lib_is_swappable >= 201603L */
1641 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1642 }
1643 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1644 if MDBX_IF_CONSTEXPR (!is_always_equal())
1645#if !defined(__cpp_if_constexpr) || __cpp_if_constexpr < 201606L
1646 /* Workaround of ms-clang (clang corrupted by microsoft) */
1647 MDBX_CXX20_UNLIKELY
1648#endif
1649 ::std::swap(left.get_allocator(), right.get_allocator());
1650 else {
1651 /* gag for buggy compilers */
1652 (void)left;
1653 (void)right;
1654 }
1655 }
1656};
1657
1658} // namespace allocation_aware_details
1659
1661 enum : size_t {
1666 };
1667
1668 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1669 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1670 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1671 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1672 return (value + pettiness_threshold - 1) & pettiness_mask;
1673 }
1674
1675 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1676 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1677 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1678
1679 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1680 return inplace;
1681
1682 if (wanna > current)
1683 /* doubling capacity, but don't made reserve more than max_reserve */
1684 return round(wanna + ::std::min(size_t(max_reserve), current));
1685
1686 if (current - wanna >
1687 /* shrink if reserve will more than half of current or max_reserve,
1688 * but not less than pettiness_threshold */
1689 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1690 return round(wanna);
1691
1692 /* keep unchanged */
1693 return current;
1694 }
1695};
1696
1698struct buffer_tag {};
1699
1701template <class ALLOCATOR, typename CAPACITY_POLICY>
1703public:
1705#if !defined(_MSC_VER) || _MSC_VER > 1900
1706 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1707#else
1708 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1709#endif /* MSVC is mad */
1710 using allocator_traits = ::std::allocator_traits<allocator_type>;
1711 using reservation_policy = CAPACITY_POLICY;
1712 enum : size_t {
1714 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1717 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1718 ? alignof(max_align_t) * 2
1721 };
1722
1724 enum class modality { reference, inplace, allocated };
1725
1726private:
1727 friend class txn;
1728 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1729 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1730 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1731
1732 using allocator_pointer = typename allocator_traits::pointer;
1733 using allocator_const_pointer = typename allocator_traits::const_pointer;
1734 using move_assign_alloc = allocation_aware_details::move_assign_alloc<silo, allocator_type>;
1735 using copy_assign_alloc = allocation_aware_details::copy_assign_alloc<silo, allocator_type>;
1736 using swap_alloc = allocation_aware_details::swap_alloc<silo, allocator_type>;
1737
1738 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1739 MDBX_INLINE_API_ASSERT(bytes >= sizeof(bin));
1740 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1741 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1742 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1743 const size_t n = (bytes + unit - 1) / unit;
1744 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1745 }
1746
1747 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1748 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1749 MDBX_INLINE_API_ASSERT(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1750 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1751 }
1752
1753 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1754 const size_t capacity = bin::advise_capacity(0, bytes);
1755 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1756 : allocate_storage(capacity);
1757 }
1758
1759 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1760#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1761 return static_cast<void *>(::std::to_address(ptr));
1762#else
1763 return static_cast<void *>(::std::addressof(*ptr));
1764#endif /* __cpp_lib_to_address */
1765 }
1766
1767 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1768#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1769 return static_cast<const void *>(::std::to_address(ptr));
1770#else
1771 return static_cast<const void *>(::std::addressof(*ptr));
1772#endif /* __cpp_lib_to_address */
1773 }
1774
1775#ifdef _MSC_VER
1776#pragma warning(push)
1777#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1778#endif /* _MSC_VER */
1779
1780 union alignas(max_align_t) bin {
1781 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1782 с учетом выравнивания */
1783 {
1784 allocator_pointer stub_ptr_;
1786 };
1787
1789 enum : size_t {
1791 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1795 };
1796
1798 byte pad_[inplace_size - sizeof(allocator_pointer)];
1799 size_t bytes_;
1800 };
1801
1803 byte buffer_[inplace_size - sizeof(byte)];
1806 };
1807
1808 allocator_pointer allocated_ptr_;
1811
1812 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1813 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1814 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1815 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1816 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1817 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1818 return capacity_bytes <= inplace_capacity();
1819 }
1820
1821 MDBX_NOTHROW_PURE_FUNCTION constexpr bool is_inplace() const noexcept {
1822 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1823 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1825 "WTF?");
1826 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1827 }
1828 MDBX_NOTHROW_PURE_FUNCTION constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1829
1832 /* properly destroy allocator::pointer */
1833 allocated_ptr_.~allocator_pointer();
1836 return address();
1837 }
1838
1839 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1842 new (&allocated_ptr_) allocator_pointer(pair.first);
1843 capacity_.bytes_ = pair.second;
1844 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1845 return address();
1846 }
1847
1849 if (::std::is_trivial<allocator_pointer>::value)
1850 /* workaround for "uninitialized" warning from some compilers */
1851 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1852 }
1853
1854 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1855 if (MDBX_UNLIKELY(wanna > max_capacity))
1856 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1857
1858 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1859 MDBX_INLINE_API_ASSERT(advised >= wanna);
1860 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1861 }
1862
1863 constexpr bool is_inplace(const void *ptr) const noexcept {
1864 return ptr != nullptr && size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1865 }
1866
1867 constexpr const byte *address() const noexcept {
1868 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1869 }
1871 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1872 }
1873 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1874 } bin_;
1875
1876#ifdef _MSC_VER
1877#pragma warning(pop)
1878#endif /* _MSC_VER */
1879
1880 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1881
1882 MDBX_CXX20_CONSTEXPR void release() noexcept {
1883 if (bin_.is_allocated()) {
1884 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1885 /* properly destroy allocator::pointer */
1886 bin_.allocated_ptr_.~allocator_pointer();
1887 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1888 }
1889 }
1890
1891 template <bool external_content>
1892 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1893 const void *const content, const size_t length) {
1894 MDBX_INLINE_API_ASSERT(wanna_capacity >= wanna_headroom + length);
1895 const size_t old_capacity = bin_.capacity();
1896 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1897 if (MDBX_LIKELY(new_capacity == old_capacity))
1899 MDBX_INLINE_API_ASSERT(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1900 byte *const new_place = bin_.address() + wanna_headroom;
1901 if (MDBX_LIKELY(length))
1903 if (external_content)
1904 /* `content` may refer into the own storage, so use memmove */
1905 ::std::memmove(new_place, content, length);
1906 else {
1907 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1908 MDBX_INLINE_API_ASSERT(old_capacity >= old_headroom + length);
1909 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1910 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1911 }
1912 }
1913 return new_place;
1914 }
1915
1916 if (bin::is_suitable_for_inplace(new_capacity)) {
1917 MDBX_INLINE_API_ASSERT(bin_.is_allocated());
1918 const auto old_allocated = bin_.allocated_ptr_;
1919 byte *const new_place = bin_.make_inplace() + wanna_headroom;
1920 if (MDBX_LIKELY(length))
1921 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1922 deallocate_storage(old_allocated, old_capacity);
1923 return new_place;
1924 }
1925
1926 if (bin_.is_inplace()) {
1927 const auto pair = allocate_storage(new_capacity);
1928 MDBX_INLINE_API_ASSERT(pair.second >= new_capacity);
1929 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1930 /* Copy the content before make_allocated(), since the latter overwrites
1931 * the inplace storage (the source of `content` for reshape<false>). */
1932 if (MDBX_LIKELY(length))
1933 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1934 bin_.make_allocated(pair);
1935 return new_place;
1936 }
1937
1938 auto pair = allocate_storage(new_capacity);
1939 std::swap(bin_.allocated_ptr_, pair.first);
1940 bin_.capacity_.bytes_ = pair.second;
1941 auto new_place = bin_.address() + wanna_headroom;
1942 if (MDBX_LIKELY(length))
1943 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1944 deallocate_storage(pair.first, old_capacity);
1945 return new_place;
1946 }
1947
1948 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1949 MDBX_INLINE_API_ASSERT(capacity() >= offset);
1950 return bin_.address() + offset;
1951 }
1952 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1953 MDBX_INLINE_API_ASSERT(capacity() >= offset);
1954 return bin_.address() + offset;
1955 }
1956 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1957 MDBX_INLINE_API_ASSERT(capacity() >= offset + length);
1958 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1959 }
1960
1961 //--------------------------------------------------------------------------
1962
1963 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1964 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1965 if (!bin::is_suitable_for_inplace(capacity))
1966 bin_.make_allocated(provide_storage(capacity));
1967 }
1968
1969 silo(silo &&other) = delete;
1971 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1972 : allocator_type(::std::move(other.get_allocator())) {
1973 if (!is_reference) {
1974 if (other.bin_.is_inplace()) {
1975 memcpy(&bin_, &other.bin_, sizeof(bin));
1976 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1977 } else {
1978 /* coverity[USE_AFTER_MOVE] */
1979 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1980 /* coverity[USE_AFTER_MOVE] */
1981 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1982 /* properly destroy allocator::pointer.
1983 *
1984 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1985 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1986 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1987 * from the 11th). */
1988 /* coverity[USE_AFTER_MOVE] */
1989 other.bin_.allocated_ptr_.~allocator_pointer();
1990 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1991 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1992 }
1993 }
1994 }
1995
1996 MDBX_CXX17_CONSTEXPR bool move_content(silo &other, const modality other_modality) noexcept {
1997 switch (other_modality) {
1998 case modality::inplace:
1999 memcpy(&bin_, &other.bin_, sizeof(bin));
2000 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
2001 return /* buffer's slice fixup is needed */ true;
2002 case modality::allocated:
2003 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
2004 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
2005 /* properly destroy allocator::pointer.
2006 *
2007 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2008 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2009 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
2010 * from the 11th). */
2011 /* coverity[use_after_move] */
2012 other.bin_.allocated_ptr_.~allocator_pointer();
2013 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
2014 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
2015 return /* buffer's slice fixup is not needed */ false;
2016 default:
2017 MDBX_CONSTEXPR_ASSERT(other_modality == modality::reference);
2018 return /* buffer's slice fixup is not needed */ false;
2019 }
2020 }
2021
2022 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
2023 exchange(silo &left, const modality left_modality, silo &right,
2024 const modality right_modality) noexcept(swap_alloc::is_nothrow()) {
2025 swap_alloc::propagate(left, right);
2026 bool left_need_fixup = false, right_need_fixup = false;
2027 if (left_modality == modality::reference || right_modality == modality::reference) {
2028 /* It is Ok here to call move_content for the left and right side in any order,
2029 * since the move_content() does nothing when modality == reference.
2030 * Thus, the actual move action will perform no more than one call of move_content(),
2031 * so the order doesn't matter here. */
2032 left_need_fixup = left.move_content(right, right_modality);
2033 right_need_fixup = right.move_content(left, left_modality);
2034 } else {
2035 silo temp(std::move(left), false);
2036 left_need_fixup = left.move_content(right, right_modality);
2037 right_need_fixup = right.move_content(temp, left_modality);
2038 }
2039 return std::make_pair(left_need_fixup, right_need_fixup);
2040 }
2041
2042 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
2043 const allocator_type &alloc = allocator_type())
2044 : silo(capacity, alloc) {
2045 MDBX_INLINE_API_ASSERT(capacity >= headroom + length);
2046 if (length)
2047 put(headroom, ptr, length);
2048 }
2049
2050 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
2051 : silo(length, 0, ptr, length, alloc) {}
2052
2053 ~silo() { release(); }
2054
2055 //--------------------------------------------------------------------------
2056
2057 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
2058 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
2059 }
2060
2061 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
2062
2063 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
2064 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
2065 return reshape<false>(whole_capacity, headroom, nullptr, 0);
2066 }
2067
2068 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
2069 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
2070 return get(offset);
2071 }
2072 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
2073 };
2074
2075 MDBX_CXX14_CONSTEXPR void fixup_imported_inplace(const typename silo::bin &src) noexcept {
2076 auto ptr = inherited::byte_ptr();
2077 if (src.is_inplace(ptr)) {
2078 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
2079 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
2080 iov_base = ptr + offset;
2081 MDBX_CONSTEXPR_ASSERT(is_freestanding());
2082 }
2083 }
2084
2085 silo silo_;
2086
2087 void insulate() {
2088 MDBX_INLINE_API_ASSERT(is_reference());
2089 iov_base = silo_.assign(iov_base, iov_len);
2090 }
2091
2092 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
2093 return static_cast<const byte *>(silo_.data());
2094 }
2095
2096 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
2097 return silo_begin() + silo_.capacity();
2098 }
2099
2100 struct data_preserver : public exception_thunk {
2101 buffer data;
2102 data_preserver(const allocator_type &alloc) : data(alloc) {}
2103 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
2104 auto self = static_cast<data_preserver *>(context);
2105 assert(self->is_clean());
2106 assert(&self->data == target);
2107 (void)target;
2108 try {
2109 self->data.assign(src, bytes, false);
2110 return MDBX_RESULT_FALSE;
2111 } catch (... /* capture any exception to rethrow it over C code */) {
2112 self->capture();
2113 return MDBX_RESULT_TRUE;
2114 }
2115 }
2116 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
2117 };
2118
2119public:
2122
2123 using move_assign_alloc = typename silo::move_assign_alloc;
2124 using copy_assign_alloc = typename silo::copy_assign_alloc;
2125 using swap_alloc = typename silo::swap_alloc;
2126 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
2127
2129 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
2130
2134 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
2135 const auto begin_ptr = inherited::byte_ptr();
2136 if (MDBX_UNLIKELY(begin_ptr == nullptr))
2137 return false;
2138 return size_t(begin_ptr - silo_begin()) < silo_.capacity();
2139 }
2140
2145 return inherited::data() != nullptr && silo_.is_inplace(inherited::data());
2146 }
2147
2150
2153 return is_freestanding() ? (is_inplace() ? modality::inplace : modality::allocated) : modality::reference;
2154 }
2155
2158 return is_freestanding() ? silo_.capacity() : 0;
2159 }
2160
2163 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
2164 }
2165
2168 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2169 }
2170
2172 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2173
2175 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2176
2183
2188 return const_cast<byte *>(inherited::end_byte_ptr());
2189 }
2190
2192 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2193
2195 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2196
2201 return const_cast<char *>(inherited::char_ptr());
2202 }
2203
2208 return const_cast<char *>(inherited::end_char_ptr());
2209 }
2210
2212 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return const_data(); }
2213
2215 MDBX_CXX11_CONSTEXPR const byte *end() const noexcept { return static_cast<const byte *>(const_end()); }
2216
2218 MDBX_CXX11_CONSTEXPR const void *const_data() const noexcept { return inherited::data(); }
2219
2221 MDBX_CXX11_CONSTEXPR const void *const_end() const noexcept { return inherited::end(); }
2222
2225 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2227 return const_cast<void *>(inherited::data());
2228 }
2229
2232 MDBX_CXX11_CONSTEXPR byte *end() noexcept {
2234 return const_cast<byte *>(inherited::end_byte_ptr());
2235 }
2236
2241
2248
2251 void resize(size_t size) { resize(size, byte(0)); }
2252
2255 void resize(size_t size, byte value) {
2256 if (MDBX_UNLIKELY(size > length())) {
2258 memset(end_byte_ptr(), value, size - length());
2259 }
2261 }
2262
2265 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2266 return set_length(static_cast<const char *>(ptr) - char_ptr());
2267 }
2268
2273 if (is_reference())
2274 insulate();
2275 }
2276
2277 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2278 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2279 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2280 const allocator_type &alloc = allocator_type());
2281
2283 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2284 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2285
2286 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2287 : buffer(inherited(c_str), make_reference, alloc) {}
2288
2289#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2290 template <class CHAR, class T>
2291 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2292 const allocator_type &alloc = allocator_type())
2293 : buffer(inherited(view), make_reference, alloc) {}
2294#endif /* __cpp_lib_string_view >= 201606L */
2295
2297 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2298 : buffer(src, src.empty() || src.is_null(), alloc) {}
2299
2301 explicit buffer(const buffer &src)
2302 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2303
2305 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2306 : buffer(inherited(ptr, bytes), alloc) {}
2307
2308 template <class CHAR, class T, class A>
2309 explicit MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2310 const allocator_type &alloc = allocator_type())
2311 : buffer(inherited(str), false, alloc) {}
2312
2313 template <class CHAR, class T, class A>
2314 explicit MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str, bool make_reference,
2315 const allocator_type &alloc = allocator_type())
2316 : buffer(inherited(str), make_reference, alloc) {}
2317
2318 template <class CHAR, class T, class A>
2319 explicit MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &&str,
2320 const allocator_type &alloc = allocator_type())
2321 : buffer(inherited(str), false, alloc) {
2322 str.clear();
2323 }
2324
2326 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2327
2328#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2329 template <class CHAR, class T>
2330 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2331 const allocator_type &alloc = allocator_type())
2332 : buffer(inherited(view), alloc) {}
2333#endif /* __cpp_lib_string_view >= 201606L */
2334
2335 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2336 : silo_(check_length(head_room, tail_room), alloc) {
2337 iov_base = silo_.get(head_room);
2338 MDBX_INLINE_API_ASSERT(iov_len == 0);
2339 }
2340
2341 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2342 iov_base = silo_.get();
2343 MDBX_INLINE_API_ASSERT(iov_len == 0);
2344 }
2345
2346 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2347 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2348 iov_len = src.length();
2349 iov_base = memcpy(silo_.get(head_room), src.data(), iov_len);
2350 }
2351
2352 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2353
2354 buffer(buffer &&src) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
2355 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2356 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2357 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2358 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2359 * 11th). */
2360 /* coverity[USE_AFTER_MOVE] */
2361 fixup_imported_inplace(src.silo_.bin_);
2362 src.invalidate();
2363 }
2364
2366 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2367
2371
2372 template <typename POD>
2373 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2374 return buffer(inherited::wrap(pod), make_reference, alloc);
2375 }
2376
2378 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2379 const allocator_type &alloc = allocator_type()) {
2380 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2381 }
2382
2385 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2386 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2387 }
2388
2390 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2391 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2392 }
2393
2395 template <typename POD>
2396 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2397 const allocator_type &alloc = allocator_type()) {
2398 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2399 }
2400
2403 template <typename POD>
2404 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2405 return base58(inherited::wrap(pod), wrap_width, alloc);
2406 }
2407
2410 template <typename POD>
2411 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2412 return base64(inherited::wrap(pod), wrap_width, alloc);
2413 }
2414
2416 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2417 const allocator_type &alloc = allocator_type()) const {
2418 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2419 }
2420
2423 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2424 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2425 }
2426
2428 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2429 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2430 }
2431
2433 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2434 const allocator_type &alloc = allocator_type()) {
2435 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2436 }
2437
2440 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2441 const allocator_type &alloc = allocator_type()) {
2442 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2443 }
2444
2447 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2448 const allocator_type &alloc = allocator_type()) {
2449 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2450 }
2451
2454 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2455 return hex_decode(*this, ignore_spaces, alloc);
2456 }
2457
2460 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2461 return base58_decode(*this, ignore_spaces, alloc);
2462 }
2463
2466 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2467 return base64_decode(*this, ignore_spaces, alloc);
2468 }
2469
2471 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2472 wanna_headroom = ::std::min(
2473 ::std::max(headroom(), wanna_headroom),
2474 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2475 wanna_tailroom = ::std::min(
2476 ::std::max(tailroom(), wanna_tailroom),
2477 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2478 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2479
2480 if (is_freestanding())
2481 iov_base = silo_.template reshape<false>(wanna_capacity, wanna_headroom, iov_base, iov_len);
2482 else if (wanna_capacity > iov_len)
2483 iov_base = silo_.template reshape<true>(wanna_capacity, wanna_headroom, iov_base, iov_len);
2484
2485 MDBX_INLINE_API_ASSERT(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2486 /* The upper bound is intentionally not checked for the tailroom: the
2487 * capacity-growth policy may legitimately over-provision (e.g. by
2488 * doubling), so the only guaranteed contract here is the lower bound. */
2489 MDBX_INLINE_API_ASSERT(tailroom() >= wanna_tailroom);
2490 }
2491
2493 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2494
2496 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2497
2501 void reserve(size_t size) { reserve(0, size > length() ? size - length() : 0); }
2502
2503 buffer &assign_reference(const void *ptr, size_t bytes) {
2504 silo_.clear();
2506 return *this;
2507 }
2508
2509 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2510 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2511 return *this;
2512 }
2513
2514 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2515 const auto pair = silo::exchange(silo_, content_modality(), other.silo_, other.content_modality());
2516 inherited::swap(other);
2517 if (pair.first)
2518 fixup_imported_inplace(other.silo_.bin_);
2519 if (pair.second)
2520 other.fixup_imported_inplace(silo_.bin_);
2521 }
2522
2523 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2524 left.swap(right);
2525 }
2526
2527 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2528 return buffer(src.headroom(), src, src.tailroom(), alloc);
2529 }
2530
2532 return buffer(static_cast<const struct slice &>(*this), !is_inplace(),
2533 allocator_traits::select_on_container_copy_construction(get_allocator()));
2534 }
2535
2537 if (MDBX_LIKELY(this != &src))
2539 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2540 invalidate();
2541 copy_assign_alloc::propagate(&silo_, src.silo_);
2542 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2543 iov_len = src.length();
2544 }
2545 else
2547 return *this;
2548 }
2549
2550 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2551 if (MDBX_LIKELY(this != &src))
2553 invalidate();
2554 copy_assign_alloc::propagate(&silo_, src.silo_);
2555 if (make_reference) {
2556 silo_.release();
2557 iov_base = src.iov_base;
2558 } else {
2559 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2560 }
2561 iov_len = src.length();
2562 }
2563 else if (!make_reference && is_reference())
2564 insulate();
2565 return *this;
2566 }
2567
2568 MDBX_CXX20_CONSTEXPR buffer &assign(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) {
2569 if (MDBX_LIKELY(this != &src))
2571 const auto kind = src.content_modality();
2572 const auto src_headroom = src.headroom();
2573 const auto src_data = src.const_data();
2574 const auto src_length = src.length();
2575 inherited::assign(std::move(src));
2576 if (!move_assign_alloc::is_moveable(&silo_, src.silo_) && kind == modality::allocated) {
2577 iov_base = silo_.template reshape<true>(src.silo_.capacity(), src_headroom, src_data, src_length);
2578 return *this;
2579 }
2580 move_assign_alloc::propagate(&silo_, src.silo_);
2581 if (silo_.move_content(src.silo_, kind))
2582 fixup_imported_inplace(src.silo_.bin_);
2583 }
2584 return *this;
2585 }
2586
2587 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2588 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2589 }
2590
2591 buffer &assign(const struct slice &src, bool make_reference = false) {
2592 return assign(src.data(), src.length(), make_reference);
2593 }
2594
2595 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2596 return assign(src.iov_base, src.iov_len, make_reference);
2597 }
2598
2599 buffer &assign(struct slice &&src, bool make_reference = false) {
2600 assign(src.data(), src.length(), make_reference);
2601 src.invalidate();
2602 return *this;
2603 }
2604
2605 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2606 assign(src.iov_base, src.iov_len, make_reference);
2607 src.iov_base = nullptr;
2608 return *this;
2609 }
2610
2611 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2612 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2613 }
2614
2615 template <class CHAR, class T, class A>
2616 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2617 return assign(str.data(), str.length() * sizeof(CHAR), make_reference);
2618 }
2619
2620 buffer &assign(const char *c_str, bool make_reference = false) {
2621 return assign(c_str, strlen(c_str), make_reference);
2622 }
2623
2624#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2625 template <class CHAR, class T>
2626 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2627 return assign(inherited(view), make_reference);
2628 }
2629
2630 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2631 assign(inherited(view), make_reference);
2632 view = {};
2633 return *this;
2634 }
2635#endif /* __cpp_lib_string_view >= 201606L */
2636
2637 buffer &operator=(const buffer &src) { return assign(src); }
2638
2639 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2640
2641 buffer &operator=(const struct slice &src) { return assign(src); }
2642
2643 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2644
2645#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2646 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2647 return assign(inherited(view));
2648 }
2649
2650 template <class CHAR, class T> buffer &append(const ::std::basic_string_view<CHAR, T> &view) {
2651 return append(view.begin(), view.end());
2652 }
2653#endif /* __cpp_lib_string_view >= 201606L */
2654
2655 template <class CHAR, class T, class A>
2656 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2657 return as_string<CHAR, T, A>();
2658 }
2659
2660 template <class CHAR, class T, class A> buffer &append(const ::std::basic_string<CHAR, T, A> &str) {
2661 return append(inherited(str));
2662 }
2663
2665 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2666
2668 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) {
2669 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2670 }
2671
2674 if (is_freestanding())
2675 iov_base = silo_.template reshape<false>(iov_len, 0, iov_base, iov_len);
2676 }
2677
2678 buffer &append(const void *src, size_t bytes) {
2679 if (MDBX_LIKELY(bytes))
2681 const auto begin_ptr = inherited::byte_ptr();
2682 const auto src_ptr = static_cast<const byte *>(src);
2683 /* In case `src` refers into the own storage, save its relative offset
2684 * since the storage may be relocated by the reserve below. */
2685 const bool aliased = src_ptr >= begin_ptr && src_ptr < inherited::end_byte_ptr();
2686 const size_t src_offset = aliased ? size_t(src_ptr - begin_ptr) : 0;
2687 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2688 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2689 ::std::memmove(end_byte_ptr(), aliased ? byte_ptr() + src_offset : src_ptr, bytes);
2690 iov_len += bytes;
2691 }
2692 return *this;
2693 }
2694
2695 buffer &append(const byte c) {
2696 if (MDBX_UNLIKELY(tailroom() < 1))
2697 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2698 *end_byte_ptr() = c;
2699 iov_len += 1;
2700 return *this;
2701 }
2702
2703 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2704
2705 buffer &add_header(const void *src, size_t bytes) {
2706 if (MDBX_LIKELY(bytes))
2708 const auto begin_ptr = inherited::byte_ptr();
2709 const auto src_ptr = static_cast<const byte *>(src);
2710 /* In case `src` refers into the own storage, save its relative offset
2711 * since the storage may be relocated by the reserve below. */
2712 const bool aliased = src_ptr >= begin_ptr && src_ptr < inherited::end_byte_ptr();
2713 const size_t src_offset = aliased ? size_t(src_ptr - begin_ptr) : 0;
2714 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2715 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2716 iov_base = ::std::memmove(byte_ptr() - bytes, aliased ? byte_ptr() + src_offset : src_ptr, bytes);
2717 iov_len += bytes;
2718 }
2719 return *this;
2720 }
2721
2722 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2723
2724 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2725 const size_t wanna_bytes = producer.envisage_result_length();
2726 if (MDBX_LIKELY(wanna_bytes))
2728 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2729 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2730 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2731 }
2732 return *this;
2733 }
2734
2735 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2736 const size_t wanna_bytes = producer.envisage_result_length();
2737 if (MDBX_LIKELY(wanna_bytes))
2739 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2740 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2741 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2742 }
2743 return *this;
2744 }
2745
2746 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2747 return append_producer(to_hex(data, uppercase, wrap_width));
2748 }
2749
2750 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2751 return append_producer(to_base58(data, wrap_width));
2752 }
2753
2754 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2755 return append_producer(to_base64(data, wrap_width));
2756 }
2757
2758 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2759 return append_producer(from_hex(data, ignore_spaces));
2760 }
2761
2762 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2763 return append_producer(from_base58(data, ignore_spaces));
2764 }
2765
2766 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2767 return append_producer(from_base64(data, ignore_spaces));
2768 }
2769
2770 buffer &append_u8(uint_fast8_t u8) {
2771 if (MDBX_UNLIKELY(tailroom() < 1))
2772 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2773 *end_byte_ptr() = uint8_t(u8);
2774 iov_len += 1;
2775 return *this;
2776 }
2777
2778 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2779
2780 buffer &append_u16(uint_fast16_t u16) {
2781 if (MDBX_UNLIKELY(tailroom() < 2))
2782 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2783 const auto ptr = end_byte_ptr();
2784 ptr[0] = uint8_t(u16);
2785 ptr[1] = uint8_t(u16 >> 8);
2786 iov_len += 2;
2787 return *this;
2788 }
2789
2790 buffer &append_u24(uint_fast32_t u24) {
2791 if (MDBX_UNLIKELY(tailroom() < 3))
2792 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2793 const auto ptr = end_byte_ptr();
2794 ptr[0] = uint8_t(u24);
2795 ptr[1] = uint8_t(u24 >> 8);
2796 ptr[2] = uint8_t(u24 >> 16);
2797 iov_len += 3;
2798 return *this;
2799 }
2800
2801 buffer &append_u32(uint_fast32_t u32) {
2802 if (MDBX_UNLIKELY(tailroom() < 4))
2803 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2804 const auto ptr = end_byte_ptr();
2805 ptr[0] = uint8_t(u32);
2806 ptr[1] = uint8_t(u32 >> 8);
2807 ptr[2] = uint8_t(u32 >> 16);
2808 ptr[3] = uint8_t(u32 >> 24);
2809 iov_len += 4;
2810 return *this;
2811 }
2812
2813 buffer &append_u48(uint_fast64_t u48) {
2814 if (MDBX_UNLIKELY(tailroom() < 6))
2815 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2816 const auto ptr = end_byte_ptr();
2817 ptr[0] = uint8_t(u48);
2818 ptr[1] = uint8_t(u48 >> 8);
2819 ptr[2] = uint8_t(u48 >> 16);
2820 ptr[3] = uint8_t(u48 >> 24);
2821 ptr[4] = uint8_t(u48 >> 32);
2822 ptr[5] = uint8_t(u48 >> 40);
2823 iov_len += 6;
2824 return *this;
2825 }
2826
2827 buffer &append_u64(uint_fast64_t u64) {
2828 if (MDBX_UNLIKELY(tailroom() < 8))
2829 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2830 const auto ptr = end_byte_ptr();
2831 ptr[0] = uint8_t(u64);
2832 ptr[1] = uint8_t(u64 >> 8);
2833 ptr[2] = uint8_t(u64 >> 16);
2834 ptr[3] = uint8_t(u64 >> 24);
2835 ptr[4] = uint8_t(u64 >> 32);
2836 ptr[5] = uint8_t(u64 >> 40);
2837 ptr[6] = uint8_t(u64 >> 48);
2838 ptr[7] = uint8_t(u64 >> 56);
2839 iov_len += 8;
2840 return *this;
2841 }
2842
2843 //----------------------------------------------------------------------------
2844
2845 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2846 return buffer(inherited(text), make_reference);
2847 }
2848
2849#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2850 template <class CHAR, class T>
2851 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2852 return buffer(src, make_reference);
2853 }
2854#endif /* __cpp_lib_string_view >= 201606L */
2855
2856 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2857
2858 template <class CHAR, class T, class A>
2859 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2860 return buffer(src, make_reference);
2861 }
2862
2863 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2864
2865 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2866
2867 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2868
2869 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2870
2871 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2872
2873 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2874
2875 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2876
2877 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2878
2879 static buffer key_from_jsonInteger(const int64_t json_integer) {
2880 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2881 }
2882
2883 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2884
2885 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2886
2887 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2888
2889 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2890
2891 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2892
2893 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2894
2895 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2896
2897 const slice &slice() const noexcept { return *this; }
2898};
2899
2900template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2904 using reservation_policy = CAPACITY_POLICY;
2905 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2907
2910 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2911
2913 : key(key, alloc), value(value, alloc) {}
2914 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2915 const allocator_type &alloc = allocator_type())
2916 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2917
2919 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2920 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2921 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2922
2924 : key(key, alloc), value(value, alloc) {}
2925 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2926 const allocator_type &alloc = allocator_type())
2927 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2928
2931 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2932 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2933
2934 buffer_pair_spec(const txn &transaction, const slice &key, const slice &value,
2935 const allocator_type &alloc = allocator_type())
2936 : key(transaction, key, alloc), value(transaction, value, alloc) {}
2937 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2938 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2939
2940 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2941 : key(::std::move(key)), value(::std::move(value)) {}
2943 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2944 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2945
2948 key.assign(std::move(src.key));
2949 value.assign(std::move(src.value));
2950 return *this;
2951 }
2952
2954 key.assign(src.key);
2955 value.assign(src.value);
2956 return *this;
2957 }
2959 key.assign(std::move(src.key));
2960 value.assign(std::move(src.value));
2961 return *this;
2962 }
2964 key.assign(src.first);
2965 value.assign(src.second);
2966 return *this;
2967 }
2969 key.assign(std::move(src.first));
2970 value.assign(std::move(src.second));
2971 return *this;
2972 }
2973
2977 return key.is_freestanding() && value.is_freestanding();
2978 }
2979
2982 return key.is_reference() || value.is_reference();
2983 }
2984
2988 key.make_freestanding();
2989 value.make_freestanding();
2990 }
2991
2992 operator pair() const noexcept { return pair(key, value); }
2993};
2994
2996
2999
3012public:
3013 cache_entry() noexcept { reset(); }
3014 cache_entry(const cache_entry &) noexcept = default;
3015 cache_entry &operator=(const cache_entry &) noexcept = default;
3016 cache_entry(cache_entry &&other) noexcept {
3017 *this = other;
3018 other.reset();
3019 }
3020
3022 void reset() noexcept { mdbx_cache_init(this); }
3023
3026 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return last_confirmed_txnid != 0; }
3028 MDBX_CXX14_CONSTEXPR bool notfound() const noexcept { return offset == 0; }
3031 MDBX_CXX14_CONSTEXPR uint64_t transaction_id() const noexcept { return trunk_txnid; }
3034 MDBX_CXX14_CONSTEXPR uint64_t last_confirmed() const noexcept { return last_confirmed_txnid; }
3035
3036 MDBX_CXX20_CONSTEXPR cache_entry(const MDBX_cache_entry_t &ce) noexcept { mdbx::memcpy(this, &ce, sizeof(*this)); }
3038 mdbx::memcpy(this, &ce, sizeof(*this));
3039 return *this;
3040 };
3041
3042 friend MDBX_CXX14_CONSTEXPR bool operator==(const cache_entry &a, const cache_entry &b) noexcept {
3043 return a.trunk_txnid == b.trunk_txnid && a.last_confirmed_txnid == b.last_confirmed_txnid &&
3044 a.offset == b.offset && a.length == b.length;
3045 }
3046 friend MDBX_CXX14_CONSTEXPR bool operator!=(const cache_entry &a, const cache_entry &b) noexcept {
3047 return !(a == b);
3048 }
3049};
3050
3051//------------------------------------------------------------------------------
3052
3055enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
3056
3073
3075 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
3076}
3077
3079 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
3080}
3081
3083 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
3084}
3085
3087 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
3088}
3089
3091
3149
3153
3155 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
3156}
3157
3159 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
3160}
3161
3163 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
3164}
3165
3167 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
3168}
3169
3171
3182 map_handle(const map_handle &) noexcept = default;
3183 map_handle &operator=(const map_handle &) noexcept = default;
3184 operator bool() const noexcept { return dbi != 0; }
3185 operator MDBX_dbi() const { return dbi; }
3186
3187#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
3188 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
3189 return a.dbi <=> b.dbi;
3190 }
3191#endif /* __cpp_impl_three_way_comparison */
3192 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
3193 return a.dbi == b.dbi;
3194 }
3195 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
3196 return a.dbi < b.dbi;
3197 }
3198 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
3199 return a.dbi > b.dbi;
3200 }
3201 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
3202 return a.dbi <= b.dbi;
3203 }
3204 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
3205 return a.dbi >= b.dbi;
3206 }
3207 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
3208 return a.dbi != b.dbi;
3209 }
3210
3222};
3223
3226 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
3227}
3229 return ::mdbx_get_datacmp(static_cast<MDBX_db_flags_t>(mode));
3230}
3231
3238
3247 friend class txn;
3248
3249protected:
3251 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
3252
3253public:
3254 MDBX_CXX11_CONSTEXPR env() noexcept = default;
3255 env(const env &) noexcept = default;
3256 env &operator=(const env &) noexcept = default;
3257 inline env &operator=(env &&) noexcept;
3258 inline env(env &&) noexcept;
3259 inline ~env() noexcept;
3260
3261 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
3262 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const noexcept { return handle_; }
3263 MDBX_CXX14_CONSTEXPR operator MDBX_env *() noexcept { return handle_; }
3264 MDBX_CXX14_CONSTEXPR const MDBX_env *handle() const noexcept { return handle_; }
3266 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
3267 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
3268
3269 //----------------------------------------------------------------------------
3270
3275
3277 enum : intptr_t {
3280 maximal_value = INTPTR_MAX,
3281 kB = 1000,
3282 MB = kB * 1000,
3283 GB = MB * 1000,
3284#if INTPTR_MAX > 0x7fffFFFFl
3285 TB = GB * 1000,
3286 PB = TB * 1000,
3287 EB = PB * 1000,
3288#endif /* 64-bit intptr_t */
3289 KiB = 1024,
3290 MiB = KiB << 10,
3291 GiB = MiB << 10,
3292#if INTPTR_MAX > 0x7fffFFFFl
3293 TiB = GiB << 10,
3294 PiB = TiB << 10,
3295 EiB = PiB << 10,
3296#endif /* 64-bit intptr_t */
3297 };
3298
3300 struct size {
3301 intptr_t bytes;
3302 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3303 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3304 };
3305
3308
3313
3325
3328
3331
3337
3338 MDBX_CXX14_CONSTEXPR geometry &make_fixed(intptr_t size) noexcept;
3339 MDBX_CXX14_CONSTEXPR geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3340
3342 MDBX_CXX14_CONSTEXPR geometry &set_size_lower(intptr_t size) noexcept;
3344 MDBX_CXX14_CONSTEXPR geometry &set_size_now(intptr_t size) noexcept;
3346 MDBX_CXX14_CONSTEXPR geometry &set_size_upper(intptr_t size) noexcept;
3348 MDBX_CXX14_CONSTEXPR geometry &set_growth_step(intptr_t step) noexcept;
3350 MDBX_CXX14_CONSTEXPR geometry &set_shrink_threshold(intptr_t threshold) noexcept;
3352 MDBX_CXX14_CONSTEXPR geometry &set_pagesize(intptr_t size) noexcept;
3353
3356 geometry(const geometry &) noexcept = default;
3357 MDBX_CXX14_CONSTEXPR geometry &operator=(const geometry &) noexcept = default;
3363
3365 static MDBX_CXX14_CONSTEXPR geometry fixed(intptr_t size) noexcept {
3366 geometry result;
3367 return result.make_fixed(size);
3368 }
3369
3371 intptr_t upper = default_value) noexcept {
3372 geometry result;
3373 return result.make_dynamic(lower, upper);
3374 }
3375
3376#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
3377 friend auto operator<=>(const geometry &a, const geometry &b) = default;
3378#else
3379 MDBX_CXX14_CONSTEXPR bool operator==(const geometry &other) const noexcept {
3380 return size_lower == other.size_lower && size_now == other.size_now && size_upper == other.size_upper &&
3381 growth_step == other.growth_step && shrink_threshold == other.shrink_threshold &&
3382 pagesize == other.pagesize;
3383 }
3384 MDBX_CXX14_CONSTEXPR bool operator!=(const geometry &other) const noexcept { return !(*this == other); }
3385#endif
3386 };
3387
3389 enum class mode : unsigned {
3390 readonly,
3391 write_file_io, // don't available on OpenBSD
3392 write_mapped_io,
3393 nested_transactions = write_file_io
3394 };
3395
3397 enum class durability : unsigned {
3398 robust_synchronous,
3399 half_synchronous_weak_last,
3400 lazy_weak_tail,
3401 whole_fragile
3402 };
3403
3407 bool lifo{false};
3410 reclaiming_options(const reclaiming_options &) noexcept = default;
3413 MDBX_CXX14_CONSTEXPR reclaiming_options &set_lifo(bool value = true) noexcept;
3414
3415#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
3416 friend auto operator<=>(const reclaiming_options &a, const reclaiming_options &b) = default;
3417#else
3418 MDBX_CXX14_CONSTEXPR bool operator==(const reclaiming_options &other) const noexcept {
3419 return lifo == other.lifo;
3420 }
3421 MDBX_CXX14_CONSTEXPR bool operator!=(const reclaiming_options &other) const noexcept { return !(*this == other); }
3422#endif
3423
3425 };
3426
3435 bool exclusive{false};
3444 operate_options(const operate_options &) noexcept = default;
3446
3448 MDBX_CXX14_CONSTEXPR operate_options &set_no_sticky_threads(bool value = true) noexcept;
3452 MDBX_CXX14_CONSTEXPR operate_options &set_exclusive(bool value = true) noexcept;
3454 MDBX_CXX14_CONSTEXPR operate_options &set_disable_readahead(bool value = true) noexcept;
3458 MDBX_CXX14_CONSTEXPR operate_options &set_enable_validation(bool value = true) noexcept;
3459
3460#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
3461 friend auto operator<=>(const operate_options &a, const operate_options &b) = default;
3462#else
3463 MDBX_CXX14_CONSTEXPR bool operator==(const operate_options &other) const noexcept {
3464 return no_sticky_threads == other.no_sticky_threads && nested_transactions == other.nested_transactions &&
3465 exclusive == other.exclusive && disable_readahead == other.disable_readahead &&
3466 disable_clear_memory == other.disable_clear_memory && enable_validation == other.enable_validation;
3467 }
3468 MDBX_CXX14_CONSTEXPR bool operator!=(const operate_options &other) const noexcept { return !(*this == other); }
3469#endif
3470
3472 };
3473
3478 unsigned max_maps{0};
3481 unsigned max_readers{0};
3486
3497 operate_parameters(const operate_parameters &) noexcept = default;
3499
3502 MDBX_CXX14_CONSTEXPR operate_parameters &set_max_maps(unsigned value) noexcept;
3514
3530 MDBX_CXX14_CONSTEXPR operate_parameters &nested_transactions(bool value = true) noexcept;
3532 MDBX_CXX14_CONSTEXPR operate_parameters &lifo(bool value = true) noexcept;
3534 MDBX_CXX14_CONSTEXPR operate_parameters &no_sticky_threads(bool value = true) noexcept;
3536 MDBX_CXX14_CONSTEXPR operate_parameters &exclusive(bool value = true) noexcept;
3538 MDBX_CXX14_CONSTEXPR operate_parameters &disable_readahead(bool value = true) noexcept;
3542 MDBX_CXX14_CONSTEXPR operate_parameters &enable_validation(bool value = true) noexcept;
3543
3555
3556#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
3557 friend auto operator<=>(const operate_parameters &a, const operate_parameters &b) = default;
3558#else
3559 MDBX_CXX14_CONSTEXPR bool operator==(const operate_parameters &other) const noexcept {
3560 return max_maps == other.max_maps && max_readers == other.max_readers && mode == other.mode &&
3561 durability == other.durability && reclaiming == other.reclaiming && options == other.options;
3562 }
3563 MDBX_CXX14_CONSTEXPR bool operator!=(const operate_parameters &other) const noexcept { return !(*this == other); }
3564#endif
3565
3569 bool use_subdirectory = false
3570 ) const;
3575 };
3576
3580 MDBX_NODISCARD inline env::mode get_mode() const;
3587
3590 bool is_pristine() const;
3591
3593 bool is_empty() const;
3594
3596 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3597
3599 struct sysraminfo {
3600 intptr_t page_size{0};
3601 intptr_t total_pages{0};
3602 intptr_t avail_pages{0};
3603 };
3604
3605 MDBX_NODISCARD static inline sysraminfo get_sysraminfo();
3606
3607 struct limits {
3608 limits() = delete;
3610 static inline size_t pagesize_min() noexcept;
3612 static inline size_t pagesize_max() noexcept;
3614 static inline size_t dbsize_min(intptr_t pagesize);
3616 static inline size_t dbsize_max(intptr_t pagesize);
3618 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3620 static inline size_t key_min(key_mode mode) noexcept;
3622 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3624 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3626 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3628 static inline size_t key_max(const env &, key_mode mode);
3630 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3632 static inline size_t value_min(value_mode) noexcept;
3633
3635 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3637 static inline size_t value_max(intptr_t pagesize, value_mode);
3639 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3641 static inline size_t value_max(const env &, value_mode);
3642
3645 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3648 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3651 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3654 static inline size_t pairsize4page_max(const env &, value_mode);
3655
3658 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3661 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3664 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3667 static inline size_t valsize4page_max(const env &, value_mode);
3668
3671 static inline size_t transaction_size_max(intptr_t pagesize);
3672
3674 static inline size_t max_map_handles(void);
3675 };
3676
3678 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3680 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3682 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3684 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3686 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3688 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3692
3695#ifdef MDBX_STD_FILESYSTEM_PATH
3696 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3697#endif /* MDBX_STD_FILESYSTEM_PATH */
3698#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3699 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3700 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3701#endif /* Windows */
3702 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3703 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3704
3706 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3707
3723
3725#ifdef MDBX_STD_FILESYSTEM_PATH
3726 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3727#endif /* MDBX_STD_FILESYSTEM_PATH */
3728#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3729 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3730 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3731#endif /* Windows */
3732 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3733 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3734
3737
3740
3747 MDBX_NODISCARD static inline info get_preopen_snapinfo(const ::std::string &pathname);
3748 MDBX_NODISCARD static inline info get_preopen_snapinfo(const char *pathname);
3749#ifdef MDBX_STD_FILESYSTEM_PATH
3752#endif /* MDBX_STD_FILESYSTEM_PATH */
3753#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3755 MDBX_NODISCARD static inline info get_preopen_snapinfo(const ::std::wstring &pathname);
3757 MDBX_NODISCARD static inline info get_preopen_snapinfo(const wchar_t *pathname);
3758#endif /* Windows */
3759
3761 inline stat get_stat() const;
3762
3764 size_t get_pagesize() const { return get_stat().ms_psize; }
3765
3767 inline info get_info() const;
3768
3770 inline stat get_stat(const txn &) const;
3771
3773 inline info get_info(const txn &) const;
3774
3776 inline filehandle get_filehandle() const;
3777
3779 const path_char *get_path() const;
3780
3782 inline MDBX_env_flags_t get_flags() const;
3783
3784 inline bool is_readonly() const { return (get_flags() & MDBX_RDONLY) != 0; }
3785
3786 inline bool is_exclusive() const { return (get_flags() & MDBX_EXCLUSIVE) != 0; }
3787
3788 inline bool is_cooperative() const { return !is_exclusive(); }
3789
3790 inline bool is_writemap() const { return (get_flags() & MDBX_WRITEMAP) != 0; }
3791
3792 inline bool is_readwrite() const { return !is_readonly(); }
3793
3794 inline bool is_nested_transactions_available() const { return (get_flags() & (MDBX_WRITEMAP | MDBX_RDONLY)) == 0; }
3795
3798 inline unsigned max_readers() const;
3799
3802 inline unsigned max_maps() const;
3803
3805 inline void *get_context() const noexcept;
3806
3808 inline env &set_context(void *your_context);
3809
3825 inline env &set_sync_threshold(size_t bytes);
3826
3832 inline size_t sync_threshold() const;
3833
3834#if __cplusplus >= 201103L || defined(DOXYGEN)
3855 inline env &set_sync_period(const duration &period);
3856
3862 inline duration sync_period() const;
3863#endif
3864
3868 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3869
3872 inline unsigned sync_period__seconds_16dot16() const;
3873
3877 inline env &set_sync_period__seconds_double(double seconds);
3878
3881 inline double sync_period__seconds_double() const;
3882
3936
3938 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3939
3941 inline uint64_t extra_option(extra_runtime_option option) const;
3942
3944 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3945
3947 inline env &set_geometry(const geometry &size);
3948
3952 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3953
3957 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3958
3977 inline void close_map(const map_handle &);
3978
3981 int slot;
3990 size_t bytes_used;
3999
4001 size_t used, size_t retained) noexcept;
4002 };
4003
4011 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
4012
4015 inline unsigned check_readers();
4016
4019 inline void thread_register();
4021 inline void thread_unregister();
4022
4029 MDBX_NODISCARD inline int warmup(MDBX_warmup_flags_t flags, unsigned timeout_seconds_16dot16,
4030 const MDBX_txn *txn = nullptr) const;
4031
4034#if !defined(_WIN32) && !defined(_WIN64) || defined(DOXYGEN)
4035 inline void resurrect_after_fork();
4036#endif /* !Windows */
4037
4044 inline void turn_for_recovery(unsigned target_meta);
4045
4072 unsigned timeout_seconds_16dot16 = 0) const;
4073
4092
4097 inline MDBX_hsr_func get_HandleSlowReaders() const noexcept;
4098
4100 inline txn_managed start_read() const;
4101
4103 inline txn_managed prepare_read() const;
4104
4106 inline txn_managed start_write(txn &parent);
4107
4109 inline txn_managed start_write(bool dont_wait = false);
4110
4113
4124 inline bool txn_lock(bool dont_wait = false);
4125
4128 inline void txn_unlock();
4129
4132
4135 enum class defrag_control : int {
4136 proceed = 0,
4137 abort = -1,
4138 discontinue = 1,
4139 };
4140
4141 template <typename VISITOR>
4180 inline defrag_result defrag(VISITOR &visitor, size_t defrag_atleast = 0, size_t time_atleast_dot16 = 0,
4181 size_t defrag_enough = 0, size_t time_limit_dot16 = 0,
4182 intptr_t acceptable_backlash = -1, intptr_t preferred_batch = 0);
4204 inline defrag_result defrag(size_t defrag_atleast = 0, size_t time_atleast_dot16 = 0, size_t defrag_enough = 0,
4205 size_t time_limit_dot16 = 0, intptr_t acceptable_backlash = -1,
4206 intptr_t preferred_batch = 0);
4207};
4208
4217class LIBMDBX_API_TYPE env_managed : public env {
4218 using inherited = env;
4220 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
4221 void setup(unsigned max_maps, unsigned max_readers = 0);
4222
4223public:
4224 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
4225
4227#ifdef MDBX_STD_FILESYSTEM_PATH
4228 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
4229#endif /* MDBX_STD_FILESYSTEM_PATH */
4230#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
4231 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
4232 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
4233#endif /* Windows */
4234 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
4235 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
4236
4243 bool use_subdirectory{false};
4245 create_parameters(const create_parameters &) noexcept = default;
4246
4252 MDBX_CXX14_CONSTEXPR create_parameters &set_use_subdirectory(bool value = true) noexcept;
4253
4254#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
4255 friend auto operator<=>(const create_parameters &a, const create_parameters &b) = default;
4256#else
4257 MDBX_CXX14_CONSTEXPR bool operator==(const create_parameters &other) const noexcept {
4258 return geometry == other.geometry && file_mode_bits == other.file_mode_bits &&
4259 use_subdirectory == other.use_subdirectory;
4260 }
4261 MDBX_CXX14_CONSTEXPR bool operator!=(const create_parameters &other) const noexcept { return !(*this == other); }
4262#endif
4263 };
4264
4266#ifdef MDBX_STD_FILESYSTEM_PATH
4268 bool accede = true);
4269#endif /* MDBX_STD_FILESYSTEM_PATH */
4270#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
4271 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
4272 bool accede = true);
4273 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
4274 bool accede = true);
4275#endif /* Windows */
4276 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
4277 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
4278
4297 static env_managed open_for_recovery(const char *pathname, unsigned target_meta, bool writeable,
4298 unsigned max_maps = 2);
4299 static env_managed open_for_recovery(const ::std::string &pathname, unsigned target_meta, bool writeable,
4300 unsigned max_maps = 2);
4301#ifdef MDBX_STD_FILESYSTEM_PATH
4302 static env_managed open_for_recovery(const MDBX_STD_FILESYSTEM_PATH &pathname, unsigned target_meta, bool writeable,
4303 unsigned max_maps = 2);
4304#endif /* MDBX_STD_FILESYSTEM_PATH */
4305#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
4306 static env_managed open_for_recovery(const wchar_t *pathname, unsigned target_meta, bool writeable,
4307 unsigned max_maps = 2);
4308 static env_managed open_for_recovery(const ::std::wstring &pathname, unsigned target_meta, bool writeable,
4309 unsigned max_maps = 2);
4310#endif /* Windows */
4311
4326 void close(bool dont_sync = false);
4327
4328 env_managed(env_managed &&) = default;
4329 env_managed &operator=(env_managed &&other) noexcept;
4330 env_managed(const env_managed &) = delete;
4331 env_managed &operator=(const env_managed &) = delete;
4332 virtual ~env_managed();
4333};
4334
4345
4348inline ::std::string ratio2digits(uint64_t numerator, uint64_t denominator, int precision) {
4349 char buffer[64];
4350 return ::mdbx_ratio2digits(numerator, denominator, precision, buffer, sizeof(buffer));
4351}
4352
4355inline ::std::string ratio2percents(uint64_t value, uint64_t whole) {
4356 char buffer[64];
4357 return ::mdbx_ratio2percents(value, whole, buffer, sizeof(buffer));
4358}
4359
4362inline bool is_readahead_reasonable(size_t volume, intptr_t redundancy) {
4363 return ::mdbx_is_readahead_reasonable(volume, redundancy) != 0;
4364}
4365
4369inline MDBX_cmp_func get_datacmp(MDBX_db_flags_t flags) { return ::mdbx_get_datacmp(flags); }
4370
4377 MDBX_debug_func logger = nullptr) {
4378 return ::mdbx_setup_debug(log_level, debug_flags, logger);
4379}
4380
4386 MDBX_debug_func_nofmt logger, char *logger_buffer, size_t logger_buffer_size) {
4387 return ::mdbx_setup_debug_nofmt(log_level, debug_flags, logger, logger_buffer, logger_buffer_size);
4388}
4389
4392inline void set_panic(MDBX_panic_func func) { ::mdbx_set_panic(func); }
4393
4402protected:
4403 friend class cursor;
4405 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
4406
4407public:
4408 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
4409 txn(const txn &) noexcept = default;
4410 txn &operator=(const txn &) noexcept = default;
4411 inline txn &operator=(txn &&) noexcept;
4412 inline txn(txn &&) noexcept;
4413 inline ~txn() noexcept;
4414
4415 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
4416 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const noexcept { return handle_; }
4417 MDBX_CXX14_CONSTEXPR operator MDBX_txn *() noexcept { return handle_; }
4418 MDBX_CXX14_CONSTEXPR const MDBX_txn *handle() const noexcept { return handle_; }
4420 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
4421 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
4422
4424 inline ::mdbx::env env() const noexcept;
4426 inline MDBX_txn_flags_t flags() const;
4428 inline uint64_t id() const;
4429
4431 inline void *get_context() const noexcept;
4432
4434 inline txn &set_context(void *your_context);
4435
4437 inline bool is_dirty(const void *ptr) const;
4438
4440 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
4441
4443 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
4444
4446 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
4447
4450 inline info get_info(bool scan_reader_lock_table = false) const;
4451
4454 size_t size_max() const { return env().transaction_size_max(); }
4455
4457 size_t size_current() const {
4458 assert(is_readwrite());
4459 return size_t(get_info().txn_space_dirty);
4460 }
4461
4462 //----------------------------------------------------------------------------
4463
4465 inline void reset_reading();
4466
4468 inline void renew_reading();
4469
4479 inline bool refresh();
4480
4482 inline txn_managed clone(void *context = nullptr) const;
4483
4485 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
4486
4492 inline void copy(const char *destination, bool compactify, bool force_dynamic_size = false);
4494 inline void copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
4495#ifdef MDBX_STD_FILESYSTEM_PATH
4497 inline void copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
4498#endif /* MDBX_STD_FILESYSTEM_PATH */
4499#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
4501 inline void copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
4503 inline void copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
4504#endif /* Windows */
4505
4508 inline void copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
4509
4511 inline void make_broken();
4512
4514 inline void park_reading(bool autounpark = true);
4515
4518 inline bool unpark_reading(bool restart_if_ousted = true);
4519
4522
4525
4527 inline cursor_managed open_cursor(map_handle map) const;
4528
4530 inline size_t release_all_cursors(bool unbind) const;
4531
4533 inline size_t close_all_cursors() const { return release_all_cursors(false); }
4534
4536 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
4537
4539 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4540 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
4542 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4543 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
4545 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4546 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
4547
4549 inline map_handle open_map_accede(const char *name) const;
4551 inline map_handle open_map_accede(const ::std::string &name) const;
4553 inline map_handle open_map_accede(const slice &name) const;
4554
4556 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4557 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
4559 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4560 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
4562 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4563 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
4564
4566 inline void drop_map(map_handle map);
4570 bool drop_map(const char *name, bool throw_if_absent = false);
4574 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
4578 bool drop_map(const slice &name, bool throw_if_absent = false);
4579
4581 inline void clear_map(map_handle map);
4584 bool clear_map(const char *name, bool throw_if_absent = false);
4587 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
4590 bool clear_map(const slice &name, bool throw_if_absent = false);
4591
4593 inline void rename_map(map_handle map, const char *new_name);
4595 inline void rename_map(map_handle map, const ::std::string &new_name);
4597 inline void rename_map(map_handle map, const slice &new_name);
4601 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
4605 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
4609 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
4610
4611#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
4612
4614 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4615 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
4616 return open_map(slice(name), key_mode, value_mode);
4617 }
4618
4619 inline map_handle open_map_accede(const ::std::string_view &name) const;
4621 inline map_handle create_map(const ::std::string_view &name,
4622 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
4623 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
4624 return create_map(slice(name), key_mode, value_mode);
4625 }
4626
4629 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
4630 return drop_map(slice(name), throw_if_absent);
4631 }
4632
4634 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
4635 return clear_map(slice(name), throw_if_absent);
4636 }
4637
4638 inline void rename_map(map_handle map, const ::std::string_view &new_name);
4642 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
4643 bool throw_if_absent = false) {
4644 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
4645 }
4646#endif /* __cpp_lib_string_view >= 201606L */
4647
4650 inline map_stat get_map_stat(map_handle map) const;
4653 inline uint32_t get_tree_deepmask(map_handle map) const;
4655 inline map_handle::info get_map_flags(map_handle map) const;
4656
4669 template <typename VISITOR> inline int enumerate_tables(VISITOR &visitor) const;
4670
4688 template <typename VISITOR> inline gc_info get_gc_info(VISITOR &visitor) const;
4689 inline gc_info get_gc_info() const;
4690
4693 inline txn &put_canary(const canary &);
4695 inline canary get_canary() const;
4696
4698 inline uint64_t sequence(map_handle map) const;
4700 inline uint64_t sequence(map_handle map, uint64_t increment);
4701
4703 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
4705 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
4707 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
4709 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
4710
4712 inline slice get(map_handle map, const slice &key) const;
4713
4716
4735 MDBX_NODISCARD inline cache_result get_cached(map_handle map, const slice &key, slice *data,
4736 cache_entry &entry) const;
4737
4749 MDBX_NODISCARD inline slice get_cached(map_handle map, const slice &key, cache_entry &entry,
4750 cache_status *status = nullptr) const;
4752 inline slice get(map_handle map, slice key, size_t &values_count) const;
4754 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
4756 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
4760 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
4764 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
4765
4766 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4767 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
4768 inline void insert(map_handle map, const slice &key, slice value);
4769 inline value_result try_insert(map_handle map, const slice &key, slice value);
4770 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
4771 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
4772
4773 inline void upsert(map_handle map, const slice &key, const slice &value);
4774 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
4775
4776 inline void update(map_handle map, const slice &key, const slice &value);
4777 inline bool try_update(map_handle map, const slice &key, const slice &value);
4778 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
4779 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
4780
4781 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
4782 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
4783 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
4784 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
4785
4787 inline bool erase(map_handle map, const slice &key);
4788
4790 inline bool erase(map_handle map, const slice &key, const slice &value);
4791
4793 inline void replace(map_handle map, const slice &key, slice &old_value, const slice &new_value);
4794
4796 template <class BUFFER, class ALLOCATOR = typename BUFFER::allocator_type>
4797 inline BUFFER extract(map_handle map, const slice &key, const ALLOCATOR &alloc = ALLOCATOR());
4798
4800 template <class BUFFER, class ALLOCATOR = typename BUFFER::allocator_type>
4801 inline BUFFER replace(map_handle map, const slice &key, const slice &new_value, const ALLOCATOR &alloc = ALLOCATOR());
4802
4803 template <class BUFFER, class ALLOCATOR = typename BUFFER::allocator_type>
4804 inline BUFFER replace_reserve(map_handle map, const slice &key, size_t length, slice &new_value_reservation,
4805 const ALLOCATOR &alloc = ALLOCATOR());
4806
4823 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4824 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4825 return append(map, kv.key, kv.value, multivalue_order_preserved);
4826 }
4827
4828 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4829 const void *values_array, size_t values_count, put_mode mode,
4830 bool allow_partial = false);
4831 template <typename VALUE>
4832 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4833 put_mode mode, bool allow_partial = false) {
4834 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4835 !::std::is_array<VALUE>::value,
4836 "Must be a standard layout type!");
4837 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4838 }
4839 template <typename VALUE>
4840 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4841 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4842 }
4843
4844 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4845 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4846 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4847 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4848};
4849
4858class LIBMDBX_API_TYPE txn_managed : public txn {
4859 using inherited = txn;
4860 friend class env;
4861 friend class txn;
4863 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4864
4865public:
4866 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4867 txn_managed(txn_managed &&) = default;
4868 txn_managed &operator=(txn_managed &&other) noexcept;
4869 txn_managed(const txn_managed &) = delete;
4870 txn_managed &operator=(const txn_managed &) = delete;
4871 ~txn_managed();
4872
4873 //----------------------------------------------------------------------------
4875
4877 void abort();
4881 void abort(finalization_latency &latency) { return abort(&latency); }
4885 finalization_latency result;
4886 abort(&result);
4887 return result;
4888 }
4889
4891 void commit();
4895 void commit(finalization_latency &latency) { return commit(&latency); }
4899 finalization_latency result;
4900 commit(&result);
4901 return result;
4902 }
4903
4909 bool checkpoint(finalization_latency &latency) { return checkpoint(&latency); }
4912 std::pair<bool, finalization_latency> checkpoint_get_latency() {
4913 finalization_latency latency;
4914 bool result = checkpoint(&latency);
4915 return std::make_pair(result, latency);
4916 }
4917
4927 finalization_latency result;
4928 commit_embark_read(&result);
4929 return result;
4930 }
4931
4934 bool amend(bool dont_wait = false);
4935};
4936
4944protected:
4946
4947public:
4949 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4950 cursor(const cursor &) noexcept = default;
4951 cursor &operator=(const cursor &) noexcept = default;
4952 inline cursor &operator=(cursor &&) noexcept;
4953 inline cursor(cursor &&) noexcept;
4954 inline ~cursor() noexcept;
4955 cursor_managed clone(void *your_context = nullptr) const;
4956 inline cursor &assign(const cursor &);
4957 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
4958 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const noexcept { return handle_; }
4959 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *() noexcept { return handle_; }
4960 MDBX_CXX14_CONSTEXPR const MDBX_cursor *handle() const noexcept { return handle_; }
4962 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept {
4963 return a.handle_ == b.handle_;
4964 }
4965 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept {
4966 return a.handle_ != b.handle_;
4967 }
4968
4969 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4970 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4971
4972 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4973 return compare_position(*this, other, ignore_nested) < 0;
4974 }
4975
4976 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4977 return compare_position(*this, other, ignore_nested) <= 0;
4978 }
4979
4980 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4981 return compare_position(*this, other, ignore_nested) == 0;
4982 }
4983
4984 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4985 return compare_position(*this, other, ignore_nested) > 0;
4986 }
4987
4988 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4989 return compare_position(*this, other, ignore_nested) >= 0;
4990 }
4991
4993 inline void *get_context() const noexcept;
4994
4996 inline cursor &set_context(void *your_context);
4997
5004
5011
5014
5018
5019 /* Doubtless cursor positioning at a specified key. */
5025
5026 /* Doubtless cursor positioning at a specified key-value pair
5027 * for dupsort/multi-value hives. */
5033
5040
5045 };
5046
5047 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
5048 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
5049 // и других параметров в bool-throw_notfound.
5050
5051 struct move_result : public pair_result {
5052 inline move_result(const cursor &cursor, bool throw_notfound);
5053 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
5054 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
5055 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
5056 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
5057 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
5058 bool throw_notfound);
5059 move_result(const move_result &) noexcept = default;
5060 move_result &operator=(const move_result &) noexcept = default;
5061 };
5062
5063 struct estimate_result : public pair {
5068 : estimate_result(cursor, operation, key, slice::invalid()) {}
5069 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
5070 estimate_result(const estimate_result &) noexcept = default;
5071 estimate_result &operator=(const estimate_result &) noexcept = default;
5072 };
5073
5074protected:
5075 /* fake `const`, but for specific move/get operations */
5076 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
5077
5078 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
5079
5080public:
5081 template <typename CALLABLE_PREDICATE>
5082 bool scan_until(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
5083 struct wrapper : public exception_thunk {
5084 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
5085 auto thunk = static_cast<wrapper *>(context);
5086 assert(thunk->is_clean());
5087 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
5088 try {
5089 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
5090 } catch (... /* capture any exception to rethrow it over C code */) {
5091 thunk->capture();
5092 return MDBX_RESULT_TRUE;
5093 }
5094 }
5095 } thunk;
5097 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
5098 thunk);
5099 }
5100
5101 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
5102 return scan_until(std::move(predicate), backward ? last : first, backward ? previous : next);
5103 }
5104
5105 template <typename CALLABLE_PREDICATE>
5106 bool scan_until_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
5107 move_operation turn = next) {
5108 struct wrapper : public exception_thunk {
5109 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
5110 auto thunk = static_cast<wrapper *>(context);
5111 assert(thunk->is_clean());
5112 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
5113 try {
5114 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
5115 } catch (... /* capture any exception to rethrow it over C code */) {
5116 thunk->capture();
5117 return MDBX_RESULT_TRUE;
5118 }
5119 }
5120 } thunk;
5121 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
5122 &from, nullptr, MDBX_cursor_op(turn), &predicate),
5123 thunk);
5124 }
5125
5126 template <typename CALLABLE_PREDICATE>
5127 bool scan_until_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
5128 move_operation turn = next) {
5129 struct wrapper : public exception_thunk {
5130 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
5131 auto thunk = static_cast<wrapper *>(context);
5132 assert(thunk->is_clean());
5133 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
5134 try {
5135 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
5136 } catch (... /* capture any exception to rethrow it over C code */) {
5137 thunk->capture();
5138 return MDBX_RESULT_TRUE;
5139 }
5140 }
5141 } thunk;
5142 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
5143 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
5144 thunk);
5145 }
5146
5147 move_result move(move_operation operation, bool throw_notfound) {
5148 return move_result(*this, operation, throw_notfound);
5149 }
5150 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
5151 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
5152 }
5153 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
5154 return move_result(*this, operation, key, value, throw_notfound);
5155 }
5156 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
5157 return move(operation, &key, &value, throw_notfound);
5158 }
5159
5160 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
5161 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
5162 move_result to_previous_last_multi(bool throw_notfound = true) {
5163 return move(multi_prevkey_lastvalue, throw_notfound);
5164 }
5165 move_result to_current_first_multi(bool throw_notfound = true) {
5166 return move(multi_currentkey_firstvalue, throw_notfound);
5167 }
5168 move_result to_current_prev_multi(bool throw_notfound = true) {
5169 return move(multi_currentkey_prevvalue, throw_notfound);
5170 }
5171 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
5172 move_result to_current_next_multi(bool throw_notfound = true) {
5173 return move(multi_currentkey_nextvalue, throw_notfound);
5174 }
5175 move_result to_current_last_multi(bool throw_notfound = true) {
5176 return move(multi_currentkey_lastvalue, throw_notfound);
5177 }
5178 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
5179 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
5180 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
5181
5182 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
5183 return move(key_lesser_than, key, throw_notfound);
5184 }
5185 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
5186 return move(key_lesser_or_equal, key, throw_notfound);
5187 }
5188 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
5189 return move(key_equal, key, throw_notfound);
5190 }
5191 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
5192 return move(key_exact, key, throw_notfound);
5193 }
5194 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
5195 return move(key_greater_or_equal, key, throw_notfound);
5196 }
5197 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
5198 return move(key_greater_than, key, throw_notfound);
5199 }
5200
5201 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
5202 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
5203 }
5204 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
5205 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
5206 }
5207 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
5208 return move(multi_exactkey_value_equal, key, value, throw_notfound);
5209 }
5210 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
5211 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
5212 }
5213 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
5214 return move(multi_exactkey_value_greater, key, value, throw_notfound);
5215 }
5216
5217 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
5218 return move(pair_lesser_than, key, value, throw_notfound);
5219 }
5220 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
5221 return move(pair_lesser_or_equal, key, value, throw_notfound);
5222 }
5223 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
5224 return move(pair_equal, key, value, throw_notfound);
5225 }
5226 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
5227 return move(pair_exact, key, value, throw_notfound);
5228 }
5229 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
5230 return move(pair_greater_or_equal, key, value, throw_notfound);
5231 }
5232 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
5233 return move(pair_greater_than, key, value, throw_notfound);
5234 }
5235
5236 inline bool seek(const slice &key);
5237 inline move_result find(const slice &key, bool throw_notfound = true);
5238 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
5239 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
5240
5242 inline size_t count_multivalue() const;
5245 inline size_t count_multivalue(MDBX_stat *stat) const;
5246
5262 inline ::std::vector<pair> get_batch(size_t max_pairs, move_operation op, bool *is_last = nullptr) const;
5263
5270 inline void ignore_key_order();
5271
5272 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
5273 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
5274 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
5275
5276 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
5277 return move(seek_and_batch_samelength, key, throw_notfound);
5278 }
5279
5280 inline move_result get_multiple_samelength(bool throw_notfound = false) {
5281 return move(batch_samelength, throw_notfound);
5282 }
5283
5284 inline move_result next_multiple_samelength(bool throw_notfound = false) {
5285 return move(batch_samelength_next, throw_notfound);
5286 }
5287
5288 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
5289 return move(batch_samelength_previous, throw_notfound);
5290 }
5291
5292 inline bool eof() const;
5293 inline bool on_first() const;
5294 inline bool on_last() const;
5295 inline bool on_first_multival() const;
5296 inline bool on_last_multival() const;
5297 inline estimate_result estimate(const slice &key, const slice &value) const;
5298 inline estimate_result estimate(const slice &key) const;
5299 inline estimate_result estimate(move_operation operation) const;
5300 inline estimate_result estimate(move_operation operation, const slice &key) const;
5301
5302 static inline ptrdiff_t distance_between(const cursor from, const cursor to,
5303 unsigned deepness = /* enough to cover whole tree height */ 42);
5304 inline ptrdiff_t distance_from(const cursor from,
5305 unsigned deepness = /* enough to cover whole tree height */ 42) const {
5306 return distance_between(from, *this, deepness);
5307 }
5308 inline ptrdiff_t distance_to(const cursor to, unsigned deepness = /* enough to cover whole tree height */ 42) const {
5309 return distance_between(*this, to, deepness);
5310 }
5311 inline ptrdiff_t distance_from_first(unsigned deepness = /* enough to cover whole tree height */ 42) const {
5312 return distance_between(nullptr, *this, deepness);
5313 }
5314 inline ptrdiff_t distance_to_end(unsigned deepness = /* enough to cover whole tree height */ 42) const {
5315 return distance_between(*this, nullptr, deepness);
5316 }
5317
5318 inline bool scroll(intptr_t distable, unsigned deepness = /* enough to cover whole tree height */ 42,
5319 bool throw_notfound = true);
5320
5321 static inline bool distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size,
5322 unsigned deepness = /* enough to cover whole tree height */ 42);
5323
5324 static inline bool distribute(const cursor from, const cursor to, const std::vector<cursor> &cursors,
5325 unsigned deepness = /* enough to cover whole tree height */ 42);
5326
5327 static inline bool distribute(const cursor from, const cursor to, const std::vector<cursor_managed> &cursors,
5328 unsigned deepness = /* enough to cover whole tree height */ 42);
5329
5330 //----------------------------------------------------------------------------
5331
5333 inline void renew(::mdbx::txn &txn);
5334
5336 inline void bind(::mdbx::txn &txn, ::mdbx::map_handle map_handle);
5337
5339 inline void unbind();
5340
5342 inline ::mdbx::txn txn() const;
5343 inline map_handle map() const;
5344
5345 inline operator ::mdbx::txn() const { return txn(); }
5346 inline operator ::mdbx::map_handle() const { return map(); }
5347
5348 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
5349 inline void put(const slice &key, slice value, put_mode mode);
5350 inline void insert(const slice &key, slice value);
5351 inline value_result try_insert(const slice &key, slice value);
5352 inline slice insert_reserve(const slice &key, size_t value_length);
5353 inline value_result try_insert_reserve(const slice &key, size_t value_length);
5354
5355 inline void upsert(const slice &key, const slice &value);
5356 inline slice upsert_reserve(const slice &key, size_t value_length);
5357
5359 void update_current(const slice &value);
5361 slice reserve_current(size_t value_length);
5363 slice reverse_current(size_t value_length) { return reserve_current(value_length); }
5364
5365 inline void update(const slice &key, const slice &value);
5366 inline bool try_update(const slice &key, const slice &value);
5367 inline slice update_reserve(const slice &key, size_t value_length);
5368 inline value_result try_update_reserve(const slice &key, size_t value_length);
5369
5370 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
5371 void insert(const pair &kv) { return insert(kv.key, kv.value); }
5372 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
5373 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
5374
5376 inline bool erase(bool whole_multivalue = false);
5377
5380 inline bool erase(const slice &key, bool whole_multivalue = true);
5381
5384 inline bool erase(const slice &key, const slice &value);
5385
5403
5409 inline size_t erase_bunch(bunch_delete action);
5410
5420 inline size_t erase_range(const cursor &end, bool end_including);
5421
5428 inline void reset();
5429
5430 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
5431 size_t values_count, put_mode mode, bool allow_partial = false);
5432 template <typename VALUE>
5433 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
5434 bool allow_partial = false) {
5435 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
5436 !::std::is_array<VALUE>::value,
5437 "Must be a standard layout type!");
5438 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
5439 }
5440 template <typename VALUE>
5441 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
5442 put_multiple_samelength(key, vector.data(), vector.size(), mode);
5443 }
5444};
5445
5453class LIBMDBX_API_TYPE cursor_managed : public cursor {
5454 using inherited = cursor;
5455 friend class txn;
5457 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
5458
5459public:
5461 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
5462 if (MDBX_UNLIKELY(!handle_))
5463 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
5464 }
5465
5467 void close();
5468
5469 cursor_managed(cursor_managed &&) = default;
5470 cursor_managed &operator=(cursor_managed &&other) noexcept;
5471
5472 inline MDBX_cursor *withdraw_handle() noexcept {
5474 handle_ = nullptr;
5475 return handle;
5476 }
5477
5478 cursor_managed(const cursor_managed &) = delete;
5479 cursor_managed &operator=(const cursor_managed &) = delete;
5481};
5482
5484
5485//==============================================================================
5486//
5487// Inline body of the libmdbx C++ API
5488//
5489
5490MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
5491MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
5492
5493static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
5494#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
5495 if (::std::is_constant_evaluated()) {
5496 size_t i = 0;
5497 if (c_str)
5498 while (c_str[i])
5499 ++i;
5500 return i;
5501 }
5502#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
5503#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
5504 return c_str ? ::std::string_view(c_str).length() : 0;
5505#else
5506 return c_str ? ::std::strlen(c_str) : 0;
5507#endif
5508}
5509
5510MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
5511#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
5512 if (::std::is_constant_evaluated()) {
5513 for (size_t i = 0; i < bytes; ++i)
5514 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
5515 return dest;
5516 } else
5517#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
5518 return ::std::memcpy(dest, src, bytes);
5519}
5520
5521static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
5522#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
5523 if (::std::is_constant_evaluated()) {
5524 for (size_t i = 0; i < bytes; ++i) {
5525 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
5526 if (diff)
5527 return diff;
5528 }
5529 return 0;
5530 } else
5531#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
5532 return bytes ? ::std::memcmp(a, b, bytes) : 0;
5533}
5534
5535//------------------------------------------------------------------------------
5536
5539
5543
5547
5548inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
5549
5550inline void exception_thunk::capture() noexcept {
5551 assert(is_clean());
5552 captured_ = ::std::current_exception();
5553}
5554
5556 if (captured_)
5557 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
5558}
5559
5560//------------------------------------------------------------------------------
5561
5562MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
5563
5564inline error &error::operator=(MDBX_error_t error_code) noexcept {
5565 code_ = error_code;
5566 return *this;
5567}
5568
5569MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
5570
5571MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
5572
5573MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
5574
5575MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_TRUE; }
5576
5577MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_FALSE; }
5578
5580 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
5581}
5582
5583MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
5584
5589
5590inline void error::throw_exception(int error_code) {
5591 const error trouble(static_cast<MDBX_error_t>(error_code));
5592 trouble.throw_exception();
5593}
5594
5595inline void error::throw_on_failure() const {
5597 MDBX_CXX20_UNLIKELY throw_exception();
5598}
5599
5600inline void error::success_or_throw() const {
5601 if (MDBX_UNLIKELY(!is_success()))
5602 MDBX_CXX20_UNLIKELY throw_exception();
5603}
5604
5605inline void error::success_or_throw(const exception_thunk &thunk) const {
5606 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
5607 if (MDBX_UNLIKELY(!is_success())) {
5608 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
5609 else throw_exception();
5610 }
5611}
5612
5613inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
5614 if (MDBX_UNLIKELY(ptr == nullptr))
5615 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
5616}
5617
5618inline void error::throw_on_failure(int error_code) {
5619 error rc(static_cast<MDBX_error_t>(error_code));
5620 rc.throw_on_failure();
5621}
5622
5623inline void error::success_or_throw(MDBX_error_t error_code) {
5624 error rc(error_code);
5625 rc.success_or_throw();
5626}
5627
5628inline bool error::boolean_or_throw(int error_code) {
5629 switch (error_code) {
5630 case MDBX_RESULT_FALSE:
5631 return false;
5632 case MDBX_RESULT_TRUE:
5633 return true;
5634 default:
5635 MDBX_CXX20_UNLIKELY throw_exception(error_code);
5636 }
5637}
5638
5639inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
5640 error rc(static_cast<MDBX_error_t>(error_code));
5641 rc.success_or_throw(thunk);
5642}
5643
5644inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
5645 if (MDBX_UNLIKELY(!thunk.is_clean()))
5646 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
5647 return boolean_or_throw(error_code);
5648}
5649
5650MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
5651
5653 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
5654
5656 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
5657
5658MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
5659
5660MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
5661
5662MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
5663
5664MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
5665
5666inline slice &slice::assign(const void *ptr, size_t bytes) {
5667 iov_base = const_cast<void *>(ptr);
5668 iov_len = check_length(bytes);
5669 return *this;
5670}
5671
5672inline slice &slice::assign(const slice &src) noexcept {
5673 iov_base = src.iov_base;
5674 iov_len = src.iov_len;
5675 return *this;
5676}
5677
5678inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
5679
5680slice &slice::assign(slice &&src) noexcept {
5681 assign(src);
5682 src.invalidate();
5683 return *this;
5684}
5685
5687 assign(src.iov_base, src.iov_len);
5688 src.iov_base = nullptr;
5689 return *this;
5690}
5691
5692inline slice &slice::assign(const void *begin, const void *end) {
5693 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
5694}
5695
5696inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
5697
5698inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
5699
5700inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
5701
5702MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
5703
5704MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
5705
5706MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
5707
5709
5710MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
5711
5712MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
5713
5714MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
5715
5717
5718MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
5719
5720MDBX_CXX11_CONSTEXPR const byte *slice::end() const noexcept { return end_byte_ptr(); }
5721
5722MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
5723
5724MDBX_CXX11_CONSTEXPR byte *slice::end() noexcept { return end_byte_ptr(); }
5725
5726MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
5727
5729 iov_len = check_length(bytes);
5730 return *this;
5731}
5732
5734 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
5735 return set_length(static_cast<const char *>(ptr) - char_ptr());
5736}
5737
5738MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
5739
5740MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
5741
5742MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
5743
5744MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
5745
5746MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
5747
5749 iov_base = nullptr;
5750 iov_len = 0;
5751}
5752
5753inline void slice::remove_prefix(size_t n) noexcept {
5754 assert(n <= size());
5755 iov_base = static_cast<byte *>(iov_base) + n;
5756 iov_len -= n;
5757}
5758
5759inline void slice::safe_remove_prefix(size_t n) {
5760 if (MDBX_UNLIKELY(n > size()))
5761 MDBX_CXX20_UNLIKELY throw_out_range();
5762 remove_prefix(n);
5763}
5764
5765inline void slice::remove_suffix(size_t n) noexcept {
5766 assert(n <= size());
5767 iov_len -= n;
5768}
5769
5770inline void slice::safe_remove_suffix(size_t n) {
5771 if (MDBX_UNLIKELY(n > size()))
5772 MDBX_CXX20_UNLIKELY throw_out_range();
5773 remove_suffix(n);
5774}
5775
5776MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
5777 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
5778}
5779
5780MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
5781 return length() >= suffix.length() &&
5782 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
5783}
5784
5786 size_t h = length() * 3977471;
5787 for (size_t i = 0; i < length(); ++i)
5788 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
5789 return h ^ 3863194411 * (h >> 11);
5790}
5791
5792MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
5794 return byte_ptr()[n];
5795}
5796
5797MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
5798 if (MDBX_UNLIKELY(n >= size()))
5799 MDBX_CXX20_UNLIKELY throw_out_range();
5800 return byte_ptr()[n];
5801}
5802
5803MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
5805 return slice(data(), n);
5806}
5807
5808MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
5810 return slice(char_ptr() + size() - n, n);
5811}
5812
5813MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
5814 MDBX_CONSTEXPR_ASSERT(from + n <= size());
5815 return slice(char_ptr() + from, n);
5816}
5817
5818MDBX_CXX11_CONSTEXPR const byte *slice::begin() const noexcept { return byte_ptr(); }
5819
5820MDBX_CXX11_CONSTEXPR byte *slice::begin() noexcept { return byte_ptr(); }
5821
5822MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t slice::find(const slice &needle, size_t pos) const noexcept {
5823 if (MDBX_UNLIKELY(needle.empty()))
5824 return pos <= length() ? pos : npos;
5825 if (needle.length() > length() || pos > length() - needle.length())
5826 return npos;
5827 for (size_t i = pos;; ++i) {
5828 if (MDBX_LIKELY(memcmp(byte_ptr() + i, needle.data(), needle.length()) == 0))
5829 return i;
5830 if (i == length() - needle.length())
5831 return npos;
5832 }
5833}
5834
5835MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t slice::find(byte c, size_t pos) const noexcept {
5836 return find(slice(&c, sizeof(c)), pos);
5837}
5838
5839MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t slice::rfind(const slice &needle, size_t pos) const noexcept {
5840 if (MDBX_UNLIKELY(needle.empty())) {
5841 if (pos > length())
5842 return length();
5843 return pos;
5844 }
5845 if (needle.length() > length())
5846 return npos;
5847 if (pos > length() - needle.length())
5848 pos = length() - needle.length();
5849 for (size_t i = pos + 1; i > 0; --i) {
5850 if (MDBX_LIKELY(memcmp(byte_ptr() + i - 1, needle.data(), needle.length()) == 0))
5851 return i - 1;
5852 }
5853 return npos;
5854}
5855
5856MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t slice::rfind(byte c, size_t pos) const noexcept {
5857 return rfind(slice(&c, sizeof(c)), pos);
5858}
5859
5861 size_t pos) const noexcept {
5862 if (MDBX_UNLIKELY(chars.empty()))
5863 return npos;
5864 for (size_t i = pos; i < length(); ++i) {
5865 if (MDBX_LIKELY(chars.find(byte_ptr()[i]) != npos))
5866 return i;
5867 }
5868 return npos;
5869}
5870
5872 return find_first_of(slice(&c, sizeof(c)), pos);
5873}
5874
5876 if (MDBX_UNLIKELY(chars.empty() || empty()))
5877 return npos;
5878 if (pos >= length())
5879 pos = length() - 1;
5880 for (size_t i = pos + 1; i > 0; --i) {
5881 if (MDBX_LIKELY(chars.find(byte_ptr()[i - 1]) != npos))
5882 return i - 1;
5883 }
5884 return npos;
5885}
5886
5888 return find_last_of(slice(&c, sizeof(c)), pos);
5889}
5890
5892 size_t pos) const noexcept {
5893 for (size_t i = pos; i < length(); ++i) {
5894 if (MDBX_LIKELY(chars.find(byte_ptr()[i]) == npos))
5895 return i;
5896 }
5897 return npos;
5898}
5899
5901 return find_first_not_of(slice(&c, sizeof(c)), pos);
5902}
5903
5905 size_t pos) const noexcept {
5906 if (MDBX_UNLIKELY(empty()))
5907 return npos;
5908 if (pos >= length())
5909 pos = length() - 1;
5910 for (size_t i = pos + 1; i > 0; --i) {
5911 if (MDBX_LIKELY(chars.find(byte_ptr()[i - 1]) == npos))
5912 return i - 1;
5913 }
5914 return npos;
5915}
5916
5918 return find_last_not_of(slice(&c, sizeof(c)), pos);
5919}
5920
5922 if (MDBX_UNLIKELY(n > size()))
5923 MDBX_CXX20_UNLIKELY throw_out_range();
5924 return head(n);
5925}
5926
5928 if (MDBX_UNLIKELY(n > size()))
5929 MDBX_CXX20_UNLIKELY throw_out_range();
5930 return tail(n);
5931}
5932
5933MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
5934 if (MDBX_UNLIKELY(n > max_length))
5935 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
5936 if (MDBX_UNLIKELY(from > max_length || from + n > size()))
5937 MDBX_CXX20_UNLIKELY throw_out_range();
5938 return middle(from, n);
5939}
5940
5941MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
5942 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
5943 return diff ? diff
5944 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
5945 : memcmp(a.data(), b.data(), a.length());
5946}
5947
5949 const size_t shortest = ::std::min(a.length(), b.length());
5950 if (MDBX_LIKELY(shortest > 0))
5952 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
5953 if (MDBX_LIKELY(diff != 0))
5954 MDBX_CXX20_LIKELY return diff;
5955 }
5956 return intptr_t(a.length()) - intptr_t(b.length());
5957}
5958
5960 return slice::compare_fast(a, b) == 0;
5961}
5962
5964 return slice::compare_lexicographically(a, b) < 0;
5965}
5966
5968 return slice::compare_lexicographically(a, b) > 0;
5969}
5970
5972 return slice::compare_lexicographically(a, b) <= 0;
5973}
5974
5976 return slice::compare_lexicographically(a, b) >= 0;
5977}
5978
5980 return slice::compare_fast(a, b) != 0;
5981}
5982
5983#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5984MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
5985 const auto cmp = slice::compare_lexicographically(a, b);
5986 return (cmp < 0) ? std::strong_ordering::less
5987 : (cmp > 0) ? std::strong_ordering::greater
5988 : std::strong_ordering::equal;
5989}
5990#endif /* __cpp_impl_three_way_comparison */
5991
5992template <class ALLOCATOR, typename CAPACITY_POLICY>
5994 const allocator_type &alloc)
5995 : inherited(src), silo_(alloc) {
5996 if (!make_reference)
5997 insulate();
5998}
5999
6000template <class ALLOCATOR, typename CAPACITY_POLICY>
6001inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
6002 const allocator_type &alloc)
6003 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
6004
6005template <class ALLOCATOR, typename CAPACITY_POLICY>
6006inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
6007 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
6008}
6009
6010#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
6012
6013#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
6015#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
6016#endif /* !MinGW || MDBX_EXPORTS */
6017
6020
6021//------------------------------------------------------------------------------
6022
6023template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
6024inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
6025 if (MDBX_LIKELY(!producer.is_empty()))
6027 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
6028 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
6029 return result;
6030 }
6032}
6033
6034template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
6035inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
6036 if (MDBX_LIKELY(!producer.is_empty()))
6038 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
6039 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
6040 return result;
6041 }
6043}
6044
6045template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
6046inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
6047 string<ALLOCATOR> result(alloc);
6048 if (MDBX_LIKELY(!producer.is_empty()))
6050 result.resize(producer.envisage_result_length());
6051 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
6052 }
6053 return result;
6054}
6055
6056template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
6057inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
6058 string<ALLOCATOR> result(alloc);
6059 if (MDBX_LIKELY(!producer.is_empty()))
6061 result.resize(producer.envisage_result_length());
6062 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
6063 }
6064 return result;
6065}
6066
6067template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
6068 return make_string<ALLOCATOR>(*this, alloc);
6069}
6070
6071template <class ALLOCATOR, typename CAPACITY_POLICY>
6073 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
6074}
6075
6076template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
6077 return make_string<ALLOCATOR>(*this, alloc);
6078}
6079
6080template <class ALLOCATOR, typename CAPACITY_POLICY>
6082 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
6083}
6084
6085template <class ALLOCATOR> string<ALLOCATOR> to_base64::as_string(const ALLOCATOR &alloc) const {
6086 return make_string<ALLOCATOR>(*this, alloc);
6087}
6088
6089template <class ALLOCATOR, typename CAPACITY_POLICY>
6091 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
6092}
6093
6094template <class ALLOCATOR> string<ALLOCATOR> from_hex::as_string(const ALLOCATOR &alloc) const {
6095 return make_string<ALLOCATOR>(*this, alloc);
6096}
6097
6098template <class ALLOCATOR, typename CAPACITY_POLICY>
6100 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
6101}
6102
6103template <class ALLOCATOR> string<ALLOCATOR> from_base58::as_string(const ALLOCATOR &alloc) const {
6104 return make_string<ALLOCATOR>(*this, alloc);
6105}
6106
6107template <class ALLOCATOR, typename CAPACITY_POLICY>
6109 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
6110}
6111
6112template <class ALLOCATOR> string<ALLOCATOR> from_base64::as_string(const ALLOCATOR &alloc) const {
6113 return make_string<ALLOCATOR>(*this, alloc);
6114}
6115
6116template <class ALLOCATOR, typename CAPACITY_POLICY>
6118 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
6119}
6120
6121template <class ALLOCATOR>
6122inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
6123 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
6124}
6125
6126template <class ALLOCATOR>
6127inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
6128 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
6129}
6130
6131template <class ALLOCATOR>
6132inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
6133 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
6134}
6135
6136template <class ALLOCATOR, class CAPACITY_POLICY>
6137inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
6138 const ALLOCATOR &alloc) const {
6139 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
6140}
6141
6142template <class ALLOCATOR, class CAPACITY_POLICY>
6143inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
6144 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
6145}
6146
6147template <class ALLOCATOR, class CAPACITY_POLICY>
6148inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
6149 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
6150}
6151
6152template <class ALLOCATOR, class CAPACITY_POLICY>
6153inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
6154 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
6155}
6156
6157template <class ALLOCATOR, class CAPACITY_POLICY>
6158inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
6159 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
6160}
6161
6162template <class ALLOCATOR, class CAPACITY_POLICY>
6163inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
6164 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
6165}
6166
6167//------------------------------------------------------------------------------
6168
6169MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
6170 const auto diff = slice::compare_fast(a.key, b.key);
6171 return diff ? diff : slice::compare_fast(a.value, b.value);
6172}
6173
6174MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
6175 const auto diff = slice::compare_lexicographically(a.key, b.key);
6176 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
6177}
6178
6180 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
6181 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
6182 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
6183}
6184
6186 return pair::compare_lexicographically(a, b) < 0;
6187}
6188
6190 return pair::compare_lexicographically(a, b) > 0;
6191}
6192
6194 return pair::compare_lexicographically(a, b) <= 0;
6195}
6196
6198 return pair::compare_lexicographically(a, b) >= 0;
6199}
6200
6202 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
6203 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
6204 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
6205}
6206
6207#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
6208MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
6210}
6211#endif /* __cpp_impl_three_way_comparison */
6212
6214template <typename BUFFER>
6216
6219
6220//------------------------------------------------------------------------------
6221
6222inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
6223inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
6224inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
6225
6226MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
6227 return !from_hex(*this, ignore_spaces).is_erroneous();
6228}
6229
6230MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
6231 return !from_base58(*this, ignore_spaces).is_erroneous();
6232}
6233
6234MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
6235 return !from_base64(*this, ignore_spaces).is_erroneous();
6236}
6237
6238//------------------------------------------------------------------------------
6239
6241
6242inline env &env::operator=(env &&other) noexcept {
6243 if (this != &other) {
6244 handle_ = other.handle_;
6245 other.handle_ = nullptr;
6246 }
6247 return *this;
6248}
6249
6250inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6251
6252inline env::~env() noexcept {
6253#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
6254 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
6255#endif
6256}
6257
6262 return *this;
6263}
6264
6266env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
6267 size_now = size_lower = lower;
6268 size_upper = upper;
6270 return *this;
6271}
6272
6275 size_lower = size;
6276 return *this;
6277}
6278
6281 size_now = size;
6282 return *this;
6283}
6284
6287 size_upper = size;
6288 return *this;
6289}
6290
6293 growth_step = step;
6294 return *this;
6295}
6296
6299 shrink_threshold = threshold;
6300 return *this;
6301}
6302
6305 pagesize = size;
6306 return *this;
6307}
6308
6312
6316
6319 geometry = value;
6320 return *this;
6321}
6322
6326 file_mode_bits = value;
6327 return *this;
6328}
6329
6335
6338 max_maps = value;
6339 return *this;
6340}
6341
6344 max_readers = value;
6345 return *this;
6346}
6347
6350 mode = value;
6351 return *this;
6352}
6353
6356 durability = value;
6357 return *this;
6358}
6359
6362 reclaiming = value;
6363 return *this;
6364}
6365
6368 options = value;
6369 return *this;
6370}
6371
6377
6383
6389
6395
6401
6407
6413
6416 options.nested_transactions = value;
6417 return *this;
6418}
6419
6422 reclaiming.lifo = value;
6423 return *this;
6424}
6425
6428 options.no_sticky_threads = value;
6429 return *this;
6430}
6431
6434 options.exclusive = value;
6435 return *this;
6436}
6437
6440 options.disable_readahead = value;
6441 return *this;
6442}
6443
6446 options.disable_clear_memory = value;
6447 return *this;
6448}
6449
6452 options.enable_validation = value;
6453 return *this;
6454}
6455
6462
6469
6476
6483
6486 lifo = value;
6487 return *this;
6488}
6489
6492 no_sticky_threads = value;
6493 return *this;
6494}
6495
6498 nested_transactions = value;
6499 return *this;
6500}
6501
6504 exclusive = value;
6505 return *this;
6506}
6507
6510 disable_readahead = value;
6511 return *this;
6512}
6513
6516 disable_clear_memory = value;
6517 return *this;
6518}
6519
6522 enable_validation = value;
6523 return *this;
6524}
6525
6526inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
6527
6528inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
6529
6530inline size_t env::limits::dbsize_min(intptr_t pagesize) {
6531 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
6532 if (result < 0)
6533 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6534 return static_cast<size_t>(result);
6535}
6536
6537inline size_t env::limits::dbsize_max(intptr_t pagesize) {
6538 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
6539 if (result < 0)
6540 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6541 return static_cast<size_t>(result);
6542}
6543
6544inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
6545
6546inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
6547
6548inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
6549 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
6550 if (result < 0)
6551 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6552 return static_cast<size_t>(result);
6553}
6554
6555inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
6556 return key_max(pagesize, MDBX_db_flags_t(mode));
6557}
6558
6559inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
6560 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
6561 if (result < 0)
6562 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6563 return static_cast<size_t>(result);
6564}
6565
6567
6568inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
6569
6571
6572inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
6573 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
6574 if (result < 0)
6575 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6576 return static_cast<size_t>(result);
6577}
6578
6579inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
6580 return value_max(pagesize, MDBX_db_flags_t(mode));
6581}
6582
6583inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
6584 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
6585 if (result < 0)
6586 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6587 return static_cast<size_t>(result);
6588}
6589
6591
6592inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
6593 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
6594 if (result < 0)
6595 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6596 return static_cast<size_t>(result);
6597}
6598
6599inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
6600 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
6601}
6602
6604 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
6605 if (result < 0)
6606 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6607 return static_cast<size_t>(result);
6608}
6609
6613
6614inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
6615 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
6616 if (result < 0)
6617 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6618 return static_cast<size_t>(result);
6619}
6620
6621inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
6622 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
6623}
6624
6626 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
6627 if (result < 0)
6628 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6629 return static_cast<size_t>(result);
6630}
6631
6635
6636inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
6637 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
6638 if (result < 0)
6639 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6640 return static_cast<size_t>(result);
6641}
6642
6643inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
6644
6652
6654
6658
6662
6666
6667inline env::stat env::get_stat() const {
6668 env::stat r;
6669 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
6670 return r;
6671}
6672
6673inline env::stat env::get_stat(const txn &txn) const {
6674 env::stat r;
6676 return r;
6677}
6678
6679inline env::info env::get_info() const {
6680 env::info r;
6681 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
6682 return r;
6683}
6684
6685inline env::info env::get_info(const txn &txn) const {
6686 env::info r;
6688 return r;
6689}
6690
6692 filehandle fd;
6694 return fd;
6695}
6696
6698 unsigned bits = 0;
6700 return MDBX_env_flags_t(bits);
6701}
6702
6703inline unsigned env::max_readers() const {
6704 unsigned r;
6706 return r;
6707}
6708
6709inline unsigned env::max_maps() const {
6710 unsigned r;
6712 return r;
6713}
6714
6715inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
6716
6717inline env &env::set_context(void *ptr) {
6719 return *this;
6720}
6721
6722inline env &env::set_sync_threshold(size_t bytes) {
6724 return *this;
6725}
6726
6727inline size_t env::sync_threshold() const {
6728 size_t bytes;
6730 return bytes;
6731}
6732
6733inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
6735 return *this;
6736}
6737
6738inline unsigned env::sync_period__seconds_16dot16() const {
6739 unsigned seconds_16dot16;
6741 return seconds_16dot16;
6742}
6743
6745 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
6746}
6747
6748inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
6749
6750#if __cplusplus >= 201103L
6751inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
6752
6754#endif
6755
6756inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
6758 return *this;
6759}
6760
6761inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
6762 uint64_t value;
6764 return value;
6765}
6766
6767inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
6769 return *this;
6770}
6771
6772inline env &env::set_geometry(const geometry &geo) {
6774 geo.growth_step, geo.shrink_threshold, geo.pagesize));
6775 return *this;
6776}
6777
6778inline bool env::sync_to_disk(bool force, bool nonblock) {
6779 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
6780 switch (err) {
6781 case MDBX_SUCCESS /* flush done */:
6782 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
6783 return true;
6784 case MDBX_BUSY /* the environment is used by other thread */:
6785 return false;
6786 default:
6787 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6788 }
6789}
6790
6792
6794env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
6795 size_t retained) noexcept
6797 bytes_retained(retained) {}
6798
6799template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
6800 struct reader_visitor_thunk : public exception_thunk {
6801 VISITOR &visitor_;
6802 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
6803 size_t used, size_t retained) noexcept {
6804 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
6805 assert(thunk->is_clean());
6806 try {
6807 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
6808 return loop_control(thunk->visitor_(info, number));
6809 } catch (... /* capture any exception to rethrow it over C code */) {
6810 thunk->capture();
6812 }
6813 }
6814 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
6815 };
6816 reader_visitor_thunk thunk(visitor);
6817 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
6818 thunk.rethrow_captured();
6819 return rc;
6820}
6821
6822inline unsigned env::check_readers() {
6823 int dead_count;
6824 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
6825 MDBX_INLINE_API_ASSERT(dead_count >= 0);
6826 return static_cast<unsigned>(dead_count);
6827}
6828
6830static const MDBX_chk_callbacks_t silent_chk_callbacks = {};
6831
6833 MDBX_chk_severity_t verbosity, unsigned timeout_seconds_16dot16) const {
6834 if (!cb)
6835 cb = &silent_chk_callbacks;
6836 error::success_or_throw(::mdbx_env_chk(handle_, cb, &ctx, flags, verbosity, timeout_seconds_16dot16));
6837 return ctx;
6838}
6839
6841 sysraminfo result;
6843 return result;
6844}
6845
6846inline env::info env::get_preopen_snapinfo(const ::std::string &pathname) {
6847 return get_preopen_snapinfo(pathname.c_str());
6848}
6849
6850inline env::info env::get_preopen_snapinfo(const char *pathname) {
6851 env::info result;
6852 error::success_or_throw(::mdbx_preopen_snapinfo(pathname, &result, sizeof(result)));
6853 return result;
6854}
6855
6856#ifdef MDBX_STD_FILESYSTEM_PATH
6858 return get_preopen_snapinfo(pathname.native().c_str());
6859}
6860#endif /* MDBX_STD_FILESYSTEM_PATH */
6861
6862#if defined(_WIN32) || defined(_WIN64)
6863inline env::info env::get_preopen_snapinfo(const ::std::wstring &pathname) {
6864 return get_preopen_snapinfo(pathname.c_str());
6865}
6866
6867inline env::info env::get_preopen_snapinfo(const wchar_t *pathname) {
6868 env::info result;
6869 error::success_or_throw(::mdbx_preopen_snapinfoW(pathname, &result, sizeof(result)));
6870 return result;
6871}
6872#endif /* Windows */
6873
6875
6877
6878inline int env::warmup(MDBX_warmup_flags_t flags, unsigned timeout_seconds_16dot16, const MDBX_txn *txn) const {
6879 return ::mdbx_env_warmup(handle_, txn, flags, timeout_seconds_16dot16);
6880}
6881
6882#if !defined(_WIN32) && !defined(_WIN64)
6884#endif /* !Windows */
6885
6886inline void env::turn_for_recovery(unsigned target_meta) {
6888}
6889
6894
6895inline MDBX_hsr_func env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
6896
6898 ::MDBX_txn *ptr;
6900 MDBX_INLINE_API_ASSERT(ptr != nullptr);
6901 return txn_managed(ptr);
6902}
6903
6905 ::MDBX_txn *ptr;
6907 MDBX_INLINE_API_ASSERT(ptr != nullptr);
6908 return txn_managed(ptr);
6909}
6910
6911inline txn_managed env::start_write(bool dont_wait) {
6912 ::MDBX_txn *ptr;
6915 MDBX_INLINE_API_ASSERT(ptr != nullptr || dont_wait);
6916 return txn_managed(ptr);
6917}
6918
6920 ::MDBX_txn *ptr;
6922 MDBX_INLINE_API_ASSERT(ptr != nullptr);
6923 return txn_managed(ptr);
6924}
6925
6927
6928inline bool env::txn_lock(bool dont_wait) {
6929 const int err = ::mdbx_txn_lock(handle_, dont_wait);
6930 switch (err) {
6931 case MDBX_SUCCESS:
6932 MDBX_CXX20_LIKELY return true;
6933 case MDBX_BUSY:
6934 return false;
6935 default:
6936 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6937 }
6938}
6939
6941
6942template <typename VISITOR>
6943inline env::defrag_result env::defrag(VISITOR &visitor, size_t defrag_atleast, size_t time_atleast_dot16,
6944 size_t defrag_enough, size_t time_limit_dot16, intptr_t acceptable_backlash,
6945 intptr_t preferred_batch) {
6946 struct defrag_thunk : public exception_thunk {
6947 VISITOR &visitor_;
6948 static int cb(void *ctx, const MDBX_defrag_result_t *progress) noexcept {
6949 defrag_thunk *thunk = static_cast<defrag_thunk *>(ctx);
6950 assert(thunk->is_clean());
6951 try {
6952 return static_cast<int>(thunk->visitor_(*progress));
6953 } catch (... /* capture any exception to rethrow it over C code */) {
6954 thunk->capture();
6955 return static_cast<int>(defrag_control::abort);
6956 }
6957 }
6958 MDBX_CXX11_CONSTEXPR defrag_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
6959 };
6960 defrag_thunk thunk(visitor);
6961 defrag_result result;
6962 const int rc =
6963 ::mdbx_env_defrag(handle_, defrag_atleast, time_atleast_dot16, defrag_enough, time_limit_dot16,
6964 acceptable_backlash, preferred_batch, thunk.cb, &thunk, &result);
6965 thunk.rethrow_captured();
6966 if (rc != MDBX_SUCCESS && rc != MDBX_RESULT_TRUE)
6968 return result;
6969}
6970
6971inline env::defrag_result env::defrag(size_t defrag_atleast, size_t time_atleast_dot16, size_t defrag_enough,
6972 size_t time_limit_dot16, intptr_t acceptable_backlash, intptr_t preferred_batch) {
6973 struct noop_visitor {
6974 defrag_control operator()(const defrag_result &) { return defrag_control::proceed; }
6975 } visitor;
6976 return defrag(visitor, defrag_atleast, time_atleast_dot16, defrag_enough, time_limit_dot16, acceptable_backlash,
6977 preferred_batch);
6978}
6979
6981
6982inline txn &txn::operator=(txn &&other) noexcept {
6983 if (this != &other) {
6984 handle_ = other.handle_;
6985 other.handle_ = nullptr;
6986 }
6987 return *this;
6988}
6989
6990inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6991
6992inline txn::~txn() noexcept {
6993#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
6994 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
6995#endif
6996}
6997
6998inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
6999
7000inline txn &txn::set_context(void *ptr) {
7002 return *this;
7003}
7004
7005inline bool txn::is_dirty(const void *ptr) const {
7006 int err = ::mdbx_is_dirty(handle_, ptr);
7007 switch (err) {
7008 default:
7009 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7010 case MDBX_RESULT_TRUE:
7011 return true;
7012 case MDBX_RESULT_FALSE:
7013 return false;
7014 }
7015}
7016
7017inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
7018
7020 const int bits = mdbx_txn_flags(handle_);
7022 return static_cast<MDBX_txn_flags_t>(bits);
7023}
7024
7025inline uint64_t txn::id() const {
7026 const uint64_t txnid = mdbx_txn_id(handle_);
7028 return txnid;
7029}
7030
7032
7034
7036
7037inline bool txn::refresh() {
7038 const int err = ::mdbx_txn_refresh(handle_);
7039 switch (err) {
7040 case MDBX_SUCCESS:
7041 return false;
7042 case MDBX_RESULT_TRUE:
7043 return true;
7044 default:
7045 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7046 }
7047}
7048
7049inline void txn::copy(const char *destination, bool compactify, bool force_dynamic_size) {
7051 handle_, destination,
7053 (force_dynamic_size ? MDBX_CP_FORCE_DYNAMIC_SIZE : MDBX_CP_DEFAULTS))));
7054}
7055
7056inline void txn::copy(const ::std::string &destination, bool compactify, bool force_dynamic_size) {
7057 copy(destination.c_str(), compactify, force_dynamic_size);
7058}
7059
7060#if defined(_WIN32) || defined(_WIN64)
7061inline void txn::copy(const wchar_t *destination, bool compactify, bool force_dynamic_size) {
7063 handle_, destination,
7065 (force_dynamic_size ? MDBX_CP_FORCE_DYNAMIC_SIZE : MDBX_CP_DEFAULTS))));
7066}
7067
7068inline void txn::copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size) {
7069 copy(destination.c_str(), compactify, force_dynamic_size);
7070}
7071#endif /* Windows */
7072
7073#ifdef MDBX_STD_FILESYSTEM_PATH
7074inline void txn::copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size) {
7075 copy(destination.native(), compactify, force_dynamic_size);
7076}
7077#endif /* MDBX_STD_FILESYSTEM_PATH */
7078
7079inline void txn::copy(filehandle fd, bool compactify, bool force_dynamic_size) {
7081 handle_, fd,
7083 (force_dynamic_size ? MDBX_CP_FORCE_DYNAMIC_SIZE : MDBX_CP_DEFAULTS))));
7084}
7085
7086inline txn_managed txn::clone(void *context) const {
7087 MDBX_txn *ptr = nullptr;
7089 MDBX_INLINE_API_ASSERT(ptr != nullptr);
7090 return txn_managed(ptr);
7091}
7092
7093inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
7094 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
7095 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
7096 MDBX_INLINE_API_ASSERT(txn_for_renew_into_clone.handle_ != nullptr);
7097}
7098
7099inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
7100
7101inline bool txn::unpark_reading(bool restart_if_ousted) {
7102 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
7103}
7104
7105inline txn::info txn::get_info(bool scan_reader_lock_table) const {
7106 txn::info r;
7107 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
7108 return r;
7109}
7110
7112 MDBX_cursor *ptr;
7114 return cursor_managed(ptr);
7115}
7116
7117inline size_t txn::release_all_cursors(bool unbind) const {
7118 size_t count;
7120 return count;
7121}
7122
7123inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
7124 const ::mdbx::value_mode value_mode) const {
7125 map_handle map;
7128 MDBX_INLINE_API_ASSERT(map.dbi != 0);
7129 return map;
7130}
7131
7132inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
7133 const ::mdbx::value_mode value_mode) const {
7134 map_handle map;
7137 MDBX_INLINE_API_ASSERT(map.dbi != 0);
7138 return map;
7139}
7140
7141inline map_handle txn::open_map_accede(const slice &name) const {
7142 map_handle map;
7144 MDBX_INLINE_API_ASSERT(map.dbi != 0);
7145 return map;
7146}
7147
7148inline map_handle txn::open_map_accede(const char *name) const {
7149 map_handle map;
7151 MDBX_INLINE_API_ASSERT(map.dbi != 0);
7152 return map;
7153}
7154
7155inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
7156 const ::mdbx::value_mode value_mode) {
7157 map_handle map;
7160 MDBX_INLINE_API_ASSERT(map.dbi != 0);
7161 return map;
7162}
7163
7164inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
7165 const ::mdbx::value_mode value_mode) {
7166 map_handle map;
7169 MDBX_INLINE_API_ASSERT(map.dbi != 0);
7170 return map;
7171}
7172
7174
7176
7177inline void txn::rename_map(map_handle map, const char *new_name) {
7179}
7180
7181inline void txn::rename_map(map_handle map, const slice &new_name) {
7183}
7184
7185inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
7186 const ::mdbx::value_mode value_mode) const {
7187 return open_map(slice(name), key_mode, value_mode);
7188}
7189
7190inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
7191
7192#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
7193inline map_handle txn::open_map_accede(const ::std::string_view &name) const {
7194 return open_map_accede(slice(name));
7195}
7196#endif /* __cpp_lib_string_view >= 201606L */
7197
7198inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
7199 const ::mdbx::value_mode value_mode) {
7200 return create_map(slice(name), key_mode, value_mode);
7201}
7202
7203inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
7204 return drop_map(slice(name), throw_if_absent);
7205}
7206
7207inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
7208 return clear_map(slice(name), throw_if_absent);
7209}
7210
7211inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
7212
7213#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
7214inline void txn::rename_map(map_handle map, const ::std::string_view &new_name) {
7215 return rename_map(map, slice(new_name));
7216}
7217#endif /* __cpp_lib_string_view >= 201606L */
7218
7220 txn::map_stat r;
7221 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
7222 return r;
7223}
7224
7225inline uint32_t txn::get_tree_deepmask(map_handle map) const {
7226 uint32_t r;
7228 return r;
7229}
7230
7236
7237template <typename VISITOR> inline int txn::enumerate_tables(VISITOR &visitor) const {
7238 struct tables_enum_thunk : public exception_thunk {
7239 VISITOR &visitor_;
7240 static int cb(void *ctx, const MDBX_txn *, const MDBX_val *name, MDBX_db_flags_t flags,
7241 const MDBX_stat *stat, MDBX_dbi dbi) noexcept {
7242 tables_enum_thunk *thunk = static_cast<tables_enum_thunk *>(ctx);
7243 assert(thunk->is_clean());
7244 try {
7245 const slice table_name(*name);
7246 return loop_control(thunk->visitor_(table_name, flags, *stat, dbi));
7247 } catch (... /* capture any exception to rethrow it over C code */) {
7248 thunk->capture();
7250 }
7251 }
7252 MDBX_CXX11_CONSTEXPR tables_enum_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
7253 };
7254 tables_enum_thunk thunk(visitor);
7255 const auto rc = ::mdbx_enumerate_tables(handle_, thunk.cb, &thunk);
7256 thunk.rethrow_captured();
7257 return rc;
7258}
7259
7260template <typename VISITOR> inline txn::gc_info txn::get_gc_info(VISITOR &visitor) const {
7261 struct gc_iter_thunk : public exception_thunk {
7262 VISITOR &visitor_;
7263 static int cb(void *ctx, const MDBX_txn *, uint64_t span_txnid, size_t span_pgno, size_t span_length,
7264 bool span_is_reclaimable) noexcept {
7265 gc_iter_thunk *thunk = static_cast<gc_iter_thunk *>(ctx);
7266 assert(thunk->is_clean());
7267 try {
7268 return loop_control(thunk->visitor_(span_txnid, span_pgno, span_length, span_is_reclaimable));
7269 } catch (... /* capture any exception to rethrow it over C code */) {
7270 thunk->capture();
7272 }
7273 }
7274 MDBX_CXX11_CONSTEXPR gc_iter_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
7275 };
7276 gc_iter_thunk thunk(visitor);
7277 gc_info info;
7278 const auto rc = ::mdbx_gc_info(handle_, &info, sizeof(info), thunk.cb, &thunk);
7279 thunk.rethrow_captured();
7280 /* The MDBX_NOTFOUND just means the GC is empty, while the C function
7281 * still fills the geometry-related fields (pages_total, pages_allocated,
7282 * etc.), which must be preserved. */
7283 if (rc != MDBX_NOTFOUND)
7285 return info;
7286}
7287
7289 struct noop_visitor {
7290 int operator()(uint64_t, size_t, size_t, bool) { return loop_control::continue_loop; }
7291 } visitor;
7292 return get_gc_info(visitor);
7293}
7294
7299
7301 txn::canary r;
7303 return r;
7304}
7305
7306inline uint64_t txn::sequence(map_handle map) const {
7307 uint64_t result;
7309 return result;
7310}
7311
7312inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
7313 uint64_t result;
7314 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
7315 return result;
7316}
7317
7318inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
7319 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
7320}
7321
7322inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
7323 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
7324}
7325
7326inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
7327 return compare_keys(map, a.key, b.key);
7328}
7329
7330inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
7331 return compare_values(map, a.value, b.value);
7332}
7333
7334inline slice txn::get(map_handle map, const slice &key) const {
7335 slice result;
7336 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
7337 return result;
7338}
7339
7340inline txn::cache_result txn::get_cached(map_handle map, const slice &key, slice *data, cache_entry &entry) const {
7341 return ::mdbx_cache_get(handle_, map.dbi, &key, data, &entry);
7342}
7343
7344inline slice txn::get_cached(map_handle map, const slice &key, cache_entry &entry, cache_status *status) const {
7345 slice value;
7346 const auto result = get_cached(map, key, &value, entry);
7347 if (status)
7348 *status = result.status;
7349 error::success_or_throw(result.errcode);
7350 return value;
7351}
7352
7353inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
7354 slice result;
7355 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
7356 return result;
7357}
7358
7359inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
7360 slice result;
7361 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
7362 switch (err) {
7363 case MDBX_SUCCESS:
7364 return result;
7365 case MDBX_NOTFOUND:
7366 return value_at_absence;
7367 default:
7368 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7369 }
7370}
7371
7372inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
7373 slice result;
7374 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
7375 switch (err) {
7376 case MDBX_SUCCESS:
7377 return result;
7378 case MDBX_NOTFOUND:
7379 return value_at_absence;
7380 default:
7381 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7382 }
7383}
7384
7386 pair result(key, slice());
7387 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
7388 return pair_result(result.key, result.value, exact);
7389}
7390
7391inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
7392 pair result{key, slice()};
7393 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
7394 switch (err) {
7395 case MDBX_SUCCESS:
7396 return pair_result{result.key, result.value, true};
7397 case MDBX_RESULT_TRUE:
7398 return pair_result{result.key, result.value, false};
7399 case MDBX_NOTFOUND:
7400 return pair_result{key, value_at_absence, false};
7401 default:
7402 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7403 }
7404}
7405
7406inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
7407 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7408 /* coverity[OVERRUN] */
7409 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
7410}
7411
7412inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
7413 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7414 /* coverity[OVERRUN] */
7415 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
7416}
7417
7418inline void txn::insert(map_handle map, const slice &key, slice value) {
7419 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7420 /* coverity[OVERRUN] */
7421 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
7423}
7424
7425inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
7426 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7427 /* coverity[OVERRUN] */
7428 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
7430 switch (err) {
7431 case MDBX_SUCCESS:
7432 return value_result{slice(), true};
7433 case MDBX_KEYEXIST:
7434 return value_result{value, false};
7435 default:
7436 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7437 }
7438}
7439
7440inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
7441 slice result(nullptr, value_length);
7442 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7443 /* coverity[OVERRUN] */
7444 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
7446 return result;
7447}
7448
7449inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
7450 slice result(nullptr, value_length);
7451 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7452 /* coverity[OVERRUN] */
7453 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
7455 switch (err) {
7456 case MDBX_SUCCESS:
7457 return value_result{result, true};
7458 case MDBX_KEYEXIST:
7459 return value_result{result, false};
7460 default:
7461 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7462 }
7463}
7464
7465inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
7466 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7467 /* coverity[OVERRUN] */
7468 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
7469}
7470
7471inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
7472 slice result(nullptr, value_length);
7473 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7474 /* coverity[OVERRUN] */
7476 return result;
7477}
7478
7479inline void txn::update(map_handle map, const slice &key, const slice &value) {
7480 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7481 /* coverity[OVERRUN] */
7482 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
7483}
7484
7485inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
7486 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7487 /* coverity[OVERRUN] */
7488 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
7489 switch (err) {
7490 case MDBX_SUCCESS:
7491 return true;
7492 case MDBX_NOTFOUND:
7493 return false;
7494 default:
7495 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7496 }
7497}
7498
7499inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
7500 slice result(nullptr, value_length);
7501 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7502 /* coverity[OVERRUN] */
7504 return result;
7505}
7506
7507inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
7508 slice result(nullptr, value_length);
7509 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
7510 /* coverity[OVERRUN] */
7511 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
7512 switch (err) {
7513 case MDBX_SUCCESS:
7514 return value_result{result, true};
7515 case MDBX_NOTFOUND:
7516 return value_result{slice(), false};
7517 default:
7518 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7519 }
7520}
7521
7522inline bool txn::erase(map_handle map, const slice &key) {
7523 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
7524 switch (err) {
7525 case MDBX_SUCCESS:
7526 return true;
7527 case MDBX_NOTFOUND:
7528 return false;
7529 default:
7530 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7531 }
7532}
7533
7534inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
7535 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
7536 switch (err) {
7537 case MDBX_SUCCESS:
7538 return true;
7539 case MDBX_NOTFOUND:
7540 return false;
7541 default:
7542 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7543 }
7544}
7545
7546inline void txn::replace(map_handle map, const slice &key, slice &old_value, const slice &new_value) {
7547 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
7548 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
7549}
7550
7551template <class BUFFER, typename ALLOCATOR>
7552inline BUFFER txn::extract(map_handle map, const slice &key, const ALLOCATOR &alloc) {
7553 typename BUFFER::data_preserver result(alloc);
7555 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.data, MDBX_CURRENT, result, &result), result);
7556 return result.data;
7557}
7558
7559template <class BUFFER, typename ALLOCATOR>
7560inline BUFFER txn::replace(map_handle map, const slice &key, const slice &new_value, const ALLOCATOR &alloc) {
7561 typename BUFFER::data_preserver result(alloc);
7562 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.data,
7563 MDBX_CURRENT, result, &result),
7564 result);
7565 return result.data;
7566}
7567
7568template <class BUFFER, typename ALLOCATOR>
7569inline BUFFER txn::replace_reserve(map_handle map, const slice &key, size_t length, slice &new_value_reservation,
7570 const ALLOCATOR &alloc) {
7571 new_value_reservation.iov_base = nullptr;
7572 new_value_reservation.iov_len = length;
7573 typename BUFFER::data_preserver result(alloc);
7574 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value_reservation, &result.data,
7575 MDBX_CURRENT | MDBX_RESERVE, result, &result),
7576 result);
7577 return result.data;
7578}
7579
7580inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
7581 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
7582 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
7583}
7584
7585inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
7586 const void *values_array, size_t values_count, put_mode mode,
7587 bool allow_partial) {
7588 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
7589 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
7590 switch (err) {
7591 case MDBX_SUCCESS:
7592 MDBX_CXX20_LIKELY break;
7593 case MDBX_KEYEXIST:
7594 if (allow_partial)
7595 break;
7597 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
7598 default:
7599 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7600 }
7601 return args[1].iov_len /* done item count */;
7602}
7603
7604inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
7605 ptrdiff_t result;
7606 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
7607 return result;
7608}
7609
7610inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
7611 ptrdiff_t result;
7612 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
7613 return result;
7614}
7615
7616inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
7617 ptrdiff_t result;
7618 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
7619 return result;
7620}
7621
7622inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
7623 ptrdiff_t result;
7624 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
7625 return result;
7626}
7627
7629
7630inline cursor &cursor::assign(const cursor &src) {
7632 return *this;
7633}
7634
7635inline cursor &cursor::operator=(cursor &&other) noexcept {
7636 if (this != &other) {
7637 handle_ = other.handle_;
7638 other.handle_ = nullptr;
7639 }
7640 return *this;
7641}
7642
7643inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
7644
7645inline cursor::~cursor() noexcept {
7646#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
7647 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
7648#endif
7649}
7650
7651inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
7652
7653inline cursor &cursor::set_context(void *ptr) {
7655 return *this;
7656}
7657
7658inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
7659 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
7660}
7661
7662inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
7663 const auto diff = compare_position_nothrow(left, right, ignore_nested);
7664 MDBX_INLINE_API_ASSERT(compare_position_nothrow(right, left, ignore_nested) == -diff);
7665 if (MDBX_LIKELY(int16_t(diff) == diff))
7666 MDBX_CXX20_LIKELY return int(diff);
7667 else
7669}
7670
7671inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
7672 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
7673}
7674
7676 bool throw_notfound)
7677 : pair_result(key, value, false) {
7678 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
7679}
7680
7681inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
7682 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
7683 switch (err) {
7684 case MDBX_SUCCESS:
7685 MDBX_CXX20_LIKELY return true;
7686 case MDBX_RESULT_TRUE:
7687 return false;
7688 case MDBX_NOTFOUND:
7689 if (!throw_notfound)
7690 return false;
7691 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
7692 default:
7693 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7694 }
7695}
7696
7698 const slice &value)
7699 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
7700 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
7701}
7702
7703inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
7704 ptrdiff_t result;
7705 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
7706 return result;
7707}
7708
7709inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
7710 ptrdiff_t result;
7712 return result;
7713}
7714
7715inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
7716 return move(key_exact, key, throw_notfound);
7717}
7718
7719inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
7720 return move(key_lowerbound, key, throw_notfound);
7721}
7722
7723inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
7724 return move(key_greater_than, key, throw_notfound);
7725}
7726
7727inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
7728 return move(multi_find_pair, key, value, throw_notfound);
7729}
7730
7731inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
7732 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
7733}
7734
7735inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
7736 return move(multi_exactkey_value_greater, key, value, throw_notfound);
7737}
7738
7739inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
7740
7741inline size_t cursor::count_multivalue() const {
7742 size_t result;
7744 return result;
7745}
7746
7747inline size_t cursor::count_multivalue(MDBX_stat *stat) const {
7748 size_t result;
7749 error::success_or_throw(::mdbx_cursor_count_ex(*this, &result, stat, sizeof(*stat)));
7750 return result;
7751}
7752
7753inline ::std::vector<pair> cursor::get_batch(size_t max_pairs, move_operation op, bool *is_last) const {
7754 if (is_last)
7755 *is_last = false;
7756 ::std::vector<pair> result;
7757 if (!max_pairs)
7758 return result;
7759
7760 const size_t limit = max_pairs * 2;
7761 ::std::vector<MDBX_val> pairs(limit);
7762 size_t count = 0;
7763 int rc = ::mdbx_cursor_get_batch(handle_, &count, pairs.data(), limit, MDBX_cursor_op(op));
7764 if (rc == MDBX_RESULT_TRUE) {
7765 if (is_last)
7766 *is_last = true;
7767 rc = MDBX_SUCCESS;
7768 }
7770
7771 MDBX_INLINE_API_ASSERT(count % 2 == 0 && count <= limit);
7772 result.reserve(count / 2);
7773 for (size_t i = 0; i + 1 < count; i += 2)
7774 result.emplace_back(slice(pairs[i]), slice(pairs[i + 1]));
7775 return result;
7776}
7777
7779
7780inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
7781
7783
7785
7787
7789
7790inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
7791 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
7792}
7793
7795 return estimate_result(*this, key_lowerbound, key);
7796}
7797
7799 return estimate_result(*this, operation);
7800}
7801
7803 return estimate_result(*this, operation, key);
7804}
7805
7807
7811
7813
7814inline txn cursor::txn() const {
7816 return ::mdbx::txn(txn);
7817}
7818
7819inline map_handle cursor::map() const {
7820 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
7821 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
7823 return map_handle(dbi);
7824}
7825
7826inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
7827 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
7828}
7829
7830inline void cursor::put(const slice &key, slice value, put_mode mode) {
7831 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
7832}
7833
7834inline void cursor::insert(const slice &key, slice value) {
7836 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
7837}
7838
7839inline value_result cursor::try_insert(const slice &key, slice value) {
7840 const int err =
7841 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
7842 switch (err) {
7843 case MDBX_SUCCESS:
7844 return value_result{slice(), true};
7845 case MDBX_KEYEXIST:
7846 return value_result{value, false};
7847 default:
7848 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7849 }
7850}
7851
7852inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
7853 slice result(nullptr, value_length);
7854 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
7856 return result;
7857}
7858
7859inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
7860 slice result(nullptr, value_length);
7861 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
7863 switch (err) {
7864 case MDBX_SUCCESS:
7865 return value_result{result, true};
7866 case MDBX_KEYEXIST:
7867 return value_result{result, false};
7868 default:
7869 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7870 }
7871}
7872
7873inline void cursor::upsert(const slice &key, const slice &value) {
7874 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
7875}
7876
7877inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
7878 slice result(nullptr, value_length);
7880 return result;
7881}
7882
7883inline void cursor::update(const slice &key, const slice &value) {
7884 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
7885}
7886
7887inline bool cursor::try_update(const slice &key, const slice &value) {
7888 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
7889 switch (err) {
7890 case MDBX_SUCCESS:
7891 return true;
7892 case MDBX_NOTFOUND:
7893 return false;
7894 default:
7895 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7896 }
7897}
7898
7899inline slice cursor::update_reserve(const slice &key, size_t value_length) {
7900 slice result(nullptr, value_length);
7902 return result;
7903}
7904
7905inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
7906 slice result(nullptr, value_length);
7907 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
7908 switch (err) {
7909 case MDBX_SUCCESS:
7910 return value_result{result, true};
7911 case MDBX_NOTFOUND:
7912 return value_result{slice(), false};
7913 default:
7914 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7915 }
7916}
7917
7918inline bool cursor::erase(bool whole_multivalue) {
7919 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
7920 switch (err) {
7921 case MDBX_SUCCESS:
7922 MDBX_CXX20_LIKELY return true;
7923 case MDBX_NOTFOUND:
7924 return false;
7925 default:
7926 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7927 }
7928}
7929
7930inline bool cursor::erase(const slice &key, bool whole_multivalue) {
7931 bool found = seek(key);
7932 return found ? erase(whole_multivalue) : found;
7933}
7934
7935inline bool cursor::erase(const slice &key, const slice &value) {
7936 move_result data = find_multivalue(key, value, false);
7937 return data.done && erase();
7938}
7939
7940inline size_t cursor::erase_bunch(bunch_delete action) {
7941 uint64_t affected;
7943 return size_t(affected);
7944}
7945
7946inline size_t cursor::erase_range(const cursor &end, bool end_including) {
7947 uint64_t affected;
7948 error::success_or_throw(::mdbx_cursor_delete_range(handle_, end.handle_, end_including, &affected));
7949 return size_t(affected);
7950}
7951
7953
7954inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
7955 size_t values_count, put_mode mode, bool allow_partial) {
7956 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
7957 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
7958 switch (err) {
7959 case MDBX_SUCCESS:
7960 MDBX_CXX20_LIKELY break;
7961 case MDBX_KEYEXIST:
7962 if (allow_partial)
7963 break;
7965 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
7966 default:
7967 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7968 }
7969 return args[1].iov_len /* done item count */;
7970}
7971
7972inline ptrdiff_t cursor::distance_between(const cursor from, const cursor to, unsigned deepness) {
7973 intptr_t distance = PTRDIFF_MIN;
7974 error::success_or_throw(mdbx_cursor_distance(from, to, &distance, deepness));
7975 return distance;
7976}
7977
7978inline bool cursor::scroll(intptr_t distance, unsigned deepness, bool throw_notfound) {
7979 const int err = ::mdbx_cursor_scroll(handle_, distance, deepness);
7980 switch (err) {
7981 case MDBX_SUCCESS:
7982 MDBX_CXX20_LIKELY return true;
7983 case MDBX_NOTFOUND:
7984 if (!throw_notfound)
7985 return false;
7986 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
7987 default:
7988 MDBX_CXX20_UNLIKELY error::throw_exception(err);
7989 }
7990}
7991
7992inline bool cursor::distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size,
7993 unsigned deepness) {
7994 static_assert(sizeof(cursors_array[0]) == sizeof(MDBX_cursor *), "oops");
7995 const int err = ::mdbx_cursor_distribute(from, to, &cursors_array[0].handle_, cursors_array_size, deepness);
7996 return error::boolean_or_throw(err);
7997}
7998
7999inline bool cursor::distribute(const cursor from, const cursor to, const std::vector<cursor> &cursors_array,
8000 unsigned deepness) {
8001 static_assert(sizeof(cursor) == sizeof(MDBX_cursor *), "oops");
8002 const int err = MDBX_LIKELY(!cursors_array.empty())
8003 ? ::mdbx_cursor_distribute(from, to, const_cast<MDBX_cursor **>(&cursors_array[0].handle_),
8004 cursors_array.size(), deepness)
8005 : MDBX_EINVAL;
8006 return error::boolean_or_throw(err);
8007}
8008
8009inline bool cursor::distribute(const cursor from, const cursor to, const std::vector<cursor_managed> &cursors_array,
8010 unsigned deepness) {
8011 static_assert(sizeof(cursor_managed) == sizeof(MDBX_cursor *), "oops");
8012 const int err = MDBX_LIKELY(!cursors_array.empty())
8013 ? ::mdbx_cursor_distribute(from, to, const_cast<MDBX_cursor **>(&cursors_array[0].handle_),
8014 cursors_array.size(), deepness)
8015 : MDBX_EINVAL;
8016 return error::boolean_or_throw(err);
8017}
8018
8019//------------------------------------------------------------------------------
8020
8021LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
8022LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
8023LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
8024LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
8025LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
8026LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
8027LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
8028LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
8029LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
8030LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
8031LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
8032
8033LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
8034LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
8035LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
8036
8037inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
8038
8040
8041} // namespace mdbx
8042
8043//------------------------------------------------------------------------------
8044
8047namespace std {
8048
8049inline string to_string(const ::mdbx::slice &value) {
8050 ostringstream out;
8051 out << value;
8052 return out.str();
8053}
8054
8055template <class ALLOCATOR, typename CAPACITY_POLICY>
8056inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
8057 ostringstream out;
8058 out << buffer;
8059 return out.str();
8060}
8061
8062inline string to_string(const ::mdbx::pair &value) {
8063 ostringstream out;
8064 out << value;
8065 return out.str();
8066}
8067
8068inline string to_string(const ::mdbx::env::geometry &value) {
8069 ostringstream out;
8070 out << value;
8071 return out.str();
8072}
8073
8074inline string to_string(const ::mdbx::env::operate_parameters &value) {
8075 ostringstream out;
8076 out << value;
8077 return out.str();
8078}
8079
8080inline string to_string(const ::mdbx::env::mode &value) {
8081 ostringstream out;
8082 out << value;
8083 return out.str();
8084}
8085
8086inline string to_string(const ::mdbx::env::durability &value) {
8087 ostringstream out;
8088 out << value;
8089 return out.str();
8090}
8091
8092inline string to_string(const ::mdbx::env::reclaiming_options &value) {
8093 ostringstream out;
8094 out << value;
8095 return out.str();
8096}
8097
8098inline string to_string(const ::mdbx::env::operate_options &value) {
8099 ostringstream out;
8100 out << value;
8101 return out.str();
8102}
8103
8104inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
8105 ostringstream out;
8106 out << value;
8107 return out.str();
8108}
8109
8110inline string to_string(const ::MDBX_log_level_t &value) {
8111 ostringstream out;
8112 out << value;
8113 return out.str();
8114}
8115
8116inline string to_string(const ::MDBX_debug_flags_t &value) {
8117 ostringstream out;
8118 out << value;
8119 return out.str();
8120}
8121
8122inline string to_string(const ::mdbx::error &value) {
8123 ostringstream out;
8124 out << value;
8125 return out.str();
8126}
8127
8128inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
8129
8130template <> struct hash<::mdbx::slice> {
8131 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
8132};
8133
8134template <> struct hash<::mdbx::map_handle> {
8135 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
8136};
8137
8138template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
8139 using inherited = std::hash<const MDBX_env *>;
8140 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
8141};
8142
8143template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
8144 using inherited = std::hash<const MDBX_txn *>;
8145 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
8146};
8147
8148template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
8149 using inherited = std::hash<const MDBX_cursor *>;
8150 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
8151};
8152
8153template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
8154 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
8155 return buffer.hash_value();
8156 }
8157};
8158
8159} // namespace std
8160
8161#if defined(__LCC__) && __LCC__ >= 126
8162#pragma diagnostic pop
8163#endif
8164
8165#ifdef _MSC_VER
8166#pragma warning(pop)
8167#endif
Definition mdbx.h++:1290
Definition mdbx.h++:1280
Definition mdbx.h++:1300
#define MDBX_CXX11_CONSTEXPR
Definition mdbx.h:458
#define MDBX_LIKELY(cond)
Definition mdbx.h:590
#define MDBX_MAYBE_UNUSED
Definition mdbx.h:524
#define MDBX_INLINE_API_ASSERT(expr)
Definition mdbx.h:605
#define MDBX_UNLIKELY(cond)
Definition mdbx.h:598
#define MDBX_CXX14_CONSTEXPR
Definition mdbx.h:477
#define MDBX_NOTHROW_PURE_FUNCTION
The pure nothrow function attribute for optimization.
Definition mdbx.h:274
size_t offset
Definition mdbx.h:5293
uint64_t last_confirmed_txnid
Definition mdbx.h:5291
uint64_t trunk_txnid
Definition mdbx.h:5289
mode_t mdbx_mode_t
Definition mdbx.h:187
#define LIBMDBX_API
Definition mdbx.h:634
#define LIBMDBX_API_TYPE
Definition mdbx.h:649
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:808
pthread_t mdbx_tid_t
Definition mdbx.h:186
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition mdbx.h:741
int mdbx_filehandle_t
Definition mdbx.h:184
pid_t mdbx_pid_t
Definition mdbx.h:185
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:822
@ MDBX_MAXDATASIZE
Definition mdbx.h:816
@ MDBX_MAX_DBI
Definition mdbx.h:813
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:819
libmdbx build information
Definition mdbx.h:677
Lightweight transparent cache entry structure used by mdbx_cache_get().
Definition mdbx.h:5288
Pair of error code and cache status as a result of mdbx_cache_get().
Definition mdbx.h:5388
The four integer markers (aka "canary") associated with the environment.
Definition mdbx.h:4781
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4187
The numerical metrics of progress and result of database defragmentation.
Definition mdbx.h:7517
Information about the environment.
Definition mdbx.h:2877
Information about Garbage Collection and page usage.
Definition mdbx.h:7442
Statistics for a table in the environment.
Definition mdbx.h:2831
Information about the transaction.
Definition mdbx.h:4085
libmdbx version information,
Definition mdbx.h:659
MDBX_bunch_action_t
Modes for deleting bunches of neighboring items with self-documenting names.
Definition mdbx.h:6485
LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, MDBX_put_flags_t flags)
Delete current key/data pair.
LIBMDBX_API int mdbx_cursor_delete_range(MDBX_cursor *begin, MDBX_cursor *end, bool end_including, uint64_t *number_of_affected)
Quickly removes given range of items.
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:5581
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_cursor_scan(MDBX_cursor *cursor, MDBX_predicate_func predicate, void *context, MDBX_cursor_op start_op, MDBX_cursor_op turn_op, void *arg)
Scans the table using the passed predicate, reducing the associated overhead.
LIBMDBX_API int mdbx_get_equal_or_great(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data)
Get equal or greater item from a table.
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 four integer markers (aka "canary") associated with the environment.
MDBX_put_flags_t
Data changing flags.
Definition mdbx.h:1663
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_get_batch(MDBX_cursor *cursor, size_t *count, MDBX_val *pairs, size_t limit, MDBX_cursor_op op)
Retrieve multiple non-dupsort key/value pairs by cursor.
LIBMDBX_API int mdbx_cursor_count(const MDBX_cursor *cursor, size_t *count)
Return count values (aka duplicates) for current key.
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:4841
LIBMDBX_API int mdbx_cursor_count_ex(const MDBX_cursor *cursor, size_t *count, MDBX_stat *stat, size_t bytes)
Return count values (aka duplicates) and nested b-tree statistics for current key.
MDBX_cache_status_t
Cache entry status returned by mdbx_cache_get().
Definition mdbx.h:5313
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5302
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_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)
Scans a table using the given predicate, starting with the given key-value pair, and reduces an assoc...
LIBMDBX_API int mdbx_cursor_bunch_delete(MDBX_cursor *cursor, MDBX_bunch_action_t action, uint64_t *number_of_affected)
Quickly removes bunches of neighboring items.
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_DELETE_AFTER_INCLUDING
Definition mdbx.h:6494
@ MDBX_DELETE_BEFORE_INCLUDING
Definition mdbx.h:6493
@ MDBX_DELETE_WHOLE
Definition mdbx.h:6496
@ MDBX_DELETE_BEFORE_EXCLUDING
Definition mdbx.h:6492
@ MDBX_DELETE_CURRENT_VALUE
Definition mdbx.h:6486
@ MDBX_DELETE_CURRENT_MULTIVAL_BEFORE_EXCLUDING
Definition mdbx.h:6487
@ MDBX_DELETE_AFTER_EXCLUDING
Definition mdbx.h:6495
@ MDBX_DELETE_CURRENT_MULTIVAL_ALL
Definition mdbx.h:6491
@ MDBX_DELETE_CURRENT_MULTIVAL_BEFORE_INCLUDING
Definition mdbx.h:6488
@ MDBX_DELETE_CURRENT_MULTIVAL_AFTER_INCLUDING
Definition mdbx.h:6489
@ MDBX_DELETE_CURRENT_MULTIVAL_AFTER_EXCLUDING
Definition mdbx.h:6490
@ MDBX_MULTIPLE
Definition mdbx.h:1700
@ MDBX_ALLDUPS
Definition mdbx.h:1683
@ MDBX_CURRENT
Definition mdbx.h:1678
@ MDBX_APPENDDUP
Definition mdbx.h:1696
@ MDBX_APPEND
Definition mdbx.h:1691
@ MDBX_UPSERT
Definition mdbx.h:1665
@ MDBX_RESERVE
Definition mdbx.h:1687
@ MDBX_NOOVERWRITE
Definition mdbx.h:1668
LIBMDBX_API int mdbx_cursor_on_first_dup(const MDBX_cursor *cursor)
Determines whether the cursor is on the first or single multi-value corresponding to the key.
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:1744
LIBMDBX_API int mdbx_cursor_compare(const MDBX_cursor *left, const MDBX_cursor *right, bool ignore_multival)
Compares the position of the cursors.
LIBMDBX_API int mdbx_cursor_on_last_dup(const MDBX_cursor *cursor)
Determines whether the cursor is on the last or single multi-value corresponding to the key.
LIBMDBX_API int mdbx_cursor_distribute(const MDBX_cursor *first, const MDBX_cursor *last, MDBX_cursor **array, intptr_t count, unsigned deepness)
Distributes cursors for multithreaded range scanning.
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_cursor_reset(MDBX_cursor *cursor)
Resets the cursor state.
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:771
LIBMDBX_API int mdbx_cursor_set_userctx(MDBX_cursor *cursor, void *ctx)
Set application information associated with the cursor.
LIBMDBX_API int mdbx_cursor_distance(const MDBX_cursor *first, const MDBX_cursor *last, intptr_t *distance, unsigned deepness)
Calculates the distance between the cursors at the specified B-tree level.
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_scroll(MDBX_cursor *cursor, intptr_t amount, unsigned deepness)
Scrolls the cursor to the specified number of positions at the specified B-tree level.
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 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:1863
@ MDBX_GET_CURRENT
Definition mdbx.h:1759
@ MDBX_GET_BOTH
Definition mdbx.h:1752
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1840
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1756
@ MDBX_SET_KEY
Definition mdbx.h:1799
@ MDBX_FIRST_DUP
Definition mdbx.h:1749
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1839
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1764
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1850
@ MDBX_NEXT_NODUP
Definition mdbx.h:1784
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1847
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1848
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1855
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1807
@ MDBX_SET_RANGE
Definition mdbx.h:1802
@ MDBX_LAST_DUP
Definition mdbx.h:1770
@ MDBX_PREV
Definition mdbx.h:1787
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1857
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1858
@ MDBX_LAST
Definition mdbx.h:1767
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1838
@ MDBX_PREV_DUP
Definition mdbx.h:1790
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1846
@ MDBX_SET
Definition mdbx.h:1796
@ MDBX_NEXT
Definition mdbx.h:1773
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1841
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1854
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1781
@ MDBX_PREV_NODUP
Definition mdbx.h:1793
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1856
@ MDBX_NEXT_DUP
Definition mdbx.h:1776
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1849
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1842
@ MDBX_FIRST
Definition mdbx.h:1746
LIBMDBX_API int mdbx_dbi_rename(MDBX_txn *txn, MDBX_dbi dbi, const char *name)
Renames the table using the DBI descriptor.
LIBMDBX_API int mdbx_dbi_rename2(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *name)
Renames the table using the DBI descriptor.
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:764
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1613
@ MDBX_INTEGERDUP
Definition mdbx.h:1637
@ MDBX_DB_ACCEDE
Definition mdbx.h:1655
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1615
@ MDBX_REVERSEKEY
Definition mdbx.h:1618
@ MDBX_DUPFIXED
Definition mdbx.h:1632
@ MDBX_INTEGERKEY
Definition mdbx.h:1628
@ MDBX_REVERSEDUP
Definition mdbx.h:1640
@ MDBX_CREATE
Definition mdbx.h:1643
@ MDBX_DUPSORT
Definition mdbx.h:1621
LIBMDBX_API const char * mdbx_dump_val(const MDBX_val *key, char *const buf, const size_t bufsize)
Dump given MDBX_val to the buffer.
void(* MDBX_panic_func)(const char *msg, const char *function, unsigned line, const void *obj, const char *obj_class) noexcept
A callback function for most assertion failures, that called before printing the message and aborting...
Definition mdbx.h:1057
void(* MDBX_debug_func)(MDBX_log_level_t log_level, const char *function, int line, const char *fmt, va_list args) noexcept
A log callback function that accepts a format string and arguments passed through the va_list pointer...
Definition mdbx.h:991
MDBX_log_level_t
Definition mdbx.h:884
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:942
LIBMDBX_API void mdbx_set_panic(MDBX_panic_func func)
Sets or reset the callback for panic() and assert() for the current process.
void(* MDBX_debug_func_nofmt)(MDBX_log_level_t log_level, const char *function, int line, const char *msg, unsigned length) noexcept
A log callback function that accepts a formatted message with length.
Definition mdbx.h:1019
@ MDBX_LOG_DONTCHANGE
Definition mdbx.h:886
@ MDBX_DBG_DONTCHANGE
Definition mdbx.h:944
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1871
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:7008
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1885
@ MDBX_BAD_TXN
Definition mdbx.h:1948
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1962
@ MDBX_SUCCESS
Definition mdbx.h:1873
@ MDBX_NOTFOUND
Definition mdbx.h:1888
@ MDBX_RESULT_TRUE
Definition mdbx.h:1879
@ MDBX_BUSY
Definition mdbx.h:1966
@ MDBX_EINVAL
Definition mdbx.h:2043
@ MDBX_ENOMEM
Definition mdbx.h:2045
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1969
@ MDBX_RESULT_FALSE
Definition mdbx.h:1876
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:2021
@ MDBX_KEYEXIST
Definition mdbx.h:1882
LIBMDBX_API int mdbx_reader_check(MDBX_env *env, int *dead)
Check for stale entries in the reader lock table.
LIBMDBX_API int mdbx_txn_copy2pathname(MDBX_txn *txn, const char *dest, MDBX_copy_flags_t flags)
Copy an MDBX environment by given read transaction to the specified path, with options.
MDBX_copy_flags_t
Environment copy flags.
Definition mdbx.h:1707
LIBMDBX_API int mdbx_env_chk(MDBX_env *env, const MDBX_chk_callbacks_t *cb, MDBX_chk_context_t *ctx, const MDBX_chk_flags_t flags, MDBX_chk_severity_t verbosity, unsigned timeout_seconds_16dot16)
Checks the integrity of a database.
LIBMDBX_API int mdbx_thread_register(const MDBX_env *env)
Registers the current thread as a reader for the environment.
LIBMDBX_API int mdbx_txn_unlock(MDBX_env *env)
Releases write-transaction lock. Provided for custom and/or complex locking scenarios.
LIBMDBX_API int mdbx_env_defrag(MDBX_env *env, size_t defrag_atleast, size_t time_atleast_dot16, size_t defrag_enough, size_t time_limit_dot16, intptr_t acceptable_backlash, intptr_t preferred_batch, MDBX_defrag_notify_func progress_callback, void *ctx, MDBX_defrag_result_t *result)
Performs database defragmentation.
MDBX_chk_flags_t
Flags/options for checking the integrity of a database.
Definition mdbx.h:7138
MDBX_chk_severity_t
Levels of logging/detailing of information supplied via callbacks during a database integrity check.
Definition mdbx.h:7161
LIBMDBX_API int mdbx_txn_lock(MDBX_env *env, bool dont_wait)
Acquires write-transaction lock. Provided for custom and/or complex locking scenarios.
LIBMDBX_API int mdbx_env_resurrect_after_fork(MDBX_env *env)
Restores an instance of the environment in a child process after forking the parent process using for...
LIBMDBX_API int mdbx_cursor_ignord(MDBX_cursor *cursor)
An auxiliary function for use in tools.
LIBMDBX_API int mdbx_thread_unregister(const MDBX_env *env)
Unregisters the current thread as a reader for the environment.
LIBMDBX_API int mdbx_env_sync_ex(MDBX_env *env, bool force, bool nonblock)
Flush the environment data buffers to disk.
LIBMDBX_API int mdbx_txn_copy2fd(MDBX_txn *txn, mdbx_filehandle_t fd, MDBX_copy_flags_t flags)
Copy an environment by given read transaction to the specified file descriptor, with options.
LIBMDBX_API int mdbx_txn_copy2pathnameW(MDBX_txn *txn, const wchar_t *dest, MDBX_copy_flags_t flags)
Copy an MDBX environment by given read transaction to the specified path, with options.
@ MDBX_CP_DEFAULTS
Definition mdbx.h:1708
@ MDBX_CP_COMPACT
Definition mdbx.h:1712
@ MDBX_CP_FORCE_DYNAMIC_SIZE
Definition mdbx.h:1715
@ MDBX_CHK_DEFAULTS
Definition mdbx.h:7140
@ MDBX_chk_info
Definition mdbx.h:7171
@ MDBX_ENV_WAIT_FOR_UNUSED
Wait until other processes closes the environment before deletion.
Definition mdbx.h:2611
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2606
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2609
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1085
LIBMDBX_API int mdbx_preopen_snapinfoW(const wchar_t *pathname, MDBX_envinfo *info, size_t bytes)
Gets basic information about the database without opening it.
LIBMDBX_API int mdbx_preopen_snapinfo(const char *pathname, MDBX_envinfo *info, size_t bytes)
Gets basic information about the database without opening it.
@ MDBX_WRITEMAP
Definition mdbx.h:1205
@ MDBX_EXCLUSIVE
Definition mdbx.h:1159
@ MDBX_RDONLY
Definition mdbx.h:1129
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:3126
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2151
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:3067
MDBX_warmup_flags_t
Warming up options.
Definition mdbx.h:3269
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:2256
@ MDBX_opt_subpage_room_threshold
Sets the minimum amount of free space on a leaf page in the absence of which the nested pages are pla...
Definition mdbx.h:2418
@ MDBX_opt_subpage_limit
Specifies the maximum size of nested pages used to accommodate a small number of multi-values associa...
Definition mdbx.h:2411
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2252
@ MDBX_opt_prefer_waf_insteadof_balance
Controls the choice between striving for uniformity of page filling/density, either for reducing the ...
Definition mdbx.h:2397
@ MDBX_opt_presync_threshold
Sets threshold in bytes for preliminary flush/sync operation without holding a transaction lock.
Definition mdbx.h:2478
@ 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:2356
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2160
@ MDBX_opt_subpage_reserve_prereq
Sets the minimum amount of free space on the main page, if available, to reserve space in the subpage...
Definition mdbx.h:2432
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2183
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2288
@ 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:2311
@ MDBX_opt_split_reserve
Sets the space reservation in 1/65536 of page size when splitting page along the edge.
Definition mdbx.h:2460
@ 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:2223
@ 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:2210
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2177
@ MDBX_opt_subpage_reserve_limit
Sets the limit for reserving space on nested pages.
Definition mdbx.h:2438
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2272
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2189
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2237
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2351
@ MDBX_opt_gc_time_limit
Controls the in-process spending time limit of searching consecutive pages inside GC.
Definition mdbx.h:2375
@ MDBX_opt_merge_threshold
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2323
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:3741
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:3146
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_gc_info(MDBX_txn *txn, MDBX_gc_info_t *info, size_t bytes, MDBX_gc_iter_func iter_func, void *iter_ctx)
Provides information of Garbage Collection and page usage.
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:3085
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 returned by mdbx_dbi_flags_ex().
Definition mdbx.h:5103
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 int mdbx_enumerate_tables(const MDBX_txn *txn, MDBX_table_enum_func func, void *ctx)
Enumerates user's named tables in a database.
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:3786
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_get_sysraminfo(intptr_t *page_size, intptr_t *total_pages, intptr_t *avail_pages)
Returns basic information about system RAM. This function provides a portable way to get information ...
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_reader_list(const MDBX_env *env, MDBX_reader_list_func func, void *ctx)
Enumerate the entries in the reader lock table.
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)
Puts the reading transaction in a "parked" state.
LIBMDBX_API int mdbx_txn_refresh(MDBX_txn *txn)
Refresh a read-only transaction for a recent data.
LIBMDBX_API int mdbx_txn_unpark(MDBX_txn *txn, bool restart_if_ousted)
Unparks a previously parked reading transaction.
MDBX_txn_flags_t
Definition mdbx.h:1512
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:4002
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:752
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:1523
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1532
@ MDBX_TXN_READWRITE
Definition mdbx.h:1517
@ MDBX_TXN_TRY
Definition mdbx.h:1538
LIBMDBX_API int mdbx_env_turn_for_recovery(MDBX_env *env, unsigned target_meta)
Turn database to the specified meta-page.
A set of callback functions used for checking the integrity of a database.
Definition mdbx.h:7332
The context for checking the integrity of a database.
Definition mdbx.h:7295
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++:6544
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:6169
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++:7546
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:5733
polymorphic_allocator default_allocator
Definition mdbx.h++:393
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:5742
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:5927
constexpr geometry & set_size_lower(intptr_t size) noexcept
Sets the lower bound of database size in bytes.
Definition mdbx.h++:6274
constexpr operate_options & set_no_sticky_threads(bool value=true) noexcept
Sets the "no sticky threads" mode.
Definition mdbx.h++:6491
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++:6143
void copy(const char *destination, bool compactify, bool force_dynamic_size=false)
Copy an MVCC-snapshot of the database to the destination path.
Definition mdbx.h++:7049
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++:6081
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++:6072
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:6998
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++:6572
constexpr operate_options & set_disable_clear_memory(bool value=true) noexcept
Sets the clear-memory disable mode.
Definition mdbx.h++:6515
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5941
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:5583
void thread_register()
Registers the current thread as a reader for the environment, i.e. assigns a reader slot.
Definition mdbx.h++:6874
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:7806
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:5540
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:5921
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:7031
class MDBX_MSVC_DECLSPEC_EMPTY_BASES buffer
Definition mdbx.h++:401
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:5710
void rethrow_captured() const
Definition mdbx.h++:5555
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:5718
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:7727
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:7703
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:6537
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++:6090
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:7507
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:7449
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:6791
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++:6722
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:7671
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++:6122
constexpr operate_parameters & write_file_io() noexcept
Sets the operation mode to env::mode::write_file_io.
Definition mdbx.h++:6379
void turn_for_recovery(unsigned target_meta)
Turns the database to the specified meta-page.
Definition mdbx.h++:6886
::mdbx::filesystem::path::string_type path_string
Definition mdbx.h++:441
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:5740
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:7616
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++:6148
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:5765
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:5666
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:7812
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:462
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:7440
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:7628
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:7177
size_t erase_range(const cursor &end, bool end_including)
Quickly removes a range of items between the current cursor position and the position of end much fas...
Definition mdbx.h++:7946
void throw_on_failure() const
Definition mdbx.h++:5595
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:7887
void update(const slice &key, const slice &value)
Definition mdbx.h++:7883
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:5537
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++:7318
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:5993
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:5728
constexpr size_t rfind(const slice &needle, size_t pos=npos) const noexcept
Finds the last occurrence of needle not after pos.
Definition mdbx.h++:5839
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++:6137
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:7000
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:6919
constexpr operate_parameters & lifo(bool value=true) noexcept
Sets the LIFO reclaiming mode, i.e. reclaiming_options::lifo.
Definition mdbx.h++:6421
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:7658
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5967
constexpr operate_parameters & set_options(const env::operate_options &value) noexcept
Sets the operate options.
Definition mdbx.h++:6367
MDBX_NODISCARD env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:6655
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:7306
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:7873
constexpr operate_parameters & write_mapped_io() noexcept
Sets the operation mode to env::mode::write_mapped_io.
Definition mdbx.h++:6385
bool is_clean() const noexcept
Definition mdbx.h++:5548
constexpr operate_parameters & lazy_weak_tail() noexcept
Sets the durability level to env::durability::lazy_weak_tail.
Definition mdbx.h++:6403
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:5628
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++:6127
path_string::value_type path_char
Definition mdbx.h++:449
constexpr operate_parameters & no_sticky_threads(bool value=true) noexcept
Sets the "no sticky threads" mode, i.e. operate_options::no_sticky_threads.
Definition mdbx.h++:6427
MDBX_NODISCARD env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:6645
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:414
constexpr operate_parameters & exclusive(bool value=true) noexcept
Sets the exclusive mode, i.e. operate_options::exclusive.
Definition mdbx.h++:6433
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:6697
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:6530
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:5808
static constexpr operate_parameters fragile_write() noexcept
Constructs parameters for a writable environment with env::durability::whole_fragile durability and e...
Definition mdbx.h++:6478
constexpr operate_parameters & set_max_readers(unsigned value) noexcept
Sets the maximum number of threads/reader slots for the environment. Zero means default value.
Definition mdbx.h++:6343
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:5562
constexpr size_t find_last_of(const slice &chars, size_t pos=npos) const noexcept
Finds the last byte matching any byte of chars not after pos.
Definition mdbx.h++:5875
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++:6153
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:5490
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:6024
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++:6890
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++:6794
void insert(const slice &key, slice value)
Definition mdbx.h++:7834
constexpr create_parameters & set_geometry(const env::geometry &value) noexcept
Sets the database geometry for size management.
Definition mdbx.h++:6318
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:7731
constexpr operate_parameters & half_synchronous_weak_last() noexcept
Sets the durability level to env::durability::half_synchronous_weak_last.
Definition mdbx.h++:6397
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++:7132
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:6218
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:392
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++:6163
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:5650
~cursor() noexcept
Definition mdbx.h++:7645
constexpr operate_parameters & enable_validation(bool value=true) noexcept
Sets the validation enable mode, i.e. operate_options::enable_validation.
Definition mdbx.h++:6451
~txn() noexcept
Definition mdbx.h++:6992
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:6727
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:6117
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:7723
uint64_t txnid
Transaction ID and MVCC-snapshot number.
Definition mdbx.h++:410
constexpr void invalidate() noexcept
Invalidates the slice by nullifying the data pointer while preserving the length; makes is_valid() re...
Definition mdbx.h++:5746
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:7814
inline ::std::vector< pair > get_batch(size_t max_pairs, move_operation op, bool *is_last=nullptr) const
Reads a batch of key-value pairs.
Definition mdbx.h++:7753
constexpr operate_options & set_enable_validation(bool value=true) noexcept
Sets the validation enable mode.
Definition mdbx.h++:6521
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7859
static MDBX_NODISCARD env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:6313
map_handle map() const
Definition mdbx.h++:7819
unsigned sync_period__seconds_16dot16() const
Gets relative period since the last unsteady commit that used to force flush the data buffers to disk...
Definition mdbx.h++:6738
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:5544
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:7715
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:7148
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:7735
void success_or_throw() const
Definition mdbx.h++:5600
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:7035
void ignore_key_order()
Disables the control of the order of keys when reading database pages for this cursor.
Definition mdbx.h++:7778
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:5780
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:6778
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5971
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:7662
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:7741
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:5776
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:6528
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:5785
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:7005
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7877
constexpr operate_parameters & set_max_maps(unsigned value) noexcept
Sets the maximum number of named tables/maps for the environment. Zero means default value.
Definition mdbx.h++:6337
MDBX_NODISCARD env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:6653
void capture() noexcept
Definition mdbx.h++:5550
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:6099
bool scroll(intptr_t distable, unsigned deepness=42, bool throw_notfound=true)
Definition mdbx.h++:7978
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++:7225
constexpr operate_parameters & robust_synchronous() noexcept
Sets the durability level to env::durability::robust_synchronous.
Definition mdbx.h++:6391
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:7485
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:5759
bool txn_lock(bool dont_wait=false)
Acquires write-transaction lock.
Definition mdbx.h++:6928
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7852
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++:6895
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 page size and table flag...
Definition mdbx.h++:6592
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++:6733
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:7604
MDBX_NODISCARD env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:6659
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:7173
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:7622
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++:7580
constexpr operate_parameters & disable_clear_memory(bool value=true) noexcept
Sets the clear-memory disable mode, i.e. operate_options::disable_clear_memory.
Definition mdbx.h++:6445
MDBX_NODISCARD env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:6663
constexpr operate_parameters & readonly() noexcept
Sets the operation mode to env::mode::readonly.
Definition mdbx.h++:6373
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:7099
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5975
MDBX_NODISCARD cache_result get_cached(map_handle map, const slice &key, slice *data, cache_entry &entry) const
Gets a value by key using the transparent read-your-writes cache.
Definition mdbx.h++:7340
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:7653
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:7219
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:7681
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++:6568
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++:7322
static MDBX_NODISCARD env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:6309
void thread_unregister()
Unregisters the current thread, i.e. releases its reader slot.
Definition mdbx.h++:6876
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:7295
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:7471
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:5803
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:5577
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++:6744
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:5933
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:5702
bool on_first() const
Definition mdbx.h++:7782
::MDBX_version_info version_info
libmdbx version information,
Definition mdbx.h++:357
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:5738
constexpr operate_parameters & set_durability(env::durability value) noexcept
Sets the durability level.
Definition mdbx.h++:6355
bool eof() const
Definition mdbx.h++:7780
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:7033
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:7019
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:6715
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:7826
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:6904
::MDBX_build_info build_info
libmdbx build information
Definition mdbx.h++:361
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:6112
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:6980
constexpr const byte * begin() const noexcept
Returns an iterator to the beginning of the referenced data.
Definition mdbx.h++:5818
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:5770
int enumerate_tables(VISITOR &visitor) const
Enumerates user's named tables in a database.
Definition mdbx.h++:7237
bool seek(const slice &key)
Definition mdbx.h++:7739
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:6767
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:6717
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:5792
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++:6636
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:7175
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++:6756
constexpr create_parameters & set_use_subdirectory(bool value=true) noexcept
Sets whether to use a subdirectory to place the DB files.
Definition mdbx.h++:6331
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:6234
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:5753
constexpr geometry & set_pagesize(intptr_t size) noexcept
Sets the database page size for new database creation.
Definition mdbx.h++:6304
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:7839
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++:7954
constexpr size_t find_first_of(const slice &chars, size_t pos=0) const noexcept
Finds the first byte matching any byte of chars starting at pos.
Definition mdbx.h++:5860
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:5613
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:5571
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:7017
static MDBX_NODISCARD info get_preopen_snapinfo(const ::std::string &pathname)
Provides information about a database, including meta-page and geometry, without opening it.
Definition mdbx.h++:6846
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:6174
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++:6158
double sync_period__seconds_double() const
Gets relative period since the last unsteady commit that used to force flush the data buffers to disk...
Definition mdbx.h++:6748
::mdbx_filehandle_t filehandle
Definition mdbx.h++:416
constexpr operate_parameters & set_reclaiming(const env::reclaiming_options &value) noexcept
Sets the garbage reclaiming options.
Definition mdbx.h++:6361
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++:6614
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:6240
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5963
void txn_unlock()
Releases write-transaction lock acquired by txn_lock().
Definition mdbx.h++:6940
BUFFER extract(map_handle map, const slice &key, const ALLOCATOR &alloc=ALLOCATOR())
Removes and return a value of the key.
Definition mdbx.h++:7552
char8_t byte
The byte-like type that don't presumes aliases for pointers as does the char.
Definition mdbx.h++:342
canary get_canary() const
Returns the four integer markers (aka "canary") associated with the environment.
Definition mdbx.h++:7300
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:7918
bool refresh()
Refresh the read-only transaction to the most recent snapshot.
Definition mdbx.h++:7037
BUFFER replace_reserve(map_handle map, const slice &key, size_t length, slice &new_value_reservation, const ALLOCATOR &alloc=ALLOCATOR())
Definition mdbx.h++:7569
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:6667
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:6067
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:7025
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:7425
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:375
constexpr size_t find_last_not_of(const slice &chars, size_t pos=npos) const noexcept
Finds the last byte not matching any byte of chars not after pos.
Definition mdbx.h++:5904
constexpr bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition mdbx.h++:5585
constexpr reclaiming_options & set_lifo(bool value=true) noexcept
Sets the LIFO reclaiming mode.
Definition mdbx.h++:6485
constexpr geometry & set_size_now(intptr_t size) noexcept
Sets the size in bytes to setup the database size for now.
Definition mdbx.h++:6280
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:6094
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:6076
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:7709
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5948
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:6085
static bool distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size, unsigned deepness=42)
Definition mdbx.h++:7992
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:6103
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:7499
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:6230
~env() noexcept
Definition mdbx.h++:6252
gc_info get_gc_info(VISITOR &visitor) const
Provides information of Garbage Collection and page usage.
Definition mdbx.h++:7260
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:7334
static constexpr operate_parameters lazy_write() noexcept
Constructs parameters for a writable environment with env::durability::lazy_weak_tail durability and ...
Definition mdbx.h++:6471
constexpr bool is_failure() const noexcept
Definition mdbx.h++:5579
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:5748
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++:7585
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:7479
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:5797
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:6897
::mdbx::filesystem::path path
Definition mdbx.h++:440
bool on_last_multival() const
Definition mdbx.h++:7788
defrag_result defrag(VISITOR &visitor, size_t defrag_atleast=0, size_t time_atleast_dot16=0, size_t defrag_enough=0, size_t time_limit_dot16=0, intptr_t acceptable_backlash=-1, intptr_t preferred_batch=0)
Performs database defragmentation.
Definition mdbx.h++:6943
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:6709
constexpr const byte * end() const noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:5720
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:7418
constexpr operate_options & set_nested_transactions(bool value=true) noexcept
Sets the nested transactions mode.
Definition mdbx.h++:6497
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:6703
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++:6548
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:6799
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:7651
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:6643
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:7111
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:7101
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:6761
MDBX_NODISCARD int warmup(MDBX_warmup_flags_t flags, unsigned timeout_seconds_16dot16, const MDBX_txn *txn=nullptr) const
Loads into memory the given pages of the database and their on-disk neighbours in advance.
Definition mdbx.h++:6878
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:5491
constexpr operate_parameters & whole_fragile() noexcept
Sets the durability level to env::durability::whole_fragile.
Definition mdbx.h++:6409
bool on_first_multival() const
Definition mdbx.h++:7786
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:7406
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:6006
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:5813
static constexpr operate_parameters safe_write() noexcept
Constructs parameters for a writable environment with env::durability::robust_synchronous durability ...
Definition mdbx.h++:6464
constexpr geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:6266
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:6679
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:7465
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:6526
string< ALLOCATOR > as_base64_string(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of the slice content.
Definition mdbx.h++:6132
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7899
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:7086
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:7719
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:5704
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:5726
gc_info get_gc_info() const
Definition mdbx.h++:7288
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++:6215
constexpr operate_options & set_disable_readahead(bool value=true) noexcept
Sets the readahead disable mode.
Definition mdbx.h++:6509
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:6822
constexpr geometry & set_size_upper(intptr_t size) noexcept
Sets the upper bound of database size in bytes.
Definition mdbx.h++:6286
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:7522
static constexpr operate_parameters read_only() noexcept
Constructs parameters for a read-only environment.
Definition mdbx.h++:6457
static MDBX_NODISCARD sysraminfo get_sysraminfo()
Returns information about the system RAM.
Definition mdbx.h++:6840
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:5575
constexpr size_t find_first_not_of(const slice &chars, size_t pos=0) const noexcept
Finds the first byte not matching any byte of chars starting at pos.
Definition mdbx.h++:5891
bool on_last() const
Definition mdbx.h++:7784
constexpr geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:6259
constexpr operate_parameters & set_mode(env::mode value) noexcept
Sets the operation mode.
Definition mdbx.h++:6349
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:436
constexpr create_parameters & set_file_mode_bits(mdbx_mode_t value) noexcept
Sets the file mode bits used for creation of the DB files.
Definition mdbx.h++:6325
constexpr geometry & set_shrink_threshold(intptr_t threshold) noexcept
Sets the shrink threshold in bytes.
Definition mdbx.h++:6298
constexpr size_t find(const slice &needle, size_t pos=0) const noexcept
Finds the first occurrence of needle starting at pos.
Definition mdbx.h++:5822
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:6691
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:6772
constexpr operate_options & set_exclusive(bool value=true) noexcept
Sets the exclusive mode.
Definition mdbx.h++:6503
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++:7808
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:6108
constexpr geometry & set_growth_step(intptr_t step) noexcept
Sets the growth step in bytes.
Definition mdbx.h++:6292
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:7117
size_t erase_bunch(bunch_delete action)
Quickly removes bunches of neighboring items much faster by cutting out entire pages and branches fro...
Definition mdbx.h++:7940
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:5569
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:6046
constexpr bool is_success() const noexcept
Definition mdbx.h++:5573
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:7905
constexpr operate_parameters & nested_transactions(bool value=true) noexcept
Sets the nested transactions mode, i.e. operate_options::nested_transactions.
Definition mdbx.h++:6415
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:6019
void reset()
Resets the cursor state.
Definition mdbx.h++:7952
cursor & assign(const cursor &)
Definition mdbx.h++:7630
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:6926
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:6226
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:7105
static ptrdiff_t distance_between(const cursor from, const cursor to, unsigned deepness=42)
Definition mdbx.h++:7972
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++:7164
MDBX_NODISCARD MDBX_chk_context_t & chk(MDBX_chk_context_t &ctx, const MDBX_chk_callbacks_t *cb=nullptr, MDBX_chk_flags_t flags=MDBX_CHK_DEFAULTS, MDBX_chk_severity_t verbosity=MDBX_chk_info, unsigned timeout_seconds_16dot16=0) const
Checks the integrity of the environment (database).
Definition mdbx.h++:6832
void resurrect_after_fork()
Restores the environment after fork(), dropping all read-write locks and reader slots of the parent p...
Definition mdbx.h++:6883
constexpr operate_parameters & disable_readahead(bool value=true) noexcept
Sets the readahead disable mode, i.e. operate_options::disable_readahead.
Definition mdbx.h++:6439
pair_result get_equal_or_great(map_handle map, const slice &key) const
Gets the value for an equal or greater key from a table.
Definition mdbx.h++:7385
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:7231
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:5712
void commit(finalization_latency &latency)
Commits all changes of the transaction into a database with collecting latencies information.
Definition mdbx.h++:4895
constexpr const MDBX_env * handle() const noexcept
Definition mdbx.h++:3264
friend class env
Definition mdbx.h++:4860
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:4448
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:5461
bool scan_until(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:5082
::MDBX_stat map_stat
Definition mdbx.h++:4648
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,...
bool amend(bool dont_wait=false)
Starts a writing transaction to amending data in the MVCC-snapshot used by the read-only transaction.
txn_managed start_nested()
Start nested write transaction.
extra_runtime_option
MDBX environment extra runtime options.
Definition mdbx.h++:3884
env_managed & operator=(env_managed &&other) noexcept
constexpr uint64_t transaction_id() const noexcept
Returns the transaction/MVCC-snapshot ID of the internal structure that holds the cached data.
Definition mdbx.h++:3031
::MDBX_cache_status_t cache_status
Definition mdbx.h++:4714
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:4629
bool scan_until_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:5127
env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede=true)
map_handle(const map_handle &) noexcept=default
mode
Operation mode.
Definition mdbx.h++:3389
@ readonly
Definition mdbx.h++:3390
@ write_mapped_io
Definition mdbx.h++:3392
@ write_file_io
Definition mdbx.h++:3391
::MDBX_db_flags_t flags
Definition mdbx.h++:3211
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5204
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:5288
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:3266
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr const MDBX_cursor * handle() const noexcept
Definition mdbx.h++:4960
::MDBX_defrag_result_t defrag_result
The result of database defragmentation, see MDBX_defrag_result_t.
Definition mdbx.h++:4131
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:3180
friend constexpr bool operator!=(const cursor &a, const cursor &b) noexcept
Definition mdbx.h++:4965
void commit_embark_read()
Commits 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++:3207
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3678
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++:5276
bool checkpoint(finalization_latency &latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4909
constexpr uint64_t last_confirmed() const noexcept
Returns the recent transaction/MVCC-snapshot ID wherein the entry was checked and confirmed.
Definition mdbx.h++:3034
constexpr cache_entry(const MDBX_cache_entry_t &ce) noexcept
Definition mdbx.h++:3036
cache_entry() noexcept
Definition mdbx.h++:3013
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:4403
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5223
ptrdiff_t distance_to_end(unsigned deepness=42) const
Definition mdbx.h++:5314
::MDBX_canary canary
Definition mdbx.h++:4691
defrag_control
Control values returned by the defragmentation progress visitor.
Definition mdbx.h++:4135
@ abort
Abort defragmentation immediately.
Definition mdbx.h++:4137
@ proceed
Continue defragmentation.
Definition mdbx.h++:4136
std::pair< bool, finalization_latency > checkpoint_get_latency()
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4912
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++:4446
void commit_embark_read(finalization_latency *latency)
Commits all the operations of a transaction into the database and then start read transaction.
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++:5153
friend constexpr bool operator!=(const txn &a, const txn &b) noexcept
Definition mdbx.h++:4421
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++:5217
bool clear_map(const char *name, bool throw_if_absent=false)
constexpr env() noexcept=default
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5226
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.
slice reserve_current(size_t value_length)
Reserves and returns the space for storing a value associated with a key at the current cursor positi...
constexpr cache_entry & operator=(const MDBX_cache_entry_t &ce) noexcept
Definition mdbx.h++:3037
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
durability
Durability level.
Definition mdbx.h++:3397
@ whole_fragile
Definition mdbx.h++:3401
@ lazy_weak_tail
Definition mdbx.h++:3400
@ robust_synchronous
Definition mdbx.h++:3398
@ half_synchronous_weak_last
Definition mdbx.h++:3399
void reset() noexcept
Initializes the cache entry to the "no cached info" state.
Definition mdbx.h++:3022
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:3201
::MDBX_gc_info_t gc_info
Definition mdbx.h++:4671
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:3181
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:5370
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:5171
cursor_managed clone(void *your_context=nullptr) const
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++:5162
static MDBX_NODISCARD info get_preopen_snapinfo(const ::std::wstring &pathname)
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++:4988
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:4536
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:4784
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5194
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4980
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4984
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++:4621
constexpr MDBX_txn * handle() noexcept
Definition mdbx.h++:4419
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3596
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:5178
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:5472
bunch_delete
Modes for deleting bunches of neighboring items, see MDBX_bunch_action_t(). The EXCLUDING and INCLUDI...
Definition mdbx.h++:5390
@ delete_current_multival_all
Definition mdbx.h++:5396
@ delete_current_multival_after_excluding
Definition mdbx.h++:5395
@ delete_current_value
Definition mdbx.h++:5391
@ delete_after_excluding
Definition mdbx.h++:5400
@ delete_current_multival_before_including
Definition mdbx.h++:5393
@ delete_current_multival_before_excluding
Definition mdbx.h++:5392
@ delete_current_multival_after_including
Definition mdbx.h++:5394
@ delete_after_including
Definition mdbx.h++:5399
@ delete_before_including
Definition mdbx.h++:5398
@ delete_before_excluding
Definition mdbx.h++:5397
@ delete_whole
Definition mdbx.h++:5401
MDBX_txn * handle_
Definition mdbx.h++:4404
void abort()
Abandon all the operations of the transaction instead of saving ones.
MDBX_commit_latency finalization_latency
Definition mdbx.h++:4874
const path_char * get_path() const
Return the path that was used for opening the environment.
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:5150
friend constexpr bool operator==(const cursor &a, const cursor &b) noexcept
Definition mdbx.h++:4962
bool is_writemap() const
Definition mdbx.h++:3790
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:5147
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3739
operator::mdbx::txn() const
Definition mdbx.h++:5345
MDBX_env * handle_
Definition mdbx.h++:3250
slice reverse_current(size_t value_length)
Deprecated misspelling of reserve_current().
Definition mdbx.h++:5363
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5210
::MDBX_cache_result_t cache_result
Definition mdbx.h++:4715
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4976
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:5160
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:5180
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:3016
bool is_nested_transactions_available() const
Definition mdbx.h++:3794
void close()
Explicitly closes the cursor.
static env_managed open_for_recovery(const ::std::string &pathname, unsigned target_meta, bool writeable, unsigned max_maps=2)
static env_managed open_for_recovery(const wchar_t *pathname, unsigned target_meta, bool writeable, unsigned max_maps=2)
constexpr MDBX_env * handle() noexcept
Definition mdbx.h++:3265
bool scan_until_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:5106
void abort(finalization_latency &latency)
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4881
bool is_pristine() const
Returns true for a freshly created database, but false if at least one transaction was committed.
intptr_t avail_pages
The number of currently available pages.
Definition mdbx.h++:3602
move_result to_key_exact(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5191
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:4443
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++:5284
env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede=true)
ptrdiff_t distance_from_first(unsigned deepness=42) const
Definition mdbx.h++:5311
void append(map_handle map, const pair &kv, bool multivalue_order_preserved=true)
Definition mdbx.h++:4824
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3709
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3719
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3721
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3716
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:5165
static env_managed open_for_recovery(const ::mdbx::filesystem::path &pathname, unsigned target_meta, bool writeable, unsigned max_maps=2)
intptr_t total_pages
The number of all pages in the system.
Definition mdbx.h++:3601
cursor_managed & operator=(cursor_managed &&other) noexcept
::MDBX_dbi_state_t state
Definition mdbx.h++:3212
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3957
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:5441
cursor_managed(cursor_managed &&)=default
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++:3684
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5220
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++:5280
ptrdiff_t distance_to(const cursor to, unsigned deepness=42) const
Definition mdbx.h++:5308
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5182
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:5179
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:5346
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3680
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:3204
friend constexpr bool operator!=(const cache_entry &a, const cache_entry &b) noexcept
Definition mdbx.h++:3046
static env_managed open_for_recovery(const char *pathname, unsigned target_meta, bool writeable, unsigned max_maps=2)
Opens an environment instance using a specific meta-page for checking and recovery.
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:4533
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:3195
void commit()
Commits all changes of the transaction into a database with collecting latencies information.
move_result to_key_greater_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5197
constexpr bool notfound() const noexcept
Returns true if the entry caches the "key not found" state.
Definition mdbx.h++:3028
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3764
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:4781
env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
static env_managed open_for_recovery(const ::std::wstring &pathname, unsigned target_meta, bool writeable, unsigned max_maps=2)
void copy(const wchar_t *destination, bool compactify, bool force_dynamic_size=false)
Copy an MVCC-snapshot of the database to the destination path.
friend int compare_position(const cursor &left, const cursor &right, bool ignore_nested)
Definition mdbx.h++:7662
void copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size=false)
Copy an MVCC-snapshot of the database to the destination path.
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4840
bool checkpoint()
Commits all the operations of the transaction and immediately starts next without releasing any locks...
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++:3691
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++:4614
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:3192
bool checkpoint(finalization_latency *latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
void commit_embark_read(finalization_latency &latency)
Commits all the operations of a transaction into the database and then start read transaction.
Definition mdbx.h++:4923
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++:4832
finalization_latency commit_embark_read_get_latency()
Commits all the operations of a transaction into the database and then start read transaction.
Definition mdbx.h++:4926
void commit(finalization_latency *)
Commits all changes of the transaction into a database with collecting latencies information.
friend constexpr bool operator>(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:3198
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++:5232
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4998
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:5013
@ multi_exactkey_value_equal
Definition mdbx.h++:5030
@ pair_greater_or_equal
Definition mdbx.h++:5038
@ key_lesser_than
Definition mdbx.h++:5020
@ next
Definition mdbx.h++:5001
@ pair_exact
Definition mdbx.h++:5037
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:5031
@ pair_lesser_or_equal
Definition mdbx.h++:5035
@ batch_samelength
Definition mdbx.h++:5041
@ seek_key
Definition mdbx.h++:5015
@ key_lowerbound
Definition mdbx.h++:5017
@ pair_lesser_than
Definition mdbx.h++:5034
@ pair_equal
Definition mdbx.h++:5036
@ key_greater_than
Definition mdbx.h++:5024
@ batch_samelength_next
Definition mdbx.h++:5042
@ multi_find_pair
Definition mdbx.h++:5012
@ key_greater_or_equal
Definition mdbx.h++:5023
@ key_exact
Definition mdbx.h++:5016
@ key_equal
Definition mdbx.h++:5022
@ multi_currentkey_prevvalue
Definition mdbx.h++:5007
@ key_lesser_or_equal
Definition mdbx.h++:5021
@ multi_nextkey_firstvalue
Definition mdbx.h++:5010
@ get_current
Definition mdbx.h++:5003
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:5029
@ multi_prevkey_lastvalue
Definition mdbx.h++:5005
@ previous
Definition mdbx.h++:5002
@ last
Definition mdbx.h++:5000
@ pair_greater_than
Definition mdbx.h++:5039
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:5028
@ multi_currentkey_firstvalue
Definition mdbx.h++:5006
@ first
Definition mdbx.h++:4999
@ batch_samelength_previous
Definition mdbx.h++:5043
@ multi_currentkey_nextvalue
Definition mdbx.h++:5008
@ seek_and_batch_samelength
Definition mdbx.h++:5044
@ multi_exactkey_value_greater
Definition mdbx.h++:5032
@ multi_currentkey_lastvalue
Definition mdbx.h++:5009
finalization_latency commit_get_latency()
Commits all changes of the transaction into a database and return latency information.
Definition mdbx.h++:4898
friend constexpr bool operator==(const cache_entry &a, const cache_entry &b) noexcept
Definition mdbx.h++:3042
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:5156
void insert(const pair &kv)
Definition mdbx.h++:5371
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:4440
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++:5373
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:5168
constexpr const MDBX_txn * handle() const noexcept
Definition mdbx.h++:4418
bool is_cooperative() const
Definition mdbx.h++:3788
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:4634
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5207
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++:5175
bool is_readonly() const
Definition mdbx.h++:3784
value_result try_insert(const pair &kv)
Definition mdbx.h++:5372
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++:5433
constexpr cursor() noexcept=default
bool is_exclusive() const
Definition mdbx.h++:3786
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5185
finalization_latency abort_get_latency()
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4884
constexpr MDBX_cursor * handle() noexcept
Definition mdbx.h++:4961
bool is_readwrite() const
Definition mdbx.h++:3792
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5229
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3688
MDBX_cursor * handle_
Definition mdbx.h++:4945
static MDBX_NODISCARD info get_preopen_snapinfo(const wchar_t *pathname)
MDBX_dbi dbi
Definition mdbx.h++:3179
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:5201
friend constexpr bool operator!=(const env &a, const env &b) noexcept
Definition mdbx.h++:3267
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:5172
intptr_t page_size
The size of a memory page in bytes.
Definition mdbx.h++:3600
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:4454
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++:5213
ptrdiff_t distance_from(const cursor from, unsigned deepness=42) const
Definition mdbx.h++:5304
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3736
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3686
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:4783
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:4782
virtual ~env_managed()
env_managed(const ::mdbx::filesystem::path &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
Create new or open existing database.
txn_managed start_nested(bool readonly)
Start nested transaction.
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++:4642
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:5188
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++:5161
friend class txn
Definition mdbx.h++:3247
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4972
friend constexpr bool operator==(const txn &a, const txn &b) noexcept
Definition mdbx.h++:4420
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3682
size_t size_current() const
Returns current write transaction size (i.e. summary volume of dirty pages) in bytes.
Definition mdbx.h++:4457
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:5101
Cache entry for the transparent read-your-writes caching, see txn::get_cached() and mdbx_cache_get().
Definition mdbx.h++:3011
Unmanaged cursor.
Definition mdbx.h++:4943
Managed cursor.
Definition mdbx.h++:5453
Unmanaged database environment.
Definition mdbx.h++:3246
Managed database environment.
Definition mdbx.h++:4217
Unmanaged database transaction.
Definition mdbx.h++:4401
Managed database transaction.
Definition mdbx.h++:4858
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:3093
int setup_debug_nofmt(MDBX_log_level_t log_level, MDBX_debug_flags_t debug_flags, MDBX_debug_func_nofmt logger, char *logger_buffer, size_t logger_buffer_size)
Sets up the global log-level, debug options and a logger for plain preformatted messages.
Definition mdbx.h++:4385
inline ::std::string ratio2percents(uint64_t value, uint64_t whole)
Converts a fraction to a percentage string without using floating-point operations.
Definition mdbx.h++:4355
env_managed::create_parameters create_parameters
Shorthand for env_managed::create_parameters.
Definition mdbx.h++:4344
::MDBX_cmp_func comparator
Definition mdbx.h++:3224
inline ::std::string ratio2digits(uint64_t numerator, uint64_t denominator, int precision)
Converts a fraction to a string of decimal digits without using floating-point operations.
Definition mdbx.h++:4348
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:3086
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:3090
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:3074
bool is_readahead_reasonable(size_t volume, intptr_t redundancy)
Quickly finds out whether readahead is reasonable for the given data volume and redundancy.
Definition mdbx.h++:4362
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:3154
MDBX_cmp_func get_datacmp(MDBX_db_flags_t flags)
Returns the built-in data (value) comparator for the given table flags, which is useful as a fallback...
Definition mdbx.h++:4369
int setup_debug(MDBX_log_level_t log_level=MDBX_LOG_DONTCHANGE, MDBX_debug_flags_t debug_flags=MDBX_DBG_DONTCHANGE, MDBX_debug_func logger=nullptr)
Sets up the global log-level, debug options and logger.
Definition mdbx.h++:4375
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:3082
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:3225
env::operate_options operate_options
Shorthand for env::operate_options.
Definition mdbx.h++:4340
put_mode
Key-value pairs put mode.
Definition mdbx.h++:3233
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:3055
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:3058
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:3078
env::operate_parameters operate_parameters
Shorthand for env::operate_parameters.
Definition mdbx.h++:4342
void set_panic(MDBX_panic_func func)
Sets a callback for assertion failures, called before printing the message and aborting.
Definition mdbx.h++:4392
env::reclaiming_options reclaiming_options
Shorthand for env::reclaiming_options.
Definition mdbx.h++:4338
env::geometry geometry
Shorthand for env::geometry.
Definition mdbx.h++:4336
@ multi_reverse_samelength
Definition mdbx.h++:3126
@ multi_samelength
Definition mdbx.h++:3111
@ multi_ordinal
Definition mdbx.h++:3118
@ msgpack
Definition mdbx.h++:3141
@ single
Definition mdbx.h++:3094
@ multi
Definition mdbx.h++:3096
@ multi_reverse
Definition mdbx.h++:3103
@ upsert
Insert or update.
Definition mdbx.h++:3235
@ update
Update existing, don't insert new.
Definition mdbx.h++:3236
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:3234
@ continue_loop
Definition mdbx.h++:3055
@ exit_loop
Definition mdbx.h++:3055
@ usual
Definition mdbx.h++:3059
@ ordinal
Definition mdbx.h++:3064
@ reverse
Definition mdbx.h++:3061
@ msgpack
Definition mdbx.h++:3069
Information about the system RAM, see mdbx_get_sysraminfo().
Definition mdbx.h++:3599
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:3178
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2611
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2291
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++:2149
void resize(size_t size, byte value)
Resizes the buffer to contain size bytes, filling the added space with value. STL-compatible counterp...
Definition mdbx.h++:2255
modality
Data storage modality.
Definition mdbx.h++:1724
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2179
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:697
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2264
constexpr allocator_type get_allocator() const
Definition mdbx.h++:2129
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:711
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:673
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++:2447
void reserve_tailroom(size_t wanna_tailroom)
Definition mdbx.h++:2496
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:664
const slice source
Definition mdbx.h++:1395
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base58 dump, and therefore can be decoded wit...
static buffer key_from(const double *ieee754_64bit)
Definition mdbx.h++:2869
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++:2396
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:733
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:2195
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2531
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2192
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2620
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2471
constexpr size_t tailroom() const noexcept
Returns the number of bytes that available in currently allocated storage after the data.
Definition mdbx.h++:2167
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2330
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2591
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2493
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2186
buffer & append(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:2650
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2335
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2901
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1710
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1113
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1371
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2536
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2225
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2758
buffer & append(const byte c)
Definition mdbx.h++:2695
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2509
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:751
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1094
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2514
buffer & operator=(const buffer &src)
Definition mdbx.h++:2637
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1112
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2780
constexpr size_t headroom() const noexcept
Returns the number of bytes available in the currently allocated storage in front of the data.
Definition mdbx.h++:2162
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2943
constexpr int64_t as_int64() const
Definition mdbx.h++:1119
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2212
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2859
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++:2378
const bool ignore_spaces
Definition mdbx.h++:1475
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:855
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++:2460
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++:2454
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2373
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2705
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2416
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++:1182
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Definition mdbx.h++:768
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2912
constexpr int16_t as_int16() const
Definition mdbx.h++:1121
slice value
Definition mdbx.h++:1146
::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++:2914
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2616
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++:2440
constexpr buffer(const ::std::basic_string< CHAR, T, A > &&str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2319
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2879
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1342
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++:2466
static constexpr buffer invalid() noexcept
Builds an invalid buffer that has a non-zero length and refers to a null address.
Definition mdbx.h++:2370
slice value
Definition mdbx.h++:1160
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2905
::std::ostream & output(::std::ostream &out) const
Output hexadecimal dump of passed slice to the std::ostream.
pair_result(const pair_result &) noexcept=default
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2885
const slice source
Definition mdbx.h++:1474
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2923
const slice source
Definition mdbx.h++:1309
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++:2404
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++:1457
const unsigned wrap_width
Definition mdbx.h++:1311
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2646
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2865
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:725
const slice & slice() const noexcept
Definition mdbx.h++:2897
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2599
const bool ignore_spaces
Definition mdbx.h++:1441
constexpr POD as_pod() const
Definition mdbx.h++:1096
constexpr buffer & assign(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2568
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++:1209
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++:1542
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2918
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2587
constexpr buffer(const buffer &src)
Definition mdbx.h++:2301
constexpr slice substr(size_t pos, size_t count=npos) const
Returns a sub-slice of [pos, pos+count) clamped to the end.
Definition mdbx.h++:981
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++:2433
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1109
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2238
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2871
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2523
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1312
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2920
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2754
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2851
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1675
constexpr byte * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2232
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2346
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:747
std::pair< slice, slice > stl_pair
Definition mdbx.h++:1159
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2778
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:2144
constexpr const byte * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2215
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
typename silo::copy_assign_alloc copy_assign_alloc
Definition mdbx.h++:2124
@ pettiness_threshold
Definition mdbx.h++:1664
@ extra_inplace_storage
Definition mdbx.h++:1662
@ max_reserve
Definition mdbx.h++:1665
@ inplace_storage_size_rounding
Definition mdbx.h++:1663
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2883
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:687
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1476
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2641
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2750
constexpr int8_t as_int8() const
Definition mdbx.h++:1122
constexpr ::std::span< char > chars()
Definition mdbx.h++:699
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1141
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1414
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2286
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++:1668
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1385
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++:1533
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:1148
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2863
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1503
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2428
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2341
const slice source
Definition mdbx.h++:1352
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:1162
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2605
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++:2133
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2887
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:698
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1516
buffer_pair_spec & operator=(buffer_pair_spec &&src)
Definition mdbx.h++:2947
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2813
constexpr void swap(slice &other) noexcept
Definition mdbx.h++:863
typename silo::swap_alloc swap_alloc
Definition mdbx.h++:2125
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2314
bool is_erroneous() const noexcept
Checks whether the content of the passed slice could be encoded; this encoder always returns false.
Definition mdbx.h++:1346
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1711
uint8_t as_uint8_adapt() const
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:678
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2877
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2283
void reserve(size_t size)
Reserves storage space for at least size bytes of payload, without changing the current length....
Definition mdbx.h++:2501
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2643
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2963
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2722
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2801
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2762
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++:1493
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:730
constexpr ::std::basic_string_view< CHAR, T > string_view() const noexcept
Return a string_view that references the same data as this slice.
Definition mdbx.h++:755
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1464
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:643
@ npos
Definition mdbx.h++:643
pair & operator=(pair &&couple) noexcept
Definition mdbx.h++:1166
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++:2411
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2893
slice inherited
Definition mdbx.h++:1704
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:1210
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1442
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2889
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++:2891
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2503
static constexpr pair invalid() noexcept
Definition mdbx.h++:1175
typename silo::move_assign_alloc move_assign_alloc
Definition mdbx.h++:2123
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2272
constexpr bool contains(const slice &needle) const noexcept
Checks whether the referenced data contains needle as a sub-slice.
Definition mdbx.h++:1028
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2595
bool done
Definition mdbx.h++:1208
::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 could be encoded; always returns false for the Base58 en...
Definition mdbx.h++:1389
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:696
constexpr intptr_t compare(const slice &other) const noexcept
Lexicographical three-way comparison with another slice.
Definition mdbx.h++:1033
constexpr const void * const_end() const noexcept
Definition mdbx.h++:2221
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:713
const bool uppercase
Definition mdbx.h++:1310
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2199
constexpr byte front() const noexcept
Returns the first byte of the referenced data.
Definition mdbx.h++:973
void clear_and_reserve(size_t whole_capacity, size_t headroom=0)
Clears the contents and reserve storage.
Definition mdbx.h++:2668
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2550
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2703
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2766
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2931
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2206
const bool ignore_spaces
Definition mdbx.h++:1515
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1398
pair(const pair &) noexcept=default
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2845
static constexpr slice invalid() noexcept
Builds an invalid slice that has a non-zero length and refers to a null address.
Definition mdbx.h++:1089
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base64 dump, and therefore can be decoded wit...
slice & operator=(const slice &) noexcept=default
uint128_t as_uint128_adapt() const
constexpr int128_t as_int128() const
Definition mdbx.h++:1117
slice key
Definition mdbx.h++:1160
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2678
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:1161
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2937
const slice source
Definition mdbx.h++:1514
pair_result & operator=(const pair_result &) noexcept=default
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2673
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1431
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2895
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2665
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2903
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++:1120
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++:2390
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2305
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1706
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2867
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2172
constexpr modality content_modality() const noexcept
Returns current modality of buffer content.
Definition mdbx.h++:2152
constexpr const void * const_data() const noexcept
Definition mdbx.h++:2218
pair & operator=(const stl_pair &couple)
Definition mdbx.h++:1177
int64_t as_int64_adapt() const
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2875
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2175
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++:2385
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2527
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2929
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1114
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2904
void resize(size_t size)
Resizes the buffer to contain size bytes, filling the added space with zeroes. STL-compatible counter...
Definition mdbx.h++:2251
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2326
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:2126
buffer & append(const ::std::basic_string< CHAR, T, A > &str)
Definition mdbx.h++:2660
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2770
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2790
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1111
constexpr byte back() const noexcept
Returns the last byte of the referenced data.
Definition mdbx.h++:977
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2925
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2873
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid hexadecimal dump, and therefore can be decode...
buffer encode_base58(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2423
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2827
const unsigned wrap_width
Definition mdbx.h++:1353
buffer & append_hex(const struct slice &data, bool uppercase=false, unsigned wrap_width=0)
Definition mdbx.h++:2746
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2366
const unsigned wrap_width
Definition mdbx.h++:1396
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2639
uint32_t as_uint32_adapt() const
constexpr bool is_valid() const noexcept
Checks the slice is valid: returns false only if it has a null data pointer and a non-zero length.
Definition mdbx.h++:1085
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++:2724
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2940
buffer_pair_spec(const txn &transaction, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2934
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++:705
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2735
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2309
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2856
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2902
bool is_erroneous() const noexcept
Checks whether the content of the passed slice could be encoded; this encoder always returns false.
Definition mdbx.h++:1435
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++:1355
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2297
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:708
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for hexadecimal dump of a passed slice.
Definition mdbx.h++:1327
buffer(buffer &&src) noexcept(::std::is_nothrow_move_constructible< allocator_type >::value)
Definition mdbx.h++:2354
bool done
Definition mdbx.h++:1147
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++:1440
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:2157
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2243
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1702
inline ::std::string dump_val(const slice &value)
Dumps the given value to a string: as-is when printable (all bytes in the range 0x20....
Definition mdbx.h++:1263
uint64_t key_from_jsonInteger(int64_t json_integer) noexcept
Value-to-Key functions to avoid using custom comparators.
Definition mdbx.h++:1226
uint64_t key_from_int64(int64_t i64) noexcept
Definition mdbx.h++:1242
float float_from_key(const slice &key) noexcept
Definition mdbx.h++:1250
uint64_t key_from_double(double ieee754_64bit) noexcept
Definition mdbx.h++:1230
int64_t jsonInteger_from_key(const slice &key) noexcept
Definition mdbx.h++:1256
uint32_t key_from_float(float ieee754_32bit) noexcept
Definition mdbx.h++:1236
int64_t int64_from_key(const slice &key) noexcept
Definition mdbx.h++:1254
uint32_t key_from_ptrfloat(const float *const ieee754_32bit) noexcept
Definition mdbx.h++:1238
uint64_t key_from_ptrdouble(const double *const ieee754_64bit) noexcept
Definition mdbx.h++:1232
double double_from_key(const slice &key) noexcept
Key-to-Value functions to avoid using custom comparators.
Definition mdbx.h++:1248
uint32_t key_from_int32(int32_t i32) noexcept
Definition mdbx.h++:1244
int32_t int32_from_key(const slice &key) noexcept
Definition mdbx.h++:1252
Definition mdbx.h++:2900
Type tag for delivered buffer template classes.
Definition mdbx.h++:1698
Definition mdbx.h++:1660
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1473
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1513
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1439
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:1158
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:1207
References a data located outside the slice.
Definition mdbx.h++:638
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1351
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1394
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1308
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:1145
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:555
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++:5571
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
Panics on unrecoverable errors inside destructors etc.
fatal(const exception &src) noexcept
Definition mdbx.h++:554
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 &)
static void success_or_throw(int error_code)
Definition mdbx.h++:525
laggard_reader(const ::mdbx::error &)
db_full(const ::mdbx::error &)
duplicated_lck_file(const ::mdbx::error &)
const ::mdbx::error error() const noexcept
Definition mdbx.h++:545
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++:556
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++:557
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++:5569
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++:487
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:472
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:563
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:5042
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:5046
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition mdbx.h++:195
#define MDBX_MSVC_DECLSPEC_EMPTY_BASES
Definition mdbx.h++:138
#define MDBX_CXX17_FALLTHROUGH
Definition mdbx.h++:237
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:286
#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES,...)
Definition mdbx.h++:128
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:205
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:184
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:223
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:228
#define MDBX_NODISCARD
Definition mdbx.h++:259
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:204
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:243
The libmdbx C API header file.
Definition mdbx.h++:1550
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1552
The libmdbx C++ API namespace.
Definition mdbx.h++:319
STL namespace.
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:8049
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1803
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1805
byte lastbyte_
Definition mdbx.h++:1804
Definition mdbx.h++:5063
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:5065
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:5064
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:5067
Definition mdbx.h++:5051
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++:5055
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:5053
Tagged type for output to std::ostream.
Definition mdbx.h++:3300
intptr_t bytes
Definition mdbx.h++:3301
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3302
Database geometry for size management.
Definition mdbx.h++:3276
constexpr geometry(const geometry &) noexcept=default
static constexpr geometry fixed(intptr_t size) noexcept
Creates a fixed-size geometry, i.e. with disabled growing and shrinking.
Definition mdbx.h++:3365
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3324
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3336
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3283
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3279
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3282
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3291
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3280
@ default_value
Means "keep current or use default".
Definition mdbx.h++:3278
@ kB
bytes (0x03E8)
Definition mdbx.h++:3281
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3290
@ KiB
bytes (0x0400)
Definition mdbx.h++:3289
constexpr geometry() noexcept
Definition mdbx.h++:3354
constexpr geometry & operator=(const geometry &) noexcept=default
static constexpr geometry dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Creates a dynamic-size geometry with the given bounds.
Definition mdbx.h++:3370
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3327
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3312
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3330
constexpr bool operator==(const geometry &other) const noexcept
Definition mdbx.h++:3379
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3307
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++:3358
constexpr bool operator!=(const geometry &other) const noexcept
Definition mdbx.h++:3384
Operate options.
Definition mdbx.h++:3428
bool disable_readahead
Definition mdbx.h++:3437
bool enable_validation
Definition mdbx.h++:3441
bool no_sticky_threads
Definition mdbx.h++:3430
constexpr operate_options() noexcept
Definition mdbx.h++:3442
bool disable_clear_memory
Definition mdbx.h++:3439
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3435
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
constexpr bool operator==(const operate_options &other) const noexcept
Definition mdbx.h++:3463
bool nested_transactions
Enables nested transactions at the cost of disabling MDBX_WRITEMAP and increasing overhead.
Definition mdbx.h++:3433
constexpr bool operator!=(const operate_options &other) const noexcept
Definition mdbx.h++:3468
Operate parameters.
Definition mdbx.h++:3475
env::durability durability
Definition mdbx.h++:3483
static MDBX_NODISCARD env::durability durability_from_flags(MDBX_env_flags_t) noexcept
env::operate_options options
Definition mdbx.h++:3485
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++:3489
constexpr operate_parameters & operator=(const operate_parameters &) noexcept=default
static MDBX_NODISCARD env::mode mode_from_flags(MDBX_env_flags_t) noexcept
unsigned max_readers
The maximum number of threads/reader slots for the environment. Zero means default value.
Definition mdbx.h++:3481
constexpr operate_parameters(const operate_parameters &) noexcept=default
MDBX_NODISCARD MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
constexpr bool operator==(const operate_parameters &other) const noexcept
Definition mdbx.h++:3559
env::reclaiming_options reclaiming
Definition mdbx.h++:3484
env::mode mode
Definition mdbx.h++:3482
unsigned max_maps
The maximum number of named tables/maps for the environment. Zero means default value.
Definition mdbx.h++:3478
constexpr operate_parameters() noexcept
Definition mdbx.h++:3487
constexpr bool operator!=(const operate_parameters &other) const noexcept
Definition mdbx.h++:3563
Reader information.
Definition mdbx.h++:3980
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3983
uint64_t transaction_lag
Definition mdbx.h++:3986
size_t bytes_used
Definition mdbx.h++:3990
uint64_t transaction_id
Definition mdbx.h++:3984
int slot
The reader lock table slot number.
Definition mdbx.h++:3981
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3982
size_t bytes_retained
Definition mdbx.h++:3993
Garbage reclaiming options.
Definition mdbx.h++:3405
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
constexpr bool operator!=(const reclaiming_options &other) const noexcept
Definition mdbx.h++:3421
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr bool operator==(const reclaiming_options &other) const noexcept
Definition mdbx.h++:3418
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3408
bool lifo
Definition mdbx.h++:3407
Additional parameters for creating a new database.
Definition mdbx.h++:4240
constexpr bool operator==(const create_parameters &other) const noexcept
Definition mdbx.h++:4257
mdbx_mode_t file_mode_bits
Definition mdbx.h++:4242
constexpr create_parameters() noexcept=default
constexpr bool operator!=(const create_parameters &other) const noexcept
Definition mdbx.h++:4261
bool use_subdirectory
Definition mdbx.h++:4243
env::geometry geometry
Definition mdbx.h++:4241
Definition mdbx.h++:3213
map_handle::state state
Definition mdbx.h++:3215
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:3214
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:8154
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:8150
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:8149
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:8140
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:8139
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:8135
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:8131
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:8144
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:8145
capacity_holder capacity_
Definition mdbx.h++:1809
allocator_pointer stub_ptr_
Definition mdbx.h++:1784
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1821
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1854
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1813
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1828
inplace_flag_holder inplace_
Definition mdbx.h++:1810
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1812
allocator_pointer allocated_ptr_
Definition mdbx.h++:1808
size_t stub_capacity_bytes_
Definition mdbx.h++:1785
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1873
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1798
size_t bytes_
Definition mdbx.h++:1799
constexpr const byte * address() const noexcept
Definition mdbx.h++:1867
constexpr bin() noexcept
Definition mdbx.h++:1848
@ inplace_size
Definition mdbx.h++:1793
@ inplace_signature_limit
Definition mdbx.h++:1790
@ inplace_size_rounding
Definition mdbx.h++:1792
constexpr byte * address() noexcept
Definition mdbx.h++:1870
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1839
@ lastbyte_poison
Definition mdbx.h++:1788
@ lastbyte_inplace_signature
Definition mdbx.h++:1788
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1863
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1830