libmdbx 0.14.2.274 (2026-07-09T20:41:59+03:00)
One of the fastest compact embeddable key-value ACID storage engine without WAL.
Loading...
Searching...
No Matches
mdbx.h++
Go to the documentation of this file.
1
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 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 /* 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
851 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
852 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
853
855 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
856 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
857
859 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
860 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
861
863 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
864 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
865
867 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
868 MDBX_CXX11_CONSTEXPR void *data() noexcept;
869
871 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
872 MDBX_CXX11_CONSTEXPR void *end() noexcept;
873
875 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
876
878 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
879
881 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
882
884 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
885
887 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
888
890 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
891
893 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
894
896 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
897
899 MDBX_CXX14_CONSTEXPR void clear() noexcept;
900
903 inline void remove_prefix(size_t n) noexcept;
904
907 inline void remove_suffix(size_t n) noexcept;
908
911 inline void safe_remove_prefix(size_t n);
912
915 inline void safe_remove_suffix(size_t n);
916
918 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
919
921 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
922
925 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
926
929 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
930
933 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
934
937 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
938
941 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
942
945 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
946
949 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
950
953 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
954
959 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
960
969 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
970
976 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
977 const slice &b) noexcept;
978 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
979 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
980 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
981 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
982 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
983 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
984#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
985 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
986#endif /* __cpp_impl_three_way_comparison */
987
989 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
990
993 return slice(/* using special constructor without length checking */ ~size_t(0));
994 }
995
997 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
998
999 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1000 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1001 "Must be a standard layout type!");
1002 if (MDBX_LIKELY(size() == sizeof(POD)))
1004 POD r;
1005 memcpy(&r, data(), sizeof(r));
1006 return r;
1007 }
1009 }
1010
1011#ifdef MDBX_U128_TYPE
1012 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1013#endif /* MDBX_U128_TYPE */
1014 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1015 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1016 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1017 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1018
1019#ifdef MDBX_I128_TYPE
1020 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1021#endif /* MDBX_I128_TYPE */
1022 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1023 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1024 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1025 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1026
1027#ifdef MDBX_U128_TYPE
1028 MDBX_U128_TYPE as_uint128_adapt() const;
1029#endif /* MDBX_U128_TYPE */
1030 uint64_t as_uint64_adapt() const;
1031 uint32_t as_uint32_adapt() const;
1032 uint16_t as_uint16_adapt() const;
1033 uint8_t as_uint8_adapt() const;
1034
1035#ifdef MDBX_I128_TYPE
1036 MDBX_I128_TYPE as_int128_adapt() const;
1037#endif /* MDBX_I128_TYPE */
1038 int64_t as_int64_adapt() const;
1039 int32_t as_int32_adapt() const;
1040 int16_t as_int16_adapt() const;
1041 int8_t as_int8_adapt() const;
1042
1043protected:
1044 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1045};
1046
1050 bool done;
1051 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
1052 value_result(const value_result &) noexcept = default;
1053 value_result &operator=(const value_result &) noexcept = default;
1054 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1056 return done;
1057 }
1058};
1059
1061struct pair {
1062 using stl_pair = std::pair<slice, slice>;
1064 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
1065 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
1066 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
1067 pair(const pair &) noexcept = default;
1068 pair &operator=(const pair &) noexcept = default;
1069 pair &operator=(pair &&couple) noexcept {
1070 key.assign(std::move(couple.key));
1071 value.assign(std::move(couple.value));
1072 return *this;
1073 }
1074 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1075 MDBX_INLINE_API_ASSERT(bool(key) == bool(value));
1076 return key;
1077 }
1079
1080 pair &operator=(const stl_pair &couple) {
1081 key.assign(couple.first);
1082 value.assign(couple.second);
1083 return *this;
1084 }
1086 key.assign(std::move(couple.first));
1087 value.assign(std::move(couple.second));
1088 return *this;
1089 }
1090
1092 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
1093
1095 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
1096 const pair &b) noexcept;
1097 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
1098 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
1099 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
1100 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
1101 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
1102 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
1103#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1104 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
1105#endif /* __cpp_impl_three_way_comparison */
1106};
1107
1110struct pair_result : public pair {
1111 bool done;
1114 : pair(key, value), done(done) {}
1115 pair_result(const pair_result &) noexcept = default;
1116 pair_result &operator=(const pair_result &) noexcept = default;
1117 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1118 MDBX_INLINE_API_ASSERT(!done || (bool(key) && bool(value)));
1119 return done;
1120 }
1121};
1122
1123#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
1124
1128template <typename T>
1129concept MutableByteProducer = requires(T a, char array[42]) {
1130 { a.is_empty() } -> std::same_as<bool>;
1131 { a.envisage_result_length() } -> std::same_as<size_t>;
1132 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1133};
1134
1138template <typename T>
1139concept ImmutableByteProducer = requires(const T &a, char array[42]) {
1140 { a.is_empty() } -> std::same_as<bool>;
1141 { a.envisage_result_length() } -> std::same_as<size_t>;
1142 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1143};
1144
1148template <typename T>
1149concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
1150 T(source);
1151 { a.is_erroneous() } -> std::same_as<bool>;
1152};
1153
1154#endif /* MDBX_HAVE_CXX20_CONCEPTS */
1155
1159 const bool uppercase = false;
1160 const unsigned wrap_width = 0;
1165
1167 template <class ALLOCATOR = default_allocator>
1168 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1169
1171 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1172 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1173
1177 const size_t bytes = source.length() << 1;
1178 return wrap_width ? bytes + bytes / wrap_width : bytes;
1179 }
1180
1183 char *write_bytes(char *dest, size_t dest_size) const;
1184
1187 ::std::ostream &output(::std::ostream &out) const;
1188
1191 bool is_empty() const noexcept { return source.empty(); }
1192
1195 bool is_erroneous() const noexcept { return false; }
1196};
1197
1202 const unsigned wrap_width = 0;
1207
1210 template <class ALLOCATOR = default_allocator>
1211 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1212
1215 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1216 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1217
1221 const size_t bytes = (source.length() * 11 + 7) / 8;
1222 return wrap_width ? bytes + bytes / wrap_width : bytes;
1223 }
1224
1227 char *write_bytes(char *dest, size_t dest_size) const;
1228
1231 ::std::ostream &output(::std::ostream &out) const;
1232
1234 bool is_empty() const noexcept { return source.empty(); }
1235
1237 bool is_erroneous() const noexcept { return false; }
1238};
1239
1244 const unsigned wrap_width = 0;
1249
1252 template <class ALLOCATOR = default_allocator>
1253 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1254
1257 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1258 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1259
1263 const size_t bytes = (source.length() + 2) / 3 * 4;
1264 return wrap_width ? bytes + bytes / wrap_width : bytes;
1265 }
1266
1270 char *write_bytes(char *dest, size_t dest_size) const;
1271
1275 ::std::ostream &output(::std::ostream &out) const;
1276
1279 bool is_empty() const noexcept { return source.empty(); }
1280
1283 bool is_erroneous() const noexcept { return false; }
1284};
1285
1289 const bool ignore_spaces = false;
1294
1296 template <class ALLOCATOR = default_allocator>
1297 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1298
1300 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1301 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1302
1305 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1306
1309 char *write_bytes(char *dest, size_t dest_size) const;
1310
1312 bool is_empty() const noexcept { return source.empty(); }
1313
1316 bool is_erroneous() const noexcept;
1317};
1318
1323 const bool ignore_spaces = false;
1328
1331 template <class ALLOCATOR = default_allocator>
1332 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1333
1336 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1337 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1338
1342 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1343 }
1344
1348 char *write_bytes(char *dest, size_t dest_size) const;
1349
1351 bool is_empty() const noexcept { return source.empty(); }
1352
1355 bool is_erroneous() const noexcept;
1356};
1357
1362 const bool ignore_spaces = false;
1367
1370 template <class ALLOCATOR = default_allocator>
1371 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1372
1375 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1376 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1377
1380 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1381
1385 char *write_bytes(char *dest, size_t dest_size) const;
1386
1389 bool is_empty() const noexcept { return source.empty(); }
1390
1394 bool is_erroneous() const noexcept;
1395};
1396
1398
1399template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1400#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1401 return ::std::allocator_traits<A>::is_always_equal::value;
1402#else
1403 return ::std::is_empty<A>::value;
1404#endif /* __cpp_lib_allocator_traits_is_always_equal */
1405}
1406
1407template <typename T, typename A = typename T::allocator_type,
1408 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1410
1411template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1412 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1413 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1414 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1415 }
1416 static MDBX_CXX20_CONSTEXPR void propagate(T *, T &) noexcept {}
1417};
1418
1419template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1420 static constexpr bool is_nothrow() noexcept {
1421 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1422 }
1423 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1424 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1425 target->get_allocator() = ::std::move(source.get_allocator());
1426 }
1427};
1428
1429template <typename T, typename A = typename T::allocator_type,
1430 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1432
1433template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1434 static constexpr bool is_nothrow() noexcept { return false; }
1435 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1436};
1437
1438template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1439 static constexpr bool is_nothrow() noexcept {
1440 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1441 }
1442 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1443 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1444 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1445 MDBX_CXX20_UNLIKELY target->get_allocator() =
1446 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1447 } else {
1448 /* gag for buggy compilers */
1449 (void)target;
1450 (void)source;
1451 }
1452 }
1453};
1454
1455template <typename T, typename A = typename T::allocator_type,
1456 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1458
1459template <typename T, typename A> struct swap_alloc<T, A, false> {
1460 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1461 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1463 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1464 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1465 } else {
1466 /* gag for buggy compilers */
1467 (void)left;
1468 (void)right;
1469 }
1470 }
1471};
1472
1473template <typename T, typename A> struct swap_alloc<T, A, true> {
1474 static constexpr bool is_nothrow() noexcept {
1475 return allocator_is_always_equal<A>() ||
1476#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1477 ::std::is_nothrow_swappable<A>() ||
1478#endif /* __cpp_lib_is_swappable >= 201603L */
1479 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1480 }
1481 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1482 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1483 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1484 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1485 } else {
1486 /* gag for buggy compilers */
1487 (void)left;
1488 (void)right;
1489 }
1490 }
1491};
1492
1493} // namespace allocation_aware_details
1494
1496 enum : size_t {
1501 };
1502
1503 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1504 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1505 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1506 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1507 return (value + pettiness_threshold - 1) & pettiness_mask;
1508 }
1509
1510 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1511 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1512 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1513
1514 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1515 return inplace;
1516
1517 if (wanna > current)
1518 /* doubling capacity, but don't made reserve more than max_reserve */
1519 return round(wanna + ::std::min(size_t(max_reserve), current));
1520
1521 if (current - wanna >
1522 /* shrink if reserve will more than half of current or max_reserve,
1523 * but not less than pettiness_threshold */
1524 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1525 return round(wanna);
1526
1527 /* keep unchanged */
1528 return current;
1529 }
1530};
1531
1533struct buffer_tag {};
1534
1536template <class ALLOCATOR, typename CAPACITY_POLICY>
1538public:
1540#if !defined(_MSC_VER) || _MSC_VER > 1900
1541 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1542#else
1543 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1544#endif /* MSVC is mad */
1545 using allocator_traits = ::std::allocator_traits<allocator_type>;
1546 using reservation_policy = CAPACITY_POLICY;
1547 enum : size_t {
1549 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1552 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1553 ? alignof(max_align_t) * 2
1556 };
1557
1558private:
1559 friend class txn;
1560 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1561 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1562 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1563
1564 using allocator_pointer = typename allocator_traits::pointer;
1565 using allocator_const_pointer = typename allocator_traits::const_pointer;
1566
1567 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1568 MDBX_INLINE_API_ASSERT(bytes >= sizeof(bin));
1569 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1570 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1571 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1572 const size_t n = (bytes + unit - 1) / unit;
1573 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1574 }
1575
1576 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1577 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1578 MDBX_INLINE_API_ASSERT(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1579 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1580 }
1581
1582 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1583 const size_t capacity = bin::advise_capacity(0, bytes);
1584 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1585 : allocate_storage(capacity);
1586 }
1587
1588 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1589#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1590 return static_cast<void *>(::std::to_address(ptr));
1591#else
1592 return static_cast<void *>(::std::addressof(*ptr));
1593#endif /* __cpp_lib_to_address */
1594 }
1595
1596 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1597#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1598 return static_cast<const void *>(::std::to_address(ptr));
1599#else
1600 return static_cast<const void *>(::std::addressof(*ptr));
1601#endif /* __cpp_lib_to_address */
1602 }
1603
1604#ifdef _MSC_VER
1605#pragma warning(push)
1606#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1607#endif /* _MSC_VER */
1608
1609 union alignas(max_align_t) bin {
1610 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1611 с учетом выравнивания */
1612 {
1613 allocator_pointer stub_ptr_;
1615 };
1616
1618 enum : size_t {
1620 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1624 };
1625
1627 byte pad_[inplace_size - sizeof(allocator_pointer)];
1628 size_t bytes_;
1629 };
1630
1632 byte buffer_[inplace_size - sizeof(byte)];
1635 };
1636
1637 allocator_pointer allocated_ptr_;
1640
1641 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1642 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1643 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1644 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1645 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1646 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1647 return capacity_bytes <= inplace_capacity();
1648 }
1649
1650 constexpr bool is_inplace() const noexcept {
1651 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1652 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1654 "WTF?");
1655 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1656 }
1657 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1658
1659 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1660 if (destroy_ptr) {
1662 /* properly destroy allocator::pointer */
1663 allocated_ptr_.~allocator_pointer();
1664 }
1667 return address();
1668 }
1669
1670 template <bool construct_ptr>
1671 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1673 if (construct_ptr) {
1675 new (&allocated_ptr_) allocator_pointer(pair.first);
1676 } else {
1678 allocated_ptr_ = pair.first;
1679 }
1680 capacity_.bytes_ = pair.second;
1681 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1682 return address();
1683 }
1684
1686 if (::std::is_trivial<allocator_pointer>::value)
1687 /* workaround for "uninitialized" warning from some compilers */
1688 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1689 }
1690
1691 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1692 if (MDBX_UNLIKELY(wanna > max_capacity))
1693 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1694
1695 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1696 MDBX_INLINE_API_ASSERT(advised >= wanna);
1697 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1698 }
1699
1700 constexpr bool is_inplace(const void *ptr) const noexcept {
1701 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1702 }
1703
1704 constexpr const byte *address() const noexcept {
1705 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1706 }
1708 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1709 }
1710 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1711 } bin_;
1712
1713#ifdef _MSC_VER
1714#pragma warning(pop)
1715#endif /* _MSC_VER */
1716
1717 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1718
1719 MDBX_CXX20_CONSTEXPR void release() noexcept {
1720 if (bin_.is_allocated()) {
1721 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1722 /* properly destroy allocator::pointer */
1723 bin_.allocated_ptr_.~allocator_pointer();
1724 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1725 }
1726 }
1727
1728 template <bool external_content>
1729 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1730 const void *const content, const size_t length) {
1731 MDBX_INLINE_API_ASSERT(wanna_capacity >= wanna_headroom + length);
1732 const size_t old_capacity = bin_.capacity();
1733 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1734 if (MDBX_LIKELY(new_capacity == old_capacity))
1736 MDBX_INLINE_API_ASSERT(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1737 byte *const new_place = bin_.address() + wanna_headroom;
1738 if (MDBX_LIKELY(length))
1740 if (external_content)
1741 memcpy(new_place, content, length);
1742 else {
1743 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1744 MDBX_INLINE_API_ASSERT(old_capacity >= old_headroom + length);
1745 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1746 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1747 }
1748 }
1749 return new_place;
1750 }
1751
1752 if (bin::is_suitable_for_inplace(new_capacity)) {
1753 MDBX_INLINE_API_ASSERT(bin_.is_allocated());
1754 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1755 /* coverity[USE_AFTER_MOVE] */
1756 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1757 if (MDBX_LIKELY(length))
1758 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1759 deallocate_storage(old_allocated, old_capacity);
1760 return new_place;
1761 }
1762
1763 if (bin_.is_inplace()) {
1764 const auto pair = allocate_storage(new_capacity);
1765 MDBX_INLINE_API_ASSERT(pair.second >= new_capacity);
1766 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1767 if (MDBX_LIKELY(length))
1768 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1769 bin_.template make_allocated<true>(pair);
1770 return new_place;
1771 }
1772
1773 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1774 if (external_content)
1775 deallocate_storage(old_allocated, old_capacity);
1776 const auto pair = allocate_storage(new_capacity);
1777 MDBX_INLINE_API_ASSERT(pair.second >= new_capacity);
1778 byte *const new_place = bin_.template make_allocated<false>(pair) + wanna_headroom;
1779 if (MDBX_LIKELY(length))
1780 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1781 if (!external_content)
1782 deallocate_storage(old_allocated, old_capacity);
1783 return new_place;
1784 }
1785
1786 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1787 MDBX_INLINE_API_ASSERT(capacity() >= offset);
1788 return bin_.address() + offset;
1789 }
1790 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1791 MDBX_INLINE_API_ASSERT(capacity() >= offset);
1792 return bin_.address() + offset;
1793 }
1794 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1795 MDBX_INLINE_API_ASSERT(capacity() >= offset + length);
1796 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1797 }
1798
1799 //--------------------------------------------------------------------------
1800
1801 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1802 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1803 if (!bin::is_suitable_for_inplace(capacity))
1804 bin_.template make_allocated<true>(provide_storage(capacity));
1805 }
1806
1807 silo(silo &&other) = delete;
1809 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1810 : allocator_type(::std::move(other.get_allocator())) {
1811 if (!is_reference) {
1812 if (other.bin_.is_inplace()) {
1813 memcpy(&bin_, &other.bin_, sizeof(bin));
1814 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1815 } else {
1816 /* coverity[USE_AFTER_MOVE] */
1817 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1818 /* coverity[USE_AFTER_MOVE] */
1819 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1820 /* properly destroy allocator::pointer.
1821 *
1822 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1823 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1824 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1825 * from the 11th). */
1826 /* coverity[USE_AFTER_MOVE] */
1827 other.bin_.allocated_ptr_.~allocator_pointer();
1828 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1829 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1830 }
1831 }
1832 }
1833
1834 MDBX_CXX17_CONSTEXPR bool move(silo &&other) noexcept {
1835 if (other.bin_.is_inplace()) {
1836 memcpy(&bin_, &other.bin_, sizeof(bin));
1837 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1838 return /* buffer's slice fixup is needed */ true;
1839 }
1840 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1841 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1842 /* properly destroy allocator::pointer.
1843 *
1844 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1845 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1846 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1847 * from the 11th). */
1848 /* coverity[use_after_move] */
1849 other.bin_.allocated_ptr_.~allocator_pointer();
1850 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1851 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1852 return false;
1853 }
1854
1855 MDBX_CXX17_CONSTEXPR bool assign_move(silo &&other, bool is_reference) noexcept {
1856 release();
1857 if (allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, other))
1858 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, other);
1859 return is_reference ? false : move(std::move(other));
1860 }
1861
1862 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1863 exchange(silo &left, const bool left_is_reference, silo &right, const bool right_is_reference) noexcept(
1864 allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1865 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(left, right);
1866 bool left_need_fixup = false, right_need_fixup = false;
1867 if (left_is_reference || right_is_reference) {
1868 left_need_fixup = !right_is_reference && left.move(std::move(right));
1869 right_need_fixup = !left_is_reference && right.move(std::move(left));
1870 } else {
1871 silo temp(std::move(left), false);
1872 left_need_fixup = left.move(std::move(right));
1873 right_need_fixup = right.move(std::move(temp));
1874 }
1875 return std::make_pair(left_need_fixup, right_need_fixup);
1876 }
1877
1878 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1879 const allocator_type &alloc = allocator_type())
1880 : silo(capacity, alloc) {
1881 MDBX_INLINE_API_ASSERT(capacity >= headroom + length);
1882 if (length)
1883 put(headroom, ptr, length);
1884 }
1885
1886 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1887 : silo(length, 0, ptr, length, alloc) {}
1888
1889 ~silo() { release(); }
1890
1891 //--------------------------------------------------------------------------
1892
1893 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1894 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1895 }
1896
1897 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1898
1899 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1900 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1901 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1902 }
1903
1904 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1905 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1906 }
1907
1908 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1909 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1910 return get(offset);
1911 }
1912 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1913 };
1914
1915 MDBX_CXX14_CONSTEXPR void fixup_import(const typename silo::bin &src) noexcept {
1916 auto ptr = inherited::byte_ptr();
1917 if (src.is_inplace(ptr)) {
1918 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1919 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1920 iov_base = ptr + offset;
1921 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1922 }
1923 }
1924
1925 silo silo_;
1926
1927 void insulate() {
1928 MDBX_INLINE_API_ASSERT(is_reference());
1929 iov_base = silo_.assign(iov_base, iov_len);
1930 }
1931
1932 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1933 return static_cast<const byte *>(silo_.data());
1934 }
1935
1936 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1937 return silo_begin() + silo_.capacity();
1938 }
1939
1940 struct data_preserver : public exception_thunk {
1941 buffer data;
1942 data_preserver(allocator_type &alloc) : data(alloc) {}
1943 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1944 auto self = static_cast<data_preserver *>(context);
1945 assert(self->is_clean());
1946 assert(&self->data == target);
1947 (void)target;
1948 try {
1949 self->data.assign(src, bytes, false);
1950 return MDBX_RESULT_FALSE;
1951 } catch (... /* capture any exception to rethrow it over C code */) {
1952 self->capture();
1953 return MDBX_RESULT_TRUE;
1954 }
1955 }
1956 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1957 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1958 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1959 };
1960
1961public:
1964
1968
1969 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1970
1972 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1973
1977 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1978 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1979 }
1980
1985 return silo_.is_inplace(inherited::data());
1986 }
1987
1991
1994 return is_freestanding() ? silo_.capacity() : 0;
1995 }
1996
2000 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
2001 }
2002
2006 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2007 }
2008
2010 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2011
2013 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2014
2021
2026 return const_cast<byte *>(inherited::end_byte_ptr());
2027 }
2028
2030 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2031
2033 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2034
2039 return const_cast<char *>(inherited::char_ptr());
2040 }
2041
2046 return const_cast<char *>(inherited::end_char_ptr());
2047 }
2048
2050 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
2051
2053 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
2054
2057 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2059 return const_cast<void *>(inherited::data());
2060 }
2061
2064 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2066 return const_cast<void *>(inherited::end());
2067 }
2068
2073
2080
2083 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2084 return set_length(static_cast<const char *>(ptr) - char_ptr());
2085 }
2086
2091 if (is_reference())
2092 insulate();
2093 }
2094
2095 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2096 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2097 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2098 const allocator_type &alloc = allocator_type());
2099
2101 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2102 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2103
2104 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2105 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2106
2107 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2108 : buffer(inherited(c_str), make_reference, alloc) {}
2109
2110#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2111 template <class CHAR, class T>
2112 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2113 const allocator_type &alloc = allocator_type())
2114 : buffer(inherited(view), make_reference, alloc) {}
2115#endif /* __cpp_lib_string_view >= 201606L */
2116
2118 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2119 : buffer(src, src.empty() || src.is_null(), alloc) {}
2120
2122 buffer(const buffer &src)
2123 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2124
2126 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2127 : buffer(inherited(ptr, bytes), alloc) {}
2128
2129 template <class CHAR, class T, class A>
2130 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2131 const allocator_type &alloc = allocator_type())
2132 : buffer(inherited(str), alloc) {}
2133
2135 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2136
2137#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2138 template <class CHAR, class T>
2139 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2140 const allocator_type &alloc = allocator_type())
2141 : buffer(inherited(view), alloc) {}
2142#endif /* __cpp_lib_string_view >= 201606L */
2143
2144 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2145 : silo_(check_length(head_room, tail_room), alloc) {
2146 iov_base = silo_.get();
2147 MDBX_INLINE_API_ASSERT(iov_len == 0);
2148 }
2149
2150 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2151 iov_base = silo_.get();
2152 MDBX_INLINE_API_ASSERT(iov_len == 0);
2153 }
2154
2155 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2156 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2157 iov_base = memcpy(silo_.get(), src.data(), iov_len = src.length());
2158 }
2159
2160 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2161
2162 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2163 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2164 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2165 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2166 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2167 * 11th). */
2168 /* coverity[USE_AFTER_MOVE] */
2169 fixup_import(src.silo_.bin_);
2170 src.invalidate();
2171 }
2172
2174 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2175
2178
2179 template <typename POD>
2180 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2181 return buffer(inherited::wrap(pod), make_reference, alloc);
2182 }
2183
2185 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2186 const allocator_type &alloc = allocator_type()) {
2187 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2188 }
2189
2192 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2193 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2194 }
2195
2197 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2198 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2199 }
2200
2202 template <typename POD>
2203 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2204 const allocator_type &alloc = allocator_type()) {
2205 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2206 }
2207
2210 template <typename POD>
2211 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2212 return base58(inherited::wrap(pod), wrap_width, alloc);
2213 }
2214
2217 template <typename POD>
2218 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2219 return base64(inherited::wrap(pod), wrap_width, alloc);
2220 }
2221
2223 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2224 const allocator_type &alloc = allocator_type()) const {
2225 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2226 }
2227
2230 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2231 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2232 }
2233
2235 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2236 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2237 }
2238
2240 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2241 const allocator_type &alloc = allocator_type()) {
2242 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2243 }
2244
2247 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2248 const allocator_type &alloc = allocator_type()) {
2249 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2250 }
2251
2254 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2255 const allocator_type &alloc = allocator_type()) {
2256 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2257 }
2258
2261 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2262 return hex_decode(*this, ignore_spaces, alloc);
2263 }
2264
2267 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2268 return base58_decode(*this, ignore_spaces, alloc);
2269 }
2270
2273 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2274 return base64_decode(*this, ignore_spaces, alloc);
2275 }
2276
2278 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2279 wanna_headroom = ::std::min(
2280 ::std::max(headroom(), wanna_headroom),
2281 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2282 wanna_tailroom = ::std::min(
2283 ::std::max(tailroom(), wanna_tailroom),
2284 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2285 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2286 silo_.resize(wanna_capacity, wanna_headroom, *this);
2287 MDBX_INLINE_API_ASSERT(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2288 MDBX_INLINE_API_ASSERT(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2289 }
2290
2292 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2293
2295 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2296
2297 buffer &assign_reference(const void *ptr, size_t bytes) {
2298 silo_.clear();
2300 return *this;
2301 }
2302
2303 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2304 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2305 return *this;
2306 }
2307
2308 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2309 const auto pair = silo::exchange(silo_, is_reference(), other.silo_, other.is_reference());
2310 std::swap(iov_base, other.iov_base);
2311 std::swap(iov_len, other.iov_len);
2312 if (pair.first)
2313 fixup_import(other.silo_.bin_);
2314 if (pair.second)
2315 other.fixup_import(silo_.bin_);
2316 }
2317
2318 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2319 left.swap(right);
2320 }
2321
2322 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2323 return buffer(src.headroom(), src, src.tailroom(), alloc);
2324 }
2325
2327 return buffer(static_cast<const struct slice &>(*this), !is_inplace(),
2328 allocator_traits::select_on_container_copy_construction(get_allocator()));
2329 }
2330
2332 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2333 if (MDBX_LIKELY(this != &src)) {
2334 invalidate();
2335 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2336 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2337 MDBX_CXX20_UNLIKELY {
2338 silo_.release();
2340 }
2341 }
2342
2343 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2344 iov_len = src.length();
2345 } else {
2346 iov_base = silo_.template reshape<false>(whole_capacity, headroom, src.data(), src.length());
2347 }
2348 return *this;
2349 }
2350
2351 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2352 if (MDBX_LIKELY(this != &src)) {
2353 invalidate();
2354 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2355 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2356 MDBX_CXX20_UNLIKELY {
2357 silo_.release();
2359 }
2360 }
2361
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 } else if (!make_reference && is_reference())
2370 insulate();
2371 return *this;
2372 }
2373
2376 if (MDBX_LIKELY(this != &src)) {
2377 const bool is_reference = src.is_reference();
2378 inherited::assign(std::move(src));
2379 if (silo_.assign_move(std::move(src.silo_), is_reference))
2380 fixup_import(src.silo_.bin_);
2381 }
2382 return *this;
2383 }
2384
2385 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2386 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2387 }
2388
2389 buffer &assign(const struct slice &src, bool make_reference = false) {
2390 return assign(src.data(), src.length(), make_reference);
2391 }
2392
2393 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2394 return assign(src.iov_base, src.iov_len, make_reference);
2395 }
2396
2397 buffer &assign(struct slice &&src, bool make_reference = false) {
2398 assign(src.data(), src.length(), make_reference);
2399 src.invalidate();
2400 return *this;
2401 }
2402
2403 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2404 assign(src.iov_base, src.iov_len, make_reference);
2405 src.iov_base = nullptr;
2406 return *this;
2407 }
2408
2409 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2410 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2411 }
2412
2413 template <class CHAR, class T, class A>
2414 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2415 return assign(str.data(), str.length(), make_reference);
2416 }
2417
2418 buffer &assign(const char *c_str, bool make_reference = false) {
2419 return assign(c_str, strlen(c_str), make_reference);
2420 }
2421
2422#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2423 template <class CHAR, class T>
2424 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2425 return assign(view.data(), view.length(), make_reference);
2426 }
2427
2428 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2429 assign(view.data(), view.length(), make_reference);
2430 view = {};
2431 return *this;
2432 }
2433#endif /* __cpp_lib_string_view >= 201606L */
2434
2435 buffer &operator=(const buffer &src) { return assign(src); }
2436
2437 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2438
2439 buffer &operator=(const struct slice &src) { return assign(src); }
2440
2441 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2442
2443#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2444 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2445 return assign(view.begin(), view.length());
2446 }
2447
2448 template <class CHAR, class T> buffer &append(const ::std::basic_string_view<CHAR, T> &view) {
2449 return append(view.data(), view.size());
2450 }
2451#endif /* __cpp_lib_string_view >= 201606L */
2452
2453 template <class CHAR, class T, class A>
2454 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2455 return as_string<CHAR, T, A>();
2456 }
2457
2458 template <class CHAR, class T, class A> buffer &append(const ::std::basic_string<CHAR, T, A> &str) {
2459 return append(str.data(), str.size());
2460 }
2461
2463 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2464
2466 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2467 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2468 }
2469
2471 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2472
2473 buffer &append(const void *src, size_t bytes) {
2474 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2475 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2476 memcpy(end_byte_ptr(), src, bytes);
2477 iov_len += bytes;
2478 return *this;
2479 }
2480
2481 buffer &append(const byte c) {
2482 if (MDBX_UNLIKELY(tailroom() < 1))
2483 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2484 *end_byte_ptr() = c;
2485 iov_len += 1;
2486 return *this;
2487 }
2488
2489 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2490
2491 buffer &add_header(const void *src, size_t bytes) {
2492 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2493 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2494 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2495 iov_len += bytes;
2496 return *this;
2497 }
2498
2499 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2500
2501 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2502 const size_t wanna_bytes = producer.envisage_result_length();
2503 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2504 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2505 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2506 }
2507
2508 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2509 const size_t wanna_bytes = producer.envisage_result_length();
2510 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2511 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2512 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2513 }
2514
2515 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2516 return append_producer(to_hex(data, uppercase, wrap_width));
2517 }
2518
2519 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2520 return append_producer(to_base58(data, wrap_width));
2521 }
2522
2523 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2524 return append_producer(to_base64(data, wrap_width));
2525 }
2526
2527 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2528 return append_producer(from_hex(data, ignore_spaces));
2529 }
2530
2531 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2532 return append_producer(from_base58(data, ignore_spaces));
2533 }
2534
2535 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2536 return append_producer(from_base64(data, ignore_spaces));
2537 }
2538
2539 buffer &append_u8(uint_fast8_t u8) {
2540 if (MDBX_UNLIKELY(tailroom() < 1))
2541 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2542 *end_byte_ptr() = uint8_t(u8);
2543 iov_len += 1;
2544 return *this;
2545 }
2546
2547 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2548
2549 buffer &append_u16(uint_fast16_t u16) {
2550 if (MDBX_UNLIKELY(tailroom() < 2))
2551 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2552 const auto ptr = end_byte_ptr();
2553 ptr[0] = uint8_t(u16);
2554 ptr[1] = uint8_t(u16 >> 8);
2555 iov_len += 2;
2556 return *this;
2557 }
2558
2559 buffer &append_u24(uint_fast32_t u24) {
2560 if (MDBX_UNLIKELY(tailroom() < 3))
2561 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2562 const auto ptr = end_byte_ptr();
2563 ptr[0] = uint8_t(u24);
2564 ptr[1] = uint8_t(u24 >> 8);
2565 ptr[2] = uint8_t(u24 >> 16);
2566 iov_len += 3;
2567 return *this;
2568 }
2569
2570 buffer &append_u32(uint_fast32_t u32) {
2571 if (MDBX_UNLIKELY(tailroom() < 4))
2572 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2573 const auto ptr = end_byte_ptr();
2574 ptr[0] = uint8_t(u32);
2575 ptr[1] = uint8_t(u32 >> 8);
2576 ptr[2] = uint8_t(u32 >> 16);
2577 ptr[3] = uint8_t(u32 >> 24);
2578 iov_len += 4;
2579 return *this;
2580 }
2581
2582 buffer &append_u48(uint_fast64_t u48) {
2583 if (MDBX_UNLIKELY(tailroom() < 6))
2584 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2585 const auto ptr = end_byte_ptr();
2586 ptr[0] = uint8_t(u48);
2587 ptr[1] = uint8_t(u48 >> 8);
2588 ptr[2] = uint8_t(u48 >> 16);
2589 ptr[3] = uint8_t(u48 >> 24);
2590 ptr[4] = uint8_t(u48 >> 32);
2591 ptr[5] = uint8_t(u48 >> 40);
2592 iov_len += 6;
2593 return *this;
2594 }
2595
2596 buffer &append_u64(uint_fast64_t u64) {
2597 if (MDBX_UNLIKELY(tailroom() < 8))
2598 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2599 const auto ptr = end_byte_ptr();
2600 ptr[0] = uint8_t(u64);
2601 ptr[1] = uint8_t(u64 >> 8);
2602 ptr[2] = uint8_t(u64 >> 16);
2603 ptr[3] = uint8_t(u64 >> 24);
2604 ptr[4] = uint8_t(u64 >> 32);
2605 ptr[5] = uint8_t(u64 >> 40);
2606 ptr[6] = uint8_t(u64 >> 48);
2607 ptr[7] = uint8_t(u64 >> 56);
2608 iov_len += 8;
2609 return *this;
2610 }
2611
2612 //----------------------------------------------------------------------------
2613
2614 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2615 return buffer(inherited(text), make_reference);
2616 }
2617
2618#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2619 template <class CHAR, class T>
2620 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2621 return buffer(src, make_reference);
2622 }
2623#endif /* __cpp_lib_string_view >= 201606L */
2624
2625 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2626
2627 template <class CHAR, class T, class A>
2628 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2629 return buffer(src, make_reference);
2630 }
2631
2632 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2633
2634 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2635
2636 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2637
2638 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2639
2640 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2641
2642 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2643
2644 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2645
2646 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2647
2648 static buffer key_from_jsonInteger(const int64_t json_integer) {
2649 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2650 }
2651
2652 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2653
2654 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2655
2656 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2657
2658 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2659
2660 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2661
2662 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2663
2664 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2665
2666 const slice &slice() const noexcept { return *this; }
2667};
2668
2669template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2673 using reservation_policy = CAPACITY_POLICY;
2674 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2676
2679 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2680
2682 : key(key, alloc), value(value, alloc) {}
2683 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2684 const allocator_type &alloc = allocator_type())
2685 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2686
2688 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2689 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2690 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2691
2693 : key(key, alloc), value(value, alloc) {}
2694 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2695 const allocator_type &alloc = allocator_type())
2696 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2697
2700 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2701 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2702
2703 buffer_pair_spec(const txn &transaction, const slice &key, const slice &value,
2704 const allocator_type &alloc = allocator_type())
2705 : key(transaction, key, alloc), value(transaction, value, alloc) {}
2706 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2707 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2708
2709 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2710 : key(::std::move(key)), value(::std::move(value)) {}
2712 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2713 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2714
2717 key.assign(std::move(src.key));
2718 value.assign(std::move(src.value));
2719 return *this;
2720 }
2721
2723 key.assign(src.key);
2724 value.assign(src.value);
2725 return *this;
2726 }
2728 key.assign(std::move(src.key));
2729 value.assign(std::move(src.value));
2730 return *this;
2731 }
2733 key.assign(src.first);
2734 value.assign(src.second);
2735 return *this;
2736 }
2738 key.assign(std::move(src.first));
2739 value.assign(std::move(src.second));
2740 return *this;
2741 }
2742
2746 return key.is_freestanding() && value.is_freestanding();
2747 }
2748
2751 return key.is_reference() || value.is_reference();
2752 }
2753
2757 key.make_freestanding();
2758 value.make_freestanding();
2759 }
2760
2761 operator pair() const noexcept { return pair(key, value); }
2762};
2763
2765
2768public:
2769 cache_entry() noexcept { reset(); }
2770 cache_entry(const cache_entry &) noexcept = default;
2771 cache_entry &operator=(const cache_entry &) noexcept = default;
2772 cache_entry(cache_entry &&other) noexcept {
2773 *this = other;
2774 other.reset();
2775 }
2776 void reset() noexcept { mdbx_cache_init(this); }
2777 MDBX_CXX20_CONSTEXPR cache_entry(const MDBX_cache_entry_t &ce) noexcept { mdbx::memcpy(this, &ce, sizeof(*this)); }
2779 mdbx::memcpy(this, &ce, sizeof(*this));
2780 return *this;
2781 };
2782};
2783
2784//------------------------------------------------------------------------------
2785
2788enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2789
2806
2808 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2809}
2810
2812 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2813}
2814
2816 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2817}
2818
2820 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2821}
2822
2824
2882
2886
2888 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2889}
2890
2892 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2893}
2894
2896 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2897}
2898
2900 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2901}
2902
2904
2915 map_handle(const map_handle &) noexcept = default;
2916 map_handle &operator=(const map_handle &) noexcept = default;
2917 operator bool() const noexcept { return dbi != 0; }
2918 operator MDBX_dbi() const { return dbi; }
2919
2920#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2921 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2922 return a.dbi <=> b.dbi;
2923 }
2924#endif /* __cpp_impl_three_way_comparison */
2925 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2926 return a.dbi == b.dbi;
2927 }
2928 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2929 return a.dbi < b.dbi;
2930 }
2931 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2932 return a.dbi > b.dbi;
2933 }
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
2955};
2956
2959 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2960}
2962 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2963}
2964
2971
2980 friend class txn;
2981
2982protected:
2984 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2985
2986public:
2987 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2988 env(const env &) noexcept = default;
2989 env &operator=(const env &) noexcept = default;
2990 inline env &operator=(env &&) noexcept;
2991 inline env(env &&) noexcept;
2992 inline ~env() noexcept;
2993
2994 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
2995 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const noexcept { return handle_; }
2996 MDBX_CXX14_CONSTEXPR operator MDBX_env *() noexcept { return handle_; }
2997 MDBX_CXX14_CONSTEXPR const MDBX_env *handle() const noexcept { return handle_; }
2999 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
3000 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
3001
3002 //----------------------------------------------------------------------------
3003
3008
3010 enum : intptr_t {
3013 maximal_value = INTPTR_MAX,
3014 kB = 1000,
3015 MB = kB * 1000,
3016 GB = MB * 1000,
3017#if INTPTR_MAX > 0x7fffFFFFl
3018 TB = GB * 1000,
3019 PB = TB * 1000,
3020 EB = PB * 1000,
3021#endif /* 64-bit intptr_t */
3022 KiB = 1024,
3023 MiB = KiB << 10,
3024 GiB = MiB << 10,
3025#if INTPTR_MAX > 0x7fffFFFFl
3026 TiB = GiB << 10,
3027 PiB = TiB << 10,
3028 EiB = PiB << 10,
3029#endif /* 64-bit intptr_t */
3030 };
3031
3033 struct size {
3034 intptr_t bytes;
3035 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3036 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3037 };
3038
3041
3046
3058
3061
3064
3070
3071 inline geometry &make_fixed(intptr_t size) noexcept;
3072 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3075 geometry(const geometry &) noexcept = default;
3081 };
3082
3090
3098
3109
3131
3136 unsigned max_maps{0};
3139 unsigned max_readers{0};
3144
3155 operate_parameters(const operate_parameters &) noexcept = default;
3157 MDBX_env_flags_t make_flags(bool accede = true,
3160 bool use_subdirectory = false
3161 ) const;
3165 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3166 };
3167
3171 inline env::mode get_mode() const;
3173 inline env::durability get_durability() const;
3177 inline env::operate_options get_options() const;
3178
3181 bool is_pristine() const;
3182
3184 bool is_empty() const;
3185
3187 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3188
3189 struct limits {
3190 limits() = delete;
3192 static inline size_t pagesize_min() noexcept;
3194 static inline size_t pagesize_max() noexcept;
3196 static inline size_t dbsize_min(intptr_t pagesize);
3198 static inline size_t dbsize_max(intptr_t pagesize);
3200 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3202 static inline size_t key_min(key_mode mode) noexcept;
3204 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3206 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3208 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3210 static inline size_t key_max(const env &, key_mode mode);
3212 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3214 static inline size_t value_min(value_mode) noexcept;
3215
3217 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3219 static inline size_t value_max(intptr_t pagesize, value_mode);
3221 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3223 static inline size_t value_max(const env &, value_mode);
3224
3227 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3230 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3233 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3236 static inline size_t pairsize4page_max(const env &, value_mode);
3237
3240 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3243 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3246 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3249 static inline size_t valsize4page_max(const env &, value_mode);
3250
3253 static inline size_t transaction_size_max(intptr_t pagesize);
3254
3256 static inline size_t max_map_handles(void);
3257 };
3258
3260 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3262 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3264 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3266 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3268 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3270 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3274
3277#ifdef MDBX_STD_FILESYSTEM_PATH
3278 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3279#endif /* MDBX_STD_FILESYSTEM_PATH */
3280#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3281 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3282 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3283#endif /* Windows */
3284 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3285 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3286
3288 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3289
3305
3307#ifdef MDBX_STD_FILESYSTEM_PATH
3308 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3309#endif /* MDBX_STD_FILESYSTEM_PATH */
3310#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3311 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3312 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3313#endif /* Windows */
3314 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3315 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3316
3319
3322
3324 inline stat get_stat() const;
3325
3327 size_t get_pagesize() const { return get_stat().ms_psize; }
3328
3330 inline info get_info() const;
3331
3333 inline stat get_stat(const txn &) const;
3334
3336 inline info get_info(const txn &) const;
3337
3339 inline filehandle get_filehandle() const;
3340
3342 const path_char *get_path() const;
3343
3345 inline MDBX_env_flags_t get_flags() const;
3346
3347 inline bool is_readonly() const { return (get_flags() & MDBX_RDONLY) != 0; }
3348
3349 inline bool is_exclusive() const { return (get_flags() & MDBX_EXCLUSIVE) != 0; }
3350
3351 inline bool is_cooperative() const { return !is_exclusive(); }
3352
3353 inline bool is_writemap() const { return (get_flags() & MDBX_WRITEMAP) != 0; }
3354
3355 inline bool is_readwrite() const { return !is_readonly(); }
3356
3357 inline bool is_nested_transactions_available() const { return (get_flags() & (MDBX_WRITEMAP | MDBX_RDONLY)) == 0; }
3358
3361 inline unsigned max_readers() const;
3362
3365 inline unsigned max_maps() const;
3366
3368 inline void *get_context() const noexcept;
3369
3371 inline env &set_context(void *your_context);
3372
3387 inline env &set_sync_threshold(size_t bytes);
3388
3394 inline size_t sync_threshold() const;
3395
3396#if __cplusplus >= 201103L || defined(DOXYGEN)
3416 inline env &set_sync_period(const duration &period);
3417
3423 inline duration sync_period() const;
3424#endif
3425
3429 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3430
3433 inline unsigned sync_period__seconds_16dot16() const;
3434
3438 inline env &set_sync_period__seconds_double(double seconds);
3439
3442 inline double sync_period__seconds_double() const;
3443
3495
3497 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3498
3500 inline uint64_t extra_option(extra_runtime_option option) const;
3501
3503 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3504
3506 inline env &set_geometry(const geometry &size);
3507
3511 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3512
3516 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3517
3536 inline void close_map(const map_handle &);
3537
3540 int slot;
3549 size_t bytes_used;
3558
3560 size_t used, size_t retained) noexcept;
3561 };
3562
3570 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3571
3574 inline unsigned check_readers();
3575
3594
3599 inline MDBX_hsr_func get_HandleSlowReaders() const noexcept;
3600
3602 inline txn_managed start_read() const;
3603
3605 inline txn_managed prepare_read() const;
3606
3608 inline txn_managed start_write(txn &parent);
3609
3611 inline txn_managed start_write(bool dont_wait = false);
3612
3615};
3616
3625class LIBMDBX_API_TYPE env_managed : public env {
3626 using inherited = env;
3628 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3629 void setup(unsigned max_maps, unsigned max_readers = 0);
3630
3631public:
3632 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3633
3635#ifdef MDBX_STD_FILESYSTEM_PATH
3636 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3637#endif /* MDBX_STD_FILESYSTEM_PATH */
3638#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3639 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3640 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3641#endif /* Windows */
3642 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3643 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3644
3655
3657#ifdef MDBX_STD_FILESYSTEM_PATH
3659 bool accede = true);
3660#endif /* MDBX_STD_FILESYSTEM_PATH */
3661#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3662 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3663 bool accede = true);
3664 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3665 bool accede = true);
3666#endif /* Windows */
3667 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3668 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3669
3683 void close(bool dont_sync = false);
3684
3685 env_managed(env_managed &&) = default;
3686 env_managed &operator=(env_managed &&other) noexcept;
3687 env_managed(const env_managed &) = delete;
3688 env_managed &operator=(const env_managed &) = delete;
3689 virtual ~env_managed();
3690};
3691
3700protected:
3701 friend class cursor;
3703 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3704
3705public:
3706 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3707 txn(const txn &) noexcept = default;
3708 txn &operator=(const txn &) noexcept = default;
3709 inline txn &operator=(txn &&) noexcept;
3710 inline txn(txn &&) noexcept;
3711 inline ~txn() noexcept;
3712
3713 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
3714 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const noexcept { return handle_; }
3715 MDBX_CXX14_CONSTEXPR operator MDBX_txn *() noexcept { return handle_; }
3716 MDBX_CXX14_CONSTEXPR const MDBX_txn *handle() const noexcept { return handle_; }
3718 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
3719 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
3720
3722 inline ::mdbx::env env() const noexcept;
3724 inline MDBX_txn_flags_t flags() const;
3726 inline uint64_t id() const;
3727
3729 inline void *get_context() const noexcept;
3730
3732 inline txn &set_context(void *your_context);
3733
3735 inline bool is_dirty(const void *ptr) const;
3736
3738 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3739
3741 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3742
3744 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3745
3748 inline info get_info(bool scan_reader_lock_table = false) const;
3749
3752 size_t size_max() const { return env().transaction_size_max(); }
3753
3755 size_t size_current() const {
3756 assert(is_readwrite());
3757 return size_t(get_info().txn_space_dirty);
3758 }
3759
3760 //----------------------------------------------------------------------------
3761
3763 inline void reset_reading();
3764
3766 inline void renew_reading();
3767
3769 inline txn_managed clone(void *context = nullptr) const;
3770
3772 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
3773
3775 inline void make_broken();
3776
3778 inline void park_reading(bool autounpark = true);
3779
3782 inline bool unpark_reading(bool restart_if_ousted = true);
3783
3786
3789
3791 inline cursor_managed open_cursor(map_handle map) const;
3792
3794 inline size_t release_all_cursors(bool unbind) const;
3795
3797 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3798
3800 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3801
3803 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3804 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3806 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3807 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3809 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3810 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3811
3813 inline map_handle open_map_accede(const char *name) const;
3815 inline map_handle open_map_accede(const ::std::string &name) const;
3817 inline map_handle open_map_accede(const slice &name) const;
3818
3820 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3821 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3823 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3824 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3826 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3827 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3828
3830 inline void drop_map(map_handle map);
3834 bool drop_map(const char *name, bool throw_if_absent = false);
3838 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3842 bool drop_map(const slice &name, bool throw_if_absent = false);
3843
3845 inline void clear_map(map_handle map);
3848 bool clear_map(const char *name, bool throw_if_absent = false);
3851 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3854 bool clear_map(const slice &name, bool throw_if_absent = false);
3855
3857 inline void rename_map(map_handle map, const char *new_name);
3859 inline void rename_map(map_handle map, const ::std::string &new_name);
3861 inline void rename_map(map_handle map, const slice &new_name);
3865 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3869 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3873 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3874
3875#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3876
3878 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3879 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3880 return open_map(slice(name), key_mode, value_mode);
3881 }
3882
3883 inline map_handle open_map_accede(const ::std::string_view &name) const;
3885 inline map_handle create_map(const ::std::string_view &name,
3886 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3887 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3888 return create_map(slice(name), key_mode, value_mode);
3889 }
3890
3893 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3894 return drop_map(slice(name), throw_if_absent);
3895 }
3896
3898 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3899 return clear_map(slice(name), throw_if_absent);
3900 }
3901
3902 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3906 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3907 bool throw_if_absent = false) {
3908 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3909 }
3910#endif /* __cpp_lib_string_view >= 201606L */
3911
3914 inline map_stat get_map_stat(map_handle map) const;
3917 inline uint32_t get_tree_deepmask(map_handle map) const;
3919 inline map_handle::info get_map_flags(map_handle map) const;
3920
3923 inline txn &put_canary(const canary &);
3925 inline canary get_canary() const;
3926
3928 inline uint64_t sequence(map_handle map) const;
3930 inline uint64_t sequence(map_handle map, uint64_t increment);
3931
3933 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3935 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3937 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3939 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3940
3942 inline slice get(map_handle map, const slice &key) const;
3944 inline slice get(map_handle map, slice key, size_t &values_count) const;
3946 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3948 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3952 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3956 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3957
3958 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3959 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3960 inline void insert(map_handle map, const slice &key, slice value);
3961 inline value_result try_insert(map_handle map, const slice &key, slice value);
3962 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3963 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3964
3965 inline void upsert(map_handle map, const slice &key, const slice &value);
3966 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3967
3968 inline void update(map_handle map, const slice &key, const slice &value);
3969 inline bool try_update(map_handle map, const slice &key, const slice &value);
3970 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3971 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3972
3973 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3974 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3975 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3976 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3977
3979 inline bool erase(map_handle map, const slice &key);
3980
3982 inline bool erase(map_handle map, const slice &key, const slice &value);
3983
3985 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3986
3988 template <class ALLOCATOR, typename CAPACITY_POLICY>
3990 extract(map_handle map, const slice &key,
3993
3995 template <class ALLOCATOR, typename CAPACITY_POLICY>
3997 replace(map_handle map, const slice &key, const slice &new_value,
4000
4001 template <class ALLOCATOR, typename CAPACITY_POLICY>
4003 replace_reserve(map_handle map, const slice &key, slice &new_value,
4006
4023 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4024 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4025 return append(map, kv.key, kv.value, multivalue_order_preserved);
4026 }
4027
4028 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4029 const void *values_array, size_t values_count, put_mode mode,
4030 bool allow_partial = false);
4031 template <typename VALUE>
4032 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4033 put_mode mode, bool allow_partial = false) {
4034 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4035 !::std::is_array<VALUE>::value,
4036 "Must be a standard layout type!");
4037 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4038 }
4039 template <typename VALUE>
4040 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4041 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4042 }
4043
4044 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4045 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4046 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4047 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4048};
4049
4058class LIBMDBX_API_TYPE txn_managed : public txn {
4059 using inherited = txn;
4060 friend class env;
4061 friend class txn;
4063 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4064
4065public:
4066 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4067 txn_managed(txn_managed &&) = default;
4068 txn_managed &operator=(txn_managed &&other) noexcept;
4069 txn_managed(const txn_managed &) = delete;
4070 txn_managed &operator=(const txn_managed &) = delete;
4071 ~txn_managed();
4072
4073 //----------------------------------------------------------------------------
4075
4077 void abort();
4081 void abort(finalization_latency &latency) { return abort(&latency); }
4085 finalization_latency result;
4086 abort(&result);
4087 return result;
4088 }
4089
4091 void commit();
4095 void commit(finalization_latency &latency) { return commit(&latency); }
4099 finalization_latency result;
4100 commit(&result);
4101 return result;
4102 }
4103
4109 bool checkpoint(finalization_latency &latency) { return checkpoint(&latency); }
4112 std::pair<bool, finalization_latency> checkpoint_get_latency() {
4113 finalization_latency latency;
4114 bool result = checkpoint(&latency);
4115 return std::make_pair(result, latency);
4116 }
4117
4127 finalization_latency result;
4128 commit_embark_read(&result);
4129 return result;
4130 }
4131
4134 bool amend(bool dont_wait = false);
4135};
4136
4144protected:
4146
4147public:
4149 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4150 cursor(const cursor &) noexcept = default;
4151 cursor &operator=(const cursor &) noexcept = default;
4152 inline cursor &operator=(cursor &&) noexcept;
4153 inline cursor(cursor &&) noexcept;
4154 inline ~cursor() noexcept;
4155 cursor_managed clone(void *your_context = nullptr) const;
4156 inline cursor &assign(const cursor &);
4157 MDBX_CXX14_CONSTEXPR operator bool() const noexcept { return handle_ != nullptr; };
4158 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const noexcept { return handle_; }
4159 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *() noexcept { return handle_; }
4160 MDBX_CXX14_CONSTEXPR const MDBX_cursor *handle() const noexcept { return handle_; }
4162 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept {
4163 return a.handle_ == b.handle_;
4164 }
4165 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept {
4166 return a.handle_ != b.handle_;
4167 }
4168
4169 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4170 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4171
4172 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4173 return compare_position(*this, other, ignore_nested) < 0;
4174 }
4175
4176 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4177 return compare_position(*this, other, ignore_nested) <= 0;
4178 }
4179
4180 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4181 return compare_position(*this, other, ignore_nested) == 0;
4182 }
4183
4184 bool is_after_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_after_than(const cursor &other, bool ignore_nested = false) const {
4189 return compare_position(*this, other, ignore_nested) >= 0;
4190 }
4191
4193 inline void *get_context() const noexcept;
4194
4196 inline cursor &set_context(void *your_context);
4197
4204
4211
4214
4218
4219 /* Doubtless cursor positioning at a specified key. */
4225
4226 /* Doubtless cursor positioning at a specified key-value pair
4227 * for dupsort/multi-value hives. */
4233
4240
4245 };
4246
4247 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4248 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4249 // и других параметров в bool-throw_notfound.
4250
4251 struct move_result : public pair_result {
4252 inline move_result(const cursor &cursor, bool throw_notfound);
4253 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4254 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4255 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4256 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4257 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4258 bool throw_notfound);
4259 move_result(const move_result &) noexcept = default;
4260 move_result &operator=(const move_result &) noexcept = default;
4261 };
4262
4263 struct estimate_result : public pair {
4268 : estimate_result(cursor, operation, key, slice::invalid()) {}
4269 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4270 estimate_result(const estimate_result &) noexcept = default;
4271 estimate_result &operator=(const estimate_result &) noexcept = default;
4272 };
4273
4274protected:
4275 /* fake `const`, but for specific move/get operations */
4276 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4277
4278 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4279
4280public:
4281 template <typename CALLABLE_PREDICATE>
4282 bool scan_until(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4283 struct wrapper : public exception_thunk {
4284 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4285 auto thunk = static_cast<wrapper *>(context);
4286 assert(thunk->is_clean());
4287 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4288 try {
4289 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4290 } catch (... /* capture any exception to rethrow it over C code */) {
4291 thunk->capture();
4292 return MDBX_RESULT_TRUE;
4293 }
4294 }
4295 } thunk;
4297 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4298 thunk);
4299 }
4300
4301 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4302 return scan_until(std::move(predicate), backward ? last : first, backward ? previous : next);
4303 }
4304
4305 template <typename CALLABLE_PREDICATE>
4306 bool scan_until_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4307 move_operation turn = next) {
4308 struct wrapper : public exception_thunk {
4309 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4310 auto thunk = static_cast<wrapper *>(context);
4311 assert(thunk->is_clean());
4312 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4313 try {
4314 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4315 } catch (... /* capture any exception to rethrow it over C code */) {
4316 thunk->capture();
4317 return MDBX_RESULT_TRUE;
4318 }
4319 }
4320 } thunk;
4321 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4322 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4323 thunk);
4324 }
4325
4326 template <typename CALLABLE_PREDICATE>
4327 bool scan_until_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4328 move_operation turn = next) {
4329 struct wrapper : public exception_thunk {
4330 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4331 auto thunk = static_cast<wrapper *>(context);
4332 assert(thunk->is_clean());
4333 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4334 try {
4335 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4336 } catch (... /* capture any exception to rethrow it over C code */) {
4337 thunk->capture();
4338 return MDBX_RESULT_TRUE;
4339 }
4340 }
4341 } thunk;
4342 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4343 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4344 thunk);
4345 }
4346
4347 move_result move(move_operation operation, bool throw_notfound) {
4348 return move_result(*this, operation, throw_notfound);
4349 }
4350 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4351 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4352 }
4353 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4354 return move_result(*this, operation, key, value, throw_notfound);
4355 }
4356 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4357 return move(operation, &key, &value, throw_notfound);
4358 }
4359
4360 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4361 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4362 move_result to_previous_last_multi(bool throw_notfound = true) {
4363 return move(multi_prevkey_lastvalue, throw_notfound);
4364 }
4365 move_result to_current_first_multi(bool throw_notfound = true) {
4366 return move(multi_currentkey_firstvalue, throw_notfound);
4367 }
4368 move_result to_current_prev_multi(bool throw_notfound = true) {
4369 return move(multi_currentkey_prevvalue, throw_notfound);
4370 }
4371 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4372 move_result to_current_next_multi(bool throw_notfound = true) {
4373 return move(multi_currentkey_nextvalue, throw_notfound);
4374 }
4375 move_result to_current_last_multi(bool throw_notfound = true) {
4376 return move(multi_currentkey_lastvalue, throw_notfound);
4377 }
4378 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4379 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4380 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4381
4382 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4383 return move(key_lesser_than, key, throw_notfound);
4384 }
4385 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4386 return move(key_lesser_or_equal, key, throw_notfound);
4387 }
4388 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4389 return move(key_equal, key, throw_notfound);
4390 }
4391 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4392 return move(key_exact, key, throw_notfound);
4393 }
4394 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4395 return move(key_greater_or_equal, key, throw_notfound);
4396 }
4397 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4398 return move(key_greater_than, key, throw_notfound);
4399 }
4400
4401 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4402 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4403 }
4404 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4405 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4406 }
4407 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4408 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4409 }
4410 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4411 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4412 }
4413 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4414 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4415 }
4416
4417 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4418 return move(pair_lesser_than, key, value, throw_notfound);
4419 }
4420 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4421 return move(pair_lesser_or_equal, key, value, throw_notfound);
4422 }
4423 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4424 return move(pair_equal, key, value, throw_notfound);
4425 }
4426 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4427 return move(pair_exact, key, value, throw_notfound);
4428 }
4429 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4430 return move(pair_greater_or_equal, key, value, throw_notfound);
4431 }
4432 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4433 return move(pair_greater_than, key, value, throw_notfound);
4434 }
4435
4436 inline bool seek(const slice &key);
4437 inline move_result find(const slice &key, bool throw_notfound = true);
4438 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4439 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4440
4442 inline size_t count_multivalue() const;
4443
4444 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4445 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4446 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4447
4448 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4449 return move(seek_and_batch_samelength, key, throw_notfound);
4450 }
4451
4452 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4453 return move(batch_samelength, throw_notfound);
4454 }
4455
4456 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4457 return move(batch_samelength_next, throw_notfound);
4458 }
4459
4460 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4461 return move(batch_samelength_previous, throw_notfound);
4462 }
4463
4464 inline bool eof() const;
4465 inline bool on_first() const;
4466 inline bool on_last() const;
4467 inline bool on_first_multival() const;
4468 inline bool on_last_multival() const;
4469 inline estimate_result estimate(const slice &key, const slice &value) const;
4470 inline estimate_result estimate(const slice &key) const;
4471 inline estimate_result estimate(move_operation operation) const;
4472 inline estimate_result estimate(move_operation operation, slice &key) const;
4473
4474 static inline ptrdiff_t distance_between(const cursor from, const cursor to,
4475 unsigned deepness = /* enough to cover whole tree height */ 42);
4476 inline ptrdiff_t distance_from(const cursor from,
4477 unsigned deepness = /* enough to cover whole tree height */ 42) const {
4478 return distance_between(from, *this, deepness);
4479 }
4480 inline ptrdiff_t distance_to(const cursor to, unsigned deepness = /* enough to cover whole tree height */ 42) const {
4481 return distance_between(*this, to, deepness);
4482 }
4483 inline ptrdiff_t distance_from_first(unsigned deepness = /* enough to cover whole tree height */ 42) const {
4484 return distance_between(nullptr, *this, deepness);
4485 }
4486 inline ptrdiff_t distance_to_end(unsigned deepness = /* enough to cover whole tree height */ 42) const {
4487 return distance_between(*this, nullptr, deepness);
4488 }
4489
4490 inline bool scroll(intptr_t distable, unsigned deepness = /* enough to cover whole tree height */ 42,
4491 bool throw_notfound = true);
4492
4493 static inline bool distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size,
4494 unsigned deepness = /* enough to cover whole tree height */ 42);
4495
4496 static inline bool distribute(const cursor from, const cursor to, const std::vector<cursor> &cursors,
4497 unsigned deepness = /* enough to cover whole tree height */ 42);
4498
4499 static inline bool distribute(const cursor from, const cursor to, const std::vector<cursor_managed> &cursors,
4500 unsigned deepness = /* enough to cover whole tree height */ 42);
4501
4502 //----------------------------------------------------------------------------
4503
4505 inline void renew(::mdbx::txn &txn);
4506
4508 inline void bind(::mdbx::txn &txn, ::mdbx::map_handle map_handle);
4509
4511 inline void unbind();
4512
4514 inline ::mdbx::txn txn() const;
4515 inline map_handle map() const;
4516
4517 inline operator ::mdbx::txn() const { return txn(); }
4518 inline operator ::mdbx::map_handle() const { return map(); }
4519
4520 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4521 inline void put(const slice &key, slice value, put_mode mode);
4522 inline void insert(const slice &key, slice value);
4523 inline value_result try_insert(const slice &key, slice value);
4524 inline slice insert_reserve(const slice &key, size_t value_length);
4525 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4526
4527 inline void upsert(const slice &key, const slice &value);
4528 inline slice upsert_reserve(const slice &key, size_t value_length);
4529
4531 void update_current(const slice &value);
4533 slice reverse_current(size_t value_length);
4534
4535 inline void update(const slice &key, const slice &value);
4536 inline bool try_update(const slice &key, const slice &value);
4537 inline slice update_reserve(const slice &key, size_t value_length);
4538 inline value_result try_update_reserve(const slice &key, size_t value_length);
4539
4540 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4541 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4542 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4543 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4544
4546 inline bool erase(bool whole_multivalue = false);
4547
4550 inline bool erase(const slice &key, bool whole_multivalue = true);
4551
4554 inline bool erase(const slice &key, const slice &value);
4555
4556 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4557 size_t values_count, put_mode mode, bool allow_partial = false);
4558 template <typename VALUE>
4559 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4560 bool allow_partial = false) {
4561 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4562 !::std::is_array<VALUE>::value,
4563 "Must be a standard layout type!");
4564 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4565 }
4566 template <typename VALUE>
4567 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4568 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4569 }
4570};
4571
4579class LIBMDBX_API_TYPE cursor_managed : public cursor {
4580 using inherited = cursor;
4581 friend class txn;
4583 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4584
4585public:
4587 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4588 if (MDBX_UNLIKELY(!handle_))
4589 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4590 }
4591
4593 void close();
4594
4595 cursor_managed(cursor_managed &&) = default;
4596 cursor_managed &operator=(cursor_managed &&other) noexcept;
4597
4598 inline MDBX_cursor *withdraw_handle() noexcept {
4600 handle_ = nullptr;
4601 return handle;
4602 }
4603
4604 cursor_managed(const cursor_managed &) = delete;
4605 cursor_managed &operator=(const cursor_managed &) = delete;
4607};
4608
4609//==============================================================================
4610//
4611// Inline body of the libmdbx C++ API
4612//
4613
4614MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4615MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4616
4617static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4618#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4619 if (::std::is_constant_evaluated()) {
4620 size_t i = 0;
4621 if (c_str)
4622 while (c_str[i])
4623 ++i;
4624 return i;
4625 }
4626#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4627#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4628 return c_str ? ::std::string_view(c_str).length() : 0;
4629#else
4630 return c_str ? ::std::strlen(c_str) : 0;
4631#endif
4632}
4633
4634MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4635#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4636 if (::std::is_constant_evaluated()) {
4637 for (size_t i = 0; i < bytes; ++i)
4638 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4639 return dest;
4640 } else
4641#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4642 return ::std::memcpy(dest, src, bytes);
4643}
4644
4645static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4646#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4647 if (::std::is_constant_evaluated()) {
4648 for (size_t i = 0; i < bytes; ++i) {
4649 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4650 if (diff)
4651 return diff;
4652 }
4653 return 0;
4654 } else
4655#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4656 return ::std::memcmp(a, b, bytes);
4657}
4658
4659//------------------------------------------------------------------------------
4660
4663
4667
4671
4672inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4673
4674inline void exception_thunk::capture() noexcept {
4675 assert(is_clean());
4676 captured_ = ::std::current_exception();
4677}
4678
4680 if (captured_)
4681 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4682}
4683
4684//------------------------------------------------------------------------------
4685
4686MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4687
4688inline error &error::operator=(MDBX_error_t error_code) noexcept {
4689 code_ = error_code;
4690 return *this;
4691}
4692
4693MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4694
4695MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4696
4697MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4698
4699MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4700
4701MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4702
4704 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4705}
4706
4707MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4708
4713
4714inline void error::throw_exception(int error_code) {
4715 const error trouble(static_cast<MDBX_error_t>(error_code));
4716 trouble.throw_exception();
4717}
4718
4719inline void error::throw_on_failure() const {
4721 MDBX_CXX20_UNLIKELY throw_exception();
4722}
4723
4724inline void error::success_or_throw() const {
4725 if (MDBX_UNLIKELY(!is_success()))
4726 MDBX_CXX20_UNLIKELY throw_exception();
4727}
4728
4729inline void error::success_or_throw(const exception_thunk &thunk) const {
4730 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4731 if (MDBX_UNLIKELY(!is_success())) {
4732 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4733 else throw_exception();
4734 }
4735}
4736
4737inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4738 if (MDBX_UNLIKELY(ptr == nullptr))
4739 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4740}
4741
4742inline void error::throw_on_failure(int error_code) {
4743 error rc(static_cast<MDBX_error_t>(error_code));
4744 rc.throw_on_failure();
4745}
4746
4747inline void error::success_or_throw(MDBX_error_t error_code) {
4748 error rc(error_code);
4749 rc.success_or_throw();
4750}
4751
4752inline bool error::boolean_or_throw(int error_code) {
4753 switch (error_code) {
4754 case MDBX_RESULT_FALSE:
4755 return false;
4756 case MDBX_RESULT_TRUE:
4757 return true;
4758 default:
4759 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4760 }
4761}
4762
4763inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4764 error rc(static_cast<MDBX_error_t>(error_code));
4765 rc.success_or_throw(thunk);
4766}
4767
4768inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4769 if (MDBX_UNLIKELY(!thunk.is_clean()))
4770 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4771 return boolean_or_throw(error_code);
4772}
4773
4774MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4775
4777 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4778
4779MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4780 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4781
4782MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4783
4784MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4785
4786MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4787
4788MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4789
4790inline slice &slice::assign(const void *ptr, size_t bytes) {
4791 iov_base = const_cast<void *>(ptr);
4792 iov_len = check_length(bytes);
4793 return *this;
4794}
4795
4796inline slice &slice::assign(const slice &src) noexcept {
4797 iov_base = src.iov_base;
4798 iov_len = src.iov_len;
4799 return *this;
4800}
4801
4802inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4803
4804slice &slice::assign(slice &&src) noexcept {
4805 assign(src);
4806 src.invalidate();
4807 return *this;
4808}
4809
4811 assign(src.iov_base, src.iov_len);
4812 src.iov_base = nullptr;
4813 return *this;
4814}
4815
4816inline slice &slice::assign(const void *begin, const void *end) {
4817 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4818}
4819
4820inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4821
4822inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4823
4824inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4825
4826MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4827
4828MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4829
4830MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4831
4833
4834MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4835
4836MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4837
4838MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4839
4841
4842MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4843
4844MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4845
4846MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4847
4848MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4849
4850MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4851
4853 iov_len = check_length(bytes);
4854 return *this;
4855}
4856
4858 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4859 return set_length(static_cast<const char *>(ptr) - char_ptr());
4860}
4861
4862MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4863
4864MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4865
4866MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4867
4868MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4869
4870MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4871
4873 iov_base = nullptr;
4874 iov_len = 0;
4875}
4876
4877inline void slice::remove_prefix(size_t n) noexcept {
4878 assert(n <= size());
4879 iov_base = static_cast<byte *>(iov_base) + n;
4880 iov_len -= n;
4881}
4882
4883inline void slice::safe_remove_prefix(size_t n) {
4884 if (MDBX_UNLIKELY(n > size()))
4885 MDBX_CXX20_UNLIKELY throw_out_range();
4886 remove_prefix(n);
4887}
4888
4889inline void slice::remove_suffix(size_t n) noexcept {
4890 assert(n <= size());
4891 iov_len -= n;
4892}
4893
4894inline void slice::safe_remove_suffix(size_t n) {
4895 if (MDBX_UNLIKELY(n > size()))
4896 MDBX_CXX20_UNLIKELY throw_out_range();
4897 remove_suffix(n);
4898}
4899
4900MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4901 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4902}
4903
4904MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4905 return length() >= suffix.length() &&
4906 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4907}
4908
4910 size_t h = length() * 3977471;
4911 for (size_t i = 0; i < length(); ++i)
4912 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4913 return h ^ 3863194411 * (h >> 11);
4914}
4915
4916MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4918 return byte_ptr()[n];
4919}
4920
4921MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4922 if (MDBX_UNLIKELY(n >= size()))
4923 MDBX_CXX20_UNLIKELY throw_out_range();
4924 return byte_ptr()[n];
4925}
4926
4927MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4929 return slice(data(), n);
4930}
4931
4932MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4934 return slice(char_ptr() + size() - n, n);
4935}
4936
4937MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4938 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4939 return slice(char_ptr() + from, n);
4940}
4941
4943 if (MDBX_UNLIKELY(n > size()))
4944 MDBX_CXX20_UNLIKELY throw_out_range();
4945 return head(n);
4946}
4947
4949 if (MDBX_UNLIKELY(n > size()))
4950 MDBX_CXX20_UNLIKELY throw_out_range();
4951 return tail(n);
4952}
4953
4954MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4955 if (MDBX_UNLIKELY(n > max_length))
4956 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4957 if (MDBX_UNLIKELY(from + n /* no overflow possible here, since size() < max_length */ > size()))
4958 MDBX_CXX20_UNLIKELY throw_out_range();
4959 return middle(from, n);
4960}
4961
4962MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4963 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4964 return diff ? diff
4965 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4966 : memcmp(a.data(), b.data(), a.length());
4967}
4968
4970 const size_t shortest = ::std::min(a.length(), b.length());
4971 if (MDBX_LIKELY(shortest > 0))
4973 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4974 if (MDBX_LIKELY(diff != 0))
4975 MDBX_CXX20_LIKELY return diff;
4976 }
4977 return intptr_t(a.length()) - intptr_t(b.length());
4978}
4979
4981 return slice::compare_fast(a, b) == 0;
4982}
4983
4985 return slice::compare_lexicographically(a, b) < 0;
4986}
4987
4989 return slice::compare_lexicographically(a, b) > 0;
4990}
4991
4993 return slice::compare_lexicographically(a, b) <= 0;
4994}
4995
4997 return slice::compare_lexicographically(a, b) >= 0;
4998}
4999
5001 return slice::compare_fast(a, b) != 0;
5002}
5003
5004#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5005MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
5006 const auto cmp = slice::compare_lexicographically(a, b);
5007 return (cmp < 0) ? std::strong_ordering::less
5008 : (cmp > 0) ? std::strong_ordering::greater
5009 : std::strong_ordering::equal;
5010}
5011#endif /* __cpp_impl_three_way_comparison */
5012
5013template <class ALLOCATOR, typename CAPACITY_POLICY>
5015 const allocator_type &alloc)
5016 : inherited(src), silo_(alloc) {
5017 if (!make_reference)
5018 insulate();
5019}
5020
5021template <class ALLOCATOR, typename CAPACITY_POLICY>
5022inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
5023 const allocator_type &alloc)
5024 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
5025
5026template <class ALLOCATOR, typename CAPACITY_POLICY>
5027inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
5028 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
5029}
5030
5031#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
5033
5034#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
5036#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
5037#endif /* !MinGW || MDBX_EXPORTS */
5038
5041
5042//------------------------------------------------------------------------------
5043
5044template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5045inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
5046 if (MDBX_LIKELY(!producer.is_empty()))
5048 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5049 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5050 return result;
5051 }
5053}
5054
5055template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5056inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
5057 if (MDBX_LIKELY(!producer.is_empty()))
5059 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5060 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5061 return result;
5062 }
5064}
5065
5066template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5067inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
5068 string<ALLOCATOR> result(alloc);
5069 if (MDBX_LIKELY(!producer.is_empty()))
5071 result.resize(producer.envisage_result_length());
5072 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5073 }
5074 return result;
5075}
5076
5077template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5078inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
5079 string<ALLOCATOR> result(alloc);
5080 if (MDBX_LIKELY(!producer.is_empty()))
5082 result.resize(producer.envisage_result_length());
5083 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5084 }
5085 return result;
5086}
5087
5088template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
5089 return make_string<ALLOCATOR>(*this, alloc);
5090}
5091
5092template <class ALLOCATOR, typename CAPACITY_POLICY>
5094 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5095}
5096
5097template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
5098 return make_string<ALLOCATOR>(*this, alloc);
5099}
5100
5101template <class ALLOCATOR, typename CAPACITY_POLICY>
5103 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5104}
5105
5106template <class ALLOCATOR> string<ALLOCATOR> to_base64::as_string(const ALLOCATOR &alloc) const {
5107 return make_string<ALLOCATOR>(*this, alloc);
5108}
5109
5110template <class ALLOCATOR, typename CAPACITY_POLICY>
5112 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5113}
5114
5115template <class ALLOCATOR> string<ALLOCATOR> from_hex::as_string(const ALLOCATOR &alloc) const {
5116 return make_string<ALLOCATOR>(*this, alloc);
5117}
5118
5119template <class ALLOCATOR, typename CAPACITY_POLICY>
5121 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5122}
5123
5124template <class ALLOCATOR> string<ALLOCATOR> from_base58::as_string(const ALLOCATOR &alloc) const {
5125 return make_string<ALLOCATOR>(*this, alloc);
5126}
5127
5128template <class ALLOCATOR, typename CAPACITY_POLICY>
5130 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5131}
5132
5133template <class ALLOCATOR> string<ALLOCATOR> from_base64::as_string(const ALLOCATOR &alloc) const {
5134 return make_string<ALLOCATOR>(*this, alloc);
5135}
5136
5137template <class ALLOCATOR, typename CAPACITY_POLICY>
5139 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5140}
5141
5142template <class ALLOCATOR>
5143inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
5144 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
5145}
5146
5147template <class ALLOCATOR>
5148inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5149 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5150}
5151
5152template <class ALLOCATOR>
5153inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5154 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5155}
5156
5157template <class ALLOCATOR, class CAPACITY_POLICY>
5158inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5159 const ALLOCATOR &alloc) const {
5160 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5161}
5162
5163template <class ALLOCATOR, class CAPACITY_POLICY>
5164inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
5165 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5166}
5167
5168template <class ALLOCATOR, class CAPACITY_POLICY>
5169inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
5170 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5171}
5172
5173template <class ALLOCATOR, class CAPACITY_POLICY>
5174inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5175 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5176}
5177
5178template <class ALLOCATOR, class CAPACITY_POLICY>
5179inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5180 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5181}
5182
5183template <class ALLOCATOR, class CAPACITY_POLICY>
5184inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5185 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5186}
5187
5188//------------------------------------------------------------------------------
5189
5190MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5191 const auto diff = slice::compare_fast(a.key, b.key);
5192 return diff ? diff : slice::compare_fast(a.value, b.value);
5193}
5194
5195MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5196 const auto diff = slice::compare_lexicographically(a.key, b.key);
5197 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5198}
5199
5201 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5202 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5203 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5204}
5205
5207 return pair::compare_lexicographically(a, b) < 0;
5208}
5209
5211 return pair::compare_lexicographically(a, b) > 0;
5212}
5213
5215 return pair::compare_lexicographically(a, b) <= 0;
5216}
5217
5219 return pair::compare_lexicographically(a, b) >= 0;
5220}
5221
5223 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5224 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5225 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5226}
5227
5228#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5229MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5231}
5232#endif /* __cpp_impl_three_way_comparison */
5233
5235template <typename BUFFER>
5237
5240
5241//------------------------------------------------------------------------------
5242
5243inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
5244inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
5245inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
5246
5247MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5248 return !from_hex(*this, ignore_spaces).is_erroneous();
5249}
5250
5251MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5252 return !from_base58(*this, ignore_spaces).is_erroneous();
5253}
5254
5255MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5256 return !from_base64(*this, ignore_spaces).is_erroneous();
5257}
5258
5259//------------------------------------------------------------------------------
5260
5262
5263inline env &env::operator=(env &&other) noexcept {
5264 if (this != &other) {
5265 handle_ = other.handle_;
5266 other.handle_ = nullptr;
5267 }
5268 return *this;
5269}
5270
5271inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5272
5273inline env::~env() noexcept {
5274#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
5275 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5276#endif
5277}
5278
5282 return *this;
5283}
5284
5285inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5286 size_now = size_lower = lower;
5287 size_upper = upper;
5289 return *this;
5290}
5291
5295
5299
5300inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5301
5302inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5303
5304inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5305 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5306 if (result < 0)
5307 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5308 return static_cast<size_t>(result);
5309}
5310
5311inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5312 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5313 if (result < 0)
5314 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5315 return static_cast<size_t>(result);
5316}
5317
5318inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5319
5320inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5321
5322inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5323 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5324 if (result < 0)
5325 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5326 return static_cast<size_t>(result);
5327}
5328
5329inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5330 return key_max(pagesize, MDBX_db_flags_t(mode));
5331}
5332
5333inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
5334 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5335 if (result < 0)
5336 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5337 return static_cast<size_t>(result);
5338}
5339
5341
5342inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5343
5345
5346inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5347 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5348 if (result < 0)
5349 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5350 return static_cast<size_t>(result);
5351}
5352
5353inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5354 return value_max(pagesize, MDBX_db_flags_t(mode));
5355}
5356
5357inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
5358 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5359 if (result < 0)
5360 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5361 return static_cast<size_t>(result);
5362}
5363
5365
5366inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5367 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5368 if (result < 0)
5369 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5370 return static_cast<size_t>(result);
5371}
5372
5373inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5374 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5375}
5376
5378 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5379 if (result < 0)
5380 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5381 return static_cast<size_t>(result);
5382}
5383
5387
5388inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5389 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5390 if (result < 0)
5391 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5392 return static_cast<size_t>(result);
5393}
5394
5395inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5396 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5397}
5398
5400 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5401 if (result < 0)
5402 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5403 return static_cast<size_t>(result);
5404}
5405
5409
5410inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5411 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5412 if (result < 0)
5413 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5414 return static_cast<size_t>(result);
5415}
5416
5417inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5418
5426
5428
5432
5436
5440
5441inline env::stat env::get_stat() const {
5442 env::stat r;
5443 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5444 return r;
5445}
5446
5447inline env::stat env::get_stat(const txn &txn) const {
5448 env::stat r;
5450 return r;
5451}
5452
5453inline env::info env::get_info() const {
5454 env::info r;
5455 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5456 return r;
5457}
5458
5459inline env::info env::get_info(const txn &txn) const {
5460 env::info r;
5462 return r;
5463}
5464
5466 filehandle fd;
5468 return fd;
5469}
5470
5472 unsigned bits = 0;
5474 return MDBX_env_flags_t(bits);
5475}
5476
5477inline unsigned env::max_readers() const {
5478 unsigned r;
5480 return r;
5481}
5482
5483inline unsigned env::max_maps() const {
5484 unsigned r;
5486 return r;
5487}
5488
5489inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5490
5491inline env &env::set_context(void *ptr) {
5493 return *this;
5494}
5495
5496inline env &env::set_sync_threshold(size_t bytes) {
5498 return *this;
5499}
5500
5501inline size_t env::sync_threshold() const {
5502 size_t bytes;
5504 return bytes;
5505}
5506
5507inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5509 return *this;
5510}
5511
5512inline unsigned env::sync_period__seconds_16dot16() const {
5513 unsigned seconds_16dot16;
5515 return seconds_16dot16;
5516}
5517
5519 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5520}
5521
5522inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5523
5524#if __cplusplus >= 201103L
5525inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5526
5528#endif
5529
5530inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5532 return *this;
5533}
5534
5535inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5536 uint64_t value;
5538 return value;
5539}
5540
5541inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
5543 return *this;
5544}
5545
5546inline env &env::set_geometry(const geometry &geo) {
5548 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5549 return *this;
5550}
5551
5552inline bool env::sync_to_disk(bool force, bool nonblock) {
5553 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5554 switch (err) {
5555 case MDBX_SUCCESS /* flush done */:
5556 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5557 return true;
5558 case MDBX_BUSY /* the environment is used by other thread */:
5559 return false;
5560 default:
5561 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5562 }
5563}
5564
5566
5568env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5569 size_t retained) noexcept
5571 bytes_retained(retained) {}
5572
5573template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5574 struct reader_visitor_thunk : public exception_thunk {
5575 VISITOR &visitor_;
5576 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5577 size_t used, size_t retained) noexcept {
5578 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5579 assert(thunk->is_clean());
5580 try {
5581 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5582 return loop_control(thunk->visitor_(info, number));
5583 } catch (... /* capture any exception to rethrow it over C code */) {
5584 thunk->capture();
5586 }
5587 }
5588 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5589 };
5590 reader_visitor_thunk thunk(visitor);
5591 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5592 thunk.rethrow_captured();
5593 return rc;
5594}
5595
5596inline unsigned env::check_readers() {
5597 int dead_count;
5598 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5599 MDBX_INLINE_API_ASSERT(dead_count >= 0);
5600 return static_cast<unsigned>(dead_count);
5601}
5602
5607
5608inline MDBX_hsr_func env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5609
5611 ::MDBX_txn *ptr;
5613 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5614 return txn_managed(ptr);
5615}
5616
5618 ::MDBX_txn *ptr;
5620 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5621 return txn_managed(ptr);
5622}
5623
5624inline txn_managed env::start_write(bool dont_wait) {
5625 ::MDBX_txn *ptr;
5628 MDBX_INLINE_API_ASSERT(ptr != nullptr || dont_wait);
5629 return txn_managed(ptr);
5630}
5631
5633 ::MDBX_txn *ptr;
5635 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5636 return txn_managed(ptr);
5637}
5638
5640
5642
5643inline txn &txn::operator=(txn &&other) noexcept {
5644 if (this != &other) {
5645 handle_ = other.handle_;
5646 other.handle_ = nullptr;
5647 }
5648 return *this;
5649}
5650
5651inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5652
5653inline txn::~txn() noexcept {
5654#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
5655 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5656#endif
5657}
5658
5659inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5660
5661inline txn &txn::set_context(void *ptr) {
5663 return *this;
5664}
5665
5666inline bool txn::is_dirty(const void *ptr) const {
5667 int err = ::mdbx_is_dirty(handle_, ptr);
5668 switch (err) {
5669 default:
5670 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5671 case MDBX_RESULT_TRUE:
5672 return true;
5673 case MDBX_RESULT_FALSE:
5674 return false;
5675 }
5676}
5677
5678inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5679
5681 const int bits = mdbx_txn_flags(handle_);
5683 return static_cast<MDBX_txn_flags_t>(bits);
5684}
5685
5686inline uint64_t txn::id() const {
5687 const uint64_t txnid = mdbx_txn_id(handle_);
5689 return txnid;
5690}
5691
5693
5695
5697
5698inline txn_managed txn::clone(void *context) const {
5699 MDBX_txn *ptr = nullptr;
5701 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5702 return txn_managed(ptr);
5703}
5704
5705inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
5706 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
5707 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
5708 MDBX_INLINE_API_ASSERT(txn_for_renew_into_clone.handle_ != nullptr);
5709}
5710
5711inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5712
5713inline bool txn::unpark_reading(bool restart_if_ousted) {
5714 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5715}
5716
5717inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5718 txn::info r;
5719 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5720 return r;
5721}
5722
5724 MDBX_cursor *ptr;
5726 return cursor_managed(ptr);
5727}
5728
5729inline size_t txn::release_all_cursors(bool unbind) const {
5730 size_t count;
5732 return count;
5733}
5734
5735inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5736 const ::mdbx::value_mode value_mode) const {
5737 map_handle map;
5740 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5741 return map;
5742}
5743
5744inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5745 const ::mdbx::value_mode value_mode) const {
5746 map_handle map;
5749 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5750 return map;
5751}
5752
5753inline map_handle txn::open_map_accede(const slice &name) const {
5754 map_handle map;
5756 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5757 return map;
5758}
5759
5760inline map_handle txn::open_map_accede(const char *name) const {
5761 map_handle map;
5763 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5764 return map;
5765}
5766
5767inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5768 const ::mdbx::value_mode value_mode) {
5769 map_handle map;
5772 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5773 return map;
5774}
5775
5776inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5777 const ::mdbx::value_mode value_mode) {
5778 map_handle map;
5781 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5782 return map;
5783}
5784
5786
5788
5789inline void txn::rename_map(map_handle map, const char *new_name) {
5791}
5792
5793inline void txn::rename_map(map_handle map, const slice &new_name) {
5795}
5796
5797inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5798 const ::mdbx::value_mode value_mode) const {
5799 return open_map(slice(name), key_mode, value_mode);
5800}
5801
5802inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5803
5804inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5805 const ::mdbx::value_mode value_mode) {
5806 return create_map(slice(name), key_mode, value_mode);
5807}
5808
5809inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5810 return drop_map(slice(name), throw_if_absent);
5811}
5812
5813inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5814 return clear_map(slice(name), throw_if_absent);
5815}
5816
5817inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5818
5820 txn::map_stat r;
5821 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5822 return r;
5823}
5824
5825inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5826 uint32_t r;
5828 return r;
5829}
5830
5836
5841
5843 txn::canary r;
5845 return r;
5846}
5847
5848inline uint64_t txn::sequence(map_handle map) const {
5849 uint64_t result;
5851 return result;
5852}
5853
5854inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5855 uint64_t result;
5856 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5857 return result;
5858}
5859
5860inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5861 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5862}
5863
5864inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5865 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5866}
5867
5868inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5869 return compare_keys(map, a.key, b.key);
5870}
5871
5872inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5873 return compare_values(map, a.value, b.value);
5874}
5875
5876inline slice txn::get(map_handle map, const slice &key) const {
5877 slice result;
5878 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5879 return result;
5880}
5881
5882inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5883 slice result;
5884 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5885 return result;
5886}
5887
5888inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5889 slice result;
5890 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5891 switch (err) {
5892 case MDBX_SUCCESS:
5893 return result;
5894 case MDBX_NOTFOUND:
5895 return value_at_absence;
5896 default:
5897 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5898 }
5899}
5900
5901inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5902 slice result;
5903 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5904 switch (err) {
5905 case MDBX_SUCCESS:
5906 return result;
5907 case MDBX_NOTFOUND:
5908 return value_at_absence;
5909 default:
5910 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5911 }
5912}
5913
5915 pair result(key, slice());
5916 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5917 return pair_result(result.key, result.value, exact);
5918}
5919
5920inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5921 pair result{key, slice()};
5922 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5923 switch (err) {
5924 case MDBX_SUCCESS:
5925 return pair_result{result.key, result.value, true};
5926 case MDBX_RESULT_TRUE:
5927 return pair_result{result.key, result.value, false};
5928 case MDBX_NOTFOUND:
5929 return pair_result{key, value_at_absence, false};
5930 default:
5931 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5932 }
5933}
5934
5935inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5936 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5937 /* coverity[OVERRUN] */
5938 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5939}
5940
5941inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5942 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5943 /* coverity[OVERRUN] */
5944 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5945}
5946
5947inline void txn::insert(map_handle map, const slice &key, slice value) {
5948 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5949 /* coverity[OVERRUN] */
5950 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5952}
5953
5954inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5955 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5956 /* coverity[OVERRUN] */
5957 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5959 switch (err) {
5960 case MDBX_SUCCESS:
5961 return value_result{slice(), true};
5962 case MDBX_KEYEXIST:
5963 return value_result{value, false};
5964 default:
5965 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5966 }
5967}
5968
5969inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5970 slice result(nullptr, value_length);
5971 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5972 /* coverity[OVERRUN] */
5973 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5975 return result;
5976}
5977
5978inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5979 slice result(nullptr, value_length);
5980 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5981 /* coverity[OVERRUN] */
5982 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5984 switch (err) {
5985 case MDBX_SUCCESS:
5986 return value_result{result, true};
5987 case MDBX_KEYEXIST:
5988 return value_result{result, false};
5989 default:
5990 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5991 }
5992}
5993
5994inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5995 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
5996 /* coverity[OVERRUN] */
5997 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5998}
5999
6000inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
6001 slice result(nullptr, value_length);
6002 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6003 /* coverity[OVERRUN] */
6005 return result;
6006}
6007
6008inline void txn::update(map_handle map, const slice &key, const slice &value) {
6009 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6010 /* coverity[OVERRUN] */
6011 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6012}
6013
6014inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
6015 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6016 /* coverity[OVERRUN] */
6017 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6018 switch (err) {
6019 case MDBX_SUCCESS:
6020 return true;
6021 case MDBX_NOTFOUND:
6022 return false;
6023 default:
6024 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6025 }
6026}
6027
6028inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
6029 slice result(nullptr, value_length);
6030 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6031 /* coverity[OVERRUN] */
6033 return result;
6034}
6035
6036inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
6037 slice result(nullptr, value_length);
6038 /* LY: ложные предупреждения coverity возникают из-за поддержки вставки массивов значений в режиме MDBX_MULTIPLE */
6039 /* coverity[OVERRUN] */
6040 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6041 switch (err) {
6042 case MDBX_SUCCESS:
6043 return value_result{result, true};
6044 case MDBX_NOTFOUND:
6045 return value_result{slice(), false};
6046 default:
6047 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6048 }
6049}
6050
6051inline bool txn::erase(map_handle map, const slice &key) {
6052 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6053 switch (err) {
6054 case MDBX_SUCCESS:
6055 return true;
6056 case MDBX_NOTFOUND:
6057 return false;
6058 default:
6059 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6060 }
6061}
6062
6063inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6064 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
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 void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
6076 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6077 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6078}
6079
6080template <class ALLOCATOR, typename CAPACITY_POLICY>
6084 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6086 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
6087 return result;
6088}
6089
6090template <class ALLOCATOR, typename CAPACITY_POLICY>
6092txn::replace(map_handle map, const slice &key, const slice &new_value,
6094 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6095 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
6096 MDBX_CURRENT, result, &result),
6097 result);
6098 return result;
6099}
6100
6101template <class ALLOCATOR, typename CAPACITY_POLICY>
6103txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
6105 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6106 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6107 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6108 result);
6109 return result;
6110}
6111
6112inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
6113 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6114 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
6115}
6116
6117inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
6118 const void *values_array, size_t values_count, put_mode mode,
6119 bool allow_partial) {
6120 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6121 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6122 switch (err) {
6123 case MDBX_SUCCESS:
6124 MDBX_CXX20_LIKELY break;
6125 case MDBX_KEYEXIST:
6126 if (allow_partial)
6127 break;
6129 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6130 default:
6131 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6132 }
6133 return args[1].iov_len /* done item count */;
6134}
6135
6136inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
6137 ptrdiff_t result;
6138 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6139 return result;
6140}
6141
6142inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6143 ptrdiff_t result;
6144 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6145 return result;
6146}
6147
6148inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6149 ptrdiff_t result;
6150 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6151 return result;
6152}
6153
6154inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6155 ptrdiff_t result;
6156 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6157 return result;
6158}
6159
6161
6162inline cursor &cursor::assign(const cursor &src) {
6164 return *this;
6165}
6166
6167inline cursor &cursor::operator=(cursor &&other) noexcept {
6168 if (this != &other) {
6169 handle_ = other.handle_;
6170 other.handle_ = nullptr;
6171 }
6172 return *this;
6173}
6174
6175inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6176
6177inline cursor::~cursor() noexcept {
6178#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
6179 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6180#endif
6181}
6182
6183inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6184
6185inline cursor &cursor::set_context(void *ptr) {
6187 return *this;
6188}
6189
6190inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6191 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6192}
6193
6194inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6195 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6196 MDBX_INLINE_API_ASSERT(compare_position_nothrow(right, left, ignore_nested) == -diff);
6197 if (MDBX_LIKELY(int16_t(diff) == diff))
6198 MDBX_CXX20_LIKELY return int(diff);
6199 else
6201}
6202
6203inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6204 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6205}
6206
6208 bool throw_notfound)
6209 : pair_result(key, value, false) {
6210 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6211}
6212
6213inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6214 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6215 switch (err) {
6216 case MDBX_SUCCESS:
6217 MDBX_CXX20_LIKELY return true;
6218 case MDBX_RESULT_TRUE:
6219 return false;
6220 case MDBX_NOTFOUND:
6221 if (!throw_notfound)
6222 return false;
6223 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6224 default:
6225 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6226 }
6227}
6228
6230 const slice &value)
6231 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6232 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6233}
6234
6235inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6236 ptrdiff_t result;
6237 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6238 return result;
6239}
6240
6241inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6242 ptrdiff_t result;
6244 return result;
6245}
6246
6247inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6248 return move(key_exact, key, throw_notfound);
6249}
6250
6251inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6252 return move(key_lowerbound, key, throw_notfound);
6253}
6254
6255inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6256 return move(key_greater_than, key, throw_notfound);
6257}
6258
6259inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6260 return move(multi_find_pair, key, value, throw_notfound);
6261}
6262
6263inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6264 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6265}
6266
6267inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6268 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6269}
6270
6271inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6272
6273inline size_t cursor::count_multivalue() const {
6274 size_t result;
6276 return result;
6277}
6278
6279inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6280
6282
6284
6286
6288
6289inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6290 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6291}
6292
6294 return estimate_result(*this, key_lowerbound, key);
6295}
6296
6298 return estimate_result(*this, operation);
6299}
6300
6302
6306
6308
6309inline txn cursor::txn() const {
6311 return ::mdbx::txn(txn);
6312}
6313
6314inline map_handle cursor::map() const {
6315 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6316 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6318 return map_handle(dbi);
6319}
6320
6321inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6322 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6323}
6324
6325inline void cursor::put(const slice &key, slice value, put_mode mode) {
6326 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6327}
6328
6329inline void cursor::insert(const slice &key, slice value) {
6331 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6332}
6333
6334inline value_result cursor::try_insert(const slice &key, slice value) {
6335 const int err =
6336 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6337 switch (err) {
6338 case MDBX_SUCCESS:
6339 return value_result{slice(), true};
6340 case MDBX_KEYEXIST:
6341 return value_result{value, false};
6342 default:
6343 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6344 }
6345}
6346
6347inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6348 slice result(nullptr, value_length);
6349 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6351 return result;
6352}
6353
6354inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6355 slice result(nullptr, value_length);
6356 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6358 switch (err) {
6359 case MDBX_SUCCESS:
6360 return value_result{result, true};
6361 case MDBX_KEYEXIST:
6362 return value_result{result, false};
6363 default:
6364 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6365 }
6366}
6367
6368inline void cursor::upsert(const slice &key, const slice &value) {
6369 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6370}
6371
6372inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6373 slice result(nullptr, value_length);
6375 return result;
6376}
6377
6378inline void cursor::update(const slice &key, const slice &value) {
6379 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6380}
6381
6382inline bool cursor::try_update(const slice &key, const slice &value) {
6383 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6384 switch (err) {
6385 case MDBX_SUCCESS:
6386 return true;
6387 case MDBX_NOTFOUND:
6388 return false;
6389 default:
6390 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6391 }
6392}
6393
6394inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6395 slice result(nullptr, value_length);
6397 return result;
6398}
6399
6400inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6401 slice result(nullptr, value_length);
6402 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6403 switch (err) {
6404 case MDBX_SUCCESS:
6405 return value_result{result, true};
6406 case MDBX_NOTFOUND:
6407 return value_result{slice(), false};
6408 default:
6409 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6410 }
6411}
6412
6413inline bool cursor::erase(bool whole_multivalue) {
6414 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6415 switch (err) {
6416 case MDBX_SUCCESS:
6417 MDBX_CXX20_LIKELY return true;
6418 case MDBX_NOTFOUND:
6419 return false;
6420 default:
6421 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6422 }
6423}
6424
6425inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6426 bool found = seek(key);
6427 return found ? erase(whole_multivalue) : found;
6428}
6429
6430inline bool cursor::erase(const slice &key, const slice &value) {
6431 move_result data = find_multivalue(key, value, false);
6432 return data.done && erase();
6433}
6434
6435inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6436 size_t values_count, put_mode mode, bool allow_partial) {
6437 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6438 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6439 switch (err) {
6440 case MDBX_SUCCESS:
6441 MDBX_CXX20_LIKELY break;
6442 case MDBX_KEYEXIST:
6443 if (allow_partial)
6444 break;
6446 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6447 default:
6448 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6449 }
6450 return args[1].iov_len /* done item count */;
6451}
6452
6453inline ptrdiff_t cursor::distance_between(const cursor from, const cursor to, unsigned deepness) {
6454 intptr_t distance = PTRDIFF_MIN;
6455 error::success_or_throw(mdbx_cursor_distance(from, to, &distance, deepness));
6456 return distance;
6457}
6458
6459inline bool cursor::scroll(intptr_t distance, unsigned deepness, bool throw_notfound) {
6460 const int err = ::mdbx_cursor_scroll(handle_, distance, deepness);
6461 switch (err) {
6462 case MDBX_SUCCESS:
6463 MDBX_CXX20_LIKELY return true;
6464 case MDBX_NOTFOUND:
6465 if (!throw_notfound)
6466 return false;
6467 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6468 default:
6469 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6470 }
6471}
6472
6473inline bool cursor::distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size,
6474 unsigned deepness) {
6475 static_assert(sizeof(cursors_array[0]) == sizeof(MDBX_cursor *), "oops");
6476 const int err = ::mdbx_cursor_distribute(from, to, &cursors_array[0].handle_, cursors_array_size, deepness);
6477 return error::boolean_or_throw(err);
6478}
6479
6480inline bool cursor::distribute(const cursor from, const cursor to, const std::vector<cursor> &cursors_array,
6481 unsigned deepness) {
6482 static_assert(sizeof(cursor) == sizeof(MDBX_cursor *), "oops");
6483 const int err = ::mdbx_cursor_distribute(from, to, const_cast<MDBX_cursor **>(&cursors_array[0].handle_),
6484 cursors_array.size(), deepness);
6485 return error::boolean_or_throw(err);
6486}
6487
6488inline bool cursor::distribute(const cursor from, const cursor to, const std::vector<cursor_managed> &cursors_array,
6489 unsigned deepness) {
6490 static_assert(sizeof(cursor_managed) == sizeof(MDBX_cursor *), "oops");
6491 const int err = ::mdbx_cursor_distribute(from, to, const_cast<MDBX_cursor **>(&cursors_array[0].handle_),
6492 cursors_array.size(), deepness);
6493 return error::boolean_or_throw(err);
6494}
6495
6496//------------------------------------------------------------------------------
6497
6498LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
6499LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
6500LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
6501LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
6502LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
6503LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
6504LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
6505LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
6506LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
6507LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
6508LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
6509
6510LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
6511LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
6512LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
6513
6514inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
6515
6517
6518} // namespace mdbx
6519
6520//------------------------------------------------------------------------------
6521
6524namespace std {
6525
6526inline string to_string(const ::mdbx::slice &value) {
6527 ostringstream out;
6528 out << value;
6529 return out.str();
6530}
6531
6532template <class ALLOCATOR, typename CAPACITY_POLICY>
6533inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6534 ostringstream out;
6535 out << buffer;
6536 return out.str();
6537}
6538
6539inline string to_string(const ::mdbx::pair &value) {
6540 ostringstream out;
6541 out << value;
6542 return out.str();
6543}
6544
6545inline string to_string(const ::mdbx::env::geometry &value) {
6546 ostringstream out;
6547 out << value;
6548 return out.str();
6549}
6550
6551inline string to_string(const ::mdbx::env::operate_parameters &value) {
6552 ostringstream out;
6553 out << value;
6554 return out.str();
6555}
6556
6557inline string to_string(const ::mdbx::env::mode &value) {
6558 ostringstream out;
6559 out << value;
6560 return out.str();
6561}
6562
6563inline string to_string(const ::mdbx::env::durability &value) {
6564 ostringstream out;
6565 out << value;
6566 return out.str();
6567}
6568
6569inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6570 ostringstream out;
6571 out << value;
6572 return out.str();
6573}
6574
6575inline string to_string(const ::mdbx::env::operate_options &value) {
6576 ostringstream out;
6577 out << value;
6578 return out.str();
6579}
6580
6581inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6582 ostringstream out;
6583 out << value;
6584 return out.str();
6585}
6586
6587inline string to_string(const ::MDBX_log_level_t &value) {
6588 ostringstream out;
6589 out << value;
6590 return out.str();
6591}
6592
6593inline string to_string(const ::MDBX_debug_flags_t &value) {
6594 ostringstream out;
6595 out << value;
6596 return out.str();
6597}
6598
6599inline string to_string(const ::mdbx::error &value) {
6600 ostringstream out;
6601 out << value;
6602 return out.str();
6603}
6604
6605inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6606
6607template <> struct hash<::mdbx::slice> {
6608 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6609};
6610
6611template <> struct hash<::mdbx::map_handle> {
6612 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6613};
6614
6615template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6616 using inherited = std::hash<const MDBX_env *>;
6617 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6618};
6619
6620template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6621 using inherited = std::hash<const MDBX_txn *>;
6622 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6623};
6624
6625template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6626 using inherited = std::hash<const MDBX_cursor *>;
6627 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6628};
6629
6630template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6631 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6632 return buffer.hash_value();
6633 }
6634};
6635
6636} // namespace std
6637
6638#if defined(__LCC__) && __LCC__ >= 126
6639#pragma diagnostic pop
6640#endif
6641
6642#ifdef _MSC_VER
6643#pragma warning(pop)
6644#endif
Definition mdbx.h++:1139
Definition mdbx.h++:1129
Definition mdbx.h++:1149
#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:5265
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4758
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4164
Information about the environment.
Definition mdbx.h:2858
Statistics for a table in the environment.
Definition mdbx.h:2812
Information about the transaction.
Definition mdbx.h:4062
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:5558
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:1655
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:4818
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5279
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:1692
@ MDBX_ALLDUPS
Definition mdbx.h:1675
@ MDBX_CURRENT
Definition mdbx.h:1670
@ MDBX_APPENDDUP
Definition mdbx.h:1688
@ MDBX_APPEND
Definition mdbx.h:1683
@ MDBX_UPSERT
Definition mdbx.h:1657
@ MDBX_RESERVE
Definition mdbx.h:1679
@ MDBX_NOOVERWRITE
Definition mdbx.h:1660
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:1736
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:1855
@ MDBX_GET_CURRENT
Definition mdbx.h:1751
@ MDBX_GET_BOTH
Definition mdbx.h:1744
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1832
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1748
@ MDBX_SET_KEY
Definition mdbx.h:1791
@ MDBX_FIRST_DUP
Definition mdbx.h:1741
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1831
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1756
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1842
@ MDBX_NEXT_NODUP
Definition mdbx.h:1776
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1839
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1840
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1847
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1799
@ MDBX_SET_RANGE
Definition mdbx.h:1794
@ MDBX_LAST_DUP
Definition mdbx.h:1762
@ MDBX_PREV
Definition mdbx.h:1779
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1849
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1850
@ MDBX_LAST
Definition mdbx.h:1759
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1830
@ MDBX_PREV_DUP
Definition mdbx.h:1782
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1838
@ MDBX_SET
Definition mdbx.h:1788
@ MDBX_NEXT
Definition mdbx.h:1765
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1833
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1846
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1773
@ MDBX_PREV_NODUP
Definition mdbx.h:1785
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1848
@ MDBX_NEXT_DUP
Definition mdbx.h:1768
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1841
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1834
@ MDBX_FIRST
Definition mdbx.h:1738
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:1605
@ MDBX_INTEGERDUP
Definition mdbx.h:1629
@ MDBX_DB_ACCEDE
Definition mdbx.h:1647
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1607
@ MDBX_REVERSEKEY
Definition mdbx.h:1610
@ MDBX_DUPFIXED
Definition mdbx.h:1624
@ MDBX_INTEGERKEY
Definition mdbx.h:1620
@ MDBX_REVERSEDUP
Definition mdbx.h:1632
@ MDBX_CREATE
Definition mdbx.h:1635
@ MDBX_DUPSORT
Definition mdbx.h:1613
MDBX_log_level_t
Definition mdbx.h:884
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:943
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1863
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:6981
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1877
@ MDBX_BAD_TXN
Definition mdbx.h:1940
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1954
@ MDBX_SUCCESS
Definition mdbx.h:1865
@ MDBX_NOTFOUND
Definition mdbx.h:1880
@ MDBX_RESULT_TRUE
Definition mdbx.h:1871
@ MDBX_BUSY
Definition mdbx.h:1958
@ MDBX_EINVAL
Definition mdbx.h:2034
@ MDBX_ENOMEM
Definition mdbx.h:2036
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1961
@ MDBX_RESULT_FALSE
Definition mdbx.h:1868
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:2013
@ MDBX_KEYEXIST
Definition mdbx.h:1874
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:2597
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2592
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2595
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1087
@ MDBX_WRITEMAP
Definition mdbx.h:1207
@ MDBX_EXCLUSIVE
Definition mdbx.h:1161
@ MDBX_RDONLY
Definition mdbx.h:1131
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:3103
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2137
LIBMDBX_API int mdbx_env_set_geometry(MDBX_env *env, intptr_t size_lower, intptr_t size_now, intptr_t size_upper, intptr_t growth_step, intptr_t shrink_threshold, intptr_t pagesize)
Set all size-related parameters of environment, including page size and the min/max size of the memor...
int mdbx_env_set_syncbytes(MDBX_env *env, size_t threshold)
Sets threshold to force flush the data buffers to disk, even any of MDBX_SAFE_NOSYNC flag in the envi...
Definition mdbx.h:3044
LIBMDBX_API int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option, uint64_t value)
Sets the value of a extra runtime options for an environment.
LIBMDBX_API int mdbx_env_set_userctx(MDBX_env *env, void *ctx)
Sets application information (a context pointer) associated with the environment.
LIBMDBX_API int mdbx_env_set_flags(MDBX_env *env, MDBX_env_flags_t flags, bool onoff)
Set environment flags.
@ MDBX_opt_txn_dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h:2242
@ MDBX_opt_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:2404
@ MDBX_opt_subpage_limit
Specifies the maximum size of nested pages used to accommodate a small number of multi-values associa...
Definition mdbx.h:2397
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2238
@ MDBX_opt_prefer_waf_insteadof_balance
Controls the choice between striving for uniformity of page filling/density, either for reducing the ...
Definition mdbx.h:2383
@ MDBX_opt_prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h:2342
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2146
@ MDBX_opt_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:2418
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2169
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2274
@ MDBX_opt_spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h:2297
@ MDBX_opt_split_reserve
Sets the space reservation in 1/65536 of page size when splitting page along the edge.
Definition mdbx.h:2446
@ MDBX_opt_loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h:2209
@ MDBX_opt_rp_augment_limit
Controls the in-process limit to grow a list of reclaimed/recycled page's numbers for finding a seque...
Definition mdbx.h:2196
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2163
@ MDBX_opt_subpage_reserve_limit
Sets the limit for reserving space on nested pages.
Definition mdbx.h:2424
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2258
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2175
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2223
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2337
@ MDBX_opt_gc_time_limit
Controls the in-process spending time limit of searching consecutive pages inside GC.
Definition mdbx.h:2361
@ MDBX_opt_merge_threshold
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2309
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:3718
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:3123
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:3062
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:5080
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:3763
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:1504
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:3979
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:1515
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1524
@ MDBX_TXN_READWRITE
Definition mdbx.h:1509
@ MDBX_TXN_TRY
Definition mdbx.h:1530
void commit(finalization_latency &latency)
ommits all changes of the transaction into a database with collecting latencies information.
Definition mdbx.h++:4095
constexpr const MDBX_env * handle() const noexcept
Definition mdbx.h++:2997
friend class env
Definition mdbx.h++:4060
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:3746
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4587
bool scan_until(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4282
::MDBX_stat map_stat
Definition mdbx.h++:3912
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++:3445
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++:3893
bool scan_until_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4327
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++:2944
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4404
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4460
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:2999
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr const MDBX_cursor * handle() const noexcept
Definition mdbx.h++:4160
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2913
durability
Durability level.
Definition mdbx.h++:3092
@ lazy_weak_tail
Definition mdbx.h++:3095
@ robust_synchronous
Definition mdbx.h++:3093
@ whole_fragile
Definition mdbx.h++:3096
@ half_synchronous_weak_last
Definition mdbx.h++:3094
friend constexpr bool operator!=(const cursor &a, const cursor &b) noexcept
Definition mdbx.h++:4165
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++:2940
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3260
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++:4448
bool checkpoint(finalization_latency &latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4109
estimate_result estimate(move_operation operation, slice &key) const
constexpr cache_entry(const MDBX_cache_entry_t &ce) noexcept
Definition mdbx.h++:2777
cache_entry() noexcept
Definition mdbx.h++:2769
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3701
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4423
ptrdiff_t distance_to_end(unsigned deepness=42) const
Definition mdbx.h++:4486
::MDBX_canary canary
Definition mdbx.h++:3921
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++:4112
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++:3744
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++:4353
friend constexpr bool operator!=(const txn &a, const txn &b) noexcept
Definition mdbx.h++:3719
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++:4417
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++:4426
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++:2778
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
void reset() noexcept
Definition mdbx.h++:2776
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2934
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2914
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4540
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4371
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++:4362
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++:4188
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3800
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3976
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4394
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4180
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4184
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++:3885
constexpr MDBX_txn * handle() noexcept
Definition mdbx.h++:3717
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3187
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4378
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4598
MDBX_txn * handle_
Definition mdbx.h++:3702
void abort()
Abandon all the operations of the transaction instead of saving ones.
MDBX_commit_latency finalization_latency
Definition mdbx.h++:4074
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++:4350
mode
Operation mode.
Definition mdbx.h++:3084
@ write_mapped_io
Definition mdbx.h++:3087
@ nested_transactions
Definition mdbx.h++:3088
@ readonly
Definition mdbx.h++:3085
@ write_file_io
Definition mdbx.h++:3086
friend constexpr bool operator==(const cursor &a, const cursor &b) noexcept
Definition mdbx.h++:4162
bool is_writemap() const
Definition mdbx.h++:3353
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4347
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3321
operator::mdbx::txn() const
Definition mdbx.h++:4517
MDBX_env * handle_
Definition mdbx.h++:2983
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++:4410
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4176
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4360
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4380
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:2772
bool is_nested_transactions_available() const
Definition mdbx.h++:3357
void close()
Explicitly closes the cursor.
constexpr MDBX_env * handle() noexcept
Definition mdbx.h++:2998
bool scan_until_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4306
void abort(finalization_latency &latency)
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4081
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++:4391
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3741
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++:4456
env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede=true)
ptrdiff_t distance_from_first(unsigned deepness=42) const
Definition mdbx.h++:4483
void append(map_handle map, const pair &kv, bool multivalue_order_preserved=true)
Definition mdbx.h++:4024
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3291
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3301
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3303
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3298
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4365
cursor_managed & operator=(cursor_managed &&other) noexcept
::MDBX_dbi_state_t state
Definition mdbx.h++:2945
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3516
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4567
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++:3266
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4420
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++:4452
ptrdiff_t distance_to(const cursor to, unsigned deepness=42) const
Definition mdbx.h++:4480
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4382
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4379
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4518
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3262
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2937
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3797
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2928
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++:4397
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3327
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3973
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++:6194
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4040
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++:3273
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++:3878
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2925
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++:4123
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++:4032
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++:4126
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++:2931
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++:4432
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4198
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4213
@ multi_exactkey_value_equal
Definition mdbx.h++:4230
@ pair_greater_or_equal
Definition mdbx.h++:4238
@ key_lesser_than
Definition mdbx.h++:4220
@ next
Definition mdbx.h++:4201
@ pair_exact
Definition mdbx.h++:4237
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4231
@ pair_lesser_or_equal
Definition mdbx.h++:4235
@ batch_samelength
Definition mdbx.h++:4241
@ seek_key
Definition mdbx.h++:4215
@ key_lowerbound
Definition mdbx.h++:4217
@ pair_lesser_than
Definition mdbx.h++:4234
@ pair_equal
Definition mdbx.h++:4236
@ key_greater_than
Definition mdbx.h++:4224
@ batch_samelength_next
Definition mdbx.h++:4242
@ multi_find_pair
Definition mdbx.h++:4212
@ key_greater_or_equal
Definition mdbx.h++:4223
@ key_exact
Definition mdbx.h++:4216
@ key_equal
Definition mdbx.h++:4222
@ multi_currentkey_prevvalue
Definition mdbx.h++:4207
@ key_lesser_or_equal
Definition mdbx.h++:4221
@ multi_nextkey_firstvalue
Definition mdbx.h++:4210
@ get_current
Definition mdbx.h++:4203
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4229
@ multi_prevkey_lastvalue
Definition mdbx.h++:4205
@ previous
Definition mdbx.h++:4202
@ last
Definition mdbx.h++:4200
@ pair_greater_than
Definition mdbx.h++:4239
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4228
@ multi_currentkey_firstvalue
Definition mdbx.h++:4206
@ first
Definition mdbx.h++:4199
@ batch_samelength_previous
Definition mdbx.h++:4243
@ multi_currentkey_nextvalue
Definition mdbx.h++:4208
@ seek_and_batch_samelength
Definition mdbx.h++:4244
@ multi_exactkey_value_greater
Definition mdbx.h++:4232
@ multi_currentkey_lastvalue
Definition mdbx.h++:4209
finalization_latency commit_get_latency()
Commits all changes of the transaction into a database and return latency information.
Definition mdbx.h++:4098
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4356
void insert(const pair &kv)
Definition mdbx.h++:4541
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3738
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++:4543
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4368
constexpr const MDBX_txn * handle() const noexcept
Definition mdbx.h++:3716
bool is_cooperative() const
Definition mdbx.h++:3351
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3898
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4407
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++:4375
bool is_readonly() const
Definition mdbx.h++:3347
value_result try_insert(const pair &kv)
Definition mdbx.h++:4542
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++:4559
constexpr cursor() noexcept=default
bool is_exclusive() const
Definition mdbx.h++:3349
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4385
finalization_latency abort_get_latency()
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4084
constexpr MDBX_cursor * handle() noexcept
Definition mdbx.h++:4161
bool is_readwrite() const
Definition mdbx.h++:3355
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4429
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3270
MDBX_cursor * handle_
Definition mdbx.h++:4145
MDBX_dbi dbi
Definition mdbx.h++:2912
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4401
friend constexpr bool operator!=(const env &a, const env &b) noexcept
Definition mdbx.h++:3000
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4372
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3752
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++:4413
ptrdiff_t distance_from(const cursor from, unsigned deepness=42) const
Definition mdbx.h++:4476
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3318
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3268
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3975
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3974
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++:3906
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4388
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++:4361
friend class txn
Definition mdbx.h++:2980
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4172
friend constexpr bool operator==(const txn &a, const txn &b) noexcept
Definition mdbx.h++:3718
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3264
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3755
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4301
Unmanaged cursor.
Definition mdbx.h++:4143
Managed cursor.
Definition mdbx.h++:4579
Unmanaged database environment.
Definition mdbx.h++:2979
Managed database environment.
Definition mdbx.h++:3625
Unmanaged database transaction.
Definition mdbx.h++:3699
Managed database transaction.
Definition mdbx.h++:4058
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++:5318
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5190
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4857
polymorphic_allocator default_allocator
Definition mdbx.h++:381
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4866
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4948
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++:5164
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++:5102
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++:5093
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5659
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++:5346
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4962
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4707
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++:6075
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6301
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2826
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4844
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:4664
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4942
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5692
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++:4834
void rethrow_captured() const
Definition mdbx.h++:4679
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4842
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6259
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6235
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5311
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5285
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++:5111
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6036
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5978
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5565
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++:5496
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6203
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++:5143
::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++:4864
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6148
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++:5169
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4889
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4790
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6307
::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++:5969
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6160
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5789
void throw_on_failure() const
Definition mdbx.h++:4719
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6382
void update(const slice &key, const slice &value)
Definition mdbx.h++:6378
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:4661
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++:5860
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:5014
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4852
::MDBX_cmp_func comparator
Definition mdbx.h++:2957
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++:5158
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5661
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5632
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6190
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4988
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5429
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5848
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6368
bool is_clean() const noexcept
Definition mdbx.h++:4672
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2819
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4752
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++:5148
path_string::value_type path_char
Definition mdbx.h++:437
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5419
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2823
::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++:5471
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5304
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4932
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4686
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++:5174
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4614
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5045
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++:6103
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++:5603
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++:5568
void insert(const slice &key, slice value)
Definition mdbx.h++:6329
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6263
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++:5744
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:5239
::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++:2807
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++:5184
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4774
~cursor() noexcept
Definition mdbx.h++:6177
~txn() noexcept
Definition mdbx.h++:5653
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5501
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:5138
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6255
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++:4870
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6309
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6354
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5296
map_handle map() const
Definition mdbx.h++:6314
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++:5512
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:4668
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6247
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5760
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6267
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2887
void success_or_throw() const
Definition mdbx.h++:4724
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5696
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4904
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5552
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4992
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6194
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6273
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4900
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5302
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4909
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5666
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6372
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5427
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2815
void capture() noexcept
Definition mdbx.h++:4674
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:5120
bool scroll(intptr_t distable, unsigned deepness=42, bool throw_notfound=true)
Definition mdbx.h++:6459
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++:5825
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6014
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4883
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2958
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6347
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++:5608
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++:5366
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++:5507
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:6136
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5433
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5785
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6154
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++:6112
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5437
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5711
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4996
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6185
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5819
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6213
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++:5342
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++:5864
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5292
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5837
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6000
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4927
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4701
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++:5518
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4954
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4826
bool on_first() const
Definition mdbx.h++:6281
::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++:4862
bool eof() const
Definition mdbx.h++:6279
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5694
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5680
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5489
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6321
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5617
::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++:5133
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5641
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4894
bool seek(const slice &key)
Definition mdbx.h++:6271
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5541
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5491
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4916
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++:5410
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5787
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++:5530
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5255
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4877
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6334
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++:6435
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4737
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4695
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5678
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2966
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5195
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++:5179
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++:5522
::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++:5388
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5261
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4984
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++:5842
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6413
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5441
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5088
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5686
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5954
::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++:4709
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:5115
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:5097
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6241
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4969
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:5106
static bool distribute(const cursor from, const cursor to, cursor *cursors_array, intptr_t cursors_array_size, unsigned deepness=42)
Definition mdbx.h++:6473
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:5124
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6028
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5251
~env() noexcept
Definition mdbx.h++:5273
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2788
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5876
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4703
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4872
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++:6117
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6008
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4921
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2791
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5610
::mdbx::filesystem::path path
Definition mdbx.h++:428
bool on_last_multival() const
Definition mdbx.h++:6287
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5483
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5947
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5477
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++:5322
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5573
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6183
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5417
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5723
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2811
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5713
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5535
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4615
bool on_first_multival() const
Definition mdbx.h++:6285
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5935
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:5027
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4937
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5453
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5994
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5300
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++:5153
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6394
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:5698
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6251
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4828
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4850
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++:5236
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5596
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:6051
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4699
bool on_last() const
Definition mdbx.h++:6283
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++:6082
#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++:5465
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5546
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++:6303
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:5129
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5279
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5729
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4693
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5067
constexpr bool is_success() const noexcept
Definition mdbx.h++:4697
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6400
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:5040
cursor & assign(const cursor &)
Definition mdbx.h++:6162
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5639
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5247
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5717
static ptrdiff_t distance_between(const cursor from, const cursor to, unsigned deepness=42)
Definition mdbx.h++:6453
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++:5776
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++:5914
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5831
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4836
@ multi_reverse_samelength
Definition mdbx.h++:2859
@ multi_samelength
Definition mdbx.h++:2844
@ multi_ordinal
Definition mdbx.h++:2851
@ msgpack
Definition mdbx.h++:2874
@ single
Definition mdbx.h++:2827
@ multi
Definition mdbx.h++:2829
@ multi_reverse
Definition mdbx.h++:2836
@ upsert
Insert or update.
Definition mdbx.h++:2968
@ update
Update existing, don't insert new.
Definition mdbx.h++:2969
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2967
@ continue_loop
Definition mdbx.h++:2788
@ exit_loop
Definition mdbx.h++:2788
@ usual
Definition mdbx.h++:2792
@ ordinal
Definition mdbx.h++:2797
@ reverse
Definition mdbx.h++:2794
@ msgpack
Definition mdbx.h++:2802
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2911
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2409
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2112
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++:1990
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2017
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++:2082
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1972
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++:2254
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2295
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++:1243
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++:2638
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++:2203
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++:2033
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2326
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2030
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2418
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2278
constexpr size_t tailroom() const noexcept
Returns the number of bytes that available in currently allocated storage after the currently data en...
Definition mdbx.h++:2005
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2139
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2389
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2292
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2024
buffer & append(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:2448
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2144
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2670
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1545
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1016
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1220
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2331
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2057
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2527
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2053
buffer & append(const byte c)
Definition mdbx.h++:2481
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2303
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++:997
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2308
buffer & operator=(const buffer &src)
Definition mdbx.h++:2435
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1015
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2549
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:1999
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2712
constexpr int64_t as_int64() const
Definition mdbx.h++:1022
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2050
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2628
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++:2185
const bool ignore_spaces
Definition mdbx.h++:1323
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++:2267
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++:2261
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2180
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2491
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2223
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++:1085
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++:2681
constexpr int16_t as_int16() const
Definition mdbx.h++:1024
slice value
Definition mdbx.h++:1049
::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++:2683
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2414
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++:2247
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2648
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1191
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++:2273
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2177
slice value
Definition mdbx.h++:1063
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2674
::std::ostream & output(::std::ostream &out) const
Output hexadecimal dump of passed slice to the std::ostream.
pair_result(const pair_result &) noexcept=default
allocation_aware_details::swap_alloc< struct silo, allocator_type > swap_alloc
Definition mdbx.h++:1967
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2654
const slice source
Definition mdbx.h++:1322
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2692
const slice source
Definition mdbx.h++:1158
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++:2211
constexpr buffer & assign(buffer &&src) noexcept(allocation_aware_details::move_assign_alloc< silo, allocator_type >::is_nothrow())
Definition mdbx.h++:2375
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++:1305
const unsigned wrap_width
Definition mdbx.h++:1160
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2444
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2634
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:712
const slice & slice() const noexcept
Definition mdbx.h++:2666
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2397
const bool ignore_spaces
Definition mdbx.h++:1289
constexpr POD as_pod() const
Definition mdbx.h++:999
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++:1112
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++:1389
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2687
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2385
constexpr buffer(const buffer &src)
Definition mdbx.h++:2122
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++:2240
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1012
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2466
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2070
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2640
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2318
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1161
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2689
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2523
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2620
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1510
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2155
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:734
std::pair< slice, slice > stl_pair
Definition mdbx.h++:1062
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2547
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:1984
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
@ pettiness_threshold
Definition mdbx.h++:1499
@ extra_inplace_storage
Definition mdbx.h++:1497
@ max_reserve
Definition mdbx.h++:1500
@ inplace_storage_size_rounding
Definition mdbx.h++:1498
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2652
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:675
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1324
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2439
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2519
constexpr int8_t as_int8() const
Definition mdbx.h++:1025
constexpr ::std::span< char > chars()
Definition mdbx.h++:687
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1044
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1262
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2107
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++:1503
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1234
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++:1380
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:1051
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2632
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1351
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2235
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2150
const slice source
Definition mdbx.h++:1201
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:1065
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2403
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++:1976
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2656
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++:1363
buffer_pair_spec & operator=(buffer_pair_spec &&src)
Definition mdbx.h++:2716
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2582
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++:1195
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1546
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++:2646
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2101
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2441
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2732
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2499
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2570
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2531
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++:1341
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++:1312
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:631
pair & operator=(pair &&couple) noexcept
Definition mdbx.h++:1069
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++:2218
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2662
slice inherited
Definition mdbx.h++:1539
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:1113
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1290
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2658
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++:2660
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2297
static constexpr pair invalid() noexcept
Definition mdbx.h++:1078
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2090
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2393
bool done
Definition mdbx.h++:1111
::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++:1237
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:684
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:700
allocation_aware_details::move_assign_alloc< silo, allocator_type > move_assign_alloc
Definition mdbx.h++:1965
const bool uppercase
Definition mdbx.h++:1159
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1966
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2037
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2351
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2489
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2535
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2700
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2044
const bool ignore_spaces
Definition mdbx.h++:1362
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1246
pair(const pair &) noexcept=default
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2614
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:992
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++:1020
slice key
Definition mdbx.h++:1063
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2473
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:1064
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2706
const slice source
Definition mdbx.h++:1361
pair_result & operator=(const pair_result &) noexcept=default
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2471
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1279
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2664
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2463
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2672
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++:1023
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++:2197
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2126
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1541
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2636
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2010
pair & operator=(const stl_pair &couple)
Definition mdbx.h++:1080
int64_t as_int64_adapt() const
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2644
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2013
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++:2192
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2322
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2698
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1017
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2673
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2135
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1969
buffer & append(const ::std::basic_string< CHAR, T, A > &str)
Definition mdbx.h++:2458
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2539
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2559
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1014
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2162
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++:2694
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2642
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++:2230
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2596
const unsigned wrap_width
Definition mdbx.h++:1202
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++:2515
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2174
const unsigned wrap_width
Definition mdbx.h++:1244
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2437
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++:989
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2064
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++:2501
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2709
buffer_pair_spec(const txn &transaction, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2703
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++:2508
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2130
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2625
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2671
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++:1283
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++:1204
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2118
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++:1176
bool done
Definition mdbx.h++:1050
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++:1288
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:1993
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2075
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1537
Definition mdbx.h++:2669
Type tag for delivered buffer template classes.
Definition mdbx.h++:1533
Definition mdbx.h++:1495
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1321
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1360
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1287
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:1061
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:1110
References a data located outside the slice.
Definition mdbx.h++:626
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1200
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1242
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1157
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:1048
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++:4695
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++:4693
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:5019
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:5023
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++:1397
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1399
The libmdbx C++ API namespace.
Definition mdbx.h++:307
STL namespace.
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6526
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1632
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1634
byte lastbyte_
Definition mdbx.h++:1633
Definition mdbx.h++:4263
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4265
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4264
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4267
Definition mdbx.h++:4251
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++:4255
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4253
Tagged type for output to std::ostream.
Definition mdbx.h++:3033
intptr_t bytes
Definition mdbx.h++:3034
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3035
Database geometry for size management.
Definition mdbx.h++:3009
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3057
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3069
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3016
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3012
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3015
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3024
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3013
@ default_value
Means "keep current or use default".
Definition mdbx.h++:3011
@ kB
bytes (0x03E8)
Definition mdbx.h++:3014
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3023
@ KiB
bytes (0x0400)
Definition mdbx.h++:3022
constexpr geometry() noexcept
Definition mdbx.h++:3073
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3060
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3045
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3063
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3040
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++:3076
Operate options.
Definition mdbx.h++:3111
bool disable_readahead
Definition mdbx.h++:3120
bool enable_validation
Definition mdbx.h++:3124
bool no_sticky_threads
Definition mdbx.h++:3113
constexpr operate_options() noexcept
Definition mdbx.h++:3125
bool disable_clear_memory
Definition mdbx.h++:3122
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3118
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
bool nested_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3116
Operate parameters.
Definition mdbx.h++:3133
env::durability durability
Definition mdbx.h++:3141
env::operate_options options
Definition mdbx.h++:3143
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++:3147
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++:3139
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3142
env::mode mode
Definition mdbx.h++:3140
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++:3136
constexpr operate_parameters() noexcept
Definition mdbx.h++:3145
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3539
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3542
uint64_t transaction_lag
Definition mdbx.h++:3545
size_t bytes_used
Definition mdbx.h++:3549
uint64_t transaction_id
Definition mdbx.h++:3543
int slot
The reader lock table slot number.
Definition mdbx.h++:3540
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3541
size_t bytes_retained
Definition mdbx.h++:3552
Garbage reclaiming options.
Definition mdbx.h++:3100
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++:3103
bool lifo
Definition mdbx.h++:3102
Additional parameters for creating a new database.
Definition mdbx.h++:3648
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3650
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3651
env::geometry geometry
Definition mdbx.h++:3649
Definition mdbx.h++:2946
map_handle::state state
Definition mdbx.h++:2948
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2947
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6631
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6627
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6626
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6617
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6616
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6612
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6608
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6621
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6622
capacity_holder capacity_
Definition mdbx.h++:1638
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1671
allocator_pointer stub_ptr_
Definition mdbx.h++:1613
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1650
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1691
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1642
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1657
inplace_flag_holder inplace_
Definition mdbx.h++:1639
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1641
allocator_pointer allocated_ptr_
Definition mdbx.h++:1637
size_t stub_capacity_bytes_
Definition mdbx.h++:1614
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1710
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1627
size_t bytes_
Definition mdbx.h++:1628
constexpr const byte * address() const noexcept
Definition mdbx.h++:1704
constexpr bin() noexcept
Definition mdbx.h++:1685
@ inplace_size
Definition mdbx.h++:1622
@ inplace_signature_limit
Definition mdbx.h++:1619
@ inplace_size_rounding
Definition mdbx.h++:1621
constexpr byte * address() noexcept
Definition mdbx.h++:1707
@ lastbyte_poison
Definition mdbx.h++:1617
@ lastbyte_inplace_signature
Definition mdbx.h++:1617
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1700
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1659