libmdbx 0.14.1.539 (2026-04-07T09:49:22+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
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) {
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 % 2 == 0, "pettiness_threshold must be even");
1506 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1507 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1508 return (value + pettiness_threshold - 1) & pettiness_mask;
1509 }
1510
1511 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1512 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1513 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1514
1515 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1516 return inplace;
1517
1518 if (wanna > current)
1519 /* doubling capacity, but don't made reserve more than max_reserve */
1520 return round(wanna + ::std::min(size_t(max_reserve), current));
1521
1522 if (current - wanna >
1523 /* shrink if reserve will more than half of current or max_reserve,
1524 * but not less than pettiness_threshold */
1525 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1526 return round(wanna);
1527
1528 /* keep unchanged */
1529 return current;
1530 }
1531};
1532
1534struct buffer_tag {};
1535
1537template <class ALLOCATOR, typename CAPACITY_POLICY>
1539public:
1541#if !defined(_MSC_VER) || _MSC_VER > 1900
1542 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1543#else
1544 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1545#endif /* MSVC is mad */
1546 using allocator_traits = ::std::allocator_traits<allocator_type>;
1547 using reservation_policy = CAPACITY_POLICY;
1548 enum : size_t {
1550 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1553 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1554 ? alignof(max_align_t) * 2
1557 };
1558
1559private:
1560 friend class txn;
1561 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1562 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1563 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1564
1565 using allocator_pointer = typename allocator_traits::pointer;
1566 using allocator_const_pointer = typename allocator_traits::const_pointer;
1567
1568 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1569 MDBX_INLINE_API_ASSERT(bytes >= sizeof(bin));
1570 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1571 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1572 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1573 const size_t n = (bytes + unit - 1) / unit;
1574 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1575 }
1576
1577 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1578 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1579 MDBX_INLINE_API_ASSERT(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1580 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1581 }
1582
1583 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1584 const size_t capacity = bin::advise_capacity(0, bytes);
1585 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1586 : allocate_storage(capacity);
1587 }
1588
1589 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1590#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1591 return static_cast<void *>(::std::to_address(ptr));
1592#else
1593 return static_cast<void *>(::std::addressof(*ptr));
1594#endif /* __cpp_lib_to_address */
1595 }
1596
1597 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1598#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1599 return static_cast<const void *>(::std::to_address(ptr));
1600#else
1601 return static_cast<const void *>(::std::addressof(*ptr));
1602#endif /* __cpp_lib_to_address */
1603 }
1604
1605#ifdef _MSC_VER
1606#pragma warning(push)
1607#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1608#endif /* _MSC_VER */
1609
1610 union alignas(max_align_t) bin {
1611 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1612 с учетом выравнивания */
1613 {
1614 allocator_pointer stub_ptr_;
1616 };
1617
1619 enum : size_t {
1621 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1625 };
1626
1628 byte pad_[inplace_size - sizeof(allocator_pointer)];
1629 size_t bytes_;
1630 };
1631
1633 byte buffer_[inplace_size - sizeof(byte)];
1635 MDBX_CXX11_CONSTEXPR inplace_flag_holder(byte signature) : lastbyte_(signature) {};
1636 };
1637
1638 allocator_pointer allocated_ptr_;
1641
1642 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1643 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1644 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1645 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1646 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1647 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1648 return capacity_bytes <= inplace_capacity();
1649 }
1650
1651 constexpr bool is_inplace() const noexcept {
1652 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1653 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1655 "WTF?");
1656 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1657 }
1658 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1659
1660 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1661 if (destroy_ptr) {
1663 /* properly destroy allocator::pointer */
1664 allocated_ptr_.~allocator_pointer();
1665 }
1668 return address();
1669 }
1670
1671 template <bool construct_ptr>
1672 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1674 if (construct_ptr) {
1676 new (&allocated_ptr_) allocator_pointer(pair.first);
1677 } else {
1679 allocated_ptr_ = pair.first;
1680 }
1681 capacity_.bytes_ = pair.second;
1682 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1683 return address();
1684 }
1685
1687 if (::std::is_trivial<allocator_pointer>::value)
1688 /* workaround for "uninitialized" warning from some compilers */
1689 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1690 }
1691
1692 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1693 if (MDBX_UNLIKELY(wanna > max_capacity))
1694 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1695
1696 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1697 MDBX_INLINE_API_ASSERT(advised >= wanna);
1698 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1699 }
1700
1701 constexpr bool is_inplace(const void *ptr) const noexcept {
1702 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1703 }
1704
1705 constexpr const byte *address() const noexcept {
1706 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1707 }
1709 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1710 }
1711 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1712 } bin_;
1713
1714#ifdef _MSC_VER
1715#pragma warning(pop)
1716#endif /* _MSC_VER */
1717
1718 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1719
1720 MDBX_CXX20_CONSTEXPR void release() noexcept {
1721 if (bin_.is_allocated()) {
1722 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1723 /* properly destroy allocator::pointer */
1724 bin_.allocated_ptr_.~allocator_pointer();
1725 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1726 }
1727 }
1728
1729 template <bool external_content>
1730 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1731 const void *const content, const size_t length) {
1732 MDBX_INLINE_API_ASSERT(wanna_capacity >= wanna_headroom + length);
1733 const size_t old_capacity = bin_.capacity();
1734 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1735 if (MDBX_LIKELY(new_capacity == old_capacity))
1737 MDBX_INLINE_API_ASSERT(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1738 byte *const new_place = bin_.address() + wanna_headroom;
1739 if (MDBX_LIKELY(length))
1741 if (external_content)
1742 memcpy(new_place, content, length);
1743 else {
1744 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1745 MDBX_INLINE_API_ASSERT(old_capacity >= old_headroom + length);
1746 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1747 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1748 }
1749 }
1750 return new_place;
1751 }
1752
1753 if (bin::is_suitable_for_inplace(new_capacity)) {
1754 MDBX_INLINE_API_ASSERT(bin_.is_allocated());
1755 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
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 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1817 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1818 /* properly destroy allocator::pointer.
1819 *
1820 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1821 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1822 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1823 * from the 11th). */
1824 /* coverity[use_after_move] */
1825 other.bin_.allocated_ptr_.~allocator_pointer();
1826 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1827 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1828 }
1829 }
1830 }
1831
1832 MDBX_CXX17_CONSTEXPR bool move(silo &&other) noexcept {
1833 if (other.bin_.is_inplace()) {
1834 memcpy(&bin_, &other.bin_, sizeof(bin));
1835 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1836 return /* buffer's slice fixup is needed */ true;
1837 }
1838 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1839 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1840 /* properly destroy allocator::pointer.
1841 *
1842 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1843 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1844 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1845 * from the 11th). */
1846 /* coverity[use_after_move] */
1847 other.bin_.allocated_ptr_.~allocator_pointer();
1848 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1849 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1850 return false;
1851 }
1852
1853 MDBX_CXX17_CONSTEXPR bool assign_move(silo &&other, bool is_reference) noexcept {
1854 release();
1855 if (!allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, other))
1856 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, other);
1857 return is_reference ? false : move(std::move(other));
1858 }
1859
1860 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1861 exchange(silo &left, const bool left_is_reference, silo &right, const bool right_is_reference) noexcept(
1862 allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1863 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(left, right);
1864 bool left_need_fixup = false, right_need_fixup = false;
1865 if (left_is_reference || right_is_reference) {
1866 left_need_fixup = !right_is_reference && left.move(std::move(right));
1867 right_need_fixup = !left_is_reference && right.move(std::move(left));
1868 } else {
1869 silo temp(std::move(left), false);
1870 left_need_fixup = left.move(std::move(right));
1871 right_need_fixup = right.move(std::move(temp));
1872 }
1873 return std::make_pair(left_need_fixup, right_need_fixup);
1874 }
1875
1876 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1877 const allocator_type &alloc = allocator_type())
1878 : silo(capacity, alloc) {
1879 MDBX_INLINE_API_ASSERT(capacity >= headroom + length);
1880 if (length)
1881 put(headroom, ptr, length);
1882 }
1883
1884 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1885 : silo(length, 0, ptr, length, alloc) {}
1886
1887 ~silo() { release(); }
1888
1889 //--------------------------------------------------------------------------
1890
1891 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1892 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1893 }
1894
1895 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1896
1897 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1898 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1899 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1900 }
1901
1902 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1903 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1904 }
1905
1906 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1907 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1908 return get(offset);
1909 }
1910 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1911 };
1912
1913 MDBX_CXX14_CONSTEXPR void fixup_import(const typename silo::bin &src) noexcept {
1914 auto ptr = inherited::byte_ptr();
1915 if (src.is_inplace(ptr)) {
1916 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1917 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1918 iov_base = ptr + offset;
1919 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1920 }
1921 }
1922
1923 silo silo_;
1924
1925 void insulate() {
1926 MDBX_INLINE_API_ASSERT(is_reference());
1927 iov_base = silo_.assign(iov_base, iov_len);
1928 }
1929
1930 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1931 return static_cast<const byte *>(silo_.data());
1932 }
1933
1934 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1935 return silo_begin() + silo_.capacity();
1936 }
1937
1938 struct data_preserver : public exception_thunk {
1939 buffer data;
1940 data_preserver(allocator_type &alloc) : data(alloc) {}
1941 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1942 auto self = static_cast<data_preserver *>(context);
1943 assert(self->is_clean());
1944 assert(&self->data == target);
1945 (void)target;
1946 try {
1947 self->data.assign(src, bytes, false);
1948 return MDBX_RESULT_FALSE;
1949 } catch (... /* capture any exception to rethrow it over C code */) {
1950 self->capture();
1951 return MDBX_RESULT_TRUE;
1952 }
1953 }
1954 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1955 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1956 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1957 };
1958
1959public:
1962
1966
1967 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1968
1970 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1971
1975 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1976 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1977 }
1978
1983 return silo_.is_inplace(inherited::data());
1984 }
1985
1989
1992 return is_freestanding() ? silo_.capacity() : 0;
1993 }
1994
1998 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
1999 }
2000
2004 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2005 }
2006
2008 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2009
2011 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2012
2019
2024 return const_cast<byte *>(inherited::end_byte_ptr());
2025 }
2026
2028 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2029
2031 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2032
2037 return const_cast<char *>(inherited::char_ptr());
2038 }
2039
2044 return const_cast<char *>(inherited::end_char_ptr());
2045 }
2046
2048 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
2049
2051 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
2052
2055 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2057 return const_cast<void *>(inherited::data());
2058 }
2059
2062 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2064 return const_cast<void *>(inherited::end());
2065 }
2066
2071
2078
2081 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2082 return set_length(static_cast<const char *>(ptr) - char_ptr());
2083 }
2084
2089 if (is_reference())
2090 insulate();
2091 }
2092
2093 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2094 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2095 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2096 const allocator_type &alloc = allocator_type());
2097
2099 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2100 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2101
2102 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2103 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2104
2105 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2106 : buffer(inherited(c_str), make_reference, alloc) {}
2107
2108#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2109 template <class CHAR, class T>
2110 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2111 const allocator_type &alloc = allocator_type())
2112 : buffer(inherited(view), make_reference, alloc) {}
2113#endif /* __cpp_lib_string_view >= 201606L */
2114
2116 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2117 : buffer(src, src.empty() || src.is_null(), alloc) {}
2118
2120 buffer(const buffer &src)
2121 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2122
2124 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2125 : buffer(inherited(ptr, bytes), alloc) {}
2126
2127 template <class CHAR, class T, class A>
2128 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2129 const allocator_type &alloc = allocator_type())
2130 : buffer(inherited(str), alloc) {}
2131
2133 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2134
2135#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2136 template <class CHAR, class T>
2137 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2138 const allocator_type &alloc = allocator_type())
2139 : buffer(inherited(view), alloc) {}
2140#endif /* __cpp_lib_string_view >= 201606L */
2141
2142 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2143 : silo_(check_length(head_room, tail_room), alloc) {
2144 iov_base = silo_.get();
2145 MDBX_INLINE_API_ASSERT(iov_len == 0);
2146 }
2147
2148 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2149 iov_base = silo_.get();
2150 MDBX_INLINE_API_ASSERT(iov_len == 0);
2151 }
2152
2153 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2154 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2155 iov_base = memcpy(silo_.get(), src.data(), iov_len = src.length());
2156 }
2157
2158 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2159
2160 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2161 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2162 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2163 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2164 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2165 * 11th). */
2166 /* coverity[use_after_move] */
2167 fixup_import(src.silo_.bin_);
2168 src.invalidate();
2169 }
2170
2172 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2173
2176
2177 template <typename POD>
2178 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2179 return buffer(inherited::wrap(pod), make_reference, alloc);
2180 }
2181
2183 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2184 const allocator_type &alloc = allocator_type()) {
2185 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2186 }
2187
2190 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2191 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2192 }
2193
2195 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2196 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2197 }
2198
2200 template <typename POD>
2201 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2202 const allocator_type &alloc = allocator_type()) {
2203 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2204 }
2205
2208 template <typename POD>
2209 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2210 return base58(inherited::wrap(pod), wrap_width, alloc);
2211 }
2212
2215 template <typename POD>
2216 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2217 return base64(inherited::wrap(pod), wrap_width, alloc);
2218 }
2219
2221 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2222 const allocator_type &alloc = allocator_type()) const {
2223 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2224 }
2225
2228 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2229 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2230 }
2231
2233 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2234 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2235 }
2236
2238 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2239 const allocator_type &alloc = allocator_type()) {
2240 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2241 }
2242
2245 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2246 const allocator_type &alloc = allocator_type()) {
2247 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2248 }
2249
2252 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2253 const allocator_type &alloc = allocator_type()) {
2254 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2255 }
2256
2259 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2260 return hex_decode(*this, ignore_spaces, alloc);
2261 }
2262
2265 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2266 return base58_decode(*this, ignore_spaces, alloc);
2267 }
2268
2271 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2272 return base64_decode(*this, ignore_spaces, alloc);
2273 }
2274
2276 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2277 wanna_headroom = ::std::min(
2278 ::std::max(headroom(), wanna_headroom),
2279 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2280 wanna_tailroom = ::std::min(
2281 ::std::max(tailroom(), wanna_tailroom),
2282 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2283 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2284 silo_.resize(wanna_capacity, wanna_headroom, *this);
2285 MDBX_INLINE_API_ASSERT(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2286 MDBX_INLINE_API_ASSERT(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2287 }
2288
2290 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2291
2293 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2294
2295 buffer &assign_reference(const void *ptr, size_t bytes) {
2296 silo_.clear();
2298 return *this;
2299 }
2300
2301 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2302 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2303 return *this;
2304 }
2305
2306 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2307 const auto pair = silo::exchange(silo_, is_reference(), other.silo_, other.is_reference());
2308 std::swap(iov_base, other.iov_base);
2309 std::swap(iov_len, other.iov_len);
2310 if (pair.first)
2311 fixup_import(other.silo_.bin_);
2312 if (pair.second)
2313 other.fixup_import(silo_.bin_);
2314 }
2315
2316 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2317 left.swap(right);
2318 }
2319
2320 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2321 return buffer(src.headroom(), src, src.tailroom(), alloc);
2322 }
2323
2325 return buffer(slice(), !is_inplace(), allocator_traits::select_on_container_copy_construction(get_allocator()));
2326 }
2327
2329 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2330 invalidate();
2331 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2332 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2333 MDBX_CXX20_UNLIKELY {
2334 silo_.release();
2336 }
2337 }
2338
2339 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2340 iov_len = src.length();
2341 return *this;
2342 }
2343
2344 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2345 invalidate();
2346 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2347 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2348 MDBX_CXX20_UNLIKELY {
2349 silo_.release();
2351 }
2352 }
2353
2354 if (make_reference) {
2355 silo_.release();
2356 iov_base = src.iov_base;
2357 } else {
2358 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2359 }
2360 iov_len = src.length();
2361 return *this;
2362 }
2363
2366 const bool is_reference = src.is_reference();
2367 inherited::assign(std::move(src));
2368 if (silo_.assign_move(std::move(src.silo_), is_reference))
2369 fixup_import(src.silo_.bin_);
2370 return *this;
2371 }
2372
2373 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2374 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2375 }
2376
2377 buffer &assign(const struct slice &src, bool make_reference = false) {
2378 return assign(src.data(), src.length(), make_reference);
2379 }
2380
2381 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2382 return assign(src.iov_base, src.iov_len, make_reference);
2383 }
2384
2385 buffer &assign(struct slice &&src, bool make_reference = false) {
2386 assign(src.data(), src.length(), make_reference);
2387 src.invalidate();
2388 return *this;
2389 }
2390
2391 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2392 assign(src.iov_base, src.iov_len, make_reference);
2393 src.iov_base = nullptr;
2394 return *this;
2395 }
2396
2397 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2398 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2399 }
2400
2401 template <class CHAR, class T, class A>
2402 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2403 return assign(str.data(), str.length(), make_reference);
2404 }
2405
2406 buffer &assign(const char *c_str, bool make_reference = false) {
2407 return assign(c_str, strlen(c_str), make_reference);
2408 }
2409
2410#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2411 template <class CHAR, class T>
2412 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2413 return assign(view.data(), view.length(), make_reference);
2414 }
2415
2416 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2417 assign(view.data(), view.length(), make_reference);
2418 view = {};
2419 return *this;
2420 }
2421#endif /* __cpp_lib_string_view >= 201606L */
2422
2423 buffer &operator=(const buffer &src) { return assign(src); }
2424
2425 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2426
2427 buffer &operator=(const struct slice &src) { return assign(src); }
2428
2429 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2430
2431#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2432 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2433 return assign(view.begin(), view.length());
2434 }
2435#endif /* __cpp_lib_string_view >= 201606L */
2436
2437 template <class CHAR, class T, class A>
2438 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2439 return as_string<CHAR, T, A>();
2440 }
2441
2443 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2444
2446 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2447 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2448 }
2449
2451 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2452
2453 buffer &append(const void *src, size_t bytes) {
2454 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2455 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2456 memcpy(end_byte_ptr(), src, bytes);
2457 iov_len += bytes;
2458 return *this;
2459 }
2460
2461 buffer &append(const byte c) {
2462 if (MDBX_UNLIKELY(tailroom() < 1))
2463 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2464 *end_byte_ptr() = c;
2465 iov_len += 1;
2466 return *this;
2467 }
2468
2469 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2470
2471 buffer &add_header(const void *src, size_t bytes) {
2472 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2473 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2474 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2475 iov_len += bytes;
2476 return *this;
2477 }
2478
2479 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2480
2481 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2482 const size_t wanna_bytes = producer.envisage_result_length();
2483 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2484 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2485 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2486 }
2487
2488 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2489 const size_t wanna_bytes = producer.envisage_result_length();
2490 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2491 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2492 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2493 }
2494
2495 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2496 return append_producer(to_hex(data, uppercase, wrap_width));
2497 }
2498
2499 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2500 return append_producer(to_base58(data, wrap_width));
2501 }
2502
2503 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2504 return append_producer(to_base64(data, wrap_width));
2505 }
2506
2507 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2508 return append_producer(from_hex(data, ignore_spaces));
2509 }
2510
2511 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2512 return append_producer(from_base58(data, ignore_spaces));
2513 }
2514
2515 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2516 return append_producer(from_base64(data, ignore_spaces));
2517 }
2518
2519 buffer &append_u8(uint_fast8_t u8) {
2520 if (MDBX_UNLIKELY(tailroom() < 1))
2521 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2522 *end_byte_ptr() = uint8_t(u8);
2523 iov_len += 1;
2524 return *this;
2525 }
2526
2527 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2528
2529 buffer &append_u16(uint_fast16_t u16) {
2530 if (MDBX_UNLIKELY(tailroom() < 2))
2531 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2532 const auto ptr = end_byte_ptr();
2533 ptr[0] = uint8_t(u16);
2534 ptr[1] = uint8_t(u16 >> 8);
2535 iov_len += 2;
2536 return *this;
2537 }
2538
2539 buffer &append_u24(uint_fast32_t u24) {
2540 if (MDBX_UNLIKELY(tailroom() < 3))
2541 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2542 const auto ptr = end_byte_ptr();
2543 ptr[0] = uint8_t(u24);
2544 ptr[1] = uint8_t(u24 >> 8);
2545 ptr[2] = uint8_t(u24 >> 16);
2546 iov_len += 3;
2547 return *this;
2548 }
2549
2550 buffer &append_u32(uint_fast32_t u32) {
2551 if (MDBX_UNLIKELY(tailroom() < 4))
2552 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2553 const auto ptr = end_byte_ptr();
2554 ptr[0] = uint8_t(u32);
2555 ptr[1] = uint8_t(u32 >> 8);
2556 ptr[2] = uint8_t(u32 >> 16);
2557 ptr[3] = uint8_t(u32 >> 24);
2558 iov_len += 4;
2559 return *this;
2560 }
2561
2562 buffer &append_u48(uint_fast64_t u48) {
2563 if (MDBX_UNLIKELY(tailroom() < 6))
2564 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2565 const auto ptr = end_byte_ptr();
2566 ptr[0] = uint8_t(u48);
2567 ptr[1] = uint8_t(u48 >> 8);
2568 ptr[2] = uint8_t(u48 >> 16);
2569 ptr[3] = uint8_t(u48 >> 24);
2570 ptr[4] = uint8_t(u48 >> 32);
2571 ptr[5] = uint8_t(u48 >> 40);
2572 iov_len += 6;
2573 return *this;
2574 }
2575
2576 buffer &append_u64(uint_fast64_t u64) {
2577 if (MDBX_UNLIKELY(tailroom() < 8))
2578 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2579 const auto ptr = end_byte_ptr();
2580 ptr[0] = uint8_t(u64);
2581 ptr[1] = uint8_t(u64 >> 8);
2582 ptr[2] = uint8_t(u64 >> 16);
2583 ptr[3] = uint8_t(u64 >> 24);
2584 ptr[4] = uint8_t(u64 >> 32);
2585 ptr[5] = uint8_t(u64 >> 40);
2586 ptr[6] = uint8_t(u64 >> 48);
2587 ptr[7] = uint8_t(u64 >> 56);
2588 iov_len += 8;
2589 return *this;
2590 }
2591
2592 //----------------------------------------------------------------------------
2593
2594 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2595 return buffer(inherited(text), make_reference);
2596 }
2597
2598#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2599 template <class CHAR, class T>
2600 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2601 return buffer(src, make_reference);
2602 }
2603#endif /* __cpp_lib_string_view >= 201606L */
2604
2605 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2606
2607 template <class CHAR, class T, class A>
2608 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2609 return buffer(src, make_reference);
2610 }
2611
2612 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2613
2614 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2615
2616 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2617
2618 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2619
2620 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2621
2622 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2623
2624 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2625
2626 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2627
2628 static buffer key_from_jsonInteger(const int64_t json_integer) {
2629 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2630 }
2631
2632 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2633
2634 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2635
2636 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2637
2638 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2639
2640 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2641
2642 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2643
2644 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2645
2646 const slice &slice() const noexcept { return *this; }
2647};
2648
2649template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2653 using reservation_policy = CAPACITY_POLICY;
2654 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2656
2659 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2660
2662 : key(key, alloc), value(value, alloc) {}
2663 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2664 const allocator_type &alloc = allocator_type())
2665 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2666
2668 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2669 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2670 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2671
2673 : key(key, alloc), value(value, alloc) {}
2674 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2675 const allocator_type &alloc = allocator_type())
2676 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2677
2680 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2681 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2682
2683 buffer_pair_spec(const txn &transacton, const slice &key, const slice &value,
2684 const allocator_type &alloc = allocator_type())
2685 : key(transacton, key, alloc), value(transacton, value, alloc) {}
2686 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2687 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2688
2689 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2690 : key(::std::move(key)), value(::std::move(value)) {}
2692 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2693 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2694
2697 key.assign(std::move(src.key));
2698 value.assign(std::move(src.value));
2699 return *this;
2700 }
2701
2703 key.assign(src.key);
2704 value.assign(src.value);
2705 return *this;
2706 }
2708 key.assign(std::move(src.key));
2709 value.assign(std::move(src.value));
2710 return *this;
2711 }
2713 key.assign(src.first);
2714 value.assign(src.second);
2715 return *this;
2716 }
2718 key.assign(std::move(src.first));
2719 value.assign(std::move(src.second));
2720 return *this;
2721 }
2722
2726 return key.is_freestanding() && value.is_freestanding();
2727 }
2728
2731 return key.is_reference() || value.is_reference();
2732 }
2733
2737 key.make_freestanding();
2738 value.make_freestanding();
2739 }
2740
2741 operator pair() const noexcept { return pair(key, value); }
2742};
2743
2745
2748public:
2749 cache_entry() noexcept { reset(); }
2750 cache_entry(const cache_entry &) noexcept = default;
2751 cache_entry &operator=(const cache_entry &) noexcept = default;
2752 cache_entry(cache_entry &&other) noexcept {
2753 *this = other;
2754 other.reset();
2755 }
2756 void reset() noexcept { mdbx_cache_init(this); }
2757};
2758
2759//------------------------------------------------------------------------------
2760
2763enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2764
2781
2783 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2784}
2785
2787 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2788}
2789
2791 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2792}
2793
2795 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2796}
2797
2799
2857
2861
2863 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2864}
2865
2867 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2868}
2869
2871 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2872}
2873
2875 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2876}
2877
2879
2890 map_handle(const map_handle &) noexcept = default;
2891 map_handle &operator=(const map_handle &) noexcept = default;
2892 operator bool() const noexcept { return dbi != 0; }
2893 operator MDBX_dbi() const { return dbi; }
2894
2895#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2896 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2897 return a.dbi <=> b.dbi;
2898 }
2899#endif /* __cpp_impl_three_way_comparison */
2900 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2901 return a.dbi == b.dbi;
2902 }
2903 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2904 return a.dbi < b.dbi;
2905 }
2906 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2907 return a.dbi > b.dbi;
2908 }
2909 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2910 return a.dbi <= b.dbi;
2911 }
2912 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2913 return a.dbi >= b.dbi;
2914 }
2915 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2916 return a.dbi != b.dbi;
2917 }
2918
2930};
2931
2934 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2935}
2937 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2938}
2939
2946
2955 friend class txn;
2956
2957protected:
2959 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2960
2961public:
2962 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2963 env(const env &) noexcept = default;
2964 env &operator=(const env &) noexcept = default;
2965 inline env &operator=(env &&) noexcept;
2966 inline env(env &&) noexcept;
2967 inline ~env() noexcept;
2968
2969 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
2970 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
2971 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
2972 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
2973 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
2974
2975 //----------------------------------------------------------------------------
2976
2981
2983 enum : intptr_t {
2986 maximal_value = INTPTR_MAX,
2987 kB = 1000,
2988 MB = kB * 1000,
2989 GB = MB * 1000,
2990#if INTPTR_MAX > 0x7fffFFFFl
2991 TB = GB * 1000,
2992 PB = TB * 1000,
2993 EB = PB * 1000,
2994#endif /* 64-bit intptr_t */
2995 KiB = 1024,
2996 MiB = KiB << 10,
2997 GiB = MiB << 10,
2998#if INTPTR_MAX > 0x7fffFFFFl
2999 TiB = GiB << 10,
3000 PiB = TiB << 10,
3001 EiB = PiB << 10,
3002#endif /* 64-bit intptr_t */
3003 };
3004
3006 struct size {
3007 intptr_t bytes;
3008 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3009 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3010 };
3011
3014
3019
3031
3034
3037
3043
3044 inline geometry &make_fixed(intptr_t size) noexcept;
3045 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3048 geometry(const geometry &) noexcept = default;
3054 };
3055
3063
3071
3084
3106
3111 unsigned max_maps{0};
3114 unsigned max_readers{0};
3119
3130 operate_parameters(const operate_parameters &) noexcept = default;
3132 MDBX_env_flags_t make_flags(bool accede = true,
3135 bool use_subdirectory = false
3136 ) const;
3140 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3141 };
3142
3146 inline env::mode get_mode() const;
3148 inline env::durability get_durability() const;
3152 inline env::operate_options get_options() const;
3153
3156 bool is_pristine() const;
3157
3159 bool is_empty() const;
3160
3162 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3163
3164 struct limits {
3165 limits() = delete;
3167 static inline size_t pagesize_min() noexcept;
3169 static inline size_t pagesize_max() noexcept;
3171 static inline size_t dbsize_min(intptr_t pagesize);
3173 static inline size_t dbsize_max(intptr_t pagesize);
3175 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3177 static inline size_t key_min(key_mode mode) noexcept;
3179 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3181 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3183 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3185 static inline size_t key_max(const env &, key_mode mode);
3187 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3189 static inline size_t value_min(value_mode) noexcept;
3190
3192 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3194 static inline size_t value_max(intptr_t pagesize, value_mode);
3196 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3198 static inline size_t value_max(const env &, value_mode);
3199
3202 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3205 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3208 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3211 static inline size_t pairsize4page_max(const env &, value_mode);
3212
3215 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3218 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3221 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3224 static inline size_t valsize4page_max(const env &, value_mode);
3225
3228 static inline size_t transaction_size_max(intptr_t pagesize);
3229
3231 static inline size_t max_map_handles(void);
3232 };
3233
3235 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3237 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3239 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3241 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3243 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3245 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3249
3252#ifdef MDBX_STD_FILESYSTEM_PATH
3253 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3254#endif /* MDBX_STD_FILESYSTEM_PATH */
3255#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3256 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3257 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3258#endif /* Windows */
3259 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3260 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3261
3263 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3264
3280
3282#ifdef MDBX_STD_FILESYSTEM_PATH
3283 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3284#endif /* MDBX_STD_FILESYSTEM_PATH */
3285#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3286 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3287 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3288#endif /* Windows */
3289 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3290 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3291
3294
3297
3299 inline stat get_stat() const;
3300
3302 size_t get_pagesize() const { return get_stat().ms_psize; }
3303
3305 inline info get_info() const;
3306
3308 inline stat get_stat(const txn &) const;
3309
3311 inline info get_info(const txn &) const;
3312
3314 inline filehandle get_filehandle() const;
3315
3317 const path_char *get_path() const;
3318
3320 inline MDBX_env_flags_t get_flags() const;
3321
3322 inline bool is_readonly() const { return (get_flags() & MDBX_RDONLY) != 0; }
3323
3324 inline bool is_exclusive() const { return (get_flags() & MDBX_EXCLUSIVE) != 0; }
3325
3326 inline bool is_cooperative() const { return !is_exclusive(); }
3327
3328 inline bool is_writemap() const { return (get_flags() & MDBX_WRITEMAP) != 0; }
3329
3330 inline bool is_readwite() const { return !is_readonly(); }
3331
3332 inline bool is_nested_transactions_available() const { return (get_flags() & (MDBX_WRITEMAP | MDBX_RDONLY)) == 0; }
3333
3336 inline unsigned max_readers() const;
3337
3340 inline unsigned max_maps() const;
3341
3343 inline void *get_context() const noexcept;
3344
3346 inline env &set_context(void *your_context);
3347
3362 inline env &set_sync_threshold(size_t bytes);
3363
3369 inline size_t sync_threshold() const;
3370
3371#if __cplusplus >= 201103L || defined(DOXYGEN)
3391 inline env &set_sync_period(const duration &period);
3392
3398 inline duration sync_period() const;
3399#endif
3400
3404 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3405
3408 inline unsigned sync_period__seconds_16dot16() const;
3409
3413 inline env &set_sync_period__seconds_double(double seconds);
3414
3417 inline double sync_period__seconds_double() const;
3418
3470
3472 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3473
3475 inline uint64_t extra_option(extra_runtime_option option) const;
3476
3478 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3479
3481 inline env &set_geometry(const geometry &size);
3482
3486 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3487
3491 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3492
3511 inline void close_map(const map_handle &);
3512
3515 int slot;
3524 size_t bytes_used;
3533
3535 size_t used, size_t retained) noexcept;
3536 };
3537
3545 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3546
3549 inline unsigned check_readers();
3550
3569
3574 inline MDBX_hsr_func get_HandleSlowReaders() const noexcept;
3575
3577 inline txn_managed start_read() const;
3578
3580 inline txn_managed prepare_read() const;
3581
3583 inline txn_managed start_write(txn &parent);
3584
3586 inline txn_managed start_write(bool dont_wait = false);
3587
3590};
3591
3600class LIBMDBX_API_TYPE env_managed : public env {
3601 using inherited = env;
3603 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3604 void setup(unsigned max_maps, unsigned max_readers = 0);
3605
3606public:
3607 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3608
3610#ifdef MDBX_STD_FILESYSTEM_PATH
3611 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3612#endif /* MDBX_STD_FILESYSTEM_PATH */
3613#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3614 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3615 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3616#endif /* Windows */
3617 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3618 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3619
3630
3632#ifdef MDBX_STD_FILESYSTEM_PATH
3634 bool accede = true);
3635#endif /* MDBX_STD_FILESYSTEM_PATH */
3636#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3637 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3638 bool accede = true);
3639 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3640 bool accede = true);
3641#endif /* Windows */
3642 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3643 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3644
3658 void close(bool dont_sync = false);
3659
3660 env_managed(env_managed &&) = default;
3661 env_managed &operator=(env_managed &&other) noexcept {
3663 MDBX_CXX20_UNLIKELY {
3664 assert(handle_ != other.handle_);
3665 close();
3666 }
3667 inherited::operator=(std::move(other));
3668 return *this;
3669 }
3670 env_managed(const env_managed &) = delete;
3671 env_managed &operator=(const env_managed &) = delete;
3672 virtual ~env_managed() noexcept;
3673};
3674
3683protected:
3684 friend class cursor;
3686 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3687
3688public:
3689 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3690 txn(const txn &) noexcept = default;
3691 txn &operator=(const txn &) noexcept = default;
3692 inline txn &operator=(txn &&) noexcept;
3693 inline txn(txn &&) noexcept;
3694 inline ~txn() noexcept;
3695
3696 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3697 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3698 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3699 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3700 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3701
3703 inline ::mdbx::env env() const noexcept;
3705 inline MDBX_txn_flags_t flags() const;
3707 inline uint64_t id() const;
3708
3710 inline void *get_context() const noexcept;
3711
3713 inline txn &set_context(void *your_context);
3714
3716 inline bool is_dirty(const void *ptr) const;
3717
3719 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3720
3722 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3723
3725 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3726
3729 inline info get_info(bool scan_reader_lock_table = false) const;
3730
3733 size_t size_max() const { return env().transaction_size_max(); }
3734
3736 size_t size_current() const {
3737 assert(is_readwrite());
3738 return size_t(get_info().txn_space_dirty);
3739 }
3740
3741 //----------------------------------------------------------------------------
3742
3744 inline void reset_reading();
3745
3747 inline void renew_reading();
3748
3750 inline txn_managed clone(void *context = nullptr) const;
3751
3753 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
3754
3756 inline void make_broken();
3757
3759 inline void park_reading(bool autounpark = true);
3760
3763 inline bool unpark_reading(bool restart_if_ousted = true);
3764
3767
3770
3772 inline cursor_managed open_cursor(map_handle map) const;
3773
3775 inline size_t release_all_cursors(bool unbind) const;
3776
3778 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3779
3781 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3782
3784 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3785 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3787 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3788 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3790 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3791 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3792
3794 inline map_handle open_map_accede(const char *name) const;
3796 inline map_handle open_map_accede(const ::std::string &name) const;
3798 inline map_handle open_map_accede(const slice &name) const;
3799
3801 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3802 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3804 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3805 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3807 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3808 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3809
3811 inline void drop_map(map_handle map);
3815 bool drop_map(const char *name, bool throw_if_absent = false);
3819 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3823 bool drop_map(const slice &name, bool throw_if_absent = false);
3824
3826 inline void clear_map(map_handle map);
3829 bool clear_map(const char *name, bool throw_if_absent = false);
3832 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3835 bool clear_map(const slice &name, bool throw_if_absent = false);
3836
3838 inline void rename_map(map_handle map, const char *new_name);
3840 inline void rename_map(map_handle map, const ::std::string &new_name);
3842 inline void rename_map(map_handle map, const slice &new_name);
3846 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3850 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3854 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3855
3856#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3857
3859 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3860 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3861 return open_map(slice(name), key_mode, value_mode);
3862 }
3863
3864 inline map_handle open_map_accede(const ::std::string_view &name) const;
3866 inline map_handle create_map(const ::std::string_view &name,
3867 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3868 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3869 return create_map(slice(name), key_mode, value_mode);
3870 }
3871
3874 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3875 return drop_map(slice(name), throw_if_absent);
3876 }
3877
3879 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3880 return clear_map(slice(name), throw_if_absent);
3881 }
3882
3883 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3887 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3888 bool throw_if_absent = false) {
3889 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3890 }
3891#endif /* __cpp_lib_string_view >= 201606L */
3892
3895 inline map_stat get_map_stat(map_handle map) const;
3898 inline uint32_t get_tree_deepmask(map_handle map) const;
3900 inline map_handle::info get_map_flags(map_handle map) const;
3901
3904 inline txn &put_canary(const canary &);
3906 inline canary get_canary() const;
3907
3909 inline uint64_t sequence(map_handle map) const;
3911 inline uint64_t sequence(map_handle map, uint64_t increment);
3912
3914 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3916 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3918 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3920 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3921
3923 inline slice get(map_handle map, const slice &key) const;
3925 inline slice get(map_handle map, slice key, size_t &values_count) const;
3927 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3929 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3933 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3937 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3938
3939 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3940 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3941 inline void insert(map_handle map, const slice &key, slice value);
3942 inline value_result try_insert(map_handle map, const slice &key, slice value);
3943 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3944 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3945
3946 inline void upsert(map_handle map, const slice &key, const slice &value);
3947 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3948
3949 inline void update(map_handle map, const slice &key, const slice &value);
3950 inline bool try_update(map_handle map, const slice &key, const slice &value);
3951 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3952 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3953
3954 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3955 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3956 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3957 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3958
3960 inline bool erase(map_handle map, const slice &key);
3961
3963 inline bool erase(map_handle map, const slice &key, const slice &value);
3964
3966 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3967
3969 template <class ALLOCATOR, typename CAPACITY_POLICY>
3971 extract(map_handle map, const slice &key,
3974
3976 template <class ALLOCATOR, typename CAPACITY_POLICY>
3978 replace(map_handle map, const slice &key, const slice &new_value,
3981
3982 template <class ALLOCATOR, typename CAPACITY_POLICY>
3984 replace_reserve(map_handle map, const slice &key, slice &new_value,
3987
4004 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4005 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4006 return append(map, kv.key, kv.value, multivalue_order_preserved);
4007 }
4008
4009 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4010 const void *values_array, size_t values_count, put_mode mode,
4011 bool allow_partial = false);
4012 template <typename VALUE>
4013 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4014 put_mode mode, bool allow_partial = false) {
4015 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4016 !::std::is_array<VALUE>::value,
4017 "Must be a standard layout type!");
4018 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4019 }
4020 template <typename VALUE>
4021 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4022 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4023 }
4024
4025 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4026 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4027 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4028 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4029};
4030
4039class LIBMDBX_API_TYPE txn_managed : public txn {
4040 using inherited = txn;
4041 friend class env;
4042 friend class txn;
4044 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4045
4046public:
4047 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4048 txn_managed(txn_managed &&) = default;
4049 txn_managed &operator=(txn_managed &&other) noexcept {
4051 MDBX_CXX20_UNLIKELY {
4052 assert(handle_ != other.handle_);
4053 abort();
4054 }
4055 inherited::operator=(std::move(other));
4056 return *this;
4057 }
4058 txn_managed(const txn_managed &) = delete;
4059 txn_managed &operator=(const txn_managed &) = delete;
4060 ~txn_managed() noexcept;
4061
4062 //----------------------------------------------------------------------------
4064
4066 void abort();
4070 void abort(finalization_latency &latency) { return abort(&latency); }
4074 finalization_latency result;
4075 abort(&result);
4076 return result;
4077 }
4078
4080 void commit();
4084 void commit(finalization_latency &latency) { return commit(&latency); }
4088 finalization_latency result;
4089 commit(&result);
4090 return result;
4091 }
4092
4098 bool checkpoint(finalization_latency &latency) { return checkpoint(&latency); }
4101 std::pair<bool, finalization_latency> checkpoint_get_latency() {
4102 finalization_latency latency;
4103 bool result = checkpoint(&latency);
4104 return std::make_pair(result, latency);
4105 }
4106
4116 finalization_latency result;
4117 commit_embark_read(&result);
4118 return result;
4119 }
4120
4123 bool amend(bool dont_wait = false);
4124};
4125
4133protected:
4135
4136public:
4138 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4139 cursor(const cursor &) noexcept = default;
4140 cursor &operator=(const cursor &) noexcept = default;
4141 inline cursor &operator=(cursor &&) noexcept;
4142 inline cursor(cursor &&) noexcept;
4143 inline ~cursor() noexcept;
4144 inline cursor_managed clone(void *your_context = nullptr) const;
4145 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4146 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4147 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4148 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4149 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4150
4151 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4152 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4153
4154 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4155 return compare_position(*this, other, ignore_nested) < 0;
4156 }
4157
4158 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4159 return compare_position(*this, other, ignore_nested) <= 0;
4160 }
4161
4162 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4163 return compare_position(*this, other, ignore_nested) == 0;
4164 }
4165
4166 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4167 return compare_position(*this, other, ignore_nested) > 0;
4168 }
4169
4170 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4171 return compare_position(*this, other, ignore_nested) >= 0;
4172 }
4173
4175 inline void *get_context() const noexcept;
4176
4178 inline cursor &set_context(void *your_context);
4179
4186
4193
4196
4200
4201 /* Doubtless cursor positioning at a specified key. */
4207
4208 /* Doubtless cursor positioning at a specified key-value pair
4209 * for dupsort/multi-value hives. */
4215
4222
4227 };
4228
4229 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4230 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4231 // и других параметров в bool-throw_notfound.
4232
4233 struct move_result : public pair_result {
4234 inline move_result(const cursor &cursor, bool throw_notfound);
4235 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4236 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4237 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4238 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4239 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4240 bool throw_notfound);
4241 move_result(const move_result &) noexcept = default;
4242 move_result &operator=(const move_result &) noexcept = default;
4243 };
4244
4245 struct estimate_result : public pair {
4250 : estimate_result(cursor, operation, key, slice::invalid()) {}
4251 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4252 estimate_result(const estimate_result &) noexcept = default;
4253 estimate_result &operator=(const estimate_result &) noexcept = default;
4254 };
4255
4256protected:
4257 /* fake `const`, but for specific move/get operations */
4258 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4259
4260 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4261
4262public:
4263 template <typename CALLABLE_PREDICATE>
4264 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4265 struct wrapper : public exception_thunk {
4266 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4267 auto thunk = static_cast<wrapper *>(context);
4268 assert(thunk->is_clean());
4269 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4270 try {
4271 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4272 } catch (... /* capture any exception to rethrow it over C code */) {
4273 thunk->capture();
4274 return MDBX_RESULT_TRUE;
4275 }
4276 }
4277 } thunk;
4279 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4280 thunk);
4281 }
4282
4283 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4284 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4285 }
4286
4287 template <typename CALLABLE_PREDICATE>
4288 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4289 move_operation turn = next) {
4290 struct wrapper : public exception_thunk {
4291 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4292 auto thunk = static_cast<wrapper *>(context);
4293 assert(thunk->is_clean());
4294 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4295 try {
4296 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4297 } catch (... /* capture any exception to rethrow it over C code */) {
4298 thunk->capture();
4299 return MDBX_RESULT_TRUE;
4300 }
4301 }
4302 } thunk;
4303 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4304 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4305 thunk);
4306 }
4307
4308 template <typename CALLABLE_PREDICATE>
4309 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4310 move_operation turn = next) {
4311 struct wrapper : public exception_thunk {
4312 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4313 auto thunk = static_cast<wrapper *>(context);
4314 assert(thunk->is_clean());
4315 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4316 try {
4317 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4318 } catch (... /* capture any exception to rethrow it over C code */) {
4319 thunk->capture();
4320 return MDBX_RESULT_TRUE;
4321 }
4322 }
4323 } thunk;
4324 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4325 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4326 thunk);
4327 }
4328
4329 move_result move(move_operation operation, bool throw_notfound) {
4330 return move_result(*this, operation, throw_notfound);
4331 }
4332 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4333 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4334 }
4335 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4336 return move_result(*this, operation, key, value, throw_notfound);
4337 }
4338 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4339 return move(operation, &key, &value, throw_notfound);
4340 }
4341
4342 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4343 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4344 move_result to_previous_last_multi(bool throw_notfound = true) {
4345 return move(multi_prevkey_lastvalue, throw_notfound);
4346 }
4347 move_result to_current_first_multi(bool throw_notfound = true) {
4348 return move(multi_currentkey_firstvalue, throw_notfound);
4349 }
4350 move_result to_current_prev_multi(bool throw_notfound = true) {
4351 return move(multi_currentkey_prevvalue, throw_notfound);
4352 }
4353 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4354 move_result to_current_next_multi(bool throw_notfound = true) {
4355 return move(multi_currentkey_nextvalue, throw_notfound);
4356 }
4357 move_result to_current_last_multi(bool throw_notfound = true) {
4358 return move(multi_currentkey_lastvalue, throw_notfound);
4359 }
4360 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4361 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4362 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4363
4364 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4365 return move(key_lesser_than, key, throw_notfound);
4366 }
4367 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4368 return move(key_lesser_or_equal, key, throw_notfound);
4369 }
4370 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4371 return move(key_equal, key, throw_notfound);
4372 }
4373 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4374 return move(key_exact, key, throw_notfound);
4375 }
4376 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4377 return move(key_greater_or_equal, key, throw_notfound);
4378 }
4379 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4380 return move(key_greater_than, key, throw_notfound);
4381 }
4382
4383 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4384 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4385 }
4386 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4387 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4388 }
4389 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4390 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4391 }
4392 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4393 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4394 }
4395 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4396 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4397 }
4398
4399 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4400 return move(pair_lesser_than, key, value, throw_notfound);
4401 }
4402 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4403 return move(pair_lesser_or_equal, key, value, throw_notfound);
4404 }
4405 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4406 return move(pair_equal, key, value, throw_notfound);
4407 }
4408 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4409 return move(pair_exact, key, value, throw_notfound);
4410 }
4411 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4412 return move(pair_greater_or_equal, key, value, throw_notfound);
4413 }
4414 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4415 return move(pair_greater_than, key, value, throw_notfound);
4416 }
4417
4418 inline bool seek(const slice &key);
4419 inline move_result find(const slice &key, bool throw_notfound = true);
4420 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4421 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4422
4424 inline size_t count_multivalue() const;
4425
4426 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4427 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4428 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4429
4430 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4431 return move(seek_and_batch_samelength, key, throw_notfound);
4432 }
4433
4434 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4435 return move(batch_samelength, throw_notfound);
4436 }
4437
4438 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4439 return move(batch_samelength_next, throw_notfound);
4440 }
4441
4442 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4443 return move(batch_samelength_previous, throw_notfound);
4444 }
4445
4446 inline bool eof() const;
4447 inline bool on_first() const;
4448 inline bool on_last() const;
4449 inline bool on_first_multival() const;
4450 inline bool on_last_multival() const;
4451 inline estimate_result estimate(const slice &key, const slice &value) const;
4452 inline estimate_result estimate(const slice &key) const;
4453 inline estimate_result estimate(move_operation operation) const;
4454 inline estimate_result estimate(move_operation operation, slice &key) const;
4455
4456 //----------------------------------------------------------------------------
4457
4459 inline void renew(::mdbx::txn &txn);
4460
4463
4465 inline void unbind();
4466
4468 inline ::mdbx::txn txn() const;
4469 inline map_handle map() const;
4470
4471 inline operator ::mdbx::txn() const { return txn(); }
4472 inline operator ::mdbx::map_handle() const { return map(); }
4473
4474 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4475 inline void put(const slice &key, slice value, put_mode mode);
4476 inline void insert(const slice &key, slice value);
4477 inline value_result try_insert(const slice &key, slice value);
4478 inline slice insert_reserve(const slice &key, size_t value_length);
4479 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4480
4481 inline void upsert(const slice &key, const slice &value);
4482 inline slice upsert_reserve(const slice &key, size_t value_length);
4483
4485 void update_current(const slice &value);
4487 slice reverse_current(size_t value_length);
4488
4489 inline void update(const slice &key, const slice &value);
4490 inline bool try_update(const slice &key, const slice &value);
4491 inline slice update_reserve(const slice &key, size_t value_length);
4492 inline value_result try_update_reserve(const slice &key, size_t value_length);
4493
4494 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4495 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4496 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4497 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4498
4500 inline bool erase(bool whole_multivalue = false);
4501
4504 inline bool erase(const slice &key, bool whole_multivalue = true);
4505
4508 inline bool erase(const slice &key, const slice &value);
4509
4510 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4511 size_t values_count, put_mode mode, bool allow_partial = false);
4512 template <typename VALUE>
4513 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4514 bool allow_partial = false) {
4515 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4516 !::std::is_array<VALUE>::value,
4517 "Must be a standard layout type!");
4518 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4519 }
4520 template <typename VALUE>
4521 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4522 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4523 }
4524};
4525
4533class LIBMDBX_API_TYPE cursor_managed : public cursor {
4534 using inherited = cursor;
4535 friend class txn;
4537 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4538
4539public:
4541 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4542 if (MDBX_UNLIKELY(!handle_))
4543 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4544 }
4545
4547 inline void close() {
4549 handle_ = nullptr;
4550 }
4551
4552 cursor_managed(cursor_managed &&) = default;
4553 cursor_managed &operator=(cursor_managed &&other) noexcept {
4555 MDBX_CXX20_UNLIKELY {
4556 assert(handle_ != other.handle_);
4557 close();
4558 }
4559 inherited::operator=(std::move(other));
4560 return *this;
4561 }
4562
4563 inline MDBX_cursor *withdraw_handle() noexcept {
4564 MDBX_cursor *handle = handle_;
4565 handle_ = nullptr;
4566 return handle;
4567 }
4568
4569 cursor_managed(const cursor_managed &) = delete;
4570 cursor_managed &operator=(const cursor_managed &) = delete;
4572};
4573
4574//==============================================================================
4575//
4576// Inline body of the libmdbx C++ API
4577//
4578
4579MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4580MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4581
4582static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4583#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4584 if (::std::is_constant_evaluated()) {
4585 for (size_t i = 0; c_str; ++i)
4586 if (!c_str[i])
4587 return i;
4588 return 0;
4589 }
4590#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4591#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4592 return c_str ? ::std::string_view(c_str).length() : 0;
4593#else
4594 return c_str ? ::std::strlen(c_str) : 0;
4595#endif
4596}
4597
4598MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4599#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4600 if (::std::is_constant_evaluated()) {
4601 for (size_t i = 0; i < bytes; ++i)
4602 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4603 return dest;
4604 } else
4605#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4606 return ::std::memcpy(dest, src, bytes);
4607}
4608
4609static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4610#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4611 if (::std::is_constant_evaluated()) {
4612 for (size_t i = 0; i < bytes; ++i) {
4613 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4614 if (diff)
4615 return diff;
4616 }
4617 return 0;
4618 } else
4619#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4620 return ::std::memcmp(a, b, bytes);
4621}
4622
4623//------------------------------------------------------------------------------
4624
4627
4631
4635
4636inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4637
4638inline void exception_thunk::capture() noexcept {
4639 assert(is_clean());
4640 captured_ = ::std::current_exception();
4641}
4642
4644 if (captured_)
4645 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4646}
4647
4648//------------------------------------------------------------------------------
4649
4650MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4651
4652inline error &error::operator=(MDBX_error_t error_code) noexcept {
4653 code_ = error_code;
4654 return *this;
4655}
4656
4657MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4658
4659MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4660
4661MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4662
4663MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4664
4665MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4666
4668 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4669}
4670
4671MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4672
4677
4678inline void error::throw_exception(int error_code) {
4679 const error trouble(static_cast<MDBX_error_t>(error_code));
4680 trouble.throw_exception();
4681}
4682
4683inline void error::throw_on_failure() const {
4685 MDBX_CXX20_UNLIKELY throw_exception();
4686}
4687
4688inline void error::success_or_throw() const {
4689 if (MDBX_UNLIKELY(!is_success()))
4690 MDBX_CXX20_UNLIKELY throw_exception();
4691}
4692
4693inline void error::success_or_throw(const exception_thunk &thunk) const {
4694 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4695 if (MDBX_UNLIKELY(!is_success())) {
4696 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4697 else throw_exception();
4698 }
4699}
4700
4701inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4702 if (MDBX_UNLIKELY(ptr == nullptr))
4703 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4704}
4705
4706inline void error::throw_on_failure(int error_code) {
4707 error rc(static_cast<MDBX_error_t>(error_code));
4708 rc.throw_on_failure();
4709}
4710
4711inline void error::success_or_throw(MDBX_error_t error_code) {
4712 error rc(error_code);
4713 rc.success_or_throw();
4714}
4715
4716inline bool error::boolean_or_throw(int error_code) {
4717 switch (error_code) {
4718 case MDBX_RESULT_FALSE:
4719 return false;
4720 case MDBX_RESULT_TRUE:
4721 return true;
4722 default:
4723 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4724 }
4725}
4726
4727inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4728 error rc(static_cast<MDBX_error_t>(error_code));
4729 rc.success_or_throw(thunk);
4730}
4731
4732inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4733 if (MDBX_UNLIKELY(!thunk.is_clean()))
4734 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4735 return boolean_or_throw(error_code);
4736}
4737
4738MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4739
4741 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4742
4743MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4744 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4745
4746MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4747
4748MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4749
4750MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4751
4752MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4753
4754inline slice &slice::assign(const void *ptr, size_t bytes) {
4755 iov_base = const_cast<void *>(ptr);
4756 iov_len = check_length(bytes);
4757 return *this;
4758}
4759
4760inline slice &slice::assign(const slice &src) noexcept {
4761 iov_base = src.iov_base;
4762 iov_len = src.iov_len;
4763 return *this;
4764}
4765
4766inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4767
4768slice &slice::assign(slice &&src) noexcept {
4769 assign(src);
4770 src.invalidate();
4771 return *this;
4772}
4773
4775 assign(src.iov_base, src.iov_len);
4776 src.iov_base = nullptr;
4777 return *this;
4778}
4779
4780inline slice &slice::assign(const void *begin, const void *end) {
4781 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4782}
4783
4784inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4785
4786inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4787
4788inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4789
4790MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4791
4792MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4793
4794MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4795
4797
4798MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4799
4800MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4801
4802MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4803
4805
4806MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4807
4808MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4809
4810MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4811
4812MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4813
4814MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4815
4817 iov_len = check_length(bytes);
4818 return *this;
4819}
4820
4822 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4823 return set_length(static_cast<const char *>(ptr) - char_ptr());
4824}
4825
4826MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4827
4828MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4829
4830MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4831
4832MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4833
4834MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4835
4837 iov_base = nullptr;
4838 iov_len = 0;
4839}
4840
4841inline void slice::remove_prefix(size_t n) noexcept {
4842 assert(n <= size());
4843 iov_base = static_cast<byte *>(iov_base) + n;
4844 iov_len -= n;
4845}
4846
4847inline void slice::safe_remove_prefix(size_t n) {
4848 if (MDBX_UNLIKELY(n > size()))
4849 MDBX_CXX20_UNLIKELY throw_out_range();
4850 remove_prefix(n);
4851}
4852
4853inline void slice::remove_suffix(size_t n) noexcept {
4854 assert(n <= size());
4855 iov_len -= n;
4856}
4857
4858inline void slice::safe_remove_suffix(size_t n) {
4859 if (MDBX_UNLIKELY(n > size()))
4860 MDBX_CXX20_UNLIKELY throw_out_range();
4861 remove_suffix(n);
4862}
4863
4864MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4865 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4866}
4867
4868MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4869 return length() >= suffix.length() &&
4870 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4871}
4872
4874 size_t h = length() * 3977471;
4875 for (size_t i = 0; i < length(); ++i)
4876 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4877 return h ^ 3863194411 * (h >> 11);
4878}
4879
4880MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4882 return byte_ptr()[n];
4883}
4884
4885MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4886 if (MDBX_UNLIKELY(n >= size()))
4887 MDBX_CXX20_UNLIKELY throw_out_range();
4888 return byte_ptr()[n];
4889}
4890
4891MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4893 return slice(data(), n);
4894}
4895
4896MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4898 return slice(char_ptr() + size() - n, n);
4899}
4900
4901MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4902 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4903 return slice(char_ptr() + from, n);
4904}
4905
4907 if (MDBX_UNLIKELY(n > size()))
4908 MDBX_CXX20_UNLIKELY throw_out_range();
4909 return head(n);
4910}
4911
4913 if (MDBX_UNLIKELY(n > size()))
4914 MDBX_CXX20_UNLIKELY throw_out_range();
4915 return tail(n);
4916}
4917
4918MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4919 if (MDBX_UNLIKELY(n > max_length))
4920 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4921 if (MDBX_UNLIKELY(from + n > size()))
4922 MDBX_CXX20_UNLIKELY throw_out_range();
4923 return middle(from, n);
4924}
4925
4926MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4927 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4928 return diff ? diff
4929 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4930 : memcmp(a.data(), b.data(), a.length());
4931}
4932
4934 const size_t shortest = ::std::min(a.length(), b.length());
4935 if (MDBX_LIKELY(shortest > 0))
4937 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4938 if (MDBX_LIKELY(diff != 0))
4939 MDBX_CXX20_LIKELY return diff;
4940 }
4941 return intptr_t(a.length()) - intptr_t(b.length());
4942}
4943
4945 return slice::compare_fast(a, b) == 0;
4946}
4947
4949 return slice::compare_lexicographically(a, b) < 0;
4950}
4951
4953 return slice::compare_lexicographically(a, b) > 0;
4954}
4955
4957 return slice::compare_lexicographically(a, b) <= 0;
4958}
4959
4961 return slice::compare_lexicographically(a, b) >= 0;
4962}
4963
4965 return slice::compare_fast(a, b) != 0;
4966}
4967
4968#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
4969MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
4971}
4972#endif /* __cpp_impl_three_way_comparison */
4973
4974template <class ALLOCATOR, typename CAPACITY_POLICY>
4976 const allocator_type &alloc)
4977 : inherited(src), silo_(alloc) {
4978 if (!make_reference)
4979 insulate();
4980}
4981
4982template <class ALLOCATOR, typename CAPACITY_POLICY>
4983inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
4984 const allocator_type &alloc)
4985 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
4986
4987template <class ALLOCATOR, typename CAPACITY_POLICY>
4988inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
4989 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
4990}
4991
4992#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
4994
4995#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
4997#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
4998#endif /* !MinGW || MDBX_EXPORTS */
4999
5002
5003//------------------------------------------------------------------------------
5004
5005template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5006inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
5007 if (MDBX_LIKELY(!producer.is_empty()))
5009 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5010 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5011 return result;
5012 }
5014}
5015
5016template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5017inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
5018 if (MDBX_LIKELY(!producer.is_empty()))
5020 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5021 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5022 return result;
5023 }
5025}
5026
5027template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5028inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
5029 string<ALLOCATOR> result(alloc);
5030 if (MDBX_LIKELY(!producer.is_empty()))
5032 result.resize(producer.envisage_result_length());
5033 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5034 }
5035 return result;
5036}
5037
5038template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5039inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
5040 string<ALLOCATOR> result(alloc);
5041 if (MDBX_LIKELY(!producer.is_empty()))
5043 result.resize(producer.envisage_result_length());
5044 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5045 }
5046 return result;
5047}
5048
5049template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
5050 return make_string<ALLOCATOR>(*this, alloc);
5051}
5052
5053template <class ALLOCATOR, typename CAPACITY_POLICY>
5055 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5056}
5057
5058template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
5059 return make_string<ALLOCATOR>(*this, alloc);
5060}
5061
5062template <class ALLOCATOR, typename CAPACITY_POLICY>
5064 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5065}
5066
5067template <class ALLOCATOR> string<ALLOCATOR> to_base64::as_string(const ALLOCATOR &alloc) const {
5068 return make_string<ALLOCATOR>(*this, alloc);
5069}
5070
5071template <class ALLOCATOR, typename CAPACITY_POLICY>
5073 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5074}
5075
5076template <class ALLOCATOR> string<ALLOCATOR> from_hex::as_string(const ALLOCATOR &alloc) const {
5077 return make_string<ALLOCATOR>(*this, alloc);
5078}
5079
5080template <class ALLOCATOR, typename CAPACITY_POLICY>
5082 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5083}
5084
5085template <class ALLOCATOR> string<ALLOCATOR> from_base58::as_string(const ALLOCATOR &alloc) const {
5086 return make_string<ALLOCATOR>(*this, alloc);
5087}
5088
5089template <class ALLOCATOR, typename CAPACITY_POLICY>
5091 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5092}
5093
5094template <class ALLOCATOR> string<ALLOCATOR> from_base64::as_string(const ALLOCATOR &alloc) const {
5095 return make_string<ALLOCATOR>(*this, alloc);
5096}
5097
5098template <class ALLOCATOR, typename CAPACITY_POLICY>
5100 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5101}
5102
5103template <class ALLOCATOR>
5104inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
5105 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
5106}
5107
5108template <class ALLOCATOR>
5109inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5110 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5111}
5112
5113template <class ALLOCATOR>
5114inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5115 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5116}
5117
5118template <class ALLOCATOR, class CAPACITY_POLICY>
5119inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5120 const ALLOCATOR &alloc) const {
5121 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5122}
5123
5124template <class ALLOCATOR, class CAPACITY_POLICY>
5125inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
5126 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5127}
5128
5129template <class ALLOCATOR, class CAPACITY_POLICY>
5130inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
5131 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5132}
5133
5134template <class ALLOCATOR, class CAPACITY_POLICY>
5135inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5136 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5137}
5138
5139template <class ALLOCATOR, class CAPACITY_POLICY>
5140inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5141 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5142}
5143
5144template <class ALLOCATOR, class CAPACITY_POLICY>
5145inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5146 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5147}
5148
5149//------------------------------------------------------------------------------
5150
5151MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5152 const auto diff = slice::compare_fast(a.key, b.key);
5153 return diff ? diff : slice::compare_fast(a.value, b.value);
5154}
5155
5156MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5157 const auto diff = slice::compare_lexicographically(a.key, b.key);
5158 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5159}
5160
5162 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5163 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5164 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5165}
5166
5168 return pair::compare_lexicographically(a, b) < 0;
5169}
5170
5172 return pair::compare_lexicographically(a, b) > 0;
5173}
5174
5176 return pair::compare_lexicographically(a, b) <= 0;
5177}
5178
5180 return pair::compare_lexicographically(a, b) >= 0;
5181}
5182
5184 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5185 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5186 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5187}
5188
5189#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5190MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5192}
5193#endif /* __cpp_impl_three_way_comparison */
5194
5196template <typename BUFFER>
5198
5201
5202//------------------------------------------------------------------------------
5203
5204inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
5205inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
5206inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
5207
5208MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5209 return !from_hex(*this, ignore_spaces).is_erroneous();
5210}
5211
5212MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5213 return !from_base58(*this, ignore_spaces).is_erroneous();
5214}
5215
5216MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5217 return !from_base64(*this, ignore_spaces).is_erroneous();
5218}
5219
5220//------------------------------------------------------------------------------
5221
5223
5224inline env &env::operator=(env &&other) noexcept {
5225 handle_ = other.handle_;
5226 other.handle_ = nullptr;
5227 return *this;
5228}
5229
5230inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5231
5232inline env::~env() noexcept {
5233#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
5234 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5235#endif
5236}
5237
5238MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5239
5240MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5241
5242MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5243
5244MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5245
5246MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5247
5251 return *this;
5252}
5253
5254inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5255 size_now = size_lower = lower;
5256 size_upper = upper;
5258 return *this;
5259}
5260
5264
5268
5269inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5270
5271inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5272
5273inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5274 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5275 if (result < 0)
5276 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5277 return static_cast<size_t>(result);
5278}
5279
5280inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5281 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5282 if (result < 0)
5283 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5284 return static_cast<size_t>(result);
5285}
5286
5287inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5288
5289inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5290
5291inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5292 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5293 if (result < 0)
5294 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5295 return static_cast<size_t>(result);
5296}
5297
5298inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5299 return key_max(pagesize, MDBX_db_flags_t(mode));
5300}
5301
5302inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
5303 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5304 if (result < 0)
5305 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5306 return static_cast<size_t>(result);
5307}
5308
5310
5311inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5312
5314
5315inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5316 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5317 if (result < 0)
5318 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5319 return static_cast<size_t>(result);
5320}
5321
5322inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5323 return value_max(pagesize, MDBX_db_flags_t(mode));
5324}
5325
5326inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
5327 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5328 if (result < 0)
5329 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5330 return static_cast<size_t>(result);
5331}
5332
5334
5335inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5336 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5337 if (result < 0)
5338 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5339 return static_cast<size_t>(result);
5340}
5341
5342inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5343 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5344}
5345
5347 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5348 if (result < 0)
5349 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5350 return static_cast<size_t>(result);
5351}
5352
5356
5357inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5358 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5359 if (result < 0)
5360 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5361 return static_cast<size_t>(result);
5362}
5363
5364inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5365 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5366}
5367
5369 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5370 if (result < 0)
5371 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5372 return static_cast<size_t>(result);
5373}
5374
5378
5379inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5380 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5381 if (result < 0)
5382 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5383 return static_cast<size_t>(result);
5384}
5385
5386inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5387
5395
5397
5401
5405
5409
5410inline env::stat env::get_stat() const {
5411 env::stat r;
5412 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5413 return r;
5414}
5415
5416inline env::stat env::get_stat(const txn &txn) const {
5417 env::stat r;
5419 return r;
5420}
5421
5422inline env::info env::get_info() const {
5423 env::info r;
5424 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5425 return r;
5426}
5427
5428inline env::info env::get_info(const txn &txn) const {
5429 env::info r;
5431 return r;
5432}
5433
5435 filehandle fd;
5437 return fd;
5438}
5439
5441 unsigned bits = 0;
5443 return MDBX_env_flags_t(bits);
5444}
5445
5446inline unsigned env::max_readers() const {
5447 unsigned r;
5449 return r;
5450}
5451
5452inline unsigned env::max_maps() const {
5453 unsigned r;
5455 return r;
5456}
5457
5458inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5459
5460inline env &env::set_context(void *ptr) {
5462 return *this;
5463}
5464
5465inline env &env::set_sync_threshold(size_t bytes) {
5467 return *this;
5468}
5469
5470inline size_t env::sync_threshold() const {
5471 size_t bytes;
5473 return bytes;
5474}
5475
5476inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5478 return *this;
5479}
5480
5481inline unsigned env::sync_period__seconds_16dot16() const {
5482 unsigned seconds_16dot16;
5484 return seconds_16dot16;
5485}
5486
5488 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5489}
5490
5491inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5492
5493#if __cplusplus >= 201103L
5494inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5495
5497#endif
5498
5499inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5501 return *this;
5502}
5503
5504inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5505 uint64_t value;
5507 return value;
5508}
5509
5510inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
5512 return *this;
5513}
5514
5515inline env &env::set_geometry(const geometry &geo) {
5517 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5518 return *this;
5519}
5520
5521inline bool env::sync_to_disk(bool force, bool nonblock) {
5522 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5523 switch (err) {
5524 case MDBX_SUCCESS /* flush done */:
5525 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5526 return true;
5527 case MDBX_BUSY /* the environment is used by other thread */:
5528 return false;
5529 default:
5530 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5531 }
5532}
5533
5534inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5535
5537env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5538 size_t retained) noexcept
5540 bytes_retained(retained) {}
5541
5542template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5543 struct reader_visitor_thunk : public exception_thunk {
5544 VISITOR &visitor_;
5545 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5546 size_t used, size_t retained) noexcept {
5547 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5548 assert(thunk->is_clean());
5549 try {
5550 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5551 return loop_control(thunk->visitor_(info, number));
5552 } catch (... /* capture any exception to rethrow it over C code */) {
5553 thunk->capture();
5555 }
5556 }
5557 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5558 };
5559 reader_visitor_thunk thunk(visitor);
5560 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5561 thunk.rethrow_captured();
5562 return rc;
5563}
5564
5565inline unsigned env::check_readers() {
5566 int dead_count;
5567 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5568 MDBX_INLINE_API_ASSERT(dead_count >= 0);
5569 return static_cast<unsigned>(dead_count);
5570}
5571
5576
5577inline MDBX_hsr_func env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5578
5580 ::MDBX_txn *ptr;
5582 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5583 return txn_managed(ptr);
5584}
5585
5587 ::MDBX_txn *ptr;
5589 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5590 return txn_managed(ptr);
5591}
5592
5593inline txn_managed env::start_write(bool dont_wait) {
5594 ::MDBX_txn *ptr;
5597 MDBX_INLINE_API_ASSERT(ptr != nullptr || dont_wait);
5598 return txn_managed(ptr);
5599}
5600
5602 ::MDBX_txn *ptr;
5604 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5605 return txn_managed(ptr);
5606}
5607
5609
5611
5612inline txn &txn::operator=(txn &&other) noexcept {
5613 handle_ = other.handle_;
5614 other.handle_ = nullptr;
5615 return *this;
5616}
5617
5618inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5619
5620inline txn::~txn() noexcept {
5621#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
5622 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5623#endif
5624}
5625
5626MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5627
5628MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5629
5630MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5631
5632MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5633
5634MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5635
5636inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5637
5638inline txn &txn::set_context(void *ptr) {
5640 return *this;
5641}
5642
5643inline bool txn::is_dirty(const void *ptr) const {
5644 int err = ::mdbx_is_dirty(handle_, ptr);
5645 switch (err) {
5646 default:
5647 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5648 case MDBX_RESULT_TRUE:
5649 return true;
5650 case MDBX_RESULT_FALSE:
5651 return false;
5652 }
5653}
5654
5655inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5656
5658 const int bits = mdbx_txn_flags(handle_);
5660 return static_cast<MDBX_txn_flags_t>(bits);
5661}
5662
5663inline uint64_t txn::id() const {
5664 const uint64_t txnid = mdbx_txn_id(handle_);
5666 return txnid;
5667}
5668
5670
5672
5674
5675inline txn_managed txn::clone(void *context) const {
5676 MDBX_txn *ptr = nullptr;
5678 MDBX_INLINE_API_ASSERT(ptr != nullptr);
5679 return txn_managed(ptr);
5680}
5681
5682inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
5683 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
5684 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
5685 MDBX_INLINE_API_ASSERT(txn_for_renew_into_clone.handle_ != nullptr);
5686}
5687
5688inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5689
5690inline bool txn::unpark_reading(bool restart_if_ousted) {
5691 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5692}
5693
5694inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5695 txn::info r;
5696 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5697 return r;
5698}
5699
5701 MDBX_cursor *ptr;
5703 return cursor_managed(ptr);
5704}
5705
5706inline size_t txn::release_all_cursors(bool unbind) const {
5707 size_t count;
5709 return count;
5710}
5711
5712inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5713 const ::mdbx::value_mode value_mode) const {
5714 map_handle map;
5717 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5718 return map;
5719}
5720
5721inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5722 const ::mdbx::value_mode value_mode) const {
5723 map_handle map;
5726 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5727 return map;
5728}
5729
5730inline map_handle txn::open_map_accede(const slice &name) const {
5731 map_handle map;
5733 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5734 return map;
5735}
5736
5737inline map_handle txn::open_map_accede(const char *name) const {
5738 map_handle map;
5740 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5741 return map;
5742}
5743
5744inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5745 const ::mdbx::value_mode value_mode) {
5746 map_handle map;
5749 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5750 return map;
5751}
5752
5753inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5754 const ::mdbx::value_mode value_mode) {
5755 map_handle map;
5758 MDBX_INLINE_API_ASSERT(map.dbi != 0);
5759 return map;
5760}
5761
5763
5765
5766inline void txn::rename_map(map_handle map, const char *new_name) {
5768}
5769
5770inline void txn::rename_map(map_handle map, const slice &new_name) {
5772}
5773
5774inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5775 const ::mdbx::value_mode value_mode) const {
5776 return open_map(slice(name), key_mode, value_mode);
5777}
5778
5779inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5780
5781inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5782 const ::mdbx::value_mode value_mode) {
5783 return create_map(slice(name), key_mode, value_mode);
5784}
5785
5786inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5787 return drop_map(slice(name), throw_if_absent);
5788}
5789
5790inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5791 return clear_map(slice(name), throw_if_absent);
5792}
5793
5794inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5795
5797 txn::map_stat r;
5798 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5799 return r;
5800}
5801
5802inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5803 uint32_t r;
5805 return r;
5806}
5807
5813
5818
5820 txn::canary r;
5822 return r;
5823}
5824
5825inline uint64_t txn::sequence(map_handle map) const {
5826 uint64_t result;
5828 return result;
5829}
5830
5831inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5832 uint64_t result;
5833 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5834 return result;
5835}
5836
5837inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5838 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5839}
5840
5841inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5842 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5843}
5844
5845inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5846 return compare_keys(map, a.key, b.key);
5847}
5848
5849inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5850 return compare_values(map, a.value, b.value);
5851}
5852
5853inline slice txn::get(map_handle map, const slice &key) const {
5854 slice result;
5855 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5856 return result;
5857}
5858
5859inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5860 slice result;
5861 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5862 return result;
5863}
5864
5865inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5866 slice result;
5867 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5868 switch (err) {
5869 case MDBX_SUCCESS:
5870 return result;
5871 case MDBX_NOTFOUND:
5872 return value_at_absence;
5873 default:
5874 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5875 }
5876}
5877
5878inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5879 slice result;
5880 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5881 switch (err) {
5882 case MDBX_SUCCESS:
5883 return result;
5884 case MDBX_NOTFOUND:
5885 return value_at_absence;
5886 default:
5887 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5888 }
5889}
5890
5892 pair result(key, slice());
5893 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5894 return pair_result(result.key, result.value, exact);
5895}
5896
5897inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5898 pair result{key, slice()};
5899 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5900 switch (err) {
5901 case MDBX_SUCCESS:
5902 return pair_result{result.key, result.value, true};
5903 case MDBX_RESULT_TRUE:
5904 return pair_result{result.key, result.value, false};
5905 case MDBX_NOTFOUND:
5906 return pair_result{key, value_at_absence, false};
5907 default:
5908 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5909 }
5910}
5911
5912inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5913 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5914}
5915
5916inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5917 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5918}
5919
5920inline void txn::insert(map_handle map, const slice &key, slice value) {
5921 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5923}
5924
5925inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5926 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5928 switch (err) {
5929 case MDBX_SUCCESS:
5930 return value_result{slice(), true};
5931 case MDBX_KEYEXIST:
5932 return value_result{value, false};
5933 default:
5934 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5935 }
5936}
5937
5938inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5939 slice result(nullptr, value_length);
5940 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5942 return result;
5943}
5944
5945inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5946 slice result(nullptr, value_length);
5947 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5949 switch (err) {
5950 case MDBX_SUCCESS:
5951 return value_result{result, true};
5952 case MDBX_KEYEXIST:
5953 return value_result{result, false};
5954 default:
5955 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5956 }
5957}
5958
5959inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5960 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5961}
5962
5963inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
5964 slice result(nullptr, value_length);
5966 return result;
5967}
5968
5969inline void txn::update(map_handle map, const slice &key, const slice &value) {
5970 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
5971}
5972
5973inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
5974 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
5975 switch (err) {
5976 case MDBX_SUCCESS:
5977 return true;
5978 case MDBX_NOTFOUND:
5979 return false;
5980 default:
5981 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5982 }
5983}
5984
5985inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
5986 slice result(nullptr, value_length);
5988 return result;
5989}
5990
5991inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
5992 slice result(nullptr, value_length);
5993 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
5994 switch (err) {
5995 case MDBX_SUCCESS:
5996 return value_result{result, true};
5997 case MDBX_NOTFOUND:
5998 return value_result{slice(), false};
5999 default:
6000 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6001 }
6002}
6003
6004inline bool txn::erase(map_handle map, const slice &key) {
6005 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6006 switch (err) {
6007 case MDBX_SUCCESS:
6008 return true;
6009 case MDBX_NOTFOUND:
6010 return false;
6011 default:
6012 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6013 }
6014}
6015
6016inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6017 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
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 void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
6029 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6030 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6031}
6032
6033template <class ALLOCATOR, typename CAPACITY_POLICY>
6037 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6039 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
6040 return result;
6041}
6042
6043template <class ALLOCATOR, typename CAPACITY_POLICY>
6045txn::replace(map_handle map, const slice &key, const slice &new_value,
6047 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6048 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
6049 MDBX_CURRENT, result, &result),
6050 result);
6051 return result;
6052}
6053
6054template <class ALLOCATOR, typename CAPACITY_POLICY>
6056txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
6058 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6059 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6060 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6061 result);
6062 return result;
6063}
6064
6065inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
6066 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6067 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
6068}
6069
6070inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
6071 const void *values_array, size_t values_count, put_mode mode,
6072 bool allow_partial) {
6073 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6074 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6075 switch (err) {
6076 case MDBX_SUCCESS:
6077 MDBX_CXX20_LIKELY break;
6078 case MDBX_KEYEXIST:
6079 if (allow_partial)
6080 break;
6082 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6083 default:
6084 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6085 }
6086 return args[1].iov_len /* done item count */;
6087}
6088
6089inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
6090 ptrdiff_t result;
6091 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6092 return result;
6093}
6094
6095inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6096 ptrdiff_t result;
6097 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6098 return result;
6099}
6100
6101inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6102 ptrdiff_t result;
6103 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6104 return result;
6105}
6106
6107inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6108 ptrdiff_t result;
6109 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6110 return result;
6111}
6112
6114
6115inline cursor_managed cursor::clone(void *your_context) const {
6116 cursor_managed clone(your_context);
6118 return clone;
6119}
6120
6121inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6122
6123inline cursor &cursor::set_context(void *ptr) {
6125 return *this;
6126}
6127
6128inline cursor &cursor::operator=(cursor &&other) noexcept {
6129 handle_ = other.handle_;
6130 other.handle_ = nullptr;
6131 return *this;
6132}
6133
6134inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6135
6136inline cursor::~cursor() noexcept {
6137#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
6138 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6139#endif
6140}
6141
6142MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
6143
6144MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
6145
6146MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6147
6148MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6149
6150MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6151
6152inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6153 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6154}
6155
6156inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6157 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6158 MDBX_INLINE_API_ASSERT(compare_position_nothrow(right, left, ignore_nested) == -diff);
6159 if (MDBX_LIKELY(int16_t(diff) == diff))
6160 MDBX_CXX20_LIKELY return int(diff);
6161 else
6163}
6164
6165inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6166 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6167}
6168
6170 bool throw_notfound)
6171 : pair_result(key, value, false) {
6172 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6173}
6174
6175inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6176 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6177 switch (err) {
6178 case MDBX_SUCCESS:
6179 MDBX_CXX20_LIKELY return true;
6180 case MDBX_RESULT_TRUE:
6181 return false;
6182 case MDBX_NOTFOUND:
6183 if (!throw_notfound)
6184 return false;
6185 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6186 default:
6187 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6188 }
6189}
6190
6192 const slice &value)
6193 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6194 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6195}
6196
6197inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6198 ptrdiff_t result;
6199 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6200 return result;
6201}
6202
6203inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6204 ptrdiff_t result;
6206 return result;
6207}
6208
6209inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6210 return move(key_exact, key, throw_notfound);
6211}
6212
6213inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6214 return move(key_lowerbound, key, throw_notfound);
6215}
6216
6217inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6218 return move(key_greater_than, key, throw_notfound);
6219}
6220
6221inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6222 return move(multi_find_pair, key, value, throw_notfound);
6223}
6224
6225inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6226 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6227}
6228
6229inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6230 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6231}
6232
6233inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6234
6235inline size_t cursor::count_multivalue() const {
6236 size_t result;
6238 return result;
6239}
6240
6241inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6242
6244
6246
6248
6250
6251inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6252 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6253}
6254
6256 return estimate_result(*this, key_lowerbound, key);
6257}
6258
6260 return estimate_result(*this, operation);
6261}
6262
6264
6268
6270
6271inline txn cursor::txn() const {
6273 return ::mdbx::txn(txn);
6274}
6275
6276inline map_handle cursor::map() const {
6277 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6278 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6280 return map_handle(dbi);
6281}
6282
6283inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6284 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6285}
6286
6287inline void cursor::put(const slice &key, slice value, put_mode mode) {
6288 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6289}
6290
6291inline void cursor::insert(const slice &key, slice value) {
6293 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6294}
6295
6296inline value_result cursor::try_insert(const slice &key, slice value) {
6297 const int err =
6298 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6299 switch (err) {
6300 case MDBX_SUCCESS:
6301 return value_result{slice(), true};
6302 case MDBX_KEYEXIST:
6303 return value_result{value, false};
6304 default:
6305 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6306 }
6307}
6308
6309inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6310 slice result(nullptr, value_length);
6311 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6313 return result;
6314}
6315
6316inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6317 slice result(nullptr, value_length);
6318 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6320 switch (err) {
6321 case MDBX_SUCCESS:
6322 return value_result{result, true};
6323 case MDBX_KEYEXIST:
6324 return value_result{result, false};
6325 default:
6326 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6327 }
6328}
6329
6330inline void cursor::upsert(const slice &key, const slice &value) {
6331 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6332}
6333
6334inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6335 slice result(nullptr, value_length);
6337 return result;
6338}
6339
6340inline void cursor::update(const slice &key, const slice &value) {
6341 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6342}
6343
6344inline bool cursor::try_update(const slice &key, const slice &value) {
6345 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6346 switch (err) {
6347 case MDBX_SUCCESS:
6348 return true;
6349 case MDBX_NOTFOUND:
6350 return false;
6351 default:
6352 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6353 }
6354}
6355
6356inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6357 slice result(nullptr, value_length);
6359 return result;
6360}
6361
6362inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6363 slice result(nullptr, value_length);
6364 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6365 switch (err) {
6366 case MDBX_SUCCESS:
6367 return value_result{result, true};
6368 case MDBX_NOTFOUND:
6369 return value_result{slice(), false};
6370 default:
6371 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6372 }
6373}
6374
6375inline bool cursor::erase(bool whole_multivalue) {
6376 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6377 switch (err) {
6378 case MDBX_SUCCESS:
6379 MDBX_CXX20_LIKELY return true;
6380 case MDBX_NOTFOUND:
6381 return false;
6382 default:
6383 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6384 }
6385}
6386
6387inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6388 bool found = seek(key);
6389 return found ? erase(whole_multivalue) : found;
6390}
6391
6392inline bool cursor::erase(const slice &key, const slice &value) {
6393 move_result data = find_multivalue(key, value, false);
6394 return data.done && erase();
6395}
6396
6397inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6398 size_t values_count, put_mode mode, bool allow_partial) {
6399 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6400 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6401 switch (err) {
6402 case MDBX_SUCCESS:
6403 MDBX_CXX20_LIKELY break;
6404 case MDBX_KEYEXIST:
6405 if (allow_partial)
6406 break;
6408 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6409 default:
6410 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6411 }
6412 return args[1].iov_len /* done item count */;
6413}
6414
6415//------------------------------------------------------------------------------
6416
6417LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
6418LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
6419LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
6420LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
6421LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
6422LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
6423LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
6424LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
6425LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
6426LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
6427LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
6428
6429LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
6430LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
6431LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
6432
6433inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
6434
6436
6437} // namespace mdbx
6438
6439//------------------------------------------------------------------------------
6440
6443namespace std {
6444
6445inline string to_string(const ::mdbx::slice &value) {
6446 ostringstream out;
6447 out << value;
6448 return out.str();
6449}
6450
6451template <class ALLOCATOR, typename CAPACITY_POLICY>
6452inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6453 ostringstream out;
6454 out << buffer;
6455 return out.str();
6456}
6457
6458inline string to_string(const ::mdbx::pair &value) {
6459 ostringstream out;
6460 out << value;
6461 return out.str();
6462}
6463
6464inline string to_string(const ::mdbx::env::geometry &value) {
6465 ostringstream out;
6466 out << value;
6467 return out.str();
6468}
6469
6470inline string to_string(const ::mdbx::env::operate_parameters &value) {
6471 ostringstream out;
6472 out << value;
6473 return out.str();
6474}
6475
6476inline string to_string(const ::mdbx::env::mode &value) {
6477 ostringstream out;
6478 out << value;
6479 return out.str();
6480}
6481
6482inline string to_string(const ::mdbx::env::durability &value) {
6483 ostringstream out;
6484 out << value;
6485 return out.str();
6486}
6487
6488inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6489 ostringstream out;
6490 out << value;
6491 return out.str();
6492}
6493
6494inline string to_string(const ::mdbx::env::operate_options &value) {
6495 ostringstream out;
6496 out << value;
6497 return out.str();
6498}
6499
6500inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6501 ostringstream out;
6502 out << value;
6503 return out.str();
6504}
6505
6506inline string to_string(const ::MDBX_log_level_t &value) {
6507 ostringstream out;
6508 out << value;
6509 return out.str();
6510}
6511
6512inline string to_string(const ::MDBX_debug_flags_t &value) {
6513 ostringstream out;
6514 out << value;
6515 return out.str();
6516}
6517
6518inline string to_string(const ::mdbx::error &value) {
6519 ostringstream out;
6520 out << value;
6521 return out.str();
6522}
6523
6524inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6525
6526template <> struct hash<::mdbx::slice> {
6527 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6528};
6529
6530template <> struct hash<::mdbx::map_handle> {
6531 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6532};
6533
6534template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6535 using inherited = std::hash<const MDBX_env *>;
6536 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6537};
6538
6539template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6540 using inherited = std::hash<const MDBX_txn *>;
6541 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6542};
6543
6544template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6545 using inherited = std::hash<const MDBX_cursor *>;
6546 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6547};
6548
6549template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6550 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6551 return buffer.hash_value();
6552 }
6553};
6554
6555} // namespace std
6556
6557#if defined(__LCC__) && __LCC__ >= 126
6558#pragma diagnostic pop
6559#endif
6560
6561#ifdef _MSC_VER
6562#pragma warning(pop)
6563#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:5247
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4740
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4146
Information about the environment.
Definition mdbx.h:2840
Statistics for a table in the environment.
Definition mdbx.h:2794
Information about the transaction.
Definition mdbx.h:4044
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:5540
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:1649
LIBMDBX_API int mdbx_replace_ex(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *new_data, MDBX_val *old_data, MDBX_put_flags_t flags, MDBX_preserve_func preserver, void *preserver_context)
Replaces item in a table using preservation callback for an original data.
LIBMDBX_API int mdbx_cursor_count(const MDBX_cursor *cursor, size_t *count)
Return count values (aka duplicates) for current key.
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:4800
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5261
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:1686
@ MDBX_ALLDUPS
Definition mdbx.h:1669
@ MDBX_CURRENT
Definition mdbx.h:1664
@ MDBX_APPENDDUP
Definition mdbx.h:1682
@ MDBX_APPEND
Definition mdbx.h:1677
@ MDBX_UPSERT
Definition mdbx.h:1651
@ MDBX_RESERVE
Definition mdbx.h:1673
@ MDBX_NOOVERWRITE
Definition mdbx.h:1654
LIBMDBX_API int mdbx_cursor_on_first_dup(const MDBX_cursor *cursor)
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:1730
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_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_eof(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to a key-value pair or not, i.e. was not positioned or point...
LIBMDBX_API int mdbx_cursor_close2(MDBX_cursor *cursor)
Closes a cursor handle with returning error code.
LIBMDBX_API void * mdbx_cursor_get_userctx(const MDBX_cursor *cursor)
Get the application information associated with the MDBX_cursor.
LIBMDBX_API int mdbx_cursor_renew(MDBX_txn *txn, MDBX_cursor *cursor)
Renew a cursor handle for use within the given transaction.
LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor)
Closes a cursor handle without returning error code.
LIBMDBX_API MDBX_txn * mdbx_cursor_txn(const MDBX_cursor *cursor)
Return the cursor's transaction handle.
LIBMDBX_API int mdbx_cursor_on_last(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to the last key-value pair or not.
LIBMDBX_API int mdbx_cursor_copy(const MDBX_cursor *src, MDBX_cursor *dest)
Copy cursor position and state.
@ MDBX_SEEK_AND_GET_MULTIPLE
Definition mdbx.h:1849
@ MDBX_GET_CURRENT
Definition mdbx.h:1745
@ MDBX_GET_BOTH
Definition mdbx.h:1738
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1826
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1742
@ MDBX_SET_KEY
Definition mdbx.h:1785
@ MDBX_FIRST_DUP
Definition mdbx.h:1735
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1825
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1750
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1836
@ MDBX_NEXT_NODUP
Definition mdbx.h:1770
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1833
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1834
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1841
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1793
@ MDBX_SET_RANGE
Definition mdbx.h:1788
@ MDBX_LAST_DUP
Definition mdbx.h:1756
@ MDBX_PREV
Definition mdbx.h:1773
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1843
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1844
@ MDBX_LAST
Definition mdbx.h:1753
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1824
@ MDBX_PREV_DUP
Definition mdbx.h:1776
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1832
@ MDBX_SET
Definition mdbx.h:1782
@ MDBX_NEXT
Definition mdbx.h:1759
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1827
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1840
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1767
@ MDBX_PREV_NODUP
Definition mdbx.h:1779
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1842
@ MDBX_NEXT_DUP
Definition mdbx.h:1762
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1835
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1828
@ MDBX_FIRST
Definition mdbx.h:1732
LIBMDBX_API int mdbx_dbi_rename(MDBX_txn *txn, MDBX_dbi dbi, const char *name)
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:1599
@ MDBX_INTEGERDUP
Definition mdbx.h:1623
@ MDBX_DB_ACCEDE
Definition mdbx.h:1641
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1601
@ MDBX_REVERSEKEY
Definition mdbx.h:1604
@ MDBX_DUPFIXED
Definition mdbx.h:1618
@ MDBX_INTEGERKEY
Definition mdbx.h:1614
@ MDBX_REVERSEDUP
Definition mdbx.h:1626
@ MDBX_CREATE
Definition mdbx.h:1629
@ MDBX_DUPSORT
Definition mdbx.h:1607
MDBX_log_level_t
Definition mdbx.h:884
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:943
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1857
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:6831
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1871
@ MDBX_BAD_TXN
Definition mdbx.h:1934
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1948
@ MDBX_SUCCESS
Definition mdbx.h:1859
@ MDBX_NOTFOUND
Definition mdbx.h:1874
@ MDBX_RESULT_TRUE
Definition mdbx.h:1865
@ MDBX_BUSY
Definition mdbx.h:1952
@ MDBX_EINVAL
Definition mdbx.h:2028
@ MDBX_ENOMEM
Definition mdbx.h:2030
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1955
@ MDBX_RESULT_FALSE
Definition mdbx.h:1862
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:2007
@ MDBX_KEYEXIST
Definition mdbx.h:1868
LIBMDBX_API int mdbx_reader_check(MDBX_env *env, int *dead)
Check for stale entries in the reader lock table.
LIBMDBX_API int mdbx_env_sync_ex(MDBX_env *env, bool force, bool nonblock)
Flush the environment data buffers to disk.
@ MDBX_ENV_WAIT_FOR_UNUSED
Wait until other processes closes the environment before deletion.
Definition mdbx.h:2576
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2571
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2574
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1058
@ MDBX_WRITEMAP
Definition mdbx.h:1178
@ MDBX_EXCLUSIVE
Definition mdbx.h:1132
@ MDBX_RDONLY
Definition mdbx.h:1102
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:3085
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2138
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:3026
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:2243
@ 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:2405
@ MDBX_opt_subpage_limit
Specifies the maximum size of nested pages used to accommodate a small number of multi-values associa...
Definition mdbx.h:2398
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2239
@ MDBX_opt_prefer_waf_insteadof_balance
Controls the choice between striving for uniformity of page filling/density, either for reducing the ...
Definition mdbx.h:2384
@ 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:2343
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2147
@ 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:2419
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2170
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2275
@ 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:2298
@ MDBX_opt_split_reserve
Sets the space reservation in 1/65536 of page size when splitting page along the edge.
Definition mdbx.h:2447
@ 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:2210
@ 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:2197
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2164
@ MDBX_opt_subpage_reserve_limit
Sets the limit for reserving space on nested pages.
Definition mdbx.h:2425
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2259
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2176
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2224
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2338
@ MDBX_opt_gc_time_limit
Controls the in-process spending time limit of searching consecutive pages inside GC.
Definition mdbx.h:2362
@ MDBX_opt_merge_threshold
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2310
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:3700
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:3105
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:3044
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:5062
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:3745
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:1498
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:3961
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:1509
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1518
@ MDBX_TXN_READWRITE
Definition mdbx.h:1503
@ MDBX_TXN_TRY
Definition mdbx.h:1524
void commit(finalization_latency &latency)
ommits all changes of the transaction into a database with collecting latencies information.
Definition mdbx.h++:4084
friend class env
Definition mdbx.h++:4041
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:3727
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4541
~txn_managed() noexcept
::MDBX_stat map_stat
Definition mdbx.h++:3893
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++:3420
@ prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h++:3454
@ 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++:3464
@ spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h++:3446
@ subpage_limit
Specifies the maximum size of nested pages used to accommodate a small number of multi-values associa...
Definition mdbx.h++:3460
@ spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h++:3448
@ writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h++:3452
@ sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h++:3429
@ dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h++:3440
@ dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h++:3442
@ spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h++:3444
@ prefer_waf_insteadof_balance
Controls the choice between striving for uniformity of page filling/density, either for reducing the ...
Definition mdbx.h++:3458
@ 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++:3462
@ merge_threshold_dot16
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h++:3450
@ 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++:3434
@ loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h++:3436
@ gc_time_limit
Controls the in-process spending time limit of searching consecutive pages inside GC.
Definition mdbx.h++:3456
@ subpage_reserve_limit
Sets the limit for reserving space on nested pages.
Definition mdbx.h++:3466
@ split_reserve
Sets the space reservation in 1/65536 of page size when splitting page along the edge.
Definition mdbx.h++:3468
@ dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h++:3438
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3661
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3874
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++:2919
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4386
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4442
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2888
durability
Durability level.
Definition mdbx.h++:3065
@ lazy_weak_tail
Definition mdbx.h++:3068
@ robust_synchronous
Definition mdbx.h++:3066
@ whole_fragile
Definition mdbx.h++:3069
@ half_synchronous_weak_last
Definition mdbx.h++:3067
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++:2915
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3235
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++:4430
bool checkpoint(finalization_latency &latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4098
estimate_result estimate(move_operation operation, slice &key) const
cache_entry() noexcept
Definition mdbx.h++:2749
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3684
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4405
::MDBX_canary canary
Definition mdbx.h++:3902
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++:4101
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++:3725
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++:4335
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++:4399
bool clear_map(const char *name, bool throw_if_absent=false)
constexpr env() noexcept=default
friend constexpr bool operator!=(const env &a, const env &b) noexcept
Definition mdbx.h++:5246
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4408
void rename_map(map_handle map, const ::std::string_view &new_name)
Переименовывает таблицу ключ-значение.
env & copy(filehandle fd, bool compactify, bool force_dynamic_size=false)
Copy an environment to the specified file descriptor.
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
void reset() noexcept
Definition mdbx.h++:2756
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2909
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2889
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4494
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4353
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++:4344
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++:4170
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3781
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3957
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4376
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4162
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4166
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++:3866
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3162
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4360
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4563
MDBX_txn * handle_
Definition mdbx.h++:3685
void abort()
Abandon all the operations of the transaction instead of saving ones.
MDBX_commit_latency finalization_latency
Definition mdbx.h++:4063
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++:4332
mode
Operation mode.
Definition mdbx.h++:3057
@ write_mapped_io
Definition mdbx.h++:3060
@ nested_transactions
Definition mdbx.h++:3061
@ readonly
Definition mdbx.h++:3058
@ write_file_io
Definition mdbx.h++:3059
bool is_writemap() const
Definition mdbx.h++:3328
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4329
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4288
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3296
operator::mdbx::txn() const
Definition mdbx.h++:4471
MDBX_env * handle_
Definition mdbx.h++:2958
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++:4392
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4158
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4342
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4362
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:2752
bool is_nested_transactions_available() const
Definition mdbx.h++:3332
void close()
Explicitly closes the cursor.
Definition mdbx.h++:4547
void abort(finalization_latency &latency)
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4070
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++:4373
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3722
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++:4438
env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede=true)
void append(map_handle map, const pair &kv, bool multivalue_order_preserved=true)
Definition mdbx.h++:4005
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3266
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3276
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3278
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3273
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4264
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4347
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4309
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4553
::MDBX_dbi_state_t state
Definition mdbx.h++:2920
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3491
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4521
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++:3241
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4402
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++:4434
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4364
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4361
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4472
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3237
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2912
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3778
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2903
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++:4379
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3302
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3954
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++:6156
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4021
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++:3248
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++:3859
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2900
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++:4112
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++:4013
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++:4115
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++:2906
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++:4414
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4180
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4195
@ multi_exactkey_value_equal
Definition mdbx.h++:4212
@ pair_greater_or_equal
Definition mdbx.h++:4220
@ key_lesser_than
Definition mdbx.h++:4202
@ next
Definition mdbx.h++:4183
@ pair_exact
Definition mdbx.h++:4219
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4213
@ pair_lesser_or_equal
Definition mdbx.h++:4217
@ batch_samelength
Definition mdbx.h++:4223
@ seek_key
Definition mdbx.h++:4197
@ key_lowerbound
Definition mdbx.h++:4199
@ pair_lesser_than
Definition mdbx.h++:4216
@ pair_equal
Definition mdbx.h++:4218
@ key_greater_than
Definition mdbx.h++:4206
@ batch_samelength_next
Definition mdbx.h++:4224
@ multi_find_pair
Definition mdbx.h++:4194
@ key_greater_or_equal
Definition mdbx.h++:4205
@ key_exact
Definition mdbx.h++:4198
@ key_equal
Definition mdbx.h++:4204
@ multi_currentkey_prevvalue
Definition mdbx.h++:4189
@ key_lesser_or_equal
Definition mdbx.h++:4203
@ multi_nextkey_firstvalue
Definition mdbx.h++:4192
@ get_current
Definition mdbx.h++:4185
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4211
@ multi_prevkey_lastvalue
Definition mdbx.h++:4187
@ previous
Definition mdbx.h++:4184
@ last
Definition mdbx.h++:4182
@ pair_greater_than
Definition mdbx.h++:4221
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4210
@ multi_currentkey_firstvalue
Definition mdbx.h++:4188
@ first
Definition mdbx.h++:4181
@ batch_samelength_previous
Definition mdbx.h++:4225
@ multi_currentkey_nextvalue
Definition mdbx.h++:4190
@ seek_and_batch_samelength
Definition mdbx.h++:4226
@ multi_exactkey_value_greater
Definition mdbx.h++:4214
@ multi_currentkey_lastvalue
Definition mdbx.h++:4191
virtual ~env_managed() noexcept
finalization_latency commit_get_latency()
Commits all changes of the transaction into a database and return latency information.
Definition mdbx.h++:4087
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4338
void insert(const pair &kv)
Definition mdbx.h++:4495
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3719
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++:4497
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4350
txn_managed & operator=(const txn_managed &)=delete
bool is_cooperative() const
Definition mdbx.h++:3326
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3879
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:5244
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4389
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++:4357
bool is_readonly() const
Definition mdbx.h++:3322
value_result try_insert(const pair &kv)
Definition mdbx.h++:4496
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++:4513
constexpr cursor() noexcept=default
bool is_exclusive() const
Definition mdbx.h++:3324
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4367
finalization_latency abort_get_latency()
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4073
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4411
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3245
MDBX_cursor * handle_
Definition mdbx.h++:4134
~cursor_managed() noexcept
Definition mdbx.h++:4571
bool is_readwite() const
Definition mdbx.h++:3330
MDBX_dbi dbi
Definition mdbx.h++:2887
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4383
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4354
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3733
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++:4395
txn_managed(const txn_managed &)=delete
friend int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept
Definition mdbx.h++:6152
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3293
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3243
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3956
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3955
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++:3887
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4370
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++:4343
friend class txn
Definition mdbx.h++:2955
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4154
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3239
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3736
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4283
Unmanaged cursor.
Definition mdbx.h++:4132
Managed cursor.
Definition mdbx.h++:4533
Unmanaged database environment.
Definition mdbx.h++:2954
Managed database environment.
Definition mdbx.h++:3600
Unmanaged database transaction.
Definition mdbx.h++:3682
Managed database transaction.
Definition mdbx.h++:4039
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++:5287
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5151
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4821
polymorphic_allocator default_allocator
Definition mdbx.h++:381
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4830
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4912
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++:5125
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++:5063
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++:5054
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5636
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++:5315
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4926
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4671
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++:6028
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6263
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2801
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4808
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:4628
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4906
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5669
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++:4798
void rethrow_captured() const
Definition mdbx.h++:4643
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4806
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6221
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6197
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5280
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5254
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++:5072
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5991
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5945
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5534
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++:5465
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6165
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++:5104
::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++:4828
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6101
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++:5130
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4853
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4754
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6269
::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++:5938
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6113
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5766
void throw_on_failure() const
Definition mdbx.h++:4683
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6344
void update(const slice &key, const slice &value)
Definition mdbx.h++:6340
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:4625
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++:5837
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:4975
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4816
::MDBX_cmp_func comparator
Definition mdbx.h++:2932
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++:5119
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5638
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5601
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6152
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4952
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5398
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5825
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6330
bool is_clean() const noexcept
Definition mdbx.h++:4636
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2794
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4716
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++:5109
path_string::value_type path_char
Definition mdbx.h++:437
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5388
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2798
::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++:5440
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5273
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4896
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4650
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++:5135
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4579
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5006
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++:6056
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++:5572
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++:5537
void insert(const slice &key, slice value)
Definition mdbx.h++:6291
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6225
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++:5721
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:5200
::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++:2782
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++:5145
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4738
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:6115
~cursor() noexcept
Definition mdbx.h++:6136
~txn() noexcept
Definition mdbx.h++:5620
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5470
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:5099
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6217
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++:4834
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6271
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6316
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5265
map_handle map() const
Definition mdbx.h++:6276
unsigned sync_period__seconds_16dot16() const
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h++:5481
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:4632
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6209
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5737
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6229
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2862
void success_or_throw() const
Definition mdbx.h++:4688
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5673
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4868
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5521
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4956
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6156
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6235
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4864
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5271
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4873
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5643
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6334
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5396
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2790
void capture() noexcept
Definition mdbx.h++:4638
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:5081
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++:5802
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5973
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4847
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2933
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6309
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++:5577
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++:5335
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++:5476
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:6089
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5402
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5762
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6107
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++:6065
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5406
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5688
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4960
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6123
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5796
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6175
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++:5311
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++:5841
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5261
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5814
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5963
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4891
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4665
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++:5487
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4918
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4790
bool on_first() const
Definition mdbx.h++:6243
::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++:4826
bool eof() const
Definition mdbx.h++:6241
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5671
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5657
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5458
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6283
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5586
::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++:5094
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5610
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4858
bool seek(const slice &key)
Definition mdbx.h++:6233
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5510
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5460
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4880
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++:5379
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5764
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++:5499
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5216
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4841
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6296
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++:6397
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4701
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4659
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5655
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2941
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5156
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++:5140
double sync_period__seconds_double() const
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h++:5491
::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++:5357
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5222
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4948
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++:5819
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6375
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5410
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5049
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5663
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5925
::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++:4673
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:5076
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:5058
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6203
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4933
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:5067
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:5085
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5985
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5212
~env() noexcept
Definition mdbx.h++:5232
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2763
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5853
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4667
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4836
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++:6070
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5969
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4885
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2766
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5579
::mdbx::filesystem::path path
Definition mdbx.h++:428
bool on_last_multival() const
Definition mdbx.h++:6249
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5452
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5920
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5446
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++:5291
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5542
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6121
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5386
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5700
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2786
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5690
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5504
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4580
bool on_first_multival() const
Definition mdbx.h++:6247
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5912
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:4988
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4901
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5422
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5959
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5269
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++:5114
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6356
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:5675
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6213
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4792
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4814
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++:5197
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5565
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:6004
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4663
bool on_last() const
Definition mdbx.h++:6245
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++:6035
#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++:5434
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5515
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++:6265
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:5090
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5248
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5706
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4657
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5028
constexpr bool is_success() const noexcept
Definition mdbx.h++:4661
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6362
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:5001
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5608
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5208
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5694
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++:5753
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++:5891
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5808
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4800
@ multi_reverse_samelength
Definition mdbx.h++:2834
@ multi_samelength
Definition mdbx.h++:2819
@ multi_ordinal
Definition mdbx.h++:2826
@ msgpack
Definition mdbx.h++:2849
@ single
Definition mdbx.h++:2802
@ multi
Definition mdbx.h++:2804
@ multi_reverse
Definition mdbx.h++:2811
@ upsert
Insert or update.
Definition mdbx.h++:2943
@ update
Update existing, don't insert new.
Definition mdbx.h++:2944
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2942
@ continue_loop
Definition mdbx.h++:2763
@ exit_loop
Definition mdbx.h++:2763
@ usual
Definition mdbx.h++:2767
@ ordinal
Definition mdbx.h++:2772
@ reverse
Definition mdbx.h++:2769
@ msgpack
Definition mdbx.h++:2777
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2886
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2397
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2110
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++:1988
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2015
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++:2080
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1970
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++:2252
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2293
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:652
buffer_pair_spec(const txn &transacton, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2683
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++:2618
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++:2201
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++:2031
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2324
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2028
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2406
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2276
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++:2003
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2137
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2377
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2290
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2022
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2142
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2650
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1546
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++:2328
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2055
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2507
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2051
buffer & append(const byte c)
Definition mdbx.h++:2461
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2301
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++:2306
buffer & operator=(const buffer &src)
Definition mdbx.h++:2423
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1015
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2529
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:1997
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2692
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++:2048
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2608
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++:2183
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++:2265
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++:2259
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2178
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2471
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2221
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++:2661
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++:2663
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2402
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++:2245
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2628
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++:2271
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2175
slice value
Definition mdbx.h++:1063
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2654
::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++:1965
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2634
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++:2672
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++:2209
constexpr buffer & assign(buffer &&src) noexcept(allocation_aware_details::move_assign_alloc< silo, allocator_type >::is_nothrow())
Definition mdbx.h++:2365
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++:2432
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2614
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:712
const slice & slice() const noexcept
Definition mdbx.h++:2646
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2385
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++:2667
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2373
constexpr buffer(const buffer &src)
Definition mdbx.h++:2120
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++:2238
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++:2446
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2068
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2620
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2316
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++:2669
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2503
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2600
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1511
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2153
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++:2527
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:1982
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++:2632
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++:2427
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2499
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++:2105
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++:2612
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++:2233
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2148
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++:2391
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++:1974
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2636
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++:2696
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2562
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++:1547
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++:2626
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2099
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2429
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2712
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2479
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2550
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2511
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
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++:2216
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2642
slice inherited
Definition mdbx.h++:1540
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++:2638
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++:2640
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2295
static constexpr pair invalid() noexcept
Definition mdbx.h++:1078
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2088
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2381
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
pair & operator=(pair &&couple)
Definition mdbx.h++:1069
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++:1963
const bool uppercase
Definition mdbx.h++:1159
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1964
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2035
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2344
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2469
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2515
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2680
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2042
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++:2594
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++:2453
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++:2686
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++:2451
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++:2644
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2443
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2652
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++:2195
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2124
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1542
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2616
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2008
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++:2624
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2011
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++:2190
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2320
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2678
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1017
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2653
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2133
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1967
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2519
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2539
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1014
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2160
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++:2674
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2622
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++:2228
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2576
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++:2495
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2172
const unsigned wrap_width
Definition mdbx.h++:1244
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2425
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++:2062
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++:2481
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2689
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++:2488
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2128
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2605
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2651
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++:2116
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++:1991
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2073
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1538
Definition mdbx.h++:2649
Type tag for delivered buffer template classes.
Definition mdbx.h++:1534
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++:4659
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++:4657
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:5001
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:5005
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++:6445
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1633
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1635
byte lastbyte_
Definition mdbx.h++:1634
Definition mdbx.h++:4245
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4247
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4246
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4249
Definition mdbx.h++:4233
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++:4237
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4235
Tagged type for output to std::ostream.
Definition mdbx.h++:3006
intptr_t bytes
Definition mdbx.h++:3007
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3008
Database geometry for size management.
Definition mdbx.h++:2982
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3030
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3042
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:2989
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:2985
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:2988
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:2997
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:2986
@ default_value
Means "keep current or use default".
Definition mdbx.h++:2984
@ kB
bytes (0x03E8)
Definition mdbx.h++:2987
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:2996
@ KiB
bytes (0x0400)
Definition mdbx.h++:2995
constexpr geometry() noexcept
Definition mdbx.h++:3046
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3033
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3018
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3036
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3013
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++:3049
Operate options.
Definition mdbx.h++:3086
bool disable_readahead
Definition mdbx.h++:3095
bool enable_validation
Definition mdbx.h++:3099
bool no_sticky_threads
Definition mdbx.h++:3088
constexpr operate_options() noexcept
Definition mdbx.h++:3100
bool disable_clear_memory
Definition mdbx.h++:3097
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3093
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
bool nested_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3091
Operate parameters.
Definition mdbx.h++:3108
env::durability durability
Definition mdbx.h++:3116
env::operate_options options
Definition mdbx.h++:3118
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++:3122
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++:3114
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3117
env::mode mode
Definition mdbx.h++:3115
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++:3111
constexpr operate_parameters() noexcept
Definition mdbx.h++:3120
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3514
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3517
uint64_t transaction_lag
Definition mdbx.h++:3520
size_t bytes_used
Definition mdbx.h++:3524
uint64_t transaction_id
Definition mdbx.h++:3518
int slot
The reader lock table slot number.
Definition mdbx.h++:3515
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3516
size_t bytes_retained
Definition mdbx.h++:3527
Garbage reclaiming options.
Definition mdbx.h++:3073
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
bool coalesce
Definition mdbx.h++:3077
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3078
bool lifo
Definition mdbx.h++:3075
Additional parameters for creating a new database.
Definition mdbx.h++:3623
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3625
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3626
env::geometry geometry
Definition mdbx.h++:3624
Definition mdbx.h++:2921
map_handle::state state
Definition mdbx.h++:2923
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2922
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6550
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6546
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6545
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6536
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6535
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6531
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6527
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6540
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6541
capacity_holder capacity_
Definition mdbx.h++:1639
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1672
allocator_pointer stub_ptr_
Definition mdbx.h++:1614
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1651
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1692
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1643
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1658
inplace_flag_holder inplace_
Definition mdbx.h++:1640
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1642
allocator_pointer allocated_ptr_
Definition mdbx.h++:1638
size_t stub_capacity_bytes_
Definition mdbx.h++:1615
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1711
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1628
size_t bytes_
Definition mdbx.h++:1629
constexpr const byte * address() const noexcept
Definition mdbx.h++:1705
constexpr bin() noexcept
Definition mdbx.h++:1686
@ inplace_size
Definition mdbx.h++:1623
@ inplace_signature_limit
Definition mdbx.h++:1620
@ inplace_size_rounding
Definition mdbx.h++:1622
constexpr byte * address() noexcept
Definition mdbx.h++:1708
@ lastbyte_poison
Definition mdbx.h++:1618
@ lastbyte_inplace_signature
Definition mdbx.h++:1618
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1701
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1660