libmdbx 0.14.1.377 (2026-02-02T23:56:19+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
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
223#ifndef MDBX_LIKELY
224#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
225#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
226#else
227#define MDBX_LIKELY(x) (x)
228#endif
229#endif /* MDBX_LIKELY */
230
231#ifndef MDBX_UNLIKELY
232#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
233#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
234#else
235#define MDBX_UNLIKELY(x) (x)
236#endif
237#endif /* MDBX_UNLIKELY */
238
240#if defined(DOXYGEN)
241#define MDBX_IF_CONSTEXPR constexpr
242#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
243#define MDBX_IF_CONSTEXPR constexpr
244#else
245#define MDBX_IF_CONSTEXPR
246#endif /* MDBX_IF_CONSTEXPR */
247
248#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
249 __cplusplus >= 201703L
250#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
251#else
252#define MDBX_CXX17_FALLTHROUGH
253#endif /* MDBX_CXX17_FALLTHROUGH */
254
255#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
256#define MDBX_CXX20_LIKELY [[likely]]
257#else
258#define MDBX_CXX20_LIKELY
259#endif /* MDBX_CXX20_LIKELY */
260
261#ifndef MDBX_CXX20_UNLIKELY
262#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
263#define MDBX_CXX20_UNLIKELY [[unlikely]]
264#else
265#define MDBX_CXX20_UNLIKELY
266#endif
267#endif /* MDBX_CXX20_UNLIKELY */
268
269#ifndef MDBX_HAVE_CXX20_CONCEPTS
270#if defined(__cpp_concepts) && __cpp_concepts >= 202002L && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
271#include <concepts>
272#define MDBX_HAVE_CXX20_CONCEPTS 1
273#elif defined(DOXYGEN)
274#define MDBX_HAVE_CXX20_CONCEPTS 1
275#else
276#define MDBX_HAVE_CXX20_CONCEPTS 0
277#endif /* <concepts> */
278#endif /* MDBX_HAVE_CXX20_CONCEPTS */
279
280#ifndef MDBX_CXX20_CONCEPT
281#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
282#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
283#else
284#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
285#endif
286#endif /* MDBX_CXX20_CONCEPT */
287
288#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
289#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
290#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
291#else
292#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
293 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
294#endif
295#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
296
297#ifdef _MSC_VER
298#pragma warning(push, 4)
299#pragma warning(disable : 4127) /* conditional expression is constant */
300#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
301 be used by clients of 'mdbx::BAR' */
302#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
303 base for dll-interface 'mdbx::BAR' */
304/* MSVC is mad and can generate this warning for its own intermediate
305 * automatically generated code, which becomes unreachable after some kinds of
306 * optimization (copy elision, etc). */
307#pragma warning(disable : 4702) /* unreachable code */
308#endif /* _MSC_VER (warnings) */
309
310#if defined(__LCC__) && __LCC__ >= 126
311#pragma diagnostic push
312#if __LCC__ < 127
313#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
314 appearing in a constant expression `true` */
315#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
316 appearing in a constant expression `false` */
317#endif
318#endif /* E2K LCC (warnings) */
319
320//------------------------------------------------------------------------------
323namespace mdbx {
324
327
345#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
346using byte = char8_t;
347#else
348// Avoid `std::byte` since it doesn't add features but inconvenient restrictions.
349using byte = unsigned char;
350#endif /* __cpp_char8_t >= 201811*/
351
352#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
353using endian = ::std::endian;
354#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
355enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
356#else
357#error "Please use a C++ compiler provides byte order information or C++20 support"
358#endif /* Byte Order enum */
359
368
370static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
371
373static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
375static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
376
379using legacy_allocator = ::std::string::allocator_type;
380
383#if defined(DOXYGEN)
384#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
385#elif !defined(MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR)
386#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && \
387 (!defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI)
388#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
389#else
390#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 0
391#endif
392#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
393
394#if defined(DOXYGEN) || MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
396using polymorphic_allocator = ::std::pmr::string::allocator_type;
398#else
400#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
401
402struct slice;
404template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
406class env;
407class env_managed;
408class txn;
409class txn_managed;
410class cursor;
411class cursor_managed;
412
414using txnid = uint64_t;
415
417template <class ALLOCATOR = default_allocator>
418using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
419
421#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
422#ifdef _MSC_VER
423namespace filesystem = ::std::experimental::filesystem::v1;
424#else
425namespace filesystem = ::std::experimental::filesystem;
426#endif
427#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
428#elif defined(DOXYGEN) || \
429 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
430 __cpp_lib_string_view >= 201606L && \
431 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
432 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
433 (!defined(_MSC_VER) || __cplusplus >= 201703L)
434namespace filesystem = ::std::filesystem;
440#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
441#endif /* MDBX_STD_FILESYSTEM_PATH */
442
443#ifdef MDBX_STD_FILESYSTEM_PATH
445#elif defined(_WIN32) || defined(_WIN64)
446using path = ::std::wstring;
447#else
448using path = ::std::string;
449#endif /* mdbx::path */
450
451#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
452#ifndef MDBX_U128_TYPE
453#define MDBX_U128_TYPE __uint128_t
454#endif /* MDBX_U128_TYPE */
455#ifndef MDBX_I128_TYPE
456#define MDBX_I128_TYPE __int128_t
457#endif /* MDBX_I128_TYPE */
458#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
459
460#if __cplusplus >= 201103L || defined(DOXYGEN)
462using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
463#endif /* Duration for C++11 */
464
467
473 ::std::exception_ptr captured_;
474
475public:
476 exception_thunk() noexcept = default;
479 exception_thunk &operator=(const exception_thunk &) = delete;
480 exception_thunk &operator=(exception_thunk &&) = delete;
481 inline bool is_clean() const noexcept;
482 inline void capture() noexcept;
483 inline void rethrow_captured() const;
484};
485
488 MDBX_error_t code_;
489 inline error &operator=(MDBX_error_t error_code) noexcept;
490
491public:
492 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
493 error(const error &) = default;
494 error(error &&) = default;
495 error &operator=(const error &) = default;
496 error &operator=(error &&) = default;
497
498 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
499 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
500
501 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
502 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
503 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
504 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
505
507 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
508
510 const char *what() const noexcept;
511
513 ::std::string message() const;
514
516 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
518 [[noreturn]] void panic(const char *context_where_when, const char *func_who_what) const noexcept;
519 [[noreturn]] void throw_exception() const;
520 [[noreturn]] static inline void throw_exception(int error_code);
521 inline void throw_on_failure() const;
522 inline void success_or_throw() const;
523 inline void success_or_throw(const exception_thunk &) const;
524 inline void panic_on_failure(const char *context_where, const char *func_who) const noexcept;
525 inline void success_or_panic(const char *context_where, const char *func_who) const noexcept;
526 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
527 static inline void success_or_throw(MDBX_error_t error_code);
528 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
529 static inline void throw_on_failure(int error_code);
530 static inline bool boolean_or_throw(int error_code);
531 static inline void success_or_throw(int error_code, const exception_thunk &);
532 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
533 static inline void panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept;
534 static inline void success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept;
535};
536
539class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
540 using base = ::std::runtime_error;
541 ::mdbx::error error_;
542
543public:
544 exception(const ::mdbx::error &) noexcept;
545 exception(const exception &) = default;
546 exception(exception &&) = default;
547 exception &operator=(const exception &) = default;
549 virtual ~exception() noexcept;
550 const ::mdbx::error error() const noexcept { return error_; }
551};
552
555 using base = exception;
556
557public:
558 fatal(const ::mdbx::error &) noexcept;
559 fatal(const exception &src) noexcept : fatal(src.error()) {}
560 fatal(exception &&src) noexcept : fatal(src.error()) {}
561 fatal(const fatal &src) noexcept : fatal(src.error()) {}
562 fatal(fatal &&src) noexcept : fatal(src.error()) {}
563 fatal &operator=(fatal &&) = default;
564 fatal &operator=(const fatal &) = default;
565 virtual ~fatal() noexcept;
566};
567
568#define MDBX_DECLARE_EXCEPTION(NAME) \
569 struct LIBMDBX_API_TYPE NAME : public exception { \
570 NAME(const ::mdbx::error &); \
571 virtual ~NAME() noexcept; \
572 }
605#undef MDBX_DECLARE_EXCEPTION
606
609[[noreturn]] LIBMDBX_API void throw_out_range();
613
614static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
615 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
616 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
617 return bytes;
618}
619
620static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
621 return check_length(check_length(headroom) + check_length(payload));
622}
623
624MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
625 return check_length(check_length(headroom, payload) + check_length(tailroom));
626}
627
629
630//------------------------------------------------------------------------------
631
634
646
647 enum : size_t { max_length = MDBX_MAXDATASIZE };
648
650 MDBX_CXX11_CONSTEXPR slice() noexcept;
651
653 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
654
656 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
657
659 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
660 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
661 }
662
663 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
664
667 template <class CHAR, class T, class A>
668 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
669 : slice(str.data(), str.length() * sizeof(CHAR)) {}
670
672 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
674 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
675
676#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
677 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
678 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
679 "Must be a standard layout type!");
680 }
681
682 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
683 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
684 "Must be a standard layout type!");
685 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
687 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
689 }
690
691 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
692 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
693 "Must be a standard layout type!");
694 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
696 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
698 }
699
700 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
701 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
702 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
703 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
704#endif /* __cpp_lib_span >= 202002L */
705
706#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
708 template <class CHAR, class T>
709 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv) : slice(sv.data(), sv.data() + sv.length()) {}
710
711 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
712#endif /* __cpp_lib_string_view >= 201606L */
713
714 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
715
716 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
717 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
718 "Must be a standard layout type!");
719 return slice(&pod, sizeof(pod));
720 }
721
722 inline slice &assign(const void *ptr, size_t bytes);
723 inline slice &assign(const slice &src) noexcept;
724 inline slice &assign(const ::MDBX_val &src);
725 inline slice &assign(slice &&src) noexcept;
726 inline slice &assign(::MDBX_val &&src);
727 inline slice &assign(const void *begin, const void *end);
728 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
729 return assign(str.data(), str.length() * sizeof(CHAR));
730 }
731 inline slice &assign(const char *c_str);
732#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
733 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
734 return assign(view.begin(), view.end());
735 }
736 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
737 assign(view);
738 view = {};
739 return *this;
740 }
741#endif /* __cpp_lib_string_view >= 201606L */
742
743 slice &operator=(const slice &) noexcept = default;
744 inline slice &operator=(slice &&src) noexcept;
745 inline slice &operator=(::MDBX_val &&src);
746 operator MDBX_val *() noexcept { return this; }
747 operator const MDBX_val *() const noexcept { return this; }
748
749#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
750 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
751 return assign(view);
752 }
753
754 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
755
757 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
758 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
759 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
760 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
761 }
762
764 template <class CHAR, class T>
765 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
766 return this->string_view<CHAR, T>();
767 }
768#endif /* __cpp_lib_string_view >= 201606L */
769
770 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
771 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
772 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
773 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
774 }
775
776 template <class CHAR, class T, class ALLOCATOR>
777 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
779 }
780
782 template <class ALLOCATOR = default_allocator>
783 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
784 const ALLOCATOR &alloc = ALLOCATOR()) const;
785
788 template <class ALLOCATOR = default_allocator>
789 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
790
793 template <class ALLOCATOR = default_allocator>
794 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
795
797 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
798 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
799 const ALLOCATOR &alloc = ALLOCATOR()) const;
800
803 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
804 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
805 const ALLOCATOR &alloc = ALLOCATOR()) const;
806
809 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
810 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
811 const ALLOCATOR &alloc = ALLOCATOR()) const;
812
814 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
815 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
816 const ALLOCATOR &alloc = ALLOCATOR()) const;
817
820 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
821 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
822 const ALLOCATOR &alloc = ALLOCATOR()) const;
823
826 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
827 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
828 const ALLOCATOR &alloc = ALLOCATOR()) const;
829
835 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
836
841 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
842
848 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
849
855 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
856
857#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
858 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
859 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
860 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
861 *this = view;
862 view = temp;
863 }
864#endif /* __cpp_lib_string_view >= 201606L */
865
867 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
868 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
869
871 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
872 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
873
875 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
876 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
877
879 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
880 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
881
883 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
884 MDBX_CXX11_CONSTEXPR void *data() noexcept;
885
887 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
888 MDBX_CXX11_CONSTEXPR void *end() noexcept;
889
891 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
892
894 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
895
897 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
898
900 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
901
903 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
904
906 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
907
909 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
910
912 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
913
915 MDBX_CXX14_CONSTEXPR void clear() noexcept;
916
919 inline void remove_prefix(size_t n) noexcept;
920
923 inline void remove_suffix(size_t n) noexcept;
924
927 inline void safe_remove_prefix(size_t n);
928
931 inline void safe_remove_suffix(size_t n);
932
934 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
935
937 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
938
941 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
942
945 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
946
949 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
950
953 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
954
957 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
958
961 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
962
965 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
966
969 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
970
975 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
976
985 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
986
992 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
993 const slice &b) noexcept;
994 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
995 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
996 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
997 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
998 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
999 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
1000#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1001 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
1002#endif /* __cpp_impl_three_way_comparison */
1003
1005 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1006
1009 return slice(/* using special constructor without length checking */ ~size_t(0));
1010 }
1011
1013 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1014
1015 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1016 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1017 "Must be a standard layout type!");
1018 if (MDBX_LIKELY(size() == sizeof(POD)))
1020 POD r;
1021 memcpy(&r, data(), sizeof(r));
1022 return r;
1023 }
1025 }
1026
1027#ifdef MDBX_U128_TYPE
1028 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1029#endif /* MDBX_U128_TYPE */
1030 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1031 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1032 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1033 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1034
1035#ifdef MDBX_I128_TYPE
1036 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1037#endif /* MDBX_I128_TYPE */
1038 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1039 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1040 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1041 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1042
1043#ifdef MDBX_U128_TYPE
1044 MDBX_U128_TYPE as_uint128_adapt() const;
1045#endif /* MDBX_U128_TYPE */
1046 uint64_t as_uint64_adapt() const;
1047 uint32_t as_uint32_adapt() const;
1048 uint16_t as_uint16_adapt() const;
1049 uint8_t as_uint8_adapt() const;
1050
1051#ifdef MDBX_I128_TYPE
1052 MDBX_I128_TYPE as_int128_adapt() const;
1053#endif /* MDBX_I128_TYPE */
1054 int64_t as_int64_adapt() const;
1055 int32_t as_int32_adapt() const;
1056 int16_t as_int16_adapt() const;
1057 int8_t as_int8_adapt() const;
1058
1059protected:
1060 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1061};
1062
1066 bool done;
1067 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
1068 value_result(const value_result &) noexcept = default;
1069 value_result &operator=(const value_result &) noexcept = default;
1070 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1071 assert(!done || bool(value));
1072 return done;
1073 }
1074};
1075
1077struct pair {
1078 using stl_pair = std::pair<slice, slice>;
1080 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
1081 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
1082 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
1083 pair(const pair &) noexcept = default;
1084 pair &operator=(const pair &) noexcept = default;
1085 pair &operator=(pair &&couple) {
1086 key.assign(std::move(couple.key));
1087 value.assign(std::move(couple.value));
1088 return *this;
1089 }
1090 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1091 assert(bool(key) == bool(value));
1092 return key;
1093 }
1095
1096 pair &operator=(const stl_pair &couple) {
1097 key.assign(couple.first);
1098 value.assign(couple.second);
1099 return *this;
1100 }
1102 key.assign(std::move(couple.first));
1103 value.assign(std::move(couple.second));
1104 return *this;
1105 }
1106
1108 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
1109
1111 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
1112 const pair &b) noexcept;
1113 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
1114 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
1115 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
1116 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
1117 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
1118 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
1119#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1120 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
1121#endif /* __cpp_impl_three_way_comparison */
1122};
1123
1126struct pair_result : public pair {
1127 bool done;
1130 : pair(key, value), done(done) {}
1131 pair_result(const pair_result &) noexcept = default;
1132 pair_result &operator=(const pair_result &) noexcept = default;
1133 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1134 assert(!done || (bool(key) && bool(value)));
1135 return done;
1136 }
1137};
1138
1139#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
1140
1144template <typename T>
1145concept MutableByteProducer = requires(T a, char array[42]) {
1146 { a.is_empty() } -> std::same_as<bool>;
1147 { a.envisage_result_length() } -> std::same_as<size_t>;
1148 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1149};
1150
1154template <typename T>
1155concept ImmutableByteProducer = requires(const T &a, char array[42]) {
1156 { a.is_empty() } -> std::same_as<bool>;
1157 { a.envisage_result_length() } -> std::same_as<size_t>;
1158 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1159};
1160
1164template <typename T>
1165concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
1166 T(source);
1167 { a.is_erroneous() } -> std::same_as<bool>;
1168};
1169
1170#endif /* MDBX_HAVE_CXX20_CONCEPTS */
1171
1175 const bool uppercase = false;
1176 const unsigned wrap_width = 0;
1181
1183 template <class ALLOCATOR = default_allocator>
1184 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1185
1187 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1188 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1189
1193 const size_t bytes = source.length() << 1;
1194 return wrap_width ? bytes + bytes / wrap_width : bytes;
1195 }
1196
1199 char *write_bytes(char *dest, size_t dest_size) const;
1200
1203 ::std::ostream &output(::std::ostream &out) const;
1204
1207 bool is_empty() const noexcept { return source.empty(); }
1208
1211 bool is_erroneous() const noexcept { return false; }
1212};
1213
1218 const unsigned wrap_width = 0;
1223
1226 template <class ALLOCATOR = default_allocator>
1227 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1228
1231 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1232 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1233
1237 const size_t bytes = (source.length() * 11 + 7) / 8;
1238 return wrap_width ? bytes + bytes / wrap_width : bytes;
1239 }
1240
1243 char *write_bytes(char *dest, size_t dest_size) const;
1244
1247 ::std::ostream &output(::std::ostream &out) const;
1248
1250 bool is_empty() const noexcept { return source.empty(); }
1251
1253 bool is_erroneous() const noexcept { return false; }
1254};
1255
1260 const unsigned wrap_width = 0;
1265
1268 template <class ALLOCATOR = default_allocator>
1269 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1270
1273 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1274 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1275
1279 const size_t bytes = (source.length() + 2) / 3 * 4;
1280 return wrap_width ? bytes + bytes / wrap_width : bytes;
1281 }
1282
1286 char *write_bytes(char *dest, size_t dest_size) const;
1287
1291 ::std::ostream &output(::std::ostream &out) const;
1292
1295 bool is_empty() const noexcept { return source.empty(); }
1296
1299 bool is_erroneous() const noexcept { return false; }
1300};
1301
1305 const bool ignore_spaces = false;
1310
1312 template <class ALLOCATOR = default_allocator>
1313 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1314
1316 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1317 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1318
1321 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1322
1325 char *write_bytes(char *dest, size_t dest_size) const;
1326
1328 bool is_empty() const noexcept { return source.empty(); }
1329
1332 bool is_erroneous() const noexcept;
1333};
1334
1339 const bool ignore_spaces = false;
1344
1347 template <class ALLOCATOR = default_allocator>
1348 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1349
1352 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1353 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1354
1358 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1359 }
1360
1364 char *write_bytes(char *dest, size_t dest_size) const;
1365
1367 bool is_empty() const noexcept { return source.empty(); }
1368
1371 bool is_erroneous() const noexcept;
1372};
1373
1378 const bool ignore_spaces = false;
1383
1386 template <class ALLOCATOR = default_allocator>
1387 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1388
1391 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1392 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1393
1396 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1397
1401 char *write_bytes(char *dest, size_t dest_size) const;
1402
1405 bool is_empty() const noexcept { return source.empty(); }
1406
1410 bool is_erroneous() const noexcept;
1411};
1412
1414
1415template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1416#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1417 return ::std::allocator_traits<A>::is_always_equal::value;
1418#else
1419 return ::std::is_empty<A>::value;
1420#endif /* __cpp_lib_allocator_traits_is_always_equal */
1421}
1422
1423template <typename T, typename A = typename T::allocator_type,
1424 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1426
1427template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1428 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1429 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1430 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1431 }
1432 static MDBX_CXX20_CONSTEXPR void propagate(T *, T &) noexcept {}
1433};
1434
1435template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1436 static constexpr bool is_nothrow() noexcept {
1437 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1438 }
1439 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1440 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1441 target->get_allocator() = ::std::move(source.get_allocator());
1442 }
1443};
1444
1445template <typename T, typename A = typename T::allocator_type,
1446 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1448
1449template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1450 static constexpr bool is_nothrow() noexcept { return false; }
1451 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1452};
1453
1454template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1455 static constexpr bool is_nothrow() noexcept {
1456 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1457 }
1458 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1459 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1460 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1461 MDBX_CXX20_UNLIKELY target->get_allocator() =
1462 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1463 } else {
1464 /* gag for buggy compilers */
1465 (void)target;
1466 (void)source;
1467 }
1468 }
1469};
1470
1471template <typename T, typename A = typename T::allocator_type,
1472 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1474
1475template <typename T, typename A> struct swap_alloc<T, A, false> {
1476 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1477 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1479 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1480 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1481 } else {
1482 /* gag for buggy compilers */
1483 (void)left;
1484 (void)right;
1485 }
1486 }
1487};
1488
1489template <typename T, typename A> struct swap_alloc<T, A, true> {
1490 static constexpr bool is_nothrow() noexcept {
1491 return allocator_is_always_equal<A>() ||
1492#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1493 ::std::is_nothrow_swappable<A>() ||
1494#endif /* __cpp_lib_is_swappable >= 201603L */
1495 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1496 }
1497 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1498 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1499 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1500 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1501 } else {
1502 /* gag for buggy compilers */
1503 (void)left;
1504 (void)right;
1505 }
1506 }
1507};
1508
1509} // namespace allocation_aware_details
1510
1512 enum : size_t {
1517 };
1518
1519 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1520 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1521 static_assert(pettiness_threshold % 2 == 0, "pettiness_threshold must be even");
1522 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1523 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1524 return (value + pettiness_threshold - 1) & pettiness_mask;
1525 }
1526
1527 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1528 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1529 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1530
1531 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1532 return inplace;
1533
1534 if (wanna > current)
1535 /* doubling capacity, but don't made reserve more than max_reserve */
1536 return round(wanna + ::std::min(size_t(max_reserve), current));
1537
1538 if (current - wanna >
1539 /* shrink if reserve will more than half of current or max_reserve,
1540 * but not less than pettiness_threshold */
1541 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1542 return round(wanna);
1543
1544 /* keep unchanged */
1545 return current;
1546 }
1547};
1548
1550struct buffer_tag {};
1551
1553template <class ALLOCATOR, typename CAPACITY_POLICY>
1555public:
1557#if !defined(_MSC_VER) || _MSC_VER > 1900
1558 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1559#else
1560 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1561#endif /* MSVC is mad */
1562 using allocator_traits = ::std::allocator_traits<allocator_type>;
1563 using reservation_policy = CAPACITY_POLICY;
1564 enum : size_t {
1566 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1569 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1570 ? alignof(max_align_t) * 2
1573 };
1574
1575private:
1576 friend class txn;
1577 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1578 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1579 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1580
1581 using allocator_pointer = typename allocator_traits::pointer;
1582 using allocator_const_pointer = typename allocator_traits::const_pointer;
1583
1584 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1585 assert(bytes >= sizeof(bin));
1586 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1587 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1588 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1589 const size_t n = (bytes + unit - 1) / unit;
1590 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1591 }
1592
1593 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1594 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1595 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1596 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1597 }
1598
1599 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1600 const size_t capacity = bin::advise_capacity(0, bytes);
1601 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1602 : allocate_storage(capacity);
1603 }
1604
1605 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1606#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1607 return static_cast<void *>(::std::to_address(ptr));
1608#else
1609 return static_cast<void *>(::std::addressof(*ptr));
1610#endif /* __cpp_lib_to_address */
1611 }
1612
1613 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1614#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1615 return static_cast<const void *>(::std::to_address(ptr));
1616#else
1617 return static_cast<const void *>(::std::addressof(*ptr));
1618#endif /* __cpp_lib_to_address */
1619 }
1620
1621#ifdef _MSC_VER
1622#pragma warning(push)
1623#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1624#endif /* _MSC_VER */
1625
1626 union alignas(max_align_t) bin {
1627 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1628 с учетом выравнивания */
1629 {
1630 allocator_pointer stub_ptr_;
1632 };
1633
1635 enum : size_t {
1637 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1641 };
1642
1644 byte pad_[inplace_size - sizeof(allocator_pointer)];
1645 size_t bytes_;
1646 };
1647
1649 byte buffer_[inplace_size - sizeof(byte)];
1651 MDBX_CXX11_CONSTEXPR inplace_flag_holder(byte signature) : lastbyte_(signature) {};
1652 };
1653
1654 allocator_pointer allocated_ptr_;
1657
1658 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1659 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1660 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1661 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1662 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1663 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1664 return capacity_bytes <= inplace_capacity();
1665 }
1666
1667 constexpr bool is_inplace() const noexcept {
1668 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1669 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1671 "WTF?");
1672 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1673 }
1674 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1675
1676 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1677 if (destroy_ptr) {
1679 /* properly destroy allocator::pointer */
1680 allocated_ptr_.~allocator_pointer();
1681 }
1684 return address();
1685 }
1686
1687 template <bool construct_ptr>
1688 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1690 if (construct_ptr) {
1692 new (&allocated_ptr_) allocator_pointer(pair.first);
1693 } else {
1695 allocated_ptr_ = pair.first;
1696 }
1697 capacity_.bytes_ = pair.second;
1698 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1699 return address();
1700 }
1701
1703 if (::std::is_trivial<allocator_pointer>::value)
1704 /* workaround for "uninitialized" warning from some compilers */
1705 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1706 }
1707
1708 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1709 if (MDBX_UNLIKELY(wanna > max_capacity))
1710 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1711
1712 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1713 assert(advised >= wanna);
1714 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1715 }
1716
1717 constexpr bool is_inplace(const void *ptr) const noexcept {
1718 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1719 }
1720
1721 constexpr const byte *address() const noexcept {
1722 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1723 }
1725 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1726 }
1727 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1728 } bin_;
1729
1730#ifdef _MSC_VER
1731#pragma warning(pop)
1732#endif /* _MSC_VER */
1733
1734 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1735
1736 MDBX_CXX20_CONSTEXPR void release() noexcept {
1737 if (bin_.is_allocated()) {
1738 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1739 /* properly destroy allocator::pointer */
1740 bin_.allocated_ptr_.~allocator_pointer();
1741 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1742 }
1743 }
1744
1745 template <bool external_content>
1746 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1747 const void *const content, const size_t length) {
1748 assert(wanna_capacity >= wanna_headroom + length);
1749 const size_t old_capacity = bin_.capacity();
1750 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1751 if (MDBX_LIKELY(new_capacity == old_capacity))
1753 assert(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1754 byte *const new_place = bin_.address() + wanna_headroom;
1755 if (MDBX_LIKELY(length))
1757 if (external_content)
1758 memcpy(new_place, content, length);
1759 else {
1760 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1761 assert(old_capacity >= old_headroom + length);
1762 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1763 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1764 }
1765 }
1766 return new_place;
1767 }
1768
1769 if (bin::is_suitable_for_inplace(new_capacity)) {
1770 assert(bin_.is_allocated());
1771 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1772 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1773 if (MDBX_LIKELY(length))
1774 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1775 deallocate_storage(old_allocated, old_capacity);
1776 return new_place;
1777 }
1778
1779 if (bin_.is_inplace()) {
1780 const auto pair = allocate_storage(new_capacity);
1781 assert(pair.second >= new_capacity);
1782 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1783 if (MDBX_LIKELY(length))
1784 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1785 bin_.template make_allocated<true>(pair);
1786 return new_place;
1787 }
1788
1789 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1790 if (external_content)
1791 deallocate_storage(old_allocated, old_capacity);
1792 const auto pair = allocate_storage(new_capacity);
1793 assert(pair.second >= new_capacity);
1794 byte *const new_place = bin_.template make_allocated<false>(pair) + wanna_headroom;
1795 if (MDBX_LIKELY(length))
1796 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1797 if (!external_content)
1798 deallocate_storage(old_allocated, old_capacity);
1799 return new_place;
1800 }
1801
1802 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1803 assert(capacity() >= offset);
1804 return bin_.address() + offset;
1805 }
1806 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1807 assert(capacity() >= offset);
1808 return bin_.address() + offset;
1809 }
1810 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1811 assert(capacity() >= offset + length);
1812 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1813 }
1814
1815 //--------------------------------------------------------------------------
1816
1817 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1818 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1819 if (!bin::is_suitable_for_inplace(capacity))
1820 bin_.template make_allocated<true>(provide_storage(capacity));
1821 }
1822
1823 silo(silo &&other) = delete;
1825 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1826 : allocator_type(::std::move(other.get_allocator())) {
1827 if (!is_reference) {
1828 if (other.bin_.is_inplace()) {
1829 memcpy(&bin_, &other.bin_, sizeof(bin));
1830 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1831 } else {
1832 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1833 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1834 /* properly destroy allocator::pointer.
1835 *
1836 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1837 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1838 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1839 * from the 11th). */
1840 /* coverity[use_after_move] */
1841 other.bin_.allocated_ptr_.~allocator_pointer();
1842 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1843 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1844 }
1845 }
1846 }
1847
1848 MDBX_CXX17_CONSTEXPR bool move(silo &&other) noexcept {
1849 if (other.bin_.is_inplace()) {
1850 memcpy(&bin_, &other.bin_, sizeof(bin));
1851 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1852 return /* buffer's slice fixup is needed */ true;
1853 }
1854 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1855 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1856 /* properly destroy allocator::pointer.
1857 *
1858 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1859 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1860 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1861 * from the 11th). */
1862 /* coverity[use_after_move] */
1863 other.bin_.allocated_ptr_.~allocator_pointer();
1864 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1865 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1866 return false;
1867 }
1868
1869 MDBX_CXX17_CONSTEXPR bool assign_move(silo &&other, bool is_reference) noexcept {
1870 release();
1871 if (!allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, other))
1872 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, other);
1873 return is_reference ? false : move(std::move(other));
1874 }
1875
1876 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1877 exchange(silo &left, const bool left_is_reference, silo &right, const bool right_is_reference) noexcept(
1878 allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1879 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(left, right);
1880 bool left_need_fixup = false, right_need_fixup = false;
1881 if (left_is_reference || right_is_reference) {
1882 left_need_fixup = !right_is_reference && left.move(std::move(right));
1883 right_need_fixup = !left_is_reference && right.move(std::move(left));
1884 } else {
1885 silo temp(std::move(left), false);
1886 left_need_fixup = left.move(std::move(right));
1887 right_need_fixup = right.move(std::move(temp));
1888 }
1889 return std::make_pair(left_need_fixup, right_need_fixup);
1890 }
1891
1892 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1893 const allocator_type &alloc = allocator_type())
1894 : silo(capacity, alloc) {
1895 assert(capacity >= headroom + length);
1896 if (length)
1897 put(headroom, ptr, length);
1898 }
1899
1900 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1901 : silo(length, 0, ptr, length, alloc) {}
1902
1903 ~silo() { release(); }
1904
1905 //--------------------------------------------------------------------------
1906
1907 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1908 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1909 }
1910
1911 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1912
1913 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1914 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1915 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1916 }
1917
1918 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1919 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1920 }
1921
1922 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1923 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1924 return get(offset);
1925 }
1926 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1927 };
1928
1929 MDBX_CXX14_CONSTEXPR void fixup_import(const typename silo::bin &src) noexcept {
1930 auto ptr = inherited::byte_ptr();
1931 if (src.is_inplace(ptr)) {
1932 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1933 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1934 iov_base = ptr + offset;
1935 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1936 }
1937 }
1938
1939 silo silo_;
1940
1941 void insulate() {
1942 assert(is_reference());
1943 iov_base = silo_.assign(iov_base, iov_len);
1944 }
1945
1946 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1947 return static_cast<const byte *>(silo_.data());
1948 }
1949
1950 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1951 return silo_begin() + silo_.capacity();
1952 }
1953
1954 struct data_preserver : public exception_thunk {
1955 buffer data;
1956 data_preserver(allocator_type &alloc) : data(alloc) {}
1957 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1958 auto self = static_cast<data_preserver *>(context);
1959 assert(self->is_clean());
1960 assert(&self->data == target);
1961 (void)target;
1962 try {
1963 self->data.assign(src, bytes, false);
1964 return MDBX_RESULT_FALSE;
1965 } catch (... /* capture any exception to rethrow it over C code */) {
1966 self->capture();
1967 return MDBX_RESULT_TRUE;
1968 }
1969 }
1970 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1971 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1972 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1973 };
1974
1975public:
1978
1982
1983 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1984
1986 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1987
1991 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1992 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1993 }
1994
1999 return silo_.is_inplace(inherited::data());
2000 }
2001
2005
2008 return is_freestanding() ? silo_.capacity() : 0;
2009 }
2010
2014 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
2015 }
2016
2020 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2021 }
2022
2024 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2025
2027 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2028
2035
2040 return const_cast<byte *>(inherited::end_byte_ptr());
2041 }
2042
2044 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2045
2047 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2048
2053 return const_cast<char *>(inherited::char_ptr());
2054 }
2055
2060 return const_cast<char *>(inherited::end_char_ptr());
2061 }
2062
2064 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
2065
2067 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
2068
2071 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2073 return const_cast<void *>(inherited::data());
2074 }
2075
2078 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2080 return const_cast<void *>(inherited::end());
2081 }
2082
2087
2094
2097 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2098 return set_length(static_cast<const char *>(ptr) - char_ptr());
2099 }
2100
2105 if (is_reference())
2106 insulate();
2107 }
2108
2109 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2110 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2111 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2112 const allocator_type &alloc = allocator_type());
2113
2115 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2116 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2117
2118 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2119 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2120
2121 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2122 : buffer(inherited(c_str), make_reference, alloc) {}
2123
2124#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2125 template <class CHAR, class T>
2126 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2127 const allocator_type &alloc = allocator_type())
2128 : buffer(inherited(view), make_reference, alloc) {}
2129#endif /* __cpp_lib_string_view >= 201606L */
2130
2132 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2133 : buffer(src, src.empty() || src.is_null(), alloc) {}
2134
2136 buffer(const buffer &src)
2137 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2138
2140 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2141 : buffer(inherited(ptr, bytes), alloc) {}
2142
2143 template <class CHAR, class T, class A>
2144 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2145 const allocator_type &alloc = allocator_type())
2146 : buffer(inherited(str), alloc) {}
2147
2149 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2150
2151#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2152 template <class CHAR, class T>
2153 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2154 const allocator_type &alloc = allocator_type())
2155 : buffer(inherited(view), alloc) {}
2156#endif /* __cpp_lib_string_view >= 201606L */
2157
2158 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2159 : silo_(check_length(head_room, tail_room), alloc) {
2160 iov_base = silo_.get();
2161 assert(iov_len == 0);
2162 }
2163
2164 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2165 iov_base = silo_.get();
2166 assert(iov_len == 0);
2167 }
2168
2169 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2170 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2171 iov_base = memcpy(silo_.get(), src.data(), iov_len = src.length());
2172 }
2173
2174 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2175
2176 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2177 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2178 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2179 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2180 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2181 * 11th). */
2182 /* coverity[use_after_move] */
2183 fixup_import(src.silo_.bin_);
2184 src.invalidate();
2185 }
2186
2188 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2189
2192
2193 template <typename POD>
2194 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2195 return buffer(inherited::wrap(pod), make_reference, alloc);
2196 }
2197
2199 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2200 const allocator_type &alloc = allocator_type()) {
2201 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2202 }
2203
2206 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2207 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2208 }
2209
2211 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2212 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2213 }
2214
2216 template <typename POD>
2217 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2218 const allocator_type &alloc = allocator_type()) {
2219 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2220 }
2221
2224 template <typename POD>
2225 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2226 return base58(inherited::wrap(pod), wrap_width, alloc);
2227 }
2228
2231 template <typename POD>
2232 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2233 return base64(inherited::wrap(pod), wrap_width, alloc);
2234 }
2235
2237 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2238 const allocator_type &alloc = allocator_type()) const {
2239 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2240 }
2241
2244 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2245 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2246 }
2247
2249 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2250 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2251 }
2252
2254 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2255 const allocator_type &alloc = allocator_type()) {
2256 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2257 }
2258
2261 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2262 const allocator_type &alloc = allocator_type()) {
2263 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2264 }
2265
2268 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2269 const allocator_type &alloc = allocator_type()) {
2270 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2271 }
2272
2275 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2276 return hex_decode(*this, ignore_spaces, alloc);
2277 }
2278
2281 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2282 return base58_decode(*this, ignore_spaces, alloc);
2283 }
2284
2287 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2288 return base64_decode(*this, ignore_spaces, alloc);
2289 }
2290
2292 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2293 wanna_headroom = ::std::min(
2294 ::std::max(headroom(), wanna_headroom),
2295 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2296 wanna_tailroom = ::std::min(
2297 ::std::max(tailroom(), wanna_tailroom),
2298 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2299 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2300 silo_.resize(wanna_capacity, wanna_headroom, *this);
2301 assert(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2302 assert(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2303 }
2304
2306 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2307
2309 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2310
2311 buffer &assign_reference(const void *ptr, size_t bytes) {
2312 silo_.clear();
2314 return *this;
2315 }
2316
2317 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2318 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2319 return *this;
2320 }
2321
2322 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2323 const auto pair = silo::exchange(silo_, is_reference(), other.silo_, other.is_reference());
2324 std::swap(iov_base, other.iov_base);
2325 std::swap(iov_len, other.iov_len);
2326 if (pair.first)
2327 fixup_import(other.silo_.bin_);
2328 if (pair.second)
2329 other.fixup_import(silo_.bin_);
2330 }
2331
2332 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2333 left.swap(right);
2334 }
2335
2336 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2337 return buffer(src.headroom(), src, src.tailroom(), alloc);
2338 }
2339
2341 return buffer(slice(), !is_inplace(), allocator_traits::select_on_container_copy_construction(get_allocator()));
2342 }
2343
2345 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2346 invalidate();
2347 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2348 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2349 MDBX_CXX20_UNLIKELY {
2350 silo_.release();
2352 }
2353 }
2354
2355 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2356 iov_len = src.length();
2357 return *this;
2358 }
2359
2360 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2361 invalidate();
2362 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2363 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2364 MDBX_CXX20_UNLIKELY {
2365 silo_.release();
2367 }
2368 }
2369
2370 if (make_reference) {
2371 silo_.release();
2372 iov_base = src.iov_base;
2373 } else {
2374 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2375 }
2376 iov_len = src.length();
2377 return *this;
2378 }
2379
2382 const bool is_reference = src.is_reference();
2383 inherited::assign(std::move(src));
2384 if (silo_.assign_move(std::move(src.silo_), is_reference))
2385 fixup_import(src.silo_.bin_);
2386 return *this;
2387 }
2388
2389 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2390 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2391 }
2392
2393 buffer &assign(const struct slice &src, bool make_reference = false) {
2394 return assign(src.data(), src.length(), make_reference);
2395 }
2396
2397 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2398 return assign(src.iov_base, src.iov_len, make_reference);
2399 }
2400
2401 buffer &assign(struct slice &&src, bool make_reference = false) {
2402 assign(src.data(), src.length(), make_reference);
2403 src.invalidate();
2404 return *this;
2405 }
2406
2407 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2408 assign(src.iov_base, src.iov_len, make_reference);
2409 src.iov_base = nullptr;
2410 return *this;
2411 }
2412
2413 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2414 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2415 }
2416
2417 template <class CHAR, class T, class A>
2418 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2419 return assign(str.data(), str.length(), make_reference);
2420 }
2421
2422 buffer &assign(const char *c_str, bool make_reference = false) {
2423 return assign(c_str, strlen(c_str), make_reference);
2424 }
2425
2426#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2427 template <class CHAR, class T>
2428 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2429 return assign(view.data(), view.length(), make_reference);
2430 }
2431
2432 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2433 assign(view.data(), view.length(), make_reference);
2434 view = {};
2435 return *this;
2436 }
2437#endif /* __cpp_lib_string_view >= 201606L */
2438
2439 buffer &operator=(const buffer &src) { return assign(src); }
2440
2441 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2442
2443 buffer &operator=(const struct slice &src) { return assign(src); }
2444
2445 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2446
2447#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2448 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2449 return assign(view.begin(), view.length());
2450 }
2451#endif /* __cpp_lib_string_view >= 201606L */
2452
2453 template <class CHAR, class T, class A>
2454 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2455 return as_string<CHAR, T, A>();
2456 }
2457
2459 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2460
2462 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2463 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2464 }
2465
2467 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2468
2469 buffer &append(const void *src, size_t bytes) {
2470 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2471 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2472 memcpy(end_byte_ptr(), src, bytes);
2473 iov_len += bytes;
2474 return *this;
2475 }
2476
2477 buffer &append(const byte c) {
2478 if (MDBX_UNLIKELY(tailroom() < 1))
2479 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2480 *end_byte_ptr() = c;
2481 iov_len += 1;
2482 return *this;
2483 }
2484
2485 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2486
2487 buffer &add_header(const void *src, size_t bytes) {
2488 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2489 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2490 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2491 iov_len += bytes;
2492 return *this;
2493 }
2494
2495 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2496
2497 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2498 const size_t wanna_bytes = producer.envisage_result_length();
2499 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2500 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2501 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2502 }
2503
2504 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2505 const size_t wanna_bytes = producer.envisage_result_length();
2506 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2507 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2508 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2509 }
2510
2511 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2512 return append_producer(to_hex(data, uppercase, wrap_width));
2513 }
2514
2515 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2516 return append_producer(to_base58(data, wrap_width));
2517 }
2518
2519 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2520 return append_producer(to_base64(data, wrap_width));
2521 }
2522
2523 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2524 return append_producer(from_hex(data, ignore_spaces));
2525 }
2526
2527 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2528 return append_producer(from_base58(data, ignore_spaces));
2529 }
2530
2531 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2532 return append_producer(from_base64(data, ignore_spaces));
2533 }
2534
2535 buffer &append_u8(uint_fast8_t u8) {
2536 if (MDBX_UNLIKELY(tailroom() < 1))
2537 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2538 *end_byte_ptr() = uint8_t(u8);
2539 iov_len += 1;
2540 return *this;
2541 }
2542
2543 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2544
2545 buffer &append_u16(uint_fast16_t u16) {
2546 if (MDBX_UNLIKELY(tailroom() < 2))
2547 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2548 const auto ptr = end_byte_ptr();
2549 ptr[0] = uint8_t(u16);
2550 ptr[1] = uint8_t(u16 >> 8);
2551 iov_len += 2;
2552 return *this;
2553 }
2554
2555 buffer &append_u24(uint_fast32_t u24) {
2556 if (MDBX_UNLIKELY(tailroom() < 3))
2557 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2558 const auto ptr = end_byte_ptr();
2559 ptr[0] = uint8_t(u24);
2560 ptr[1] = uint8_t(u24 >> 8);
2561 ptr[2] = uint8_t(u24 >> 16);
2562 iov_len += 3;
2563 return *this;
2564 }
2565
2566 buffer &append_u32(uint_fast32_t u32) {
2567 if (MDBX_UNLIKELY(tailroom() < 4))
2568 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2569 const auto ptr = end_byte_ptr();
2570 ptr[0] = uint8_t(u32);
2571 ptr[1] = uint8_t(u32 >> 8);
2572 ptr[2] = uint8_t(u32 >> 16);
2573 ptr[3] = uint8_t(u32 >> 24);
2574 iov_len += 4;
2575 return *this;
2576 }
2577
2578 buffer &append_u48(uint_fast64_t u48) {
2579 if (MDBX_UNLIKELY(tailroom() < 6))
2580 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2581 const auto ptr = end_byte_ptr();
2582 ptr[0] = uint8_t(u48);
2583 ptr[1] = uint8_t(u48 >> 8);
2584 ptr[2] = uint8_t(u48 >> 16);
2585 ptr[3] = uint8_t(u48 >> 24);
2586 ptr[4] = uint8_t(u48 >> 32);
2587 ptr[5] = uint8_t(u48 >> 40);
2588 iov_len += 6;
2589 return *this;
2590 }
2591
2592 buffer &append_u64(uint_fast64_t u64) {
2593 if (MDBX_UNLIKELY(tailroom() < 8))
2594 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2595 const auto ptr = end_byte_ptr();
2596 ptr[0] = uint8_t(u64);
2597 ptr[1] = uint8_t(u64 >> 8);
2598 ptr[2] = uint8_t(u64 >> 16);
2599 ptr[3] = uint8_t(u64 >> 24);
2600 ptr[4] = uint8_t(u64 >> 32);
2601 ptr[5] = uint8_t(u64 >> 40);
2602 ptr[6] = uint8_t(u64 >> 48);
2603 ptr[7] = uint8_t(u64 >> 56);
2604 iov_len += 8;
2605 return *this;
2606 }
2607
2608 //----------------------------------------------------------------------------
2609
2610 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2611 return buffer(inherited(text), make_reference);
2612 }
2613
2614#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2615 template <class CHAR, class T>
2616 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2617 return buffer(src, make_reference);
2618 }
2619#endif /* __cpp_lib_string_view >= 201606L */
2620
2621 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2622
2623 template <class CHAR, class T, class A>
2624 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2625 return buffer(src, make_reference);
2626 }
2627
2628 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2629
2630 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2631
2632 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2633
2634 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2635
2636 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2637
2638 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2639
2640 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2641
2642 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2643
2644 static buffer key_from_jsonInteger(const int64_t json_integer) {
2645 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2646 }
2647
2648 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2649
2650 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2651
2652 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2653
2654 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2655
2656 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2657
2658 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2659
2660 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2661
2662 const slice &slice() const noexcept { return *this; }
2663};
2664
2665template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2669 using reservation_policy = CAPACITY_POLICY;
2670 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2672
2675 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2676
2678 : key(key, alloc), value(value, alloc) {}
2679 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2680 const allocator_type &alloc = allocator_type())
2681 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2682
2684 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2685 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2686 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2687
2689 : key(key, alloc), value(value, alloc) {}
2690 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2691 const allocator_type &alloc = allocator_type())
2692 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2693
2696 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2697 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2698
2699 buffer_pair_spec(const txn &transacton, const slice &key, const slice &value,
2700 const allocator_type &alloc = allocator_type())
2701 : key(transacton, key, alloc), value(transacton, value, alloc) {}
2702 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2703 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2704
2705 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2706 : key(::std::move(key)), value(::std::move(value)) {}
2708 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2709 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2710
2713 key.assign(std::move(src.key));
2714 value.assign(std::move(src.value));
2715 return *this;
2716 }
2717
2719 key.assign(src.key);
2720 value.assign(src.value);
2721 return *this;
2722 }
2724 key.assign(std::move(src.key));
2725 value.assign(std::move(src.value));
2726 return *this;
2727 }
2729 key.assign(src.first);
2730 value.assign(src.second);
2731 return *this;
2732 }
2734 key.assign(std::move(src.first));
2735 value.assign(std::move(src.second));
2736 return *this;
2737 }
2738
2742 return key.is_freestanding() && value.is_freestanding();
2743 }
2744
2747 return key.is_reference() || value.is_reference();
2748 }
2749
2753 key.make_freestanding();
2754 value.make_freestanding();
2755 }
2756
2757 operator pair() const noexcept { return pair(key, value); }
2758};
2759
2761
2764public:
2765 cache_entry() noexcept { reset(); }
2766 cache_entry(const cache_entry &) noexcept = default;
2767 cache_entry &operator=(const cache_entry &) noexcept = default;
2768 cache_entry(cache_entry &&other) noexcept {
2769 *this = other;
2770 other.reset();
2771 }
2772 void reset() noexcept { mdbx_cache_init(this); }
2773};
2774
2775//------------------------------------------------------------------------------
2776
2779enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2780
2797
2799 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2800}
2801
2803 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2804}
2805
2807 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2808}
2809
2811 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2812}
2813
2815
2873
2877
2879 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2880}
2881
2883 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2884}
2885
2887 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2888}
2889
2891 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2892}
2893
2895
2906 map_handle(const map_handle &) noexcept = default;
2907 map_handle &operator=(const map_handle &) noexcept = default;
2908 operator bool() const noexcept { return dbi != 0; }
2909 operator MDBX_dbi() const { return dbi; }
2910
2911#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2912 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2913 return a.dbi <=> b.dbi;
2914 }
2915#endif /* __cpp_impl_three_way_comparison */
2916 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2917 return a.dbi == b.dbi;
2918 }
2919 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2920 return a.dbi < b.dbi;
2921 }
2922 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2923 return a.dbi > b.dbi;
2924 }
2925 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2926 return a.dbi <= b.dbi;
2927 }
2928 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2929 return a.dbi >= b.dbi;
2930 }
2931 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2932 return a.dbi != b.dbi;
2933 }
2934
2946};
2947
2950 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2951}
2953 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2954}
2955
2962
2971 friend class txn;
2972
2973protected:
2975 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2976
2977public:
2978 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2979 env(const env &) noexcept = default;
2980 env &operator=(const env &) noexcept = default;
2981 inline env &operator=(env &&) noexcept;
2982 inline env(env &&) noexcept;
2983 inline ~env() noexcept;
2984
2985 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
2986 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
2987 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
2988 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
2989 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
2990
2991 //----------------------------------------------------------------------------
2992
2997
2999 enum : intptr_t {
3002 maximal_value = INTPTR_MAX,
3003 kB = 1000,
3004 MB = kB * 1000,
3005 GB = MB * 1000,
3006#if INTPTR_MAX > 0x7fffFFFFl
3007 TB = GB * 1000,
3008 PB = TB * 1000,
3009 EB = PB * 1000,
3010#endif /* 64-bit intptr_t */
3011 KiB = 1024,
3012 MiB = KiB << 10,
3013 GiB = MiB << 10,
3014#if INTPTR_MAX > 0x7fffFFFFl
3015 TiB = GiB << 10,
3016 PiB = TiB << 10,
3017 EiB = PiB << 10,
3018#endif /* 64-bit intptr_t */
3019 };
3020
3022 struct size {
3023 intptr_t bytes;
3024 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3025 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3026 };
3027
3030
3035
3047
3050
3053
3059
3060 inline geometry &make_fixed(intptr_t size) noexcept;
3061 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3064 geometry(const geometry &) noexcept = default;
3070 };
3071
3079
3087
3100
3122
3127 unsigned max_maps{0};
3130 unsigned max_readers{0};
3135
3146 operate_parameters(const operate_parameters &) noexcept = default;
3148 MDBX_env_flags_t make_flags(bool accede = true,
3151 bool use_subdirectory = false
3152 ) const;
3156 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3157 };
3158
3162 inline env::mode get_mode() const;
3164 inline env::durability get_durability() const;
3168 inline env::operate_options get_options() const;
3169
3172 bool is_pristine() const;
3173
3175 bool is_empty() const;
3176
3178 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3179
3180 struct limits {
3181 limits() = delete;
3183 static inline size_t pagesize_min() noexcept;
3185 static inline size_t pagesize_max() noexcept;
3187 static inline size_t dbsize_min(intptr_t pagesize);
3189 static inline size_t dbsize_max(intptr_t pagesize);
3191 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3193 static inline size_t key_min(key_mode mode) noexcept;
3195 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3197 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3199 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3201 static inline size_t key_max(const env &, key_mode mode);
3203 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3205 static inline size_t value_min(value_mode) noexcept;
3206
3208 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3210 static inline size_t value_max(intptr_t pagesize, value_mode);
3212 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3214 static inline size_t value_max(const env &, value_mode);
3215
3218 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3221 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3224 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3227 static inline size_t pairsize4page_max(const env &, value_mode);
3228
3231 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3234 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3237 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3240 static inline size_t valsize4page_max(const env &, value_mode);
3241
3244 static inline size_t transaction_size_max(intptr_t pagesize);
3245
3247 static inline size_t max_map_handles(void);
3248 };
3249
3251 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3253 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3255 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3257 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3259 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3261 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3265
3268#ifdef MDBX_STD_FILESYSTEM_PATH
3269 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3270#endif /* MDBX_STD_FILESYSTEM_PATH */
3271#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3272 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3273 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3274#endif /* Windows */
3275 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3276 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3277
3279 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3280
3296
3298#ifdef MDBX_STD_FILESYSTEM_PATH
3299 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3300#endif /* MDBX_STD_FILESYSTEM_PATH */
3301#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3302 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3303 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3304#endif /* Windows */
3305 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3306 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3307
3310
3313
3315 inline stat get_stat() const;
3316
3318 size_t get_pagesize() const { return get_stat().ms_psize; }
3319
3321 inline info get_info() const;
3322
3324 inline stat get_stat(const txn &) const;
3325
3327 inline info get_info(const txn &) const;
3328
3330 inline filehandle get_filehandle() const;
3331
3334
3336 inline MDBX_env_flags_t get_flags() const;
3337
3338 inline bool is_readonly() const { return (get_flags() & MDBX_RDONLY) != 0; }
3339
3340 inline bool is_exclusive() const { return (get_flags() & MDBX_EXCLUSIVE) != 0; }
3341
3342 inline bool is_cooperative() const { return !is_exclusive(); }
3343
3344 inline bool is_writemap() const { return (get_flags() & MDBX_WRITEMAP) != 0; }
3345
3346 inline bool is_readwite() const { return !is_readonly(); }
3347
3348 inline bool is_nested_transactions_available() const { return (get_flags() & (MDBX_WRITEMAP | MDBX_RDONLY)) == 0; }
3349
3352 inline unsigned max_readers() const;
3353
3356 inline unsigned max_maps() const;
3357
3359 inline void *get_context() const noexcept;
3360
3362 inline env &set_context(void *your_context);
3363
3378 inline env &set_sync_threshold(size_t bytes);
3379
3385 inline size_t sync_threshold() const;
3386
3387#if __cplusplus >= 201103L || defined(DOXYGEN)
3407 inline env &set_sync_period(const duration &period);
3408
3414 inline duration sync_period() const;
3415#endif
3416
3420 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3421
3424 inline unsigned sync_period__seconds_16dot16() const;
3425
3429 inline env &set_sync_period__seconds_double(double seconds);
3430
3433 inline double sync_period__seconds_double() const;
3434
3472
3474 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3475
3477 inline uint64_t extra_option(extra_runtime_option option) const;
3478
3480 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3481
3483 inline env &set_geometry(const geometry &size);
3484
3488 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3489
3493 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3494
3513 inline void close_map(const map_handle &);
3514
3517 int slot;
3526 size_t bytes_used;
3535
3537 size_t used, size_t retained) noexcept;
3538 };
3539
3547 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3548
3551 inline unsigned check_readers();
3552
3571
3576 inline MDBX_hsr_func *get_HandleSlowReaders() const noexcept;
3577
3579 inline txn_managed start_read() const;
3580
3582 inline txn_managed prepare_read() const;
3583
3585 inline txn_managed start_write(txn &parent);
3586
3588 inline txn_managed start_write(bool dont_wait = false);
3589
3592};
3593
3602class LIBMDBX_API_TYPE env_managed : public env {
3603 using inherited = env;
3605 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3606 void setup(unsigned max_maps, unsigned max_readers = 0);
3607
3608public:
3609 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3610
3612#ifdef MDBX_STD_FILESYSTEM_PATH
3613 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3614#endif /* MDBX_STD_FILESYSTEM_PATH */
3615#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3616 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3617 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3618#endif /* Windows */
3619 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3620 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3621
3632
3634#ifdef MDBX_STD_FILESYSTEM_PATH
3636 bool accede = true);
3637#endif /* MDBX_STD_FILESYSTEM_PATH */
3638#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3639 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3640 bool accede = true);
3641 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3642 bool accede = true);
3643#endif /* Windows */
3644 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3645 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3646
3660 void close(bool dont_sync = false);
3661
3662 env_managed(env_managed &&) = default;
3663 env_managed &operator=(env_managed &&other) noexcept {
3665 MDBX_CXX20_UNLIKELY {
3666 assert(handle_ != other.handle_);
3667 close();
3668 }
3669 inherited::operator=(std::move(other));
3670 return *this;
3671 }
3672 env_managed(const env_managed &) = delete;
3673 env_managed &operator=(const env_managed &) = delete;
3674 virtual ~env_managed() noexcept;
3675};
3676
3685protected:
3686 friend class cursor;
3688 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3689
3690public:
3691 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3692 txn(const txn &) noexcept = default;
3693 txn &operator=(const txn &) noexcept = default;
3694 inline txn &operator=(txn &&) noexcept;
3695 inline txn(txn &&) noexcept;
3696 inline ~txn() noexcept;
3697
3698 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3699 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3700 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3701 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3702 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3703
3705 inline ::mdbx::env env() const noexcept;
3707 inline MDBX_txn_flags_t flags() const;
3709 inline uint64_t id() const;
3710
3712 inline void *get_context() const noexcept;
3713
3715 inline txn &set_context(void *your_context);
3716
3718 inline bool is_dirty(const void *ptr) const;
3719
3721 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3722
3724 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3725
3727 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3728
3731 inline info get_info(bool scan_reader_lock_table = false) const;
3732
3735 size_t size_max() const { return env().transaction_size_max(); }
3736
3738 size_t size_current() const {
3739 assert(is_readwrite());
3740 return size_t(get_info().txn_space_dirty);
3741 }
3742
3743 //----------------------------------------------------------------------------
3744
3746 inline void reset_reading();
3747
3749 inline void renew_reading();
3750
3752 inline txn_managed clone(void *context = nullptr) const;
3753
3755 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
3756
3758 inline void make_broken();
3759
3761 inline void park_reading(bool autounpark = true);
3762
3765 inline bool unpark_reading(bool restart_if_ousted = true);
3766
3769
3772
3774 inline cursor_managed open_cursor(map_handle map) const;
3775
3777 inline size_t release_all_cursors(bool unbind) const;
3778
3780 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3781
3783 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3784
3786 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3787 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3789 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3790 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3792 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3793 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3794
3796 inline map_handle open_map_accede(const char *name) const;
3798 inline map_handle open_map_accede(const ::std::string &name) const;
3800 inline map_handle open_map_accede(const slice &name) const;
3801
3803 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3804 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3806 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3807 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3809 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3810 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3811
3813 inline void drop_map(map_handle map);
3817 bool drop_map(const char *name, bool throw_if_absent = false);
3821 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3825 bool drop_map(const slice &name, bool throw_if_absent = false);
3826
3828 inline void clear_map(map_handle map);
3831 bool clear_map(const char *name, bool throw_if_absent = false);
3834 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3837 bool clear_map(const slice &name, bool throw_if_absent = false);
3838
3840 inline void rename_map(map_handle map, const char *new_name);
3842 inline void rename_map(map_handle map, const ::std::string &new_name);
3844 inline void rename_map(map_handle map, const slice &new_name);
3848 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3852 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3856 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3857
3858#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3859
3861 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3862 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3863 return open_map(slice(name), key_mode, value_mode);
3864 }
3865
3866 inline map_handle open_map_accede(const ::std::string_view &name) const;
3868 inline map_handle create_map(const ::std::string_view &name,
3869 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3870 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3871 return create_map(slice(name), key_mode, value_mode);
3872 }
3873
3876 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3877 return drop_map(slice(name), throw_if_absent);
3878 }
3879
3881 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3882 return clear_map(slice(name), throw_if_absent);
3883 }
3884
3885 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3889 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3890 bool throw_if_absent = false) {
3891 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3892 }
3893#endif /* __cpp_lib_string_view >= 201606L */
3894
3897 inline map_stat get_map_stat(map_handle map) const;
3900 inline uint32_t get_tree_deepmask(map_handle map) const;
3902 inline map_handle::info get_map_flags(map_handle map) const;
3903
3906 inline txn &put_canary(const canary &);
3908 inline canary get_canary() const;
3909
3911 inline uint64_t sequence(map_handle map) const;
3913 inline uint64_t sequence(map_handle map, uint64_t increment);
3914
3916 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3918 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3920 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3922 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3923
3925 inline slice get(map_handle map, const slice &key) const;
3927 inline slice get(map_handle map, slice key, size_t &values_count) const;
3929 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3931 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3935 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3939 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3940
3941 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3942 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3943 inline void insert(map_handle map, const slice &key, slice value);
3944 inline value_result try_insert(map_handle map, const slice &key, slice value);
3945 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3946 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3947
3948 inline void upsert(map_handle map, const slice &key, const slice &value);
3949 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3950
3951 inline void update(map_handle map, const slice &key, const slice &value);
3952 inline bool try_update(map_handle map, const slice &key, const slice &value);
3953 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3954 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3955
3956 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3957 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3958 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3959 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3960
3962 inline bool erase(map_handle map, const slice &key);
3963
3965 inline bool erase(map_handle map, const slice &key, const slice &value);
3966
3968 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3969
3971 template <class ALLOCATOR, typename CAPACITY_POLICY>
3973 extract(map_handle map, const slice &key,
3976
3978 template <class ALLOCATOR, typename CAPACITY_POLICY>
3980 replace(map_handle map, const slice &key, const slice &new_value,
3983
3984 template <class ALLOCATOR, typename CAPACITY_POLICY>
3986 replace_reserve(map_handle map, const slice &key, slice &new_value,
3989
4006 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4007 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4008 return append(map, kv.key, kv.value, multivalue_order_preserved);
4009 }
4010
4011 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4012 const void *values_array, size_t values_count, put_mode mode,
4013 bool allow_partial = false);
4014 template <typename VALUE>
4015 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4016 put_mode mode, bool allow_partial = false) {
4017 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4018 !::std::is_array<VALUE>::value,
4019 "Must be a standard layout type!");
4020 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4021 }
4022 template <typename VALUE>
4023 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4024 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4025 }
4026
4027 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4028 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4029 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4030 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4031};
4032
4041class LIBMDBX_API_TYPE txn_managed : public txn {
4042 using inherited = txn;
4043 friend class env;
4044 friend class txn;
4046 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4047
4048public:
4049 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4050 txn_managed(txn_managed &&) = default;
4051 txn_managed &operator=(txn_managed &&other) noexcept {
4053 MDBX_CXX20_UNLIKELY {
4054 assert(handle_ != other.handle_);
4055 abort();
4056 }
4057 inherited::operator=(std::move(other));
4058 return *this;
4059 }
4060 txn_managed(const txn_managed &) = delete;
4061 txn_managed &operator=(const txn_managed &) = delete;
4062 ~txn_managed() noexcept;
4063
4064 //----------------------------------------------------------------------------
4066
4068 void abort();
4072 void abort(finalization_latency &latency) { return abort(&latency); }
4076 finalization_latency result;
4077 abort(&result);
4078 return result;
4079 }
4080
4082 void commit();
4086 void commit(finalization_latency &latency) { return commit(&latency); }
4090 finalization_latency result;
4091 commit(&result);
4092 return result;
4093 }
4094
4100 bool checkpoint(finalization_latency &latency) { return checkpoint(&latency); }
4103 std::pair<bool, finalization_latency> checkpoint_get_latency() {
4104 finalization_latency latency;
4105 bool result = checkpoint(&latency);
4106 return std::make_pair(result, latency);
4107 }
4108
4118 finalization_latency result;
4119 commit_embark_read(&result);
4120 return result;
4121 }
4122
4125 bool amend(bool dont_wait = false);
4126};
4127
4135protected:
4137
4138public:
4140 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4141 cursor(const cursor &) noexcept = default;
4142 cursor &operator=(const cursor &) noexcept = default;
4143 inline cursor &operator=(cursor &&) noexcept;
4144 inline cursor(cursor &&) noexcept;
4145 inline ~cursor() noexcept;
4146 inline cursor_managed clone(void *your_context = nullptr) const;
4147 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4148 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4149 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4150 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4151 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4152
4153 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4154 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4155
4156 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4157 return compare_position(*this, other, ignore_nested) < 0;
4158 }
4159
4160 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4161 return compare_position(*this, other, ignore_nested) <= 0;
4162 }
4163
4164 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4165 return compare_position(*this, other, ignore_nested) == 0;
4166 }
4167
4168 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4169 return compare_position(*this, other, ignore_nested) > 0;
4170 }
4171
4172 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4173 return compare_position(*this, other, ignore_nested) >= 0;
4174 }
4175
4177 inline void *get_context() const noexcept;
4178
4180 inline cursor &set_context(void *your_context);
4181
4188
4195
4198
4202
4203 /* Doubtless cursor positioning at a specified key. */
4209
4210 /* Doubtless cursor positioning at a specified key-value pair
4211 * for dupsort/multi-value hives. */
4217
4224
4229 };
4230
4231 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4232 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4233 // и других параметров в bool-throw_notfound.
4234
4235 struct move_result : public pair_result {
4236 inline move_result(const cursor &cursor, bool throw_notfound);
4237 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4238 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4239 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4240 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4241 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4242 bool throw_notfound);
4243 move_result(const move_result &) noexcept = default;
4244 move_result &operator=(const move_result &) noexcept = default;
4245 };
4246
4247 struct estimate_result : public pair {
4252 : estimate_result(cursor, operation, key, slice::invalid()) {}
4253 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4254 estimate_result(const estimate_result &) noexcept = default;
4255 estimate_result &operator=(const estimate_result &) noexcept = default;
4256 };
4257
4258protected:
4259 /* fake `const`, but for specific move/get operations */
4260 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4261
4262 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4263
4264public:
4265 template <typename CALLABLE_PREDICATE>
4266 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4267 struct wrapper : public exception_thunk {
4268 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4269 auto thunk = static_cast<wrapper *>(context);
4270 assert(thunk->is_clean());
4271 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4272 try {
4273 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4274 } catch (... /* capture any exception to rethrow it over C code */) {
4275 thunk->capture();
4276 return MDBX_RESULT_TRUE;
4277 }
4278 }
4279 } thunk;
4281 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4282 thunk);
4283 }
4284
4285 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4286 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4287 }
4288
4289 template <typename CALLABLE_PREDICATE>
4290 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4291 move_operation turn = next) {
4292 struct wrapper : public exception_thunk {
4293 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4294 auto thunk = static_cast<wrapper *>(context);
4295 assert(thunk->is_clean());
4296 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4297 try {
4298 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4299 } catch (... /* capture any exception to rethrow it over C code */) {
4300 thunk->capture();
4301 return MDBX_RESULT_TRUE;
4302 }
4303 }
4304 } thunk;
4305 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4306 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4307 thunk);
4308 }
4309
4310 template <typename CALLABLE_PREDICATE>
4311 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4312 move_operation turn = next) {
4313 struct wrapper : public exception_thunk {
4314 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4315 auto thunk = static_cast<wrapper *>(context);
4316 assert(thunk->is_clean());
4317 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4318 try {
4319 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4320 } catch (... /* capture any exception to rethrow it over C code */) {
4321 thunk->capture();
4322 return MDBX_RESULT_TRUE;
4323 }
4324 }
4325 } thunk;
4326 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4327 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4328 thunk);
4329 }
4330
4331 move_result move(move_operation operation, bool throw_notfound) {
4332 return move_result(*this, operation, throw_notfound);
4333 }
4334 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4335 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4336 }
4337 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4338 return move_result(*this, operation, key, value, throw_notfound);
4339 }
4340 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4341 return move(operation, &key, &value, throw_notfound);
4342 }
4343
4344 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4345 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4346 move_result to_previous_last_multi(bool throw_notfound = true) {
4347 return move(multi_prevkey_lastvalue, throw_notfound);
4348 }
4349 move_result to_current_first_multi(bool throw_notfound = true) {
4350 return move(multi_currentkey_firstvalue, throw_notfound);
4351 }
4352 move_result to_current_prev_multi(bool throw_notfound = true) {
4353 return move(multi_currentkey_prevvalue, throw_notfound);
4354 }
4355 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4356 move_result to_current_next_multi(bool throw_notfound = true) {
4357 return move(multi_currentkey_nextvalue, throw_notfound);
4358 }
4359 move_result to_current_last_multi(bool throw_notfound = true) {
4360 return move(multi_currentkey_lastvalue, throw_notfound);
4361 }
4362 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4363 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4364 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4365
4366 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4367 return move(key_lesser_than, key, throw_notfound);
4368 }
4369 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4370 return move(key_lesser_or_equal, key, throw_notfound);
4371 }
4372 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4373 return move(key_equal, key, throw_notfound);
4374 }
4375 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4376 return move(key_exact, key, throw_notfound);
4377 }
4378 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4379 return move(key_greater_or_equal, key, throw_notfound);
4380 }
4381 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4382 return move(key_greater_than, key, throw_notfound);
4383 }
4384
4385 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4386 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4387 }
4388 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4389 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4390 }
4391 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4392 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4393 }
4394 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4395 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4396 }
4397 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4398 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4399 }
4400
4401 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4402 return move(pair_lesser_than, key, value, throw_notfound);
4403 }
4404 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4405 return move(pair_lesser_or_equal, key, value, throw_notfound);
4406 }
4407 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4408 return move(pair_equal, key, value, throw_notfound);
4409 }
4410 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4411 return move(pair_exact, key, value, throw_notfound);
4412 }
4413 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4414 return move(pair_greater_or_equal, key, value, throw_notfound);
4415 }
4416 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4417 return move(pair_greater_than, key, value, throw_notfound);
4418 }
4419
4420 inline bool seek(const slice &key);
4421 inline move_result find(const slice &key, bool throw_notfound = true);
4422 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4423 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4424
4426 inline size_t count_multivalue() const;
4427
4428 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4429 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4430 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4431
4432 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4433 return move(seek_and_batch_samelength, key, throw_notfound);
4434 }
4435
4436 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4437 return move(batch_samelength, throw_notfound);
4438 }
4439
4440 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4441 return move(batch_samelength_next, throw_notfound);
4442 }
4443
4444 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4445 return move(batch_samelength_previous, throw_notfound);
4446 }
4447
4448 inline bool eof() const;
4449 inline bool on_first() const;
4450 inline bool on_last() const;
4451 inline bool on_first_multival() const;
4452 inline bool on_last_multival() const;
4453 inline estimate_result estimate(const slice &key, const slice &value) const;
4454 inline estimate_result estimate(const slice &key) const;
4455 inline estimate_result estimate(move_operation operation) const;
4456 inline estimate_result estimate(move_operation operation, slice &key) const;
4457
4458 //----------------------------------------------------------------------------
4459
4461 inline void renew(::mdbx::txn &txn);
4462
4465
4467 inline void unbind();
4468
4470 inline ::mdbx::txn txn() const;
4471 inline map_handle map() const;
4472
4473 inline operator ::mdbx::txn() const { return txn(); }
4474 inline operator ::mdbx::map_handle() const { return map(); }
4475
4476 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4477 inline void put(const slice &key, slice value, put_mode mode);
4478 inline void insert(const slice &key, slice value);
4479 inline value_result try_insert(const slice &key, slice value);
4480 inline slice insert_reserve(const slice &key, size_t value_length);
4481 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4482
4483 inline void upsert(const slice &key, const slice &value);
4484 inline slice upsert_reserve(const slice &key, size_t value_length);
4485
4487 void update_current(const slice &value);
4489 slice reverse_current(size_t value_length);
4490
4491 inline void update(const slice &key, const slice &value);
4492 inline bool try_update(const slice &key, const slice &value);
4493 inline slice update_reserve(const slice &key, size_t value_length);
4494 inline value_result try_update_reserve(const slice &key, size_t value_length);
4495
4496 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4497 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4498 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4499 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4500
4502 inline bool erase(bool whole_multivalue = false);
4503
4506 inline bool erase(const slice &key, bool whole_multivalue = true);
4507
4510 inline bool erase(const slice &key, const slice &value);
4511
4512 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4513 size_t values_count, put_mode mode, bool allow_partial = false);
4514 template <typename VALUE>
4515 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4516 bool allow_partial = false) {
4517 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4518 !::std::is_array<VALUE>::value,
4519 "Must be a standard layout type!");
4520 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4521 }
4522 template <typename VALUE>
4523 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4524 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4525 }
4526};
4527
4535class LIBMDBX_API_TYPE cursor_managed : public cursor {
4536 using inherited = cursor;
4537 friend class txn;
4539 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4540
4541public:
4543 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4544 if (MDBX_UNLIKELY(!handle_))
4545 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4546 }
4547
4549 inline void close() {
4551 handle_ = nullptr;
4552 }
4553
4554 cursor_managed(cursor_managed &&) = default;
4555 cursor_managed &operator=(cursor_managed &&other) noexcept {
4557 MDBX_CXX20_UNLIKELY {
4558 assert(handle_ != other.handle_);
4559 close();
4560 }
4561 inherited::operator=(std::move(other));
4562 return *this;
4563 }
4564
4565 inline MDBX_cursor *withdraw_handle() noexcept {
4566 MDBX_cursor *handle = handle_;
4567 handle_ = nullptr;
4568 return handle;
4569 }
4570
4571 cursor_managed(const cursor_managed &) = delete;
4572 cursor_managed &operator=(const cursor_managed &) = delete;
4574};
4575
4576//==============================================================================
4577//
4578// Inline body of the libmdbx C++ API
4579//
4580
4581MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4582MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4583
4584static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4585#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4586 if (::std::is_constant_evaluated()) {
4587 for (size_t i = 0; c_str; ++i)
4588 if (!c_str[i])
4589 return i;
4590 return 0;
4591 }
4592#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4593#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4594 return c_str ? ::std::string_view(c_str).length() : 0;
4595#else
4596 return c_str ? ::std::strlen(c_str) : 0;
4597#endif
4598}
4599
4600MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4601#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4602 if (::std::is_constant_evaluated()) {
4603 for (size_t i = 0; i < bytes; ++i)
4604 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4605 return dest;
4606 } else
4607#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4608 return ::std::memcpy(dest, src, bytes);
4609}
4610
4611static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4612#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4613 if (::std::is_constant_evaluated()) {
4614 for (size_t i = 0; i < bytes; ++i) {
4615 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4616 if (diff)
4617 return diff;
4618 }
4619 return 0;
4620 } else
4621#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4622 return ::std::memcmp(a, b, bytes);
4623}
4624
4625//------------------------------------------------------------------------------
4626
4629
4633
4637
4638inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4639
4640inline void exception_thunk::capture() noexcept {
4641 assert(is_clean());
4642 captured_ = ::std::current_exception();
4643}
4644
4646 if (captured_)
4647 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4648}
4649
4650//------------------------------------------------------------------------------
4651
4652MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4653
4654inline error &error::operator=(MDBX_error_t error_code) noexcept {
4655 code_ = error_code;
4656 return *this;
4657}
4658
4659MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4660
4661MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4662
4663MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4664
4665MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4666
4667MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4668
4670 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4671}
4672
4673MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4674
4679
4680inline void error::throw_exception(int error_code) {
4681 const error trouble(static_cast<MDBX_error_t>(error_code));
4682 trouble.throw_exception();
4683}
4684
4685inline void error::throw_on_failure() const {
4687 MDBX_CXX20_UNLIKELY throw_exception();
4688}
4689
4690inline void error::success_or_throw() const {
4691 if (MDBX_UNLIKELY(!is_success()))
4692 MDBX_CXX20_UNLIKELY throw_exception();
4693}
4694
4695inline void error::success_or_throw(const exception_thunk &thunk) const {
4696 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4697 if (MDBX_UNLIKELY(!is_success())) {
4698 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4699 else throw_exception();
4700 }
4701}
4702
4703inline void error::panic_on_failure(const char *context_where, const char *func_who) const noexcept {
4705 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4706}
4707
4708inline void error::success_or_panic(const char *context_where, const char *func_who) const noexcept {
4709 if (MDBX_UNLIKELY(!is_success()))
4710 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4711}
4712
4713inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4714 if (MDBX_UNLIKELY(ptr == nullptr))
4715 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4716}
4717
4718inline void error::throw_on_failure(int error_code) {
4719 error rc(static_cast<MDBX_error_t>(error_code));
4720 rc.throw_on_failure();
4721}
4722
4723inline void error::success_or_throw(MDBX_error_t error_code) {
4724 error rc(error_code);
4725 rc.success_or_throw();
4726}
4727
4728inline bool error::boolean_or_throw(int error_code) {
4729 switch (error_code) {
4730 case MDBX_RESULT_FALSE:
4731 return false;
4732 case MDBX_RESULT_TRUE:
4733 return true;
4734 default:
4735 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4736 }
4737}
4738
4739inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4740 error rc(static_cast<MDBX_error_t>(error_code));
4741 rc.success_or_throw(thunk);
4742}
4743
4744inline void error::panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept {
4745 error rc(static_cast<MDBX_error_t>(error_code));
4746 rc.panic_on_failure(context_where, func_who);
4747}
4748
4749inline void error::success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept {
4750 error rc(static_cast<MDBX_error_t>(error_code));
4751 rc.success_or_panic(context_where, func_who);
4752}
4753
4754inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4755 if (MDBX_UNLIKELY(!thunk.is_clean()))
4756 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4757 return boolean_or_throw(error_code);
4758}
4759
4760MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4761
4763 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4764
4765MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4766 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4767
4768MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4769
4770MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4771
4772MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4773
4774MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4775
4776inline slice &slice::assign(const void *ptr, size_t bytes) {
4777 iov_base = const_cast<void *>(ptr);
4778 iov_len = check_length(bytes);
4779 return *this;
4780}
4781
4782inline slice &slice::assign(const slice &src) noexcept {
4783 iov_base = src.iov_base;
4784 iov_len = src.iov_len;
4785 return *this;
4786}
4787
4788inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4789
4790slice &slice::assign(slice &&src) noexcept {
4791 assign(src);
4792 src.invalidate();
4793 return *this;
4794}
4795
4797 assign(src.iov_base, src.iov_len);
4798 src.iov_base = nullptr;
4799 return *this;
4800}
4801
4802inline slice &slice::assign(const void *begin, const void *end) {
4803 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4804}
4805
4806inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4807
4808inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4809
4810inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4811
4812MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4813
4814MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4815
4816MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4817
4819
4820MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4821
4822MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4823
4824MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4825
4827
4828MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4829
4830MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4831
4832MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4833
4834MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4835
4836MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4837
4839 iov_len = check_length(bytes);
4840 return *this;
4841}
4842
4844 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4845 return set_length(static_cast<const char *>(ptr) - char_ptr());
4846}
4847
4848MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4849
4850MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4851
4852MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4853
4854MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4855
4856MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4857
4859 iov_base = nullptr;
4860 iov_len = 0;
4861}
4862
4863inline void slice::remove_prefix(size_t n) noexcept {
4864 assert(n <= size());
4865 iov_base = static_cast<byte *>(iov_base) + n;
4866 iov_len -= n;
4867}
4868
4869inline void slice::safe_remove_prefix(size_t n) {
4870 if (MDBX_UNLIKELY(n > size()))
4871 MDBX_CXX20_UNLIKELY throw_out_range();
4872 remove_prefix(n);
4873}
4874
4875inline void slice::remove_suffix(size_t n) noexcept {
4876 assert(n <= size());
4877 iov_len -= n;
4878}
4879
4880inline void slice::safe_remove_suffix(size_t n) {
4881 if (MDBX_UNLIKELY(n > size()))
4882 MDBX_CXX20_UNLIKELY throw_out_range();
4883 remove_suffix(n);
4884}
4885
4886MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4887 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4888}
4889
4890MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4891 return length() >= suffix.length() &&
4892 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4893}
4894
4896 size_t h = length() * 3977471;
4897 for (size_t i = 0; i < length(); ++i)
4898 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4899 return h ^ 3863194411 * (h >> 11);
4900}
4901
4902MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4904 return byte_ptr()[n];
4905}
4906
4907MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4908 if (MDBX_UNLIKELY(n >= size()))
4909 MDBX_CXX20_UNLIKELY throw_out_range();
4910 return byte_ptr()[n];
4911}
4912
4913MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4915 return slice(data(), n);
4916}
4917
4918MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4920 return slice(char_ptr() + size() - n, n);
4921}
4922
4923MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4924 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4925 return slice(char_ptr() + from, n);
4926}
4927
4929 if (MDBX_UNLIKELY(n > size()))
4930 MDBX_CXX20_UNLIKELY throw_out_range();
4931 return head(n);
4932}
4933
4935 if (MDBX_UNLIKELY(n > size()))
4936 MDBX_CXX20_UNLIKELY throw_out_range();
4937 return tail(n);
4938}
4939
4940MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4941 if (MDBX_UNLIKELY(n > max_length))
4942 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4943 if (MDBX_UNLIKELY(from + n > size()))
4944 MDBX_CXX20_UNLIKELY throw_out_range();
4945 return middle(from, n);
4946}
4947
4948MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4949 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4950 return diff ? diff
4951 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4952 : memcmp(a.data(), b.data(), a.length());
4953}
4954
4956 const size_t shortest = ::std::min(a.length(), b.length());
4957 if (MDBX_LIKELY(shortest > 0))
4959 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4960 if (MDBX_LIKELY(diff != 0))
4961 MDBX_CXX20_LIKELY return diff;
4962 }
4963 return intptr_t(a.length()) - intptr_t(b.length());
4964}
4965
4967 return slice::compare_fast(a, b) == 0;
4968}
4969
4971 return slice::compare_lexicographically(a, b) < 0;
4972}
4973
4975 return slice::compare_lexicographically(a, b) > 0;
4976}
4977
4979 return slice::compare_lexicographically(a, b) <= 0;
4980}
4981
4983 return slice::compare_lexicographically(a, b) >= 0;
4984}
4985
4987 return slice::compare_fast(a, b) != 0;
4988}
4989
4990#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
4991MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
4993}
4994#endif /* __cpp_impl_three_way_comparison */
4995
4996template <class ALLOCATOR, typename CAPACITY_POLICY>
4998 const allocator_type &alloc)
4999 : inherited(src), silo_(alloc) {
5000 if (!make_reference)
5001 insulate();
5002}
5003
5004template <class ALLOCATOR, typename CAPACITY_POLICY>
5005inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
5006 const allocator_type &alloc)
5007 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
5008
5009template <class ALLOCATOR, typename CAPACITY_POLICY>
5010inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
5011 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
5012}
5013
5014#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
5016
5017#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
5019#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
5020#endif /* !MinGW || MDBX_EXPORTS */
5021
5024
5025//------------------------------------------------------------------------------
5026
5027template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5028inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
5029 if (MDBX_LIKELY(!producer.is_empty()))
5031 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5032 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5033 return result;
5034 }
5036}
5037
5038template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5039inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
5040 if (MDBX_LIKELY(!producer.is_empty()))
5042 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5043 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5044 return result;
5045 }
5047}
5048
5049template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5050inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
5051 string<ALLOCATOR> result(alloc);
5052 if (MDBX_LIKELY(!producer.is_empty()))
5054 result.resize(producer.envisage_result_length());
5055 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5056 }
5057 return result;
5058}
5059
5060template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5061inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
5062 string<ALLOCATOR> result(alloc);
5063 if (MDBX_LIKELY(!producer.is_empty()))
5065 result.resize(producer.envisage_result_length());
5066 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5067 }
5068 return result;
5069}
5070
5071template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
5072 return make_string<ALLOCATOR>(*this, alloc);
5073}
5074
5075template <class ALLOCATOR, typename CAPACITY_POLICY>
5077 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5078}
5079
5080template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
5081 return make_string<ALLOCATOR>(*this, alloc);
5082}
5083
5084template <class ALLOCATOR, typename CAPACITY_POLICY>
5086 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5087}
5088
5089template <class ALLOCATOR> string<ALLOCATOR> to_base64::as_string(const ALLOCATOR &alloc) const {
5090 return make_string<ALLOCATOR>(*this, alloc);
5091}
5092
5093template <class ALLOCATOR, typename CAPACITY_POLICY>
5095 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5096}
5097
5098template <class ALLOCATOR> string<ALLOCATOR> from_hex::as_string(const ALLOCATOR &alloc) const {
5099 return make_string<ALLOCATOR>(*this, alloc);
5100}
5101
5102template <class ALLOCATOR, typename CAPACITY_POLICY>
5104 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5105}
5106
5107template <class ALLOCATOR> string<ALLOCATOR> from_base58::as_string(const ALLOCATOR &alloc) const {
5108 return make_string<ALLOCATOR>(*this, alloc);
5109}
5110
5111template <class ALLOCATOR, typename CAPACITY_POLICY>
5113 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5114}
5115
5116template <class ALLOCATOR> string<ALLOCATOR> from_base64::as_string(const ALLOCATOR &alloc) const {
5117 return make_string<ALLOCATOR>(*this, alloc);
5118}
5119
5120template <class ALLOCATOR, typename CAPACITY_POLICY>
5122 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5123}
5124
5125template <class ALLOCATOR>
5126inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
5127 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
5128}
5129
5130template <class ALLOCATOR>
5131inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5132 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5133}
5134
5135template <class ALLOCATOR>
5136inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5137 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5138}
5139
5140template <class ALLOCATOR, class CAPACITY_POLICY>
5141inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5142 const ALLOCATOR &alloc) const {
5143 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5144}
5145
5146template <class ALLOCATOR, class CAPACITY_POLICY>
5147inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
5148 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5149}
5150
5151template <class ALLOCATOR, class CAPACITY_POLICY>
5152inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
5153 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5154}
5155
5156template <class ALLOCATOR, class CAPACITY_POLICY>
5157inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5158 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5159}
5160
5161template <class ALLOCATOR, class CAPACITY_POLICY>
5162inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5163 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5164}
5165
5166template <class ALLOCATOR, class CAPACITY_POLICY>
5167inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5168 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5169}
5170
5171//------------------------------------------------------------------------------
5172
5173MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5174 const auto diff = slice::compare_fast(a.key, b.key);
5175 return diff ? diff : slice::compare_fast(a.value, b.value);
5176}
5177
5178MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5179 const auto diff = slice::compare_lexicographically(a.key, b.key);
5180 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
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
5190 return pair::compare_lexicographically(a, b) < 0;
5191}
5192
5194 return pair::compare_lexicographically(a, b) > 0;
5195}
5196
5198 return pair::compare_lexicographically(a, b) <= 0;
5199}
5200
5202 return pair::compare_lexicographically(a, b) >= 0;
5203}
5204
5206 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5207 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5208 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5209}
5210
5211#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5212MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5214}
5215#endif /* __cpp_impl_three_way_comparison */
5216
5218template <typename BUFFER>
5220
5223
5224//------------------------------------------------------------------------------
5225
5226inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
5227inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
5228inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
5229
5230MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5231 return !from_hex(*this, ignore_spaces).is_erroneous();
5232}
5233
5234MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5235 return !from_base58(*this, ignore_spaces).is_erroneous();
5236}
5237
5238MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5239 return !from_base64(*this, ignore_spaces).is_erroneous();
5240}
5241
5242//------------------------------------------------------------------------------
5243
5245
5246inline env &env::operator=(env &&other) noexcept {
5247 handle_ = other.handle_;
5248 other.handle_ = nullptr;
5249 return *this;
5250}
5251
5252inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5253
5254inline env::~env() noexcept {
5255#ifndef NDEBUG
5256 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5257#endif
5258}
5259
5260MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5261
5262MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5263
5264MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5265
5266MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5267
5268MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5269
5273 return *this;
5274}
5275
5276inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5277 size_now = size_lower = lower;
5278 size_upper = upper;
5280 return *this;
5281}
5282
5286
5290
5291inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5292
5293inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5294
5295inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5296 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5297 if (result < 0)
5298 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5299 return static_cast<size_t>(result);
5300}
5301
5302inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5303 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5304 if (result < 0)
5305 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5306 return static_cast<size_t>(result);
5307}
5308
5309inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5310
5311inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5312
5313inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5314 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5315 if (result < 0)
5316 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5317 return static_cast<size_t>(result);
5318}
5319
5320inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5321 return key_max(pagesize, MDBX_db_flags_t(mode));
5322}
5323
5324inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
5325 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5326 if (result < 0)
5327 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5328 return static_cast<size_t>(result);
5329}
5330
5332
5333inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5334
5336
5337inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5338 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5339 if (result < 0)
5340 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5341 return static_cast<size_t>(result);
5342}
5343
5344inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5345 return value_max(pagesize, MDBX_db_flags_t(mode));
5346}
5347
5348inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
5349 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5350 if (result < 0)
5351 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5352 return static_cast<size_t>(result);
5353}
5354
5356
5357inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5358 const intptr_t result = mdbx_limits_pairsize4page_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::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5365 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5366}
5367
5369 const intptr_t result = mdbx_env_get_pairsize4page_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::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5380 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
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::valsize4page_max(intptr_t pagesize, value_mode mode) {
5387 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5388}
5389
5391 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5392 if (result < 0)
5393 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5394 return static_cast<size_t>(result);
5395}
5396
5400
5401inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5402 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5403 if (result < 0)
5404 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5405 return static_cast<size_t>(result);
5406}
5407
5408inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5409
5417
5419
5423
5427
5431
5432inline env::stat env::get_stat() const {
5433 env::stat r;
5434 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5435 return r;
5436}
5437
5438inline env::stat env::get_stat(const txn &txn) const {
5439 env::stat r;
5441 return r;
5442}
5443
5444inline env::info env::get_info() const {
5445 env::info r;
5446 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5447 return r;
5448}
5449
5450inline env::info env::get_info(const txn &txn) const {
5451 env::info r;
5453 return r;
5454}
5455
5457 filehandle fd;
5459 return fd;
5460}
5461
5463 unsigned bits = 0;
5465 return MDBX_env_flags_t(bits);
5466}
5467
5468inline unsigned env::max_readers() const {
5469 unsigned r;
5471 return r;
5472}
5473
5474inline unsigned env::max_maps() const {
5475 unsigned r;
5477 return r;
5478}
5479
5480inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5481
5482inline env &env::set_context(void *ptr) {
5484 return *this;
5485}
5486
5487inline env &env::set_sync_threshold(size_t bytes) {
5489 return *this;
5490}
5491
5492inline size_t env::sync_threshold() const {
5493 size_t bytes;
5495 return bytes;
5496}
5497
5498inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5500 return *this;
5501}
5502
5503inline unsigned env::sync_period__seconds_16dot16() const {
5504 unsigned seconds_16dot16;
5506 return seconds_16dot16;
5507}
5508
5510 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5511}
5512
5513inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5514
5515#if __cplusplus >= 201103L
5516inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5517
5519#endif
5520
5521inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5523 return *this;
5524}
5525
5526inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5527 uint64_t value;
5529 return value;
5530}
5531
5532inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
5534 return *this;
5535}
5536
5537inline env &env::set_geometry(const geometry &geo) {
5539 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5540 return *this;
5541}
5542
5543inline bool env::sync_to_disk(bool force, bool nonblock) {
5544 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5545 switch (err) {
5546 case MDBX_SUCCESS /* flush done */:
5547 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5548 return true;
5549 case MDBX_BUSY /* the environment is used by other thread */:
5550 return false;
5551 default:
5552 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5553 }
5554}
5555
5556inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5557
5559env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5560 size_t retained) noexcept
5562 bytes_retained(retained) {}
5563
5564template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5565 struct reader_visitor_thunk : public exception_thunk {
5566 VISITOR &visitor_;
5567 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5568 size_t used, size_t retained) noexcept {
5569 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5570 assert(thunk->is_clean());
5571 try {
5572 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5573 return loop_control(thunk->visitor_(info, number));
5574 } catch (... /* capture any exception to rethrow it over C code */) {
5575 thunk->capture();
5577 }
5578 }
5579 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5580 };
5581 reader_visitor_thunk thunk(visitor);
5582 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5583 thunk.rethrow_captured();
5584 return rc;
5585}
5586
5587inline unsigned env::check_readers() {
5588 int dead_count;
5589 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5590 assert(dead_count >= 0);
5591 return static_cast<unsigned>(dead_count);
5592}
5593
5598
5599inline MDBX_hsr_func *env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5600
5602 ::MDBX_txn *ptr;
5604 assert(ptr != nullptr);
5605 return txn_managed(ptr);
5606}
5607
5609 ::MDBX_txn *ptr;
5611 assert(ptr != nullptr);
5612 return txn_managed(ptr);
5613}
5614
5615inline txn_managed env::start_write(bool dont_wait) {
5616 ::MDBX_txn *ptr;
5619 assert(ptr != nullptr || dont_wait);
5620 return txn_managed(ptr);
5621}
5622
5624 ::MDBX_txn *ptr;
5626 assert(ptr != nullptr);
5627 return txn_managed(ptr);
5628}
5629
5631
5633
5634inline txn &txn::operator=(txn &&other) noexcept {
5635 handle_ = other.handle_;
5636 other.handle_ = nullptr;
5637 return *this;
5638}
5639
5640inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5641
5642inline txn::~txn() noexcept {
5643#ifndef NDEBUG
5644 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5645#endif
5646}
5647
5648MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5649
5650MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5651
5652MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5653
5654MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5655
5656MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5657
5658inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5659
5660inline txn &txn::set_context(void *ptr) {
5662 return *this;
5663}
5664
5665inline bool txn::is_dirty(const void *ptr) const {
5666 int err = ::mdbx_is_dirty(handle_, ptr);
5667 switch (err) {
5668 default:
5669 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5670 case MDBX_RESULT_TRUE:
5671 return true;
5672 case MDBX_RESULT_FALSE:
5673 return false;
5674 }
5675}
5676
5677inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5678
5680 const int bits = mdbx_txn_flags(handle_);
5682 return static_cast<MDBX_txn_flags_t>(bits);
5683}
5684
5685inline uint64_t txn::id() const {
5686 const uint64_t txnid = mdbx_txn_id(handle_);
5688 return txnid;
5689}
5690
5692
5694
5696
5697inline txn_managed txn::clone(void *context) const {
5698 MDBX_txn *ptr = nullptr;
5700 assert(ptr != nullptr);
5701 return txn_managed(ptr);
5702}
5703
5704inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
5705 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
5706 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
5707 assert(txn_for_renew_into_clone.handle_ != nullptr);
5708}
5709
5710inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5711
5712inline bool txn::unpark_reading(bool restart_if_ousted) {
5713 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5714}
5715
5716inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5717 txn::info r;
5718 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5719 return r;
5720}
5721
5723 MDBX_cursor *ptr;
5725 return cursor_managed(ptr);
5726}
5727
5728inline size_t txn::release_all_cursors(bool unbind) const {
5729 size_t count;
5731 return count;
5732}
5733
5734inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5735 const ::mdbx::value_mode value_mode) const {
5736 map_handle map;
5739 assert(map.dbi != 0);
5740 return map;
5741}
5742
5743inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5744 const ::mdbx::value_mode value_mode) const {
5745 map_handle map;
5748 assert(map.dbi != 0);
5749 return map;
5750}
5751
5752inline map_handle txn::open_map_accede(const slice &name) const {
5753 map_handle map;
5755 assert(map.dbi != 0);
5756 return map;
5757}
5758
5759inline map_handle txn::open_map_accede(const char *name) const {
5760 map_handle map;
5762 assert(map.dbi != 0);
5763 return map;
5764}
5765
5766inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5767 const ::mdbx::value_mode value_mode) {
5768 map_handle map;
5771 assert(map.dbi != 0);
5772 return map;
5773}
5774
5775inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5776 const ::mdbx::value_mode value_mode) {
5777 map_handle map;
5780 assert(map.dbi != 0);
5781 return map;
5782}
5783
5785
5787
5788inline void txn::rename_map(map_handle map, const char *new_name) {
5790}
5791
5792inline void txn::rename_map(map_handle map, const slice &new_name) {
5794}
5795
5796inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5797 const ::mdbx::value_mode value_mode) const {
5798 return open_map(slice(name), key_mode, value_mode);
5799}
5800
5801inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5802
5803inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5804 const ::mdbx::value_mode value_mode) {
5805 return create_map(slice(name), key_mode, value_mode);
5806}
5807
5808inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5809 return drop_map(slice(name), throw_if_absent);
5810}
5811
5812inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5813 return clear_map(slice(name), throw_if_absent);
5814}
5815
5816inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5817
5819 txn::map_stat r;
5820 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5821 return r;
5822}
5823
5824inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5825 uint32_t r;
5827 return r;
5828}
5829
5835
5840
5842 txn::canary r;
5844 return r;
5845}
5846
5847inline uint64_t txn::sequence(map_handle map) const {
5848 uint64_t result;
5850 return result;
5851}
5852
5853inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5854 uint64_t result;
5855 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5856 return result;
5857}
5858
5859inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5860 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5861}
5862
5863inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5864 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5865}
5866
5867inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5868 return compare_keys(map, a.key, b.key);
5869}
5870
5871inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5872 return compare_values(map, a.value, b.value);
5873}
5874
5875inline slice txn::get(map_handle map, const slice &key) const {
5876 slice result;
5877 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5878 return result;
5879}
5880
5881inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5882 slice result;
5883 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5884 return result;
5885}
5886
5887inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5888 slice result;
5889 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5890 switch (err) {
5891 case MDBX_SUCCESS:
5892 return result;
5893 case MDBX_NOTFOUND:
5894 return value_at_absence;
5895 default:
5896 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5897 }
5898}
5899
5900inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5901 slice result;
5902 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5903 switch (err) {
5904 case MDBX_SUCCESS:
5905 return result;
5906 case MDBX_NOTFOUND:
5907 return value_at_absence;
5908 default:
5909 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5910 }
5911}
5912
5914 pair result(key, slice());
5915 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5916 return pair_result(result.key, result.value, exact);
5917}
5918
5919inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5920 pair result{key, slice()};
5921 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5922 switch (err) {
5923 case MDBX_SUCCESS:
5924 return pair_result{result.key, result.value, true};
5925 case MDBX_RESULT_TRUE:
5926 return pair_result{result.key, result.value, false};
5927 case MDBX_NOTFOUND:
5928 return pair_result{key, value_at_absence, false};
5929 default:
5930 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5931 }
5932}
5933
5934inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5935 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5936}
5937
5938inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5939 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5940}
5941
5942inline void txn::insert(map_handle map, const slice &key, slice value) {
5943 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5945}
5946
5947inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5948 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5950 switch (err) {
5951 case MDBX_SUCCESS:
5952 return value_result{slice(), true};
5953 case MDBX_KEYEXIST:
5954 return value_result{value, false};
5955 default:
5956 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5957 }
5958}
5959
5960inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5961 slice result(nullptr, value_length);
5962 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5964 return result;
5965}
5966
5967inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5968 slice result(nullptr, value_length);
5969 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5971 switch (err) {
5972 case MDBX_SUCCESS:
5973 return value_result{result, true};
5974 case MDBX_KEYEXIST:
5975 return value_result{result, false};
5976 default:
5977 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5978 }
5979}
5980
5981inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5982 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5983}
5984
5985inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
5986 slice result(nullptr, value_length);
5988 return result;
5989}
5990
5991inline void txn::update(map_handle map, const slice &key, const slice &value) {
5992 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
5993}
5994
5995inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
5996 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
5997 switch (err) {
5998 case MDBX_SUCCESS:
5999 return true;
6000 case MDBX_NOTFOUND:
6001 return false;
6002 default:
6003 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6004 }
6005}
6006
6007inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
6008 slice result(nullptr, value_length);
6010 return result;
6011}
6012
6013inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
6014 slice result(nullptr, value_length);
6015 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6016 switch (err) {
6017 case MDBX_SUCCESS:
6018 return value_result{result, true};
6019 case MDBX_NOTFOUND:
6020 return value_result{slice(), false};
6021 default:
6022 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6023 }
6024}
6025
6026inline bool txn::erase(map_handle map, const slice &key) {
6027 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6028 switch (err) {
6029 case MDBX_SUCCESS:
6030 return true;
6031 case MDBX_NOTFOUND:
6032 return false;
6033 default:
6034 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6035 }
6036}
6037
6038inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6039 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
6040 switch (err) {
6041 case MDBX_SUCCESS:
6042 return true;
6043 case MDBX_NOTFOUND:
6044 return false;
6045 default:
6046 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6047 }
6048}
6049
6050inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
6051 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6052 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6053}
6054
6055template <class ALLOCATOR, typename CAPACITY_POLICY>
6059 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6061 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
6062 return result;
6063}
6064
6065template <class ALLOCATOR, typename CAPACITY_POLICY>
6067txn::replace(map_handle map, const slice &key, const slice &new_value,
6069 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6070 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
6071 MDBX_CURRENT, result, &result),
6072 result);
6073 return result;
6074}
6075
6076template <class ALLOCATOR, typename CAPACITY_POLICY>
6078txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
6080 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6081 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6082 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6083 result);
6084 return result;
6085}
6086
6087inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
6088 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6089 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
6090}
6091
6092inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
6093 const void *values_array, size_t values_count, put_mode mode,
6094 bool allow_partial) {
6095 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6096 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6097 switch (err) {
6098 case MDBX_SUCCESS:
6099 MDBX_CXX20_LIKELY break;
6100 case MDBX_KEYEXIST:
6101 if (allow_partial)
6102 break;
6104 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6105 default:
6106 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6107 }
6108 return args[1].iov_len /* done item count */;
6109}
6110
6111inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
6112 ptrdiff_t result;
6113 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6114 return result;
6115}
6116
6117inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6118 ptrdiff_t result;
6119 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6120 return result;
6121}
6122
6123inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6124 ptrdiff_t result;
6125 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6126 return result;
6127}
6128
6129inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6130 ptrdiff_t result;
6131 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6132 return result;
6133}
6134
6136
6137inline cursor_managed cursor::clone(void *your_context) const {
6138 cursor_managed clone(your_context);
6140 return clone;
6141}
6142
6143inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6144
6145inline cursor &cursor::set_context(void *ptr) {
6147 return *this;
6148}
6149
6150inline cursor &cursor::operator=(cursor &&other) noexcept {
6151 handle_ = other.handle_;
6152 other.handle_ = nullptr;
6153 return *this;
6154}
6155
6156inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6157
6158inline cursor::~cursor() noexcept {
6159#ifndef NDEBUG
6160 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6161#endif
6162}
6163
6164MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
6165
6166MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
6167
6168MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6169
6170MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6171
6172MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6173
6174inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6175 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6176}
6177
6178inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6179 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6180 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6181 if (MDBX_LIKELY(int16_t(diff) == diff))
6182 MDBX_CXX20_LIKELY return int(diff);
6183 else
6185}
6186
6187inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6188 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6189}
6190
6192 bool throw_notfound)
6193 : pair_result(key, value, false) {
6194 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6195}
6196
6197inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6198 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6199 switch (err) {
6200 case MDBX_SUCCESS:
6201 MDBX_CXX20_LIKELY return true;
6202 case MDBX_RESULT_TRUE:
6203 return false;
6204 case MDBX_NOTFOUND:
6205 if (!throw_notfound)
6206 return false;
6207 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6208 default:
6209 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6210 }
6211}
6212
6214 const slice &value)
6215 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6216 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6217}
6218
6219inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6220 ptrdiff_t result;
6221 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6222 return result;
6223}
6224
6225inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6226 ptrdiff_t result;
6228 return result;
6229}
6230
6231inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6232 return move(key_exact, key, throw_notfound);
6233}
6234
6235inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6236 return move(key_lowerbound, key, throw_notfound);
6237}
6238
6239inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6240 return move(key_greater_than, key, throw_notfound);
6241}
6242
6243inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6244 return move(multi_find_pair, key, value, throw_notfound);
6245}
6246
6247inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6248 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6249}
6250
6251inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6252 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6253}
6254
6255inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6256
6257inline size_t cursor::count_multivalue() const {
6258 size_t result;
6260 return result;
6261}
6262
6263inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6264
6266
6268
6270
6272
6273inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6274 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6275}
6276
6278 return estimate_result(*this, key_lowerbound, key);
6279}
6280
6282 return estimate_result(*this, operation);
6283}
6284
6286
6290
6292
6293inline txn cursor::txn() const {
6295 return ::mdbx::txn(txn);
6296}
6297
6298inline map_handle cursor::map() const {
6299 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6300 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6302 return map_handle(dbi);
6303}
6304
6305inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6306 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6307}
6308
6309inline void cursor::put(const slice &key, slice value, put_mode mode) {
6310 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6311}
6312
6313inline void cursor::insert(const slice &key, slice value) {
6315 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6316}
6317
6318inline value_result cursor::try_insert(const slice &key, slice value) {
6319 const int err =
6320 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6321 switch (err) {
6322 case MDBX_SUCCESS:
6323 return value_result{slice(), true};
6324 case MDBX_KEYEXIST:
6325 return value_result{value, false};
6326 default:
6327 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6328 }
6329}
6330
6331inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6332 slice result(nullptr, value_length);
6333 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6335 return result;
6336}
6337
6338inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6339 slice result(nullptr, value_length);
6340 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6342 switch (err) {
6343 case MDBX_SUCCESS:
6344 return value_result{result, true};
6345 case MDBX_KEYEXIST:
6346 return value_result{result, false};
6347 default:
6348 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6349 }
6350}
6351
6352inline void cursor::upsert(const slice &key, const slice &value) {
6353 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6354}
6355
6356inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6357 slice result(nullptr, value_length);
6359 return result;
6360}
6361
6362inline void cursor::update(const slice &key, const slice &value) {
6363 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6364}
6365
6366inline bool cursor::try_update(const slice &key, const slice &value) {
6367 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6368 switch (err) {
6369 case MDBX_SUCCESS:
6370 return true;
6371 case MDBX_NOTFOUND:
6372 return false;
6373 default:
6374 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6375 }
6376}
6377
6378inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6379 slice result(nullptr, value_length);
6381 return result;
6382}
6383
6384inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6385 slice result(nullptr, value_length);
6386 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6387 switch (err) {
6388 case MDBX_SUCCESS:
6389 return value_result{result, true};
6390 case MDBX_NOTFOUND:
6391 return value_result{slice(), false};
6392 default:
6393 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6394 }
6395}
6396
6397inline bool cursor::erase(bool whole_multivalue) {
6398 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6399 switch (err) {
6400 case MDBX_SUCCESS:
6401 MDBX_CXX20_LIKELY return true;
6402 case MDBX_NOTFOUND:
6403 return false;
6404 default:
6405 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6406 }
6407}
6408
6409inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6410 bool found = seek(key);
6411 return found ? erase(whole_multivalue) : found;
6412}
6413
6414inline bool cursor::erase(const slice &key, const slice &value) {
6415 move_result data = find_multivalue(key, value, false);
6416 return data.done && erase();
6417}
6418
6419inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6420 size_t values_count, put_mode mode, bool allow_partial) {
6421 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6422 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6423 switch (err) {
6424 case MDBX_SUCCESS:
6425 MDBX_CXX20_LIKELY break;
6426 case MDBX_KEYEXIST:
6427 if (allow_partial)
6428 break;
6430 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6431 default:
6432 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6433 }
6434 return args[1].iov_len /* done item count */;
6435}
6436
6437//------------------------------------------------------------------------------
6438
6439LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
6440LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
6441LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
6442LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
6443LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
6444LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
6445LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
6446LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
6447LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
6448LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
6449LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
6450
6451LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
6452LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
6453LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
6454
6455inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
6456
6458
6459} // namespace mdbx
6460
6461//------------------------------------------------------------------------------
6462
6465namespace std {
6466
6467inline string to_string(const ::mdbx::slice &value) {
6468 ostringstream out;
6469 out << value;
6470 return out.str();
6471}
6472
6473template <class ALLOCATOR, typename CAPACITY_POLICY>
6474inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6475 ostringstream out;
6476 out << buffer;
6477 return out.str();
6478}
6479
6480inline string to_string(const ::mdbx::pair &value) {
6481 ostringstream out;
6482 out << value;
6483 return out.str();
6484}
6485
6486inline string to_string(const ::mdbx::env::geometry &value) {
6487 ostringstream out;
6488 out << value;
6489 return out.str();
6490}
6491
6492inline string to_string(const ::mdbx::env::operate_parameters &value) {
6493 ostringstream out;
6494 out << value;
6495 return out.str();
6496}
6497
6498inline string to_string(const ::mdbx::env::mode &value) {
6499 ostringstream out;
6500 out << value;
6501 return out.str();
6502}
6503
6504inline string to_string(const ::mdbx::env::durability &value) {
6505 ostringstream out;
6506 out << value;
6507 return out.str();
6508}
6509
6510inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6511 ostringstream out;
6512 out << value;
6513 return out.str();
6514}
6515
6516inline string to_string(const ::mdbx::env::operate_options &value) {
6517 ostringstream out;
6518 out << value;
6519 return out.str();
6520}
6521
6522inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6523 ostringstream out;
6524 out << value;
6525 return out.str();
6526}
6527
6528inline string to_string(const ::MDBX_log_level_t &value) {
6529 ostringstream out;
6530 out << value;
6531 return out.str();
6532}
6533
6534inline string to_string(const ::MDBX_debug_flags_t &value) {
6535 ostringstream out;
6536 out << value;
6537 return out.str();
6538}
6539
6540inline string to_string(const ::mdbx::error &value) {
6541 ostringstream out;
6542 out << value;
6543 return out.str();
6544}
6545
6546inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6547
6548template <> struct hash<::mdbx::slice> {
6549 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6550};
6551
6552template <> struct hash<::mdbx::map_handle> {
6553 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6554};
6555
6556template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6557 using inherited = std::hash<const MDBX_env *>;
6558 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6559};
6560
6561template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6562 using inherited = std::hash<const MDBX_txn *>;
6563 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6564};
6565
6566template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6567 using inherited = std::hash<const MDBX_cursor *>;
6568 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6569};
6570
6571template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6572 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6573 return buffer.hash_value();
6574 }
6575};
6576
6577} // namespace std
6578
6579#if defined(__LCC__) && __LCC__ >= 126
6580#pragma diagnostic pop
6581#endif
6582
6583#ifdef _MSC_VER
6584#pragma warning(pop)
6585#endif
Definition mdbx.h++:1155
Definition mdbx.h++:1145
Definition mdbx.h++:1165
#define MDBX_CXX11_CONSTEXPR
Definition mdbx.h:458
#define MDBX_MAYBE_UNUSED
Definition mdbx.h:524
#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:606
#define LIBMDBX_API_TYPE
Definition mdbx.h:621
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the table. .
Definition mdbx.h:780
pthread_t mdbx_tid_t
Definition mdbx.h:186
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition mdbx.h:713
int mdbx_filehandle_t
Definition mdbx.h:184
pid_t mdbx_pid_t
Definition mdbx.h:185
@ MDBX_MAX_PAGESIZE
Definition mdbx.h:794
@ MDBX_MAXDATASIZE
Definition mdbx.h:788
@ MDBX_MAX_DBI
Definition mdbx.h:785
@ MDBX_MIN_PAGESIZE
Definition mdbx.h:791
libmdbx build information
Definition mdbx.h:649
Lightweight transparent cache entry structure used by mdbx_cache_get().
Definition mdbx.h:5166
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4659
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4098
Information about the environment.
Definition mdbx.h:2792
Statistics for a table in the environment.
Definition mdbx.h:2746
Information about the transaction.
Definition mdbx.h:4000
libmdbx version information,
Definition mdbx.h:631
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:5459
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_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_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_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:1629
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.
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)
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5180
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:4719
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_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:1666
@ MDBX_ALLDUPS
Definition mdbx.h:1649
@ MDBX_CURRENT
Definition mdbx.h:1644
@ MDBX_APPENDDUP
Definition mdbx.h:1662
@ MDBX_APPEND
Definition mdbx.h:1657
@ MDBX_UPSERT
Definition mdbx.h:1631
@ MDBX_RESERVE
Definition mdbx.h:1653
@ MDBX_NOOVERWRITE
Definition mdbx.h:1634
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:1710
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:743
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:1829
@ MDBX_GET_CURRENT
Definition mdbx.h:1725
@ MDBX_GET_BOTH
Definition mdbx.h:1718
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1806
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1722
@ MDBX_SET_KEY
Definition mdbx.h:1765
@ MDBX_FIRST_DUP
Definition mdbx.h:1715
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1805
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1730
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1816
@ MDBX_NEXT_NODUP
Definition mdbx.h:1750
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1813
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1814
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1821
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1773
@ MDBX_SET_RANGE
Definition mdbx.h:1768
@ MDBX_LAST_DUP
Definition mdbx.h:1736
@ MDBX_PREV
Definition mdbx.h:1753
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1823
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1824
@ MDBX_LAST
Definition mdbx.h:1733
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1804
@ MDBX_PREV_DUP
Definition mdbx.h:1756
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1812
@ MDBX_SET
Definition mdbx.h:1762
@ MDBX_NEXT
Definition mdbx.h:1739
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1807
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1820
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1747
@ MDBX_PREV_NODUP
Definition mdbx.h:1759
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1822
@ MDBX_NEXT_DUP
Definition mdbx.h:1742
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1815
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1808
@ MDBX_FIRST
Definition mdbx.h:1712
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:736
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1579
@ MDBX_INTEGERDUP
Definition mdbx.h:1603
@ MDBX_DB_ACCEDE
Definition mdbx.h:1621
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1581
@ MDBX_REVERSEKEY
Definition mdbx.h:1584
@ MDBX_DUPFIXED
Definition mdbx.h:1598
@ MDBX_INTEGERKEY
Definition mdbx.h:1594
@ MDBX_REVERSEDUP
Definition mdbx.h:1606
@ MDBX_CREATE
Definition mdbx.h:1609
@ MDBX_DUPSORT
Definition mdbx.h:1587
MDBX_log_level_t
Definition mdbx.h:856
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:915
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:6750
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1837
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1851
@ MDBX_BAD_TXN
Definition mdbx.h:1916
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1930
@ MDBX_SUCCESS
Definition mdbx.h:1839
@ MDBX_NOTFOUND
Definition mdbx.h:1854
@ MDBX_RESULT_TRUE
Definition mdbx.h:1845
@ MDBX_BUSY
Definition mdbx.h:1934
@ MDBX_EINVAL
Definition mdbx.h:2006
@ MDBX_ENOMEM
Definition mdbx.h:2008
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1937
@ MDBX_RESULT_FALSE
Definition mdbx.h:1842
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:1985
@ MDBX_KEYEXIST
Definition mdbx.h:1848
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:2528
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2523
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2526
MDBX_env_flags_t
Environment flags.
Definition mdbx.h:1038
@ MDBX_WRITEMAP
Definition mdbx.h:1158
@ MDBX_EXCLUSIVE
Definition mdbx.h:1112
@ MDBX_RDONLY
Definition mdbx.h:1082
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:3039
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2116
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:2978
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:2221
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2217
@ 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:2321
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2125
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2288
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2148
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2253
@ 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:2276
@ 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:2188
@ 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:2175
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2142
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2237
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2154
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2202
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2316
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:3656
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:3059
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:2996
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:4981
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:3701
LIBMDBX_API intptr_t mdbx_limits_keysize_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal key size in bytes for given page size and table flags, or -1 if pagesize is invalid.
LIBMDBX_API int mdbx_reader_list(const MDBX_env *env, MDBX_reader_list_func *func, void *ctx)
Enumerate the entries in the reader lock table.
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_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:1478
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:3917
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition mdbx.h:724
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:1489
@ MDBX_TXN_RDONLY_PREPARE
Definition mdbx.h:1498
@ MDBX_TXN_READWRITE
Definition mdbx.h:1483
@ MDBX_TXN_TRY
Definition mdbx.h:1504
void commit(finalization_latency &latency)
ommits all changes of the transaction into a database with collecting latencies information.
Definition mdbx.h++:4086
friend class env
Definition mdbx.h++:4043
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:3729
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4543
~txn_managed() noexcept
::MDBX_stat map_stat
Definition mdbx.h++:3895
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++:3436
@ prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h++:3470
@ spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h++:3462
@ spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h++:3464
@ writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h++:3468
@ sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h++:3445
@ dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h++:3456
@ dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h++:3458
@ spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h++:3460
@ merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h++:3466
@ 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++:3450
@ loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h++:3452
@ dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h++:3454
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3663
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3876
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++:2935
path get_path() const
Return the path that was used for opening the environment.
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4388
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4444
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2904
durability
Durability level.
Definition mdbx.h++:3081
@ lazy_weak_tail
Definition mdbx.h++:3084
@ robust_synchronous
Definition mdbx.h++:3082
@ whole_fragile
Definition mdbx.h++:3085
@ half_synchronous_weak_last
Definition mdbx.h++:3083
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++:2931
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3251
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++:4432
bool checkpoint(finalization_latency &latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4100
estimate_result estimate(move_operation operation, slice &key) const
cache_entry() noexcept
Definition mdbx.h++:2765
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3686
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4407
::MDBX_canary canary
Definition mdbx.h++:3904
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++:4103
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++:3727
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++:4337
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++:4401
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++:5268
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4410
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++:2772
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2925
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2905
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4496
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4355
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++:4346
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++:4172
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3783
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3959
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4378
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4164
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4168
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++:3868
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3178
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4362
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4565
MDBX_txn * handle_
Definition mdbx.h++:3687
void abort()
Abandon all the operations of the transaction instead of saving ones.
MDBX_commit_latency finalization_latency
Definition mdbx.h++:4065
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4334
mode
Operation mode.
Definition mdbx.h++:3073
@ write_mapped_io
Definition mdbx.h++:3076
@ nested_transactions
Definition mdbx.h++:3077
@ readonly
Definition mdbx.h++:3074
@ write_file_io
Definition mdbx.h++:3075
bool is_writemap() const
Definition mdbx.h++:3344
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4331
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4290
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3312
operator::mdbx::txn() const
Definition mdbx.h++:4473
MDBX_env * handle_
Definition mdbx.h++:2974
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++:4394
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4160
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4344
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4364
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:2768
bool is_nested_transactions_available() const
Definition mdbx.h++:3348
void close()
Explicitly closes the cursor.
Definition mdbx.h++:4549
void abort(finalization_latency &latency)
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4072
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++:4375
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3724
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++:4440
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++:4007
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3282
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3292
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3294
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3289
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4266
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4349
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4311
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4555
::MDBX_dbi_state_t state
Definition mdbx.h++:2936
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3493
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4523
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++:3257
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4404
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++:4436
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4366
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4363
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4474
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3253
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2928
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3780
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2919
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++:4381
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3318
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3956
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++:6178
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4023
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++:3264
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++:3861
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2916
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++:4114
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++:4015
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++:4117
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++:2922
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++:4416
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4182
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4197
@ multi_exactkey_value_equal
Definition mdbx.h++:4214
@ pair_greater_or_equal
Definition mdbx.h++:4222
@ key_lesser_than
Definition mdbx.h++:4204
@ next
Definition mdbx.h++:4185
@ pair_exact
Definition mdbx.h++:4221
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4215
@ pair_lesser_or_equal
Definition mdbx.h++:4219
@ batch_samelength
Definition mdbx.h++:4225
@ seek_key
Definition mdbx.h++:4199
@ key_lowerbound
Definition mdbx.h++:4201
@ pair_lesser_than
Definition mdbx.h++:4218
@ pair_equal
Definition mdbx.h++:4220
@ key_greater_than
Definition mdbx.h++:4208
@ batch_samelength_next
Definition mdbx.h++:4226
@ multi_find_pair
Definition mdbx.h++:4196
@ key_greater_or_equal
Definition mdbx.h++:4207
@ key_exact
Definition mdbx.h++:4200
@ key_equal
Definition mdbx.h++:4206
@ multi_currentkey_prevvalue
Definition mdbx.h++:4191
@ key_lesser_or_equal
Definition mdbx.h++:4205
@ multi_nextkey_firstvalue
Definition mdbx.h++:4194
@ get_current
Definition mdbx.h++:4187
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4213
@ multi_prevkey_lastvalue
Definition mdbx.h++:4189
@ previous
Definition mdbx.h++:4186
@ last
Definition mdbx.h++:4184
@ pair_greater_than
Definition mdbx.h++:4223
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4212
@ multi_currentkey_firstvalue
Definition mdbx.h++:4190
@ first
Definition mdbx.h++:4183
@ batch_samelength_previous
Definition mdbx.h++:4227
@ multi_currentkey_nextvalue
Definition mdbx.h++:4192
@ seek_and_batch_samelength
Definition mdbx.h++:4228
@ multi_exactkey_value_greater
Definition mdbx.h++:4216
@ multi_currentkey_lastvalue
Definition mdbx.h++:4193
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++:4089
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4340
void insert(const pair &kv)
Definition mdbx.h++:4497
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3721
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++:4499
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4352
txn_managed & operator=(const txn_managed &)=delete
bool is_cooperative() const
Definition mdbx.h++:3342
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3881
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:5266
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4391
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++:4359
bool is_readonly() const
Definition mdbx.h++:3338
value_result try_insert(const pair &kv)
Definition mdbx.h++:4498
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++:4515
constexpr cursor() noexcept=default
bool is_exclusive() const
Definition mdbx.h++:3340
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4369
finalization_latency abort_get_latency()
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4075
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4413
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3261
MDBX_cursor * handle_
Definition mdbx.h++:4136
~cursor_managed() noexcept
Definition mdbx.h++:4573
bool is_readwite() const
Definition mdbx.h++:3346
MDBX_dbi dbi
Definition mdbx.h++:2903
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4385
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4356
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3735
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++:4397
txn_managed(const txn_managed &)=delete
friend int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept
Definition mdbx.h++:6174
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3309
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3259
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3958
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3957
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++:3889
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4372
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++:4345
friend class txn
Definition mdbx.h++:2971
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4156
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3255
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3738
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4285
Unmanaged cursor.
Definition mdbx.h++:4134
Managed cursor.
Definition mdbx.h++:4535
Unmanaged database environment.
Definition mdbx.h++:2970
Managed database environment.
Definition mdbx.h++:3602
Unmanaged database transaction.
Definition mdbx.h++:3684
Managed database transaction.
Definition mdbx.h++:4041
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++:5309
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5173
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4843
polymorphic_allocator default_allocator
Definition mdbx.h++:397
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4852
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4934
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++:5147
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++:5594
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++:5085
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++:5076
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5658
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++:5337
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4948
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4673
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++:6050
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6285
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2817
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4830
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:4630
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4928
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5691
class MDBX_MSVC_DECLSPEC_EMPTY_BASES buffer
Definition mdbx.h++:405
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:4820
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4708
void rethrow_captured() const
Definition mdbx.h++:4645
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4828
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6243
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6219
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5302
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5276
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++:5094
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6013
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5967
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5556
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++:5487
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6187
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++:5126
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4850
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6123
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++:5152
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4875
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4776
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6291
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:462
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5960
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6135
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5788
void throw_on_failure() const
Definition mdbx.h++:4685
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6366
void update(const slice &key, const slice &value)
Definition mdbx.h++:6362
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:4627
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++:5859
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:4997
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4838
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++:5141
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5660
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5623
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6174
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4974
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5420
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5847
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6352
bool is_clean() const noexcept
Definition mdbx.h++:4638
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2810
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4728
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++:5131
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5410
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2814
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition mdbx.h++:418
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition mdbx.h++:5462
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5295
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4918
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4652
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++:5157
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4581
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5028
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++:6078
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++:5559
void insert(const slice &key, slice value)
Definition mdbx.h++:6313
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6247
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++:5743
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:5222
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition mdbx.h++:396
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition mdbx.h++:2798
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++:5599
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++:5167
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4760
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:6137
~cursor() noexcept
Definition mdbx.h++:6158
~txn() noexcept
Definition mdbx.h++:5642
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5492
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:5121
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6239
uint64_t txnid
Transaction ID and MVCC-snapshot number.
Definition mdbx.h++:414
constexpr void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition mdbx.h++:4856
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6293
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6338
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5287
map_handle map() const
Definition mdbx.h++:6298
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++:5503
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:4634
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6231
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5759
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6251
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2878
void success_or_throw() const
Definition mdbx.h++:4690
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5695
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4890
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5543
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4978
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6178
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6257
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4886
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5293
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4895
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5665
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6356
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5418
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2806
void capture() noexcept
Definition mdbx.h++:4640
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:5103
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++:5824
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5995
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4869
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2949
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6331
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++:5357
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++:5498
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:6111
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5424
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5784
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6129
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++:6087
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5428
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5710
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4982
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6145
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5818
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6197
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++:5333
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++:5863
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5283
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5836
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5985
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4913
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4667
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++:5509
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4940
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4812
bool on_first() const
Definition mdbx.h++:6265
::MDBX_version_info version_info
libmdbx version information,
Definition mdbx.h++:361
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition mdbx.h++:4848
bool eof() const
Definition mdbx.h++:6263
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5693
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5679
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5480
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6305
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5608
::MDBX_build_info build_info
libmdbx build information
Definition mdbx.h++:365
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition mdbx.h++:5116
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5632
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4880
bool seek(const slice &key)
Definition mdbx.h++:6255
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5532
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5482
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4902
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++:5401
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5786
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++:5521
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5238
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4863
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6318
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++:6419
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4713
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4661
::MDBX_cmp_func * comparator
Definition mdbx.h++:2948
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5677
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2957
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5178
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++:5162
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++:5513
::mdbx_filehandle_t filehandle
Definition mdbx.h++:420
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++:5379
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5244
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4970
char8_t byte
The byte-like type that don't presumes aliases for pointers as does the char.
Definition mdbx.h++:346
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5841
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6397
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5432
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5071
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5685
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5947
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:379
constexpr bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition mdbx.h++:4675
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:5098
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:5080
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6225
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4955
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:5089
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:5107
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6007
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5234
~env() noexcept
Definition mdbx.h++:5254
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2779
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5875
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4669
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4858
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++:6092
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5991
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4907
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2782
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5601
::mdbx::filesystem::path path
Definition mdbx.h++:444
bool on_last_multival() const
Definition mdbx.h++:6271
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5474
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5942
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5468
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++:5313
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5564
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6143
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5408
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5722
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2802
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5712
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5526
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4582
bool on_first_multival() const
Definition mdbx.h++:6269
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5934
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4703
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:5010
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4923
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5444
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5981
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5291
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++:5136
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6378
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:5697
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6235
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4814
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4836
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++:5219
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5587
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:6026
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4665
bool on_last() const
Definition mdbx.h++:6267
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++:6057
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition mdbx.h++:440
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition mdbx.h++:5456
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5537
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++:6287
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:5112
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5270
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5728
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4659
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5050
constexpr bool is_success() const noexcept
Definition mdbx.h++:4663
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6384
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:5023
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5630
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5230
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5716
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++:5775
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++:5913
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5830
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4822
@ multi_reverse_samelength
Definition mdbx.h++:2850
@ multi_samelength
Definition mdbx.h++:2835
@ multi_ordinal
Definition mdbx.h++:2842
@ msgpack
Definition mdbx.h++:2865
@ single
Definition mdbx.h++:2818
@ multi
Definition mdbx.h++:2820
@ multi_reverse
Definition mdbx.h++:2827
@ upsert
Insert or update.
Definition mdbx.h++:2959
@ update
Update existing, don't insert new.
Definition mdbx.h++:2960
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2958
@ continue_loop
Definition mdbx.h++:2779
@ exit_loop
Definition mdbx.h++:2779
@ usual
Definition mdbx.h++:2783
@ ordinal
Definition mdbx.h++:2788
@ reverse
Definition mdbx.h++:2785
@ msgpack
Definition mdbx.h++:2793
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2902
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2413
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2126
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++:2004
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2031
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:701
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2096
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1986
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:714
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:677
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++:2268
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2309
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:668
buffer_pair_spec(const txn &transacton, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2699
const slice source
Definition mdbx.h++:1259
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++:2634
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++:2217
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:736
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:2047
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2340
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2044
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2422
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2292
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++:2019
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2153
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2393
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2306
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2038
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2158
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2666
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1562
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1032
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1236
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2344
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2071
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2523
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2067
buffer & append(const byte c)
Definition mdbx.h++:2477
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2317
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:754
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1013
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2322
buffer & operator=(const buffer &src)
Definition mdbx.h++:2439
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1031
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2545
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:2013
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2708
constexpr int64_t as_int64() const
Definition mdbx.h++:1038
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2064
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2624
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++:2199
const bool ignore_spaces
Definition mdbx.h++:1339
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:858
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++:2281
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++:2275
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2194
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2487
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2237
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++:1101
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Definition mdbx.h++:771
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2677
constexpr int16_t as_int16() const
Definition mdbx.h++:1040
slice value
Definition mdbx.h++:1065
::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++:2679
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2418
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++:2261
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2644
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1207
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++:2287
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2191
slice value
Definition mdbx.h++:1079
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2670
::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++:1981
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2650
const slice source
Definition mdbx.h++:1338
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2688
const slice source
Definition mdbx.h++:1174
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++:2225
constexpr buffer & assign(buffer &&src) noexcept(allocation_aware_details::move_assign_alloc< silo, allocator_type >::is_nothrow())
Definition mdbx.h++:2381
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++:1321
const unsigned wrap_width
Definition mdbx.h++:1176
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2448
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2630
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:728
const slice & slice() const noexcept
Definition mdbx.h++:2662
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2401
const bool ignore_spaces
Definition mdbx.h++:1305
constexpr POD as_pod() const
Definition mdbx.h++:1015
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++:1128
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++:1405
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2683
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2389
constexpr buffer(const buffer &src)
Definition mdbx.h++:2136
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++:2254
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1028
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2462
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2084
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2636
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2332
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1177
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2685
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2519
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2616
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1527
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2169
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:750
std::pair< slice, slice > stl_pair
Definition mdbx.h++:1078
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2543
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:1998
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
@ pettiness_threshold
Definition mdbx.h++:1515
@ extra_inplace_storage
Definition mdbx.h++:1513
@ max_reserve
Definition mdbx.h++:1516
@ inplace_storage_size_rounding
Definition mdbx.h++:1514
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2648
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:691
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1340
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2443
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2515
constexpr int8_t as_int8() const
Definition mdbx.h++:1041
constexpr ::std::span< char > chars()
Definition mdbx.h++:703
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1060
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1278
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2121
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++:1519
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1250
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++:1396
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:1067
static buffer key_from(buffer &&src) noexcept
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++:1367
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2249
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2164
const slice source
Definition mdbx.h++:1217
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:1081
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2407
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++:1990
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2652
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:702
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1379
buffer_pair_spec & operator=(buffer_pair_spec &&src)
Definition mdbx.h++:2712
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2578
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++:1211
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1563
uint8_t as_uint8_adapt() const
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:682
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2642
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2115
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2445
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2728
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2495
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2566
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2527
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++:1357
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:733
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++:758
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1328
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:647
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++:2232
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2658
slice inherited
Definition mdbx.h++:1556
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:1129
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1306
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2654
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++:2656
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2311
static constexpr pair invalid() noexcept
Definition mdbx.h++:1094
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2104
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2397
bool done
Definition mdbx.h++:1127
::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++:1253
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:700
pair & operator=(pair &&couple)
Definition mdbx.h++:1085
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:716
allocation_aware_details::move_assign_alloc< silo, allocator_type > move_assign_alloc
Definition mdbx.h++:1979
const bool uppercase
Definition mdbx.h++:1175
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1980
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2051
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2360
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2485
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2531
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2696
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2058
const bool ignore_spaces
Definition mdbx.h++:1378
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1262
pair(const pair &) noexcept=default
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2610
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:1008
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++:1036
slice key
Definition mdbx.h++:1079
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2469
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:1080
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2702
const slice source
Definition mdbx.h++:1377
pair_result & operator=(const pair_result &) noexcept=default
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2467
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1295
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2660
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2459
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2668
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++:1039
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++:2211
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2140
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1558
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2632
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2024
pair & operator=(const stl_pair &couple)
Definition mdbx.h++:1096
int64_t as_int64_adapt() const
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2640
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2027
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++:2206
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2336
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2694
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1033
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2669
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2149
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1983
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2535
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2555
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1030
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2176
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++:2690
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2638
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++:2244
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2592
const unsigned wrap_width
Definition mdbx.h++:1218
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++:2511
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2188
const unsigned wrap_width
Definition mdbx.h++:1260
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2441
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++:1005
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2078
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++:2497
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2705
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++:709
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2504
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2144
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2621
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2667
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++:1299
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++:1220
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2132
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:711
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++:1192
bool done
Definition mdbx.h++:1066
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++:1304
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:2007
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2089
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1554
Definition mdbx.h++:2665
Type tag for delivered buffer template classes.
Definition mdbx.h++:1550
Definition mdbx.h++:1511
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1337
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1376
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1303
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:1077
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:1126
References a data located outside the slice.
Definition mdbx.h++:642
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1216
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1258
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1173
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:1064
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:560
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++:4661
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
fatal(const exception &src) noexcept
Definition mdbx.h++:559
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 &)
void panic(const char *context_where_when, const char *func_who_what) const noexcept
Panics on unrecoverable errors inside destructors etc.
static void success_or_throw(int error_code)
Definition mdbx.h++:528
db_full(const ::mdbx::error &)
duplicated_lck_file(const ::mdbx::error &)
const ::mdbx::error error() const noexcept
Definition mdbx.h++:550
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++:561
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++:562
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++:4659
error & operator=(const error &)=default
virtual ~exception() noexcept
error(error &&)=default
thread_mismatch(const ::mdbx::error &)
db_corrupted(const ::mdbx::error &)
internal_page_full(const ::mdbx::error &)
mvcc_retarded(const ::mdbx::error &)
max_maps_reached(const ::mdbx::error &)
bad_value_size(const ::mdbx::error &)
Implements error information and throwing corresponding exceptions.
Definition mdbx.h++:487
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:472
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:568
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:4920
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:4924
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++:250
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition mdbx.h++:290
#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES,...)
Definition mdbx.h++:125
#define MDBX_LIKELY(cond)
Definition mdbx.h++:225
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition mdbx.h++:202
#define MDBX_UNLIKELY(cond)
Definition mdbx.h++:233
#define MDBX_CXX17_CONSTEXPR
Definition mdbx.h++:181
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition mdbx.h++:220
#define MDBX_IF_CONSTEXPR
Definition mdbx.h++:241
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition mdbx.h++:201
#define MDBX_CXX20_LIKELY
Definition mdbx.h++:256
The libmdbx C API header file.
Definition mdbx.h++:1413
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1415
The libmdbx C++ API namespace.
Definition mdbx.h++:323
STL namespace.
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6467
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1649
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1651
byte lastbyte_
Definition mdbx.h++:1650
Definition mdbx.h++:4247
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4249
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4248
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4251
Definition mdbx.h++:4235
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++:4239
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4237
Tagged type for output to std::ostream.
Definition mdbx.h++:3022
intptr_t bytes
Definition mdbx.h++:3023
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3024
Database geometry for size management.
Definition mdbx.h++:2998
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3046
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3058
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3005
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3001
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3004
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3013
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3002
@ default_value
Means "keep current or use default".
Definition mdbx.h++:3000
@ kB
bytes (0x03E8)
Definition mdbx.h++:3003
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3012
@ KiB
bytes (0x0400)
Definition mdbx.h++:3011
constexpr geometry() noexcept
Definition mdbx.h++:3062
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3049
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3034
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3052
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3029
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++:3065
Operate options.
Definition mdbx.h++:3102
bool disable_readahead
Definition mdbx.h++:3111
bool enable_validation
Definition mdbx.h++:3115
bool no_sticky_threads
Definition mdbx.h++:3104
constexpr operate_options() noexcept
Definition mdbx.h++:3116
bool disable_clear_memory
Definition mdbx.h++:3113
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3109
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
bool nested_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3107
Operate parameters.
Definition mdbx.h++:3124
env::durability durability
Definition mdbx.h++:3132
env::operate_options options
Definition mdbx.h++:3134
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++:3138
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++:3130
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3133
env::mode mode
Definition mdbx.h++:3131
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++:3127
constexpr operate_parameters() noexcept
Definition mdbx.h++:3136
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3516
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3519
uint64_t transaction_lag
Definition mdbx.h++:3522
size_t bytes_used
Definition mdbx.h++:3526
uint64_t transaction_id
Definition mdbx.h++:3520
int slot
The reader lock table slot number.
Definition mdbx.h++:3517
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3518
size_t bytes_retained
Definition mdbx.h++:3529
Garbage reclaiming options.
Definition mdbx.h++:3089
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
bool coalesce
Definition mdbx.h++:3093
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3094
bool lifo
Definition mdbx.h++:3091
Additional parameters for creating a new database.
Definition mdbx.h++:3625
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3627
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3628
env::geometry geometry
Definition mdbx.h++:3626
Definition mdbx.h++:2937
map_handle::state state
Definition mdbx.h++:2939
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2938
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6572
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6568
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6567
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6558
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6557
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6553
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6549
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6562
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6563
capacity_holder capacity_
Definition mdbx.h++:1655
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1688
allocator_pointer stub_ptr_
Definition mdbx.h++:1630
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1667
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1708
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1659
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1674
inplace_flag_holder inplace_
Definition mdbx.h++:1656
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1658
allocator_pointer allocated_ptr_
Definition mdbx.h++:1654
size_t stub_capacity_bytes_
Definition mdbx.h++:1631
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1727
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1644
size_t bytes_
Definition mdbx.h++:1645
constexpr const byte * address() const noexcept
Definition mdbx.h++:1721
constexpr bin() noexcept
Definition mdbx.h++:1702
@ inplace_size
Definition mdbx.h++:1639
@ inplace_signature_limit
Definition mdbx.h++:1636
@ inplace_size_rounding
Definition mdbx.h++:1638
constexpr byte * address() noexcept
Definition mdbx.h++:1724
@ lastbyte_poison
Definition mdbx.h++:1634
@ lastbyte_inplace_signature
Definition mdbx.h++:1634
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1717
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1676