libmdbx 0.14.3.8 (2026-08-12T00:57:40+03:00)
One of the fastest compact embeddable key-value ACID storage engine without WAL.
Loading...
Searching...
No Matches
mdbx.h++
Go to the documentation of this file.
1
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_EXPERIMETAL_FILESYSTEM
96#ifdef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
97#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
98#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && __cplusplus >= 201703L
99#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
100#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
101 (defined(_MSC_VER) && defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && __cplusplus >= 201403L))
102#if defined(__cpp_lib_experimental_filesystem) && __cpp_lib_experimental_filesystem >= 201406L
103#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
104#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && __has_include(<experimental/filesystem>)
105#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
106#else
107#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
108#endif
109#else
110#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
111#endif
112#endif /* MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM */
113
114#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
115#include <experimental/filesystem>
116#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
117#include <filesystem>
118#endif
119
120#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
121#include <span>
122#endif
123
124#if !defined(_MSC_VER) || defined(__clang__)
125#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class API_ATTRIBUTES __VA_ARGS__
126#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class __VA_ARGS__
127#else
128#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class __VA_ARGS__
129#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class API_ATTRIBUTES __VA_ARGS__
130#endif
131
132#if defined(_MSC_VER) && _MSC_VER >= 1900
133#define MDBX_MSVC_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
134#else
135#define MDBX_MSVC_DECLSPEC_EMPTY_BASES /* nope */
136#endif /* _MSC_VER >= 1900 */
137
138#if __cplusplus >= 201103L
139#include <chrono>
140#include <ratio>
141#endif
142
143#include "mdbx.h"
144
145#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
146 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
147 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
148 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
149#include <bit>
150#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
151#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
152#define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
153#define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
154#define __BYTE_ORDER__ __BYTE_ORDER
155#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
156#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
157#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
158#define __BYTE_ORDER__ _BYTE_ORDER
159#else
160#define __ORDER_LITTLE_ENDIAN__ 1234
161#define __ORDER_BIG_ENDIAN__ 4321
162#if defined(__LITTLE_ENDIAN__) || (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || defined(__ARMEL__) || \
163 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
164 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || defined(__elbrus_4c__) || defined(__elbrus_8c__) || \
165 defined(__bfin__) || defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
166 defined(__ia64) || defined(_M_IA64) || defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
167 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || defined(__WINDOWS__)
168#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
169#elif defined(__BIG_ENDIAN__) || (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || defined(__ARMEB__) || \
170 defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
171 defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
172 defined(__sparc__) || defined(__sparc) || defined(__370__) || defined(__THW_370__) || defined(__s390__) || \
173 defined(__s390x__) || defined(__SYSC_ZARCH__)
174#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
175#endif
176#endif
177#endif /* Byte Order */
178
180#if defined(DOXYGEN)
181#define MDBX_CXX17_CONSTEXPR constexpr
182#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
183 ((defined(_MSC_VER) && _MSC_VER >= 1915) || (defined(__clang__) && __clang_major__ > 5) || \
184 (defined(__GNUC__) && __GNUC__ > 7) || (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
185#define MDBX_CXX17_CONSTEXPR constexpr
186#else
187#define MDBX_CXX17_CONSTEXPR inline
188#endif /* MDBX_CXX17_CONSTEXPR */
189
191#if defined(DOXYGEN)
192#define MDBX_CXX20_CONSTEXPR constexpr
193#elif defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L && \
194 defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
195#define MDBX_CXX20_CONSTEXPR constexpr
196#else
197#define MDBX_CXX20_CONSTEXPR inline
198#endif /* MDBX_CXX20_CONSTEXPR */
199
200#if MDBX_CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
201#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
202#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
203#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
204#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
205#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
206#else
207#define MDBX_CXX01_CONSTEXPR_ENUM inline
208#define MDBX_CXX11_CONSTEXPR_ENUM inline
209#define MDBX_CXX14_CONSTEXPR_ENUM inline
210#define MDBX_CXX17_CONSTEXPR_ENUM inline
211#define MDBX_CXX20_CONSTEXPR_ENUM inline
212#endif /* MDBX_CONSTEXPR_ENUM_FLAGS_OPERATIONS */
213
215#if defined(CONSTEXPR_ASSERT)
216#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
217#elif defined(NDEBUG) && (!defined(MDBX_CHECKING) || !MDBX_CHECKING) && (!defined(MDBX_DEBUG) || !MDBX_DEBUG)
218#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
219#else
220#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
221#endif /* MDBX_CONSTEXPR_ASSERT */
222
224#if defined(DOXYGEN)
225#define MDBX_IF_CONSTEXPR constexpr
226#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
227#define MDBX_IF_CONSTEXPR constexpr
228#else
229#define MDBX_IF_CONSTEXPR
230#endif /* MDBX_IF_CONSTEXPR */
231
232#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
233 __cplusplus >= 201703L
234#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
235#else
236#define MDBX_CXX17_FALLTHROUGH
237#endif /* MDBX_CXX17_FALLTHROUGH */
238
239#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
240#define MDBX_CXX20_LIKELY [[likely]]
241#else
242#define MDBX_CXX20_LIKELY
243#endif /* MDBX_CXX20_LIKELY */
244
245#ifndef MDBX_CXX20_UNLIKELY
246#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
247#define MDBX_CXX20_UNLIKELY [[unlikely]]
248#else
249#define MDBX_CXX20_UNLIKELY
250#endif
251#endif /* MDBX_CXX20_UNLIKELY */
252
253#ifndef MDBX_HAVE_CXX20_CONCEPTS
254#if defined(__cpp_concepts) && __cpp_concepts >= 202002L && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
255#include <concepts>
256#define MDBX_HAVE_CXX20_CONCEPTS 1
257#elif defined(DOXYGEN)
258#define MDBX_HAVE_CXX20_CONCEPTS 1
259#else
260#define MDBX_HAVE_CXX20_CONCEPTS 0
261#endif /* <concepts> */
262#endif /* MDBX_HAVE_CXX20_CONCEPTS */
263
264#ifndef MDBX_CXX20_CONCEPT
265#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
266#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
267#else
268#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
269#endif
270#endif /* MDBX_CXX20_CONCEPT */
271
272#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
273#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
274#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
275#else
276#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
277 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
278#endif
279#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
280
281#ifdef _MSC_VER
282#pragma warning(push, 4)
283#pragma warning(disable : 4127) /* conditional expression is constant */
284#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
285 be used by clients of 'mdbx::BAR' */
286#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
287 base for dll-interface 'mdbx::BAR' */
288/* MSVC is mad and can generate this warning for its own intermediate
289 * automatically generated code, which becomes unreachable after some kinds of
290 * optimization (copy elision, etc). */
291#pragma warning(disable : 4702) /* unreachable code */
292#endif /* _MSC_VER (warnings) */
293
294#if defined(__LCC__) && __LCC__ >= 126
295#pragma diagnostic push
296#if __LCC__ < 127
297#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
298 appearing in a constant expression `true` */
299#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
300 appearing in a constant expression `false` */
301#endif
302#endif /* E2K LCC (warnings) */
303
304//------------------------------------------------------------------------------
307namespace mdbx {
308
311
329#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
330using byte = char8_t;
331#else
332// Avoid `std::byte` since it doesn't add features but inconvenient restrictions.
333using byte = unsigned char;
334#endif /* __cpp_char8_t >= 201811*/
335
336#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
337using endian = ::std::endian;
338#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
339enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
340#else
341#error "Please use a C++ compiler provides byte order information or C++20 support"
342#endif /* Byte Order enum */
343
352
354static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
355
357static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
359static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
360
363using legacy_allocator = ::std::string::allocator_type;
364
367#if defined(DOXYGEN)
368#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
369#elif !defined(MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR)
370#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && \
371 (!defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI)
372#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
373#else
374#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 0
375#endif
376#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
377
378#if defined(DOXYGEN) || MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
380using polymorphic_allocator = ::std::pmr::string::allocator_type;
382#else
384#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
385
386struct slice;
388template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
390class env;
391class env_managed;
392class txn;
393class txn_managed;
394class cursor;
395class cursor_managed;
396
398using txnid = uint64_t;
399
401template <class ALLOCATOR = default_allocator>
402using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
403
405#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
406#ifdef _MSC_VER
407namespace filesystem = ::std::experimental::filesystem::v1;
408#else
409namespace filesystem = ::std::experimental::filesystem;
410#endif
411#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
412#elif defined(DOXYGEN) || \
413 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
414 __cpp_lib_string_view >= 201606L && \
415 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
416 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
417 (!defined(_MSC_VER) || __cplusplus >= 201703L)
418namespace filesystem = ::std::filesystem;
424#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
425#endif /* MDBX_STD_FILESYSTEM_PATH */
426
427#ifdef MDBX_STD_FILESYSTEM_PATH
429using path_string = MDBX_STD_FILESYSTEM_PATH::string_type;
430#elif defined(_WIN32) || defined(_WIN64)
431using path = ::std::wstring;
432using path_string = path;
433#else
434using path = ::std::string;
435using path_string = path;
436#endif /* mdbx::path */
437using path_char = path_string::value_type;
438
439#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
440#ifndef MDBX_U128_TYPE
441#define MDBX_U128_TYPE __uint128_t
442#endif /* MDBX_U128_TYPE */
443#ifndef MDBX_I128_TYPE
444#define MDBX_I128_TYPE __int128_t
445#endif /* MDBX_I128_TYPE */
446#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
447
448#if __cplusplus >= 201103L || defined(DOXYGEN)
450using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
451#endif /* Duration for C++11 */
452
455
461 ::std::exception_ptr captured_;
462
463public:
464 exception_thunk() noexcept = default;
467 exception_thunk &operator=(const exception_thunk &) = delete;
468 exception_thunk &operator=(exception_thunk &&) = delete;
469 inline bool is_clean() const noexcept;
470 inline void capture() noexcept;
471 inline void rethrow_captured() const;
472};
473
476 MDBX_error_t code_;
477 inline error &operator=(MDBX_error_t error_code) noexcept;
478
479public:
480 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
481 error(const error &) = default;
482 error(error &&) = default;
483 error &operator=(const error &) = default;
484 error &operator=(error &&) = default;
485
486 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
487 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
488
489 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
490 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
491 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
492 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
493
495 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
496
498 const char *what() const noexcept;
499
501 ::std::string message() const;
502
504 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
506 [[noreturn]] void throw_exception() const;
507 [[noreturn]] static inline void throw_exception(int error_code);
508 inline void throw_on_failure() const;
509 inline void success_or_throw() const;
510 inline void success_or_throw(const exception_thunk &) const;
511 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
512 static inline void success_or_throw(MDBX_error_t error_code);
513 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
514 static inline void throw_on_failure(int error_code);
515 static inline bool boolean_or_throw(int error_code);
516 static inline void success_or_throw(int error_code, const exception_thunk &);
517 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
518};
519
522class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
523 using base = ::std::runtime_error;
524 ::mdbx::error error_;
525
526public:
527 exception(const ::mdbx::error &) noexcept;
528 exception(const exception &) = default;
529 exception(exception &&) = default;
530 exception &operator=(const exception &) = default;
532 virtual ~exception() noexcept;
533 const ::mdbx::error error() const noexcept { return error_; }
534};
535
538 using base = exception;
539
540public:
541 fatal(const ::mdbx::error &) noexcept;
542 fatal(const exception &src) noexcept : fatal(src.error()) {}
543 fatal(exception &&src) noexcept : fatal(src.error()) {}
544 fatal(const fatal &src) noexcept : fatal(src.error()) {}
545 fatal(fatal &&src) noexcept : fatal(src.error()) {}
546 fatal &operator=(fatal &&) = default;
547 fatal &operator=(const fatal &) = default;
548 virtual ~fatal() noexcept;
549};
550
551#define MDBX_DECLARE_EXCEPTION(NAME) \
552 struct LIBMDBX_API_TYPE NAME : public exception { \
553 NAME(const ::mdbx::error &); \
554 virtual ~NAME() noexcept; \
555 }
589#undef MDBX_DECLARE_EXCEPTION
590
593[[noreturn]] LIBMDBX_API void throw_out_range();
597
598static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
599 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
600 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
601 return bytes;
602}
603
604static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
605 return check_length(check_length(headroom) + check_length(payload));
606}
607
608MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
609 return check_length(check_length(headroom, payload) + check_length(tailroom));
610}
611
613
614//------------------------------------------------------------------------------
615
618
630
631 enum : size_t { max_length = MDBX_MAXDATASIZE };
632
634 MDBX_CXX11_CONSTEXPR slice() noexcept;
635
637 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
638
640 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
641
643 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
644 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
645 }
646
647 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
648
651 template <class CHAR, class T, class A>
652 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
653 : slice(str.data(), str.length() * sizeof(CHAR)) {}
654
656 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
658 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
659
660#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
661 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
662 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
663 "Must be a standard layout type!");
664 }
665
666 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
667 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
668 "Must be a standard layout type!");
669 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
671 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
673 }
674
675 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
676 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
677 "Must be a standard layout type!");
678 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
680 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
682 }
683
684 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
685 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
686 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
687 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
688#endif /* __cpp_lib_span >= 202002L */
689
690#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
692 template <class CHAR, class T>
693 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv)
694 : slice(sv.data(), sv.size() * sizeof(CHAR)) {}
695
696 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
697#endif /* __cpp_lib_string_view >= 201606L */
698
699 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
700
701 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
702 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
703 "Must be a standard layout type!");
704 return slice(&pod, sizeof(pod));
705 }
706
707 inline slice &assign(const void *ptr, size_t bytes);
708 inline slice &assign(const slice &src) noexcept;
709 inline slice &assign(const ::MDBX_val &src);
710 inline slice &assign(slice &&src) noexcept;
711 inline slice &assign(::MDBX_val &&src);
712 inline slice &assign(const void *begin, const void *end);
713 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
714 return assign(str.data(), str.size() * sizeof(CHAR));
715 }
716 inline slice &assign(const char *c_str);
717#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
718 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
719 return assign(view.data(), view.size() * sizeof(CHAR));
720 }
721 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
722 assign(view);
723 view = {};
724 return *this;
725 }
726#endif /* __cpp_lib_string_view >= 201606L */
727
728 slice &operator=(const slice &) noexcept = default;
729 inline slice &operator=(slice &&src) noexcept;
730 inline slice &operator=(::MDBX_val &&src);
731 operator MDBX_val *() noexcept { return this; }
732 operator const MDBX_val *() const noexcept { return this; }
733
734#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
735 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
736 return assign(view);
737 }
738
739 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
740
742 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
743 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
744 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
745 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
746 }
747
749 template <class CHAR, class T>
750 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
751 return this->string_view<CHAR, T>();
752 }
753#endif /* __cpp_lib_string_view >= 201606L */
754
755 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
756 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
757 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
758 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
759 }
760
761 template <class CHAR, class T, class ALLOCATOR>
762 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
764 }
765
767 template <class ALLOCATOR = default_allocator>
768 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
769 const ALLOCATOR &alloc = ALLOCATOR()) const;
770
773 template <class ALLOCATOR = default_allocator>
774 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
775
778 template <class ALLOCATOR = default_allocator>
779 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
780
782 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
783 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
784 const ALLOCATOR &alloc = ALLOCATOR()) const;
785
788 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
789 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
790 const ALLOCATOR &alloc = ALLOCATOR()) const;
791
794 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
795 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
796 const ALLOCATOR &alloc = ALLOCATOR()) const;
797
799 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
800 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
801 const ALLOCATOR &alloc = ALLOCATOR()) const;
802
805 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
806 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
807 const ALLOCATOR &alloc = ALLOCATOR()) const;
808
811 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
812 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
813 const ALLOCATOR &alloc = ALLOCATOR()) const;
814
820 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
821
826 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
827
833 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
834
840 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
841
842#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
843 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
844 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
845 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
846 *this = view;
847 view = temp;
848 }
849#endif /* __cpp_lib_string_view >= 201606L */
850
851 MDBX_CXX20_CONSTEXPR void swap(slice &other) noexcept {
852 auto temp = other;
853 other = *this;
854 *this = temp;
855 }
856
858 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
859 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
860
862 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
863 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
864
866 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
867 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
868
870 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
871 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
872
874 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
875 MDBX_CXX11_CONSTEXPR void *data() noexcept;
876
878 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
879 MDBX_CXX11_CONSTEXPR void *end() noexcept;
880
882 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
883
885 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
886
888 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
889
891 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
892
894 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
895
897 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
898
900 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
901
903 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
904
906 MDBX_CXX14_CONSTEXPR void clear() noexcept;
907
910 inline void remove_prefix(size_t n) noexcept;
911
914 inline void remove_suffix(size_t n) noexcept;
915
918 inline void safe_remove_prefix(size_t n);
919
922 inline void safe_remove_suffix(size_t n);
923
925 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
926
928 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
929
932 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
933
936 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
937
940 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
941
944 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
945
948 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
949
952 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
953
956 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
957
960 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
961
966 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
967
976 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
977
983 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
984 const slice &b) noexcept;
985 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
986 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
987 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
988 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
989 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
990 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
991#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
992 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
993#endif /* __cpp_impl_three_way_comparison */
994
996 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
997
1000 return slice(/* using special constructor without length checking */ ~size_t(0));
1001 }
1002
1004 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1005
1006 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1007 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1008 "Must be a standard layout type!");
1009 if (MDBX_LIKELY(size() == sizeof(POD)))
1011 POD _as_pod_local;
1012 memcpy(&_as_pod_local, data(), sizeof(_as_pod_local));
1013 return _as_pod_local;
1014 }
1016 }
1017
1018#ifdef MDBX_U128_TYPE
1019 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1020#endif /* MDBX_U128_TYPE */
1021 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1022 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1023 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1024 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1025
1026#ifdef MDBX_I128_TYPE
1027 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1028#endif /* MDBX_I128_TYPE */
1029 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1030 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1031 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1032 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1033
1034#ifdef MDBX_U128_TYPE
1035 MDBX_U128_TYPE as_uint128_adapt() const;
1036#endif /* MDBX_U128_TYPE */
1037 uint64_t as_uint64_adapt() const;
1038 uint32_t as_uint32_adapt() const;
1039 uint16_t as_uint16_adapt() const;
1040 uint8_t as_uint8_adapt() const;
1041
1042#ifdef MDBX_I128_TYPE
1043 MDBX_I128_TYPE as_int128_adapt() const;
1044#endif /* MDBX_I128_TYPE */
1045 int64_t as_int64_adapt() const;
1046 int32_t as_int32_adapt() const;
1047 int16_t as_int16_adapt() const;
1048 int8_t as_int8_adapt() const;
1049
1050protected:
1051 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1052};
1053
1057 bool done;
1058 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
1059 value_result(const value_result &) noexcept = default;
1060 value_result &operator=(const value_result &) noexcept = default;
1061 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1062 MDBX_INLINE_API_ASSERT(!done || value.is_valid());
1063 return done;
1064 }
1065};
1066
1068struct pair {
1069 using stl_pair = std::pair<slice, slice>;
1071 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
1072 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
1073 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
1074 pair(const pair &) noexcept = default;
1075 pair &operator=(const pair &) noexcept = default;
1076 pair &operator=(pair &&couple) noexcept {
1077 key.assign(std::move(couple.key));
1078 value.assign(std::move(couple.value));
1079 return *this;
1080 }
1081 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1082 MDBX_INLINE_API_ASSERT(bool(key) == bool(value));
1083 return key;
1084 }
1086
1087 pair &operator=(const stl_pair &couple) {
1088 key.assign(couple.first);
1089 value.assign(couple.second);
1090 return *this;
1091 }
1093 key.assign(std::move(couple.first));
1094 value.assign(std::move(couple.second));
1095 return *this;
1096 }
1097
1099 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
1100
1102 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
1103 const pair &b) noexcept;
1104 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
1105 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
1106 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
1107 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
1108 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
1109 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
1110#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1111 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
1112#endif /* __cpp_impl_three_way_comparison */
1113};
1114
1117struct pair_result : public pair {
1118 bool done;
1121 : pair(key, value), done(done) {}
1122 pair_result(const pair_result &) noexcept = default;
1123 pair_result &operator=(const pair_result &) noexcept = default;
1124 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1125 MDBX_INLINE_API_ASSERT(!done || (bool(key) && bool(value)));
1126 return done;
1127 }
1128};
1129
1130#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
1131
1135template <typename T>
1136concept MutableByteProducer = requires(T a, char array[42]) {
1137 { a.is_empty() } -> std::same_as<bool>;
1138 { a.envisage_result_length() } -> std::same_as<size_t>;
1139 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1140};
1141
1145template <typename T>
1146concept ImmutableByteProducer = requires(const T &a, char array[42]) {
1147 { a.is_empty() } -> std::same_as<bool>;
1148 { a.envisage_result_length() } -> std::same_as<size_t>;
1149 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1150};
1151
1155template <typename T>
1156concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
1157 T(source);
1158 { a.is_erroneous() } -> std::same_as<bool>;
1159};
1160
1161#endif /* MDBX_HAVE_CXX20_CONCEPTS */
1162
1166 const bool uppercase = false;
1167 const unsigned wrap_width = 0;
1172
1174 template <class ALLOCATOR = default_allocator>
1175 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1176
1178 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1179 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1180
1184 const size_t bytes = source.length() << 1;
1185 return wrap_width ? bytes + bytes / wrap_width : bytes;
1186 }
1187
1190 char *write_bytes(char *dest, size_t dest_size) const;
1191
1194 ::std::ostream &output(::std::ostream &out) const;
1195
1198 bool is_empty() const noexcept { return source.empty(); }
1199
1202 bool is_erroneous() const noexcept { return false; }
1203};
1204
1209 const unsigned wrap_width = 0;
1214
1217 template <class ALLOCATOR = default_allocator>
1218 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1219
1222 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1223 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1224
1228 const size_t bytes = (source.length() * 11 + 7) / 8;
1229 return wrap_width ? bytes + bytes / wrap_width : bytes;
1230 }
1231
1234 char *write_bytes(char *dest, size_t dest_size) const;
1235
1238 ::std::ostream &output(::std::ostream &out) const;
1239
1241 bool is_empty() const noexcept { return source.empty(); }
1242
1244 bool is_erroneous() const noexcept { return false; }
1245};
1246
1251 const unsigned wrap_width = 0;
1256
1259 template <class ALLOCATOR = default_allocator>
1260 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1261
1264 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1265 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1266
1270 const size_t bytes = (source.length() + 2) / 3 * 4;
1271 return wrap_width ? bytes + bytes / wrap_width : bytes;
1272 }
1273
1277 char *write_bytes(char *dest, size_t dest_size) const;
1278
1282 ::std::ostream &output(::std::ostream &out) const;
1283
1286 bool is_empty() const noexcept { return source.empty(); }
1287
1290 bool is_erroneous() const noexcept { return false; }
1291};
1292
1296 const bool ignore_spaces = false;
1301
1303 template <class ALLOCATOR = default_allocator>
1304 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1305
1307 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1308 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1309
1312 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1313
1316 char *write_bytes(char *dest, size_t dest_size) const;
1317
1319 bool is_empty() const noexcept { return source.empty(); }
1320
1323 bool is_erroneous() const noexcept;
1324};
1325
1330 const bool ignore_spaces = false;
1335
1338 template <class ALLOCATOR = default_allocator>
1339 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1340
1343 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1344 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1345
1349 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1350 }
1351
1355 char *write_bytes(char *dest, size_t dest_size) const;
1356
1358 bool is_empty() const noexcept { return source.empty(); }
1359
1362 bool is_erroneous() const noexcept;
1363};
1364
1369 const bool ignore_spaces = false;
1374
1377 template <class ALLOCATOR = default_allocator>
1378 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1379
1382 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1383 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1384
1387 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1388
1392 char *write_bytes(char *dest, size_t dest_size) const;
1393
1396 bool is_empty() const noexcept { return source.empty(); }
1397
1401 bool is_erroneous() const noexcept;
1402};
1403
1405
1406template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1407#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1408 return ::std::allocator_traits<A>::is_always_equal::value;
1409#else
1410 return ::std::is_empty<A>::value;
1411#endif /* __cpp_lib_allocator_traits_is_always_equal */
1412}
1413
1414template <typename T, typename A = typename T::allocator_type,
1415 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1417
1418template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1419 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1420 static constexpr bool is_nothrow() noexcept { return is_always_equal(); }
1421 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1422 if MDBX_IF_CONSTEXPR (is_always_equal())
1423 return true;
1424 else
1425 return target->get_allocator() == source.get_allocator();
1426 }
1427 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &) noexcept { target->release(); }
1428};
1429
1430template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1431 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1432 static constexpr bool is_nothrow() noexcept { return ::std::is_nothrow_move_assignable<A>::value; }
1433 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1434 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1435 target->release();
1436 target->get_allocator() = ::std::move(source.get_allocator());
1437 }
1438};
1439
1440template <typename T, typename A = typename T::allocator_type,
1441 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1443
1444template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1445 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1446 static constexpr bool is_nothrow() noexcept { return false; }
1447 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1448};
1449
1450template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1451 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1452 static constexpr bool is_nothrow() noexcept {
1453 return is_always_equal() || ::std::is_nothrow_copy_assignable<A>::value;
1454 }
1455 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1456 if MDBX_IF_CONSTEXPR (!is_always_equal()) {
1457 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator())) {
1458 target->release();
1459 MDBX_CXX20_UNLIKELY target->get_allocator() = source.get_allocator();
1460 }
1461 } else {
1462 /* gag for buggy compilers */
1463 (void)target;
1464 (void)source;
1465 }
1466 }
1467};
1468
1469template <typename T, typename A = typename T::allocator_type,
1470 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1472
1473template <typename T, typename A> struct swap_alloc<T, A, false> {
1474 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1475 static constexpr bool is_nothrow() noexcept { return is_always_equal(); }
1476 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1477 if MDBX_IF_CONSTEXPR (!is_always_equal()) {
1478 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1479 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1480 } else {
1481 /* gag for buggy compilers */
1482 (void)left;
1483 (void)right;
1484 }
1485 }
1486};
1487
1488template <typename T, typename A> struct swap_alloc<T, A, true> {
1489 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1490 static constexpr bool is_nothrow() noexcept {
1491 return is_always_equal() ||
1492#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1493 ::std::is_nothrow_swappable<A>() ||
1494#endif /* __cpp_lib_is_swappable >= 201603L */
1495 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1496 }
1497 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1498 if MDBX_IF_CONSTEXPR (!is_always_equal())
1499 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1500 else {
1501 /* gag for buggy compilers */
1502 (void)left;
1503 (void)right;
1504 }
1505 }
1506};
1507
1508} // namespace allocation_aware_details
1509
1511 enum : size_t {
1516 };
1517
1518 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1519 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1520 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1521 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1522 return (value + pettiness_threshold - 1) & pettiness_mask;
1523 }
1524
1525 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1526 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1527 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1528
1529 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1530 return inplace;
1531
1532 if (wanna > current)
1533 /* doubling capacity, but don't made reserve more than max_reserve */
1534 return round(wanna + ::std::min(size_t(max_reserve), current));
1535
1536 if (current - wanna >
1537 /* shrink if reserve will more than half of current or max_reserve,
1538 * but not less than pettiness_threshold */
1539 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1540 return round(wanna);
1541
1542 /* keep unchanged */
1543 return current;
1544 }
1545};
1546
1548struct buffer_tag {};
1549
1551template <class ALLOCATOR, typename CAPACITY_POLICY>
1553public:
1555#if !defined(_MSC_VER) || _MSC_VER > 1900
1556 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1557#else
1558 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1559#endif /* MSVC is mad */
1560 using allocator_traits = ::std::allocator_traits<allocator_type>;
1561 using reservation_policy = CAPACITY_POLICY;
1562 enum : size_t {
1564 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1567 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1568 ? alignof(max_align_t) * 2
1571 };
1572
1574 enum class modality { reference, inplace, allocated };
1575
1576private:
1577 friend class txn;
1578 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1579 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1580 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1581
1582 using allocator_pointer = typename allocator_traits::pointer;
1583 using allocator_const_pointer = typename allocator_traits::const_pointer;
1584 using move_assign_alloc = allocation_aware_details::move_assign_alloc<silo, allocator_type>;
1585 using copy_assign_alloc = allocation_aware_details::copy_assign_alloc<silo, allocator_type>;
1586 using swap_alloc = allocation_aware_details::swap_alloc<silo, allocator_type>;
1587
1588 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1589 MDBX_INLINE_API_ASSERT(bytes >= sizeof(bin));
1590 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1591 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1592 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1593 const size_t n = (bytes + unit - 1) / unit;
1594 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1595 }
1596
1597 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1598 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1599 MDBX_INLINE_API_ASSERT(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1600 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1601 }
1602
1603 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1604 const size_t capacity = bin::advise_capacity(0, bytes);
1605 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1606 : allocate_storage(capacity);
1607 }
1608
1609 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1610#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1611 return static_cast<void *>(::std::to_address(ptr));
1612#else
1613 return static_cast<void *>(::std::addressof(*ptr));
1614#endif /* __cpp_lib_to_address */
1615 }
1616
1617 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1618#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1619 return static_cast<const void *>(::std::to_address(ptr));
1620#else
1621 return static_cast<const void *>(::std::addressof(*ptr));
1622#endif /* __cpp_lib_to_address */
1623 }
1624
1625#ifdef _MSC_VER
1626#pragma warning(push)
1627#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1628#endif /* _MSC_VER */
1629
1630 union alignas(max_align_t) bin {
1631 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1632 с учетом выравнивания */
1633 {
1634 allocator_pointer stub_ptr_;
1636 };
1637
1639 enum : size_t {
1641 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1645 };
1646
1648 byte pad_[inplace_size - sizeof(allocator_pointer)];
1649 size_t bytes_;
1650 };
1651
1653 byte buffer_[inplace_size - sizeof(byte)];
1656 };
1657
1658 allocator_pointer allocated_ptr_;
1661
1662 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1663 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1664 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1665 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1666 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1667 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1668 return capacity_bytes <= inplace_capacity();
1669 }
1670
1671 MDBX_NOTHROW_PURE_FUNCTION constexpr bool is_inplace() const noexcept {
1672 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1673 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1675 "WTF?");
1676 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1677 }
1678 MDBX_NOTHROW_PURE_FUNCTION constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1679
1682 /* properly destroy allocator::pointer */
1683 allocated_ptr_.~allocator_pointer();
1686 return address();
1687 }
1688
1689 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1692 new (&allocated_ptr_) allocator_pointer(pair.first);
1693 capacity_.bytes_ = pair.second;
1694 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1695 return address();
1696 }
1697
1699 if (::std::is_trivial<allocator_pointer>::value)
1700 /* workaround for "uninitialized" warning from some compilers */
1701 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1702 }
1703
1704 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1705 if (MDBX_UNLIKELY(wanna > max_capacity))
1706 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1707
1708 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1709 MDBX_INLINE_API_ASSERT(advised >= wanna);
1710 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1711 }
1712
1713 constexpr bool is_inplace(const void *ptr) const noexcept {
1714 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1715 }
1716
1717 constexpr const byte *address() const noexcept {
1718 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1719 }
1721 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1722 }
1723 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1724 } bin_;
1725
1726#ifdef _MSC_VER
1727#pragma warning(pop)
1728#endif /* _MSC_VER */
1729
1730 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1731
1732 MDBX_CXX20_CONSTEXPR void release() noexcept {
1733 if (bin_.is_allocated()) {
1734 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1735 /* properly destroy allocator::pointer */
1736 bin_.allocated_ptr_.~allocator_pointer();
1737 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1738 }
1739 }
1740
1741 template <bool external_content>
1742 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1743 const void *const content, const size_t length) {
1744 MDBX_INLINE_API_ASSERT(wanna_capacity >= wanna_headroom + length);
1745 const size_t old_capacity = bin_.capacity();
1746 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1747 if (MDBX_LIKELY(new_capacity == old_capacity))
1749 MDBX_INLINE_API_ASSERT(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1750 byte *const new_place = bin_.address() + wanna_headroom;
1751 if (MDBX_LIKELY(length))
1753 if (external_content)
1754 memcpy(new_place, content, length);
1755 else {
1756 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1757 MDBX_INLINE_API_ASSERT(old_capacity >= old_headroom + length);
1758 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1759 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1760 }
1761 }
1762 return new_place;
1763 }
1764
1765 if (bin::is_suitable_for_inplace(new_capacity)) {
1766 MDBX_INLINE_API_ASSERT(bin_.is_allocated());
1767 const auto old_allocated = bin_.allocated_ptr_;
1768 byte *const new_place = bin_.make_inplace() + wanna_headroom;
1769 if (MDBX_LIKELY(length))
1770 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1771 deallocate_storage(old_allocated, old_capacity);
1772 return new_place;
1773 }
1774
1775 if (bin_.is_inplace()) {
1776 const auto pair = allocate_storage(new_capacity);
1777 MDBX_INLINE_API_ASSERT(pair.second >= new_capacity);
1778 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1779 bin_.make_allocated(pair);
1780 if (MDBX_LIKELY(length))
1781 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1782 return new_place;
1783 }
1784
1785 auto pair = allocate_storage(new_capacity);
1786 std::swap(bin_.allocated_ptr_, pair.first);
1787 bin_.capacity_.bytes_ = pair.second;
1788 auto new_place = bin_.address() + wanna_headroom;
1789 if (MDBX_LIKELY(length))
1790 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1791 deallocate_storage(pair.first, old_capacity);
1792 return new_place;
1793 }
1794
1795 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1796 MDBX_INLINE_API_ASSERT(capacity() >= offset);
1797 return bin_.address() + offset;
1798 }
1799 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1800 MDBX_INLINE_API_ASSERT(capacity() >= offset);
1801 return bin_.address() + offset;
1802 }
1803 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1804 MDBX_INLINE_API_ASSERT(capacity() >= offset + length);
1805 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1806 }
1807
1808 //--------------------------------------------------------------------------
1809
1810 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1811 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1812 if (!bin::is_suitable_for_inplace(capacity))
1813 bin_.make_allocated(provide_storage(capacity));
1814 }
1815
1816 silo(silo &&other) = delete;
1818 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1819 : allocator_type(::std::move(other.get_allocator())) {
1820 if (!is_reference) {
1821 if (other.bin_.is_inplace()) {
1822 memcpy(&bin_, &other.bin_, sizeof(bin));
1823 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1824 } else {
1825 /* coverity[USE_AFTER_MOVE] */
1826 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1827 /* coverity[USE_AFTER_MOVE] */
1828 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1829 /* properly destroy allocator::pointer.
1830 *
1831 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1832 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1833 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1834 * from the 11th). */
1835 /* coverity[USE_AFTER_MOVE] */
1836 other.bin_.allocated_ptr_.~allocator_pointer();
1837 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1838 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1839 }
1840 }
1841 }
1842
1843 MDBX_CXX17_CONSTEXPR bool move_content(silo &other, const modality other_modality) noexcept {
1844 switch (other_modality) {
1845 case modality::inplace:
1846 memcpy(&bin_, &other.bin_, sizeof(bin));
1847 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1848 return /* buffer's slice fixup is needed */ true;
1849 case modality::allocated:
1850 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1851 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1852 /* properly destroy allocator::pointer.
1853 *
1854 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1855 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1856 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1857 * from the 11th). */
1858 /* coverity[use_after_move] */
1859 other.bin_.allocated_ptr_.~allocator_pointer();
1860 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1861 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1862 return /* buffer's slice fixup is not needed */ false;
1863 default:
1864 MDBX_CONSTEXPR_ASSERT(other_modality == modality::reference);
1865 return /* buffer's slice fixup is not needed */ false;
1866 }
1867 }
1868
1869 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1870 exchange(silo &left, const modality left_modality, silo &right,
1871 const modality right_modality) noexcept(swap_alloc::is_nothrow()) {
1872 swap_alloc::propagate(left, right);
1873 bool left_need_fixup = false, right_need_fixup = false;
1874 if (left_modality == modality::reference || right_modality == modality::reference) {
1875 /* It is Ok here to call move_content for the left and right side in any order,
1876 * since the move_content() does nothing when modality == reference.
1877 * Thus, the actual move action will perform no more than one call of move_content(),
1878 * so the order doesn't matter here. */
1879 left_need_fixup = left.move_content(right, right_modality);
1880 right_need_fixup = right.move_content(left, left_modality);
1881 } else {
1882 silo temp(std::move(left), false);
1883 left_need_fixup = left.move_content(right, right_modality);
1884 right_need_fixup = right.move_content(temp, left_modality);
1885 }
1886 return std::make_pair(left_need_fixup, right_need_fixup);
1887 }
1888
1889 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1890 const allocator_type &alloc = allocator_type())
1891 : silo(capacity, alloc) {
1892 MDBX_INLINE_API_ASSERT(capacity >= headroom + length);
1893 if (length)
1894 put(headroom, ptr, length);
1895 }
1896
1897 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1898 : silo(length, 0, ptr, length, alloc) {}
1899
1900 ~silo() { release(); }
1901
1902 //--------------------------------------------------------------------------
1903
1904 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1905 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1906 }
1907
1908 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1909
1910 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1911 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1912 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1913 }
1914
1915 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1916 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1917 return get(offset);
1918 }
1919 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1920 };
1921
1922 MDBX_CXX14_CONSTEXPR void fixup_imported_inplace(const typename silo::bin &src) noexcept {
1923 auto ptr = inherited::byte_ptr();
1924 if (src.is_inplace(ptr)) {
1925 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1926 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1927 iov_base = ptr + offset;
1928 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1929 }
1930 }
1931
1932 silo silo_;
1933
1934 void insulate() {
1935 MDBX_INLINE_API_ASSERT(is_reference());
1936 iov_base = silo_.assign(iov_base, iov_len);
1937 }
1938
1939 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1940 return static_cast<const byte *>(silo_.data());
1941 }
1942
1943 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1944 return silo_begin() + silo_.capacity();
1945 }
1946
1947 struct data_preserver : public exception_thunk {
1948 buffer data;
1949 data_preserver(const allocator_type &alloc) : data(alloc) {}
1950 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1951 auto self = static_cast<data_preserver *>(context);
1952 assert(self->is_clean());
1953 assert(&self->data == target);
1954 (void)target;
1955 try {
1956 self->data.assign(src, bytes, false);
1957 return MDBX_RESULT_FALSE;
1958 } catch (... /* capture any exception to rethrow it over C code */) {
1959 self->capture();
1960 return MDBX_RESULT_TRUE;
1961 }
1962 }
1963 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1964 };
1965
1966public:
1969
1970 using move_assign_alloc = typename silo::move_assign_alloc;
1971 using copy_assign_alloc = typename silo::copy_assign_alloc;
1972 using swap_alloc = typename silo::swap_alloc;
1973 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1974
1976 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1977
1981 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1982 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1983 }
1984
1989 return silo_.is_inplace(inherited::data());
1990 }
1991
1994
1997 return is_freestanding() ? (is_inplace() ? modality::inplace : modality::allocated) : modality::reference;
1998 }
1999
2002 return is_freestanding() ? silo_.capacity() : 0;
2003 }
2004
2007 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
2008 }
2009
2012 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2013 }
2014
2016 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2017
2019 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2020
2027
2032 return const_cast<byte *>(inherited::end_byte_ptr());
2033 }
2034
2036 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2037
2039 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2040
2045 return const_cast<char *>(inherited::char_ptr());
2046 }
2047
2052 return const_cast<char *>(inherited::end_char_ptr());
2053 }
2054
2056 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return const_data(); }
2057
2059 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return const_end(); }
2060
2062 MDBX_CXX11_CONSTEXPR const void *const_data() const noexcept { return inherited::data(); }
2063
2065 MDBX_CXX11_CONSTEXPR const void *const_end() const noexcept { return inherited::end(); }
2066
2069 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2071 return const_cast<void *>(inherited::data());
2072 }
2073
2076 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2078 return const_cast<void *>(inherited::end());
2079 }
2080
2085
2092
2095 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2096 return set_length(static_cast<const char *>(ptr) - char_ptr());
2097 }
2098
2103 if (is_reference())
2104 insulate();
2105 }
2106
2107 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2108 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2109 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2110 const allocator_type &alloc = allocator_type());
2111
2113 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2114 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2115
2116 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2117 : buffer(inherited(c_str), make_reference, alloc) {}
2118
2119#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2120 template <class CHAR, class T>
2121 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2122 const allocator_type &alloc = allocator_type())
2123 : buffer(inherited(view), make_reference, alloc) {}
2124#endif /* __cpp_lib_string_view >= 201606L */
2125
2127 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2128 : buffer(src, src.empty() || src.is_null(), alloc) {}
2129
2131 explicit buffer(const buffer &src)
2132 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2133
2135 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2136 : buffer(inherited(ptr, bytes), alloc) {}
2137
2138 template <class CHAR, class T, class A>
2139 explicit MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2140 const allocator_type &alloc = allocator_type())
2141 : buffer(inherited(str), false, alloc) {}
2142
2143 template <class CHAR, class T, class A>
2144 explicit MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str, bool make_reference,
2145 const allocator_type &alloc = allocator_type())
2146 : buffer(inherited(str), make_reference, alloc) {}
2147
2148 template <class CHAR, class T, class A>
2149 explicit MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &&str,
2150 const allocator_type &alloc = allocator_type())
2151 : buffer(inherited(str), false, alloc) {
2152 str.clear();
2153 }
2154
2156 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2157
2158#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2159 template <class CHAR, class T>
2160 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2161 const allocator_type &alloc = allocator_type())
2162 : buffer(inherited(view), alloc) {}
2163#endif /* __cpp_lib_string_view >= 201606L */
2164
2165 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2166 : silo_(check_length(head_room, tail_room), alloc) {
2167 iov_base = silo_.get(head_room);
2168 MDBX_INLINE_API_ASSERT(iov_len == 0);
2169 }
2170
2171 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2172 iov_base = silo_.get();
2173 MDBX_INLINE_API_ASSERT(iov_len == 0);
2174 }
2175
2176 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2177 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2178 iov_len = src.length();
2179 iov_base = memcpy(silo_.get(head_room), src.data(), iov_len);
2180 }
2181
2182 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2183
2184 buffer(buffer &&src) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
2185 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2186 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2187 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2188 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2189 * 11th). */
2190 /* coverity[USE_AFTER_MOVE] */
2191 fixup_imported_inplace(src.silo_.bin_);
2192 src.invalidate();
2193 }
2194
2196 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2197
2200
2201 template <typename POD>
2202 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2203 return buffer(inherited::wrap(pod), make_reference, alloc);
2204 }
2205
2207 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2208 const allocator_type &alloc = allocator_type()) {
2209 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2210 }
2211
2214 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2215 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2216 }
2217
2219 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2220 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2221 }
2222
2224 template <typename POD>
2225 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2226 const allocator_type &alloc = allocator_type()) {
2227 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2228 }
2229
2232 template <typename POD>
2233 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2234 return base58(inherited::wrap(pod), wrap_width, alloc);
2235 }
2236
2239 template <typename POD>
2240 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2241 return base64(inherited::wrap(pod), wrap_width, alloc);
2242 }
2243
2245 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2246 const allocator_type &alloc = allocator_type()) const {
2247 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2248 }
2249
2252 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2253 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2254 }
2255
2257 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2258 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2259 }
2260
2262 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2263 const allocator_type &alloc = allocator_type()) {
2264 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2265 }
2266
2269 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2270 const allocator_type &alloc = allocator_type()) {
2271 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2272 }
2273
2276 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2277 const allocator_type &alloc = allocator_type()) {
2278 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2279 }
2280
2283 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2284 return hex_decode(*this, ignore_spaces, alloc);
2285 }
2286
2289 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2290 return base58_decode(*this, ignore_spaces, alloc);
2291 }
2292
2295 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2296 return base64_decode(*this, ignore_spaces, alloc);
2297 }
2298
2300 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2301 wanna_headroom = ::std::min(
2302 ::std::max(headroom(), wanna_headroom),
2303 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2304 wanna_tailroom = ::std::min(
2305 ::std::max(tailroom(), wanna_tailroom),
2306 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2307 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2308
2309 if (is_freestanding())
2310 iov_base = silo_.template reshape<false>(wanna_capacity, wanna_headroom, iov_base, iov_len);
2311 else if (wanna_capacity > iov_len)
2312 iov_base = silo_.template reshape<true>(wanna_capacity, wanna_headroom, iov_base, iov_len);
2313
2314 MDBX_INLINE_API_ASSERT(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2315 MDBX_INLINE_API_ASSERT(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2316 }
2317
2319 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2320
2322 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2323
2324 buffer &assign_reference(const void *ptr, size_t bytes) {
2325 silo_.clear();
2327 return *this;
2328 }
2329
2330 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2331 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2332 return *this;
2333 }
2334
2335 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2336 const auto pair = silo::exchange(silo_, content_modality(), other.silo_, other.content_modality());
2337 inherited::swap(other);
2338 if (pair.first)
2339 fixup_imported_inplace(other.silo_.bin_);
2340 if (pair.second)
2341 other.fixup_imported_inplace(silo_.bin_);
2342 }
2343
2344 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2345 left.swap(right);
2346 }
2347
2348 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2349 return buffer(src.headroom(), src, src.tailroom(), alloc);
2350 }
2351
2353 return buffer(static_cast<const struct slice &>(*this), !is_inplace(),
2354 allocator_traits::select_on_container_copy_construction(get_allocator()));
2355 }
2356
2358 if (MDBX_LIKELY(this != &src))
2360 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2361 invalidate();
2362 copy_assign_alloc::propagate(&silo_, src.silo_);
2363 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2364 iov_len = src.length();
2365 }
2366 else
2368 return *this;
2369 }
2370
2371 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2372 if (MDBX_LIKELY(this != &src))
2374 invalidate();
2375 copy_assign_alloc::propagate(&silo_, src.silo_);
2376 if (make_reference) {
2377 silo_.release();
2378 iov_base = src.iov_base;
2379 } else {
2380 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2381 }
2382 iov_len = src.length();
2383 }
2384 else if (!make_reference && is_reference())
2385 insulate();
2386 return *this;
2387 }
2388
2389 MDBX_CXX20_CONSTEXPR buffer &assign(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) {
2390 if (MDBX_LIKELY(this != &src))
2392 const auto kind = src.content_modality();
2393 const auto src_headroom = src.headroom();
2394 const auto src_data = src.const_data();
2395 const auto src_length = src.length();
2396 inherited::assign(std::move(src));
2397 if (!move_assign_alloc::is_moveable(&silo_, src.silo_) && kind == modality::allocated) {
2398 iov_base = silo_.template reshape<true>(src.silo_.capacity(), src_headroom, src_data, src_length);
2399 return *this;
2400 }
2401 move_assign_alloc::propagate(&silo_, src.silo_);
2402 if (silo_.move_content(src.silo_, kind))
2403 fixup_imported_inplace(src.silo_.bin_);
2404 }
2405 return *this;
2406 }
2407
2408 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2409 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2410 }
2411
2412 buffer &assign(const struct slice &src, bool make_reference = false) {
2413 return assign(src.data(), src.length(), make_reference);
2414 }
2415
2416 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2417 return assign(src.iov_base, src.iov_len, make_reference);
2418 }
2419
2420 buffer &assign(struct slice &&src, bool make_reference = false) {
2421 assign(src.data(), src.length(), make_reference);
2422 src.invalidate();
2423 return *this;
2424 }
2425
2426 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2427 assign(src.iov_base, src.iov_len, make_reference);
2428 src.iov_base = nullptr;
2429 return *this;
2430 }
2431
2432 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2433 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2434 }
2435
2436 template <class CHAR, class T, class A>
2437 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2438 return assign(str.data(), str.length() * sizeof(CHAR), make_reference);
2439 }
2440
2441 buffer &assign(const char *c_str, bool make_reference = false) {
2442 return assign(c_str, strlen(c_str), make_reference);
2443 }
2444
2445#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2446 template <class CHAR, class T>
2447 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2448 return assign(inherited(view), make_reference);
2449 }
2450
2451 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2452 assign(inherited(view), make_reference);
2453 view = {};
2454 return *this;
2455 }
2456#endif /* __cpp_lib_string_view >= 201606L */
2457
2458 buffer &operator=(const buffer &src) { return assign(src); }
2459
2460 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2461
2462 buffer &operator=(const struct slice &src) { return assign(src); }
2463
2464 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2465
2466#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2467 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2468 return assign(inherited(view));
2469 }
2470
2471 template <class CHAR, class T> buffer &append(const ::std::basic_string_view<CHAR, T> &view) {
2472 return append(view.begin(), view.end());
2473 }
2474#endif /* __cpp_lib_string_view >= 201606L */
2475
2476 template <class CHAR, class T, class A>
2477 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2478 return as_string<CHAR, T, A>();
2479 }
2480
2481 template <class CHAR, class T, class A> buffer &append(const ::std::basic_string<CHAR, T, A> &str) {
2482 return append(inherited(str));
2483 }
2484
2486 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2487
2489 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) {
2490 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2491 }
2492
2495 if (is_freestanding())
2496 iov_base = silo_.template reshape<false>(iov_len, 0, iov_base, iov_len);
2497 }
2498
2499 buffer &append(const void *src, size_t bytes) {
2500 if (MDBX_LIKELY(bytes))
2502 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2503 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2504 memcpy(end_byte_ptr(), src, bytes);
2505 iov_len += bytes;
2506 }
2507 return *this;
2508 }
2509
2510 buffer &append(const byte c) {
2511 if (MDBX_UNLIKELY(tailroom() < 1))
2512 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2513 *end_byte_ptr() = c;
2514 iov_len += 1;
2515 return *this;
2516 }
2517
2518 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2519
2520 buffer &add_header(const void *src, size_t bytes) {
2521 if (MDBX_LIKELY(bytes))
2523 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2524 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2525 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2526 iov_len += bytes;
2527 }
2528 return *this;
2529 }
2530
2531 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2532
2533 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2534 const size_t wanna_bytes = producer.envisage_result_length();
2535 if (MDBX_LIKELY(wanna_bytes))
2537 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2538 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2539 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2540 }
2541 return *this;
2542 }
2543
2544 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2545 const size_t wanna_bytes = producer.envisage_result_length();
2546 if (MDBX_LIKELY(wanna_bytes))
2548 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2549 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2550 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2551 }
2552 return *this;
2553 }
2554
2555 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2556 return append_producer(to_hex(data, uppercase, wrap_width));
2557 }
2558
2559 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2560 return append_producer(to_base58(data, wrap_width));
2561 }
2562
2563 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2564 return append_producer(to_base64(data, wrap_width));
2565 }
2566
2567 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2568 return append_producer(from_hex(data, ignore_spaces));
2569 }
2570
2571 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2572 return append_producer(from_base58(data, ignore_spaces));
2573 }
2574
2575 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2576 return append_producer(from_base64(data, ignore_spaces));
2577 }
2578
2579 buffer &append_u8(uint_fast8_t u8) {
2580 if (MDBX_UNLIKELY(tailroom() < 1))
2581 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2582 *end_byte_ptr() = uint8_t(u8);
2583 iov_len += 1;
2584 return *this;
2585 }
2586
2587 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2588
2589 buffer &append_u16(uint_fast16_t u16) {
2590 if (MDBX_UNLIKELY(tailroom() < 2))
2591 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2592 const auto ptr = end_byte_ptr();
2593 ptr[0] = uint8_t(u16);
2594 ptr[1] = uint8_t(u16 >> 8);
2595 iov_len += 2;
2596 return *this;
2597 }
2598
2599 buffer &append_u24(uint_fast32_t u24) {
2600 if (MDBX_UNLIKELY(tailroom() < 3))
2601 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2602 const auto ptr = end_byte_ptr();
2603 ptr[0] = uint8_t(u24);
2604 ptr[1] = uint8_t(u24 >> 8);
2605 ptr[2] = uint8_t(u24 >> 16);
2606 iov_len += 3;
2607 return *this;
2608 }
2609
2610 buffer &append_u32(uint_fast32_t u32) {
2611 if (MDBX_UNLIKELY(tailroom() < 4))
2612 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2613 const auto ptr = end_byte_ptr();
2614 ptr[0] = uint8_t(u32);
2615 ptr[1] = uint8_t(u32 >> 8);
2616 ptr[2] = uint8_t(u32 >> 16);
2617 ptr[3] = uint8_t(u32 >> 24);
2618 iov_len += 4;
2619 return *this;
2620 }
2621
2622 buffer &append_u48(uint_fast64_t u48) {
2623 if (MDBX_UNLIKELY(tailroom() < 6))
2624 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2625 const auto ptr = end_byte_ptr();
2626 ptr[0] = uint8_t(u48);
2627 ptr[1] = uint8_t(u48 >> 8);
2628 ptr[2] = uint8_t(u48 >> 16);
2629 ptr[3] = uint8_t(u48 >> 24);
2630 ptr[4] = uint8_t(u48 >> 32);
2631 ptr[5] = uint8_t(u48 >> 40);
2632 iov_len += 6;
2633 return *this;
2634 }
2635
2636 buffer &append_u64(uint_fast64_t u64) {
2637 if (MDBX_UNLIKELY(tailroom() < 8))
2638 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2639 const auto ptr = end_byte_ptr();
2640 ptr[0] = uint8_t(u64);
2641 ptr[1] = uint8_t(u64 >> 8);
2642 ptr[2] = uint8_t(u64 >> 16);
2643 ptr[3] = uint8_t(u64 >> 24);
2644 ptr[4] = uint8_t(u64 >> 32);
2645 ptr[5] = uint8_t(u64 >> 40);
2646 ptr[6] = uint8_t(u64 >> 48);
2647 ptr[7] = uint8_t(u64 >> 56);
2648 iov_len += 8;
2649 return *this;
2650 }
2651
2652 //----------------------------------------------------------------------------
2653
2654 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2655 return buffer(inherited(text), make_reference);
2656 }
2657
2658#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2659 template <class CHAR, class T>
2660 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2661 return buffer(src, make_reference);
2662 }
2663#endif /* __cpp_lib_string_view >= 201606L */
2664
2665 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2666
2667 template <class CHAR, class T, class A>
2668 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2669 return buffer(src, make_reference);
2670 }
2671
2672 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2673
2674 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2675
2676 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2677
2678 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2679
2680 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2681
2682 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2683
2684 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2685
2686 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2687
2688 static buffer key_from_jsonInteger(const int64_t json_integer) {
2689 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2690 }
2691
2692 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2693
2694 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2695
2696 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2697
2698 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2699
2700 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2701
2702 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2703
2704 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2705
2706 const slice &slice() const noexcept { return *this; }
2707};
2708
2709template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2713 using reservation_policy = CAPACITY_POLICY;
2714 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2716
2719 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2720
2722 : key(key, alloc), value(value, alloc) {}
2723 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2724 const allocator_type &alloc = allocator_type())
2725 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2726
2728 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2729 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2730 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2731
2733 : key(key, alloc), value(value, alloc) {}
2734 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2735 const allocator_type &alloc = allocator_type())
2736 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2737
2740 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2741 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2742
2743 buffer_pair_spec(const txn &transaction, const slice &key, const slice &value,
2744 const allocator_type &alloc = allocator_type())
2745 : key(transaction, key, alloc), value(transaction, value, alloc) {}
2746 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2747 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2748
2749 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2750 : key(::std::move(key)), value(::std::move(value)) {}
2752 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2753 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2754
2757 key.assign(std::move(src.key));
2758 value.assign(std::move(src.value));
2759 return *this;
2760 }
2761
2763 key.assign(src.key);
2764 value.assign(src.value);
2765 return *this;
2766 }
2768 key.assign(std::move(src.key));
2769 value.assign(std::move(src.value));
2770 return *this;
2771 }
2773 key.assign(src.first);
2774 value.assign(src.second);
2775 return *this;
2776 }
2778 key.assign(std::move(src.first));
2779 value.assign(std::move(src.second));
2780 return *this;
2781 }
2782
2786 return key.is_freestanding() && value.is_freestanding();
2787 }
2788
2791 return key.is_reference() || value.is_reference();
2792 }
2793
2797 key.make_freestanding();
2798 value.make_freestanding();
2799 }
2800
2801 operator pair() const noexcept { return pair(key, value); }
2802};
2803
2805
2808public:
2809 cache_entry() noexcept { reset(); }
2810 cache_entry(const cache_entry &) noexcept = default;
2811 cache_entry &operator=(const cache_entry &) noexcept = default;
2812 cache_entry(cache_entry &&other) noexcept {
2813 *this = other;
2814 other.reset();
2815 }
2816 void reset() noexcept { mdbx_cache_init(this); }
2817 MDBX_CXX20_CONSTEXPR cache_entry(const MDBX_cache_entry_t &ce) noexcept { mdbx::memcpy(this, &ce, sizeof(*this)); }
2819 mdbx::memcpy(this, &ce, sizeof(*this));
2820 return *this;
2821 };
2822};
2823
2824//------------------------------------------------------------------------------
2825
2828enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2829
2846
2848 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2849}
2850
2852 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2853}
2854
2856 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2857}
2858
2860 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2861}
2862
2864
2922
2926
2928 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2929}
2930
2932 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2933}
2934
2936 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2937}
2938
2940 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2941}
2942
2944
2955 map_handle(const map_handle &) noexcept = default;
2956 map_handle &operator=(const map_handle &) noexcept = default;
2957 operator bool() const noexcept { return dbi != 0; }
2958 operator MDBX_dbi() const { return dbi; }
2959
2960#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2961 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2962 return a.dbi <=> b.dbi;
2963 }
2964#endif /* __cpp_impl_three_way_comparison */
2965 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2966 return a.dbi == b.dbi;
2967 }
2968 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2969 return a.dbi < b.dbi;
2970 }
2971 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2972 return a.dbi > b.dbi;
2973 }
2974 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2975 return a.dbi <= b.dbi;
2976 }
2977 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2978 return a.dbi >= b.dbi;
2979 }
2980 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2981 return a.dbi != b.dbi;
2982 }
2983
2995};
2996
2999 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
3000}
3002 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
3003}
3004
3011
3020 friend class txn;
3021
3022protected:
3024 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
3025
3026public:
3027 MDBX_CXX11_CONSTEXPR env() noexcept = default;
3028 env(const env &) noexcept = default;
3029 env &operator=(const env &) noexcept = default;
3030 inline env &operator=(env &&) noexcept;
3031 inline env(env &&) noexcept;
3032 inline ~env() noexcept;
3033
3034 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
3035 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const noexcept { return handle_; }
3036 MDBX_CXX14_CONSTEXPR operator MDBX_env *() noexcept { return handle_; }
3037 MDBX_CXX14_CONSTEXPR const MDBX_env *handle() const noexcept { return handle_; }
3039 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
3040 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
3041
3042 //----------------------------------------------------------------------------
3043
3048
3050 enum : intptr_t {
3053 maximal_value = INTPTR_MAX,
3054 kB = 1000,
3055 MB = kB * 1000,
3056 GB = MB * 1000,
3057#if INTPTR_MAX > 0x7fffFFFFl
3058 TB = GB * 1000,
3059 PB = TB * 1000,
3060 EB = PB * 1000,
3061#endif /* 64-bit intptr_t */
3062 KiB = 1024,
3063 MiB = KiB << 10,
3064 GiB = MiB << 10,
3065#if INTPTR_MAX > 0x7fffFFFFl
3066 TiB = GiB << 10,
3067 PiB = TiB << 10,
3068 EiB = PiB << 10,
3069#endif /* 64-bit intptr_t */
3070 };
3071
3073 struct size {
3074 intptr_t bytes;
3075 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3076 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3077 };
3078
3081
3086
3098
3101
3104
3110
3111 inline geometry &make_fixed(intptr_t size) noexcept;
3112 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3115 geometry(const geometry &) noexcept = default;
3116 MDBX_CXX14_CONSTEXPR geometry &operator=(const geometry &) noexcept = default;
3122 };
3123
3131
3139
3150
3172
3177 unsigned max_maps{0};
3180 unsigned max_readers{0};
3185
3196 operate_parameters(const operate_parameters &) noexcept = default;
3198 MDBX_env_flags_t make_flags(bool accede = true,
3201 bool use_subdirectory = false
3202 ) const;
3206 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3207 };
3208
3212 inline env::mode get_mode() const;
3214 inline env::durability get_durability() const;
3218 inline env::operate_options get_options() const;
3219
3222 bool is_pristine() const;
3223
3225 bool is_empty() const;
3226
3228 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3229
3230 struct limits {
3231 limits() = delete;
3233 static inline size_t pagesize_min() noexcept;
3235 static inline size_t pagesize_max() noexcept;
3237 static inline size_t dbsize_min(intptr_t pagesize);
3239 static inline size_t dbsize_max(intptr_t pagesize);
3241 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3243 static inline size_t key_min(key_mode mode) noexcept;
3245 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3247 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3249 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3251 static inline size_t key_max(const env &, key_mode mode);
3253 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3255 static inline size_t value_min(value_mode) noexcept;
3256
3258 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3260 static inline size_t value_max(intptr_t pagesize, value_mode);
3262 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3264 static inline size_t value_max(const env &, value_mode);
3265
3268 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3271 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3274 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3277 static inline size_t pairsize4page_max(const env &, value_mode);
3278
3281 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3284 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3287 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3290 static inline size_t valsize4page_max(const env &, value_mode);
3291
3294 static inline size_t transaction_size_max(intptr_t pagesize);
3295
3297 static inline size_t max_map_handles(void);
3298 };
3299
3301 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3303 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3305 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3307 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3309 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3311 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3315
3318#ifdef MDBX_STD_FILESYSTEM_PATH
3319 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3320#endif /* MDBX_STD_FILESYSTEM_PATH */
3321#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3322 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3323 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3324#endif /* Windows */
3325 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3326 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3327
3329 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3330
3346
3348#ifdef MDBX_STD_FILESYSTEM_PATH
3349 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3350#endif /* MDBX_STD_FILESYSTEM_PATH */
3351#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3352 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3353 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3354#endif /* Windows */
3355 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3356 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3357
3360
3363
3365 inline stat get_stat() const;
3366
3368 size_t get_pagesize() const { return get_stat().ms_psize; }
3369
3371 inline info get_info() const;
3372
3374 inline stat get_stat(const txn &) const;
3375
3377 inline info get_info(const txn &) const;
3378
3380 inline filehandle get_filehandle() const;
3381
3383 const path_char *get_path() const;
3384
3386 inline MDBX_env_flags_t get_flags() const;
3387
3388 inline bool is_readonly() const { return (get_flags() & MDBX_RDONLY) != 0; }
3389
3390 inline bool is_exclusive() const { return (get_flags() & MDBX_EXCLUSIVE) != 0; }
3391
3392 inline bool is_cooperative() const { return !is_exclusive(); }
3393
3394 inline bool is_writemap() const { return (get_flags() & MDBX_WRITEMAP) != 0; }
3395
3396 inline bool is_readwrite() const { return !is_readonly(); }
3397
3398 inline bool is_nested_transactions_available() const { return (get_flags() & (MDBX_WRITEMAP | MDBX_RDONLY)) == 0; }
3399
3402 inline unsigned max_readers() const;
3403
3406 inline unsigned max_maps() const;
3407
3409 inline void *get_context() const noexcept;
3410
3412 inline env &set_context(void *your_context);
3413
3428 inline env &set_sync_threshold(size_t bytes);
3429
3435 inline size_t sync_threshold() const;
3436
3437#if __cplusplus >= 201103L || defined(DOXYGEN)
3457 inline env &set_sync_period(const duration &period);
3458
3464 inline duration sync_period() const;
3465#endif
3466
3470 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3471
3474 inline unsigned sync_period__seconds_16dot16() const;
3475
3479 inline env &set_sync_period__seconds_double(double seconds);
3480
3483 inline double sync_period__seconds_double() const;
3484
3538
3540 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3541
3543 inline uint64_t extra_option(extra_runtime_option option) const;
3544
3546 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3547
3549 inline env &set_geometry(const geometry &size);
3550
3554 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3555
3559 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3560
3579 inline void close_map(const map_handle &);
3580
3583 int slot;
3592 size_t bytes_used;
3601
3603 size_t used, size_t retained) noexcept;
3604 };
3605
3613 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3614
3617 inline unsigned check_readers();
3618
3637
3642 inline MDBX_hsr_func get_HandleSlowReaders() const noexcept;
3643
3645 inline txn_managed start_read() const;
3646
3648 inline txn_managed prepare_read() const;
3649
3651 inline txn_managed start_write(txn &parent);
3652
3654 inline txn_managed start_write(bool dont_wait = false);
3655
3658};
3659
3668class LIBMDBX_API_TYPE env_managed : public env {
3669 using inherited = env;
3671 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3672 void setup(unsigned max_maps, unsigned max_readers = 0);
3673
3674public:
3675 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3676
3678#ifdef MDBX_STD_FILESYSTEM_PATH
3679 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3680#endif /* MDBX_STD_FILESYSTEM_PATH */
3681#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3682 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3683 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3684#endif /* Windows */
3685 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3686 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3687
3698
3700#ifdef MDBX_STD_FILESYSTEM_PATH
3702 bool accede = true);
3703#endif /* MDBX_STD_FILESYSTEM_PATH */
3704#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3705 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3706 bool accede = true);
3707 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3708 bool accede = true);
3709#endif /* Windows */
3710 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3711 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3712
3726 void close(bool dont_sync = false);
3727
3728 env_managed(env_managed &&) = default;
3729 env_managed &operator=(env_managed &&other) noexcept;
3730 env_managed(const env_managed &) = delete;
3731 env_managed &operator=(const env_managed &) = delete;
3732 virtual ~env_managed();
3733};
3734
3743protected:
3744 friend class cursor;
3746 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3747
3748public:
3749 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3750 txn(const txn &) noexcept = default;
3751 txn &operator=(const txn &) noexcept = default;
3752 inline txn &operator=(txn &&) noexcept;
3753 inline txn(txn &&) noexcept;
3754 inline ~txn() noexcept;
3755
3756 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
3757 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const noexcept { return handle_; }
3758 MDBX_CXX14_CONSTEXPR operator MDBX_txn *() noexcept { return handle_; }
3759 MDBX_CXX14_CONSTEXPR const MDBX_txn *handle() const noexcept { return handle_; }
3761 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
3762 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
3763
3765 inline ::mdbx::env env() const noexcept;
3767 inline MDBX_txn_flags_t flags() const;
3769 inline uint64_t id() const;
3770
3772 inline void *get_context() const noexcept;
3773
3775 inline txn &set_context(void *your_context);
3776
3778 inline bool is_dirty(const void *ptr) const;
3779
3781 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3782
3784 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3785
3787 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3788
3791 inline info get_info(bool scan_reader_lock_table = false) const;
3792
3795 size_t size_max() const { return env().transaction_size_max(); }
3796
3798 size_t size_current() const {
3799 assert(is_readwrite());
3800 return size_t(get_info().txn_space_dirty);
3801 }
3802
3803 //----------------------------------------------------------------------------
3804
3806 inline void reset_reading();
3807
3809 inline void renew_reading();
3810
3812 inline txn_managed clone(void *context = nullptr) const;
3813
3815 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
3816
3818 inline void make_broken();
3819
3821 inline void park_reading(bool autounpark = true);
3822
3825 inline bool unpark_reading(bool restart_if_ousted = true);
3826
3829
3832
3834 inline cursor_managed open_cursor(map_handle map) const;
3835
3837 inline size_t release_all_cursors(bool unbind) const;
3838
3840 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3841
3843 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3844
3846 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3847 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3849 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3850 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3852 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3853 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3854
3856 inline map_handle open_map_accede(const char *name) const;
3858 inline map_handle open_map_accede(const ::std::string &name) const;
3860 inline map_handle open_map_accede(const slice &name) const;
3861
3863 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3864 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3866 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3867 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3869 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3870 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3871
3873 inline void drop_map(map_handle map);
3877 bool drop_map(const char *name, bool throw_if_absent = false);
3881 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3885 bool drop_map(const slice &name, bool throw_if_absent = false);
3886
3888 inline void clear_map(map_handle map);
3891 bool clear_map(const char *name, bool throw_if_absent = false);
3894 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3897 bool clear_map(const slice &name, bool throw_if_absent = false);
3898
3900 inline void rename_map(map_handle map, const char *new_name);
3902 inline void rename_map(map_handle map, const ::std::string &new_name);
3904 inline void rename_map(map_handle map, const slice &new_name);
3908 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3912 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3916 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3917
3918#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3919
3921 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3922 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3923 return open_map(slice(name), key_mode, value_mode);
3924 }
3925
3926 inline map_handle open_map_accede(const ::std::string_view &name) const;
3928 inline map_handle create_map(const ::std::string_view &name,
3929 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3930 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3931 return create_map(slice(name), key_mode, value_mode);
3932 }
3933
3936 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3937 return drop_map(slice(name), throw_if_absent);
3938 }
3939
3941 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3942 return clear_map(slice(name), throw_if_absent);
3943 }
3944
3945 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3949 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3950 bool throw_if_absent = false) {
3951 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3952 }
3953#endif /* __cpp_lib_string_view >= 201606L */
3954
3957 inline map_stat get_map_stat(map_handle map) const;
3960 inline uint32_t get_tree_deepmask(map_handle map) const;
3962 inline map_handle::info get_map_flags(map_handle map) const;
3963
3966 inline txn &put_canary(const canary &);
3968 inline canary get_canary() const;
3969
3971 inline uint64_t sequence(map_handle map) const;
3973 inline uint64_t sequence(map_handle map, uint64_t increment);
3974
3976 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3978 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3980 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3982 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3983
3985 inline slice get(map_handle map, const slice &key) const;
3987 inline slice get(map_handle map, slice key, size_t &values_count) const;
3989 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3991 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3995 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3999 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
4000
4001 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4002 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
4003 inline void insert(map_handle map, const slice &key, slice value);
4004 inline value_result try_insert(map_handle map, const slice &key, slice value);
4005 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
4006 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
4007
4008 inline void upsert(map_handle map, const slice &key, const slice &value);
4009 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
4010
4011 inline void update(map_handle map, const slice &key, const slice &value);
4012 inline bool try_update(map_handle map, const slice &key, const slice &value);
4013 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
4014 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
4015
4016 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
4017 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
4018 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
4019 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
4020
4022 inline bool erase(map_handle map, const slice &key);
4023
4025 inline bool erase(map_handle map, const slice &key, const slice &value);
4026
4028 inline void replace(map_handle map, const slice &key, slice &old_value, const slice &new_value);
4029
4031 template <class BUFFER, class ALLOCATOR = typename BUFFER::allocator_type>
4032 inline BUFFER extract(map_handle map, const slice &key, const ALLOCATOR &alloc = ALLOCATOR());
4033
4035 template <class BUFFER, class ALLOCATOR = typename BUFFER::allocator_type>
4036 inline BUFFER replace(map_handle map, const slice &key, const slice &new_value, const ALLOCATOR &alloc = ALLOCATOR());
4037
4038 template <class BUFFER, class ALLOCATOR = typename BUFFER::allocator_type>
4039 inline BUFFER replace_reserve(map_handle map, const slice &key, size_t length, slice &new_value_reservation,
4040 const ALLOCATOR &alloc = ALLOCATOR());
4041
4058 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4059 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4060 return append(map, kv.key, kv.value, multivalue_order_preserved);
4061 }
4062
4063 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4064 const void *values_array, size_t values_count, put_mode mode,
4065 bool allow_partial = false);
4066 template <typename VALUE>
4067 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4068 put_mode mode, bool allow_partial = false) {
4069 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4070 !::std::is_array<VALUE>::value,
4071 "Must be a standard layout type!");
4072 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4073 }
4074 template <typename VALUE>
4075 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4076 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4077 }
4078
4079 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4080 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4081 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4082 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4083};
4084
4093class LIBMDBX_API_TYPE txn_managed : public txn {
4094 using inherited = txn;
4095 friend class env;
4096 friend class txn;
4098 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4099
4100public:
4101 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4102 txn_managed(txn_managed &&) = default;
4103 txn_managed &operator=(txn_managed &&other) noexcept;
4104 txn_managed(const txn_managed &) = delete;
4105 txn_managed &operator=(const txn_managed &) = delete;
4106 ~txn_managed();
4107
4108 //----------------------------------------------------------------------------
4110
4112 void abort();
4116 void abort(finalization_latency &latency) { return abort(&latency); }
4120 finalization_latency result;
4121 abort(&result);
4122 return result;
4123 }
4124
4126 void commit();
4130 void commit(finalization_latency &latency) { return commit(&latency); }
4134 finalization_latency result;
4135 commit(&result);
4136 return result;
4137 }
4138
4144 bool checkpoint(finalization_latency &latency) { return checkpoint(&latency); }
4147 std::pair<bool, finalization_latency> checkpoint_get_latency() {
4148 finalization_latency latency;
4149 bool result = checkpoint(&latency);
4150 return std::make_pair(result, latency);
4151 }
4152
4162 finalization_latency result;
4163 commit_embark_read(&result);
4164 return result;
4165 }
4166
4169 bool amend(bool dont_wait = false);
4170};
4171
4179protected:
4181
4182public:
4184 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4185 cursor(const cursor &) noexcept = default;
4186 cursor &operator=(const cursor &) noexcept = default;
4187 inline cursor &operator=(cursor &&) noexcept;
4188 inline cursor(cursor &&) noexcept;
4189 inline ~cursor() noexcept;
4190 cursor_managed clone(void *your_context = nullptr) const;
4191 inline cursor &assign(const cursor &);
4192 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
4193 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const noexcept { return handle_; }
4194 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *() noexcept { return handle_; }
4195 MDBX_CXX14_CONSTEXPR const MDBX_cursor *handle() const noexcept { return handle_; }
4197 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept {
4198 return a.handle_ == b.handle_;
4199 }
4200 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept {
4201 return a.handle_ != b.handle_;
4202 }
4203
4204 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4205 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4206
4207 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4208 return compare_position(*this, other, ignore_nested) < 0;
4209 }
4210
4211 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4212 return compare_position(*this, other, ignore_nested) <= 0;
4213 }
4214
4215 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4216 return compare_position(*this, other, ignore_nested) == 0;
4217 }
4218
4219 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4220 return compare_position(*this, other, ignore_nested) > 0;
4221 }
4222
4223 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4224 return compare_position(*this, other, ignore_nested) >= 0;
4225 }
4226
4228 inline void *get_context() const noexcept;
4229
4231 inline cursor &set_context(void *your_context);
4232
4239
4246
4249
4253
4254 /* Doubtless cursor positioning at a specified key. */
4260
4261 /* Doubtless cursor positioning at a specified key-value pair
4262 * for dupsort/multi-value hives. */
4268
4275
4280 };
4281
4282 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4283 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4284 // и других параметров в bool-throw_notfound.
4285
4286 struct move_result : public pair_result {
4287 inline move_result(const cursor &cursor, bool throw_notfound);
4288 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4289 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4290 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4291 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4292 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4293 bool throw_notfound);
4294 move_result(const move_result &) noexcept = default;
4295 move_result &operator=(const move_result &) noexcept = default;
4296 };
4297
4298 struct estimate_result : public pair {
4303 : estimate_result(cursor, operation, key, slice::invalid()) {}
4304 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4305 estimate_result(const estimate_result &) noexcept = default;
4306 estimate_result &operator=(const estimate_result &) noexcept = default;
4307 };
4308
4309protected:
4310 /* fake `const`, but for specific move/get operations */
4311 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4312
4313 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4314
4315public:
4316 template <typename CALLABLE_PREDICATE>
4317 bool scan_until(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4318 struct wrapper : public exception_thunk {
4319 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4320 auto thunk = static_cast<wrapper *>(context);
4321 assert(thunk->is_clean());
4322 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4323 try {
4324 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4325 } catch (... /* capture any exception to rethrow it over C code */) {
4326 thunk->capture();
4327 return MDBX_RESULT_TRUE;
4328 }
4329 }
4330 } thunk;
4332 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4333 thunk);
4334 }
4335
4336 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4337 return scan_until(std::move(predicate), backward ? last : first, backward ? previous : next);
4338 }
4339
4340 template <typename CALLABLE_PREDICATE>
4341 bool scan_until_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4342 move_operation turn = next) {
4343 struct wrapper : public exception_thunk {
4344 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4345 auto thunk = static_cast<wrapper *>(context);
4346 assert(thunk->is_clean());
4347 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4348 try {
4349 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4350 } catch (... /* capture any exception to rethrow it over C code */) {
4351 thunk->capture();
4352 return MDBX_RESULT_TRUE;
4353 }
4354 }
4355 } thunk;
4356 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4357 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4358 thunk);
4359 }
4360
4361 template <typename CALLABLE_PREDICATE>
4362 bool scan_until_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4363 move_operation turn = next) {
4364 struct wrapper : public exception_thunk {
4365 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4366 auto thunk = static_cast<wrapper *>(context);
4367 assert(thunk->is_clean());
4368 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4369 try {
4370 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4371 } catch (... /* capture any exception to rethrow it over C code */) {
4372 thunk->capture();
4373 return MDBX_RESULT_TRUE;
4374 }
4375 }
4376 } thunk;
4377 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4378 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4379 thunk);
4380 }
4381
4382 move_result move(move_operation operation, bool throw_notfound) {
4383 return move_result(*this, operation, throw_notfound);
4384 }
4385 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4386 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4387 }
4388 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4389 return move_result(*this, operation, key, value, throw_notfound);
4390 }
4391 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4392 return move(operation, &key, &value, throw_notfound);
4393 }
4394
4395 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4396 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4397 move_result to_previous_last_multi(bool throw_notfound = true) {
4398 return move(multi_prevkey_lastvalue, throw_notfound);
4399 }
4400 move_result to_current_first_multi(bool throw_notfound = true) {
4401 return move(multi_currentkey_firstvalue, throw_notfound);
4402 }
4403 move_result to_current_prev_multi(bool throw_notfound = true) {
4404 return move(multi_currentkey_prevvalue, throw_notfound);
4405 }
4406 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4407 move_result to_current_next_multi(bool throw_notfound = true) {
4408 return move(multi_currentkey_nextvalue, throw_notfound);
4409 }
4410 move_result to_current_last_multi(bool throw_notfound = true) {
4411 return move(multi_currentkey_lastvalue, throw_notfound);
4412 }
4413 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4414 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4415 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4416
4417 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4418 return move(key_lesser_than, key, throw_notfound);
4419 }
4420 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4421 return move(key_lesser_or_equal, key, throw_notfound);
4422 }
4423 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4424 return move(key_equal, key, throw_notfound);
4425 }
4426 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4427 return move(key_exact, key, throw_notfound);
4428 }
4429 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4430 return move(key_greater_or_equal, key, throw_notfound);
4431 }
4432 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4433 return move(key_greater_than, key, throw_notfound);
4434 }
4435
4436 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4437 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4438 }
4439 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4440 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4441 }
4442 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4443 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4444 }
4445 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4446 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4447 }
4448 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4449 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4450 }
4451
4452 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4453 return move(pair_lesser_than, key, value, throw_notfound);
4454 }
4455 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4456 return move(pair_lesser_or_equal, key, value, throw_notfound);
4457 }
4458 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4459 return move(pair_equal, key, value, throw_notfound);
4460 }
4461 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4462 return move(pair_exact, key, value, throw_notfound);
4463 }
4464 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4465 return move(pair_greater_or_equal, key, value, throw_notfound);
4466 }
4467 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4468 return move(pair_greater_than, key, value, throw_notfound);
4469 }
4470
4471 inline bool seek(const slice &key);
4472 inline move_result find(const slice &key, bool throw_notfound = true);
4473 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4474 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4475
4477 inline size_t count_multivalue() const;
4478
4479 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4480 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4481 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4482
4483 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4484 return move(seek_and_batch_samelength, key, throw_notfound);
4485 }
4486
4487 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4488 return move(batch_samelength, throw_notfound);
4489 }
4490
4491 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4492 return move(batch_samelength_next, throw_notfound);
4493 }
4494
4495 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4496 return move(batch_samelength_previous, throw_notfound);
4497 }
4498
4499 inline bool eof() const;
4500 inline bool on_first() const;
4501 inline bool on_last() const;
4502 inline bool on_first_multival() const;
4503 inline bool on_last_multival() const;
4504 inline estimate_result estimate(const slice &key, const slice &value) const;
4505 inline estimate_result estimate(const slice &key) const;
4506 inline estimate_result estimate(move_operation operation) const;
4507 inline estimate_result estimate(move_operation operation, const slice &key) const;
4508
4509 static inline ptrdiff_t distance_between(const cursor from, const cursor to,
4510 unsigned deepness = /* enough to cover whole tree height */ 42);
4511 inline ptrdiff_t distance_from(const cursor from,
4512 unsigned deepness = /* enough to cover whole tree height */ 42) const {
4513 return distance_between(from, *this, deepness);
4514 }
4515 inline ptrdiff_t distance_to(const cursor to, unsigned deepness = /* enough to cover whole tree height */ 42) const {
4516 return distance_between(*this, to, deepness);
4517 }
4518 inline ptrdiff_t distance_from_first(unsigned deepness = /* enough to cover whole tree height */ 42) const {
4519 return distance_between(nullptr, *this, deepness);
4520 }
4521 inline ptrdiff_t distance_to_end(unsigned deepness = /* enough to cover whole tree height */ 42) const {
4522 return distance_between(*this, nullptr, deepness);
4523 }
4524
4525 inline bool scroll(intptr_t distable, unsigned deepness = /* enough to cover whole tree height */ 42,
4526 bool throw_notfound = true);
4527
4528 static inline bool distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size,
4529 unsigned deepness = /* enough to cover whole tree height */ 42);
4530
4531 static inline bool distribute(const cursor from, const cursor to, const std::vector<cursor> &cursors,
4532 unsigned deepness = /* enough to cover whole tree height */ 42);
4533
4534 static inline bool distribute(const cursor from, const cursor to, const std::vector<cursor_managed> &cursors,
4535 unsigned deepness = /* enough to cover whole tree height */ 42);
4536
4537 //----------------------------------------------------------------------------
4538
4540 inline void renew(::mdbx::txn &txn);
4541
4543 inline void bind(::mdbx::txn &txn, ::mdbx::map_handle map_handle);
4544
4546 inline void unbind();
4547
4549 inline ::mdbx::txn txn() const;
4550 inline map_handle map() const;
4551
4552 inline operator ::mdbx::txn() const { return txn(); }
4553 inline operator ::mdbx::map_handle() const { return map(); }
4554
4555 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4556 inline void put(const slice &key, slice value, put_mode mode);
4557 inline void insert(const slice &key, slice value);
4558 inline value_result try_insert(const slice &key, slice value);
4559 inline slice insert_reserve(const slice &key, size_t value_length);
4560 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4561
4562 inline void upsert(const slice &key, const slice &value);
4563 inline slice upsert_reserve(const slice &key, size_t value_length);
4564
4566 void update_current(const slice &value);
4568 slice reverse_current(size_t value_length);
4569
4570 inline void update(const slice &key, const slice &value);
4571 inline bool try_update(const slice &key, const slice &value);
4572 inline slice update_reserve(const slice &key, size_t value_length);
4573 inline value_result try_update_reserve(const slice &key, size_t value_length);
4574
4575 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4576 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4577 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4578 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4579
4581 inline bool erase(bool whole_multivalue = false);
4582
4585 inline bool erase(const slice &key, bool whole_multivalue = true);
4586
4589 inline bool erase(const slice &key, const slice &value);
4590
4591 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4592 size_t values_count, put_mode mode, bool allow_partial = false);
4593 template <typename VALUE>
4594 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4595 bool allow_partial = false) {
4596 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4597 !::std::is_array<VALUE>::value,
4598 "Must be a standard layout type!");
4599 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4600 }
4601 template <typename VALUE>
4602 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4603 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4604 }
4605};
4606
4614class LIBMDBX_API_TYPE cursor_managed : public cursor {
4615 using inherited = cursor;
4616 friend class txn;
4618 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4619
4620public:
4622 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4623 if (MDBX_UNLIKELY(!handle_))
4624 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4625 }
4626
4628 void close();
4629
4630 cursor_managed(cursor_managed &&) = default;
4631 cursor_managed &operator=(cursor_managed &&other) noexcept;
4632
4633 inline MDBX_cursor *withdraw_handle() noexcept {
4635 handle_ = nullptr;
4636 return handle;
4637 }
4638
4639 cursor_managed(const cursor_managed &) = delete;
4640 cursor_managed &operator=(const cursor_managed &) = delete;
4642};
4643
4644//==============================================================================
4645//
4646// Inline body of the libmdbx C++ API
4647//
4648
4649MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4650MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4651
4652static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4653#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4654 if (::std::is_constant_evaluated()) {
4655 size_t i = 0;
4656 if (c_str)
4657 while (c_str[i])
4658 ++i;
4659 return i;
4660 }
4661#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4662#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4663 return c_str ? ::std::string_view(c_str).length() : 0;
4664#else
4665 return c_str ? ::std::strlen(c_str) : 0;
4666#endif
4667}
4668
4669MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4670#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4671 if (::std::is_constant_evaluated()) {
4672 for (size_t i = 0; i < bytes; ++i)
4673 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4674 return dest;
4675 } else
4676#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4677 return ::std::memcpy(dest, src, bytes);
4678}
4679
4680static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4681#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4682 if (::std::is_constant_evaluated()) {
4683 for (size_t i = 0; i < bytes; ++i) {
4684 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4685 if (diff)
4686 return diff;
4687 }
4688 return 0;
4689 } else
4690#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4691 return ::std::memcmp(a, b, bytes);
4692}
4693
4694//------------------------------------------------------------------------------
4695
4698
4702
4706
4707inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4708
4709inline void exception_thunk::capture() noexcept {
4710 assert(is_clean());
4711 captured_ = ::std::current_exception();
4712}
4713
4715 if (captured_)
4716 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4717}
4718
4719//------------------------------------------------------------------------------
4720
4721MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4722
4723inline error &error::operator=(MDBX_error_t error_code) noexcept {
4724 code_ = error_code;
4725 return *this;
4726}
4727
4728MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4729
4730MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4731
4732MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4733
4734MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4735
4736MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4737
4739 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4740}
4741
4742MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4743
4748
4749inline void error::throw_exception(int error_code) {
4750 const error trouble(static_cast<MDBX_error_t>(error_code));
4751 trouble.throw_exception();
4752}
4753
4754inline void error::throw_on_failure() const {
4756 MDBX_CXX20_UNLIKELY throw_exception();
4757}
4758
4759inline void error::success_or_throw() const {
4760 if (MDBX_UNLIKELY(!is_success()))
4761 MDBX_CXX20_UNLIKELY throw_exception();
4762}
4763
4764inline void error::success_or_throw(const exception_thunk &thunk) const {
4765 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4766 if (MDBX_UNLIKELY(!is_success())) {
4767 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4768 else throw_exception();
4769 }
4770}
4771
4772inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4773 if (MDBX_UNLIKELY(ptr == nullptr))
4774 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4775}
4776
4777inline void error::throw_on_failure(int error_code) {
4778 error rc(static_cast<MDBX_error_t>(error_code));
4779 rc.throw_on_failure();
4780}
4781
4782inline void error::success_or_throw(MDBX_error_t error_code) {
4783 error rc(error_code);
4784 rc.success_or_throw();
4785}
4786
4787inline bool error::boolean_or_throw(int error_code) {
4788 switch (error_code) {
4789 case MDBX_RESULT_FALSE:
4790 return false;
4791 case MDBX_RESULT_TRUE:
4792 return true;
4793 default:
4794 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4795 }
4796}
4797
4798inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4799 error rc(static_cast<MDBX_error_t>(error_code));
4800 rc.success_or_throw(thunk);
4801}
4802
4803inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4804 if (MDBX_UNLIKELY(!thunk.is_clean()))
4805 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4806 return boolean_or_throw(error_code);
4807}
4808
4809MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4810
4812 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4813
4814MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4815 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4816
4817MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4818
4819MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4820
4821MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4822
4823MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4824
4825inline slice &slice::assign(const void *ptr, size_t bytes) {
4826 iov_base = const_cast<void *>(ptr);
4827 iov_len = check_length(bytes);
4828 return *this;
4829}
4830
4831inline slice &slice::assign(const slice &src) noexcept {
4832 iov_base = src.iov_base;
4833 iov_len = src.iov_len;
4834 return *this;
4835}
4836
4837inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4838
4839slice &slice::assign(slice &&src) noexcept {
4840 assign(src);
4841 src.invalidate();
4842 return *this;
4843}
4844
4846 assign(src.iov_base, src.iov_len);
4847 src.iov_base = nullptr;
4848 return *this;
4849}
4850
4851inline slice &slice::assign(const void *begin, const void *end) {
4852 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4853}
4854
4855inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4856
4857inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4858
4859inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4860
4861MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4862
4863MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4864
4865MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4866
4868
4869MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4870
4871MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4872
4873MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4874
4876
4877MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4878
4879MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4880
4881MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4882
4883MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4884
4885MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4886
4888 iov_len = check_length(bytes);
4889 return *this;
4890}
4891
4893 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4894 return set_length(static_cast<const char *>(ptr) - char_ptr());
4895}
4896
4897MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4898
4899MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4900
4901MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4902
4903MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4904
4905MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4906
4908 iov_base = nullptr;
4909 iov_len = 0;
4910}
4911
4912inline void slice::remove_prefix(size_t n) noexcept {
4913 assert(n <= size());
4914 iov_base = static_cast<byte *>(iov_base) + n;
4915 iov_len -= n;
4916}
4917
4918inline void slice::safe_remove_prefix(size_t n) {
4919 if (MDBX_UNLIKELY(n > size()))
4920 MDBX_CXX20_UNLIKELY throw_out_range();
4921 remove_prefix(n);
4922}
4923
4924inline void slice::remove_suffix(size_t n) noexcept {
4925 assert(n <= size());
4926 iov_len -= n;
4927}
4928
4929inline void slice::safe_remove_suffix(size_t n) {
4930 if (MDBX_UNLIKELY(n > size()))
4931 MDBX_CXX20_UNLIKELY throw_out_range();
4932 remove_suffix(n);
4933}
4934
4935MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4936 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4937}
4938
4939MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4940 return length() >= suffix.length() &&
4941 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4942}
4943
4945 size_t h = length() * 3977471;
4946 for (size_t i = 0; i < length(); ++i)
4947 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4948 return h ^ 3863194411 * (h >> 11);
4949}
4950
4951MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4953 return byte_ptr()[n];
4954}
4955
4956MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4957 if (MDBX_UNLIKELY(n >= size()))
4958 MDBX_CXX20_UNLIKELY throw_out_range();
4959 return byte_ptr()[n];
4960}
4961
4962MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4964 return slice(data(), n);
4965}
4966
4967MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4969 return slice(char_ptr() + size() - n, n);
4970}
4971
4972MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4973 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4974 return slice(char_ptr() + from, n);
4975}
4976
4978 if (MDBX_UNLIKELY(n > size()))
4979 MDBX_CXX20_UNLIKELY throw_out_range();
4980 return head(n);
4981}
4982
4984 if (MDBX_UNLIKELY(n > size()))
4985 MDBX_CXX20_UNLIKELY throw_out_range();
4986 return tail(n);
4987}
4988
4989MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4990 if (MDBX_UNLIKELY(n > max_length))
4991 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4992 if (MDBX_UNLIKELY(from > max_length || from + n > size()))
4993 MDBX_CXX20_UNLIKELY throw_out_range();
4994 return middle(from, n);
4995}
4996
4997MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4998 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4999 return diff ? diff
5000 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
5001 : memcmp(a.data(), b.data(), a.length());
5002}
5003
5005 const size_t shortest = ::std::min(a.length(), b.length());
5006 if (MDBX_LIKELY(shortest > 0))
5008 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
5009 if (MDBX_LIKELY(diff != 0))
5010 MDBX_CXX20_LIKELY return diff;
5011 }
5012 return intptr_t(a.length()) - intptr_t(b.length());
5013}
5014
5016 return slice::compare_fast(a, b) == 0;
5017}
5018
5020 return slice::compare_lexicographically(a, b) < 0;
5021}
5022
5024 return slice::compare_lexicographically(a, b) > 0;
5025}
5026
5028 return slice::compare_lexicographically(a, b) <= 0;
5029}
5030
5032 return slice::compare_lexicographically(a, b) >= 0;
5033}
5034
5036 return slice::compare_fast(a, b) != 0;
5037}
5038
5039#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5040MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
5041 const auto cmp = slice::compare_lexicographically(a, b);
5042 return (cmp < 0) ? std::strong_ordering::less
5043 : (cmp > 0) ? std::strong_ordering::greater
5044 : std::strong_ordering::equal;
5045}
5046#endif /* __cpp_impl_three_way_comparison */
5047
5048template <class ALLOCATOR, typename CAPACITY_POLICY>
5050 const allocator_type &alloc)
5051 : inherited(src), silo_(alloc) {
5052 if (!make_reference)
5053 insulate();
5054}
5055
5056template <class ALLOCATOR, typename CAPACITY_POLICY>
5057inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
5058 const allocator_type &alloc)
5059 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
5060
5061template <class ALLOCATOR, typename CAPACITY_POLICY>
5062inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
5063 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
5064}
5065
5066#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
5068
5069#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
5071#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
5072#endif /* !MinGW || MDBX_EXPORTS */
5073
5076
5077//------------------------------------------------------------------------------
5078
5079template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5080inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
5081 if (MDBX_LIKELY(!producer.is_empty()))
5083 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5084 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5085 return result;
5086 }
5088}
5089
5090template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5091inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
5092 if (MDBX_LIKELY(!producer.is_empty()))
5094 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5095 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5096 return result;
5097 }
5099}
5100
5101template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5102inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
5103 string<ALLOCATOR> result(alloc);
5104 if (MDBX_LIKELY(!producer.is_empty()))
5106 result.resize(producer.envisage_result_length());
5107 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5108 }
5109 return result;
5110}
5111
5112template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5113inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
5114 string<ALLOCATOR> result(alloc);
5115 if (MDBX_LIKELY(!producer.is_empty()))
5117 result.resize(producer.envisage_result_length());
5118 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5119 }
5120 return result;
5121}
5122
5123template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
5124 return make_string<ALLOCATOR>(*this, alloc);
5125}
5126
5127template <class ALLOCATOR, typename CAPACITY_POLICY>
5129 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5130}
5131
5132template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
5133 return make_string<ALLOCATOR>(*this, alloc);
5134}
5135
5136template <class ALLOCATOR, typename CAPACITY_POLICY>
5138 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5139}
5140
5141template <class ALLOCATOR> string<ALLOCATOR> to_base64::as_string(const ALLOCATOR &alloc) const {
5142 return make_string<ALLOCATOR>(*this, alloc);
5143}
5144
5145template <class ALLOCATOR, typename CAPACITY_POLICY>
5147 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5148}
5149
5150template <class ALLOCATOR> string<ALLOCATOR> from_hex::as_string(const ALLOCATOR &alloc) const {
5151 return make_string<ALLOCATOR>(*this, alloc);
5152}
5153
5154template <class ALLOCATOR, typename CAPACITY_POLICY>
5156 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5157}
5158
5159template <class ALLOCATOR> string<ALLOCATOR> from_base58::as_string(const ALLOCATOR &alloc) const {
5160 return make_string<ALLOCATOR>(*this, alloc);
5161}
5162
5163template <class ALLOCATOR, typename CAPACITY_POLICY>
5165 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5166}
5167
5168template <class ALLOCATOR> string<ALLOCATOR> from_base64::as_string(const ALLOCATOR &alloc) const {
5169 return make_string<ALLOCATOR>(*this, alloc);
5170}
5171
5172template <class ALLOCATOR, typename CAPACITY_POLICY>
5174 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5175}
5176
5177template <class ALLOCATOR>
5178inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
5179 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
5180}
5181
5182template <class ALLOCATOR>
5183inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5184 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5185}
5186
5187template <class ALLOCATOR>
5188inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5189 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5190}
5191
5192template <class ALLOCATOR, class CAPACITY_POLICY>
5193inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5194 const ALLOCATOR &alloc) const {
5195 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5196}
5197
5198template <class ALLOCATOR, class CAPACITY_POLICY>
5199inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
5200 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5201}
5202
5203template <class ALLOCATOR, class CAPACITY_POLICY>
5204inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
5205 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5206}
5207
5208template <class ALLOCATOR, class CAPACITY_POLICY>
5209inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5210 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5211}
5212
5213template <class ALLOCATOR, class CAPACITY_POLICY>
5214inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5215 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5216}
5217
5218template <class ALLOCATOR, class CAPACITY_POLICY>
5219inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5220 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5221}
5222
5223//------------------------------------------------------------------------------
5224
5225MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5226 const auto diff = slice::compare_fast(a.key, b.key);
5227 return diff ? diff : slice::compare_fast(a.value, b.value);
5228}
5229
5230MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5231 const auto diff = slice::compare_lexicographically(a.key, b.key);
5232 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5233}
5234
5236 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5237 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5238 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5239}
5240
5242 return pair::compare_lexicographically(a, b) < 0;
5243}
5244
5246 return pair::compare_lexicographically(a, b) > 0;
5247}
5248
5250 return pair::compare_lexicographically(a, b) <= 0;
5251}
5252
5254 return pair::compare_lexicographically(a, b) >= 0;
5255}
5256
5258 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5259 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5260 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5261}
5262
5263#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5264MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5266}
5267#endif /* __cpp_impl_three_way_comparison */
5268
5270template <typename BUFFER>
5272
5275
5276//------------------------------------------------------------------------------
5277
5278inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
5279inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
5280inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
5281
5282MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5283 return !from_hex(*this, ignore_spaces).is_erroneous();
5284}
5285
5286MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5287 return !from_base58(*this, ignore_spaces).is_erroneous();
5288}
5289
5290MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5291 return !from_base64(*this, ignore_spaces).is_erroneous();
5292}
5293
5294//------------------------------------------------------------------------------
5295
5297
5298inline env &env::operator=(env &&other) noexcept {
5299 if (this != &other) {
5300 handle_ = other.handle_;
5301 other.handle_ = nullptr;
5302 }
5303 return *this;
5304}
5305
5306inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5307
5308inline env::~env() noexcept {
5309#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
5310 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5311#endif
5312}
5313
5317 return *this;
5318}
5319
5320inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5321 size_now = size_lower = lower;
5322 size_upper = upper;
5324 return *this;
5325}
5326
5330
5334
5335inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5336
5337inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5338
5339inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5340 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5341 if (result < 0)
5342 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5343 return static_cast<size_t>(result);
5344}
5345
5346inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5347 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5348 if (result < 0)
5349 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5350 return static_cast<size_t>(result);
5351}
5352
5353inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5354
5355inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5356
5357inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5358 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5359 if (result < 0)
5360 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5361 return static_cast<size_t>(result);
5362}
5363
5364inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5365 return key_max(pagesize, MDBX_db_flags_t(mode));
5366}
5367
5368inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
5369 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5370 if (result < 0)
5371 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5372 return static_cast<size_t>(result);
5373}
5374
5376
5377inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5378
5380
5381inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5382 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5383 if (result < 0)
5384 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5385 return static_cast<size_t>(result);
5386}
5387
5388inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5389 return value_max(pagesize, MDBX_db_flags_t(mode));
5390}
5391
5392inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
5393 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5394 if (result < 0)
5395 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5396 return static_cast<size_t>(result);
5397}
5398
5400
5401inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5402 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5403 if (result < 0)
5404 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5405 return static_cast<size_t>(result);
5406}
5407
5408inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5409 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5410}
5411
5413 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5414 if (result < 0)
5415 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5416 return static_cast<size_t>(result);
5417}
5418
5422
5423inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5424 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5425 if (result < 0)
5426 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5427 return static_cast<size_t>(result);
5428}
5429
5430inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5431 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5432}
5433
5435 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5436 if (result < 0)
5437 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5438 return static_cast<size_t>(result);
5439}
5440
5444
5445inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5446 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5447 if (result < 0)
5448 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5449 return static_cast<size_t>(result);
5450}
5451
5452inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5453
5461
5463
5467
5471
5475
5476inline env::stat env::get_stat() const {
5477 env::stat r;
5478 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5479 return r;
5480}
5481
5482inline env::stat env::get_stat(const txn &txn) const {
5483 env::stat r;
5485 return r;
5486}
5487
5488inline env::info env::get_info() const {
5489 env::info r;
5490 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5491 return r;
5492}
5493
5494inline env::info env::get_info(const txn &txn) const {
5495 env::info r;
5497 return r;
5498}
5499
5501 filehandle fd;
5503 return fd;
5504}
5505
5507 unsigned bits = 0;
5509 return MDBX_env_flags_t(bits);
5510}
5511
5512inline unsigned env::max_readers() const {
5513 unsigned r;
5515 return r;
5516}
5517
5518inline unsigned env::max_maps() const {
5519 unsigned r;
5521 return r;
5522}
5523
5524inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5525
5526inline env &env::set_context(void *ptr) {
5528 return *this;
5529}
5530
5531inline env &env::set_sync_threshold(size_t bytes) {
5533 return *this;
5534}
5535
5536inline size_t env::sync_threshold() const {
5537 size_t bytes;
5539 return bytes;
5540}
5541
5542inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5544 return *this;
5545}
5546
5547inline unsigned env::sync_period__seconds_16dot16() const {
5548 unsigned seconds_16dot16;
5550 return seconds_16dot16;
5551}
5552
5554 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5555}
5556
5557inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5558
5559#if __cplusplus >= 201103L
5560inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5561
5563#endif
5564
5565inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5567 return *this;
5568}
5569
5570inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5571 uint64_t value;
5573 return value;
5574}
5575
5576inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
5578 return *this;
5579}
5580
5581inline env &env::set_geometry(const geometry &geo) {
5583 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5584 return *this;
5585}
5586
5587inline bool env::sync_to_disk(bool force, bool nonblock) {
5588 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5589 switch (err) {
5590 case MDBX_SUCCESS /* flush done */:
5591 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5592 return true;
5593 case MDBX_BUSY /* the environment is used by other thread */:
5594 return false;
5595 default:
5596 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5597 }
5598}
5599
5601
5603env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5604 size_t retained) noexcept
5606 bytes_retained(retained) {}
5607
5608template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5609 struct reader_visitor_thunk : public exception_thunk {
5610 VISITOR &visitor_;
5611 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5612 size_t used, size_t retained) noexcept {
5613 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5614 assert(thunk->is_clean());
5615 try {
5616 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5617 return loop_control(thunk->visitor_(info, number));
5618 } catch (... /* capture any exception to rethrow it over C code */) {
5619 thunk->capture();
5621 }
5622 }
5623 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5624 };
5625 reader_visitor_thunk thunk(visitor);
5626 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5627 thunk.rethrow_captured();
5628 return rc;
5629}
5630
5631inline unsigned env::check_readers() {
5632 int dead_count;
5633 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5634 MDBX_INLINE_API_ASSERT(dead_count >= 0);
5635 return static_cast<unsigned>(dead_count);
5636}
5637
5642
5643inline MDBX_hsr_func env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5644
5646 ::MDBX_txn *ptr;
5648 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5649 return txn_managed(ptr);
5650}
5651
5653 ::MDBX_txn *ptr;
5655 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5656 return txn_managed(ptr);
5657}
5658
5659inline txn_managed env::start_write(bool dont_wait) {
5660 ::MDBX_txn *ptr;
5663 MDBX_INLINE_API_ASSERT(ptr != nullptr || dont_wait);
5664 return txn_managed(ptr);
5665}
5666
5668 ::MDBX_txn *ptr;
5670 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5671 return txn_managed(ptr);
5672}
5673
5675
5677
5678inline txn &txn::operator=(txn &&other) noexcept {
5679 if (this != &other) {
5680 handle_ = other.handle_;
5681 other.handle_ = nullptr;
5682 }
5683 return *this;
5684}
5685
5686inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5687
5688inline txn::~txn() noexcept {
5689#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
5690 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5691#endif
5692}
5693
5694inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5695
5696inline txn &txn::set_context(void *ptr) {
5698 return *this;
5699}
5700
5701inline bool txn::is_dirty(const void *ptr) const {
5702 int err = ::mdbx_is_dirty(handle_, ptr);
5703 switch (err) {
5704 default:
5705 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5706 case MDBX_RESULT_TRUE:
5707 return true;
5708 case MDBX_RESULT_FALSE:
5709 return false;
5710 }
5711}
5712
5713inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5714
5716 const int bits = mdbx_txn_flags(handle_);
5718 return static_cast<MDBX_txn_flags_t>(bits);
5719}
5720
5721inline uint64_t txn::id() const {
5722 const uint64_t txnid = mdbx_txn_id(handle_);
5724 return txnid;
5725}
5726
5728
5730
5732
5733inline txn_managed txn::clone(void *context) const {
5734 MDBX_txn *ptr = nullptr;
5736 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5737 return txn_managed(ptr);
5738}
5739
5740inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
5741 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
5742 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
5743 MDBX_INLINE_API_ASSERT(txn_for_renew_into_clone.handle_ != nullptr);
5744}
5745
5746inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5747
5748inline bool txn::unpark_reading(bool restart_if_ousted) {
5749 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5750}
5751
5752inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5753 txn::info r;
5754 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5755 return r;
5756}
5757
5759 MDBX_cursor *ptr;
5761 return cursor_managed(ptr);
5762}
5763
5764inline size_t txn::release_all_cursors(bool unbind) const {
5765 size_t count;
5767 return count;
5768}
5769
5770inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5771 const ::mdbx::value_mode value_mode) const {
5772 map_handle map;
5775 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5776 return map;
5777}
5778
5779inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5780 const ::mdbx::value_mode value_mode) const {
5781 map_handle map;
5784 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5785 return map;
5786}
5787
5788inline map_handle txn::open_map_accede(const slice &name) const {
5789 map_handle map;
5791 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5792 return map;
5793}
5794
5795inline map_handle txn::open_map_accede(const char *name) const {
5796 map_handle map;
5798 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5799 return map;
5800}
5801
5802inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5803 const ::mdbx::value_mode value_mode) {
5804 map_handle map;
5807 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5808 return map;
5809}
5810
5811inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5812 const ::mdbx::value_mode value_mode) {
5813 map_handle map;
5816 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5817 return map;
5818}
5819
5821
5823
5824inline void txn::rename_map(map_handle map, const char *new_name) {
5826}
5827
5828inline void txn::rename_map(map_handle map, const slice &new_name) {
5830}
5831
5832inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5833 const ::mdbx::value_mode value_mode) const {
5834 return open_map(slice(name), key_mode, value_mode);
5835}
5836
5837inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5838
5839inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5840 const ::mdbx::value_mode value_mode) {
5841 return create_map(slice(name), key_mode, value_mode);
5842}
5843
5844inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5845 return drop_map(slice(name), throw_if_absent);
5846}
5847
5848inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5849 return clear_map(slice(name), throw_if_absent);
5850}
5851
5852inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5853
5855 txn::map_stat r;
5856 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5857 return r;
5858}
5859
5860inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5861 uint32_t r;
5863 return r;
5864}
5865
5871
5876
5878 txn::canary r;
5880 return r;
5881}
5882
5883inline uint64_t txn::sequence(map_handle map) const {
5884 uint64_t result;
5886 return result;
5887}
5888
5889inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5890 uint64_t result;
5891 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5892 return result;
5893}
5894
5895inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5896 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5897}
5898
5899inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5900 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5901}
5902
5903inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5904 return compare_keys(map, a.key, b.key);
5905}
5906
5907inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5908 return compare_values(map, a.value, b.value);
5909}
5910
5911inline slice txn::get(map_handle map, const slice &key) const {
5912 slice result;
5913 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5914 return result;
5915}
5916
5917inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5918 slice result;
5919 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5920 return result;
5921}
5922
5923inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5924 slice result;
5925 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5926 switch (err) {
5927 case MDBX_SUCCESS:
5928 return result;
5929 case MDBX_NOTFOUND:
5930 return value_at_absence;
5931 default:
5932 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5933 }
5934}
5935
5936inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5937 slice result;
5938 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5939 switch (err) {
5940 case MDBX_SUCCESS:
5941 return result;
5942 case MDBX_NOTFOUND:
5943 return value_at_absence;
5944 default:
5945 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5946 }
5947}
5948
5950 pair result(key, slice());
5951 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5952 return pair_result(result.key, result.value, exact);
5953}
5954
5955inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5956 pair result{key, slice()};
5957 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5958 switch (err) {
5959 case MDBX_SUCCESS:
5960 return pair_result{result.key, result.value, true};
5961 case MDBX_RESULT_TRUE:
5962 return pair_result{result.key, result.value, false};
5963 case MDBX_NOTFOUND:
5964 return pair_result{key, value_at_absence, false};
5965 default:
5966 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5967 }
5968}
5969
5970inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5971 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5972 /* coverity[OVERRUN] */
5973 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5974}
5975
5976inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5977 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5978 /* coverity[OVERRUN] */
5979 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5980}
5981
5982inline void txn::insert(map_handle map, const slice &key, slice value) {
5983 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5984 /* coverity[OVERRUN] */
5985 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5987}
5988
5989inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5990 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5991 /* coverity[OVERRUN] */
5992 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5994 switch (err) {
5995 case MDBX_SUCCESS:
5996 return value_result{slice(), true};
5997 case MDBX_KEYEXIST:
5998 return value_result{value, false};
5999 default:
6000 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6001 }
6002}
6003
6004inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
6005 slice result(nullptr, value_length);
6006 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6007 /* coverity[OVERRUN] */
6008 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
6010 return result;
6011}
6012
6013inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
6014 slice result(nullptr, value_length);
6015 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6016 /* coverity[OVERRUN] */
6017 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
6019 switch (err) {
6020 case MDBX_SUCCESS:
6021 return value_result{result, true};
6022 case MDBX_KEYEXIST:
6023 return value_result{result, false};
6024 default:
6025 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6026 }
6027}
6028
6029inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
6030 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6031 /* coverity[OVERRUN] */
6032 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6033}
6034
6035inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
6036 slice result(nullptr, value_length);
6037 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6038 /* coverity[OVERRUN] */
6040 return result;
6041}
6042
6043inline void txn::update(map_handle map, const slice &key, const slice &value) {
6044 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6045 /* coverity[OVERRUN] */
6046 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6047}
6048
6049inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
6050 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6051 /* coverity[OVERRUN] */
6052 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6053 switch (err) {
6054 case MDBX_SUCCESS:
6055 return true;
6056 case MDBX_NOTFOUND:
6057 return false;
6058 default:
6059 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6060 }
6061}
6062
6063inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
6064 slice result(nullptr, value_length);
6065 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6066 /* coverity[OVERRUN] */
6068 return result;
6069}
6070
6071inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
6072 slice result(nullptr, value_length);
6073 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6074 /* coverity[OVERRUN] */
6075 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6076 switch (err) {
6077 case MDBX_SUCCESS:
6078 return value_result{result, true};
6079 case MDBX_NOTFOUND:
6080 return value_result{slice(), false};
6081 default:
6082 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6083 }
6084}
6085
6086inline bool txn::erase(map_handle map, const slice &key) {
6087 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6088 switch (err) {
6089 case MDBX_SUCCESS:
6090 return true;
6091 case MDBX_NOTFOUND:
6092 return false;
6093 default:
6094 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6095 }
6096}
6097
6098inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6099 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
6100 switch (err) {
6101 case MDBX_SUCCESS:
6102 return true;
6103 case MDBX_NOTFOUND:
6104 return false;
6105 default:
6106 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6107 }
6108}
6109
6110inline void txn::replace(map_handle map, const slice &key, slice &old_value, const slice &new_value) {
6111 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6112 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6113}
6114
6115template <class BUFFER, typename ALLOCATOR>
6116inline BUFFER txn::extract(map_handle map, const slice &key, const ALLOCATOR &alloc) {
6117 typename BUFFER::data_preserver result(alloc);
6119 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.data, MDBX_CURRENT, result, &result), result);
6120 return result.data;
6121}
6122
6123template <class BUFFER, typename ALLOCATOR>
6124inline BUFFER txn::replace(map_handle map, const slice &key, const slice &new_value, const ALLOCATOR &alloc) {
6125 typename BUFFER::data_preserver result(alloc);
6126 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.data,
6127 MDBX_CURRENT, result, &result),
6128 result);
6129 return result.data;
6130}
6131
6132template <class BUFFER, typename ALLOCATOR>
6133inline BUFFER txn::replace_reserve(map_handle map, const slice &key, size_t length, slice &new_value_reservation,
6134 const ALLOCATOR &alloc) {
6135 new_value_reservation.iov_base = nullptr;
6136 new_value_reservation.iov_len = length;
6137 typename BUFFER::data_preserver result(alloc);
6138 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value_reservation, &result.data,
6139 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6140 result);
6141 return result.data;
6142}
6143
6144inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
6145 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6146 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
6147}
6148
6149inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
6150 const void *values_array, size_t values_count, put_mode mode,
6151 bool allow_partial) {
6152 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6153 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6154 switch (err) {
6155 case MDBX_SUCCESS:
6156 MDBX_CXX20_LIKELY break;
6157 case MDBX_KEYEXIST:
6158 if (allow_partial)
6159 break;
6161 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6162 default:
6163 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6164 }
6165 return args[1].iov_len /* done item count */;
6166}
6167
6168inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
6169 ptrdiff_t result;
6170 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6171 return result;
6172}
6173
6174inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6175 ptrdiff_t result;
6176 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6177 return result;
6178}
6179
6180inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6181 ptrdiff_t result;
6182 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6183 return result;
6184}
6185
6186inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6187 ptrdiff_t result;
6188 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6189 return result;
6190}
6191
6193
6194inline cursor &cursor::assign(const cursor &src) {
6196 return *this;
6197}
6198
6199inline cursor &cursor::operator=(cursor &&other) noexcept {
6200 if (this != &other) {
6201 handle_ = other.handle_;
6202 other.handle_ = nullptr;
6203 }
6204 return *this;
6205}
6206
6207inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6208
6209inline cursor::~cursor() noexcept {
6210#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
6211 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6212#endif
6213}
6214
6215inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6216
6217inline cursor &cursor::set_context(void *ptr) {
6219 return *this;
6220}
6221
6222inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6223 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6224}
6225
6226inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6227 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6228 MDBX_INLINE_API_ASSERT(compare_position_nothrow(right, left, ignore_nested) == -diff);
6229 if (MDBX_LIKELY(int16_t(diff) == diff))
6230 MDBX_CXX20_LIKELY return int(diff);
6231 else
6233}
6234
6235inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6236 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6237}
6238
6240 bool throw_notfound)
6241 : pair_result(key, value, false) {
6242 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6243}
6244
6245inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6246 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6247 switch (err) {
6248 case MDBX_SUCCESS:
6249 MDBX_CXX20_LIKELY return true;
6250 case MDBX_RESULT_TRUE:
6251 return false;
6252 case MDBX_NOTFOUND:
6253 if (!throw_notfound)
6254 return false;
6255 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6256 default:
6257 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6258 }
6259}
6260
6262 const slice &value)
6263 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6264 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6265}
6266
6267inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6268 ptrdiff_t result;
6269 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6270 return result;
6271}
6272
6273inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6274 ptrdiff_t result;
6276 return result;
6277}
6278
6279inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6280 return move(key_exact, key, throw_notfound);
6281}
6282
6283inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6284 return move(key_lowerbound, key, throw_notfound);
6285}
6286
6287inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6288 return move(key_greater_than, key, throw_notfound);
6289}
6290
6291inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6292 return move(multi_find_pair, key, value, throw_notfound);
6293}
6294
6295inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6296 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6297}
6298
6299inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6300 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6301}
6302
6303inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6304
6305inline size_t cursor::count_multivalue() const {
6306 size_t result;
6308 return result;
6309}
6310
6311inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6312
6314
6316
6318
6320
6321inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6322 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6323}
6324
6326 return estimate_result(*this, key_lowerbound, key);
6327}
6328
6330 return estimate_result(*this, operation);
6331}
6332
6334 return estimate_result(*this, operation, key);
6335}
6336
6338
6342
6344
6345inline txn cursor::txn() const {
6347 return ::mdbx::txn(txn);
6348}
6349
6350inline map_handle cursor::map() const {
6351 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6352 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6354 return map_handle(dbi);
6355}
6356
6357inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6358 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6359}
6360
6361inline void cursor::put(const slice &key, slice value, put_mode mode) {
6362 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6363}
6364
6365inline void cursor::insert(const slice &key, slice value) {
6367 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6368}
6369
6370inline value_result cursor::try_insert(const slice &key, slice value) {
6371 const int err =
6372 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6373 switch (err) {
6374 case MDBX_SUCCESS:
6375 return value_result{slice(), true};
6376 case MDBX_KEYEXIST:
6377 return value_result{value, false};
6378 default:
6379 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6380 }
6381}
6382
6383inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6384 slice result(nullptr, value_length);
6385 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6387 return result;
6388}
6389
6390inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6391 slice result(nullptr, value_length);
6392 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6394 switch (err) {
6395 case MDBX_SUCCESS:
6396 return value_result{result, true};
6397 case MDBX_KEYEXIST:
6398 return value_result{result, false};
6399 default:
6400 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6401 }
6402}
6403
6404inline void cursor::upsert(const slice &key, const slice &value) {
6405 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6406}
6407
6408inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6409 slice result(nullptr, value_length);
6411 return result;
6412}
6413
6414inline void cursor::update(const slice &key, const slice &value) {
6415 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6416}
6417
6418inline bool cursor::try_update(const slice &key, const slice &value) {
6419 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6420 switch (err) {
6421 case MDBX_SUCCESS:
6422 return true;
6423 case MDBX_NOTFOUND:
6424 return false;
6425 default:
6426 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6427 }
6428}
6429
6430inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6431 slice result(nullptr, value_length);
6433 return result;
6434}
6435
6436inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6437 slice result(nullptr, value_length);
6438 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6439 switch (err) {
6440 case MDBX_SUCCESS:
6441 return value_result{result, true};
6442 case MDBX_NOTFOUND:
6443 return value_result{slice(), false};
6444 default:
6445 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6446 }
6447}
6448
6449inline bool cursor::erase(bool whole_multivalue) {
6450 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6451 switch (err) {
6452 case MDBX_SUCCESS:
6453 MDBX_CXX20_LIKELY return true;
6454 case MDBX_NOTFOUND:
6455 return false;
6456 default:
6457 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6458 }
6459}
6460
6461inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6462 bool found = seek(key);
6463 return found ? erase(whole_multivalue) : found;
6464}
6465
6466inline bool cursor::erase(const slice &key, const slice &value) {
6467 move_result data = find_multivalue(key, value, false);
6468 return data.done && erase();
6469}
6470
6471inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6472 size_t values_count, put_mode mode, bool allow_partial) {
6473 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6474 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6475 switch (err) {
6476 case MDBX_SUCCESS:
6477 MDBX_CXX20_LIKELY break;
6478 case MDBX_KEYEXIST:
6479 if (allow_partial)
6480 break;
6482 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6483 default:
6484 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6485 }
6486 return args[1].iov_len /* done item count */;
6487}
6488
6489inline ptrdiff_t cursor::distance_between(const cursor from, const cursor to, unsigned deepness) {
6490 intptr_t distance = PTRDIFF_MIN;
6491 error::success_or_throw(mdbx_cursor_distance(from, to, &distance, deepness));
6492 return distance;
6493}
6494
6495inline bool cursor::scroll(intptr_t distance, unsigned deepness, bool throw_notfound) {
6496 const int err = ::mdbx_cursor_scroll(handle_, distance, deepness);
6497 switch (err) {
6498 case MDBX_SUCCESS:
6499 MDBX_CXX20_LIKELY return true;
6500 case MDBX_NOTFOUND:
6501 if (!throw_notfound)
6502 return false;
6503 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6504 default:
6505 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6506 }
6507}
6508
6509inline bool cursor::distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size,
6510 unsigned deepness) {
6511 static_assert(sizeof(cursors_array[0]) == sizeof(MDBX_cursor *), "oops");
6512 const int err = ::mdbx_cursor_distribute(from, to, &cursors_array[0].handle_, cursors_array_size, deepness);
6513 return error::boolean_or_throw(err);
6514}
6515
6516inline bool cursor::distribute(const cursor from, const cursor to, const std::vector<cursor> &cursors_array,
6517 unsigned deepness) {
6518 static_assert(sizeof(cursor) == sizeof(MDBX_cursor *), "oops");
6519 const int err = MDBX_LIKELY(!cursors_array.empty())
6520 ? ::mdbx_cursor_distribute(from, to, const_cast<MDBX_cursor **>(&cursors_array[0].handle_),
6521 cursors_array.size(), deepness)
6522 : MDBX_EINVAL;
6523 return error::boolean_or_throw(err);
6524}
6525
6526inline bool cursor::distribute(const cursor from, const cursor to, const std::vector<cursor_managed> &cursors_array,
6527 unsigned deepness) {
6528 static_assert(sizeof(cursor_managed) == sizeof(MDBX_cursor *), "oops");
6529 const int err = MDBX_LIKELY(!cursors_array.empty())
6530 ? ::mdbx_cursor_distribute(from, to, const_cast<MDBX_cursor **>(&cursors_array[0].handle_),
6531 cursors_array.size(), deepness)
6532 : MDBX_EINVAL;
6533 return error::boolean_or_throw(err);
6534}
6535
6536//------------------------------------------------------------------------------
6537
6538LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
6539LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
6540LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
6541LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
6542LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
6543LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
6544LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
6545LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
6546LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
6547LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
6548LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
6549
6550LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
6551LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
6552LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
6553
6554inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
6555
6557
6558} // namespace mdbx
6559
6560//------------------------------------------------------------------------------
6561
6564namespace std {
6565
6566inline string to_string(const ::mdbx::slice &value) {
6567 ostringstream out;
6568 out << value;
6569 return out.str();
6570}
6571
6572template <class ALLOCATOR, typename CAPACITY_POLICY>
6573inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6574 ostringstream out;
6575 out << buffer;
6576 return out.str();
6577}
6578
6579inline string to_string(const ::mdbx::pair &value) {
6580 ostringstream out;
6581 out << value;
6582 return out.str();
6583}
6584
6585inline string to_string(const ::mdbx::env::geometry &value) {
6586 ostringstream out;
6587 out << value;
6588 return out.str();
6589}
6590
6591inline string to_string(const ::mdbx::env::operate_parameters &value) {
6592 ostringstream out;
6593 out << value;
6594 return out.str();
6595}
6596
6597inline string to_string(const ::mdbx::env::mode &value) {
6598 ostringstream out;
6599 out << value;
6600 return out.str();
6601}
6602
6603inline string to_string(const ::mdbx::env::durability &value) {
6604 ostringstream out;
6605 out << value;
6606 return out.str();
6607}
6608
6609inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6610 ostringstream out;
6611 out << value;
6612 return out.str();
6613}
6614
6615inline string to_string(const ::mdbx::env::operate_options &value) {
6616 ostringstream out;
6617 out << value;
6618 return out.str();
6619}
6620
6621inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6622 ostringstream out;
6623 out << value;
6624 return out.str();
6625}
6626
6627inline string to_string(const ::MDBX_log_level_t &value) {
6628 ostringstream out;
6629 out << value;
6630 return out.str();
6631}
6632
6633inline string to_string(const ::MDBX_debug_flags_t &value) {
6634 ostringstream out;
6635 out << value;
6636 return out.str();
6637}
6638
6639inline string to_string(const ::mdbx::error &value) {
6640 ostringstream out;
6641 out << value;
6642 return out.str();
6643}
6644
6645inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6646
6647template <> struct hash<::mdbx::slice> {
6648 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6649};
6650
6651template <> struct hash<::mdbx::map_handle> {
6652 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6653};
6654
6655template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6656 using inherited = std::hash<const MDBX_env *>;
6657 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6658};
6659
6660template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6661 using inherited = std::hash<const MDBX_txn *>;
6662 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6663};
6664
6665template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6666 using inherited = std::hash<const MDBX_cursor *>;
6667 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6668};
6669
6670template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6671 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6672 return buffer.hash_value();
6673 }
6674};
6675
6676} // namespace std
6677
6678#if defined(__LCC__) && __LCC__ >= 126
6679#pragma diagnostic pop
6680#endif
6681
6682#ifdef _MSC_VER
6683#pragma warning(pop)
6684#endif
Definition mdbx.h++:1146
Definition mdbx.h++:1136
Definition mdbx.h++:1156
#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
mode_t mdbx_mode_t
Definition mdbx.h:187
#define LIBMDBX_API
Definition mdbx.h:633
#define LIBMDBX_API_TYPE
Definition mdbx.h:648
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:807
pthread_t mdbx_tid_t
Definition mdbx.h:186
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition mdbx.h:740
int mdbx_filehandle_t
Definition mdbx.h:184
pid_t mdbx_pid_t
Definition mdbx.h:185
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:821
@ MDBX_MAXDATASIZE
Definition mdbx.h:815
@ MDBX_MAX_DBI
Definition mdbx.h:812
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:818
libmdbx build information
Definition mdbx.h:676
Lightweight transparent cache entry structure used by mdbx_cache_get().
Definition mdbx.h:5269
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4762
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4168
Information about the environment.
Definition mdbx.h:2862
Statistics for a table in the environment.
Definition mdbx.h:2816
Information about the transaction.
Definition mdbx.h:4066
libmdbx version information,
Definition mdbx.h:658
LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, MDBX_put_flags_t flags)
Delete current key/data pair.
int(* MDBX_preserve_func)(void *context, MDBX_val *target, const void *src, size_t bytes)
A data preservation callback for using within mdbx_replace_ex().
Definition mdbx.h:5562
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 great 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 fours integers markers (aka "canary") associated with the environment.
MDBX_put_flags_t
Data changing flags.
Definition mdbx.h:1652
LIBMDBX_API int mdbx_replace_ex(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *new_data, MDBX_val *old_data, MDBX_put_flags_t flags, MDBX_preserve_func preserver, void *preserver_context)
Replaces item in a table using preservation callback for an original data.
LIBMDBX_API int mdbx_cursor_count(const MDBX_cursor *cursor, size_t *count)
Return count values (aka duplicates) for current key.
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:4822
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5283
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)
LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store by cursor.
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store items into a table.
LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del)
Empty or delete and close a table.
LIBMDBX_API int mdbx_cursor_get(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, MDBX_cursor_op op)
Retrieve by cursor.
LIBMDBX_API int mdbx_get(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data)
Get items from a table.
@ MDBX_MULTIPLE
Definition mdbx.h:1689
@ MDBX_ALLDUPS
Definition mdbx.h:1672
@ MDBX_CURRENT
Definition mdbx.h:1667
@ MDBX_APPENDDUP
Definition mdbx.h:1685
@ MDBX_APPEND
Definition mdbx.h:1680
@ MDBX_UPSERT
Definition mdbx.h:1654
@ MDBX_RESERVE
Definition mdbx.h:1676
@ MDBX_NOOVERWRITE
Definition mdbx.h:1657
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:1733
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_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:770
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:1852
@ MDBX_GET_CURRENT
Definition mdbx.h:1748
@ MDBX_GET_BOTH
Definition mdbx.h:1741
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1829
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1745
@ MDBX_SET_KEY
Definition mdbx.h:1788
@ MDBX_FIRST_DUP
Definition mdbx.h:1738
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1828
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1753
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1839
@ MDBX_NEXT_NODUP
Definition mdbx.h:1773
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1836
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1837
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1844
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1796
@ MDBX_SET_RANGE
Definition mdbx.h:1791
@ MDBX_LAST_DUP
Definition mdbx.h:1759
@ MDBX_PREV
Definition mdbx.h:1776
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1846
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1847
@ MDBX_LAST
Definition mdbx.h:1756
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1827
@ MDBX_PREV_DUP
Definition mdbx.h:1779
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1835
@ MDBX_SET
Definition mdbx.h:1785
@ MDBX_NEXT
Definition mdbx.h:1762
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1830
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1843
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1770
@ MDBX_PREV_NODUP
Definition mdbx.h:1782
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1845
@ MDBX_NEXT_DUP
Definition mdbx.h:1765
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1838
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1831
@ MDBX_FIRST
Definition mdbx.h:1735
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:763
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1602
@ MDBX_INTEGERDUP
Definition mdbx.h:1626
@ MDBX_DB_ACCEDE
Definition mdbx.h:1644
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1604
@ MDBX_REVERSEKEY
Definition mdbx.h:1607
@ MDBX_DUPFIXED
Definition mdbx.h:1621
@ MDBX_INTEGERKEY
Definition mdbx.h:1617
@ MDBX_REVERSEDUP
Definition mdbx.h:1629
@ MDBX_CREATE
Definition mdbx.h:1632
@ MDBX_DUPSORT
Definition mdbx.h:1610
MDBX_log_level_t
Definition mdbx.h:883
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:941
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1860
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:6989
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1874
@ MDBX_BAD_TXN
Definition mdbx.h:1937
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1951
@ MDBX_SUCCESS
Definition mdbx.h:1862
@ MDBX_NOTFOUND
Definition mdbx.h:1877
@ MDBX_RESULT_TRUE
Definition mdbx.h:1868
@ MDBX_BUSY
Definition mdbx.h:1955
@ MDBX_EINVAL
Definition mdbx.h:2032
@ MDBX_ENOMEM
Definition mdbx.h:2034
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1958
@ MDBX_RESULT_FALSE
Definition mdbx.h:1865
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:2010
@ MDBX_KEYEXIST
Definition mdbx.h:1871
LIBMDBX_API int mdbx_reader_check(MDBX_env *env, int *dead)
Check for stale entries in the reader lock table.
LIBMDBX_API int mdbx_env_sync_ex(MDBX_env *env, bool force, bool nonblock)
Flush the environment data buffers to disk.
@ MDBX_ENV_WAIT_FOR_UNUSED
Wait until other processes closes the environment before deletion.
Definition mdbx.h:2596
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2591
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2594
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1084
@ MDBX_WRITEMAP
Definition mdbx.h:1204
@ MDBX_EXCLUSIVE
Definition mdbx.h:1158
@ MDBX_RDONLY
Definition mdbx.h:1128
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:3107
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2136
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:3048
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:2241
@ 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:2403
@ MDBX_opt_subpage_limit
Specifies the maximum size of nested pages used to accommodate a small number of multi-values associa...
Definition mdbx.h:2396
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2237
@ MDBX_opt_prefer_waf_insteadof_balance
Controls the choice between striving for uniformity of page filling/density, either for reducing the ...
Definition mdbx.h:2382
@ MDBX_opt_presync_threshold
Sets threshold in bytes for preliminary flush/sync operation without holding a transaction lock.
Definition mdbx.h:2463
@ 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:2341
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2145
@ 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:2417
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2168
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2273
@ 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:2296
@ MDBX_opt_split_reserve
Sets the space reservation in 1/65536 of page size when splitting page along the edge.
Definition mdbx.h:2445
@ 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:2208
@ 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:2195
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2162
@ MDBX_opt_subpage_reserve_limit
Sets the limit for reserving space on nested pages.
Definition mdbx.h:2423
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2257
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2174
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2222
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2336
@ MDBX_opt_gc_time_limit
Controls the in-process spending time limit of searching consecutive pages inside GC.
Definition mdbx.h:2360
@ MDBX_opt_merge_threshold
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2308
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:3722
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:3127
LIBMDBX_API int mdbx_env_get_maxkeysize_ex(const MDBX_env *env, MDBX_db_flags_t flags)
Returns the maximum size of keys can put.
LIBMDBX_API int mdbx_env_get_maxvalsize_ex(const MDBX_env *env, MDBX_db_flags_t flags)
Returns the maximum size of data we can put.
LIBMDBX_API int mdbx_env_stat_ex(const MDBX_env *env, const MDBX_txn *txn, MDBX_stat *stat, size_t bytes)
Return statistics about the MDBX environment.
LIBMDBX_API int mdbx_env_get_pairsize4page_max(const MDBX_env *env, MDBX_db_flags_t flags)
Returns maximal size of key-value pair to fit in a single page for specified table flags.
int mdbx_env_get_syncbytes(const MDBX_env *env, size_t *threshold)
Get threshold to force flush the data buffers to disk, even any of MDBX_SAFE_NOSYNC flag in the envir...
Definition mdbx.h:3066
LIBMDBX_API intptr_t mdbx_limits_valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal data size in bytes to fit in a leaf-page or single large/overflow-page with the given...
LIBMDBX_API intptr_t mdbx_limits_txnsize_max(intptr_t pagesize)
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes for gi...
LIBMDBX_API int mdbx_dbi_dupsort_depthmask(const MDBX_txn *txn, MDBX_dbi dbi, uint32_t *mask)
Retrieve depth (bitmask) information of nested dupsort (multi-value) B+trees for given table.
LIBMDBX_API int mdbx_txn_info(const MDBX_txn *txn, MDBX_txn_info *info, bool scan_rlt)
Return information about the MDBX transaction.
LIBMDBX_API int mdbx_is_dirty(const MDBX_txn *txn, const void *ptr)
Determines whether the given address is on a dirty database page of the transaction or not.
MDBX_dbi_state_t
DBI state bits returted by mdbx_dbi_flags_ex().
Definition mdbx.h:5084
LIBMDBX_API int mdbx_env_get_valsize4page_max(const MDBX_env *env, MDBX_db_flags_t flags)
Returns maximal data size in bytes to fit in a leaf-page or single large/overflow-page for specified ...
LIBMDBX_API int mdbx_env_get_fd(const MDBX_env *env, mdbx_filehandle_t *fd)
Return the file descriptor for the given environment.
LIBMDBX_API void * mdbx_env_get_userctx(const MDBX_env *env)
Returns an application information (a context pointer) associated with the environment.
int mdbx_env_get_maxdbs(const MDBX_env *env, MDBX_dbi *dbs)
Get the maximum number of named tables for the environment.
Definition mdbx.h:3767
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 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_unpark(MDBX_txn *txn, bool restart_if_ousted)
Unparks a previously parked reading transaction.
MDBX_txn_flags_t
Definition mdbx.h:1501
LIBMDBX_API void * mdbx_txn_get_userctx(const MDBX_txn *txn)
Returns an application information (a context pointer) associated with the transaction.
int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, MDBX_txn_flags_t flags, MDBX_txn **txn)
Create a transaction for use with the environment.
Definition mdbx.h:3983
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:751
LIBMDBX_API int mdbx_txn_reset(MDBX_txn *txn)
Reset a read-only transaction.
LIBMDBX_API int mdbx_txn_renew(MDBX_txn *txn)
Renew a read-only transaction.
LIBMDBX_API MDBX_txn_flags_t mdbx_txn_flags(const MDBX_txn *txn)
Return the transaction's flags.
@ MDBX_TXN_RDONLY
Definition mdbx.h:1512
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1521
@ MDBX_TXN_READWRITE
Definition mdbx.h:1506
@ MDBX_TXN_TRY
Definition mdbx.h:1527
void commit(finalization_latency &latency)
Commits all changes of the transaction into a database with collecting latencies information.
Definition mdbx.h++:4130
constexpr const MDBX_env * handle() const noexcept
Definition mdbx.h++:3037
friend class env
Definition mdbx.h++:4095
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:3789
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4622
bool scan_until(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4317
::MDBX_stat map_stat
Definition mdbx.h++:3955
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++:3486
env_managed & operator=(env_managed &&other) noexcept
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3936
bool scan_until_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4362
env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede=true)
map_handle(const map_handle &) noexcept=default
::MDBX_db_flags_t flags
Definition mdbx.h++:2984
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4439
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4495
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:3039
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr const MDBX_cursor * handle() const noexcept
Definition mdbx.h++:4195
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2953
durability
Durability level.
Definition mdbx.h++:3133
@ lazy_weak_tail
Definition mdbx.h++:3136
@ robust_synchronous
Definition mdbx.h++:3134
@ whole_fragile
Definition mdbx.h++:3137
@ half_synchronous_weak_last
Definition mdbx.h++:3135
friend constexpr bool operator!=(const cursor &a, const cursor &b) noexcept
Definition mdbx.h++:4200
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++:2980
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3301
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++:4483
bool checkpoint(finalization_latency &latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4144
constexpr cache_entry(const MDBX_cache_entry_t &ce) noexcept
Definition mdbx.h++:2817
cache_entry() noexcept
Definition mdbx.h++:2809
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3744
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4458
ptrdiff_t distance_to_end(unsigned deepness=42) const
Definition mdbx.h++:4521
::MDBX_canary canary
Definition mdbx.h++:3964
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++:4147
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++:3787
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++:4388
friend constexpr bool operator!=(const txn &a, const txn &b) noexcept
Definition mdbx.h++:3762
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++:4452
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++:4461
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.
constexpr cache_entry & operator=(const MDBX_cache_entry_t &ce) noexcept
Definition mdbx.h++:2818
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
void reset() noexcept
Definition mdbx.h++:2816
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2974
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2954
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4575
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4406
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++:4397
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++:4223
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3843
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:4019
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4429
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4215
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4219
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++:3928
constexpr MDBX_txn * handle() noexcept
Definition mdbx.h++:3760
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3228
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4413
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4633
MDBX_txn * handle_
Definition mdbx.h++:3745
void abort()
Abandon all the operations of the transaction instead of saving ones.
MDBX_commit_latency finalization_latency
Definition mdbx.h++:4109
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++:4385
mode
Operation mode.
Definition mdbx.h++:3125
@ write_mapped_io
Definition mdbx.h++:3128
@ nested_transactions
Definition mdbx.h++:3129
@ readonly
Definition mdbx.h++:3126
@ write_file_io
Definition mdbx.h++:3127
friend constexpr bool operator==(const cursor &a, const cursor &b) noexcept
Definition mdbx.h++:4197
bool is_writemap() const
Definition mdbx.h++:3394
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4382
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3362
operator::mdbx::txn() const
Definition mdbx.h++:4552
MDBX_env * handle_
Definition mdbx.h++:3023
slice reverse_current(size_t value_length)
Reserves and returns the space to storing a value associated with a key at the current cursor positio...
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4445
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4211
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4395
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4415
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:2812
bool is_nested_transactions_available() const
Definition mdbx.h++:3398
void close()
Explicitly closes the cursor.
constexpr MDBX_env * handle() noexcept
Definition mdbx.h++:3038
bool scan_until_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4341
void abort(finalization_latency &latency)
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4116
bool is_pristine() const
Returns true for a freshly created database, but false if at least one transaction was committed.
move_result to_key_exact(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4426
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3784
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++:4491
env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede=true)
ptrdiff_t distance_from_first(unsigned deepness=42) const
Definition mdbx.h++:4518
void append(map_handle map, const pair &kv, bool multivalue_order_preserved=true)
Definition mdbx.h++:4059
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3332
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3342
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3344
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3339
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4400
cursor_managed & operator=(cursor_managed &&other) noexcept
::MDBX_dbi_state_t state
Definition mdbx.h++:2985
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3559
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4602
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++:3307
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4455
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++:4487
ptrdiff_t distance_to(const cursor to, unsigned deepness=42) const
Definition mdbx.h++:4515
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4417
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4414
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4553
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3303
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2977
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3840
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2968
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++:4432
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3368
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:4016
env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
friend int compare_position(const cursor &left, const cursor &right, bool ignore_nested)
Definition mdbx.h++:6226
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4075
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++:3314
map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single) const
Open existing key-value map.
Definition mdbx.h++:3921
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2965
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++:4158
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++:4067
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++:4161
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++:2971
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++:4467
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4233
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4248
@ multi_exactkey_value_equal
Definition mdbx.h++:4265
@ pair_greater_or_equal
Definition mdbx.h++:4273
@ key_lesser_than
Definition mdbx.h++:4255
@ next
Definition mdbx.h++:4236
@ pair_exact
Definition mdbx.h++:4272
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4266
@ pair_lesser_or_equal
Definition mdbx.h++:4270
@ batch_samelength
Definition mdbx.h++:4276
@ seek_key
Definition mdbx.h++:4250
@ key_lowerbound
Definition mdbx.h++:4252
@ pair_lesser_than
Definition mdbx.h++:4269
@ pair_equal
Definition mdbx.h++:4271
@ key_greater_than
Definition mdbx.h++:4259
@ batch_samelength_next
Definition mdbx.h++:4277
@ multi_find_pair
Definition mdbx.h++:4247
@ key_greater_or_equal
Definition mdbx.h++:4258
@ key_exact
Definition mdbx.h++:4251
@ key_equal
Definition mdbx.h++:4257
@ multi_currentkey_prevvalue
Definition mdbx.h++:4242
@ key_lesser_or_equal
Definition mdbx.h++:4256
@ multi_nextkey_firstvalue
Definition mdbx.h++:4245
@ get_current
Definition mdbx.h++:4238
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4264
@ multi_prevkey_lastvalue
Definition mdbx.h++:4240
@ previous
Definition mdbx.h++:4237
@ last
Definition mdbx.h++:4235
@ pair_greater_than
Definition mdbx.h++:4274
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4263
@ multi_currentkey_firstvalue
Definition mdbx.h++:4241
@ first
Definition mdbx.h++:4234
@ batch_samelength_previous
Definition mdbx.h++:4278
@ multi_currentkey_nextvalue
Definition mdbx.h++:4243
@ seek_and_batch_samelength
Definition mdbx.h++:4279
@ multi_exactkey_value_greater
Definition mdbx.h++:4267
@ multi_currentkey_lastvalue
Definition mdbx.h++:4244
finalization_latency commit_get_latency()
Commits all changes of the transaction into a database and return latency information.
Definition mdbx.h++:4133
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4391
void insert(const pair &kv)
Definition mdbx.h++:4576
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3781
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++:4578
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4403
constexpr const MDBX_txn * handle() const noexcept
Definition mdbx.h++:3759
bool is_cooperative() const
Definition mdbx.h++:3392
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3941
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4442
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++:4410
bool is_readonly() const
Definition mdbx.h++:3388
value_result try_insert(const pair &kv)
Definition mdbx.h++:4577
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++:4594
constexpr cursor() noexcept=default
bool is_exclusive() const
Definition mdbx.h++:3390
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4420
finalization_latency abort_get_latency()
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4119
constexpr MDBX_cursor * handle() noexcept
Definition mdbx.h++:4196
bool is_readwrite() const
Definition mdbx.h++:3396
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4464
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3311
MDBX_cursor * handle_
Definition mdbx.h++:4180
MDBX_dbi dbi
Definition mdbx.h++:2952
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4436
friend constexpr bool operator!=(const env &a, const env &b) noexcept
Definition mdbx.h++:3040
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4407
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3795
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++:4448
ptrdiff_t distance_from(const cursor from, unsigned deepness=42) const
Definition mdbx.h++:4511
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3359
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3309
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:4018
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:4017
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++:3949
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4423
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++:4396
friend class txn
Definition mdbx.h++:3020
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4207
friend constexpr bool operator==(const txn &a, const txn &b) noexcept
Definition mdbx.h++:3761
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3305
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3798
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4336
Unmanaged cursor.
Definition mdbx.h++:4178
Managed cursor.
Definition mdbx.h++:4614
Unmanaged database environment.
Definition mdbx.h++:3019
Managed database environment.
Definition mdbx.h++:3668
Unmanaged database transaction.
Definition mdbx.h++:3742
Managed database transaction.
Definition mdbx.h++:4093
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++:5353
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5225
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++:6110
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4892
polymorphic_allocator default_allocator
Definition mdbx.h++:381
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4901
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4983
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++:5199
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++:5137
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++:5128
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5694
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++:5381
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4997
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4742
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6337
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2866
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4879
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:4699
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4977
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5727
class MDBX_MSVC_DECLSPEC_EMPTY_BASES buffer
Definition mdbx.h++:389
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:4869
void rethrow_captured() const
Definition mdbx.h++:4714
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4877
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6291
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6267
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5346
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5320
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++:5146
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6071
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6013
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5600
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++:5531
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6235
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++:5178
::mdbx::filesystem::path::string_type path_string
Definition mdbx.h++:429
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4899
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6180
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++:5204
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4924
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4825
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6343
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:450
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6004
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6192
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5824
void throw_on_failure() const
Definition mdbx.h++:4754
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6418
void update(const slice &key, const slice &value)
Definition mdbx.h++:6414
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:4696
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++:5895
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:5049
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4887
::MDBX_cmp_func comparator
Definition mdbx.h++:2997
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++:5193
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5696
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5667
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6222
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5023
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5464
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5883
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6404
bool is_clean() const noexcept
Definition mdbx.h++:4707
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2859
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4787
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++:5183
path_string::value_type path_char
Definition mdbx.h++:437
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5454
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2863
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:402
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:5506
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5339
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4967
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4721
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++:5209
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4649
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5080
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++:5638
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++:5603
void insert(const slice &key, slice value)
Definition mdbx.h++:6365
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6295
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++:5779
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:5274
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:380
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:2847
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++:5219
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4809
~cursor() noexcept
Definition mdbx.h++:6209
~txn() noexcept
Definition mdbx.h++:5688
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5536
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:5173
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6287
uint64_t txnid
Transaction ID and MVCC-snapshot number.
Definition mdbx.h++:398
constexpr void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition mdbx.h++:4905
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6345
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6390
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5331
map_handle map() const
Definition mdbx.h++:6350
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++:5547
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:4703
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6279
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5795
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6299
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2927
void success_or_throw() const
Definition mdbx.h++:4759
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5731
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4939
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5587
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5027
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6226
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6305
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4935
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5337
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4944
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5701
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6408
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5462
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2855
void capture() noexcept
Definition mdbx.h++:4709
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:5155
bool scroll(intptr_t distable, unsigned deepness=42, bool throw_notfound=true)
Definition mdbx.h++:6495
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++:5860
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6049
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4918
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2998
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6383
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++:5643
static size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal size of key-value pair to fit in a single page for specified size and table flags.
Definition mdbx.h++:5401
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++:5542
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:6168
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5468
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5820
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6186
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++:6144
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5472
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5746
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5031
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6217
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5854
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6245
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++:5377
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++:5899
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5327
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5872
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6035
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4962
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4736
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++:5553
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4989
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4861
bool on_first() const
Definition mdbx.h++:6313
::MDBX_version_info version_info
libmdbx version information,
Definition mdbx.h++:345
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:4897
bool eof() const
Definition mdbx.h++:6311
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5729
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5715
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5524
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6357
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5652
::MDBX_build_info build_info
libmdbx build information
Definition mdbx.h++:349
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:5168
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5676
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4929
bool seek(const slice &key)
Definition mdbx.h++:6303
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5576
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5526
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4951
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++:5445
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5822
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++:5565
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5290
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4912
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6370
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++:6471
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4772
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4730
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5713
put_mode
Key-value pairs put mode.
Definition mdbx.h++:3006
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5230
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++:5214
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++:5557
::mdbx_filehandle_t filehandle
Definition mdbx.h++:404
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++:5423
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5296
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5019
BUFFER extract(map_handle map, const slice &key, const ALLOCATOR &alloc=ALLOCATOR())
Removes and return a value of the key.
Definition mdbx.h++:6116
char8_t byte
The byte-like type that don't presumes aliases for pointers as does the char.
Definition mdbx.h++:330
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5877
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6449
BUFFER replace_reserve(map_handle map, const slice &key, size_t length, slice &new_value_reservation, const ALLOCATOR &alloc=ALLOCATOR())
Definition mdbx.h++:6133
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5476
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5123
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5721
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5989
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:363
constexpr bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition mdbx.h++:4744
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:5150
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:5132
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6273
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5004
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:5141
static bool distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size, unsigned deepness=42)
Definition mdbx.h++:6509
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:5159
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6063
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5286
~env() noexcept
Definition mdbx.h++:5308
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2828
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5911
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4738
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4907
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++:6149
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6043
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4956
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2831
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5645
::mdbx::filesystem::path path
Definition mdbx.h++:428
bool on_last_multival() const
Definition mdbx.h++:6319
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5518
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5982
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5512
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++:5357
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5608
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6215
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5452
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5758
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2851
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5748
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5570
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4650
bool on_first_multival() const
Definition mdbx.h++:6317
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5970
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:5062
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4972
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5488
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6029
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5335
string< ALLOCATOR > as_base64_string(unsigned wrap_width=0, const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition mdbx.h++:5188
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6430
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:5733
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6283
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4863
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4885
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++:5271
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5631
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:6086
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4734
bool on_last() const
Definition mdbx.h++:6315
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:424
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:5500
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5581
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++:6339
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:5164
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5314
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5764
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4728
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5102
constexpr bool is_success() const noexcept
Definition mdbx.h++:4732
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6436
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:5075
cursor & assign(const cursor &)
Definition mdbx.h++:6194
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5674
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5282
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5752
static ptrdiff_t distance_between(const cursor from, const cursor to, unsigned deepness=42)
Definition mdbx.h++:6489
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++:5811
pair_result get_equal_or_great(map_handle map, const slice &key) const
Get value for equal or great key from a table.
Definition mdbx.h++:5949
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5866
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4871
@ multi_reverse_samelength
Definition mdbx.h++:2899
@ multi_samelength
Definition mdbx.h++:2884
@ multi_ordinal
Definition mdbx.h++:2891
@ msgpack
Definition mdbx.h++:2914
@ single
Definition mdbx.h++:2867
@ multi
Definition mdbx.h++:2869
@ multi_reverse
Definition mdbx.h++:2876
@ upsert
Insert or update.
Definition mdbx.h++:3008
@ update
Update existing, don't insert new.
Definition mdbx.h++:3009
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:3007
@ continue_loop
Definition mdbx.h++:2828
@ exit_loop
Definition mdbx.h++:2828
@ usual
Definition mdbx.h++:2832
@ ordinal
Definition mdbx.h++:2837
@ reverse
Definition mdbx.h++:2834
@ msgpack
Definition mdbx.h++:2842
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2951
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2432
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2121
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++:1993
modality
Data storage modality.
Definition mdbx.h++:1574
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2023
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:685
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2094
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1976
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:699
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:661
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++:2276
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2322
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:652
const slice source
Definition mdbx.h++:1250
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base58 dump, and therefore there could be dec...
static buffer key_from(const double *ieee754_64bit)
Definition mdbx.h++:2678
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++:2225
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:721
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:2039
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2352
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2036
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2441
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2300
constexpr size_t tailroom() const noexcept
Returns the number of bytes that available in currently allocated storage after the data.
Definition mdbx.h++:2011
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2160
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2412
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2319
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2030
buffer & append(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:2471
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2165
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2710
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1560
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1023
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1227
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2357
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2069
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2567
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2059
buffer & append(const byte c)
Definition mdbx.h++:2510
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2330
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:739
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1004
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2335
buffer & operator=(const buffer &src)
Definition mdbx.h++:2458
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1022
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2589
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++:2006
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2752
constexpr int64_t as_int64() const
Definition mdbx.h++:1029
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2056
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2668
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++:2207
const bool ignore_spaces
Definition mdbx.h++:1330
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:843
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++:2289
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++:2283
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2202
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2520
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2245
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++:1092
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Definition mdbx.h++:756
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2721
constexpr int16_t as_int16() const
Definition mdbx.h++:1031
slice value
Definition mdbx.h++:1056
::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++:2723
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2437
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++:2269
constexpr buffer(const ::std::basic_string< CHAR, T, A > &&str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2149
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2688
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1198
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++:2295
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2199
slice value
Definition mdbx.h++:1070
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2714
::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++:2694
const slice source
Definition mdbx.h++:1329
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2732
const slice source
Definition mdbx.h++:1165
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++:2233
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++:1312
const unsigned wrap_width
Definition mdbx.h++:1167
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2467
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2674
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:713
const slice & slice() const noexcept
Definition mdbx.h++:2706
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2420
const bool ignore_spaces
Definition mdbx.h++:1296
constexpr POD as_pod() const
Definition mdbx.h++:1006
constexpr buffer & assign(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2389
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++:1119
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++:1396
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2727
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2408
constexpr buffer(const buffer &src)
Definition mdbx.h++:2131
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++:2262
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1019
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2082
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2680
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2344
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1168
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2729
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2563
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2660
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1525
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2176
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:735
std::pair< slice, slice > stl_pair
Definition mdbx.h++:1069
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2587
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:1988
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
typename silo::copy_assign_alloc copy_assign_alloc
Definition mdbx.h++:1971
@ pettiness_threshold
Definition mdbx.h++:1514
@ extra_inplace_storage
Definition mdbx.h++:1512
@ max_reserve
Definition mdbx.h++:1515
@ inplace_storage_size_rounding
Definition mdbx.h++:1513
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2692
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:675
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1331
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2462
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2559
constexpr int8_t as_int8() const
Definition mdbx.h++:1032
constexpr ::std::span< char > chars()
Definition mdbx.h++:687
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1051
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1269
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2116
buffer(const txn &transaction, const slice &src, const allocator_type &alloc=allocator_type())
static constexpr size_t round(const size_t value)
Definition mdbx.h++:1518
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1241
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++:1387
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:1058
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2672
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1358
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2257
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2171
const slice source
Definition mdbx.h++:1208
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:1072
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2426
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++:1980
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2696
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:686
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1370
buffer_pair_spec & operator=(buffer_pair_spec &&src)
Definition mdbx.h++:2756
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2622
constexpr void swap(slice &other) noexcept
Definition mdbx.h++:851
typename silo::swap_alloc swap_alloc
Definition mdbx.h++:1972
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2144
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid data and could be encoded or unexpectedly not...
Definition mdbx.h++:1202
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1561
uint8_t as_uint8_adapt() const
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:666
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2686
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2113
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2464
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2772
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2531
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2610
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2571
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++:1348
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:718
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++:743
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1319
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:631
pair & operator=(pair &&couple) noexcept
Definition mdbx.h++:1076
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++:2240
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2702
slice inherited
Definition mdbx.h++:1554
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:1120
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1297
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2698
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++:2700
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2324
static constexpr pair invalid() noexcept
Definition mdbx.h++:1085
typename silo::move_assign_alloc move_assign_alloc
Definition mdbx.h++:1970
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2102
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2416
bool done
Definition mdbx.h++:1118
::std::ostream & output(::std::ostream &out) const
Output Base58 dump of passed slice to the std::ostream.
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid data and could be encoded or unexpectedly not...
Definition mdbx.h++:1244
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:684
constexpr const void * const_end() const noexcept
Definition mdbx.h++:2065
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:701
const bool uppercase
Definition mdbx.h++:1166
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2043
void clear_and_reserve(size_t whole_capacity, size_t headroom=0)
Clears the contents and reserve storage.
Definition mdbx.h++:2489
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2371
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2518
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2575
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2740
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2050
const bool ignore_spaces
Definition mdbx.h++:1369
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1253
pair(const pair &) noexcept=default
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2654
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:999
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base64 dump, and therefore there could be dec...
slice & operator=(const slice &) noexcept=default
uint128_t as_uint128_adapt() const
constexpr int128_t as_int128() const
Definition mdbx.h++:1027
slice key
Definition mdbx.h++:1070
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2499
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:1071
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2746
const slice source
Definition mdbx.h++:1368
pair_result & operator=(const pair_result &) noexcept=default
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2494
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1286
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2704
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2486
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2712
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++:1030
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++:2219
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2135
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1556
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2676
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2016
constexpr modality content_modality() const noexcept
Returns current modality of buffer content.
Definition mdbx.h++:1996
constexpr const void * const_data() const noexcept
Definition mdbx.h++:2062
pair & operator=(const stl_pair &couple)
Definition mdbx.h++:1087
int64_t as_int64_adapt() const
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2684
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2019
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++:2214
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2348
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2738
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1024
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2713
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2156
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1973
buffer & append(const ::std::basic_string< CHAR, T, A > &str)
Definition mdbx.h++:2481
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2579
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2599
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1021
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2734
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2682
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid hexadecimal dump, and therefore there could b...
buffer encode_base58(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2252
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2636
const unsigned wrap_width
Definition mdbx.h++:1209
buffer & append_hex(const struct slice &data, bool uppercase=false, unsigned wrap_width=0)
Definition mdbx.h++:2555
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2196
const unsigned wrap_width
Definition mdbx.h++:1251
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2460
uint32_t as_uint32_adapt() const
constexpr bool is_valid() const noexcept
Checks the slice is not refers to null address or has zero length.
Definition mdbx.h++:996
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2076
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++:2533
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2749
buffer_pair_spec(const txn &transaction, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2743
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++:693
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2544
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2139
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2665
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2711
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid data and could be encoded or unexpectedly not...
Definition mdbx.h++:1290
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++:1211
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2127
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:696
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++:1183
buffer(buffer &&src) noexcept(::std::is_nothrow_move_constructible< allocator_type >::value)
Definition mdbx.h++:2184
bool done
Definition mdbx.h++:1057
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++:1295
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:2001
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2087
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1552
Definition mdbx.h++:2709
Type tag for delivered buffer template classes.
Definition mdbx.h++:1548
Definition mdbx.h++:1510
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1328
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1367
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1294
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:1068
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:1117
References a data located outside the slice.
Definition mdbx.h++:626
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1207
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1249
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1164
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:1055
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:543
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++:4730
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++:542
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++:513
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++:533
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++:544
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++:545
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++:4728
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++:475
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:460
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:551
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:5023
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:5027
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition mdbx.h++:192
#define MDBX_MSVC_DECLSPEC_EMPTY_BASES
Definition mdbx.h++:135
#define MDBX_CXX17_FALLTHROUGH
Definition mdbx.h++:234
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:274
#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES,...)
Definition mdbx.h++:125
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:202
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:181
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:220
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:225
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:201
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:240
The libmdbx C API header file.
Definition mdbx.h++:1404
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1406
The libmdbx C++ API namespace.
Definition mdbx.h++:307
STL namespace.
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6566
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1653
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1655
byte lastbyte_
Definition mdbx.h++:1654
Definition mdbx.h++:4298
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4300
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4299
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4302
Definition mdbx.h++:4286
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++:4290
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4288
Tagged type for output to std::ostream.
Definition mdbx.h++:3073
intptr_t bytes
Definition mdbx.h++:3074
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3075
Database geometry for size management.
Definition mdbx.h++:3049
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3097
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3109
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3056
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3052
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3055
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3064
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3053
@ default_value
Means "keep current or use default".
Definition mdbx.h++:3051
@ kB
bytes (0x03E8)
Definition mdbx.h++:3054
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3063
@ KiB
bytes (0x0400)
Definition mdbx.h++:3062
constexpr geometry() noexcept
Definition mdbx.h++:3113
constexpr geometry & operator=(const geometry &) noexcept=default
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3100
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3085
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3103
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3080
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++:3117
Operate options.
Definition mdbx.h++:3152
bool disable_readahead
Definition mdbx.h++:3161
bool enable_validation
Definition mdbx.h++:3165
bool no_sticky_threads
Definition mdbx.h++:3154
constexpr operate_options() noexcept
Definition mdbx.h++:3166
bool disable_clear_memory
Definition mdbx.h++:3163
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3159
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
bool nested_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3157
Operate parameters.
Definition mdbx.h++:3174
env::durability durability
Definition mdbx.h++:3182
env::operate_options options
Definition mdbx.h++:3184
constexpr operate_parameters(const unsigned max_maps, const unsigned max_readers=0, const env::mode mode=env::mode::write_mapped_io, env::durability durability=env::durability::robust_synchronous, const env::reclaiming_options &reclaiming=env::reclaiming_options(), const env::operate_options &options=env::operate_options()) noexcept
Definition mdbx.h++:3188
static env::mode mode_from_flags(MDBX_env_flags_t) noexcept
constexpr operate_parameters & operator=(const operate_parameters &) noexcept=default
unsigned max_readers
The maximum number of threads/reader slots for the environment. Zero means default value.
Definition mdbx.h++:3180
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3183
env::mode mode
Definition mdbx.h++:3181
static env::durability durability_from_flags(MDBX_env_flags_t) noexcept
unsigned max_maps
The maximum number of named tables/maps for the environment. Zero means default value.
Definition mdbx.h++:3177
constexpr operate_parameters() noexcept
Definition mdbx.h++:3186
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3582
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3585
uint64_t transaction_lag
Definition mdbx.h++:3588
size_t bytes_used
Definition mdbx.h++:3592
uint64_t transaction_id
Definition mdbx.h++:3586
int slot
The reader lock table slot number.
Definition mdbx.h++:3583
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3584
size_t bytes_retained
Definition mdbx.h++:3595
Garbage reclaiming options.
Definition mdbx.h++:3141
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3144
bool lifo
Definition mdbx.h++:3143
Additional parameters for creating a new database.
Definition mdbx.h++:3691
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3693
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3694
env::geometry geometry
Definition mdbx.h++:3692
Definition mdbx.h++:2986
map_handle::state state
Definition mdbx.h++:2988
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2987
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6671
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6667
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6666
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6657
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6656
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6652
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6648
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6661
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6662
capacity_holder capacity_
Definition mdbx.h++:1659
allocator_pointer stub_ptr_
Definition mdbx.h++:1634
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1671
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1704
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1663
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1678
inplace_flag_holder inplace_
Definition mdbx.h++:1660
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1662
allocator_pointer allocated_ptr_
Definition mdbx.h++:1658
size_t stub_capacity_bytes_
Definition mdbx.h++:1635
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1723
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1648
size_t bytes_
Definition mdbx.h++:1649
constexpr const byte * address() const noexcept
Definition mdbx.h++:1717
constexpr bin() noexcept
Definition mdbx.h++:1698
@ inplace_size
Definition mdbx.h++:1643
@ inplace_signature_limit
Definition mdbx.h++:1640
@ inplace_size_rounding
Definition mdbx.h++:1642
constexpr byte * address() noexcept
Definition mdbx.h++:1720
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1689
@ lastbyte_poison
Definition mdbx.h++:1638
@ lastbyte_inplace_signature
Definition mdbx.h++:1638
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1713
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1680