libmdbx 0.14.2.422 (2026-07-27T15:51:14+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) : slice(sv.data(), sv.data() + sv.length()) {}
694
695 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
696#endif /* __cpp_lib_string_view >= 201606L */
697
698 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
699
700 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
701 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
702 "Must be a standard layout type!");
703 return slice(&pod, sizeof(pod));
704 }
705
706 inline slice &assign(const void *ptr, size_t bytes);
707 inline slice &assign(const slice &src) noexcept;
708 inline slice &assign(const ::MDBX_val &src);
709 inline slice &assign(slice &&src) noexcept;
710 inline slice &assign(::MDBX_val &&src);
711 inline slice &assign(const void *begin, const void *end);
712 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
713 return assign(str.data(), str.length() * sizeof(CHAR));
714 }
715 inline slice &assign(const char *c_str);
716#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
717 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
718 return assign(view.begin(), view.end());
719 }
720 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
721 assign(view);
722 view = {};
723 return *this;
724 }
725#endif /* __cpp_lib_string_view >= 201606L */
726
727 slice &operator=(const slice &) noexcept = default;
728 inline slice &operator=(slice &&src) noexcept;
729 inline slice &operator=(::MDBX_val &&src);
730 operator MDBX_val *() noexcept { return this; }
731 operator const MDBX_val *() const noexcept { return this; }
732
733#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
734 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
735 return assign(view);
736 }
737
738 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
739
741 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
742 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
743 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
744 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
745 }
746
748 template <class CHAR, class T>
749 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
750 return this->string_view<CHAR, T>();
751 }
752#endif /* __cpp_lib_string_view >= 201606L */
753
754 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
755 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
756 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
757 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
758 }
759
760 template <class CHAR, class T, class ALLOCATOR>
761 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
763 }
764
766 template <class ALLOCATOR = default_allocator>
767 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
768 const ALLOCATOR &alloc = ALLOCATOR()) const;
769
772 template <class ALLOCATOR = default_allocator>
773 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
774
777 template <class ALLOCATOR = default_allocator>
778 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
779
781 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
782 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
783 const ALLOCATOR &alloc = ALLOCATOR()) const;
784
787 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
788 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
789 const ALLOCATOR &alloc = ALLOCATOR()) const;
790
793 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
794 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
795 const ALLOCATOR &alloc = ALLOCATOR()) const;
796
798 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
799 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
800 const ALLOCATOR &alloc = ALLOCATOR()) const;
801
804 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
805 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
806 const ALLOCATOR &alloc = ALLOCATOR()) const;
807
810 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
811 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
812 const ALLOCATOR &alloc = ALLOCATOR()) const;
813
819 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
820
825 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
826
832 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
833
839 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
840
841#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
842 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
843 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
844 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
845 *this = view;
846 view = temp;
847 }
848#endif /* __cpp_lib_string_view >= 201606L */
849
850 MDBX_CXX20_CONSTEXPR void swap(slice &other) noexcept {
851 auto temp = other;
852 other = *this;
853 *this = temp;
854 }
855
857 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
858 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
859
861 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
862 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
863
865 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
866 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
867
869 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
870 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
871
873 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
874 MDBX_CXX11_CONSTEXPR void *data() noexcept;
875
877 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
878 MDBX_CXX11_CONSTEXPR void *end() noexcept;
879
881 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
882
884 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
885
887 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
888
890 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
891
893 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
894
896 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
897
899 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
900
902 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
903
905 MDBX_CXX14_CONSTEXPR void clear() noexcept;
906
909 inline void remove_prefix(size_t n) noexcept;
910
913 inline void remove_suffix(size_t n) noexcept;
914
917 inline void safe_remove_prefix(size_t n);
918
921 inline void safe_remove_suffix(size_t n);
922
924 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
925
927 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
928
931 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
932
935 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
936
939 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
940
943 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
944
947 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
948
951 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
952
955 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
956
959 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
960
965 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
966
975 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
976
982 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
983 const slice &b) noexcept;
984 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, 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#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
991 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
992#endif /* __cpp_impl_three_way_comparison */
993
995 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
996
999 return slice(/* using special constructor without length checking */ ~size_t(0));
1000 }
1001
1003 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1004
1005 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1006 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1007 "Must be a standard layout type!");
1008 if (MDBX_LIKELY(size() == sizeof(POD)))
1010 POD _as_pod_local;
1011 memcpy(&_as_pod_local, data(), sizeof(_as_pod_local));
1012 return _as_pod_local;
1013 }
1015 }
1016
1017#ifdef MDBX_U128_TYPE
1018 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1019#endif /* MDBX_U128_TYPE */
1020 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1021 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1022 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1023 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1024
1025#ifdef MDBX_I128_TYPE
1026 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1027#endif /* MDBX_I128_TYPE */
1028 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1029 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1030 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1031 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1032
1033#ifdef MDBX_U128_TYPE
1034 MDBX_U128_TYPE as_uint128_adapt() const;
1035#endif /* MDBX_U128_TYPE */
1036 uint64_t as_uint64_adapt() const;
1037 uint32_t as_uint32_adapt() const;
1038 uint16_t as_uint16_adapt() const;
1039 uint8_t as_uint8_adapt() const;
1040
1041#ifdef MDBX_I128_TYPE
1042 MDBX_I128_TYPE as_int128_adapt() const;
1043#endif /* MDBX_I128_TYPE */
1044 int64_t as_int64_adapt() const;
1045 int32_t as_int32_adapt() const;
1046 int16_t as_int16_adapt() const;
1047 int8_t as_int8_adapt() const;
1048
1049protected:
1050 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1051};
1052
1056 bool done;
1057 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
1058 value_result(const value_result &) noexcept = default;
1059 value_result &operator=(const value_result &) noexcept = default;
1060 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1062 return done;
1063 }
1064};
1065
1067struct pair {
1068 using stl_pair = std::pair<slice, slice>;
1070 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
1071 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
1072 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
1073 pair(const pair &) noexcept = default;
1074 pair &operator=(const pair &) noexcept = default;
1075 pair &operator=(pair &&couple) noexcept {
1076 key.assign(std::move(couple.key));
1077 value.assign(std::move(couple.value));
1078 return *this;
1079 }
1080 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1081 MDBX_INLINE_API_ASSERT(bool(key) == bool(value));
1082 return key;
1083 }
1085
1086 pair &operator=(const stl_pair &couple) {
1087 key.assign(couple.first);
1088 value.assign(couple.second);
1089 return *this;
1090 }
1092 key.assign(std::move(couple.first));
1093 value.assign(std::move(couple.second));
1094 return *this;
1095 }
1096
1098 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
1099
1101 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
1102 const pair &b) noexcept;
1103 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, 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#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1110 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
1111#endif /* __cpp_impl_three_way_comparison */
1112};
1113
1116struct pair_result : public pair {
1117 bool done;
1120 : pair(key, value), done(done) {}
1121 pair_result(const pair_result &) noexcept = default;
1122 pair_result &operator=(const pair_result &) noexcept = default;
1123 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1124 MDBX_INLINE_API_ASSERT(!done || (bool(key) && bool(value)));
1125 return done;
1126 }
1127};
1128
1129#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
1130
1134template <typename T>
1135concept MutableByteProducer = requires(T a, char array[42]) {
1136 { a.is_empty() } -> std::same_as<bool>;
1137 { a.envisage_result_length() } -> std::same_as<size_t>;
1138 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1139};
1140
1144template <typename T>
1145concept ImmutableByteProducer = requires(const T &a, char array[42]) {
1146 { a.is_empty() } -> std::same_as<bool>;
1147 { a.envisage_result_length() } -> std::same_as<size_t>;
1148 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1149};
1150
1154template <typename T>
1155concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
1156 T(source);
1157 { a.is_erroneous() } -> std::same_as<bool>;
1158};
1159
1160#endif /* MDBX_HAVE_CXX20_CONCEPTS */
1161
1165 const bool uppercase = false;
1166 const unsigned wrap_width = 0;
1171
1173 template <class ALLOCATOR = default_allocator>
1174 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1175
1177 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1178 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1179
1183 const size_t bytes = source.length() << 1;
1184 return wrap_width ? bytes + bytes / wrap_width : bytes;
1185 }
1186
1189 char *write_bytes(char *dest, size_t dest_size) const;
1190
1193 ::std::ostream &output(::std::ostream &out) const;
1194
1197 bool is_empty() const noexcept { return source.empty(); }
1198
1201 bool is_erroneous() const noexcept { return false; }
1202};
1203
1208 const unsigned wrap_width = 0;
1213
1216 template <class ALLOCATOR = default_allocator>
1217 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1218
1221 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1222 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1223
1227 const size_t bytes = (source.length() * 11 + 7) / 8;
1228 return wrap_width ? bytes + bytes / wrap_width : bytes;
1229 }
1230
1233 char *write_bytes(char *dest, size_t dest_size) const;
1234
1237 ::std::ostream &output(::std::ostream &out) const;
1238
1240 bool is_empty() const noexcept { return source.empty(); }
1241
1243 bool is_erroneous() const noexcept { return false; }
1244};
1245
1250 const unsigned wrap_width = 0;
1255
1258 template <class ALLOCATOR = default_allocator>
1259 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1260
1263 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1264 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1265
1269 const size_t bytes = (source.length() + 2) / 3 * 4;
1270 return wrap_width ? bytes + bytes / wrap_width : bytes;
1271 }
1272
1276 char *write_bytes(char *dest, size_t dest_size) const;
1277
1281 ::std::ostream &output(::std::ostream &out) const;
1282
1285 bool is_empty() const noexcept { return source.empty(); }
1286
1289 bool is_erroneous() const noexcept { return false; }
1290};
1291
1295 const bool ignore_spaces = false;
1300
1302 template <class ALLOCATOR = default_allocator>
1303 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1304
1306 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1307 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1308
1311 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1312
1315 char *write_bytes(char *dest, size_t dest_size) const;
1316
1318 bool is_empty() const noexcept { return source.empty(); }
1319
1322 bool is_erroneous() const noexcept;
1323};
1324
1329 const bool ignore_spaces = false;
1334
1337 template <class ALLOCATOR = default_allocator>
1338 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1339
1342 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1343 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1344
1348 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1349 }
1350
1354 char *write_bytes(char *dest, size_t dest_size) const;
1355
1357 bool is_empty() const noexcept { return source.empty(); }
1358
1361 bool is_erroneous() const noexcept;
1362};
1363
1368 const bool ignore_spaces = false;
1373
1376 template <class ALLOCATOR = default_allocator>
1377 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1378
1381 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1382 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1383
1386 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1387
1391 char *write_bytes(char *dest, size_t dest_size) const;
1392
1395 bool is_empty() const noexcept { return source.empty(); }
1396
1400 bool is_erroneous() const noexcept;
1401};
1402
1404
1405template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1406#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1407 return ::std::allocator_traits<A>::is_always_equal::value;
1408#else
1409 return ::std::is_empty<A>::value;
1410#endif /* __cpp_lib_allocator_traits_is_always_equal */
1411}
1412
1413template <typename T, typename A = typename T::allocator_type,
1414 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1416
1417template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1418 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1419 static constexpr bool is_nothrow() noexcept { return is_always_equal(); }
1420 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1421 if MDBX_IF_CONSTEXPR (is_always_equal())
1422 return true;
1423 else
1424 return target->get_allocator() == source.get_allocator();
1425 }
1426 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &) noexcept { target->release(); }
1427};
1428
1429template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1430 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1431 static constexpr bool is_nothrow() noexcept { return ::std::is_nothrow_move_assignable<A>::value; }
1432 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1433 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1434 target->release();
1435 target->get_allocator() = ::std::move(source.get_allocator());
1436 }
1437};
1438
1439template <typename T, typename A = typename T::allocator_type,
1440 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1442
1443template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1444 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1445 static constexpr bool is_nothrow() noexcept { return false; }
1446 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1447};
1448
1449template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1450 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1451 static constexpr bool is_nothrow() noexcept {
1452 return is_always_equal() || ::std::is_nothrow_copy_assignable<A>::value;
1453 }
1454 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1455 if MDBX_IF_CONSTEXPR (!is_always_equal()) {
1456 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator())) {
1457 target->release();
1458 MDBX_CXX20_UNLIKELY target->get_allocator() = source.get_allocator();
1459 }
1460 } else {
1461 /* gag for buggy compilers */
1462 (void)target;
1463 (void)source;
1464 }
1465 }
1466};
1467
1468template <typename T, typename A = typename T::allocator_type,
1469 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1471
1472template <typename T, typename A> struct swap_alloc<T, A, false> {
1473 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1474 static constexpr bool is_nothrow() noexcept { return is_always_equal(); }
1475 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1476 if MDBX_IF_CONSTEXPR (!is_always_equal()) {
1477 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1478 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1479 } else {
1480 /* gag for buggy compilers */
1481 (void)left;
1482 (void)right;
1483 }
1484 }
1485};
1486
1487template <typename T, typename A> struct swap_alloc<T, A, true> {
1488 static constexpr bool is_always_equal() noexcept { return allocator_is_always_equal<A>(); }
1489 static constexpr bool is_nothrow() noexcept {
1490 return is_always_equal() ||
1491#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1492 ::std::is_nothrow_swappable<A>() ||
1493#endif /* __cpp_lib_is_swappable >= 201603L */
1494 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1495 }
1496 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1497 if MDBX_IF_CONSTEXPR (!is_always_equal())
1498 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1499 else {
1500 /* gag for buggy compilers */
1501 (void)left;
1502 (void)right;
1503 }
1504 }
1505};
1506
1507} // namespace allocation_aware_details
1508
1510 enum : size_t {
1515 };
1516
1517 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1518 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1519 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1520 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1521 return (value + pettiness_threshold - 1) & pettiness_mask;
1522 }
1523
1524 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1525 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1526 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1527
1528 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1529 return inplace;
1530
1531 if (wanna > current)
1532 /* doubling capacity, but don't made reserve more than max_reserve */
1533 return round(wanna + ::std::min(size_t(max_reserve), current));
1534
1535 if (current - wanna >
1536 /* shrink if reserve will more than half of current or max_reserve,
1537 * but not less than pettiness_threshold */
1538 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1539 return round(wanna);
1540
1541 /* keep unchanged */
1542 return current;
1543 }
1544};
1545
1547struct buffer_tag {};
1548
1550template <class ALLOCATOR, typename CAPACITY_POLICY>
1552public:
1554#if !defined(_MSC_VER) || _MSC_VER > 1900
1555 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1556#else
1557 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1558#endif /* MSVC is mad */
1559 using allocator_traits = ::std::allocator_traits<allocator_type>;
1560 using reservation_policy = CAPACITY_POLICY;
1561 enum : size_t {
1563 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1566 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1567 ? alignof(max_align_t) * 2
1570 };
1571
1573 enum class modality { reference, inplace, allocated };
1574
1575private:
1576 friend class txn;
1577 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1578 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1579 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1580
1581 using allocator_pointer = typename allocator_traits::pointer;
1582 using allocator_const_pointer = typename allocator_traits::const_pointer;
1583 using move_assign_alloc = allocation_aware_details::move_assign_alloc<silo, allocator_type>;
1584 using copy_assign_alloc = allocation_aware_details::copy_assign_alloc<silo, allocator_type>;
1585 using swap_alloc = allocation_aware_details::swap_alloc<silo, allocator_type>;
1586
1587 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1588 MDBX_INLINE_API_ASSERT(bytes >= sizeof(bin));
1589 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1590 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1591 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1592 const size_t n = (bytes + unit - 1) / unit;
1593 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1594 }
1595
1596 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1597 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1598 MDBX_INLINE_API_ASSERT(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1599 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1600 }
1601
1602 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1603 const size_t capacity = bin::advise_capacity(0, bytes);
1604 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1605 : allocate_storage(capacity);
1606 }
1607
1608 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1609#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1610 return static_cast<void *>(::std::to_address(ptr));
1611#else
1612 return static_cast<void *>(::std::addressof(*ptr));
1613#endif /* __cpp_lib_to_address */
1614 }
1615
1616 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1617#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1618 return static_cast<const void *>(::std::to_address(ptr));
1619#else
1620 return static_cast<const void *>(::std::addressof(*ptr));
1621#endif /* __cpp_lib_to_address */
1622 }
1623
1624#ifdef _MSC_VER
1625#pragma warning(push)
1626#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1627#endif /* _MSC_VER */
1628
1629 union alignas(max_align_t) bin {
1630 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1631 с учетом выравнивания */
1632 {
1633 allocator_pointer stub_ptr_;
1635 };
1636
1638 enum : size_t {
1640 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1644 };
1645
1647 byte pad_[inplace_size - sizeof(allocator_pointer)];
1648 size_t bytes_;
1649 };
1650
1652 byte buffer_[inplace_size - sizeof(byte)];
1655 };
1656
1657 allocator_pointer allocated_ptr_;
1660
1661 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1662 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1663 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1664 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1665 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1666 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1667 return capacity_bytes <= inplace_capacity();
1668 }
1669
1670 MDBX_NOTHROW_PURE_FUNCTION constexpr bool is_inplace() const noexcept {
1671 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1672 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1674 "WTF?");
1675 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1676 }
1677 MDBX_NOTHROW_PURE_FUNCTION constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1678
1681 /* properly destroy allocator::pointer */
1682 allocated_ptr_.~allocator_pointer();
1685 return address();
1686 }
1687
1688 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1691 new (&allocated_ptr_) allocator_pointer(pair.first);
1692 capacity_.bytes_ = pair.second;
1693 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1694 return address();
1695 }
1696
1698 if (::std::is_trivial<allocator_pointer>::value)
1699 /* workaround for "uninitialized" warning from some compilers */
1700 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1701 }
1702
1703 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1704 if (MDBX_UNLIKELY(wanna > max_capacity))
1705 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1706
1707 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1708 MDBX_INLINE_API_ASSERT(advised >= wanna);
1709 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1710 }
1711
1712 constexpr bool is_inplace(const void *ptr) const noexcept {
1713 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1714 }
1715
1716 constexpr const byte *address() const noexcept {
1717 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1718 }
1720 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1721 }
1722 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1723 } bin_;
1724
1725#ifdef _MSC_VER
1726#pragma warning(pop)
1727#endif /* _MSC_VER */
1728
1729 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1730
1731 MDBX_CXX20_CONSTEXPR void release() noexcept {
1732 if (bin_.is_allocated()) {
1733 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1734 /* properly destroy allocator::pointer */
1735 bin_.allocated_ptr_.~allocator_pointer();
1736 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1737 }
1738 }
1739
1740 template <bool external_content>
1741 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1742 const void *const content, const size_t length) {
1743 MDBX_INLINE_API_ASSERT(wanna_capacity >= wanna_headroom + length);
1744 const size_t old_capacity = bin_.capacity();
1745 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1746 if (MDBX_LIKELY(new_capacity == old_capacity))
1748 MDBX_INLINE_API_ASSERT(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1749 byte *const new_place = bin_.address() + wanna_headroom;
1750 if (MDBX_LIKELY(length))
1752 if (external_content)
1753 memcpy(new_place, content, length);
1754 else {
1755 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1756 MDBX_INLINE_API_ASSERT(old_capacity >= old_headroom + length);
1757 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1758 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1759 }
1760 }
1761 return new_place;
1762 }
1763
1764 if (bin::is_suitable_for_inplace(new_capacity)) {
1765 MDBX_INLINE_API_ASSERT(bin_.is_allocated());
1766 const auto old_allocated = bin_.allocated_ptr_;
1767 byte *const new_place = bin_.make_inplace() + wanna_headroom;
1768 if (MDBX_LIKELY(length))
1769 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1770 deallocate_storage(old_allocated, old_capacity);
1771 return new_place;
1772 }
1773
1774 if (bin_.is_inplace()) {
1775 const auto pair = allocate_storage(new_capacity);
1776 MDBX_INLINE_API_ASSERT(pair.second >= new_capacity);
1777 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1778 bin_.make_allocated(pair);
1779 if (MDBX_LIKELY(length))
1780 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1781 return new_place;
1782 }
1783
1784 auto pair = allocate_storage(new_capacity);
1785 std::swap(bin_.allocated_ptr_, pair.first);
1786 bin_.capacity_.bytes_ = pair.second;
1787 auto new_place = bin_.address() + wanna_headroom;
1788 if (MDBX_LIKELY(length))
1789 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1790 deallocate_storage(pair.first, old_capacity);
1791 return new_place;
1792 }
1793
1794 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1795 MDBX_INLINE_API_ASSERT(capacity() >= offset);
1796 return bin_.address() + offset;
1797 }
1798 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1799 MDBX_INLINE_API_ASSERT(capacity() >= offset);
1800 return bin_.address() + offset;
1801 }
1802 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1803 MDBX_INLINE_API_ASSERT(capacity() >= offset + length);
1804 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1805 }
1806
1807 //--------------------------------------------------------------------------
1808
1809 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1810 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1811 if (!bin::is_suitable_for_inplace(capacity))
1812 bin_.make_allocated(provide_storage(capacity));
1813 }
1814
1815 silo(silo &&other) = delete;
1817 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1818 : allocator_type(::std::move(other.get_allocator())) {
1819 if (!is_reference) {
1820 if (other.bin_.is_inplace()) {
1821 memcpy(&bin_, &other.bin_, sizeof(bin));
1822 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1823 } else {
1824 /* coverity[USE_AFTER_MOVE] */
1825 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1826 /* coverity[USE_AFTER_MOVE] */
1827 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1828 /* properly destroy allocator::pointer.
1829 *
1830 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1831 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1832 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1833 * from the 11th). */
1834 /* coverity[USE_AFTER_MOVE] */
1835 other.bin_.allocated_ptr_.~allocator_pointer();
1836 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1837 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1838 }
1839 }
1840 }
1841
1842 MDBX_CXX17_CONSTEXPR bool move_content(silo &other, const modality other_modality) noexcept {
1843 switch (other_modality) {
1844 case modality::inplace:
1845 memcpy(&bin_, &other.bin_, sizeof(bin));
1846 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1847 return /* buffer's slice fixup is needed */ true;
1848 case modality::allocated:
1849 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1850 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1851 /* properly destroy allocator::pointer.
1852 *
1853 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1854 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1855 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1856 * from the 11th). */
1857 /* coverity[use_after_move] */
1858 other.bin_.allocated_ptr_.~allocator_pointer();
1859 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1860 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1861 return /* buffer's slice fixup is not needed */ false;
1862 default:
1863 MDBX_CONSTEXPR_ASSERT(other_modality == modality::reference);
1864 return /* buffer's slice fixup is not needed */ false;
1865 }
1866 }
1867
1868 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1869 exchange(silo &left, const modality left_modality, silo &right,
1870 const modality right_modality) noexcept(swap_alloc::is_nothrow()) {
1871 swap_alloc::propagate(left, right);
1872 bool left_need_fixup = false, right_need_fixup = false;
1873 if (left_modality == modality::reference || right_modality == modality::reference) {
1874 /* It is Ok here to call move_content for the left and right side in any order,
1875 * since the move_content() does nothing when modality == reference.
1876 * Thus, the actual move action will perform no more than one call of move_content(),
1877 * so the order doesn't matter here. */
1878 left_need_fixup = left.move_content(right, right_modality);
1879 right_need_fixup = right.move_content(left, left_modality);
1880 } else {
1881 silo temp(std::move(left), false);
1882 left_need_fixup = left.move_content(right, right_modality);
1883 right_need_fixup = right.move_content(temp, left_modality);
1884 }
1885 return std::make_pair(left_need_fixup, right_need_fixup);
1886 }
1887
1888 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1889 const allocator_type &alloc = allocator_type())
1890 : silo(capacity, alloc) {
1891 MDBX_INLINE_API_ASSERT(capacity >= headroom + length);
1892 if (length)
1893 put(headroom, ptr, length);
1894 }
1895
1896 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1897 : silo(length, 0, ptr, length, alloc) {}
1898
1899 ~silo() { release(); }
1900
1901 //--------------------------------------------------------------------------
1902
1903 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1904 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1905 }
1906
1907 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1908
1909 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1910 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1911 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1912 }
1913
1914 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1915 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1916 }
1917
1918 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1919 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1920 return get(offset);
1921 }
1922 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1923 };
1924
1925 MDBX_CXX14_CONSTEXPR void fixup_imported_inplace(const typename silo::bin &src) noexcept {
1926 auto ptr = inherited::byte_ptr();
1927 if (src.is_inplace(ptr)) {
1928 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1929 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1930 iov_base = ptr + offset;
1931 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1932 }
1933 }
1934
1935 silo silo_;
1936
1937 void insulate() {
1938 MDBX_INLINE_API_ASSERT(is_reference());
1939 iov_base = silo_.assign(iov_base, iov_len);
1940 }
1941
1942 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1943 return static_cast<const byte *>(silo_.data());
1944 }
1945
1946 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1947 return silo_begin() + silo_.capacity();
1948 }
1949
1950 struct data_preserver : public exception_thunk {
1951 buffer data;
1952 data_preserver(allocator_type &alloc) : data(alloc) {}
1953 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1954 auto self = static_cast<data_preserver *>(context);
1955 assert(self->is_clean());
1956 assert(&self->data == target);
1957 (void)target;
1958 try {
1959 self->data.assign(src, bytes, false);
1960 return MDBX_RESULT_FALSE;
1961 } catch (... /* capture any exception to rethrow it over C code */) {
1962 self->capture();
1963 return MDBX_RESULT_TRUE;
1964 }
1965 }
1966 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1967 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1968 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1969 };
1970
1971public:
1974
1975 using move_assign_alloc = typename silo::move_assign_alloc;
1976 using copy_assign_alloc = typename silo::copy_assign_alloc;
1977 using swap_alloc = typename silo::swap_alloc;
1978 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1979
1981 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1982
1986 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1987 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1988 }
1989
1994 return silo_.is_inplace(inherited::data());
1995 }
1996
1999
2002 return is_freestanding() ? (is_inplace() ? modality::inplace : modality::allocated) : modality::reference;
2003 }
2004
2007 return is_freestanding() ? silo_.capacity() : 0;
2008 }
2009
2012 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
2013 }
2014
2017 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2018 }
2019
2021 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2022
2024 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2025
2032
2037 return const_cast<byte *>(inherited::end_byte_ptr());
2038 }
2039
2041 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2042
2044 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2045
2050 return const_cast<char *>(inherited::char_ptr());
2051 }
2052
2057 return const_cast<char *>(inherited::end_char_ptr());
2058 }
2059
2061 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
2062
2064 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
2065
2068 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2070 return const_cast<void *>(inherited::data());
2071 }
2072
2075 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2077 return const_cast<void *>(inherited::end());
2078 }
2079
2084
2091
2094 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2095 return set_length(static_cast<const char *>(ptr) - char_ptr());
2096 }
2097
2102 if (is_reference())
2103 insulate();
2104 }
2105
2106 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2107 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2108 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2109 const allocator_type &alloc = allocator_type());
2110
2112 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2113 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2114
2115 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2116 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2117
2118 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2119 : buffer(inherited(c_str), make_reference, alloc) {}
2120
2121#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2122 template <class CHAR, class T>
2123 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2124 const allocator_type &alloc = allocator_type())
2125 : buffer(inherited(view), make_reference, alloc) {}
2126#endif /* __cpp_lib_string_view >= 201606L */
2127
2129 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2130 : buffer(src, src.empty() || src.is_null(), alloc) {}
2131
2133 buffer(const buffer &src)
2134 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2135
2137 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2138 : buffer(inherited(ptr, bytes), alloc) {}
2139
2140 template <class CHAR, class T, class A>
2141 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2142 const allocator_type &alloc = allocator_type())
2143 : buffer(inherited(str), alloc) {}
2144
2146 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2147
2148#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2149 template <class CHAR, class T>
2150 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2151 const allocator_type &alloc = allocator_type())
2152 : buffer(inherited(view), alloc) {}
2153#endif /* __cpp_lib_string_view >= 201606L */
2154
2155 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2156 : silo_(check_length(head_room, tail_room), alloc) {
2157 iov_base = silo_.get(head_room);
2158 MDBX_INLINE_API_ASSERT(iov_len == 0);
2159 }
2160
2161 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2162 iov_base = silo_.get();
2163 MDBX_INLINE_API_ASSERT(iov_len == 0);
2164 }
2165
2166 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2167 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2168 iov_len = src.length();
2169 iov_base = memcpy(silo_.get(head_room), src.data(), iov_len);
2170 }
2171
2172 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2173
2174 buffer(buffer &&src) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
2175 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2176 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2177 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2178 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2179 * 11th). */
2180 /* coverity[USE_AFTER_MOVE] */
2181 fixup_imported_inplace(src.silo_.bin_);
2182 src.invalidate();
2183 }
2184
2186 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2187
2190
2191 template <typename POD>
2192 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2193 return buffer(inherited::wrap(pod), make_reference, alloc);
2194 }
2195
2197 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2198 const allocator_type &alloc = allocator_type()) {
2199 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2200 }
2201
2204 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2205 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2206 }
2207
2209 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2210 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2211 }
2212
2214 template <typename POD>
2215 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2216 const allocator_type &alloc = allocator_type()) {
2217 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2218 }
2219
2222 template <typename POD>
2223 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2224 return base58(inherited::wrap(pod), wrap_width, alloc);
2225 }
2226
2229 template <typename POD>
2230 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2231 return base64(inherited::wrap(pod), wrap_width, alloc);
2232 }
2233
2235 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2236 const allocator_type &alloc = allocator_type()) const {
2237 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2238 }
2239
2242 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2243 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2244 }
2245
2247 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2248 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2249 }
2250
2252 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2253 const allocator_type &alloc = allocator_type()) {
2254 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2255 }
2256
2259 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2260 const allocator_type &alloc = allocator_type()) {
2261 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2262 }
2263
2266 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2267 const allocator_type &alloc = allocator_type()) {
2268 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2269 }
2270
2273 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2274 return hex_decode(*this, ignore_spaces, alloc);
2275 }
2276
2279 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2280 return base58_decode(*this, ignore_spaces, alloc);
2281 }
2282
2285 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2286 return base64_decode(*this, ignore_spaces, alloc);
2287 }
2288
2290 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2291 wanna_headroom = ::std::min(
2292 ::std::max(headroom(), wanna_headroom),
2293 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2294 wanna_tailroom = ::std::min(
2295 ::std::max(tailroom(), wanna_tailroom),
2296 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2297 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2298 silo_.resize(wanna_capacity, wanna_headroom, *this);
2299 MDBX_INLINE_API_ASSERT(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2300 MDBX_INLINE_API_ASSERT(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2301 }
2302
2304 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2305
2307 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2308
2309 buffer &assign_reference(const void *ptr, size_t bytes) {
2310 silo_.clear();
2312 return *this;
2313 }
2314
2315 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2316 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2317 return *this;
2318 }
2319
2320 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2321 const auto pair = silo::exchange(silo_, content_modality(), other.silo_, other.content_modality());
2322 inherited::swap(other);
2323 if (pair.first)
2324 fixup_imported_inplace(other.silo_.bin_);
2325 if (pair.second)
2326 other.fixup_imported_inplace(silo_.bin_);
2327 }
2328
2329 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2330 left.swap(right);
2331 }
2332
2333 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2334 return buffer(src.headroom(), src, src.tailroom(), alloc);
2335 }
2336
2338 return buffer(static_cast<const struct slice &>(*this), !is_inplace(),
2339 allocator_traits::select_on_container_copy_construction(get_allocator()));
2340 }
2341
2343 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2344 if (MDBX_LIKELY(this != &src))
2346 invalidate();
2347 copy_assign_alloc::propagate(&silo_, src.silo_);
2348 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2349 iov_len = src.length();
2350 }
2351 else {
2352 iov_base = silo_.template reshape<false>(whole_capacity, headroom, src.data(), src.length());
2353 }
2354 return *this;
2355 }
2356
2357 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2358 if (MDBX_LIKELY(this != &src))
2360 invalidate();
2361 copy_assign_alloc::propagate(&silo_, src.silo_);
2362 if (make_reference) {
2363 silo_.release();
2364 iov_base = src.iov_base;
2365 } else {
2366 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2367 }
2368 iov_len = src.length();
2369 }
2370 else if (!make_reference && is_reference())
2371 insulate();
2372 return *this;
2373 }
2374
2375 MDBX_CXX20_CONSTEXPR buffer &assign(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) {
2376 if (MDBX_LIKELY(this != &src))
2378 const auto kind = src.content_modality();
2379 const auto src_headroom = src.headroom();
2380 const auto src_data = src.data();
2381 const auto src_length = src.length();
2382 inherited::assign(std::move(src));
2383 if (!move_assign_alloc::is_moveable(&silo_, src.silo_) && kind == modality::allocated) {
2384 iov_base = silo_.template reshape<true>(src.silo_.capacity(), src_headroom, src_data, src_length);
2385 return *this;
2386 }
2387 move_assign_alloc::propagate(&silo_, src.silo_);
2388 if (silo_.move_content(src.silo_, kind))
2389 fixup_imported_inplace(src.silo_.bin_);
2390 }
2391 return *this;
2392 }
2393
2394 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2395 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2396 }
2397
2398 buffer &assign(const struct slice &src, bool make_reference = false) {
2399 return assign(src.data(), src.length(), make_reference);
2400 }
2401
2402 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2403 return assign(src.iov_base, src.iov_len, make_reference);
2404 }
2405
2406 buffer &assign(struct slice &&src, bool make_reference = false) {
2407 assign(src.data(), src.length(), make_reference);
2408 src.invalidate();
2409 return *this;
2410 }
2411
2412 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2413 assign(src.iov_base, src.iov_len, make_reference);
2414 src.iov_base = nullptr;
2415 return *this;
2416 }
2417
2418 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2419 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2420 }
2421
2422 template <class CHAR, class T, class A>
2423 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2424 return assign(str.data(), str.length(), make_reference);
2425 }
2426
2427 buffer &assign(const char *c_str, bool make_reference = false) {
2428 return assign(c_str, strlen(c_str), make_reference);
2429 }
2430
2431#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2432 template <class CHAR, class T>
2433 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2434 return assign(view.data(), view.length(), make_reference);
2435 }
2436
2437 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2438 assign(view.data(), view.length(), make_reference);
2439 view = {};
2440 return *this;
2441 }
2442#endif /* __cpp_lib_string_view >= 201606L */
2443
2444 buffer &operator=(const buffer &src) { return assign(src); }
2445
2446 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2447
2448 buffer &operator=(const struct slice &src) { return assign(src); }
2449
2450 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2451
2452#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2453 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2454 return assign(view.begin(), view.length());
2455 }
2456
2457 template <class CHAR, class T> buffer &append(const ::std::basic_string_view<CHAR, T> &view) {
2458 return append(view.data(), view.size());
2459 }
2460#endif /* __cpp_lib_string_view >= 201606L */
2461
2462 template <class CHAR, class T, class A>
2463 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2464 return as_string<CHAR, T, A>();
2465 }
2466
2467 template <class CHAR, class T, class A> buffer &append(const ::std::basic_string<CHAR, T, A> &str) {
2468 return append(str.data(), str.size());
2469 }
2470
2472 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2473
2475 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2476 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2477 }
2478
2480 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2481
2482 buffer &append(const void *src, size_t bytes) {
2483 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2484 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2485 memcpy(end_byte_ptr(), src, bytes);
2486 iov_len += bytes;
2487 return *this;
2488 }
2489
2490 buffer &append(const byte c) {
2491 if (MDBX_UNLIKELY(tailroom() < 1))
2492 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2493 *end_byte_ptr() = c;
2494 iov_len += 1;
2495 return *this;
2496 }
2497
2498 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2499
2500 buffer &add_header(const void *src, size_t bytes) {
2501 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2502 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2503 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2504 iov_len += bytes;
2505 return *this;
2506 }
2507
2508 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2509
2510 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2511 const size_t wanna_bytes = producer.envisage_result_length();
2512 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2513 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2514 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2515 }
2516
2517 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2518 const size_t wanna_bytes = producer.envisage_result_length();
2519 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2520 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2521 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2522 }
2523
2524 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2525 return append_producer(to_hex(data, uppercase, wrap_width));
2526 }
2527
2528 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2529 return append_producer(to_base58(data, wrap_width));
2530 }
2531
2532 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2533 return append_producer(to_base64(data, wrap_width));
2534 }
2535
2536 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2537 return append_producer(from_hex(data, ignore_spaces));
2538 }
2539
2540 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2541 return append_producer(from_base58(data, ignore_spaces));
2542 }
2543
2544 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2545 return append_producer(from_base64(data, ignore_spaces));
2546 }
2547
2548 buffer &append_u8(uint_fast8_t u8) {
2549 if (MDBX_UNLIKELY(tailroom() < 1))
2550 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2551 *end_byte_ptr() = uint8_t(u8);
2552 iov_len += 1;
2553 return *this;
2554 }
2555
2556 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2557
2558 buffer &append_u16(uint_fast16_t u16) {
2559 if (MDBX_UNLIKELY(tailroom() < 2))
2560 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2561 const auto ptr = end_byte_ptr();
2562 ptr[0] = uint8_t(u16);
2563 ptr[1] = uint8_t(u16 >> 8);
2564 iov_len += 2;
2565 return *this;
2566 }
2567
2568 buffer &append_u24(uint_fast32_t u24) {
2569 if (MDBX_UNLIKELY(tailroom() < 3))
2570 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2571 const auto ptr = end_byte_ptr();
2572 ptr[0] = uint8_t(u24);
2573 ptr[1] = uint8_t(u24 >> 8);
2574 ptr[2] = uint8_t(u24 >> 16);
2575 iov_len += 3;
2576 return *this;
2577 }
2578
2579 buffer &append_u32(uint_fast32_t u32) {
2580 if (MDBX_UNLIKELY(tailroom() < 4))
2581 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2582 const auto ptr = end_byte_ptr();
2583 ptr[0] = uint8_t(u32);
2584 ptr[1] = uint8_t(u32 >> 8);
2585 ptr[2] = uint8_t(u32 >> 16);
2586 ptr[3] = uint8_t(u32 >> 24);
2587 iov_len += 4;
2588 return *this;
2589 }
2590
2591 buffer &append_u48(uint_fast64_t u48) {
2592 if (MDBX_UNLIKELY(tailroom() < 6))
2593 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2594 const auto ptr = end_byte_ptr();
2595 ptr[0] = uint8_t(u48);
2596 ptr[1] = uint8_t(u48 >> 8);
2597 ptr[2] = uint8_t(u48 >> 16);
2598 ptr[3] = uint8_t(u48 >> 24);
2599 ptr[4] = uint8_t(u48 >> 32);
2600 ptr[5] = uint8_t(u48 >> 40);
2601 iov_len += 6;
2602 return *this;
2603 }
2604
2605 buffer &append_u64(uint_fast64_t u64) {
2606 if (MDBX_UNLIKELY(tailroom() < 8))
2607 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2608 const auto ptr = end_byte_ptr();
2609 ptr[0] = uint8_t(u64);
2610 ptr[1] = uint8_t(u64 >> 8);
2611 ptr[2] = uint8_t(u64 >> 16);
2612 ptr[3] = uint8_t(u64 >> 24);
2613 ptr[4] = uint8_t(u64 >> 32);
2614 ptr[5] = uint8_t(u64 >> 40);
2615 ptr[6] = uint8_t(u64 >> 48);
2616 ptr[7] = uint8_t(u64 >> 56);
2617 iov_len += 8;
2618 return *this;
2619 }
2620
2621 //----------------------------------------------------------------------------
2622
2623 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2624 return buffer(inherited(text), make_reference);
2625 }
2626
2627#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2628 template <class CHAR, class T>
2629 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2630 return buffer(src, make_reference);
2631 }
2632#endif /* __cpp_lib_string_view >= 201606L */
2633
2634 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2635
2636 template <class CHAR, class T, class A>
2637 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2638 return buffer(src, make_reference);
2639 }
2640
2641 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2642
2643 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2644
2645 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2646
2647 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2648
2649 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2650
2651 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2652
2653 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2654
2655 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2656
2657 static buffer key_from_jsonInteger(const int64_t json_integer) {
2658 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2659 }
2660
2661 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2662
2663 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2664
2665 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2666
2667 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2668
2669 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2670
2671 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2672
2673 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2674
2675 const slice &slice() const noexcept { return *this; }
2676};
2677
2678template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2682 using reservation_policy = CAPACITY_POLICY;
2683 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2685
2688 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2689
2691 : key(key, alloc), value(value, alloc) {}
2692 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2693 const allocator_type &alloc = allocator_type())
2694 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2695
2697 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2698 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2699 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2700
2702 : key(key, alloc), value(value, alloc) {}
2703 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2704 const allocator_type &alloc = allocator_type())
2705 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2706
2709 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2710 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2711
2712 buffer_pair_spec(const txn &transaction, const slice &key, const slice &value,
2713 const allocator_type &alloc = allocator_type())
2714 : key(transaction, key, alloc), value(transaction, value, alloc) {}
2715 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2716 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2717
2718 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2719 : key(::std::move(key)), value(::std::move(value)) {}
2721 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2722 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2723
2726 key.assign(std::move(src.key));
2727 value.assign(std::move(src.value));
2728 return *this;
2729 }
2730
2732 key.assign(src.key);
2733 value.assign(src.value);
2734 return *this;
2735 }
2737 key.assign(std::move(src.key));
2738 value.assign(std::move(src.value));
2739 return *this;
2740 }
2742 key.assign(src.first);
2743 value.assign(src.second);
2744 return *this;
2745 }
2747 key.assign(std::move(src.first));
2748 value.assign(std::move(src.second));
2749 return *this;
2750 }
2751
2755 return key.is_freestanding() && value.is_freestanding();
2756 }
2757
2760 return key.is_reference() || value.is_reference();
2761 }
2762
2766 key.make_freestanding();
2767 value.make_freestanding();
2768 }
2769
2770 operator pair() const noexcept { return pair(key, value); }
2771};
2772
2774
2777public:
2778 cache_entry() noexcept { reset(); }
2779 cache_entry(const cache_entry &) noexcept = default;
2780 cache_entry &operator=(const cache_entry &) noexcept = default;
2781 cache_entry(cache_entry &&other) noexcept {
2782 *this = other;
2783 other.reset();
2784 }
2785 void reset() noexcept { mdbx_cache_init(this); }
2786 MDBX_CXX20_CONSTEXPR cache_entry(const MDBX_cache_entry_t &ce) noexcept { mdbx::memcpy(this, &ce, sizeof(*this)); }
2788 mdbx::memcpy(this, &ce, sizeof(*this));
2789 return *this;
2790 };
2791};
2792
2793//------------------------------------------------------------------------------
2794
2797enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2798
2815
2817 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2818}
2819
2821 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2822}
2823
2825 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2826}
2827
2829 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2830}
2831
2833
2891
2895
2897 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2898}
2899
2901 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2902}
2903
2905 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2906}
2907
2909 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2910}
2911
2913
2924 map_handle(const map_handle &) noexcept = default;
2925 map_handle &operator=(const map_handle &) noexcept = default;
2926 operator bool() const noexcept { return dbi != 0; }
2927 operator MDBX_dbi() const { return dbi; }
2928
2929#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2930 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2931 return a.dbi <=> b.dbi;
2932 }
2933#endif /* __cpp_impl_three_way_comparison */
2934 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2935 return a.dbi == b.dbi;
2936 }
2937 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2938 return a.dbi < b.dbi;
2939 }
2940 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2941 return a.dbi > b.dbi;
2942 }
2943 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2944 return a.dbi <= b.dbi;
2945 }
2946 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2947 return a.dbi >= b.dbi;
2948 }
2949 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2950 return a.dbi != b.dbi;
2951 }
2952
2964};
2965
2968 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2969}
2971 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2972}
2973
2980
2989 friend class txn;
2990
2991protected:
2993 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2994
2995public:
2996 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2997 env(const env &) noexcept = default;
2998 env &operator=(const env &) noexcept = default;
2999 inline env &operator=(env &&) noexcept;
3000 inline env(env &&) noexcept;
3001 inline ~env() noexcept;
3002
3003 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
3004 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const noexcept { return handle_; }
3005 MDBX_CXX14_CONSTEXPR operator MDBX_env *() noexcept { return handle_; }
3006 MDBX_CXX14_CONSTEXPR const MDBX_env *handle() const noexcept { return handle_; }
3008 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
3009 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
3010
3011 //----------------------------------------------------------------------------
3012
3017
3019 enum : intptr_t {
3022 maximal_value = INTPTR_MAX,
3023 kB = 1000,
3024 MB = kB * 1000,
3025 GB = MB * 1000,
3026#if INTPTR_MAX > 0x7fffFFFFl
3027 TB = GB * 1000,
3028 PB = TB * 1000,
3029 EB = PB * 1000,
3030#endif /* 64-bit intptr_t */
3031 KiB = 1024,
3032 MiB = KiB << 10,
3033 GiB = MiB << 10,
3034#if INTPTR_MAX > 0x7fffFFFFl
3035 TiB = GiB << 10,
3036 PiB = TiB << 10,
3037 EiB = PiB << 10,
3038#endif /* 64-bit intptr_t */
3039 };
3040
3042 struct size {
3043 intptr_t bytes;
3044 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3045 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3046 };
3047
3050
3055
3067
3070
3073
3079
3080 inline geometry &make_fixed(intptr_t size) noexcept;
3081 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3084 geometry(const geometry &) noexcept = default;
3085 MDBX_CXX14_CONSTEXPR geometry &operator=(const geometry &) noexcept = default;
3091 };
3092
3100
3108
3119
3141
3146 unsigned max_maps{0};
3149 unsigned max_readers{0};
3154
3165 operate_parameters(const operate_parameters &) noexcept = default;
3167 MDBX_env_flags_t make_flags(bool accede = true,
3170 bool use_subdirectory = false
3171 ) const;
3175 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3176 };
3177
3181 inline env::mode get_mode() const;
3183 inline env::durability get_durability() const;
3187 inline env::operate_options get_options() const;
3188
3191 bool is_pristine() const;
3192
3194 bool is_empty() const;
3195
3197 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3198
3199 struct limits {
3200 limits() = delete;
3202 static inline size_t pagesize_min() noexcept;
3204 static inline size_t pagesize_max() noexcept;
3206 static inline size_t dbsize_min(intptr_t pagesize);
3208 static inline size_t dbsize_max(intptr_t pagesize);
3210 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3212 static inline size_t key_min(key_mode mode) noexcept;
3214 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3216 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3218 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3220 static inline size_t key_max(const env &, key_mode mode);
3222 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3224 static inline size_t value_min(value_mode) noexcept;
3225
3227 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3229 static inline size_t value_max(intptr_t pagesize, value_mode);
3231 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3233 static inline size_t value_max(const env &, value_mode);
3234
3237 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3240 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3243 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3246 static inline size_t pairsize4page_max(const env &, value_mode);
3247
3250 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3253 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3256 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3259 static inline size_t valsize4page_max(const env &, value_mode);
3260
3263 static inline size_t transaction_size_max(intptr_t pagesize);
3264
3266 static inline size_t max_map_handles(void);
3267 };
3268
3270 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3272 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3274 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3276 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3278 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3280 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3284
3287#ifdef MDBX_STD_FILESYSTEM_PATH
3288 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3289#endif /* MDBX_STD_FILESYSTEM_PATH */
3290#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3291 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3292 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3293#endif /* Windows */
3294 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3295 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3296
3298 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3299
3315
3317#ifdef MDBX_STD_FILESYSTEM_PATH
3318 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3319#endif /* MDBX_STD_FILESYSTEM_PATH */
3320#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3321 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3322 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3323#endif /* Windows */
3324 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3325 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3326
3329
3332
3334 inline stat get_stat() const;
3335
3337 size_t get_pagesize() const { return get_stat().ms_psize; }
3338
3340 inline info get_info() const;
3341
3343 inline stat get_stat(const txn &) const;
3344
3346 inline info get_info(const txn &) const;
3347
3349 inline filehandle get_filehandle() const;
3350
3352 const path_char *get_path() const;
3353
3355 inline MDBX_env_flags_t get_flags() const;
3356
3357 inline bool is_readonly() const { return (get_flags() & MDBX_RDONLY) != 0; }
3358
3359 inline bool is_exclusive() const { return (get_flags() & MDBX_EXCLUSIVE) != 0; }
3360
3361 inline bool is_cooperative() const { return !is_exclusive(); }
3362
3363 inline bool is_writemap() const { return (get_flags() & MDBX_WRITEMAP) != 0; }
3364
3365 inline bool is_readwrite() const { return !is_readonly(); }
3366
3367 inline bool is_nested_transactions_available() const { return (get_flags() & (MDBX_WRITEMAP | MDBX_RDONLY)) == 0; }
3368
3371 inline unsigned max_readers() const;
3372
3375 inline unsigned max_maps() const;
3376
3378 inline void *get_context() const noexcept;
3379
3381 inline env &set_context(void *your_context);
3382
3397 inline env &set_sync_threshold(size_t bytes);
3398
3404 inline size_t sync_threshold() const;
3405
3406#if __cplusplus >= 201103L || defined(DOXYGEN)
3426 inline env &set_sync_period(const duration &period);
3427
3433 inline duration sync_period() const;
3434#endif
3435
3439 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3440
3443 inline unsigned sync_period__seconds_16dot16() const;
3444
3448 inline env &set_sync_period__seconds_double(double seconds);
3449
3452 inline double sync_period__seconds_double() const;
3453
3507
3509 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3510
3512 inline uint64_t extra_option(extra_runtime_option option) const;
3513
3515 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3516
3518 inline env &set_geometry(const geometry &size);
3519
3523 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3524
3528 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3529
3548 inline void close_map(const map_handle &);
3549
3552 int slot;
3561 size_t bytes_used;
3570
3572 size_t used, size_t retained) noexcept;
3573 };
3574
3582 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3583
3586 inline unsigned check_readers();
3587
3606
3611 inline MDBX_hsr_func get_HandleSlowReaders() const noexcept;
3612
3614 inline txn_managed start_read() const;
3615
3617 inline txn_managed prepare_read() const;
3618
3620 inline txn_managed start_write(txn &parent);
3621
3623 inline txn_managed start_write(bool dont_wait = false);
3624
3627};
3628
3637class LIBMDBX_API_TYPE env_managed : public env {
3638 using inherited = env;
3640 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3641 void setup(unsigned max_maps, unsigned max_readers = 0);
3642
3643public:
3644 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3645
3647#ifdef MDBX_STD_FILESYSTEM_PATH
3648 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3649#endif /* MDBX_STD_FILESYSTEM_PATH */
3650#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3651 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3652 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3653#endif /* Windows */
3654 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3655 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3656
3667
3669#ifdef MDBX_STD_FILESYSTEM_PATH
3671 bool accede = true);
3672#endif /* MDBX_STD_FILESYSTEM_PATH */
3673#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3674 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3675 bool accede = true);
3676 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3677 bool accede = true);
3678#endif /* Windows */
3679 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3680 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3681
3695 void close(bool dont_sync = false);
3696
3697 env_managed(env_managed &&) = default;
3698 env_managed &operator=(env_managed &&other) noexcept;
3699 env_managed(const env_managed &) = delete;
3700 env_managed &operator=(const env_managed &) = delete;
3701 virtual ~env_managed();
3702};
3703
3712protected:
3713 friend class cursor;
3715 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3716
3717public:
3718 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3719 txn(const txn &) noexcept = default;
3720 txn &operator=(const txn &) noexcept = default;
3721 inline txn &operator=(txn &&) noexcept;
3722 inline txn(txn &&) noexcept;
3723 inline ~txn() noexcept;
3724
3725 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
3726 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const noexcept { return handle_; }
3727 MDBX_CXX14_CONSTEXPR operator MDBX_txn *() noexcept { return handle_; }
3728 MDBX_CXX14_CONSTEXPR const MDBX_txn *handle() const noexcept { return handle_; }
3730 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
3731 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
3732
3734 inline ::mdbx::env env() const noexcept;
3736 inline MDBX_txn_flags_t flags() const;
3738 inline uint64_t id() const;
3739
3741 inline void *get_context() const noexcept;
3742
3744 inline txn &set_context(void *your_context);
3745
3747 inline bool is_dirty(const void *ptr) const;
3748
3750 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3751
3753 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3754
3756 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3757
3760 inline info get_info(bool scan_reader_lock_table = false) const;
3761
3764 size_t size_max() const { return env().transaction_size_max(); }
3765
3767 size_t size_current() const {
3768 assert(is_readwrite());
3769 return size_t(get_info().txn_space_dirty);
3770 }
3771
3772 //----------------------------------------------------------------------------
3773
3775 inline void reset_reading();
3776
3778 inline void renew_reading();
3779
3781 inline txn_managed clone(void *context = nullptr) const;
3782
3784 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
3785
3787 inline void make_broken();
3788
3790 inline void park_reading(bool autounpark = true);
3791
3794 inline bool unpark_reading(bool restart_if_ousted = true);
3795
3798
3801
3803 inline cursor_managed open_cursor(map_handle map) const;
3804
3806 inline size_t release_all_cursors(bool unbind) const;
3807
3809 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3810
3812 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3813
3815 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3816 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3818 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3819 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3821 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3822 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3823
3825 inline map_handle open_map_accede(const char *name) const;
3827 inline map_handle open_map_accede(const ::std::string &name) const;
3829 inline map_handle open_map_accede(const slice &name) const;
3830
3832 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3833 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3835 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3836 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3838 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3839 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3840
3842 inline void drop_map(map_handle map);
3846 bool drop_map(const char *name, bool throw_if_absent = false);
3850 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3854 bool drop_map(const slice &name, bool throw_if_absent = false);
3855
3857 inline void clear_map(map_handle map);
3860 bool clear_map(const char *name, bool throw_if_absent = false);
3863 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3866 bool clear_map(const slice &name, bool throw_if_absent = false);
3867
3869 inline void rename_map(map_handle map, const char *new_name);
3871 inline void rename_map(map_handle map, const ::std::string &new_name);
3873 inline void rename_map(map_handle map, const slice &new_name);
3877 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3881 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3885 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3886
3887#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3888
3890 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3891 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3892 return open_map(slice(name), key_mode, value_mode);
3893 }
3894
3895 inline map_handle open_map_accede(const ::std::string_view &name) const;
3897 inline map_handle create_map(const ::std::string_view &name,
3898 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3899 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3900 return create_map(slice(name), key_mode, value_mode);
3901 }
3902
3905 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3906 return drop_map(slice(name), throw_if_absent);
3907 }
3908
3910 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3911 return clear_map(slice(name), throw_if_absent);
3912 }
3913
3914 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3918 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3919 bool throw_if_absent = false) {
3920 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3921 }
3922#endif /* __cpp_lib_string_view >= 201606L */
3923
3926 inline map_stat get_map_stat(map_handle map) const;
3929 inline uint32_t get_tree_deepmask(map_handle map) const;
3931 inline map_handle::info get_map_flags(map_handle map) const;
3932
3935 inline txn &put_canary(const canary &);
3937 inline canary get_canary() const;
3938
3940 inline uint64_t sequence(map_handle map) const;
3942 inline uint64_t sequence(map_handle map, uint64_t increment);
3943
3945 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3947 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3949 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3951 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3952
3954 inline slice get(map_handle map, const slice &key) const;
3956 inline slice get(map_handle map, slice key, size_t &values_count) const;
3958 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3960 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3964 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3968 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3969
3970 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3971 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3972 inline void insert(map_handle map, const slice &key, slice value);
3973 inline value_result try_insert(map_handle map, const slice &key, slice value);
3974 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3975 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3976
3977 inline void upsert(map_handle map, const slice &key, const slice &value);
3978 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3979
3980 inline void update(map_handle map, const slice &key, const slice &value);
3981 inline bool try_update(map_handle map, const slice &key, const slice &value);
3982 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3983 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3984
3985 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3986 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3987 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3988 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3989
3991 inline bool erase(map_handle map, const slice &key);
3992
3994 inline bool erase(map_handle map, const slice &key, const slice &value);
3995
3997 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3998
4000 template <class ALLOCATOR, typename CAPACITY_POLICY>
4002 extract(map_handle map, const slice &key,
4005
4007 template <class ALLOCATOR, typename CAPACITY_POLICY>
4009 replace(map_handle map, const slice &key, const slice &new_value,
4012
4013 template <class ALLOCATOR, typename CAPACITY_POLICY>
4015 replace_reserve(map_handle map, const slice &key, slice &new_value,
4018
4035 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4036 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4037 return append(map, kv.key, kv.value, multivalue_order_preserved);
4038 }
4039
4040 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4041 const void *values_array, size_t values_count, put_mode mode,
4042 bool allow_partial = false);
4043 template <typename VALUE>
4044 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4045 put_mode mode, bool allow_partial = false) {
4046 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4047 !::std::is_array<VALUE>::value,
4048 "Must be a standard layout type!");
4049 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4050 }
4051 template <typename VALUE>
4052 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4053 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4054 }
4055
4056 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4057 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4058 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4059 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4060};
4061
4070class LIBMDBX_API_TYPE txn_managed : public txn {
4071 using inherited = txn;
4072 friend class env;
4073 friend class txn;
4075 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4076
4077public:
4078 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4079 txn_managed(txn_managed &&) = default;
4080 txn_managed &operator=(txn_managed &&other) noexcept;
4081 txn_managed(const txn_managed &) = delete;
4082 txn_managed &operator=(const txn_managed &) = delete;
4083 ~txn_managed();
4084
4085 //----------------------------------------------------------------------------
4087
4089 void abort();
4093 void abort(finalization_latency &latency) { return abort(&latency); }
4097 finalization_latency result;
4098 abort(&result);
4099 return result;
4100 }
4101
4103 void commit();
4107 void commit(finalization_latency &latency) { return commit(&latency); }
4111 finalization_latency result;
4112 commit(&result);
4113 return result;
4114 }
4115
4121 bool checkpoint(finalization_latency &latency) { return checkpoint(&latency); }
4124 std::pair<bool, finalization_latency> checkpoint_get_latency() {
4125 finalization_latency latency;
4126 bool result = checkpoint(&latency);
4127 return std::make_pair(result, latency);
4128 }
4129
4139 finalization_latency result;
4140 commit_embark_read(&result);
4141 return result;
4142 }
4143
4146 bool amend(bool dont_wait = false);
4147};
4148
4156protected:
4158
4159public:
4161 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4162 cursor(const cursor &) noexcept = default;
4163 cursor &operator=(const cursor &) noexcept = default;
4164 inline cursor &operator=(cursor &&) noexcept;
4165 inline cursor(cursor &&) noexcept;
4166 inline ~cursor() noexcept;
4167 cursor_managed clone(void *your_context = nullptr) const;
4168 inline cursor &assign(const cursor &);
4169 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
4170 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const noexcept { return handle_; }
4171 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *() noexcept { return handle_; }
4172 MDBX_CXX14_CONSTEXPR const MDBX_cursor *handle() const noexcept { return handle_; }
4174 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept {
4175 return a.handle_ == b.handle_;
4176 }
4177 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept {
4178 return a.handle_ != b.handle_;
4179 }
4180
4181 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4182 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4183
4184 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4185 return compare_position(*this, other, ignore_nested) < 0;
4186 }
4187
4188 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4189 return compare_position(*this, other, ignore_nested) <= 0;
4190 }
4191
4192 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4193 return compare_position(*this, other, ignore_nested) == 0;
4194 }
4195
4196 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4197 return compare_position(*this, other, ignore_nested) > 0;
4198 }
4199
4200 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4201 return compare_position(*this, other, ignore_nested) >= 0;
4202 }
4203
4205 inline void *get_context() const noexcept;
4206
4208 inline cursor &set_context(void *your_context);
4209
4216
4223
4226
4230
4231 /* Doubtless cursor positioning at a specified key. */
4237
4238 /* Doubtless cursor positioning at a specified key-value pair
4239 * for dupsort/multi-value hives. */
4245
4252
4257 };
4258
4259 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4260 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4261 // и других параметров в bool-throw_notfound.
4262
4263 struct move_result : public pair_result {
4264 inline move_result(const cursor &cursor, bool throw_notfound);
4265 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4266 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4267 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4268 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4269 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4270 bool throw_notfound);
4271 move_result(const move_result &) noexcept = default;
4272 move_result &operator=(const move_result &) noexcept = default;
4273 };
4274
4275 struct estimate_result : public pair {
4280 : estimate_result(cursor, operation, key, slice::invalid()) {}
4281 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4282 estimate_result(const estimate_result &) noexcept = default;
4283 estimate_result &operator=(const estimate_result &) noexcept = default;
4284 };
4285
4286protected:
4287 /* fake `const`, but for specific move/get operations */
4288 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4289
4290 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4291
4292public:
4293 template <typename CALLABLE_PREDICATE>
4294 bool scan_until(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4295 struct wrapper : public exception_thunk {
4296 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4297 auto thunk = static_cast<wrapper *>(context);
4298 assert(thunk->is_clean());
4299 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4300 try {
4301 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4302 } catch (... /* capture any exception to rethrow it over C code */) {
4303 thunk->capture();
4304 return MDBX_RESULT_TRUE;
4305 }
4306 }
4307 } thunk;
4309 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4310 thunk);
4311 }
4312
4313 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4314 return scan_until(std::move(predicate), backward ? last : first, backward ? previous : next);
4315 }
4316
4317 template <typename CALLABLE_PREDICATE>
4318 bool scan_until_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4319 move_operation turn = next) {
4320 struct wrapper : public exception_thunk {
4321 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4322 auto thunk = static_cast<wrapper *>(context);
4323 assert(thunk->is_clean());
4324 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4325 try {
4326 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4327 } catch (... /* capture any exception to rethrow it over C code */) {
4328 thunk->capture();
4329 return MDBX_RESULT_TRUE;
4330 }
4331 }
4332 } thunk;
4333 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4334 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4335 thunk);
4336 }
4337
4338 template <typename CALLABLE_PREDICATE>
4339 bool scan_until_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4340 move_operation turn = next) {
4341 struct wrapper : public exception_thunk {
4342 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4343 auto thunk = static_cast<wrapper *>(context);
4344 assert(thunk->is_clean());
4345 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4346 try {
4347 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4348 } catch (... /* capture any exception to rethrow it over C code */) {
4349 thunk->capture();
4350 return MDBX_RESULT_TRUE;
4351 }
4352 }
4353 } thunk;
4354 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4355 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4356 thunk);
4357 }
4358
4359 move_result move(move_operation operation, bool throw_notfound) {
4360 return move_result(*this, operation, throw_notfound);
4361 }
4362 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4363 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4364 }
4365 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4366 return move_result(*this, operation, key, value, throw_notfound);
4367 }
4368 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4369 return move(operation, &key, &value, throw_notfound);
4370 }
4371
4372 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4373 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4374 move_result to_previous_last_multi(bool throw_notfound = true) {
4375 return move(multi_prevkey_lastvalue, throw_notfound);
4376 }
4377 move_result to_current_first_multi(bool throw_notfound = true) {
4378 return move(multi_currentkey_firstvalue, throw_notfound);
4379 }
4380 move_result to_current_prev_multi(bool throw_notfound = true) {
4381 return move(multi_currentkey_prevvalue, throw_notfound);
4382 }
4383 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4384 move_result to_current_next_multi(bool throw_notfound = true) {
4385 return move(multi_currentkey_nextvalue, throw_notfound);
4386 }
4387 move_result to_current_last_multi(bool throw_notfound = true) {
4388 return move(multi_currentkey_lastvalue, throw_notfound);
4389 }
4390 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4391 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4392 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4393
4394 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4395 return move(key_lesser_than, key, throw_notfound);
4396 }
4397 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4398 return move(key_lesser_or_equal, key, throw_notfound);
4399 }
4400 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4401 return move(key_equal, key, throw_notfound);
4402 }
4403 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4404 return move(key_exact, key, throw_notfound);
4405 }
4406 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4407 return move(key_greater_or_equal, key, throw_notfound);
4408 }
4409 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4410 return move(key_greater_than, key, throw_notfound);
4411 }
4412
4413 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4414 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4415 }
4416 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4417 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4418 }
4419 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4420 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4421 }
4422 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4423 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4424 }
4425 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4426 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4427 }
4428
4429 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4430 return move(pair_lesser_than, key, value, throw_notfound);
4431 }
4432 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4433 return move(pair_lesser_or_equal, key, value, throw_notfound);
4434 }
4435 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4436 return move(pair_equal, key, value, throw_notfound);
4437 }
4438 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4439 return move(pair_exact, key, value, throw_notfound);
4440 }
4441 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4442 return move(pair_greater_or_equal, key, value, throw_notfound);
4443 }
4444 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4445 return move(pair_greater_than, key, value, throw_notfound);
4446 }
4447
4448 inline bool seek(const slice &key);
4449 inline move_result find(const slice &key, bool throw_notfound = true);
4450 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4451 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4452
4454 inline size_t count_multivalue() const;
4455
4456 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4457 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4458 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4459
4460 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4461 return move(seek_and_batch_samelength, key, throw_notfound);
4462 }
4463
4464 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4465 return move(batch_samelength, throw_notfound);
4466 }
4467
4468 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4469 return move(batch_samelength_next, throw_notfound);
4470 }
4471
4472 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4473 return move(batch_samelength_previous, throw_notfound);
4474 }
4475
4476 inline bool eof() const;
4477 inline bool on_first() const;
4478 inline bool on_last() const;
4479 inline bool on_first_multival() const;
4480 inline bool on_last_multival() const;
4481 inline estimate_result estimate(const slice &key, const slice &value) const;
4482 inline estimate_result estimate(const slice &key) const;
4483 inline estimate_result estimate(move_operation operation) const;
4484 inline estimate_result estimate(move_operation operation, const slice &key) const;
4485
4486 static inline ptrdiff_t distance_between(const cursor from, const cursor to,
4487 unsigned deepness = /* enough to cover whole tree height */ 42);
4488 inline ptrdiff_t distance_from(const cursor from,
4489 unsigned deepness = /* enough to cover whole tree height */ 42) const {
4490 return distance_between(from, *this, deepness);
4491 }
4492 inline ptrdiff_t distance_to(const cursor to, unsigned deepness = /* enough to cover whole tree height */ 42) const {
4493 return distance_between(*this, to, deepness);
4494 }
4495 inline ptrdiff_t distance_from_first(unsigned deepness = /* enough to cover whole tree height */ 42) const {
4496 return distance_between(nullptr, *this, deepness);
4497 }
4498 inline ptrdiff_t distance_to_end(unsigned deepness = /* enough to cover whole tree height */ 42) const {
4499 return distance_between(*this, nullptr, deepness);
4500 }
4501
4502 inline bool scroll(intptr_t distable, unsigned deepness = /* enough to cover whole tree height */ 42,
4503 bool throw_notfound = true);
4504
4505 static inline bool distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size,
4506 unsigned deepness = /* enough to cover whole tree height */ 42);
4507
4508 static inline bool distribute(const cursor from, const cursor to, const std::vector<cursor> &cursors,
4509 unsigned deepness = /* enough to cover whole tree height */ 42);
4510
4511 static inline bool distribute(const cursor from, const cursor to, const std::vector<cursor_managed> &cursors,
4512 unsigned deepness = /* enough to cover whole tree height */ 42);
4513
4514 //----------------------------------------------------------------------------
4515
4517 inline void renew(::mdbx::txn &txn);
4518
4520 inline void bind(::mdbx::txn &txn, ::mdbx::map_handle map_handle);
4521
4523 inline void unbind();
4524
4526 inline ::mdbx::txn txn() const;
4527 inline map_handle map() const;
4528
4529 inline operator ::mdbx::txn() const { return txn(); }
4530 inline operator ::mdbx::map_handle() const { return map(); }
4531
4532 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4533 inline void put(const slice &key, slice value, put_mode mode);
4534 inline void insert(const slice &key, slice value);
4535 inline value_result try_insert(const slice &key, slice value);
4536 inline slice insert_reserve(const slice &key, size_t value_length);
4537 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4538
4539 inline void upsert(const slice &key, const slice &value);
4540 inline slice upsert_reserve(const slice &key, size_t value_length);
4541
4543 void update_current(const slice &value);
4545 slice reverse_current(size_t value_length);
4546
4547 inline void update(const slice &key, const slice &value);
4548 inline bool try_update(const slice &key, const slice &value);
4549 inline slice update_reserve(const slice &key, size_t value_length);
4550 inline value_result try_update_reserve(const slice &key, size_t value_length);
4551
4552 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4553 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4554 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4555 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4556
4558 inline bool erase(bool whole_multivalue = false);
4559
4562 inline bool erase(const slice &key, bool whole_multivalue = true);
4563
4566 inline bool erase(const slice &key, const slice &value);
4567
4568 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4569 size_t values_count, put_mode mode, bool allow_partial = false);
4570 template <typename VALUE>
4571 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4572 bool allow_partial = false) {
4573 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4574 !::std::is_array<VALUE>::value,
4575 "Must be a standard layout type!");
4576 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4577 }
4578 template <typename VALUE>
4579 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4580 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4581 }
4582};
4583
4591class LIBMDBX_API_TYPE cursor_managed : public cursor {
4592 using inherited = cursor;
4593 friend class txn;
4595 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4596
4597public:
4599 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4600 if (MDBX_UNLIKELY(!handle_))
4601 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4602 }
4603
4605 void close();
4606
4607 cursor_managed(cursor_managed &&) = default;
4608 cursor_managed &operator=(cursor_managed &&other) noexcept;
4609
4610 inline MDBX_cursor *withdraw_handle() noexcept {
4612 handle_ = nullptr;
4613 return handle;
4614 }
4615
4616 cursor_managed(const cursor_managed &) = delete;
4617 cursor_managed &operator=(const cursor_managed &) = delete;
4619};
4620
4621//==============================================================================
4622//
4623// Inline body of the libmdbx C++ API
4624//
4625
4626MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4627MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4628
4629static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4630#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4631 if (::std::is_constant_evaluated()) {
4632 size_t i = 0;
4633 if (c_str)
4634 while (c_str[i])
4635 ++i;
4636 return i;
4637 }
4638#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4639#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4640 return c_str ? ::std::string_view(c_str).length() : 0;
4641#else
4642 return c_str ? ::std::strlen(c_str) : 0;
4643#endif
4644}
4645
4646MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4647#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4648 if (::std::is_constant_evaluated()) {
4649 for (size_t i = 0; i < bytes; ++i)
4650 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4651 return dest;
4652 } else
4653#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4654 return ::std::memcpy(dest, src, bytes);
4655}
4656
4657static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4658#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4659 if (::std::is_constant_evaluated()) {
4660 for (size_t i = 0; i < bytes; ++i) {
4661 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4662 if (diff)
4663 return diff;
4664 }
4665 return 0;
4666 } else
4667#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4668 return ::std::memcmp(a, b, bytes);
4669}
4670
4671//------------------------------------------------------------------------------
4672
4675
4679
4683
4684inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4685
4686inline void exception_thunk::capture() noexcept {
4687 assert(is_clean());
4688 captured_ = ::std::current_exception();
4689}
4690
4692 if (captured_)
4693 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4694}
4695
4696//------------------------------------------------------------------------------
4697
4698MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4699
4700inline error &error::operator=(MDBX_error_t error_code) noexcept {
4701 code_ = error_code;
4702 return *this;
4703}
4704
4705MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4706
4707MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4708
4709MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4710
4711MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4712
4713MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4714
4716 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4717}
4718
4719MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4720
4725
4726inline void error::throw_exception(int error_code) {
4727 const error trouble(static_cast<MDBX_error_t>(error_code));
4728 trouble.throw_exception();
4729}
4730
4731inline void error::throw_on_failure() const {
4733 MDBX_CXX20_UNLIKELY throw_exception();
4734}
4735
4736inline void error::success_or_throw() const {
4737 if (MDBX_UNLIKELY(!is_success()))
4738 MDBX_CXX20_UNLIKELY throw_exception();
4739}
4740
4741inline void error::success_or_throw(const exception_thunk &thunk) const {
4742 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4743 if (MDBX_UNLIKELY(!is_success())) {
4744 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4745 else throw_exception();
4746 }
4747}
4748
4749inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4750 if (MDBX_UNLIKELY(ptr == nullptr))
4751 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4752}
4753
4754inline void error::throw_on_failure(int error_code) {
4755 error rc(static_cast<MDBX_error_t>(error_code));
4756 rc.throw_on_failure();
4757}
4758
4759inline void error::success_or_throw(MDBX_error_t error_code) {
4760 error rc(error_code);
4761 rc.success_or_throw();
4762}
4763
4764inline bool error::boolean_or_throw(int error_code) {
4765 switch (error_code) {
4766 case MDBX_RESULT_FALSE:
4767 return false;
4768 case MDBX_RESULT_TRUE:
4769 return true;
4770 default:
4771 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4772 }
4773}
4774
4775inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4776 error rc(static_cast<MDBX_error_t>(error_code));
4777 rc.success_or_throw(thunk);
4778}
4779
4780inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4781 if (MDBX_UNLIKELY(!thunk.is_clean()))
4782 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4783 return boolean_or_throw(error_code);
4784}
4785
4786MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4787
4789 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4790
4791MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4792 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4793
4794MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4795
4796MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4797
4798MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4799
4800MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4801
4802inline slice &slice::assign(const void *ptr, size_t bytes) {
4803 iov_base = const_cast<void *>(ptr);
4804 iov_len = check_length(bytes);
4805 return *this;
4806}
4807
4808inline slice &slice::assign(const slice &src) noexcept {
4809 iov_base = src.iov_base;
4810 iov_len = src.iov_len;
4811 return *this;
4812}
4813
4814inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4815
4816slice &slice::assign(slice &&src) noexcept {
4817 assign(src);
4818 src.invalidate();
4819 return *this;
4820}
4821
4823 assign(src.iov_base, src.iov_len);
4824 src.iov_base = nullptr;
4825 return *this;
4826}
4827
4828inline slice &slice::assign(const void *begin, const void *end) {
4829 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4830}
4831
4832inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4833
4834inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4835
4836inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4837
4838MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4839
4840MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4841
4842MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4843
4845
4846MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4847
4848MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4849
4850MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4851
4853
4854MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4855
4856MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4857
4858MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4859
4860MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4861
4862MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4863
4865 iov_len = check_length(bytes);
4866 return *this;
4867}
4868
4870 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4871 return set_length(static_cast<const char *>(ptr) - char_ptr());
4872}
4873
4874MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4875
4876MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4877
4878MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4879
4880MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4881
4882MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4883
4885 iov_base = nullptr;
4886 iov_len = 0;
4887}
4888
4889inline void slice::remove_prefix(size_t n) noexcept {
4890 assert(n <= size());
4891 iov_base = static_cast<byte *>(iov_base) + n;
4892 iov_len -= n;
4893}
4894
4895inline void slice::safe_remove_prefix(size_t n) {
4896 if (MDBX_UNLIKELY(n > size()))
4897 MDBX_CXX20_UNLIKELY throw_out_range();
4898 remove_prefix(n);
4899}
4900
4901inline void slice::remove_suffix(size_t n) noexcept {
4902 assert(n <= size());
4903 iov_len -= n;
4904}
4905
4906inline void slice::safe_remove_suffix(size_t n) {
4907 if (MDBX_UNLIKELY(n > size()))
4908 MDBX_CXX20_UNLIKELY throw_out_range();
4909 remove_suffix(n);
4910}
4911
4912MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4913 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4914}
4915
4916MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4917 return length() >= suffix.length() &&
4918 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4919}
4920
4922 size_t h = length() * 3977471;
4923 for (size_t i = 0; i < length(); ++i)
4924 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4925 return h ^ 3863194411 * (h >> 11);
4926}
4927
4928MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4930 return byte_ptr()[n];
4931}
4932
4933MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4934 if (MDBX_UNLIKELY(n >= size()))
4935 MDBX_CXX20_UNLIKELY throw_out_range();
4936 return byte_ptr()[n];
4937}
4938
4939MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4941 return slice(data(), n);
4942}
4943
4944MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4946 return slice(char_ptr() + size() - n, n);
4947}
4948
4949MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4950 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4951 return slice(char_ptr() + from, n);
4952}
4953
4955 if (MDBX_UNLIKELY(n > size()))
4956 MDBX_CXX20_UNLIKELY throw_out_range();
4957 return head(n);
4958}
4959
4961 if (MDBX_UNLIKELY(n > size()))
4962 MDBX_CXX20_UNLIKELY throw_out_range();
4963 return tail(n);
4964}
4965
4966MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4967 if (MDBX_UNLIKELY(n > max_length))
4968 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4969 if (MDBX_UNLIKELY(from > max_length || from + n > size()))
4970 MDBX_CXX20_UNLIKELY throw_out_range();
4971 return middle(from, n);
4972}
4973
4974MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4975 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4976 return diff ? diff
4977 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4978 : memcmp(a.data(), b.data(), a.length());
4979}
4980
4982 const size_t shortest = ::std::min(a.length(), b.length());
4983 if (MDBX_LIKELY(shortest > 0))
4985 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4986 if (MDBX_LIKELY(diff != 0))
4987 MDBX_CXX20_LIKELY return diff;
4988 }
4989 return intptr_t(a.length()) - intptr_t(b.length());
4990}
4991
4993 return slice::compare_fast(a, b) == 0;
4994}
4995
4997 return slice::compare_lexicographically(a, b) < 0;
4998}
4999
5001 return slice::compare_lexicographically(a, b) > 0;
5002}
5003
5005 return slice::compare_lexicographically(a, b) <= 0;
5006}
5007
5009 return slice::compare_lexicographically(a, b) >= 0;
5010}
5011
5013 return slice::compare_fast(a, b) != 0;
5014}
5015
5016#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5017MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
5018 const auto cmp = slice::compare_lexicographically(a, b);
5019 return (cmp < 0) ? std::strong_ordering::less
5020 : (cmp > 0) ? std::strong_ordering::greater
5021 : std::strong_ordering::equal;
5022}
5023#endif /* __cpp_impl_three_way_comparison */
5024
5025template <class ALLOCATOR, typename CAPACITY_POLICY>
5027 const allocator_type &alloc)
5028 : inherited(src), silo_(alloc) {
5029 if (!make_reference)
5030 insulate();
5031}
5032
5033template <class ALLOCATOR, typename CAPACITY_POLICY>
5034inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
5035 const allocator_type &alloc)
5036 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
5037
5038template <class ALLOCATOR, typename CAPACITY_POLICY>
5039inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
5040 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
5041}
5042
5043#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
5045
5046#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
5048#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
5049#endif /* !MinGW || MDBX_EXPORTS */
5050
5053
5054//------------------------------------------------------------------------------
5055
5056template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5057inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
5058 if (MDBX_LIKELY(!producer.is_empty()))
5060 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5061 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5062 return result;
5063 }
5065}
5066
5067template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5068inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
5069 if (MDBX_LIKELY(!producer.is_empty()))
5071 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5072 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5073 return result;
5074 }
5076}
5077
5078template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5079inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
5080 string<ALLOCATOR> result(alloc);
5081 if (MDBX_LIKELY(!producer.is_empty()))
5083 result.resize(producer.envisage_result_length());
5084 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5085 }
5086 return result;
5087}
5088
5089template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5090inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
5091 string<ALLOCATOR> result(alloc);
5092 if (MDBX_LIKELY(!producer.is_empty()))
5094 result.resize(producer.envisage_result_length());
5095 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5096 }
5097 return result;
5098}
5099
5100template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
5101 return make_string<ALLOCATOR>(*this, alloc);
5102}
5103
5104template <class ALLOCATOR, typename CAPACITY_POLICY>
5106 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5107}
5108
5109template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
5110 return make_string<ALLOCATOR>(*this, alloc);
5111}
5112
5113template <class ALLOCATOR, typename CAPACITY_POLICY>
5115 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5116}
5117
5118template <class ALLOCATOR> string<ALLOCATOR> to_base64::as_string(const ALLOCATOR &alloc) const {
5119 return make_string<ALLOCATOR>(*this, alloc);
5120}
5121
5122template <class ALLOCATOR, typename CAPACITY_POLICY>
5124 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5125}
5126
5127template <class ALLOCATOR> string<ALLOCATOR> from_hex::as_string(const ALLOCATOR &alloc) const {
5128 return make_string<ALLOCATOR>(*this, alloc);
5129}
5130
5131template <class ALLOCATOR, typename CAPACITY_POLICY>
5133 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5134}
5135
5136template <class ALLOCATOR> string<ALLOCATOR> from_base58::as_string(const ALLOCATOR &alloc) const {
5137 return make_string<ALLOCATOR>(*this, alloc);
5138}
5139
5140template <class ALLOCATOR, typename CAPACITY_POLICY>
5142 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5143}
5144
5145template <class ALLOCATOR> string<ALLOCATOR> from_base64::as_string(const ALLOCATOR &alloc) const {
5146 return make_string<ALLOCATOR>(*this, alloc);
5147}
5148
5149template <class ALLOCATOR, typename CAPACITY_POLICY>
5151 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5152}
5153
5154template <class ALLOCATOR>
5155inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
5156 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
5157}
5158
5159template <class ALLOCATOR>
5160inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5161 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5162}
5163
5164template <class ALLOCATOR>
5165inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5166 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5167}
5168
5169template <class ALLOCATOR, class CAPACITY_POLICY>
5170inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5171 const ALLOCATOR &alloc) const {
5172 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5173}
5174
5175template <class ALLOCATOR, class CAPACITY_POLICY>
5176inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
5177 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5178}
5179
5180template <class ALLOCATOR, class CAPACITY_POLICY>
5181inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
5182 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5183}
5184
5185template <class ALLOCATOR, class CAPACITY_POLICY>
5186inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5187 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5188}
5189
5190template <class ALLOCATOR, class CAPACITY_POLICY>
5191inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5192 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5193}
5194
5195template <class ALLOCATOR, class CAPACITY_POLICY>
5196inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5197 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5198}
5199
5200//------------------------------------------------------------------------------
5201
5202MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5203 const auto diff = slice::compare_fast(a.key, b.key);
5204 return diff ? diff : slice::compare_fast(a.value, b.value);
5205}
5206
5207MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5208 const auto diff = slice::compare_lexicographically(a.key, b.key);
5209 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5210}
5211
5213 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5214 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5215 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5216}
5217
5219 return pair::compare_lexicographically(a, b) < 0;
5220}
5221
5223 return pair::compare_lexicographically(a, b) > 0;
5224}
5225
5227 return pair::compare_lexicographically(a, b) <= 0;
5228}
5229
5231 return pair::compare_lexicographically(a, b) >= 0;
5232}
5233
5235 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5236 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5237 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5238}
5239
5240#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5241MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5243}
5244#endif /* __cpp_impl_three_way_comparison */
5245
5247template <typename BUFFER>
5249
5252
5253//------------------------------------------------------------------------------
5254
5255inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
5256inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
5257inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
5258
5259MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5260 return !from_hex(*this, ignore_spaces).is_erroneous();
5261}
5262
5263MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5264 return !from_base58(*this, ignore_spaces).is_erroneous();
5265}
5266
5267MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5268 return !from_base64(*this, ignore_spaces).is_erroneous();
5269}
5270
5271//------------------------------------------------------------------------------
5272
5274
5275inline env &env::operator=(env &&other) noexcept {
5276 if (this != &other) {
5277 handle_ = other.handle_;
5278 other.handle_ = nullptr;
5279 }
5280 return *this;
5281}
5282
5283inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5284
5285inline env::~env() noexcept {
5286#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
5287 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5288#endif
5289}
5290
5294 return *this;
5295}
5296
5297inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5298 size_now = size_lower = lower;
5299 size_upper = upper;
5301 return *this;
5302}
5303
5307
5311
5312inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5313
5314inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5315
5316inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5317 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5318 if (result < 0)
5319 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5320 return static_cast<size_t>(result);
5321}
5322
5323inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5324 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5325 if (result < 0)
5326 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5327 return static_cast<size_t>(result);
5328}
5329
5330inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5331
5332inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5333
5334inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5335 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5336 if (result < 0)
5337 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5338 return static_cast<size_t>(result);
5339}
5340
5341inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5342 return key_max(pagesize, MDBX_db_flags_t(mode));
5343}
5344
5345inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
5346 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5347 if (result < 0)
5348 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5349 return static_cast<size_t>(result);
5350}
5351
5353
5354inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5355
5357
5358inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5359 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5360 if (result < 0)
5361 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5362 return static_cast<size_t>(result);
5363}
5364
5365inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5366 return value_max(pagesize, MDBX_db_flags_t(mode));
5367}
5368
5369inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
5370 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5371 if (result < 0)
5372 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5373 return static_cast<size_t>(result);
5374}
5375
5377
5378inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5379 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5380 if (result < 0)
5381 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5382 return static_cast<size_t>(result);
5383}
5384
5385inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5386 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5387}
5388
5390 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5391 if (result < 0)
5392 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5393 return static_cast<size_t>(result);
5394}
5395
5399
5400inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5401 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5402 if (result < 0)
5403 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5404 return static_cast<size_t>(result);
5405}
5406
5407inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5408 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5409}
5410
5412 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5413 if (result < 0)
5414 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5415 return static_cast<size_t>(result);
5416}
5417
5421
5422inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5423 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5424 if (result < 0)
5425 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5426 return static_cast<size_t>(result);
5427}
5428
5429inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5430
5438
5440
5444
5448
5452
5453inline env::stat env::get_stat() const {
5454 env::stat r;
5455 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5456 return r;
5457}
5458
5459inline env::stat env::get_stat(const txn &txn) const {
5460 env::stat r;
5462 return r;
5463}
5464
5465inline env::info env::get_info() const {
5466 env::info r;
5467 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5468 return r;
5469}
5470
5471inline env::info env::get_info(const txn &txn) const {
5472 env::info r;
5474 return r;
5475}
5476
5478 filehandle fd;
5480 return fd;
5481}
5482
5484 unsigned bits = 0;
5486 return MDBX_env_flags_t(bits);
5487}
5488
5489inline unsigned env::max_readers() const {
5490 unsigned r;
5492 return r;
5493}
5494
5495inline unsigned env::max_maps() const {
5496 unsigned r;
5498 return r;
5499}
5500
5501inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5502
5503inline env &env::set_context(void *ptr) {
5505 return *this;
5506}
5507
5508inline env &env::set_sync_threshold(size_t bytes) {
5510 return *this;
5511}
5512
5513inline size_t env::sync_threshold() const {
5514 size_t bytes;
5516 return bytes;
5517}
5518
5519inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5521 return *this;
5522}
5523
5524inline unsigned env::sync_period__seconds_16dot16() const {
5525 unsigned seconds_16dot16;
5527 return seconds_16dot16;
5528}
5529
5531 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5532}
5533
5534inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5535
5536#if __cplusplus >= 201103L
5537inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5538
5540#endif
5541
5542inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5544 return *this;
5545}
5546
5547inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5548 uint64_t value;
5550 return value;
5551}
5552
5553inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
5555 return *this;
5556}
5557
5558inline env &env::set_geometry(const geometry &geo) {
5560 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5561 return *this;
5562}
5563
5564inline bool env::sync_to_disk(bool force, bool nonblock) {
5565 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5566 switch (err) {
5567 case MDBX_SUCCESS /* flush done */:
5568 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5569 return true;
5570 case MDBX_BUSY /* the environment is used by other thread */:
5571 return false;
5572 default:
5573 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5574 }
5575}
5576
5578
5580env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5581 size_t retained) noexcept
5583 bytes_retained(retained) {}
5584
5585template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5586 struct reader_visitor_thunk : public exception_thunk {
5587 VISITOR &visitor_;
5588 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5589 size_t used, size_t retained) noexcept {
5590 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5591 assert(thunk->is_clean());
5592 try {
5593 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5594 return loop_control(thunk->visitor_(info, number));
5595 } catch (... /* capture any exception to rethrow it over C code */) {
5596 thunk->capture();
5598 }
5599 }
5600 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5601 };
5602 reader_visitor_thunk thunk(visitor);
5603 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5604 thunk.rethrow_captured();
5605 return rc;
5606}
5607
5608inline unsigned env::check_readers() {
5609 int dead_count;
5610 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5611 MDBX_INLINE_API_ASSERT(dead_count >= 0);
5612 return static_cast<unsigned>(dead_count);
5613}
5614
5619
5620inline MDBX_hsr_func env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5621
5623 ::MDBX_txn *ptr;
5625 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5626 return txn_managed(ptr);
5627}
5628
5630 ::MDBX_txn *ptr;
5632 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5633 return txn_managed(ptr);
5634}
5635
5636inline txn_managed env::start_write(bool dont_wait) {
5637 ::MDBX_txn *ptr;
5640 MDBX_INLINE_API_ASSERT(ptr != nullptr || dont_wait);
5641 return txn_managed(ptr);
5642}
5643
5645 ::MDBX_txn *ptr;
5647 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5648 return txn_managed(ptr);
5649}
5650
5652
5654
5655inline txn &txn::operator=(txn &&other) noexcept {
5656 if (this != &other) {
5657 handle_ = other.handle_;
5658 other.handle_ = nullptr;
5659 }
5660 return *this;
5661}
5662
5663inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5664
5665inline txn::~txn() noexcept {
5666#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
5667 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5668#endif
5669}
5670
5671inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5672
5673inline txn &txn::set_context(void *ptr) {
5675 return *this;
5676}
5677
5678inline bool txn::is_dirty(const void *ptr) const {
5679 int err = ::mdbx_is_dirty(handle_, ptr);
5680 switch (err) {
5681 default:
5682 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5683 case MDBX_RESULT_TRUE:
5684 return true;
5685 case MDBX_RESULT_FALSE:
5686 return false;
5687 }
5688}
5689
5690inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5691
5693 const int bits = mdbx_txn_flags(handle_);
5695 return static_cast<MDBX_txn_flags_t>(bits);
5696}
5697
5698inline uint64_t txn::id() const {
5699 const uint64_t txnid = mdbx_txn_id(handle_);
5701 return txnid;
5702}
5703
5705
5707
5709
5710inline txn_managed txn::clone(void *context) const {
5711 MDBX_txn *ptr = nullptr;
5713 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5714 return txn_managed(ptr);
5715}
5716
5717inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
5718 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
5719 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
5720 MDBX_INLINE_API_ASSERT(txn_for_renew_into_clone.handle_ != nullptr);
5721}
5722
5723inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5724
5725inline bool txn::unpark_reading(bool restart_if_ousted) {
5726 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5727}
5728
5729inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5730 txn::info r;
5731 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5732 return r;
5733}
5734
5736 MDBX_cursor *ptr;
5738 return cursor_managed(ptr);
5739}
5740
5741inline size_t txn::release_all_cursors(bool unbind) const {
5742 size_t count;
5744 return count;
5745}
5746
5747inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5748 const ::mdbx::value_mode value_mode) const {
5749 map_handle map;
5752 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5753 return map;
5754}
5755
5756inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5757 const ::mdbx::value_mode value_mode) const {
5758 map_handle map;
5761 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5762 return map;
5763}
5764
5765inline map_handle txn::open_map_accede(const slice &name) const {
5766 map_handle map;
5768 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5769 return map;
5770}
5771
5772inline map_handle txn::open_map_accede(const char *name) const {
5773 map_handle map;
5775 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5776 return map;
5777}
5778
5779inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5780 const ::mdbx::value_mode value_mode) {
5781 map_handle map;
5784 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5785 return map;
5786}
5787
5788inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5789 const ::mdbx::value_mode value_mode) {
5790 map_handle map;
5793 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5794 return map;
5795}
5796
5798
5800
5801inline void txn::rename_map(map_handle map, const char *new_name) {
5803}
5804
5805inline void txn::rename_map(map_handle map, const slice &new_name) {
5807}
5808
5809inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5810 const ::mdbx::value_mode value_mode) const {
5811 return open_map(slice(name), key_mode, value_mode);
5812}
5813
5814inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5815
5816inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5817 const ::mdbx::value_mode value_mode) {
5818 return create_map(slice(name), key_mode, value_mode);
5819}
5820
5821inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5822 return drop_map(slice(name), throw_if_absent);
5823}
5824
5825inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5826 return clear_map(slice(name), throw_if_absent);
5827}
5828
5829inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5830
5832 txn::map_stat r;
5833 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5834 return r;
5835}
5836
5837inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5838 uint32_t r;
5840 return r;
5841}
5842
5848
5853
5855 txn::canary r;
5857 return r;
5858}
5859
5860inline uint64_t txn::sequence(map_handle map) const {
5861 uint64_t result;
5863 return result;
5864}
5865
5866inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5867 uint64_t result;
5868 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5869 return result;
5870}
5871
5872inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5873 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5874}
5875
5876inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5877 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5878}
5879
5880inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5881 return compare_keys(map, a.key, b.key);
5882}
5883
5884inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5885 return compare_values(map, a.value, b.value);
5886}
5887
5888inline slice txn::get(map_handle map, const slice &key) const {
5889 slice result;
5890 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5891 return result;
5892}
5893
5894inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5895 slice result;
5896 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5897 return result;
5898}
5899
5900inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5901 slice result;
5902 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5903 switch (err) {
5904 case MDBX_SUCCESS:
5905 return result;
5906 case MDBX_NOTFOUND:
5907 return value_at_absence;
5908 default:
5909 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5910 }
5911}
5912
5913inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5914 slice result;
5915 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5916 switch (err) {
5917 case MDBX_SUCCESS:
5918 return result;
5919 case MDBX_NOTFOUND:
5920 return value_at_absence;
5921 default:
5922 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5923 }
5924}
5925
5927 pair result(key, slice());
5928 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5929 return pair_result(result.key, result.value, exact);
5930}
5931
5932inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5933 pair result{key, slice()};
5934 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5935 switch (err) {
5936 case MDBX_SUCCESS:
5937 return pair_result{result.key, result.value, true};
5938 case MDBX_RESULT_TRUE:
5939 return pair_result{result.key, result.value, false};
5940 case MDBX_NOTFOUND:
5941 return pair_result{key, value_at_absence, false};
5942 default:
5943 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5944 }
5945}
5946
5947inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5948 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5949 /* coverity[OVERRUN] */
5950 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5951}
5952
5953inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5954 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5955 /* coverity[OVERRUN] */
5956 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5957}
5958
5959inline void txn::insert(map_handle map, const slice &key, slice value) {
5960 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5961 /* coverity[OVERRUN] */
5962 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5964}
5965
5966inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5967 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5968 /* coverity[OVERRUN] */
5969 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5971 switch (err) {
5972 case MDBX_SUCCESS:
5973 return value_result{slice(), true};
5974 case MDBX_KEYEXIST:
5975 return value_result{value, false};
5976 default:
5977 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5978 }
5979}
5980
5981inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5982 slice result(nullptr, value_length);
5983 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5984 /* coverity[OVERRUN] */
5985 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5987 return result;
5988}
5989
5990inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5991 slice result(nullptr, value_length);
5992 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5993 /* coverity[OVERRUN] */
5994 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5996 switch (err) {
5997 case MDBX_SUCCESS:
5998 return value_result{result, true};
5999 case MDBX_KEYEXIST:
6000 return value_result{result, false};
6001 default:
6002 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6003 }
6004}
6005
6006inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
6007 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6008 /* coverity[OVERRUN] */
6009 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6010}
6011
6012inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
6013 slice result(nullptr, value_length);
6014 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6015 /* coverity[OVERRUN] */
6017 return result;
6018}
6019
6020inline void txn::update(map_handle map, const slice &key, const slice &value) {
6021 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6022 /* coverity[OVERRUN] */
6023 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6024}
6025
6026inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
6027 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6028 /* coverity[OVERRUN] */
6029 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6030 switch (err) {
6031 case MDBX_SUCCESS:
6032 return true;
6033 case MDBX_NOTFOUND:
6034 return false;
6035 default:
6036 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6037 }
6038}
6039
6040inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
6041 slice result(nullptr, value_length);
6042 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6043 /* coverity[OVERRUN] */
6045 return result;
6046}
6047
6048inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
6049 slice result(nullptr, value_length);
6050 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6051 /* coverity[OVERRUN] */
6052 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6053 switch (err) {
6054 case MDBX_SUCCESS:
6055 return value_result{result, true};
6056 case MDBX_NOTFOUND:
6057 return value_result{slice(), false};
6058 default:
6059 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6060 }
6061}
6062
6063inline bool txn::erase(map_handle map, const slice &key) {
6064 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6065 switch (err) {
6066 case MDBX_SUCCESS:
6067 return true;
6068 case MDBX_NOTFOUND:
6069 return false;
6070 default:
6071 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6072 }
6073}
6074
6075inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6076 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
6077 switch (err) {
6078 case MDBX_SUCCESS:
6079 return true;
6080 case MDBX_NOTFOUND:
6081 return false;
6082 default:
6083 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6084 }
6085}
6086
6087inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
6088 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6089 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6090}
6091
6092template <class ALLOCATOR, typename CAPACITY_POLICY>
6096 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6098 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
6099 return result;
6100}
6101
6102template <class ALLOCATOR, typename CAPACITY_POLICY>
6104txn::replace(map_handle map, const slice &key, const slice &new_value,
6106 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6107 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
6108 MDBX_CURRENT, result, &result),
6109 result);
6110 return result;
6111}
6112
6113template <class ALLOCATOR, typename CAPACITY_POLICY>
6115txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
6117 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6118 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6119 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6120 result);
6121 return result;
6122}
6123
6124inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
6125 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6126 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
6127}
6128
6129inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
6130 const void *values_array, size_t values_count, put_mode mode,
6131 bool allow_partial) {
6132 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6133 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6134 switch (err) {
6135 case MDBX_SUCCESS:
6136 MDBX_CXX20_LIKELY break;
6137 case MDBX_KEYEXIST:
6138 if (allow_partial)
6139 break;
6141 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6142 default:
6143 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6144 }
6145 return args[1].iov_len /* done item count */;
6146}
6147
6148inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
6149 ptrdiff_t result;
6150 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6151 return result;
6152}
6153
6154inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6155 ptrdiff_t result;
6156 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6157 return result;
6158}
6159
6160inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6161 ptrdiff_t result;
6162 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6163 return result;
6164}
6165
6166inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6167 ptrdiff_t result;
6168 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6169 return result;
6170}
6171
6173
6174inline cursor &cursor::assign(const cursor &src) {
6176 return *this;
6177}
6178
6179inline cursor &cursor::operator=(cursor &&other) noexcept {
6180 if (this != &other) {
6181 handle_ = other.handle_;
6182 other.handle_ = nullptr;
6183 }
6184 return *this;
6185}
6186
6187inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6188
6189inline cursor::~cursor() noexcept {
6190#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
6191 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6192#endif
6193}
6194
6195inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6196
6197inline cursor &cursor::set_context(void *ptr) {
6199 return *this;
6200}
6201
6202inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6203 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6204}
6205
6206inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6207 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6208 MDBX_INLINE_API_ASSERT(compare_position_nothrow(right, left, ignore_nested) == -diff);
6209 if (MDBX_LIKELY(int16_t(diff) == diff))
6210 MDBX_CXX20_LIKELY return int(diff);
6211 else
6213}
6214
6215inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6216 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6217}
6218
6220 bool throw_notfound)
6221 : pair_result(key, value, false) {
6222 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6223}
6224
6225inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6226 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6227 switch (err) {
6228 case MDBX_SUCCESS:
6229 MDBX_CXX20_LIKELY return true;
6230 case MDBX_RESULT_TRUE:
6231 return false;
6232 case MDBX_NOTFOUND:
6233 if (!throw_notfound)
6234 return false;
6235 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6236 default:
6237 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6238 }
6239}
6240
6242 const slice &value)
6243 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6244 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6245}
6246
6247inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6248 ptrdiff_t result;
6249 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6250 return result;
6251}
6252
6253inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6254 ptrdiff_t result;
6256 return result;
6257}
6258
6259inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6260 return move(key_exact, key, throw_notfound);
6261}
6262
6263inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6264 return move(key_lowerbound, key, throw_notfound);
6265}
6266
6267inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6268 return move(key_greater_than, key, throw_notfound);
6269}
6270
6271inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6272 return move(multi_find_pair, key, value, throw_notfound);
6273}
6274
6275inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6276 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6277}
6278
6279inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6280 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6281}
6282
6283inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6284
6285inline size_t cursor::count_multivalue() const {
6286 size_t result;
6288 return result;
6289}
6290
6291inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6292
6294
6296
6298
6300
6301inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6302 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6303}
6304
6306 return estimate_result(*this, key_lowerbound, key);
6307}
6308
6310 return estimate_result(*this, operation);
6311}
6312
6314 return estimate_result(*this, operation, key);
6315}
6316
6318
6322
6324
6325inline txn cursor::txn() const {
6327 return ::mdbx::txn(txn);
6328}
6329
6330inline map_handle cursor::map() const {
6331 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6332 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6334 return map_handle(dbi);
6335}
6336
6337inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6338 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6339}
6340
6341inline void cursor::put(const slice &key, slice value, put_mode mode) {
6342 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6343}
6344
6345inline void cursor::insert(const slice &key, slice value) {
6347 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6348}
6349
6350inline value_result cursor::try_insert(const slice &key, slice value) {
6351 const int err =
6352 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6353 switch (err) {
6354 case MDBX_SUCCESS:
6355 return value_result{slice(), true};
6356 case MDBX_KEYEXIST:
6357 return value_result{value, false};
6358 default:
6359 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6360 }
6361}
6362
6363inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6364 slice result(nullptr, value_length);
6365 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6367 return result;
6368}
6369
6370inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6371 slice result(nullptr, value_length);
6372 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6374 switch (err) {
6375 case MDBX_SUCCESS:
6376 return value_result{result, true};
6377 case MDBX_KEYEXIST:
6378 return value_result{result, false};
6379 default:
6380 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6381 }
6382}
6383
6384inline void cursor::upsert(const slice &key, const slice &value) {
6385 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6386}
6387
6388inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6389 slice result(nullptr, value_length);
6391 return result;
6392}
6393
6394inline void cursor::update(const slice &key, const slice &value) {
6395 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6396}
6397
6398inline bool cursor::try_update(const slice &key, const slice &value) {
6399 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6400 switch (err) {
6401 case MDBX_SUCCESS:
6402 return true;
6403 case MDBX_NOTFOUND:
6404 return false;
6405 default:
6406 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6407 }
6408}
6409
6410inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6411 slice result(nullptr, value_length);
6413 return result;
6414}
6415
6416inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6417 slice result(nullptr, value_length);
6418 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6419 switch (err) {
6420 case MDBX_SUCCESS:
6421 return value_result{result, true};
6422 case MDBX_NOTFOUND:
6423 return value_result{slice(), false};
6424 default:
6425 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6426 }
6427}
6428
6429inline bool cursor::erase(bool whole_multivalue) {
6430 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6431 switch (err) {
6432 case MDBX_SUCCESS:
6433 MDBX_CXX20_LIKELY return true;
6434 case MDBX_NOTFOUND:
6435 return false;
6436 default:
6437 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6438 }
6439}
6440
6441inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6442 bool found = seek(key);
6443 return found ? erase(whole_multivalue) : found;
6444}
6445
6446inline bool cursor::erase(const slice &key, const slice &value) {
6447 move_result data = find_multivalue(key, value, false);
6448 return data.done && erase();
6449}
6450
6451inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6452 size_t values_count, put_mode mode, bool allow_partial) {
6453 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6454 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6455 switch (err) {
6456 case MDBX_SUCCESS:
6457 MDBX_CXX20_LIKELY break;
6458 case MDBX_KEYEXIST:
6459 if (allow_partial)
6460 break;
6462 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6463 default:
6464 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6465 }
6466 return args[1].iov_len /* done item count */;
6467}
6468
6469inline ptrdiff_t cursor::distance_between(const cursor from, const cursor to, unsigned deepness) {
6470 intptr_t distance = PTRDIFF_MIN;
6471 error::success_or_throw(mdbx_cursor_distance(from, to, &distance, deepness));
6472 return distance;
6473}
6474
6475inline bool cursor::scroll(intptr_t distance, unsigned deepness, bool throw_notfound) {
6476 const int err = ::mdbx_cursor_scroll(handle_, distance, deepness);
6477 switch (err) {
6478 case MDBX_SUCCESS:
6479 MDBX_CXX20_LIKELY return true;
6480 case MDBX_NOTFOUND:
6481 if (!throw_notfound)
6482 return false;
6483 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6484 default:
6485 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6486 }
6487}
6488
6489inline bool cursor::distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size,
6490 unsigned deepness) {
6491 static_assert(sizeof(cursors_array[0]) == sizeof(MDBX_cursor *), "oops");
6492 const int err = ::mdbx_cursor_distribute(from, to, &cursors_array[0].handle_, cursors_array_size, deepness);
6493 return error::boolean_or_throw(err);
6494}
6495
6496inline bool cursor::distribute(const cursor from, const cursor to, const std::vector<cursor> &cursors_array,
6497 unsigned deepness) {
6498 static_assert(sizeof(cursor) == sizeof(MDBX_cursor *), "oops");
6499 const int err = MDBX_LIKELY(!cursors_array.empty())
6500 ? ::mdbx_cursor_distribute(from, to, const_cast<MDBX_cursor **>(&cursors_array[0].handle_),
6501 cursors_array.size(), deepness)
6502 : MDBX_EINVAL;
6503 return error::boolean_or_throw(err);
6504}
6505
6506inline bool cursor::distribute(const cursor from, const cursor to, const std::vector<cursor_managed> &cursors_array,
6507 unsigned deepness) {
6508 static_assert(sizeof(cursor_managed) == sizeof(MDBX_cursor *), "oops");
6509 const int err = MDBX_LIKELY(!cursors_array.empty())
6510 ? ::mdbx_cursor_distribute(from, to, const_cast<MDBX_cursor **>(&cursors_array[0].handle_),
6511 cursors_array.size(), deepness)
6512 : MDBX_EINVAL;
6513 return error::boolean_or_throw(err);
6514}
6515
6516//------------------------------------------------------------------------------
6517
6518LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
6519LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
6520LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
6521LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
6522LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
6523LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
6524LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
6525LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
6526LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
6527LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
6528LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
6529
6530LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
6531LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
6532LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
6533
6534inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
6535
6537
6538} // namespace mdbx
6539
6540//------------------------------------------------------------------------------
6541
6544namespace std {
6545
6546inline string to_string(const ::mdbx::slice &value) {
6547 ostringstream out;
6548 out << value;
6549 return out.str();
6550}
6551
6552template <class ALLOCATOR, typename CAPACITY_POLICY>
6553inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6554 ostringstream out;
6555 out << buffer;
6556 return out.str();
6557}
6558
6559inline string to_string(const ::mdbx::pair &value) {
6560 ostringstream out;
6561 out << value;
6562 return out.str();
6563}
6564
6565inline string to_string(const ::mdbx::env::geometry &value) {
6566 ostringstream out;
6567 out << value;
6568 return out.str();
6569}
6570
6571inline string to_string(const ::mdbx::env::operate_parameters &value) {
6572 ostringstream out;
6573 out << value;
6574 return out.str();
6575}
6576
6577inline string to_string(const ::mdbx::env::mode &value) {
6578 ostringstream out;
6579 out << value;
6580 return out.str();
6581}
6582
6583inline string to_string(const ::mdbx::env::durability &value) {
6584 ostringstream out;
6585 out << value;
6586 return out.str();
6587}
6588
6589inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6590 ostringstream out;
6591 out << value;
6592 return out.str();
6593}
6594
6595inline string to_string(const ::mdbx::env::operate_options &value) {
6596 ostringstream out;
6597 out << value;
6598 return out.str();
6599}
6600
6601inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6602 ostringstream out;
6603 out << value;
6604 return out.str();
6605}
6606
6607inline string to_string(const ::MDBX_log_level_t &value) {
6608 ostringstream out;
6609 out << value;
6610 return out.str();
6611}
6612
6613inline string to_string(const ::MDBX_debug_flags_t &value) {
6614 ostringstream out;
6615 out << value;
6616 return out.str();
6617}
6618
6619inline string to_string(const ::mdbx::error &value) {
6620 ostringstream out;
6621 out << value;
6622 return out.str();
6623}
6624
6625inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6626
6627template <> struct hash<::mdbx::slice> {
6628 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6629};
6630
6631template <> struct hash<::mdbx::map_handle> {
6632 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6633};
6634
6635template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6636 using inherited = std::hash<const MDBX_env *>;
6637 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6638};
6639
6640template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6641 using inherited = std::hash<const MDBX_txn *>;
6642 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6643};
6644
6645template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6646 using inherited = std::hash<const MDBX_cursor *>;
6647 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6648};
6649
6650template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6651 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6652 return buffer.hash_value();
6653 }
6654};
6655
6656} // namespace std
6657
6658#if defined(__LCC__) && __LCC__ >= 126
6659#pragma diagnostic pop
6660#endif
6661
6662#ifdef _MSC_VER
6663#pragma warning(pop)
6664#endif
Definition mdbx.h++:1145
Definition mdbx.h++:1135
Definition mdbx.h++:1155
#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:634
#define LIBMDBX_API_TYPE
Definition mdbx.h:649
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:808
pthread_t mdbx_tid_t
Definition mdbx.h:186
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition mdbx.h:741
int mdbx_filehandle_t
Definition mdbx.h:184
pid_t mdbx_pid_t
Definition mdbx.h:185
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:822
@ MDBX_MAXDATASIZE
Definition mdbx.h:816
@ MDBX_MAX_DBI
Definition mdbx.h:813
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:819
libmdbx build information
Definition mdbx.h:677
Lightweight transparent cache entry structure used by mdbx_cache_get().
Definition mdbx.h:5263
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4756
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4162
Information about the environment.
Definition mdbx.h:2856
Statistics for a table in the environment.
Definition mdbx.h:2810
Information about the transaction.
Definition mdbx.h:4060
libmdbx version information,
Definition mdbx.h:659
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:5556
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:1653
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:4816
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5277
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:1690
@ MDBX_ALLDUPS
Definition mdbx.h:1673
@ MDBX_CURRENT
Definition mdbx.h:1668
@ MDBX_APPENDDUP
Definition mdbx.h:1686
@ MDBX_APPEND
Definition mdbx.h:1681
@ MDBX_UPSERT
Definition mdbx.h:1655
@ MDBX_RESERVE
Definition mdbx.h:1677
@ MDBX_NOOVERWRITE
Definition mdbx.h:1658
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:1734
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:771
LIBMDBX_API int mdbx_cursor_set_userctx(MDBX_cursor *cursor, void *ctx)
Set application information associated with the cursor.
LIBMDBX_API int mdbx_cursor_distance(const MDBX_cursor *first, const MDBX_cursor *last, intptr_t *distance, unsigned deepness)
Calculates the distance between the cursors at the specified B-tree level.
LIBMDBX_API int mdbx_cursor_eof(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to a key-value pair or not, i.e. was not positioned or point...
LIBMDBX_API int mdbx_cursor_scroll(MDBX_cursor *cursor, intptr_t amount, unsigned deepness)
Scrolls the cursor to the specified number of positions at the specified B-tree level.
LIBMDBX_API void * mdbx_cursor_get_userctx(const MDBX_cursor *cursor)
Get the application information associated with the MDBX_cursor.
LIBMDBX_API int mdbx_cursor_renew(MDBX_txn *txn, MDBX_cursor *cursor)
Renew a cursor handle for use within the given transaction.
LIBMDBX_API MDBX_txn * mdbx_cursor_txn(const MDBX_cursor *cursor)
Return the cursor's transaction handle.
LIBMDBX_API int mdbx_cursor_on_last(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to the last key-value pair or not.
LIBMDBX_API int mdbx_cursor_copy(const MDBX_cursor *src, MDBX_cursor *dest)
Copy cursor position and state.
@ MDBX_SEEK_AND_GET_MULTIPLE
Definition mdbx.h:1853
@ MDBX_GET_CURRENT
Definition mdbx.h:1749
@ MDBX_GET_BOTH
Definition mdbx.h:1742
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1830
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1746
@ MDBX_SET_KEY
Definition mdbx.h:1789
@ MDBX_FIRST_DUP
Definition mdbx.h:1739
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1829
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1754
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1840
@ MDBX_NEXT_NODUP
Definition mdbx.h:1774
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1837
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1838
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1845
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1797
@ MDBX_SET_RANGE
Definition mdbx.h:1792
@ MDBX_LAST_DUP
Definition mdbx.h:1760
@ MDBX_PREV
Definition mdbx.h:1777
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1847
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1848
@ MDBX_LAST
Definition mdbx.h:1757
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1828
@ MDBX_PREV_DUP
Definition mdbx.h:1780
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1836
@ MDBX_SET
Definition mdbx.h:1786
@ MDBX_NEXT
Definition mdbx.h:1763
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1831
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1844
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1771
@ MDBX_PREV_NODUP
Definition mdbx.h:1783
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1846
@ MDBX_NEXT_DUP
Definition mdbx.h:1766
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1839
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1832
@ MDBX_FIRST
Definition mdbx.h:1736
LIBMDBX_API int mdbx_dbi_rename(MDBX_txn *txn, MDBX_dbi dbi, const char *name)
Renames the table using the DBI descriptor.
LIBMDBX_API int mdbx_dbi_rename2(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *name)
Renames the table using the DBI descriptor.
LIBMDBX_API int mdbx_dbi_close(MDBX_env *env, MDBX_dbi dbi)
Close a table handle. Normally unnecessary.
LIBMDBX_API int mdbx_dbi_open(MDBX_txn *txn, const char *name, MDBX_db_flags_t flags, MDBX_dbi *dbi)
Open or Create a named table in the environment.
LIBMDBX_API int mdbx_dbi_open2(MDBX_txn *txn, const MDBX_val *name, MDBX_db_flags_t flags, MDBX_dbi *dbi)
Open or Create a named table in the environment.
uint32_t MDBX_dbi
A handle for an individual table (key-value spaces) in the environment.
Definition mdbx.h:764
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1603
@ MDBX_INTEGERDUP
Definition mdbx.h:1627
@ MDBX_DB_ACCEDE
Definition mdbx.h:1645
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1605
@ MDBX_REVERSEKEY
Definition mdbx.h:1608
@ MDBX_DUPFIXED
Definition mdbx.h:1622
@ MDBX_INTEGERKEY
Definition mdbx.h:1618
@ MDBX_REVERSEDUP
Definition mdbx.h:1630
@ MDBX_CREATE
Definition mdbx.h:1633
@ MDBX_DUPSORT
Definition mdbx.h:1611
MDBX_log_level_t
Definition mdbx.h:884
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:942
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1861
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:6983
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1875
@ MDBX_BAD_TXN
Definition mdbx.h:1938
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1952
@ MDBX_SUCCESS
Definition mdbx.h:1863
@ MDBX_NOTFOUND
Definition mdbx.h:1878
@ MDBX_RESULT_TRUE
Definition mdbx.h:1869
@ MDBX_BUSY
Definition mdbx.h:1956
@ MDBX_EINVAL
Definition mdbx.h:2032
@ MDBX_ENOMEM
Definition mdbx.h:2034
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1959
@ MDBX_RESULT_FALSE
Definition mdbx.h:1866
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:2011
@ MDBX_KEYEXIST
Definition mdbx.h:1872
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:2595
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2590
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2593
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1085
@ MDBX_WRITEMAP
Definition mdbx.h:1205
@ MDBX_EXCLUSIVE
Definition mdbx.h:1159
@ MDBX_RDONLY
Definition mdbx.h:1129
LIBMDBX_API int mdbx_estimate_distance(const MDBX_cursor *first, const MDBX_cursor *last, ptrdiff_t *distance_items)
Estimates the distance between cursors as a number of elements.
LIBMDBX_API int mdbx_estimate_move(const MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, MDBX_cursor_op move_op, ptrdiff_t *distance_items)
Estimates the move distance.
LIBMDBX_API int mdbx_estimate_range(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *begin_key, const MDBX_val *begin_data, const MDBX_val *end_key, const MDBX_val *end_data, ptrdiff_t *distance_items)
Estimates the size of a range as a number of elements.
LIBMDBX_API int mdbx_env_get_option(const MDBX_env *env, const MDBX_option_t option, uint64_t *pvalue)
Gets the value of extra runtime options from an environment.
int mdbx_env_set_syncperiod(MDBX_env *env, unsigned seconds_16dot16)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
Definition mdbx.h:3101
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2135
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:3042
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:2240
@ 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:2402
@ MDBX_opt_subpage_limit
Specifies the maximum size of nested pages used to accommodate a small number of multi-values associa...
Definition mdbx.h:2395
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2236
@ MDBX_opt_prefer_waf_insteadof_balance
Controls the choice between striving for uniformity of page filling/density, either for reducing the ...
Definition mdbx.h:2381
@ MDBX_opt_presync_threshold
Sets threshold in bytes for preliminary flush/sync operation without holding a transaction lock.
Definition mdbx.h:2462
@ 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:2340
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2144
@ 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:2416
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2167
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2272
@ 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:2295
@ MDBX_opt_split_reserve
Sets the space reservation in 1/65536 of page size when splitting page along the edge.
Definition mdbx.h:2444
@ 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:2207
@ 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:2194
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2161
@ MDBX_opt_subpage_reserve_limit
Sets the limit for reserving space on nested pages.
Definition mdbx.h:2422
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2256
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2173
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2221
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2335
@ MDBX_opt_gc_time_limit
Controls the in-process spending time limit of searching consecutive pages inside GC.
Definition mdbx.h:2359
@ MDBX_opt_merge_threshold
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2307
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:3716
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:3121
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:3060
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:5078
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:3761
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:1502
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:3977
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:752
LIBMDBX_API int mdbx_txn_reset(MDBX_txn *txn)
Reset a read-only transaction.
LIBMDBX_API int mdbx_txn_renew(MDBX_txn *txn)
Renew a read-only transaction.
LIBMDBX_API MDBX_txn_flags_t mdbx_txn_flags(const MDBX_txn *txn)
Return the transaction's flags.
@ MDBX_TXN_RDONLY
Definition mdbx.h:1513
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1522
@ MDBX_TXN_READWRITE
Definition mdbx.h:1507
@ MDBX_TXN_TRY
Definition mdbx.h:1528
void commit(finalization_latency &latency)
ommits all changes of the transaction into a database with collecting latencies information.
Definition mdbx.h++:4107
constexpr const MDBX_env * handle() const noexcept
Definition mdbx.h++:3006
friend class env
Definition mdbx.h++:4072
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:3758
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4599
bool scan_until(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4294
::MDBX_stat map_stat
Definition mdbx.h++:3924
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++:3455
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++:3905
bool scan_until_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4339
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++:2953
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4416
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4472
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:3008
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr const MDBX_cursor * handle() const noexcept
Definition mdbx.h++:4172
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2922
durability
Durability level.
Definition mdbx.h++:3102
@ lazy_weak_tail
Definition mdbx.h++:3105
@ robust_synchronous
Definition mdbx.h++:3103
@ whole_fragile
Definition mdbx.h++:3106
@ half_synchronous_weak_last
Definition mdbx.h++:3104
friend constexpr bool operator!=(const cursor &a, const cursor &b) noexcept
Definition mdbx.h++:4177
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++:2949
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3270
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++:4460
bool checkpoint(finalization_latency &latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4121
constexpr cache_entry(const MDBX_cache_entry_t &ce) noexcept
Definition mdbx.h++:2786
cache_entry() noexcept
Definition mdbx.h++:2778
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3713
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4435
ptrdiff_t distance_to_end(unsigned deepness=42) const
Definition mdbx.h++:4498
::MDBX_canary canary
Definition mdbx.h++:3933
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++:4124
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++:3756
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++:4365
friend constexpr bool operator!=(const txn &a, const txn &b) noexcept
Definition mdbx.h++:3731
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++:4429
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++:4438
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++:2787
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
void reset() noexcept
Definition mdbx.h++:2785
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2943
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2923
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4552
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4383
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++:4374
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++:4200
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3812
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3988
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4406
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4192
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4196
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++:3897
constexpr MDBX_txn * handle() noexcept
Definition mdbx.h++:3729
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3197
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4390
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4610
MDBX_txn * handle_
Definition mdbx.h++:3714
void abort()
Abandon all the operations of the transaction instead of saving ones.
MDBX_commit_latency finalization_latency
Definition mdbx.h++:4086
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++:4362
mode
Operation mode.
Definition mdbx.h++:3094
@ write_mapped_io
Definition mdbx.h++:3097
@ nested_transactions
Definition mdbx.h++:3098
@ readonly
Definition mdbx.h++:3095
@ write_file_io
Definition mdbx.h++:3096
friend constexpr bool operator==(const cursor &a, const cursor &b) noexcept
Definition mdbx.h++:4174
bool is_writemap() const
Definition mdbx.h++:3363
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4359
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3331
operator::mdbx::txn() const
Definition mdbx.h++:4529
MDBX_env * handle_
Definition mdbx.h++:2992
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++:4422
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4188
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4372
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4392
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:2781
bool is_nested_transactions_available() const
Definition mdbx.h++:3367
void close()
Explicitly closes the cursor.
constexpr MDBX_env * handle() noexcept
Definition mdbx.h++:3007
bool scan_until_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4318
void abort(finalization_latency &latency)
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4093
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++:4403
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3753
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++:4468
env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede=true)
ptrdiff_t distance_from_first(unsigned deepness=42) const
Definition mdbx.h++:4495
void append(map_handle map, const pair &kv, bool multivalue_order_preserved=true)
Definition mdbx.h++:4036
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3301
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3311
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3313
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3308
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4377
cursor_managed & operator=(cursor_managed &&other) noexcept
::MDBX_dbi_state_t state
Definition mdbx.h++:2954
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3528
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4579
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++:3276
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4432
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++:4464
ptrdiff_t distance_to(const cursor to, unsigned deepness=42) const
Definition mdbx.h++:4492
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4394
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4391
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4530
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3272
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2946
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3809
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2937
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++:4409
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3337
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3985
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++:6206
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4052
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++:3283
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++:3890
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2934
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++:4135
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++:4044
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++:4138
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++:2940
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++:4444
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4210
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4225
@ multi_exactkey_value_equal
Definition mdbx.h++:4242
@ pair_greater_or_equal
Definition mdbx.h++:4250
@ key_lesser_than
Definition mdbx.h++:4232
@ next
Definition mdbx.h++:4213
@ pair_exact
Definition mdbx.h++:4249
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4243
@ pair_lesser_or_equal
Definition mdbx.h++:4247
@ batch_samelength
Definition mdbx.h++:4253
@ seek_key
Definition mdbx.h++:4227
@ key_lowerbound
Definition mdbx.h++:4229
@ pair_lesser_than
Definition mdbx.h++:4246
@ pair_equal
Definition mdbx.h++:4248
@ key_greater_than
Definition mdbx.h++:4236
@ batch_samelength_next
Definition mdbx.h++:4254
@ multi_find_pair
Definition mdbx.h++:4224
@ key_greater_or_equal
Definition mdbx.h++:4235
@ key_exact
Definition mdbx.h++:4228
@ key_equal
Definition mdbx.h++:4234
@ multi_currentkey_prevvalue
Definition mdbx.h++:4219
@ key_lesser_or_equal
Definition mdbx.h++:4233
@ multi_nextkey_firstvalue
Definition mdbx.h++:4222
@ get_current
Definition mdbx.h++:4215
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4241
@ multi_prevkey_lastvalue
Definition mdbx.h++:4217
@ previous
Definition mdbx.h++:4214
@ last
Definition mdbx.h++:4212
@ pair_greater_than
Definition mdbx.h++:4251
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4240
@ multi_currentkey_firstvalue
Definition mdbx.h++:4218
@ first
Definition mdbx.h++:4211
@ batch_samelength_previous
Definition mdbx.h++:4255
@ multi_currentkey_nextvalue
Definition mdbx.h++:4220
@ seek_and_batch_samelength
Definition mdbx.h++:4256
@ multi_exactkey_value_greater
Definition mdbx.h++:4244
@ multi_currentkey_lastvalue
Definition mdbx.h++:4221
finalization_latency commit_get_latency()
Commits all changes of the transaction into a database and return latency information.
Definition mdbx.h++:4110
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4368
void insert(const pair &kv)
Definition mdbx.h++:4553
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3750
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++:4555
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4380
constexpr const MDBX_txn * handle() const noexcept
Definition mdbx.h++:3728
bool is_cooperative() const
Definition mdbx.h++:3361
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3910
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4419
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++:4387
bool is_readonly() const
Definition mdbx.h++:3357
value_result try_insert(const pair &kv)
Definition mdbx.h++:4554
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++:4571
constexpr cursor() noexcept=default
bool is_exclusive() const
Definition mdbx.h++:3359
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4397
finalization_latency abort_get_latency()
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4096
constexpr MDBX_cursor * handle() noexcept
Definition mdbx.h++:4173
bool is_readwrite() const
Definition mdbx.h++:3365
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4441
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3280
MDBX_cursor * handle_
Definition mdbx.h++:4157
MDBX_dbi dbi
Definition mdbx.h++:2921
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4413
friend constexpr bool operator!=(const env &a, const env &b) noexcept
Definition mdbx.h++:3009
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4384
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3764
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++:4425
ptrdiff_t distance_from(const cursor from, unsigned deepness=42) const
Definition mdbx.h++:4488
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3328
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3278
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3987
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3986
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++:3918
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4400
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++:4373
friend class txn
Definition mdbx.h++:2989
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4184
friend constexpr bool operator==(const txn &a, const txn &b) noexcept
Definition mdbx.h++:3730
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3274
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3767
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4313
Unmanaged cursor.
Definition mdbx.h++:4155
Managed cursor.
Definition mdbx.h++:4591
Unmanaged database environment.
Definition mdbx.h++:2988
Managed database environment.
Definition mdbx.h++:3637
Unmanaged database transaction.
Definition mdbx.h++:3711
Managed database transaction.
Definition mdbx.h++:4070
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++:5330
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5202
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4869
polymorphic_allocator default_allocator
Definition mdbx.h++:381
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4878
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4960
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++:5176
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++:5114
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++:5105
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5671
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++:5358
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4974
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4719
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++:6087
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6317
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2835
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4856
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:4676
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4954
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5704
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++:4846
void rethrow_captured() const
Definition mdbx.h++:4691
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4854
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6271
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6247
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5323
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5297
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++:5123
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6048
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5990
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5577
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++:5508
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6215
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++:5155
::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++:4876
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6160
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++:5181
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4901
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4802
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6323
::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++:5981
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6172
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5801
void throw_on_failure() const
Definition mdbx.h++:4731
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6398
void update(const slice &key, const slice &value)
Definition mdbx.h++:6394
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:4673
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++:5872
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:5026
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4864
::MDBX_cmp_func comparator
Definition mdbx.h++:2966
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++:5170
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5673
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5644
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6202
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5000
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5441
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5860
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6384
bool is_clean() const noexcept
Definition mdbx.h++:4684
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2828
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4764
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++:5160
path_string::value_type path_char
Definition mdbx.h++:437
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5431
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2832
::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++:5483
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5316
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4944
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4698
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++:5186
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4626
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5057
buffer< ALLOCATOR, CAPACITY_POLICY > replace_reserve(map_handle map, const slice &key, slice &new_value, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &alloc=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Definition mdbx.h++:6115
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++:5615
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++:5580
void insert(const slice &key, slice value)
Definition mdbx.h++:6345
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6275
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++:5756
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:5251
::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++:2816
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++:5196
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4786
~cursor() noexcept
Definition mdbx.h++:6189
~txn() noexcept
Definition mdbx.h++:5665
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5513
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:5150
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6267
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++:4882
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6325
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6370
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5308
map_handle map() const
Definition mdbx.h++:6330
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++:5524
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:4680
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6259
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5772
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6279
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2896
void success_or_throw() const
Definition mdbx.h++:4736
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5708
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4916
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5564
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5004
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6206
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6285
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4912
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5314
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4921
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5678
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6388
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5439
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2824
void capture() noexcept
Definition mdbx.h++:4686
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:5132
bool scroll(intptr_t distable, unsigned deepness=42, bool throw_notfound=true)
Definition mdbx.h++:6475
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++:5837
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6026
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4895
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2967
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6363
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++:5620
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++:5378
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++:5519
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:6148
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5445
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5797
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6166
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++:6124
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5449
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5723
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5008
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6197
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5831
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6225
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++:5354
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++:5876
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5304
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5849
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6012
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4939
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4713
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++:5530
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4966
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4838
bool on_first() const
Definition mdbx.h++:6293
::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++:4874
bool eof() const
Definition mdbx.h++:6291
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5706
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5692
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5501
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6337
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5629
::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++:5145
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5653
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4906
bool seek(const slice &key)
Definition mdbx.h++:6283
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5553
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5503
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4928
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++:5422
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5799
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++:5542
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5267
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4889
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6350
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++:6451
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4749
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4707
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5690
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2975
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5207
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++:5191
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++:5534
::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++:5400
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5273
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4996
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++:5854
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6429
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5453
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5100
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5698
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5966
::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++:4721
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:5127
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:5109
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6253
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4981
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:5118
static bool distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size, unsigned deepness=42)
Definition mdbx.h++:6489
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:5136
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6040
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5263
~env() noexcept
Definition mdbx.h++:5285
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2797
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5888
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4715
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4884
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++:6129
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6020
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4933
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2800
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5622
::mdbx::filesystem::path path
Definition mdbx.h++:428
bool on_last_multival() const
Definition mdbx.h++:6299
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5495
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5959
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5489
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++:5334
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5585
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6195
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5429
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5735
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2820
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5725
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5547
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4627
bool on_first_multival() const
Definition mdbx.h++:6297
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5947
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:5039
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4949
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5465
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6006
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5312
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++:5165
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6410
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:5710
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6263
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4840
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4862
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++:5248
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5608
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:6063
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4711
bool on_last() const
Definition mdbx.h++:6295
buffer< ALLOCATOR, CAPACITY_POLICY > extract(map_handle map, const slice &key, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &alloc=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Removes and return a value of the key.
Definition mdbx.h++:6094
#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++:5477
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5558
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++:6319
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:5141
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5291
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5741
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4705
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5079
constexpr bool is_success() const noexcept
Definition mdbx.h++:4709
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6416
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:5052
cursor & assign(const cursor &)
Definition mdbx.h++:6174
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5651
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5259
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5729
static ptrdiff_t distance_between(const cursor from, const cursor to, unsigned deepness=42)
Definition mdbx.h++:6469
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++:5788
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++:5926
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5843
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4848
@ multi_reverse_samelength
Definition mdbx.h++:2868
@ multi_samelength
Definition mdbx.h++:2853
@ multi_ordinal
Definition mdbx.h++:2860
@ msgpack
Definition mdbx.h++:2883
@ single
Definition mdbx.h++:2836
@ multi
Definition mdbx.h++:2838
@ multi_reverse
Definition mdbx.h++:2845
@ upsert
Insert or update.
Definition mdbx.h++:2977
@ update
Update existing, don't insert new.
Definition mdbx.h++:2978
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2976
@ continue_loop
Definition mdbx.h++:2797
@ exit_loop
Definition mdbx.h++:2797
@ usual
Definition mdbx.h++:2801
@ ordinal
Definition mdbx.h++:2806
@ reverse
Definition mdbx.h++:2803
@ msgpack
Definition mdbx.h++:2811
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2920
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2418
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2123
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++:1998
modality
Data storage modality.
Definition mdbx.h++:1573
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2028
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++:2093
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1981
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:698
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++:2266
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2307
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++:1249
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++:2647
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++:2215
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:720
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:2044
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2337
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2041
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2427
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2290
constexpr size_t tailroom() const noexcept
Returns the number of bytes that available in currently allocated storage after the data.
Definition mdbx.h++:2016
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2150
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2398
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2304
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2035
buffer & append(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:2457
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2155
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2679
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1559
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1022
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1226
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2342
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2068
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2536
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2064
buffer & append(const byte c)
Definition mdbx.h++:2490
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2315
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:738
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1003
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2320
buffer & operator=(const buffer &src)
Definition mdbx.h++:2444
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1021
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2558
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++:2011
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2721
constexpr int64_t as_int64() const
Definition mdbx.h++:1028
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2061
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2637
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++:2197
const bool ignore_spaces
Definition mdbx.h++:1329
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:842
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++:2279
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++:2273
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2192
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2500
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2235
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++:1091
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Definition mdbx.h++:755
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2690
constexpr int16_t as_int16() const
Definition mdbx.h++:1030
slice value
Definition mdbx.h++:1055
::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++:2692
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2423
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++:2259
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2657
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1197
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++:2285
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2189
slice value
Definition mdbx.h++:1069
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2683
::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++:2663
const slice source
Definition mdbx.h++:1328
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2701
const slice source
Definition mdbx.h++:1164
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++:2223
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++:1311
const unsigned wrap_width
Definition mdbx.h++:1166
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2453
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2643
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:712
const slice & slice() const noexcept
Definition mdbx.h++:2675
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2406
const bool ignore_spaces
Definition mdbx.h++:1295
constexpr POD as_pod() const
Definition mdbx.h++:1005
constexpr buffer & assign(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2375
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++:1118
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++:1395
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2696
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2394
constexpr buffer(const buffer &src)
Definition mdbx.h++:2133
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++:2252
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1018
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2475
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2081
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2649
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2329
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1167
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2698
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2532
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2629
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1524
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2166
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:734
std::pair< slice, slice > stl_pair
Definition mdbx.h++:1068
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2556
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:1993
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
typename silo::copy_assign_alloc copy_assign_alloc
Definition mdbx.h++:1976
@ pettiness_threshold
Definition mdbx.h++:1513
@ extra_inplace_storage
Definition mdbx.h++:1511
@ max_reserve
Definition mdbx.h++:1514
@ inplace_storage_size_rounding
Definition mdbx.h++:1512
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2661
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:675
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1330
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2448
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2528
constexpr int8_t as_int8() const
Definition mdbx.h++:1031
constexpr ::std::span< char > chars()
Definition mdbx.h++:687
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1050
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1268
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2118
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++:1517
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1240
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++:1386
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:1057
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2641
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1357
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2247
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2161
const slice source
Definition mdbx.h++:1207
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:1071
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2412
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++:1985
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2665
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++:1369
buffer_pair_spec & operator=(buffer_pair_spec &&src)
Definition mdbx.h++:2725
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2591
constexpr void swap(slice &other) noexcept
Definition mdbx.h++:850
typename silo::swap_alloc swap_alloc
Definition mdbx.h++:1977
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++:1201
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1560
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++:2655
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2112
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2450
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2741
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2508
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2579
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2540
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++:1347
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:717
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++:742
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1318
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:631
pair & operator=(pair &&couple) noexcept
Definition mdbx.h++:1075
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++:2230
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2671
slice inherited
Definition mdbx.h++:1553
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:1119
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1296
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2667
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++:2669
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2309
static constexpr pair invalid() noexcept
Definition mdbx.h++:1084
typename silo::move_assign_alloc move_assign_alloc
Definition mdbx.h++:1975
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2101
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2402
bool done
Definition mdbx.h++:1117
::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++:1243
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:684
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:700
const bool uppercase
Definition mdbx.h++:1165
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2048
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2357
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2498
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2544
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2709
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2055
const bool ignore_spaces
Definition mdbx.h++:1368
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1252
pair(const pair &) noexcept=default
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2623
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:998
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++:1026
slice key
Definition mdbx.h++:1069
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2482
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:1070
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2715
const slice source
Definition mdbx.h++:1367
pair_result & operator=(const pair_result &) noexcept=default
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2480
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1285
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2673
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2472
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2681
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++:1029
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++:2209
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2137
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1555
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2645
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2021
constexpr modality content_modality() const noexcept
Returns current modality of buffer content.
Definition mdbx.h++:2001
pair & operator=(const stl_pair &couple)
Definition mdbx.h++:1086
int64_t as_int64_adapt() const
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2653
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2024
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++:2204
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2333
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2707
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1023
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2682
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2146
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1978
buffer & append(const ::std::basic_string< CHAR, T, A > &str)
Definition mdbx.h++:2467
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2548
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2568
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1020
buffer(const ::std::basic_string< CHAR, T, A > &&)=delete
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2703
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2651
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++:2242
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2605
const unsigned wrap_width
Definition mdbx.h++:1208
buffer(const ::std::basic_string< CHAR, T, A > &)=delete
buffer & append_hex(const struct slice &data, bool uppercase=false, unsigned wrap_width=0)
Definition mdbx.h++:2524
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2186
const unsigned wrap_width
Definition mdbx.h++:1250
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2446
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++:995
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2075
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++:2510
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2718
buffer_pair_spec(const txn &transaction, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2712
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++:2517
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2141
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2634
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2680
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++:1289
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++:1210
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2129
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:695
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++:1182
buffer(buffer &&src) noexcept(::std::is_nothrow_move_constructible< allocator_type >::value)
Definition mdbx.h++:2174
bool done
Definition mdbx.h++:1056
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++:1294
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:2006
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2086
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1551
Definition mdbx.h++:2678
Type tag for delivered buffer template classes.
Definition mdbx.h++:1547
Definition mdbx.h++:1509
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1327
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1366
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1293
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:1067
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:1116
References a data located outside the slice.
Definition mdbx.h++:626
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1206
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1248
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1163
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:1054
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++:4707
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++:4705
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:5017
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:5021
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++:1403
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1405
The libmdbx C++ API namespace.
Definition mdbx.h++:307
STL namespace.
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6546
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1652
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1654
byte lastbyte_
Definition mdbx.h++:1653
Definition mdbx.h++:4275
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4277
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4276
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4279
Definition mdbx.h++:4263
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++:4267
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4265
Tagged type for output to std::ostream.
Definition mdbx.h++:3042
intptr_t bytes
Definition mdbx.h++:3043
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3044
Database geometry for size management.
Definition mdbx.h++:3018
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3066
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3078
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3025
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3021
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3024
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3033
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3022
@ default_value
Means "keep current or use default".
Definition mdbx.h++:3020
@ kB
bytes (0x03E8)
Definition mdbx.h++:3023
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3032
@ KiB
bytes (0x0400)
Definition mdbx.h++:3031
constexpr geometry() noexcept
Definition mdbx.h++:3082
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++:3069
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3054
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3072
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3049
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++:3086
Operate options.
Definition mdbx.h++:3121
bool disable_readahead
Definition mdbx.h++:3130
bool enable_validation
Definition mdbx.h++:3134
bool no_sticky_threads
Definition mdbx.h++:3123
constexpr operate_options() noexcept
Definition mdbx.h++:3135
bool disable_clear_memory
Definition mdbx.h++:3132
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3128
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
bool nested_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3126
Operate parameters.
Definition mdbx.h++:3143
env::durability durability
Definition mdbx.h++:3151
env::operate_options options
Definition mdbx.h++:3153
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++:3157
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++:3149
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3152
env::mode mode
Definition mdbx.h++:3150
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++:3146
constexpr operate_parameters() noexcept
Definition mdbx.h++:3155
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3551
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3554
uint64_t transaction_lag
Definition mdbx.h++:3557
size_t bytes_used
Definition mdbx.h++:3561
uint64_t transaction_id
Definition mdbx.h++:3555
int slot
The reader lock table slot number.
Definition mdbx.h++:3552
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3553
size_t bytes_retained
Definition mdbx.h++:3564
Garbage reclaiming options.
Definition mdbx.h++:3110
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++:3113
bool lifo
Definition mdbx.h++:3112
Additional parameters for creating a new database.
Definition mdbx.h++:3660
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3662
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3663
env::geometry geometry
Definition mdbx.h++:3661
Definition mdbx.h++:2955
map_handle::state state
Definition mdbx.h++:2957
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2956
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6651
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6647
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6646
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6637
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6636
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6632
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6628
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6641
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6642
capacity_holder capacity_
Definition mdbx.h++:1658
allocator_pointer stub_ptr_
Definition mdbx.h++:1633
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1670
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1703
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1662
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1677
inplace_flag_holder inplace_
Definition mdbx.h++:1659
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1661
allocator_pointer allocated_ptr_
Definition mdbx.h++:1657
size_t stub_capacity_bytes_
Definition mdbx.h++:1634
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1722
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1647
size_t bytes_
Definition mdbx.h++:1648
constexpr const byte * address() const noexcept
Definition mdbx.h++:1716
constexpr bin() noexcept
Definition mdbx.h++:1697
@ inplace_size
Definition mdbx.h++:1642
@ inplace_signature_limit
Definition mdbx.h++:1639
@ inplace_size_rounding
Definition mdbx.h++:1641
constexpr byte * address() noexcept
Definition mdbx.h++:1719
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1688
@ lastbyte_poison
Definition mdbx.h++:1637
@ lastbyte_inplace_signature
Definition mdbx.h++:1637
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1712
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1679