libmdbx 0.14.1.479 (2026-03-20T07:19:50+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
445using path_string = MDBX_STD_FILESYSTEM_PATH::string_type;
446#elif defined(_WIN32) || defined(_WIN64)
447using path = ::std::wstring;
448using path_string = path;
449#else
450using path = ::std::string;
451using path_string = path;
452#endif /* mdbx::path */
453using path_char = path_string::value_type;
454
455#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
456#ifndef MDBX_U128_TYPE
457#define MDBX_U128_TYPE __uint128_t
458#endif /* MDBX_U128_TYPE */
459#ifndef MDBX_I128_TYPE
460#define MDBX_I128_TYPE __int128_t
461#endif /* MDBX_I128_TYPE */
462#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
463
464#if __cplusplus >= 201103L || defined(DOXYGEN)
466using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
467#endif /* Duration for C++11 */
468
471
477 ::std::exception_ptr captured_;
478
479public:
480 exception_thunk() noexcept = default;
483 exception_thunk &operator=(const exception_thunk &) = delete;
484 exception_thunk &operator=(exception_thunk &&) = delete;
485 inline bool is_clean() const noexcept;
486 inline void capture() noexcept;
487 inline void rethrow_captured() const;
488};
489
492 MDBX_error_t code_;
493 inline error &operator=(MDBX_error_t error_code) noexcept;
494
495public:
496 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
497 error(const error &) = default;
498 error(error &&) = default;
499 error &operator=(const error &) = default;
500 error &operator=(error &&) = default;
501
502 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
503 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
504
505 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
506 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
507 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
508 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
509
511 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
512
514 const char *what() const noexcept;
515
517 ::std::string message() const;
518
520 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
522 [[noreturn]] void panic(const char *context_where_when, const char *func_who_what) const noexcept;
523 [[noreturn]] void throw_exception() const;
524 [[noreturn]] static inline void throw_exception(int error_code);
525 inline void throw_on_failure() const;
526 inline void success_or_throw() const;
527 inline void success_or_throw(const exception_thunk &) const;
528 inline void panic_on_failure(const char *context_where, const char *func_who) const noexcept;
529 inline void success_or_panic(const char *context_where, const char *func_who) const noexcept;
530 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
531 static inline void success_or_throw(MDBX_error_t error_code);
532 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
533 static inline void throw_on_failure(int error_code);
534 static inline bool boolean_or_throw(int error_code);
535 static inline void success_or_throw(int error_code, const exception_thunk &);
536 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
537 static inline void panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept;
538 static inline void success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept;
539};
540
543class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
544 using base = ::std::runtime_error;
545 ::mdbx::error error_;
546
547public:
548 exception(const ::mdbx::error &) noexcept;
549 exception(const exception &) = default;
550 exception(exception &&) = default;
551 exception &operator=(const exception &) = default;
553 virtual ~exception() noexcept;
554 const ::mdbx::error error() const noexcept { return error_; }
555};
556
559 using base = exception;
560
561public:
562 fatal(const ::mdbx::error &) noexcept;
563 fatal(const exception &src) noexcept : fatal(src.error()) {}
564 fatal(exception &&src) noexcept : fatal(src.error()) {}
565 fatal(const fatal &src) noexcept : fatal(src.error()) {}
566 fatal(fatal &&src) noexcept : fatal(src.error()) {}
567 fatal &operator=(fatal &&) = default;
568 fatal &operator=(const fatal &) = default;
569 virtual ~fatal() noexcept;
570};
571
572#define MDBX_DECLARE_EXCEPTION(NAME) \
573 struct LIBMDBX_API_TYPE NAME : public exception { \
574 NAME(const ::mdbx::error &); \
575 virtual ~NAME() noexcept; \
576 }
610#undef MDBX_DECLARE_EXCEPTION
611
614[[noreturn]] LIBMDBX_API void throw_out_range();
618
619static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
620 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
621 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
622 return bytes;
623}
624
625static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
626 return check_length(check_length(headroom) + check_length(payload));
627}
628
629MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
630 return check_length(check_length(headroom, payload) + check_length(tailroom));
631}
632
634
635//------------------------------------------------------------------------------
636
639
651
652 enum : size_t { max_length = MDBX_MAXDATASIZE };
653
655 MDBX_CXX11_CONSTEXPR slice() noexcept;
656
658 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
659
661 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
662
664 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
665 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
666 }
667
668 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
669
672 template <class CHAR, class T, class A>
673 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
674 : slice(str.data(), str.length() * sizeof(CHAR)) {}
675
677 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
679 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
680
681#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
682 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
683 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
684 "Must be a standard layout type!");
685 }
686
687 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
688 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
689 "Must be a standard layout type!");
690 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
692 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
694 }
695
696 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
697 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
698 "Must be a standard layout type!");
699 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
701 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
703 }
704
705 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
706 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
707 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
708 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
709#endif /* __cpp_lib_span >= 202002L */
710
711#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
713 template <class CHAR, class T>
714 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv) : slice(sv.data(), sv.data() + sv.length()) {}
715
716 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
717#endif /* __cpp_lib_string_view >= 201606L */
718
719 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
720
721 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
722 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
723 "Must be a standard layout type!");
724 return slice(&pod, sizeof(pod));
725 }
726
727 inline slice &assign(const void *ptr, size_t bytes);
728 inline slice &assign(const slice &src) noexcept;
729 inline slice &assign(const ::MDBX_val &src);
730 inline slice &assign(slice &&src) noexcept;
731 inline slice &assign(::MDBX_val &&src);
732 inline slice &assign(const void *begin, const void *end);
733 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
734 return assign(str.data(), str.length() * sizeof(CHAR));
735 }
736 inline slice &assign(const char *c_str);
737#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
738 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
739 return assign(view.begin(), view.end());
740 }
741 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
742 assign(view);
743 view = {};
744 return *this;
745 }
746#endif /* __cpp_lib_string_view >= 201606L */
747
748 slice &operator=(const slice &) noexcept = default;
749 inline slice &operator=(slice &&src) noexcept;
750 inline slice &operator=(::MDBX_val &&src);
751 operator MDBX_val *() noexcept { return this; }
752 operator const MDBX_val *() const noexcept { return this; }
753
754#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
755 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
756 return assign(view);
757 }
758
759 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
760
762 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
763 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
764 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
765 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
766 }
767
769 template <class CHAR, class T>
770 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
771 return this->string_view<CHAR, T>();
772 }
773#endif /* __cpp_lib_string_view >= 201606L */
774
775 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
776 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
777 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
778 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
779 }
780
781 template <class CHAR, class T, class ALLOCATOR>
782 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
784 }
785
787 template <class ALLOCATOR = default_allocator>
788 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
789 const ALLOCATOR &alloc = ALLOCATOR()) const;
790
793 template <class ALLOCATOR = default_allocator>
794 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
795
798 template <class ALLOCATOR = default_allocator>
799 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
800
802 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
803 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
804 const ALLOCATOR &alloc = ALLOCATOR()) const;
805
808 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
809 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
810 const ALLOCATOR &alloc = ALLOCATOR()) const;
811
814 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
815 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
816 const ALLOCATOR &alloc = ALLOCATOR()) const;
817
819 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
820 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
821 const ALLOCATOR &alloc = ALLOCATOR()) const;
822
825 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
826 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
827 const ALLOCATOR &alloc = ALLOCATOR()) const;
828
831 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
832 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
833 const ALLOCATOR &alloc = ALLOCATOR()) const;
834
840 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
841
846 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
847
853 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
854
860 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
861
862#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
863 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
864 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
865 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
866 *this = view;
867 view = temp;
868 }
869#endif /* __cpp_lib_string_view >= 201606L */
870
872 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
873 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
874
876 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
877 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
878
880 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
881 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
882
884 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
885 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
886
888 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
889 MDBX_CXX11_CONSTEXPR void *data() noexcept;
890
892 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
893 MDBX_CXX11_CONSTEXPR void *end() noexcept;
894
896 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
897
899 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
900
902 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
903
905 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
906
908 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
909
911 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
912
914 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
915
917 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
918
920 MDBX_CXX14_CONSTEXPR void clear() noexcept;
921
924 inline void remove_prefix(size_t n) noexcept;
925
928 inline void remove_suffix(size_t n) noexcept;
929
932 inline void safe_remove_prefix(size_t n);
933
936 inline void safe_remove_suffix(size_t n);
937
939 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
940
942 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
943
946 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
947
950 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
951
954 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
955
958 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
959
962 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
963
966 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
967
970 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
971
974 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
975
980 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
981
990 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
991
997 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
998 const slice &b) noexcept;
999 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
1000 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
1001 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
1002 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
1003 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
1004 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
1005#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1006 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
1007#endif /* __cpp_impl_three_way_comparison */
1008
1010 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1011
1014 return slice(/* using special constructor without length checking */ ~size_t(0));
1015 }
1016
1018 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1019
1020 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1021 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1022 "Must be a standard layout type!");
1023 if (MDBX_LIKELY(size() == sizeof(POD)))
1025 POD r;
1026 memcpy(&r, data(), sizeof(r));
1027 return r;
1028 }
1030 }
1031
1032#ifdef MDBX_U128_TYPE
1033 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1034#endif /* MDBX_U128_TYPE */
1035 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1036 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1037 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1038 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1039
1040#ifdef MDBX_I128_TYPE
1041 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1042#endif /* MDBX_I128_TYPE */
1043 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1044 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1045 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1046 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1047
1048#ifdef MDBX_U128_TYPE
1049 MDBX_U128_TYPE as_uint128_adapt() const;
1050#endif /* MDBX_U128_TYPE */
1051 uint64_t as_uint64_adapt() const;
1052 uint32_t as_uint32_adapt() const;
1053 uint16_t as_uint16_adapt() const;
1054 uint8_t as_uint8_adapt() const;
1055
1056#ifdef MDBX_I128_TYPE
1057 MDBX_I128_TYPE as_int128_adapt() const;
1058#endif /* MDBX_I128_TYPE */
1059 int64_t as_int64_adapt() const;
1060 int32_t as_int32_adapt() const;
1061 int16_t as_int16_adapt() const;
1062 int8_t as_int8_adapt() const;
1063
1064protected:
1065 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1066};
1067
1071 bool done;
1072 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
1073 value_result(const value_result &) noexcept = default;
1074 value_result &operator=(const value_result &) noexcept = default;
1075 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1076 assert(!done || bool(value));
1077 return done;
1078 }
1079};
1080
1082struct pair {
1083 using stl_pair = std::pair<slice, slice>;
1085 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
1086 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
1087 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
1088 pair(const pair &) noexcept = default;
1089 pair &operator=(const pair &) noexcept = default;
1090 pair &operator=(pair &&couple) {
1091 key.assign(std::move(couple.key));
1092 value.assign(std::move(couple.value));
1093 return *this;
1094 }
1095 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1096 assert(bool(key) == bool(value));
1097 return key;
1098 }
1100
1101 pair &operator=(const stl_pair &couple) {
1102 key.assign(couple.first);
1103 value.assign(couple.second);
1104 return *this;
1105 }
1107 key.assign(std::move(couple.first));
1108 value.assign(std::move(couple.second));
1109 return *this;
1110 }
1111
1113 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
1114
1116 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
1117 const pair &b) noexcept;
1118 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
1119 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
1120 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
1121 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
1122 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
1123 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
1124#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1125 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
1126#endif /* __cpp_impl_three_way_comparison */
1127};
1128
1131struct pair_result : public pair {
1132 bool done;
1135 : pair(key, value), done(done) {}
1136 pair_result(const pair_result &) noexcept = default;
1137 pair_result &operator=(const pair_result &) noexcept = default;
1138 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1139 assert(!done || (bool(key) && bool(value)));
1140 return done;
1141 }
1142};
1143
1144#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
1145
1149template <typename T>
1150concept MutableByteProducer = requires(T a, char array[42]) {
1151 { a.is_empty() } -> std::same_as<bool>;
1152 { a.envisage_result_length() } -> std::same_as<size_t>;
1153 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1154};
1155
1159template <typename T>
1160concept ImmutableByteProducer = requires(const T &a, char array[42]) {
1161 { a.is_empty() } -> std::same_as<bool>;
1162 { a.envisage_result_length() } -> std::same_as<size_t>;
1163 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1164};
1165
1169template <typename T>
1170concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
1171 T(source);
1172 { a.is_erroneous() } -> std::same_as<bool>;
1173};
1174
1175#endif /* MDBX_HAVE_CXX20_CONCEPTS */
1176
1180 const bool uppercase = false;
1181 const unsigned wrap_width = 0;
1186
1188 template <class ALLOCATOR = default_allocator>
1189 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1190
1192 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1193 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1194
1198 const size_t bytes = source.length() << 1;
1199 return wrap_width ? bytes + bytes / wrap_width : bytes;
1200 }
1201
1204 char *write_bytes(char *dest, size_t dest_size) const;
1205
1208 ::std::ostream &output(::std::ostream &out) const;
1209
1212 bool is_empty() const noexcept { return source.empty(); }
1213
1216 bool is_erroneous() const noexcept { return false; }
1217};
1218
1223 const unsigned wrap_width = 0;
1228
1231 template <class ALLOCATOR = default_allocator>
1232 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1233
1236 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1237 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1238
1242 const size_t bytes = (source.length() * 11 + 7) / 8;
1243 return wrap_width ? bytes + bytes / wrap_width : bytes;
1244 }
1245
1248 char *write_bytes(char *dest, size_t dest_size) const;
1249
1252 ::std::ostream &output(::std::ostream &out) const;
1253
1255 bool is_empty() const noexcept { return source.empty(); }
1256
1258 bool is_erroneous() const noexcept { return false; }
1259};
1260
1265 const unsigned wrap_width = 0;
1270
1273 template <class ALLOCATOR = default_allocator>
1274 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1275
1278 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1279 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1280
1284 const size_t bytes = (source.length() + 2) / 3 * 4;
1285 return wrap_width ? bytes + bytes / wrap_width : bytes;
1286 }
1287
1291 char *write_bytes(char *dest, size_t dest_size) const;
1292
1296 ::std::ostream &output(::std::ostream &out) const;
1297
1300 bool is_empty() const noexcept { return source.empty(); }
1301
1304 bool is_erroneous() const noexcept { return false; }
1305};
1306
1310 const bool ignore_spaces = false;
1315
1317 template <class ALLOCATOR = default_allocator>
1318 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1319
1321 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1322 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1323
1326 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1327
1330 char *write_bytes(char *dest, size_t dest_size) const;
1331
1333 bool is_empty() const noexcept { return source.empty(); }
1334
1337 bool is_erroneous() const noexcept;
1338};
1339
1344 const bool ignore_spaces = false;
1349
1352 template <class ALLOCATOR = default_allocator>
1353 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1354
1357 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1358 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1359
1363 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1364 }
1365
1369 char *write_bytes(char *dest, size_t dest_size) const;
1370
1372 bool is_empty() const noexcept { return source.empty(); }
1373
1376 bool is_erroneous() const noexcept;
1377};
1378
1383 const bool ignore_spaces = false;
1388
1391 template <class ALLOCATOR = default_allocator>
1392 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1393
1396 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1397 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1398
1401 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1402
1406 char *write_bytes(char *dest, size_t dest_size) const;
1407
1410 bool is_empty() const noexcept { return source.empty(); }
1411
1415 bool is_erroneous() const noexcept;
1416};
1417
1419
1420template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1421#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1422 return ::std::allocator_traits<A>::is_always_equal::value;
1423#else
1424 return ::std::is_empty<A>::value;
1425#endif /* __cpp_lib_allocator_traits_is_always_equal */
1426}
1427
1428template <typename T, typename A = typename T::allocator_type,
1429 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1431
1432template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1433 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1434 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1435 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1436 }
1437 static MDBX_CXX20_CONSTEXPR void propagate(T *, T &) noexcept {}
1438};
1439
1440template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1441 static constexpr bool is_nothrow() noexcept {
1442 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1443 }
1444 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1445 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1446 target->get_allocator() = ::std::move(source.get_allocator());
1447 }
1448};
1449
1450template <typename T, typename A = typename T::allocator_type,
1451 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1453
1454template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1455 static constexpr bool is_nothrow() noexcept { return false; }
1456 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1457};
1458
1459template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1460 static constexpr bool is_nothrow() noexcept {
1461 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1462 }
1463 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1464 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1465 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1466 MDBX_CXX20_UNLIKELY target->get_allocator() =
1467 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1468 } else {
1469 /* gag for buggy compilers */
1470 (void)target;
1471 (void)source;
1472 }
1473 }
1474};
1475
1476template <typename T, typename A = typename T::allocator_type,
1477 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1479
1480template <typename T, typename A> struct swap_alloc<T, A, false> {
1481 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1482 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1484 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1485 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1486 } else {
1487 /* gag for buggy compilers */
1488 (void)left;
1489 (void)right;
1490 }
1491 }
1492};
1493
1494template <typename T, typename A> struct swap_alloc<T, A, true> {
1495 static constexpr bool is_nothrow() noexcept {
1496 return allocator_is_always_equal<A>() ||
1497#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1498 ::std::is_nothrow_swappable<A>() ||
1499#endif /* __cpp_lib_is_swappable >= 201603L */
1500 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1501 }
1502 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1503 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1504 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1505 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1506 } else {
1507 /* gag for buggy compilers */
1508 (void)left;
1509 (void)right;
1510 }
1511 }
1512};
1513
1514} // namespace allocation_aware_details
1515
1517 enum : size_t {
1522 };
1523
1524 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1525 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1526 static_assert(pettiness_threshold % 2 == 0, "pettiness_threshold must be even");
1527 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1528 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1529 return (value + pettiness_threshold - 1) & pettiness_mask;
1530 }
1531
1532 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1533 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1534 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1535
1536 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1537 return inplace;
1538
1539 if (wanna > current)
1540 /* doubling capacity, but don't made reserve more than max_reserve */
1541 return round(wanna + ::std::min(size_t(max_reserve), current));
1542
1543 if (current - wanna >
1544 /* shrink if reserve will more than half of current or max_reserve,
1545 * but not less than pettiness_threshold */
1546 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1547 return round(wanna);
1548
1549 /* keep unchanged */
1550 return current;
1551 }
1552};
1553
1555struct buffer_tag {};
1556
1558template <class ALLOCATOR, typename CAPACITY_POLICY>
1560public:
1562#if !defined(_MSC_VER) || _MSC_VER > 1900
1563 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1564#else
1565 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1566#endif /* MSVC is mad */
1567 using allocator_traits = ::std::allocator_traits<allocator_type>;
1568 using reservation_policy = CAPACITY_POLICY;
1569 enum : size_t {
1571 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1574 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1575 ? alignof(max_align_t) * 2
1578 };
1579
1580private:
1581 friend class txn;
1582 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1583 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1584 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1585
1586 using allocator_pointer = typename allocator_traits::pointer;
1587 using allocator_const_pointer = typename allocator_traits::const_pointer;
1588
1589 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1590 assert(bytes >= sizeof(bin));
1591 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1592 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1593 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1594 const size_t n = (bytes + unit - 1) / unit;
1595 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1596 }
1597
1598 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1599 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1600 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1601 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1602 }
1603
1604 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1605 const size_t capacity = bin::advise_capacity(0, bytes);
1606 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1607 : allocate_storage(capacity);
1608 }
1609
1610 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1611#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1612 return static_cast<void *>(::std::to_address(ptr));
1613#else
1614 return static_cast<void *>(::std::addressof(*ptr));
1615#endif /* __cpp_lib_to_address */
1616 }
1617
1618 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1619#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1620 return static_cast<const void *>(::std::to_address(ptr));
1621#else
1622 return static_cast<const void *>(::std::addressof(*ptr));
1623#endif /* __cpp_lib_to_address */
1624 }
1625
1626#ifdef _MSC_VER
1627#pragma warning(push)
1628#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1629#endif /* _MSC_VER */
1630
1631 union alignas(max_align_t) bin {
1632 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1633 с учетом выравнивания */
1634 {
1635 allocator_pointer stub_ptr_;
1637 };
1638
1640 enum : size_t {
1642 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1646 };
1647
1649 byte pad_[inplace_size - sizeof(allocator_pointer)];
1650 size_t bytes_;
1651 };
1652
1654 byte buffer_[inplace_size - sizeof(byte)];
1656 MDBX_CXX11_CONSTEXPR inplace_flag_holder(byte signature) : lastbyte_(signature) {};
1657 };
1658
1659 allocator_pointer allocated_ptr_;
1662
1663 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1664 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1665 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1666 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1667 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1668 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1669 return capacity_bytes <= inplace_capacity();
1670 }
1671
1672 constexpr bool is_inplace() const noexcept {
1673 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1674 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1676 "WTF?");
1677 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1678 }
1679 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1680
1681 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1682 if (destroy_ptr) {
1684 /* properly destroy allocator::pointer */
1685 allocated_ptr_.~allocator_pointer();
1686 }
1689 return address();
1690 }
1691
1692 template <bool construct_ptr>
1693 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1695 if (construct_ptr) {
1697 new (&allocated_ptr_) allocator_pointer(pair.first);
1698 } else {
1700 allocated_ptr_ = pair.first;
1701 }
1702 capacity_.bytes_ = pair.second;
1703 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1704 return address();
1705 }
1706
1708 if (::std::is_trivial<allocator_pointer>::value)
1709 /* workaround for "uninitialized" warning from some compilers */
1710 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1711 }
1712
1713 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1714 if (MDBX_UNLIKELY(wanna > max_capacity))
1715 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1716
1717 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1718 assert(advised >= wanna);
1719 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1720 }
1721
1722 constexpr bool is_inplace(const void *ptr) const noexcept {
1723 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1724 }
1725
1726 constexpr const byte *address() const noexcept {
1727 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1728 }
1730 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1731 }
1732 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1733 } bin_;
1734
1735#ifdef _MSC_VER
1736#pragma warning(pop)
1737#endif /* _MSC_VER */
1738
1739 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1740
1741 MDBX_CXX20_CONSTEXPR void release() noexcept {
1742 if (bin_.is_allocated()) {
1743 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1744 /* properly destroy allocator::pointer */
1745 bin_.allocated_ptr_.~allocator_pointer();
1746 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1747 }
1748 }
1749
1750 template <bool external_content>
1751 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1752 const void *const content, const size_t length) {
1753 assert(wanna_capacity >= wanna_headroom + length);
1754 const size_t old_capacity = bin_.capacity();
1755 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1756 if (MDBX_LIKELY(new_capacity == old_capacity))
1758 assert(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1759 byte *const new_place = bin_.address() + wanna_headroom;
1760 if (MDBX_LIKELY(length))
1762 if (external_content)
1763 memcpy(new_place, content, length);
1764 else {
1765 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1766 assert(old_capacity >= old_headroom + length);
1767 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1768 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1769 }
1770 }
1771 return new_place;
1772 }
1773
1774 if (bin::is_suitable_for_inplace(new_capacity)) {
1775 assert(bin_.is_allocated());
1776 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1777 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1778 if (MDBX_LIKELY(length))
1779 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1780 deallocate_storage(old_allocated, old_capacity);
1781 return new_place;
1782 }
1783
1784 if (bin_.is_inplace()) {
1785 const auto pair = allocate_storage(new_capacity);
1786 assert(pair.second >= new_capacity);
1787 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1788 if (MDBX_LIKELY(length))
1789 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1790 bin_.template make_allocated<true>(pair);
1791 return new_place;
1792 }
1793
1794 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1795 if (external_content)
1796 deallocate_storage(old_allocated, old_capacity);
1797 const auto pair = allocate_storage(new_capacity);
1798 assert(pair.second >= new_capacity);
1799 byte *const new_place = bin_.template make_allocated<false>(pair) + wanna_headroom;
1800 if (MDBX_LIKELY(length))
1801 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1802 if (!external_content)
1803 deallocate_storage(old_allocated, old_capacity);
1804 return new_place;
1805 }
1806
1807 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1808 assert(capacity() >= offset);
1809 return bin_.address() + offset;
1810 }
1811 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1812 assert(capacity() >= offset);
1813 return bin_.address() + offset;
1814 }
1815 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1816 assert(capacity() >= offset + length);
1817 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1818 }
1819
1820 //--------------------------------------------------------------------------
1821
1822 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1823 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1824 if (!bin::is_suitable_for_inplace(capacity))
1825 bin_.template make_allocated<true>(provide_storage(capacity));
1826 }
1827
1828 silo(silo &&other) = delete;
1830 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1831 : allocator_type(::std::move(other.get_allocator())) {
1832 if (!is_reference) {
1833 if (other.bin_.is_inplace()) {
1834 memcpy(&bin_, &other.bin_, sizeof(bin));
1835 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1836 } else {
1837 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1838 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1839 /* properly destroy allocator::pointer.
1840 *
1841 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1842 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1843 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1844 * from the 11th). */
1845 /* coverity[use_after_move] */
1846 other.bin_.allocated_ptr_.~allocator_pointer();
1847 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1848 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1849 }
1850 }
1851 }
1852
1853 MDBX_CXX17_CONSTEXPR bool move(silo &&other) noexcept {
1854 if (other.bin_.is_inplace()) {
1855 memcpy(&bin_, &other.bin_, sizeof(bin));
1856 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1857 return /* buffer's slice fixup is needed */ true;
1858 }
1859 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1860 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1861 /* properly destroy allocator::pointer.
1862 *
1863 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1864 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1865 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1866 * from the 11th). */
1867 /* coverity[use_after_move] */
1868 other.bin_.allocated_ptr_.~allocator_pointer();
1869 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1870 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1871 return false;
1872 }
1873
1874 MDBX_CXX17_CONSTEXPR bool assign_move(silo &&other, bool is_reference) noexcept {
1875 release();
1876 if (!allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, other))
1877 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, other);
1878 return is_reference ? false : move(std::move(other));
1879 }
1880
1881 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1882 exchange(silo &left, const bool left_is_reference, silo &right, const bool right_is_reference) noexcept(
1883 allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1884 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(left, right);
1885 bool left_need_fixup = false, right_need_fixup = false;
1886 if (left_is_reference || right_is_reference) {
1887 left_need_fixup = !right_is_reference && left.move(std::move(right));
1888 right_need_fixup = !left_is_reference && right.move(std::move(left));
1889 } else {
1890 silo temp(std::move(left), false);
1891 left_need_fixup = left.move(std::move(right));
1892 right_need_fixup = right.move(std::move(temp));
1893 }
1894 return std::make_pair(left_need_fixup, right_need_fixup);
1895 }
1896
1897 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1898 const allocator_type &alloc = allocator_type())
1899 : silo(capacity, alloc) {
1900 assert(capacity >= headroom + length);
1901 if (length)
1902 put(headroom, ptr, length);
1903 }
1904
1905 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1906 : silo(length, 0, ptr, length, alloc) {}
1907
1908 ~silo() { release(); }
1909
1910 //--------------------------------------------------------------------------
1911
1912 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1913 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1914 }
1915
1916 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1917
1918 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1919 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1920 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1921 }
1922
1923 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1924 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1925 }
1926
1927 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1928 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1929 return get(offset);
1930 }
1931 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1932 };
1933
1934 MDBX_CXX14_CONSTEXPR void fixup_import(const typename silo::bin &src) noexcept {
1935 auto ptr = inherited::byte_ptr();
1936 if (src.is_inplace(ptr)) {
1937 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1938 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1939 iov_base = ptr + offset;
1940 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1941 }
1942 }
1943
1944 silo silo_;
1945
1946 void insulate() {
1947 assert(is_reference());
1948 iov_base = silo_.assign(iov_base, iov_len);
1949 }
1950
1951 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1952 return static_cast<const byte *>(silo_.data());
1953 }
1954
1955 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1956 return silo_begin() + silo_.capacity();
1957 }
1958
1959 struct data_preserver : public exception_thunk {
1960 buffer data;
1961 data_preserver(allocator_type &alloc) : data(alloc) {}
1962 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1963 auto self = static_cast<data_preserver *>(context);
1964 assert(self->is_clean());
1965 assert(&self->data == target);
1966 (void)target;
1967 try {
1968 self->data.assign(src, bytes, false);
1969 return MDBX_RESULT_FALSE;
1970 } catch (... /* capture any exception to rethrow it over C code */) {
1971 self->capture();
1972 return MDBX_RESULT_TRUE;
1973 }
1974 }
1975 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1976 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1977 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1978 };
1979
1980public:
1983
1987
1988 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1989
1991 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1992
1996 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1997 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1998 }
1999
2004 return silo_.is_inplace(inherited::data());
2005 }
2006
2010
2013 return is_freestanding() ? silo_.capacity() : 0;
2014 }
2015
2019 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
2020 }
2021
2025 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2026 }
2027
2029 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2030
2032 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2033
2040
2045 return const_cast<byte *>(inherited::end_byte_ptr());
2046 }
2047
2049 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2050
2052 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2053
2058 return const_cast<char *>(inherited::char_ptr());
2059 }
2060
2065 return const_cast<char *>(inherited::end_char_ptr());
2066 }
2067
2069 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
2070
2072 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
2073
2076 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2078 return const_cast<void *>(inherited::data());
2079 }
2080
2083 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2085 return const_cast<void *>(inherited::end());
2086 }
2087
2092
2099
2102 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2103 return set_length(static_cast<const char *>(ptr) - char_ptr());
2104 }
2105
2110 if (is_reference())
2111 insulate();
2112 }
2113
2114 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2115 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2116 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2117 const allocator_type &alloc = allocator_type());
2118
2120 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2121 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2122
2123 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2124 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2125
2126 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2127 : buffer(inherited(c_str), make_reference, alloc) {}
2128
2129#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2130 template <class CHAR, class T>
2131 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2132 const allocator_type &alloc = allocator_type())
2133 : buffer(inherited(view), make_reference, alloc) {}
2134#endif /* __cpp_lib_string_view >= 201606L */
2135
2137 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2138 : buffer(src, src.empty() || src.is_null(), alloc) {}
2139
2141 buffer(const buffer &src)
2142 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2143
2145 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2146 : buffer(inherited(ptr, bytes), alloc) {}
2147
2148 template <class CHAR, class T, class A>
2149 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2150 const allocator_type &alloc = allocator_type())
2151 : buffer(inherited(str), alloc) {}
2152
2154 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2155
2156#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2157 template <class CHAR, class T>
2158 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2159 const allocator_type &alloc = allocator_type())
2160 : buffer(inherited(view), alloc) {}
2161#endif /* __cpp_lib_string_view >= 201606L */
2162
2163 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2164 : silo_(check_length(head_room, tail_room), alloc) {
2165 iov_base = silo_.get();
2166 assert(iov_len == 0);
2167 }
2168
2169 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2170 iov_base = silo_.get();
2171 assert(iov_len == 0);
2172 }
2173
2174 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2175 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2176 iov_base = memcpy(silo_.get(), src.data(), iov_len = src.length());
2177 }
2178
2179 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2180
2181 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2182 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2183 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2184 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2185 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2186 * 11th). */
2187 /* coverity[use_after_move] */
2188 fixup_import(src.silo_.bin_);
2189 src.invalidate();
2190 }
2191
2193 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2194
2197
2198 template <typename POD>
2199 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2200 return buffer(inherited::wrap(pod), make_reference, alloc);
2201 }
2202
2204 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2205 const allocator_type &alloc = allocator_type()) {
2206 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2207 }
2208
2211 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2212 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2213 }
2214
2216 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2217 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2218 }
2219
2221 template <typename POD>
2222 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2223 const allocator_type &alloc = allocator_type()) {
2224 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2225 }
2226
2229 template <typename POD>
2230 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2231 return base58(inherited::wrap(pod), wrap_width, alloc);
2232 }
2233
2236 template <typename POD>
2237 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2238 return base64(inherited::wrap(pod), wrap_width, alloc);
2239 }
2240
2242 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2243 const allocator_type &alloc = allocator_type()) const {
2244 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2245 }
2246
2249 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2250 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2251 }
2252
2254 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2255 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2256 }
2257
2259 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2260 const allocator_type &alloc = allocator_type()) {
2261 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2262 }
2263
2266 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2267 const allocator_type &alloc = allocator_type()) {
2268 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2269 }
2270
2273 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2274 const allocator_type &alloc = allocator_type()) {
2275 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2276 }
2277
2280 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2281 return hex_decode(*this, ignore_spaces, alloc);
2282 }
2283
2286 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2287 return base58_decode(*this, ignore_spaces, alloc);
2288 }
2289
2292 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2293 return base64_decode(*this, ignore_spaces, alloc);
2294 }
2295
2297 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2298 wanna_headroom = ::std::min(
2299 ::std::max(headroom(), wanna_headroom),
2300 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2301 wanna_tailroom = ::std::min(
2302 ::std::max(tailroom(), wanna_tailroom),
2303 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2304 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2305 silo_.resize(wanna_capacity, wanna_headroom, *this);
2306 assert(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2307 assert(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2308 }
2309
2311 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2312
2314 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2315
2316 buffer &assign_reference(const void *ptr, size_t bytes) {
2317 silo_.clear();
2319 return *this;
2320 }
2321
2322 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2323 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2324 return *this;
2325 }
2326
2327 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2328 const auto pair = silo::exchange(silo_, is_reference(), other.silo_, other.is_reference());
2329 std::swap(iov_base, other.iov_base);
2330 std::swap(iov_len, other.iov_len);
2331 if (pair.first)
2332 fixup_import(other.silo_.bin_);
2333 if (pair.second)
2334 other.fixup_import(silo_.bin_);
2335 }
2336
2337 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2338 left.swap(right);
2339 }
2340
2341 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2342 return buffer(src.headroom(), src, src.tailroom(), alloc);
2343 }
2344
2346 return buffer(slice(), !is_inplace(), allocator_traits::select_on_container_copy_construction(get_allocator()));
2347 }
2348
2350 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2351 invalidate();
2352 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2353 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2354 MDBX_CXX20_UNLIKELY {
2355 silo_.release();
2357 }
2358 }
2359
2360 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2361 iov_len = src.length();
2362 return *this;
2363 }
2364
2365 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2366 invalidate();
2367 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2368 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2369 MDBX_CXX20_UNLIKELY {
2370 silo_.release();
2372 }
2373 }
2374
2375 if (make_reference) {
2376 silo_.release();
2377 iov_base = src.iov_base;
2378 } else {
2379 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2380 }
2381 iov_len = src.length();
2382 return *this;
2383 }
2384
2387 const bool is_reference = src.is_reference();
2388 inherited::assign(std::move(src));
2389 if (silo_.assign_move(std::move(src.silo_), is_reference))
2390 fixup_import(src.silo_.bin_);
2391 return *this;
2392 }
2393
2394 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2395 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2396 }
2397
2398 buffer &assign(const struct slice &src, bool make_reference = false) {
2399 return assign(src.data(), src.length(), make_reference);
2400 }
2401
2402 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2403 return assign(src.iov_base, src.iov_len, make_reference);
2404 }
2405
2406 buffer &assign(struct slice &&src, bool make_reference = false) {
2407 assign(src.data(), src.length(), make_reference);
2408 src.invalidate();
2409 return *this;
2410 }
2411
2412 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2413 assign(src.iov_base, src.iov_len, make_reference);
2414 src.iov_base = nullptr;
2415 return *this;
2416 }
2417
2418 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2419 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2420 }
2421
2422 template <class CHAR, class T, class A>
2423 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2424 return assign(str.data(), str.length(), make_reference);
2425 }
2426
2427 buffer &assign(const char *c_str, bool make_reference = false) {
2428 return assign(c_str, strlen(c_str), make_reference);
2429 }
2430
2431#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2432 template <class CHAR, class T>
2433 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2434 return assign(view.data(), view.length(), make_reference);
2435 }
2436
2437 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2438 assign(view.data(), view.length(), make_reference);
2439 view = {};
2440 return *this;
2441 }
2442#endif /* __cpp_lib_string_view >= 201606L */
2443
2444 buffer &operator=(const buffer &src) { return assign(src); }
2445
2446 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2447
2448 buffer &operator=(const struct slice &src) { return assign(src); }
2449
2450 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2451
2452#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2453 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2454 return assign(view.begin(), view.length());
2455 }
2456#endif /* __cpp_lib_string_view >= 201606L */
2457
2458 template <class CHAR, class T, class A>
2459 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2460 return as_string<CHAR, T, A>();
2461 }
2462
2464 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2465
2467 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2468 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2469 }
2470
2472 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2473
2474 buffer &append(const void *src, size_t bytes) {
2475 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2476 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2477 memcpy(end_byte_ptr(), src, bytes);
2478 iov_len += bytes;
2479 return *this;
2480 }
2481
2482 buffer &append(const byte c) {
2483 if (MDBX_UNLIKELY(tailroom() < 1))
2484 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2485 *end_byte_ptr() = c;
2486 iov_len += 1;
2487 return *this;
2488 }
2489
2490 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2491
2492 buffer &add_header(const void *src, size_t bytes) {
2493 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2494 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2495 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2496 iov_len += bytes;
2497 return *this;
2498 }
2499
2500 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2501
2502 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2503 const size_t wanna_bytes = producer.envisage_result_length();
2504 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2505 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2506 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2507 }
2508
2509 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2510 const size_t wanna_bytes = producer.envisage_result_length();
2511 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2512 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2513 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2514 }
2515
2516 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2517 return append_producer(to_hex(data, uppercase, wrap_width));
2518 }
2519
2520 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2521 return append_producer(to_base58(data, wrap_width));
2522 }
2523
2524 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2525 return append_producer(to_base64(data, wrap_width));
2526 }
2527
2528 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2529 return append_producer(from_hex(data, ignore_spaces));
2530 }
2531
2532 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2533 return append_producer(from_base58(data, ignore_spaces));
2534 }
2535
2536 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2537 return append_producer(from_base64(data, ignore_spaces));
2538 }
2539
2540 buffer &append_u8(uint_fast8_t u8) {
2541 if (MDBX_UNLIKELY(tailroom() < 1))
2542 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2543 *end_byte_ptr() = uint8_t(u8);
2544 iov_len += 1;
2545 return *this;
2546 }
2547
2548 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2549
2550 buffer &append_u16(uint_fast16_t u16) {
2551 if (MDBX_UNLIKELY(tailroom() < 2))
2552 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2553 const auto ptr = end_byte_ptr();
2554 ptr[0] = uint8_t(u16);
2555 ptr[1] = uint8_t(u16 >> 8);
2556 iov_len += 2;
2557 return *this;
2558 }
2559
2560 buffer &append_u24(uint_fast32_t u24) {
2561 if (MDBX_UNLIKELY(tailroom() < 3))
2562 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2563 const auto ptr = end_byte_ptr();
2564 ptr[0] = uint8_t(u24);
2565 ptr[1] = uint8_t(u24 >> 8);
2566 ptr[2] = uint8_t(u24 >> 16);
2567 iov_len += 3;
2568 return *this;
2569 }
2570
2571 buffer &append_u32(uint_fast32_t u32) {
2572 if (MDBX_UNLIKELY(tailroom() < 4))
2573 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2574 const auto ptr = end_byte_ptr();
2575 ptr[0] = uint8_t(u32);
2576 ptr[1] = uint8_t(u32 >> 8);
2577 ptr[2] = uint8_t(u32 >> 16);
2578 ptr[3] = uint8_t(u32 >> 24);
2579 iov_len += 4;
2580 return *this;
2581 }
2582
2583 buffer &append_u48(uint_fast64_t u48) {
2584 if (MDBX_UNLIKELY(tailroom() < 6))
2585 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2586 const auto ptr = end_byte_ptr();
2587 ptr[0] = uint8_t(u48);
2588 ptr[1] = uint8_t(u48 >> 8);
2589 ptr[2] = uint8_t(u48 >> 16);
2590 ptr[3] = uint8_t(u48 >> 24);
2591 ptr[4] = uint8_t(u48 >> 32);
2592 ptr[5] = uint8_t(u48 >> 40);
2593 iov_len += 6;
2594 return *this;
2595 }
2596
2597 buffer &append_u64(uint_fast64_t u64) {
2598 if (MDBX_UNLIKELY(tailroom() < 8))
2599 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2600 const auto ptr = end_byte_ptr();
2601 ptr[0] = uint8_t(u64);
2602 ptr[1] = uint8_t(u64 >> 8);
2603 ptr[2] = uint8_t(u64 >> 16);
2604 ptr[3] = uint8_t(u64 >> 24);
2605 ptr[4] = uint8_t(u64 >> 32);
2606 ptr[5] = uint8_t(u64 >> 40);
2607 ptr[6] = uint8_t(u64 >> 48);
2608 ptr[7] = uint8_t(u64 >> 56);
2609 iov_len += 8;
2610 return *this;
2611 }
2612
2613 //----------------------------------------------------------------------------
2614
2615 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2616 return buffer(inherited(text), make_reference);
2617 }
2618
2619#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2620 template <class CHAR, class T>
2621 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2622 return buffer(src, make_reference);
2623 }
2624#endif /* __cpp_lib_string_view >= 201606L */
2625
2626 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2627
2628 template <class CHAR, class T, class A>
2629 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2630 return buffer(src, make_reference);
2631 }
2632
2633 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2634
2635 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2636
2637 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2638
2639 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2640
2641 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2642
2643 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2644
2645 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2646
2647 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2648
2649 static buffer key_from_jsonInteger(const int64_t json_integer) {
2650 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2651 }
2652
2653 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2654
2655 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2656
2657 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2658
2659 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2660
2661 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2662
2663 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2664
2665 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2666
2667 const slice &slice() const noexcept { return *this; }
2668};
2669
2670template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2674 using reservation_policy = CAPACITY_POLICY;
2675 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2677
2680 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2681
2683 : key(key, alloc), value(value, alloc) {}
2684 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2685 const allocator_type &alloc = allocator_type())
2686 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2687
2689 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2690 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2691 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2692
2694 : key(key, alloc), value(value, alloc) {}
2695 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2696 const allocator_type &alloc = allocator_type())
2697 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2698
2701 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2702 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2703
2704 buffer_pair_spec(const txn &transacton, const slice &key, const slice &value,
2705 const allocator_type &alloc = allocator_type())
2706 : key(transacton, key, alloc), value(transacton, value, alloc) {}
2707 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2708 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2709
2710 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2711 : key(::std::move(key)), value(::std::move(value)) {}
2713 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2714 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2715
2718 key.assign(std::move(src.key));
2719 value.assign(std::move(src.value));
2720 return *this;
2721 }
2722
2724 key.assign(src.key);
2725 value.assign(src.value);
2726 return *this;
2727 }
2729 key.assign(std::move(src.key));
2730 value.assign(std::move(src.value));
2731 return *this;
2732 }
2734 key.assign(src.first);
2735 value.assign(src.second);
2736 return *this;
2737 }
2739 key.assign(std::move(src.first));
2740 value.assign(std::move(src.second));
2741 return *this;
2742 }
2743
2747 return key.is_freestanding() && value.is_freestanding();
2748 }
2749
2752 return key.is_reference() || value.is_reference();
2753 }
2754
2758 key.make_freestanding();
2759 value.make_freestanding();
2760 }
2761
2762 operator pair() const noexcept { return pair(key, value); }
2763};
2764
2766
2769public:
2770 cache_entry() noexcept { reset(); }
2771 cache_entry(const cache_entry &) noexcept = default;
2772 cache_entry &operator=(const cache_entry &) noexcept = default;
2773 cache_entry(cache_entry &&other) noexcept {
2774 *this = other;
2775 other.reset();
2776 }
2777 void reset() noexcept { mdbx_cache_init(this); }
2778};
2779
2780//------------------------------------------------------------------------------
2781
2784enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2785
2802
2804 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2805}
2806
2808 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2809}
2810
2812 return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
2813}
2814
2816 return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
2817}
2818
2820
2878
2882
2884 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2885}
2886
2888 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2889}
2890
2892 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2893}
2894
2896 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2897}
2898
2900
2911 map_handle(const map_handle &) noexcept = default;
2912 map_handle &operator=(const map_handle &) noexcept = default;
2913 operator bool() const noexcept { return dbi != 0; }
2914 operator MDBX_dbi() const { return dbi; }
2915
2916#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2917 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2918 return a.dbi <=> b.dbi;
2919 }
2920#endif /* __cpp_impl_three_way_comparison */
2921 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2922 return a.dbi == b.dbi;
2923 }
2924 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2925 return a.dbi < b.dbi;
2926 }
2927 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2928 return a.dbi > b.dbi;
2929 }
2930 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2931 return a.dbi <= b.dbi;
2932 }
2933 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2934 return a.dbi >= b.dbi;
2935 }
2936 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2937 return a.dbi != b.dbi;
2938 }
2939
2951};
2952
2955 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2956}
2958 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2959}
2960
2967
2976 friend class txn;
2977
2978protected:
2980 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2981
2982public:
2983 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2984 env(const env &) noexcept = default;
2985 env &operator=(const env &) noexcept = default;
2986 inline env &operator=(env &&) noexcept;
2987 inline env(env &&) noexcept;
2988 inline ~env() noexcept;
2989
2990 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
2991 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
2992 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
2993 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
2994 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
2995
2996 //----------------------------------------------------------------------------
2997
3002
3004 enum : intptr_t {
3007 maximal_value = INTPTR_MAX,
3008 kB = 1000,
3009 MB = kB * 1000,
3010 GB = MB * 1000,
3011#if INTPTR_MAX > 0x7fffFFFFl
3012 TB = GB * 1000,
3013 PB = TB * 1000,
3014 EB = PB * 1000,
3015#endif /* 64-bit intptr_t */
3016 KiB = 1024,
3017 MiB = KiB << 10,
3018 GiB = MiB << 10,
3019#if INTPTR_MAX > 0x7fffFFFFl
3020 TiB = GiB << 10,
3021 PiB = TiB << 10,
3022 EiB = PiB << 10,
3023#endif /* 64-bit intptr_t */
3024 };
3025
3027 struct size {
3028 intptr_t bytes;
3029 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3030 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3031 };
3032
3035
3040
3052
3055
3058
3064
3065 inline geometry &make_fixed(intptr_t size) noexcept;
3066 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3069 geometry(const geometry &) noexcept = default;
3075 };
3076
3084
3092
3105
3127
3132 unsigned max_maps{0};
3135 unsigned max_readers{0};
3140
3151 operate_parameters(const operate_parameters &) noexcept = default;
3153 MDBX_env_flags_t make_flags(bool accede = true,
3156 bool use_subdirectory = false
3157 ) const;
3161 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3162 };
3163
3167 inline env::mode get_mode() const;
3169 inline env::durability get_durability() const;
3173 inline env::operate_options get_options() const;
3174
3177 bool is_pristine() const;
3178
3180 bool is_empty() const;
3181
3183 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3184
3185 struct limits {
3186 limits() = delete;
3188 static inline size_t pagesize_min() noexcept;
3190 static inline size_t pagesize_max() noexcept;
3192 static inline size_t dbsize_min(intptr_t pagesize);
3194 static inline size_t dbsize_max(intptr_t pagesize);
3196 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3198 static inline size_t key_min(key_mode mode) noexcept;
3200 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3202 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3204 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3206 static inline size_t key_max(const env &, key_mode mode);
3208 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3210 static inline size_t value_min(value_mode) noexcept;
3211
3213 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3215 static inline size_t value_max(intptr_t pagesize, value_mode);
3217 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3219 static inline size_t value_max(const env &, value_mode);
3220
3223 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3226 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3229 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3232 static inline size_t pairsize4page_max(const env &, value_mode);
3233
3236 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3239 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3242 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3245 static inline size_t valsize4page_max(const env &, value_mode);
3246
3249 static inline size_t transaction_size_max(intptr_t pagesize);
3250
3252 static inline size_t max_map_handles(void);
3253 };
3254
3256 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3258 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3260 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3262 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3264 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3266 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3270
3273#ifdef MDBX_STD_FILESYSTEM_PATH
3274 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3275#endif /* MDBX_STD_FILESYSTEM_PATH */
3276#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3277 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3278 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3279#endif /* Windows */
3280 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3281 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3282
3284 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3285
3301
3303#ifdef MDBX_STD_FILESYSTEM_PATH
3304 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3305#endif /* MDBX_STD_FILESYSTEM_PATH */
3306#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3307 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3308 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3309#endif /* Windows */
3310 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3311 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3312
3315
3318
3320 inline stat get_stat() const;
3321
3323 size_t get_pagesize() const { return get_stat().ms_psize; }
3324
3326 inline info get_info() const;
3327
3329 inline stat get_stat(const txn &) const;
3330
3332 inline info get_info(const txn &) const;
3333
3335 inline filehandle get_filehandle() const;
3336
3338 const path_char *get_path() const;
3339
3341 inline MDBX_env_flags_t get_flags() const;
3342
3343 inline bool is_readonly() const { return (get_flags() & MDBX_RDONLY) != 0; }
3344
3345 inline bool is_exclusive() const { return (get_flags() & MDBX_EXCLUSIVE) != 0; }
3346
3347 inline bool is_cooperative() const { return !is_exclusive(); }
3348
3349 inline bool is_writemap() const { return (get_flags() & MDBX_WRITEMAP) != 0; }
3350
3351 inline bool is_readwite() const { return !is_readonly(); }
3352
3353 inline bool is_nested_transactions_available() const { return (get_flags() & (MDBX_WRITEMAP | MDBX_RDONLY)) == 0; }
3354
3357 inline unsigned max_readers() const;
3358
3361 inline unsigned max_maps() const;
3362
3364 inline void *get_context() const noexcept;
3365
3367 inline env &set_context(void *your_context);
3368
3383 inline env &set_sync_threshold(size_t bytes);
3384
3390 inline size_t sync_threshold() const;
3391
3392#if __cplusplus >= 201103L || defined(DOXYGEN)
3412 inline env &set_sync_period(const duration &period);
3413
3419 inline duration sync_period() const;
3420#endif
3421
3425 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3426
3429 inline unsigned sync_period__seconds_16dot16() const;
3430
3434 inline env &set_sync_period__seconds_double(double seconds);
3435
3438 inline double sync_period__seconds_double() const;
3439
3491
3493 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3494
3496 inline uint64_t extra_option(extra_runtime_option option) const;
3497
3499 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3500
3502 inline env &set_geometry(const geometry &size);
3503
3507 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3508
3512 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3513
3532 inline void close_map(const map_handle &);
3533
3536 int slot;
3545 size_t bytes_used;
3554
3556 size_t used, size_t retained) noexcept;
3557 };
3558
3566 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3567
3570 inline unsigned check_readers();
3571
3590
3595 inline MDBX_hsr_func get_HandleSlowReaders() const noexcept;
3596
3598 inline txn_managed start_read() const;
3599
3601 inline txn_managed prepare_read() const;
3602
3604 inline txn_managed start_write(txn &parent);
3605
3607 inline txn_managed start_write(bool dont_wait = false);
3608
3611};
3612
3621class LIBMDBX_API_TYPE env_managed : public env {
3622 using inherited = env;
3624 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3625 void setup(unsigned max_maps, unsigned max_readers = 0);
3626
3627public:
3628 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3629
3631#ifdef MDBX_STD_FILESYSTEM_PATH
3632 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3633#endif /* MDBX_STD_FILESYSTEM_PATH */
3634#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3635 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3636 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3637#endif /* Windows */
3638 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3639 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3640
3651
3653#ifdef MDBX_STD_FILESYSTEM_PATH
3655 bool accede = true);
3656#endif /* MDBX_STD_FILESYSTEM_PATH */
3657#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3658 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3659 bool accede = true);
3660 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3661 bool accede = true);
3662#endif /* Windows */
3663 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3664 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3665
3679 void close(bool dont_sync = false);
3680
3681 env_managed(env_managed &&) = default;
3682 env_managed &operator=(env_managed &&other) noexcept {
3684 MDBX_CXX20_UNLIKELY {
3685 assert(handle_ != other.handle_);
3686 close();
3687 }
3688 inherited::operator=(std::move(other));
3689 return *this;
3690 }
3691 env_managed(const env_managed &) = delete;
3692 env_managed &operator=(const env_managed &) = delete;
3693 virtual ~env_managed() noexcept;
3694};
3695
3704protected:
3705 friend class cursor;
3707 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3708
3709public:
3710 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3711 txn(const txn &) noexcept = default;
3712 txn &operator=(const txn &) noexcept = default;
3713 inline txn &operator=(txn &&) noexcept;
3714 inline txn(txn &&) noexcept;
3715 inline ~txn() noexcept;
3716
3717 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3718 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3719 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3720 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3721 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3722
3724 inline ::mdbx::env env() const noexcept;
3726 inline MDBX_txn_flags_t flags() const;
3728 inline uint64_t id() const;
3729
3731 inline void *get_context() const noexcept;
3732
3734 inline txn &set_context(void *your_context);
3735
3737 inline bool is_dirty(const void *ptr) const;
3738
3740 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3741
3743 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3744
3746 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3747
3750 inline info get_info(bool scan_reader_lock_table = false) const;
3751
3754 size_t size_max() const { return env().transaction_size_max(); }
3755
3757 size_t size_current() const {
3758 assert(is_readwrite());
3759 return size_t(get_info().txn_space_dirty);
3760 }
3761
3762 //----------------------------------------------------------------------------
3763
3765 inline void reset_reading();
3766
3768 inline void renew_reading();
3769
3771 inline txn_managed clone(void *context = nullptr) const;
3772
3774 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
3775
3777 inline void make_broken();
3778
3780 inline void park_reading(bool autounpark = true);
3781
3784 inline bool unpark_reading(bool restart_if_ousted = true);
3785
3788
3791
3793 inline cursor_managed open_cursor(map_handle map) const;
3794
3796 inline size_t release_all_cursors(bool unbind) const;
3797
3799 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3800
3802 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3803
3805 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3806 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3808 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3809 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3811 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3812 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3813
3815 inline map_handle open_map_accede(const char *name) const;
3817 inline map_handle open_map_accede(const ::std::string &name) const;
3819 inline map_handle open_map_accede(const slice &name) const;
3820
3822 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3823 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3825 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3826 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3828 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3829 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3830
3832 inline void drop_map(map_handle map);
3836 bool drop_map(const char *name, bool throw_if_absent = false);
3840 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3844 bool drop_map(const slice &name, bool throw_if_absent = false);
3845
3847 inline void clear_map(map_handle map);
3850 bool clear_map(const char *name, bool throw_if_absent = false);
3853 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3856 bool clear_map(const slice &name, bool throw_if_absent = false);
3857
3859 inline void rename_map(map_handle map, const char *new_name);
3861 inline void rename_map(map_handle map, const ::std::string &new_name);
3863 inline void rename_map(map_handle map, const slice &new_name);
3867 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3871 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3875 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3876
3877#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3878
3880 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3881 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3882 return open_map(slice(name), key_mode, value_mode);
3883 }
3884
3885 inline map_handle open_map_accede(const ::std::string_view &name) const;
3887 inline map_handle create_map(const ::std::string_view &name,
3888 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3889 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3890 return create_map(slice(name), key_mode, value_mode);
3891 }
3892
3895 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3896 return drop_map(slice(name), throw_if_absent);
3897 }
3898
3900 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3901 return clear_map(slice(name), throw_if_absent);
3902 }
3903
3904 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3908 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3909 bool throw_if_absent = false) {
3910 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3911 }
3912#endif /* __cpp_lib_string_view >= 201606L */
3913
3916 inline map_stat get_map_stat(map_handle map) const;
3919 inline uint32_t get_tree_deepmask(map_handle map) const;
3921 inline map_handle::info get_map_flags(map_handle map) const;
3922
3925 inline txn &put_canary(const canary &);
3927 inline canary get_canary() const;
3928
3930 inline uint64_t sequence(map_handle map) const;
3932 inline uint64_t sequence(map_handle map, uint64_t increment);
3933
3935 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3937 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3939 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3941 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3942
3944 inline slice get(map_handle map, const slice &key) const;
3946 inline slice get(map_handle map, slice key, size_t &values_count) const;
3948 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3950 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3954 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3958 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3959
3960 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3961 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3962 inline void insert(map_handle map, const slice &key, slice value);
3963 inline value_result try_insert(map_handle map, const slice &key, slice value);
3964 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3965 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3966
3967 inline void upsert(map_handle map, const slice &key, const slice &value);
3968 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3969
3970 inline void update(map_handle map, const slice &key, const slice &value);
3971 inline bool try_update(map_handle map, const slice &key, const slice &value);
3972 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3973 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3974
3975 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3976 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3977 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3978 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3979
3981 inline bool erase(map_handle map, const slice &key);
3982
3984 inline bool erase(map_handle map, const slice &key, const slice &value);
3985
3987 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3988
3990 template <class ALLOCATOR, typename CAPACITY_POLICY>
3992 extract(map_handle map, const slice &key,
3995
3997 template <class ALLOCATOR, typename CAPACITY_POLICY>
3999 replace(map_handle map, const slice &key, const slice &new_value,
4002
4003 template <class ALLOCATOR, typename CAPACITY_POLICY>
4005 replace_reserve(map_handle map, const slice &key, slice &new_value,
4008
4025 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4026 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4027 return append(map, kv.key, kv.value, multivalue_order_preserved);
4028 }
4029
4030 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4031 const void *values_array, size_t values_count, put_mode mode,
4032 bool allow_partial = false);
4033 template <typename VALUE>
4034 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4035 put_mode mode, bool allow_partial = false) {
4036 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4037 !::std::is_array<VALUE>::value,
4038 "Must be a standard layout type!");
4039 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4040 }
4041 template <typename VALUE>
4042 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4043 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4044 }
4045
4046 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4047 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4048 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4049 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4050};
4051
4060class LIBMDBX_API_TYPE txn_managed : public txn {
4061 using inherited = txn;
4062 friend class env;
4063 friend class txn;
4065 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4066
4067public:
4068 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4069 txn_managed(txn_managed &&) = default;
4070 txn_managed &operator=(txn_managed &&other) noexcept {
4072 MDBX_CXX20_UNLIKELY {
4073 assert(handle_ != other.handle_);
4074 abort();
4075 }
4076 inherited::operator=(std::move(other));
4077 return *this;
4078 }
4079 txn_managed(const txn_managed &) = delete;
4080 txn_managed &operator=(const txn_managed &) = delete;
4081 ~txn_managed() noexcept;
4082
4083 //----------------------------------------------------------------------------
4085
4087 void abort();
4091 void abort(finalization_latency &latency) { return abort(&latency); }
4095 finalization_latency result;
4096 abort(&result);
4097 return result;
4098 }
4099
4101 void commit();
4105 void commit(finalization_latency &latency) { return commit(&latency); }
4109 finalization_latency result;
4110 commit(&result);
4111 return result;
4112 }
4113
4119 bool checkpoint(finalization_latency &latency) { return checkpoint(&latency); }
4122 std::pair<bool, finalization_latency> checkpoint_get_latency() {
4123 finalization_latency latency;
4124 bool result = checkpoint(&latency);
4125 return std::make_pair(result, latency);
4126 }
4127
4137 finalization_latency result;
4138 commit_embark_read(&result);
4139 return result;
4140 }
4141
4144 bool amend(bool dont_wait = false);
4145};
4146
4154protected:
4156
4157public:
4159 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4160 cursor(const cursor &) noexcept = default;
4161 cursor &operator=(const cursor &) noexcept = default;
4162 inline cursor &operator=(cursor &&) noexcept;
4163 inline cursor(cursor &&) noexcept;
4164 inline ~cursor() noexcept;
4165 inline cursor_managed clone(void *your_context = nullptr) const;
4166 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4167 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4168 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4169 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4170 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4171
4172 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4173 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4174
4175 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4176 return compare_position(*this, other, ignore_nested) < 0;
4177 }
4178
4179 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4180 return compare_position(*this, other, ignore_nested) <= 0;
4181 }
4182
4183 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4184 return compare_position(*this, other, ignore_nested) == 0;
4185 }
4186
4187 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4188 return compare_position(*this, other, ignore_nested) > 0;
4189 }
4190
4191 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4192 return compare_position(*this, other, ignore_nested) >= 0;
4193 }
4194
4196 inline void *get_context() const noexcept;
4197
4199 inline cursor &set_context(void *your_context);
4200
4207
4214
4217
4221
4222 /* Doubtless cursor positioning at a specified key. */
4228
4229 /* Doubtless cursor positioning at a specified key-value pair
4230 * for dupsort/multi-value hives. */
4236
4243
4248 };
4249
4250 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4251 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4252 // и других параметров в bool-throw_notfound.
4253
4254 struct move_result : public pair_result {
4255 inline move_result(const cursor &cursor, bool throw_notfound);
4256 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4257 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4258 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4259 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4260 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4261 bool throw_notfound);
4262 move_result(const move_result &) noexcept = default;
4263 move_result &operator=(const move_result &) noexcept = default;
4264 };
4265
4266 struct estimate_result : public pair {
4271 : estimate_result(cursor, operation, key, slice::invalid()) {}
4272 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4273 estimate_result(const estimate_result &) noexcept = default;
4274 estimate_result &operator=(const estimate_result &) noexcept = default;
4275 };
4276
4277protected:
4278 /* fake `const`, but for specific move/get operations */
4279 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4280
4281 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4282
4283public:
4284 template <typename CALLABLE_PREDICATE>
4285 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4286 struct wrapper : public exception_thunk {
4287 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4288 auto thunk = static_cast<wrapper *>(context);
4289 assert(thunk->is_clean());
4290 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4291 try {
4292 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4293 } catch (... /* capture any exception to rethrow it over C code */) {
4294 thunk->capture();
4295 return MDBX_RESULT_TRUE;
4296 }
4297 }
4298 } thunk;
4300 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4301 thunk);
4302 }
4303
4304 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4305 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4306 }
4307
4308 template <typename CALLABLE_PREDICATE>
4309 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4310 move_operation turn = next) {
4311 struct wrapper : public exception_thunk {
4312 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4313 auto thunk = static_cast<wrapper *>(context);
4314 assert(thunk->is_clean());
4315 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4316 try {
4317 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4318 } catch (... /* capture any exception to rethrow it over C code */) {
4319 thunk->capture();
4320 return MDBX_RESULT_TRUE;
4321 }
4322 }
4323 } thunk;
4324 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4325 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4326 thunk);
4327 }
4328
4329 template <typename CALLABLE_PREDICATE>
4330 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4331 move_operation turn = next) {
4332 struct wrapper : public exception_thunk {
4333 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4334 auto thunk = static_cast<wrapper *>(context);
4335 assert(thunk->is_clean());
4336 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4337 try {
4338 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4339 } catch (... /* capture any exception to rethrow it over C code */) {
4340 thunk->capture();
4341 return MDBX_RESULT_TRUE;
4342 }
4343 }
4344 } thunk;
4345 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4346 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4347 thunk);
4348 }
4349
4350 move_result move(move_operation operation, bool throw_notfound) {
4351 return move_result(*this, operation, throw_notfound);
4352 }
4353 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4354 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4355 }
4356 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4357 return move_result(*this, operation, key, value, throw_notfound);
4358 }
4359 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4360 return move(operation, &key, &value, throw_notfound);
4361 }
4362
4363 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4364 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4365 move_result to_previous_last_multi(bool throw_notfound = true) {
4366 return move(multi_prevkey_lastvalue, throw_notfound);
4367 }
4368 move_result to_current_first_multi(bool throw_notfound = true) {
4369 return move(multi_currentkey_firstvalue, throw_notfound);
4370 }
4371 move_result to_current_prev_multi(bool throw_notfound = true) {
4372 return move(multi_currentkey_prevvalue, throw_notfound);
4373 }
4374 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4375 move_result to_current_next_multi(bool throw_notfound = true) {
4376 return move(multi_currentkey_nextvalue, throw_notfound);
4377 }
4378 move_result to_current_last_multi(bool throw_notfound = true) {
4379 return move(multi_currentkey_lastvalue, throw_notfound);
4380 }
4381 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4382 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4383 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4384
4385 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4386 return move(key_lesser_than, key, throw_notfound);
4387 }
4388 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4389 return move(key_lesser_or_equal, key, throw_notfound);
4390 }
4391 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4392 return move(key_equal, key, throw_notfound);
4393 }
4394 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4395 return move(key_exact, key, throw_notfound);
4396 }
4397 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4398 return move(key_greater_or_equal, key, throw_notfound);
4399 }
4400 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4401 return move(key_greater_than, key, throw_notfound);
4402 }
4403
4404 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4405 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4406 }
4407 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4408 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4409 }
4410 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4411 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4412 }
4413 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4414 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4415 }
4416 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4417 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4418 }
4419
4420 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4421 return move(pair_lesser_than, key, value, throw_notfound);
4422 }
4423 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4424 return move(pair_lesser_or_equal, key, value, throw_notfound);
4425 }
4426 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4427 return move(pair_equal, key, value, throw_notfound);
4428 }
4429 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4430 return move(pair_exact, key, value, throw_notfound);
4431 }
4432 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4433 return move(pair_greater_or_equal, key, value, throw_notfound);
4434 }
4435 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4436 return move(pair_greater_than, key, value, throw_notfound);
4437 }
4438
4439 inline bool seek(const slice &key);
4440 inline move_result find(const slice &key, bool throw_notfound = true);
4441 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4442 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4443
4445 inline size_t count_multivalue() const;
4446
4447 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4448 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4449 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4450
4451 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4452 return move(seek_and_batch_samelength, key, throw_notfound);
4453 }
4454
4455 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4456 return move(batch_samelength, throw_notfound);
4457 }
4458
4459 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4460 return move(batch_samelength_next, throw_notfound);
4461 }
4462
4463 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4464 return move(batch_samelength_previous, throw_notfound);
4465 }
4466
4467 inline bool eof() const;
4468 inline bool on_first() const;
4469 inline bool on_last() const;
4470 inline bool on_first_multival() const;
4471 inline bool on_last_multival() const;
4472 inline estimate_result estimate(const slice &key, const slice &value) const;
4473 inline estimate_result estimate(const slice &key) const;
4474 inline estimate_result estimate(move_operation operation) const;
4475 inline estimate_result estimate(move_operation operation, slice &key) const;
4476
4477 //----------------------------------------------------------------------------
4478
4480 inline void renew(::mdbx::txn &txn);
4481
4484
4486 inline void unbind();
4487
4489 inline ::mdbx::txn txn() const;
4490 inline map_handle map() const;
4491
4492 inline operator ::mdbx::txn() const { return txn(); }
4493 inline operator ::mdbx::map_handle() const { return map(); }
4494
4495 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4496 inline void put(const slice &key, slice value, put_mode mode);
4497 inline void insert(const slice &key, slice value);
4498 inline value_result try_insert(const slice &key, slice value);
4499 inline slice insert_reserve(const slice &key, size_t value_length);
4500 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4501
4502 inline void upsert(const slice &key, const slice &value);
4503 inline slice upsert_reserve(const slice &key, size_t value_length);
4504
4506 void update_current(const slice &value);
4508 slice reverse_current(size_t value_length);
4509
4510 inline void update(const slice &key, const slice &value);
4511 inline bool try_update(const slice &key, const slice &value);
4512 inline slice update_reserve(const slice &key, size_t value_length);
4513 inline value_result try_update_reserve(const slice &key, size_t value_length);
4514
4515 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4516 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4517 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4518 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4519
4521 inline bool erase(bool whole_multivalue = false);
4522
4525 inline bool erase(const slice &key, bool whole_multivalue = true);
4526
4529 inline bool erase(const slice &key, const slice &value);
4530
4531 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4532 size_t values_count, put_mode mode, bool allow_partial = false);
4533 template <typename VALUE>
4534 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4535 bool allow_partial = false) {
4536 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4537 !::std::is_array<VALUE>::value,
4538 "Must be a standard layout type!");
4539 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4540 }
4541 template <typename VALUE>
4542 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4543 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4544 }
4545};
4546
4554class LIBMDBX_API_TYPE cursor_managed : public cursor {
4555 using inherited = cursor;
4556 friend class txn;
4558 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4559
4560public:
4562 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4563 if (MDBX_UNLIKELY(!handle_))
4564 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4565 }
4566
4568 inline void close() {
4570 handle_ = nullptr;
4571 }
4572
4573 cursor_managed(cursor_managed &&) = default;
4574 cursor_managed &operator=(cursor_managed &&other) noexcept {
4576 MDBX_CXX20_UNLIKELY {
4577 assert(handle_ != other.handle_);
4578 close();
4579 }
4580 inherited::operator=(std::move(other));
4581 return *this;
4582 }
4583
4584 inline MDBX_cursor *withdraw_handle() noexcept {
4585 MDBX_cursor *handle = handle_;
4586 handle_ = nullptr;
4587 return handle;
4588 }
4589
4590 cursor_managed(const cursor_managed &) = delete;
4591 cursor_managed &operator=(const cursor_managed &) = delete;
4593};
4594
4595//==============================================================================
4596//
4597// Inline body of the libmdbx C++ API
4598//
4599
4600MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4601MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4602
4603static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4604#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4605 if (::std::is_constant_evaluated()) {
4606 for (size_t i = 0; c_str; ++i)
4607 if (!c_str[i])
4608 return i;
4609 return 0;
4610 }
4611#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4612#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4613 return c_str ? ::std::string_view(c_str).length() : 0;
4614#else
4615 return c_str ? ::std::strlen(c_str) : 0;
4616#endif
4617}
4618
4619MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4620#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4621 if (::std::is_constant_evaluated()) {
4622 for (size_t i = 0; i < bytes; ++i)
4623 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4624 return dest;
4625 } else
4626#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4627 return ::std::memcpy(dest, src, bytes);
4628}
4629
4630static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4631#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4632 if (::std::is_constant_evaluated()) {
4633 for (size_t i = 0; i < bytes; ++i) {
4634 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4635 if (diff)
4636 return diff;
4637 }
4638 return 0;
4639 } else
4640#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4641 return ::std::memcmp(a, b, bytes);
4642}
4643
4644//------------------------------------------------------------------------------
4645
4648
4652
4656
4657inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4658
4659inline void exception_thunk::capture() noexcept {
4660 assert(is_clean());
4661 captured_ = ::std::current_exception();
4662}
4663
4665 if (captured_)
4666 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4667}
4668
4669//------------------------------------------------------------------------------
4670
4671MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4672
4673inline error &error::operator=(MDBX_error_t error_code) noexcept {
4674 code_ = error_code;
4675 return *this;
4676}
4677
4678MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4679
4680MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4681
4682MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4683
4684MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4685
4686MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4687
4689 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4690}
4691
4692MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4693
4698
4699inline void error::throw_exception(int error_code) {
4700 const error trouble(static_cast<MDBX_error_t>(error_code));
4701 trouble.throw_exception();
4702}
4703
4704inline void error::throw_on_failure() const {
4706 MDBX_CXX20_UNLIKELY throw_exception();
4707}
4708
4709inline void error::success_or_throw() const {
4710 if (MDBX_UNLIKELY(!is_success()))
4711 MDBX_CXX20_UNLIKELY throw_exception();
4712}
4713
4714inline void error::success_or_throw(const exception_thunk &thunk) const {
4715 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4716 if (MDBX_UNLIKELY(!is_success())) {
4717 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4718 else throw_exception();
4719 }
4720}
4721
4722inline void error::panic_on_failure(const char *context_where, const char *func_who) const noexcept {
4724 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4725}
4726
4727inline void error::success_or_panic(const char *context_where, const char *func_who) const noexcept {
4728 if (MDBX_UNLIKELY(!is_success()))
4729 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4730}
4731
4732inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4733 if (MDBX_UNLIKELY(ptr == nullptr))
4734 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4735}
4736
4737inline void error::throw_on_failure(int error_code) {
4738 error rc(static_cast<MDBX_error_t>(error_code));
4739 rc.throw_on_failure();
4740}
4741
4742inline void error::success_or_throw(MDBX_error_t error_code) {
4743 error rc(error_code);
4744 rc.success_or_throw();
4745}
4746
4747inline bool error::boolean_or_throw(int error_code) {
4748 switch (error_code) {
4749 case MDBX_RESULT_FALSE:
4750 return false;
4751 case MDBX_RESULT_TRUE:
4752 return true;
4753 default:
4754 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4755 }
4756}
4757
4758inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4759 error rc(static_cast<MDBX_error_t>(error_code));
4760 rc.success_or_throw(thunk);
4761}
4762
4763inline void error::panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept {
4764 error rc(static_cast<MDBX_error_t>(error_code));
4765 rc.panic_on_failure(context_where, func_who);
4766}
4767
4768inline void error::success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept {
4769 error rc(static_cast<MDBX_error_t>(error_code));
4770 rc.success_or_panic(context_where, func_who);
4771}
4772
4773inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4774 if (MDBX_UNLIKELY(!thunk.is_clean()))
4775 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4776 return boolean_or_throw(error_code);
4777}
4778
4779MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4780
4782 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4783
4784MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4785 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4786
4787MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4788
4789MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4790
4791MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4792
4793MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4794
4795inline slice &slice::assign(const void *ptr, size_t bytes) {
4796 iov_base = const_cast<void *>(ptr);
4797 iov_len = check_length(bytes);
4798 return *this;
4799}
4800
4801inline slice &slice::assign(const slice &src) noexcept {
4802 iov_base = src.iov_base;
4803 iov_len = src.iov_len;
4804 return *this;
4805}
4806
4807inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4808
4809slice &slice::assign(slice &&src) noexcept {
4810 assign(src);
4811 src.invalidate();
4812 return *this;
4813}
4814
4816 assign(src.iov_base, src.iov_len);
4817 src.iov_base = nullptr;
4818 return *this;
4819}
4820
4821inline slice &slice::assign(const void *begin, const void *end) {
4822 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4823}
4824
4825inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4826
4827inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4828
4829inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4830
4831MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4832
4833MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4834
4835MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4836
4838
4839MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4840
4841MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4842
4843MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4844
4846
4847MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4848
4849MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4850
4851MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4852
4853MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4854
4855MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4856
4858 iov_len = check_length(bytes);
4859 return *this;
4860}
4861
4863 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4864 return set_length(static_cast<const char *>(ptr) - char_ptr());
4865}
4866
4867MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4868
4869MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4870
4871MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4872
4873MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4874
4875MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4876
4878 iov_base = nullptr;
4879 iov_len = 0;
4880}
4881
4882inline void slice::remove_prefix(size_t n) noexcept {
4883 assert(n <= size());
4884 iov_base = static_cast<byte *>(iov_base) + n;
4885 iov_len -= n;
4886}
4887
4888inline void slice::safe_remove_prefix(size_t n) {
4889 if (MDBX_UNLIKELY(n > size()))
4890 MDBX_CXX20_UNLIKELY throw_out_range();
4891 remove_prefix(n);
4892}
4893
4894inline void slice::remove_suffix(size_t n) noexcept {
4895 assert(n <= size());
4896 iov_len -= n;
4897}
4898
4899inline void slice::safe_remove_suffix(size_t n) {
4900 if (MDBX_UNLIKELY(n > size()))
4901 MDBX_CXX20_UNLIKELY throw_out_range();
4902 remove_suffix(n);
4903}
4904
4905MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4906 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4907}
4908
4909MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4910 return length() >= suffix.length() &&
4911 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4912}
4913
4915 size_t h = length() * 3977471;
4916 for (size_t i = 0; i < length(); ++i)
4917 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4918 return h ^ 3863194411 * (h >> 11);
4919}
4920
4921MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4923 return byte_ptr()[n];
4924}
4925
4926MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4927 if (MDBX_UNLIKELY(n >= size()))
4928 MDBX_CXX20_UNLIKELY throw_out_range();
4929 return byte_ptr()[n];
4930}
4931
4932MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4934 return slice(data(), n);
4935}
4936
4937MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4939 return slice(char_ptr() + size() - n, n);
4940}
4941
4942MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4943 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4944 return slice(char_ptr() + from, n);
4945}
4946
4948 if (MDBX_UNLIKELY(n > size()))
4949 MDBX_CXX20_UNLIKELY throw_out_range();
4950 return head(n);
4951}
4952
4954 if (MDBX_UNLIKELY(n > size()))
4955 MDBX_CXX20_UNLIKELY throw_out_range();
4956 return tail(n);
4957}
4958
4959MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4960 if (MDBX_UNLIKELY(n > max_length))
4961 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4962 if (MDBX_UNLIKELY(from + n > size()))
4963 MDBX_CXX20_UNLIKELY throw_out_range();
4964 return middle(from, n);
4965}
4966
4967MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4968 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4969 return diff ? diff
4970 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4971 : memcmp(a.data(), b.data(), a.length());
4972}
4973
4975 const size_t shortest = ::std::min(a.length(), b.length());
4976 if (MDBX_LIKELY(shortest > 0))
4978 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4979 if (MDBX_LIKELY(diff != 0))
4980 MDBX_CXX20_LIKELY return diff;
4981 }
4982 return intptr_t(a.length()) - intptr_t(b.length());
4983}
4984
4986 return slice::compare_fast(a, b) == 0;
4987}
4988
4990 return slice::compare_lexicographically(a, b) < 0;
4991}
4992
4994 return slice::compare_lexicographically(a, b) > 0;
4995}
4996
4998 return slice::compare_lexicographically(a, b) <= 0;
4999}
5000
5002 return slice::compare_lexicographically(a, b) >= 0;
5003}
5004
5006 return slice::compare_fast(a, b) != 0;
5007}
5008
5009#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5010MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
5012}
5013#endif /* __cpp_impl_three_way_comparison */
5014
5015template <class ALLOCATOR, typename CAPACITY_POLICY>
5017 const allocator_type &alloc)
5018 : inherited(src), silo_(alloc) {
5019 if (!make_reference)
5020 insulate();
5021}
5022
5023template <class ALLOCATOR, typename CAPACITY_POLICY>
5024inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
5025 const allocator_type &alloc)
5026 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
5027
5028template <class ALLOCATOR, typename CAPACITY_POLICY>
5029inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
5030 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
5031}
5032
5033#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
5035
5036#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
5038#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
5039#endif /* !MinGW || MDBX_EXPORTS */
5040
5043
5044//------------------------------------------------------------------------------
5045
5046template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5047inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
5048 if (MDBX_LIKELY(!producer.is_empty()))
5050 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5051 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5052 return result;
5053 }
5055}
5056
5057template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5058inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
5059 if (MDBX_LIKELY(!producer.is_empty()))
5061 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5062 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5063 return result;
5064 }
5066}
5067
5068template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5069inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
5070 string<ALLOCATOR> result(alloc);
5071 if (MDBX_LIKELY(!producer.is_empty()))
5073 result.resize(producer.envisage_result_length());
5074 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5075 }
5076 return result;
5077}
5078
5079template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5080inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
5081 string<ALLOCATOR> result(alloc);
5082 if (MDBX_LIKELY(!producer.is_empty()))
5084 result.resize(producer.envisage_result_length());
5085 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5086 }
5087 return result;
5088}
5089
5090template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
5091 return make_string<ALLOCATOR>(*this, alloc);
5092}
5093
5094template <class ALLOCATOR, typename CAPACITY_POLICY>
5096 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5097}
5098
5099template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
5100 return make_string<ALLOCATOR>(*this, alloc);
5101}
5102
5103template <class ALLOCATOR, typename CAPACITY_POLICY>
5105 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5106}
5107
5108template <class ALLOCATOR> string<ALLOCATOR> to_base64::as_string(const ALLOCATOR &alloc) const {
5109 return make_string<ALLOCATOR>(*this, alloc);
5110}
5111
5112template <class ALLOCATOR, typename CAPACITY_POLICY>
5114 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5115}
5116
5117template <class ALLOCATOR> string<ALLOCATOR> from_hex::as_string(const ALLOCATOR &alloc) const {
5118 return make_string<ALLOCATOR>(*this, alloc);
5119}
5120
5121template <class ALLOCATOR, typename CAPACITY_POLICY>
5123 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5124}
5125
5126template <class ALLOCATOR> string<ALLOCATOR> from_base58::as_string(const ALLOCATOR &alloc) const {
5127 return make_string<ALLOCATOR>(*this, alloc);
5128}
5129
5130template <class ALLOCATOR, typename CAPACITY_POLICY>
5132 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5133}
5134
5135template <class ALLOCATOR> string<ALLOCATOR> from_base64::as_string(const ALLOCATOR &alloc) const {
5136 return make_string<ALLOCATOR>(*this, alloc);
5137}
5138
5139template <class ALLOCATOR, typename CAPACITY_POLICY>
5141 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5142}
5143
5144template <class ALLOCATOR>
5145inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
5146 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
5147}
5148
5149template <class ALLOCATOR>
5150inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5151 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5152}
5153
5154template <class ALLOCATOR>
5155inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5156 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5157}
5158
5159template <class ALLOCATOR, class CAPACITY_POLICY>
5160inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5161 const ALLOCATOR &alloc) const {
5162 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5163}
5164
5165template <class ALLOCATOR, class CAPACITY_POLICY>
5166inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
5167 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5168}
5169
5170template <class ALLOCATOR, class CAPACITY_POLICY>
5171inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
5172 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5173}
5174
5175template <class ALLOCATOR, class CAPACITY_POLICY>
5176inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5177 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5178}
5179
5180template <class ALLOCATOR, class CAPACITY_POLICY>
5181inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5182 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5183}
5184
5185template <class ALLOCATOR, class CAPACITY_POLICY>
5186inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5187 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5188}
5189
5190//------------------------------------------------------------------------------
5191
5192MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5193 const auto diff = slice::compare_fast(a.key, b.key);
5194 return diff ? diff : slice::compare_fast(a.value, b.value);
5195}
5196
5197MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5198 const auto diff = slice::compare_lexicographically(a.key, b.key);
5199 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5200}
5201
5203 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5204 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5205 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5206}
5207
5209 return pair::compare_lexicographically(a, b) < 0;
5210}
5211
5213 return pair::compare_lexicographically(a, b) > 0;
5214}
5215
5217 return pair::compare_lexicographically(a, b) <= 0;
5218}
5219
5221 return pair::compare_lexicographically(a, b) >= 0;
5222}
5223
5225 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5226 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5227 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5228}
5229
5230#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5231MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5233}
5234#endif /* __cpp_impl_three_way_comparison */
5235
5237template <typename BUFFER>
5239
5242
5243//------------------------------------------------------------------------------
5244
5245inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
5246inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
5247inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
5248
5249MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5250 return !from_hex(*this, ignore_spaces).is_erroneous();
5251}
5252
5253MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5254 return !from_base58(*this, ignore_spaces).is_erroneous();
5255}
5256
5257MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5258 return !from_base64(*this, ignore_spaces).is_erroneous();
5259}
5260
5261//------------------------------------------------------------------------------
5262
5264
5265inline env &env::operator=(env &&other) noexcept {
5266 handle_ = other.handle_;
5267 other.handle_ = nullptr;
5268 return *this;
5269}
5270
5271inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5272
5273inline env::~env() noexcept {
5274#ifndef NDEBUG
5275 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5276#endif
5277}
5278
5279MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5280
5281MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5282
5283MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5284
5285MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5286
5287MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5288
5292 return *this;
5293}
5294
5295inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5296 size_now = size_lower = lower;
5297 size_upper = upper;
5299 return *this;
5300}
5301
5305
5309
5310inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5311
5312inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5313
5314inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5315 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5316 if (result < 0)
5317 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5318 return static_cast<size_t>(result);
5319}
5320
5321inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5322 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5323 if (result < 0)
5324 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5325 return static_cast<size_t>(result);
5326}
5327
5328inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5329
5330inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5331
5332inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5333 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5334 if (result < 0)
5335 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5336 return static_cast<size_t>(result);
5337}
5338
5339inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5340 return key_max(pagesize, MDBX_db_flags_t(mode));
5341}
5342
5343inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
5344 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5345 if (result < 0)
5346 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5347 return static_cast<size_t>(result);
5348}
5349
5351
5352inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5353
5355
5356inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5357 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5358 if (result < 0)
5359 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5360 return static_cast<size_t>(result);
5361}
5362
5363inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5364 return value_max(pagesize, MDBX_db_flags_t(mode));
5365}
5366
5367inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
5368 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5369 if (result < 0)
5370 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5371 return static_cast<size_t>(result);
5372}
5373
5375
5376inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5377 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5378 if (result < 0)
5379 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5380 return static_cast<size_t>(result);
5381}
5382
5383inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5384 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5385}
5386
5388 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5389 if (result < 0)
5390 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5391 return static_cast<size_t>(result);
5392}
5393
5397
5398inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5399 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5400 if (result < 0)
5401 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5402 return static_cast<size_t>(result);
5403}
5404
5405inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5406 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5407}
5408
5410 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5411 if (result < 0)
5412 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5413 return static_cast<size_t>(result);
5414}
5415
5419
5420inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5421 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5422 if (result < 0)
5423 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5424 return static_cast<size_t>(result);
5425}
5426
5427inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5428
5436
5438
5442
5446
5450
5451inline env::stat env::get_stat() const {
5452 env::stat r;
5453 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5454 return r;
5455}
5456
5457inline env::stat env::get_stat(const txn &txn) const {
5458 env::stat r;
5460 return r;
5461}
5462
5463inline env::info env::get_info() const {
5464 env::info r;
5465 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5466 return r;
5467}
5468
5469inline env::info env::get_info(const txn &txn) const {
5470 env::info r;
5472 return r;
5473}
5474
5476 filehandle fd;
5478 return fd;
5479}
5480
5482 unsigned bits = 0;
5484 return MDBX_env_flags_t(bits);
5485}
5486
5487inline unsigned env::max_readers() const {
5488 unsigned r;
5490 return r;
5491}
5492
5493inline unsigned env::max_maps() const {
5494 unsigned r;
5496 return r;
5497}
5498
5499inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5500
5501inline env &env::set_context(void *ptr) {
5503 return *this;
5504}
5505
5506inline env &env::set_sync_threshold(size_t bytes) {
5508 return *this;
5509}
5510
5511inline size_t env::sync_threshold() const {
5512 size_t bytes;
5514 return bytes;
5515}
5516
5517inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5519 return *this;
5520}
5521
5522inline unsigned env::sync_period__seconds_16dot16() const {
5523 unsigned seconds_16dot16;
5525 return seconds_16dot16;
5526}
5527
5529 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5530}
5531
5532inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5533
5534#if __cplusplus >= 201103L
5535inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5536
5538#endif
5539
5540inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5542 return *this;
5543}
5544
5545inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5546 uint64_t value;
5548 return value;
5549}
5550
5551inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
5553 return *this;
5554}
5555
5556inline env &env::set_geometry(const geometry &geo) {
5558 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5559 return *this;
5560}
5561
5562inline bool env::sync_to_disk(bool force, bool nonblock) {
5563 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5564 switch (err) {
5565 case MDBX_SUCCESS /* flush done */:
5566 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5567 return true;
5568 case MDBX_BUSY /* the environment is used by other thread */:
5569 return false;
5570 default:
5571 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5572 }
5573}
5574
5575inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5576
5578env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5579 size_t retained) noexcept
5581 bytes_retained(retained) {}
5582
5583template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5584 struct reader_visitor_thunk : public exception_thunk {
5585 VISITOR &visitor_;
5586 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5587 size_t used, size_t retained) noexcept {
5588 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5589 assert(thunk->is_clean());
5590 try {
5591 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5592 return loop_control(thunk->visitor_(info, number));
5593 } catch (... /* capture any exception to rethrow it over C code */) {
5594 thunk->capture();
5596 }
5597 }
5598 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5599 };
5600 reader_visitor_thunk thunk(visitor);
5601 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5602 thunk.rethrow_captured();
5603 return rc;
5604}
5605
5606inline unsigned env::check_readers() {
5607 int dead_count;
5608 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5609 assert(dead_count >= 0);
5610 return static_cast<unsigned>(dead_count);
5611}
5612
5617
5618inline MDBX_hsr_func env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5619
5621 ::MDBX_txn *ptr;
5623 assert(ptr != nullptr);
5624 return txn_managed(ptr);
5625}
5626
5628 ::MDBX_txn *ptr;
5630 assert(ptr != nullptr);
5631 return txn_managed(ptr);
5632}
5633
5634inline txn_managed env::start_write(bool dont_wait) {
5635 ::MDBX_txn *ptr;
5638 assert(ptr != nullptr || dont_wait);
5639 return txn_managed(ptr);
5640}
5641
5643 ::MDBX_txn *ptr;
5645 assert(ptr != nullptr);
5646 return txn_managed(ptr);
5647}
5648
5650
5652
5653inline txn &txn::operator=(txn &&other) noexcept {
5654 handle_ = other.handle_;
5655 other.handle_ = nullptr;
5656 return *this;
5657}
5658
5659inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5660
5661inline txn::~txn() noexcept {
5662#ifndef NDEBUG
5663 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5664#endif
5665}
5666
5667MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5668
5669MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5670
5671MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5672
5673MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5674
5675MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5676
5677inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5678
5679inline txn &txn::set_context(void *ptr) {
5681 return *this;
5682}
5683
5684inline bool txn::is_dirty(const void *ptr) const {
5685 int err = ::mdbx_is_dirty(handle_, ptr);
5686 switch (err) {
5687 default:
5688 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5689 case MDBX_RESULT_TRUE:
5690 return true;
5691 case MDBX_RESULT_FALSE:
5692 return false;
5693 }
5694}
5695
5696inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5697
5699 const int bits = mdbx_txn_flags(handle_);
5701 return static_cast<MDBX_txn_flags_t>(bits);
5702}
5703
5704inline uint64_t txn::id() const {
5705 const uint64_t txnid = mdbx_txn_id(handle_);
5707 return txnid;
5708}
5709
5711
5713
5715
5716inline txn_managed txn::clone(void *context) const {
5717 MDBX_txn *ptr = nullptr;
5719 assert(ptr != nullptr);
5720 return txn_managed(ptr);
5721}
5722
5723inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
5724 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
5725 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
5726 assert(txn_for_renew_into_clone.handle_ != nullptr);
5727}
5728
5729inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5730
5731inline bool txn::unpark_reading(bool restart_if_ousted) {
5732 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5733}
5734
5735inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5736 txn::info r;
5737 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5738 return r;
5739}
5740
5742 MDBX_cursor *ptr;
5744 return cursor_managed(ptr);
5745}
5746
5747inline size_t txn::release_all_cursors(bool unbind) const {
5748 size_t count;
5750 return count;
5751}
5752
5753inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5754 const ::mdbx::value_mode value_mode) const {
5755 map_handle map;
5758 assert(map.dbi != 0);
5759 return map;
5760}
5761
5762inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5763 const ::mdbx::value_mode value_mode) const {
5764 map_handle map;
5767 assert(map.dbi != 0);
5768 return map;
5769}
5770
5771inline map_handle txn::open_map_accede(const slice &name) const {
5772 map_handle map;
5774 assert(map.dbi != 0);
5775 return map;
5776}
5777
5778inline map_handle txn::open_map_accede(const char *name) const {
5779 map_handle map;
5781 assert(map.dbi != 0);
5782 return map;
5783}
5784
5785inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5786 const ::mdbx::value_mode value_mode) {
5787 map_handle map;
5790 assert(map.dbi != 0);
5791 return map;
5792}
5793
5794inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5795 const ::mdbx::value_mode value_mode) {
5796 map_handle map;
5799 assert(map.dbi != 0);
5800 return map;
5801}
5802
5804
5806
5807inline void txn::rename_map(map_handle map, const char *new_name) {
5809}
5810
5811inline void txn::rename_map(map_handle map, const slice &new_name) {
5813}
5814
5815inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5816 const ::mdbx::value_mode value_mode) const {
5817 return open_map(slice(name), key_mode, value_mode);
5818}
5819
5820inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5821
5822inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5823 const ::mdbx::value_mode value_mode) {
5824 return create_map(slice(name), key_mode, value_mode);
5825}
5826
5827inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5828 return drop_map(slice(name), throw_if_absent);
5829}
5830
5831inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5832 return clear_map(slice(name), throw_if_absent);
5833}
5834
5835inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5836
5838 txn::map_stat r;
5839 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5840 return r;
5841}
5842
5843inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5844 uint32_t r;
5846 return r;
5847}
5848
5854
5859
5861 txn::canary r;
5863 return r;
5864}
5865
5866inline uint64_t txn::sequence(map_handle map) const {
5867 uint64_t result;
5869 return result;
5870}
5871
5872inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5873 uint64_t result;
5874 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5875 return result;
5876}
5877
5878inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5879 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5880}
5881
5882inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5883 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5884}
5885
5886inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5887 return compare_keys(map, a.key, b.key);
5888}
5889
5890inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5891 return compare_values(map, a.value, b.value);
5892}
5893
5894inline slice txn::get(map_handle map, const slice &key) const {
5895 slice result;
5896 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5897 return result;
5898}
5899
5900inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5901 slice result;
5902 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5903 return result;
5904}
5905
5906inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5907 slice result;
5908 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5909 switch (err) {
5910 case MDBX_SUCCESS:
5911 return result;
5912 case MDBX_NOTFOUND:
5913 return value_at_absence;
5914 default:
5915 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5916 }
5917}
5918
5919inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5920 slice result;
5921 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5922 switch (err) {
5923 case MDBX_SUCCESS:
5924 return result;
5925 case MDBX_NOTFOUND:
5926 return value_at_absence;
5927 default:
5928 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5929 }
5930}
5931
5933 pair result(key, slice());
5934 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5935 return pair_result(result.key, result.value, exact);
5936}
5937
5938inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5939 pair result{key, slice()};
5940 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5941 switch (err) {
5942 case MDBX_SUCCESS:
5943 return pair_result{result.key, result.value, true};
5944 case MDBX_RESULT_TRUE:
5945 return pair_result{result.key, result.value, false};
5946 case MDBX_NOTFOUND:
5947 return pair_result{key, value_at_absence, false};
5948 default:
5949 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5950 }
5951}
5952
5953inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5954 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5955}
5956
5957inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5958 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5959}
5960
5961inline void txn::insert(map_handle map, const slice &key, slice value) {
5962 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5964}
5965
5966inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5967 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5969 switch (err) {
5970 case MDBX_SUCCESS:
5971 return value_result{slice(), true};
5972 case MDBX_KEYEXIST:
5973 return value_result{value, false};
5974 default:
5975 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5976 }
5977}
5978
5979inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5980 slice result(nullptr, value_length);
5981 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5983 return result;
5984}
5985
5986inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5987 slice result(nullptr, value_length);
5988 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5990 switch (err) {
5991 case MDBX_SUCCESS:
5992 return value_result{result, true};
5993 case MDBX_KEYEXIST:
5994 return value_result{result, false};
5995 default:
5996 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5997 }
5998}
5999
6000inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
6001 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6002}
6003
6004inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
6005 slice result(nullptr, value_length);
6007 return result;
6008}
6009
6010inline void txn::update(map_handle map, const slice &key, const slice &value) {
6011 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6012}
6013
6014inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
6015 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6016 switch (err) {
6017 case MDBX_SUCCESS:
6018 return true;
6019 case MDBX_NOTFOUND:
6020 return false;
6021 default:
6022 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6023 }
6024}
6025
6026inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
6027 slice result(nullptr, value_length);
6029 return result;
6030}
6031
6032inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
6033 slice result(nullptr, value_length);
6034 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6035 switch (err) {
6036 case MDBX_SUCCESS:
6037 return value_result{result, true};
6038 case MDBX_NOTFOUND:
6039 return value_result{slice(), false};
6040 default:
6041 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6042 }
6043}
6044
6045inline bool txn::erase(map_handle map, const slice &key) {
6046 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6047 switch (err) {
6048 case MDBX_SUCCESS:
6049 return true;
6050 case MDBX_NOTFOUND:
6051 return false;
6052 default:
6053 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6054 }
6055}
6056
6057inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6058 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
6059 switch (err) {
6060 case MDBX_SUCCESS:
6061 return true;
6062 case MDBX_NOTFOUND:
6063 return false;
6064 default:
6065 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6066 }
6067}
6068
6069inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
6070 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6071 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6072}
6073
6074template <class ALLOCATOR, typename CAPACITY_POLICY>
6078 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6080 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
6081 return result;
6082}
6083
6084template <class ALLOCATOR, typename CAPACITY_POLICY>
6086txn::replace(map_handle map, const slice &key, const slice &new_value,
6088 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6089 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
6090 MDBX_CURRENT, result, &result),
6091 result);
6092 return result;
6093}
6094
6095template <class ALLOCATOR, typename CAPACITY_POLICY>
6097txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
6099 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6100 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6101 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6102 result);
6103 return result;
6104}
6105
6106inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
6107 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6108 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
6109}
6110
6111inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
6112 const void *values_array, size_t values_count, put_mode mode,
6113 bool allow_partial) {
6114 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6115 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6116 switch (err) {
6117 case MDBX_SUCCESS:
6118 MDBX_CXX20_LIKELY break;
6119 case MDBX_KEYEXIST:
6120 if (allow_partial)
6121 break;
6123 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6124 default:
6125 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6126 }
6127 return args[1].iov_len /* done item count */;
6128}
6129
6130inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
6131 ptrdiff_t result;
6132 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6133 return result;
6134}
6135
6136inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6137 ptrdiff_t result;
6138 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6139 return result;
6140}
6141
6142inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6143 ptrdiff_t result;
6144 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6145 return result;
6146}
6147
6148inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6149 ptrdiff_t result;
6150 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6151 return result;
6152}
6153
6155
6156inline cursor_managed cursor::clone(void *your_context) const {
6157 cursor_managed clone(your_context);
6159 return clone;
6160}
6161
6162inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6163
6164inline cursor &cursor::set_context(void *ptr) {
6166 return *this;
6167}
6168
6169inline cursor &cursor::operator=(cursor &&other) noexcept {
6170 handle_ = other.handle_;
6171 other.handle_ = nullptr;
6172 return *this;
6173}
6174
6175inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6176
6177inline cursor::~cursor() noexcept {
6178#ifndef NDEBUG
6179 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6180#endif
6181}
6182
6183MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
6184
6185MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
6186
6187MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6188
6189MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6190
6191MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6192
6193inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6194 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6195}
6196
6197inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6198 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6199 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6200 if (MDBX_LIKELY(int16_t(diff) == diff))
6201 MDBX_CXX20_LIKELY return int(diff);
6202 else
6204}
6205
6206inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6207 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6208}
6209
6211 bool throw_notfound)
6212 : pair_result(key, value, false) {
6213 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6214}
6215
6216inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6217 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6218 switch (err) {
6219 case MDBX_SUCCESS:
6220 MDBX_CXX20_LIKELY return true;
6221 case MDBX_RESULT_TRUE:
6222 return false;
6223 case MDBX_NOTFOUND:
6224 if (!throw_notfound)
6225 return false;
6226 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6227 default:
6228 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6229 }
6230}
6231
6233 const slice &value)
6234 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6235 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6236}
6237
6238inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6239 ptrdiff_t result;
6240 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6241 return result;
6242}
6243
6244inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6245 ptrdiff_t result;
6247 return result;
6248}
6249
6250inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6251 return move(key_exact, key, throw_notfound);
6252}
6253
6254inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6255 return move(key_lowerbound, key, throw_notfound);
6256}
6257
6258inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6259 return move(key_greater_than, key, throw_notfound);
6260}
6261
6262inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6263 return move(multi_find_pair, key, value, throw_notfound);
6264}
6265
6266inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6267 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6268}
6269
6270inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6271 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6272}
6273
6274inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6275
6276inline size_t cursor::count_multivalue() const {
6277 size_t result;
6279 return result;
6280}
6281
6282inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6283
6285
6287
6289
6291
6292inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6293 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6294}
6295
6297 return estimate_result(*this, key_lowerbound, key);
6298}
6299
6301 return estimate_result(*this, operation);
6302}
6303
6305
6309
6311
6312inline txn cursor::txn() const {
6314 return ::mdbx::txn(txn);
6315}
6316
6317inline map_handle cursor::map() const {
6318 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6319 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6321 return map_handle(dbi);
6322}
6323
6324inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6325 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6326}
6327
6328inline void cursor::put(const slice &key, slice value, put_mode mode) {
6329 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6330}
6331
6332inline void cursor::insert(const slice &key, slice value) {
6334 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6335}
6336
6337inline value_result cursor::try_insert(const slice &key, slice value) {
6338 const int err =
6339 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6340 switch (err) {
6341 case MDBX_SUCCESS:
6342 return value_result{slice(), true};
6343 case MDBX_KEYEXIST:
6344 return value_result{value, false};
6345 default:
6346 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6347 }
6348}
6349
6350inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6351 slice result(nullptr, value_length);
6352 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6354 return result;
6355}
6356
6357inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6358 slice result(nullptr, value_length);
6359 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6361 switch (err) {
6362 case MDBX_SUCCESS:
6363 return value_result{result, true};
6364 case MDBX_KEYEXIST:
6365 return value_result{result, false};
6366 default:
6367 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6368 }
6369}
6370
6371inline void cursor::upsert(const slice &key, const slice &value) {
6372 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6373}
6374
6375inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6376 slice result(nullptr, value_length);
6378 return result;
6379}
6380
6381inline void cursor::update(const slice &key, const slice &value) {
6382 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6383}
6384
6385inline bool cursor::try_update(const slice &key, const slice &value) {
6386 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6387 switch (err) {
6388 case MDBX_SUCCESS:
6389 return true;
6390 case MDBX_NOTFOUND:
6391 return false;
6392 default:
6393 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6394 }
6395}
6396
6397inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6398 slice result(nullptr, value_length);
6400 return result;
6401}
6402
6403inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6404 slice result(nullptr, value_length);
6405 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6406 switch (err) {
6407 case MDBX_SUCCESS:
6408 return value_result{result, true};
6409 case MDBX_NOTFOUND:
6410 return value_result{slice(), false};
6411 default:
6412 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6413 }
6414}
6415
6416inline bool cursor::erase(bool whole_multivalue) {
6417 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6418 switch (err) {
6419 case MDBX_SUCCESS:
6420 MDBX_CXX20_LIKELY return true;
6421 case MDBX_NOTFOUND:
6422 return false;
6423 default:
6424 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6425 }
6426}
6427
6428inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6429 bool found = seek(key);
6430 return found ? erase(whole_multivalue) : found;
6431}
6432
6433inline bool cursor::erase(const slice &key, const slice &value) {
6434 move_result data = find_multivalue(key, value, false);
6435 return data.done && erase();
6436}
6437
6438inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6439 size_t values_count, put_mode mode, bool allow_partial) {
6440 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6441 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6442 switch (err) {
6443 case MDBX_SUCCESS:
6444 MDBX_CXX20_LIKELY break;
6445 case MDBX_KEYEXIST:
6446 if (allow_partial)
6447 break;
6449 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6450 default:
6451 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6452 }
6453 return args[1].iov_len /* done item count */;
6454}
6455
6456//------------------------------------------------------------------------------
6457
6458LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
6459LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
6460LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
6461LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
6462LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
6463LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
6464LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
6465LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
6466LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
6467LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
6468LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
6469
6470LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
6471LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
6472LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
6473
6474inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
6475
6477
6478} // namespace mdbx
6479
6480//------------------------------------------------------------------------------
6481
6484namespace std {
6485
6486inline string to_string(const ::mdbx::slice &value) {
6487 ostringstream out;
6488 out << value;
6489 return out.str();
6490}
6491
6492template <class ALLOCATOR, typename CAPACITY_POLICY>
6493inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6494 ostringstream out;
6495 out << buffer;
6496 return out.str();
6497}
6498
6499inline string to_string(const ::mdbx::pair &value) {
6500 ostringstream out;
6501 out << value;
6502 return out.str();
6503}
6504
6505inline string to_string(const ::mdbx::env::geometry &value) {
6506 ostringstream out;
6507 out << value;
6508 return out.str();
6509}
6510
6511inline string to_string(const ::mdbx::env::operate_parameters &value) {
6512 ostringstream out;
6513 out << value;
6514 return out.str();
6515}
6516
6517inline string to_string(const ::mdbx::env::mode &value) {
6518 ostringstream out;
6519 out << value;
6520 return out.str();
6521}
6522
6523inline string to_string(const ::mdbx::env::durability &value) {
6524 ostringstream out;
6525 out << value;
6526 return out.str();
6527}
6528
6529inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6530 ostringstream out;
6531 out << value;
6532 return out.str();
6533}
6534
6535inline string to_string(const ::mdbx::env::operate_options &value) {
6536 ostringstream out;
6537 out << value;
6538 return out.str();
6539}
6540
6541inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6542 ostringstream out;
6543 out << value;
6544 return out.str();
6545}
6546
6547inline string to_string(const ::MDBX_log_level_t &value) {
6548 ostringstream out;
6549 out << value;
6550 return out.str();
6551}
6552
6553inline string to_string(const ::MDBX_debug_flags_t &value) {
6554 ostringstream out;
6555 out << value;
6556 return out.str();
6557}
6558
6559inline string to_string(const ::mdbx::error &value) {
6560 ostringstream out;
6561 out << value;
6562 return out.str();
6563}
6564
6565inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6566
6567template <> struct hash<::mdbx::slice> {
6568 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6569};
6570
6571template <> struct hash<::mdbx::map_handle> {
6572 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6573};
6574
6575template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6576 using inherited = std::hash<const MDBX_env *>;
6577 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6578};
6579
6580template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6581 using inherited = std::hash<const MDBX_txn *>;
6582 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6583};
6584
6585template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6586 using inherited = std::hash<const MDBX_cursor *>;
6587 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6588};
6589
6590template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6591 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6592 return buffer.hash_value();
6593 }
6594};
6595
6596} // namespace std
6597
6598#if defined(__LCC__) && __LCC__ >= 126
6599#pragma diagnostic pop
6600#endif
6601
6602#ifdef _MSC_VER
6603#pragma warning(pop)
6604#endif
Definition mdbx.h++:1160
Definition mdbx.h++:1150
Definition mdbx.h++:1170
#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:5231
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4724
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4130
Information about the environment.
Definition mdbx.h:2820
Statistics for a table in the environment.
Definition mdbx.h:2774
Information about the transaction.
Definition mdbx.h:4028
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:5524
LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result, uint64_t increment)
Sequence generation for a table.
LIBMDBX_API int mdbx_cursor_scan(MDBX_cursor *cursor, MDBX_predicate_func predicate, void *context, MDBX_cursor_op start_op, MDBX_cursor_op turn_op, void *arg)
Scans the table using the passed predicate, reducing the associated overhead.
LIBMDBX_API int mdbx_get_equal_or_great(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data)
Get equal or great item from a table.
LIBMDBX_API int mdbx_canary_put(MDBX_txn *txn, const MDBX_canary *canary)
Set integers markers (aka "canary") associated with the environment.
LIBMDBX_API int mdbx_canary_get(const MDBX_txn *txn, MDBX_canary *canary)
Returns fours integers markers (aka "canary") associated with the environment.
MDBX_put_flags_t
Data changing flags.
Definition mdbx.h: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.
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:4784
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5245
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, const MDBX_val *data)
Delete items from a table.
LIBMDBX_API int mdbx_get_ex(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, size_t *values_count)
Get items from a table and optionally number of data items for a given key.
LIBMDBX_API int mdbx_cursor_scan_from(MDBX_cursor *cursor, MDBX_predicate_func predicate, void *context, MDBX_cursor_op from_op, MDBX_val *from_key, MDBX_val *from_value, MDBX_cursor_op turn_op, void *arg)
LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store by cursor.
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store items into a table.
LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del)
Empty or delete and close a table.
LIBMDBX_API int mdbx_cursor_get(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, MDBX_cursor_op op)
Retrieve by cursor.
LIBMDBX_API int mdbx_get(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data)
Get items from a table.
@ MDBX_MULTIPLE
Definition mdbx.h: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
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1837
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:6815
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1851
@ MDBX_BAD_TXN
Definition mdbx.h:1914
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1928
@ MDBX_SUCCESS
Definition mdbx.h:1839
@ MDBX_NOTFOUND
Definition mdbx.h:1854
@ MDBX_RESULT_TRUE
Definition mdbx.h:1845
@ MDBX_BUSY
Definition mdbx.h:1932
@ MDBX_EINVAL
Definition mdbx.h:2008
@ MDBX_ENOMEM
Definition mdbx.h:2010
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1935
@ MDBX_RESULT_FALSE
Definition mdbx.h:1842
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:1987
@ 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:2556
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2551
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2554
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:3067
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2118
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:3006
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:2223
@ MDBX_opt_subpage_room_threshold
Sets the minimum amount of free space on a leaf page in the absence of which the nested pages are pla...
Definition mdbx.h:2385
@ MDBX_opt_subpage_limit
Specifies the maximum size of nested pages used to accommodate a small number of multi-values associa...
Definition mdbx.h:2378
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2219
@ MDBX_opt_prefer_waf_insteadof_balance
Controls the choice between striving for uniformity of page filling/density, either for reducing the ...
Definition mdbx.h:2364
@ 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:2323
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2127
@ MDBX_opt_subpage_reserve_prereq
Sets the minimum amount of free space on the main page, if available, to reserve space in the subpage...
Definition mdbx.h:2399
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2150
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2255
@ 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:2278
@ MDBX_opt_split_reserve
Sets the space reservation in 1/65536 of page size when splitting page along the edge.
Definition mdbx.h:2427
@ 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:2190
@ 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:2177
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2144
@ MDBX_opt_subpage_reserve_limit
Sets the limit for reserving space on nested pages.
Definition mdbx.h:2405
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2239
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2156
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2204
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2318
@ MDBX_opt_gc_time_limit
Controls the in-process spending time limit of searching consecutive pages inside GC.
Definition mdbx.h:2342
@ MDBX_opt_merge_threshold
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2290
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:3684
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:3087
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:3024
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:5046
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:3729
LIBMDBX_API intptr_t mdbx_limits_keysize_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal key size in bytes for given page size and table flags, or -1 if pagesize is invalid.
LIBMDBX_API intptr_t mdbx_limits_pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal size of key-value pair to fit in a single page with the given size and table flags,...
LIBMDBX_API intptr_t mdbx_limits_dbsize_max(intptr_t pagesize)
Returns maximal database size in bytes for given page size, or -1 if pagesize is invalid.
LIBMDBX_API intptr_t mdbx_limits_dbsize_min(intptr_t pagesize)
Returns minimal database size in bytes for given page size, or -1 if pagesize is invalid.
LIBMDBX_API int mdbx_env_get_flags(const MDBX_env *env, unsigned *flags)
Get environment flags.
LIBMDBX_API int mdbx_dbi_flags_ex(const MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags, unsigned *state)
Retrieve the DB flags and status for a table handle.
LIBMDBX_API int mdbx_reader_list(const MDBX_env *env, MDBX_reader_list_func func, void *ctx)
Enumerate the entries in the reader lock table.
LIBMDBX_API int mdbx_txn_break(MDBX_txn *txn)
Marks transaction as broken to prevent further operations.
LIBMDBX_API int mdbx_txn_set_userctx(MDBX_txn *txn, void *ctx)
Sets application information associated (a context pointer) with the transaction.
LIBMDBX_API int mdbx_txn_clone(const MDBX_txn *origin, MDBX_txn **in_out_clone, void *context)
Starts a read-only clone of a given transaction.
LIBMDBX_API int mdbx_txn_park(MDBX_txn *txn, bool autounpark)
Puts the reading transaction in a "parked" state.
LIBMDBX_API int mdbx_txn_unpark(MDBX_txn *txn, bool restart_if_ousted)
Unparks a previously parked reading transaction.
MDBX_txn_flags_t
Definition mdbx.h: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:3945
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++:4105
friend class env
Definition mdbx.h++:4062
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:3748
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4562
~txn_managed() noexcept
::MDBX_stat map_stat
Definition mdbx.h++:3914
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++:3441
@ prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h++:3475
@ subpage_reserve_prereq
Sets the minimum amount of free space on the main page, if available, to reserve space in the subpage...
Definition mdbx.h++:3485
@ spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h++:3467
@ subpage_limit
Specifies the maximum size of nested pages used to accommodate a small number of multi-values associa...
Definition mdbx.h++:3481
@ spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h++:3469
@ writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h++:3473
@ sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h++:3450
@ dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h++:3461
@ dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h++:3463
@ spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h++:3465
@ prefer_waf_insteadof_balance
Controls the choice between striving for uniformity of page filling/density, either for reducing the ...
Definition mdbx.h++:3479
@ subpage_room_threshold
Sets the minimum amount of free space on a leaf page in the absence of which the nested pages are pla...
Definition mdbx.h++:3483
@ merge_threshold_dot16
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h++:3471
@ 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++:3455
@ loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h++:3457
@ gc_time_limit
Controls the in-process spending time limit of searching consecutive pages inside GC.
Definition mdbx.h++:3477
@ subpage_reserve_limit
Sets the limit for reserving space on nested pages.
Definition mdbx.h++:3487
@ split_reserve
Sets the space reservation in 1/65536 of page size when splitting page along the edge.
Definition mdbx.h++:3489
@ dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h++:3459
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3682
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3895
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++:2940
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4407
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4463
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2909
durability
Durability level.
Definition mdbx.h++:3086
@ lazy_weak_tail
Definition mdbx.h++:3089
@ robust_synchronous
Definition mdbx.h++:3087
@ whole_fragile
Definition mdbx.h++:3090
@ half_synchronous_weak_last
Definition mdbx.h++:3088
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++:2936
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3256
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++:4451
bool checkpoint(finalization_latency &latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4119
estimate_result estimate(move_operation operation, slice &key) const
cache_entry() noexcept
Definition mdbx.h++:2770
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3705
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4426
::MDBX_canary canary
Definition mdbx.h++:3923
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++:4122
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++:3746
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++:4356
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++:4420
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++:5287
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4429
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++:2777
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2930
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2910
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4515
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4374
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++:4365
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++:4191
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3802
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3978
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4397
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4183
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4187
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++:3887
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3183
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4381
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4584
MDBX_txn * handle_
Definition mdbx.h++:3706
void abort()
Abandon all the operations of the transaction instead of saving ones.
MDBX_commit_latency finalization_latency
Definition mdbx.h++:4084
const path_char * get_path() const
Return the path that was used for opening the environment.
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4353
mode
Operation mode.
Definition mdbx.h++:3078
@ write_mapped_io
Definition mdbx.h++:3081
@ nested_transactions
Definition mdbx.h++:3082
@ readonly
Definition mdbx.h++:3079
@ write_file_io
Definition mdbx.h++:3080
bool is_writemap() const
Definition mdbx.h++:3349
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4350
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4309
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3317
operator::mdbx::txn() const
Definition mdbx.h++:4492
MDBX_env * handle_
Definition mdbx.h++:2979
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++:4413
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4179
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4363
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4383
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:2773
bool is_nested_transactions_available() const
Definition mdbx.h++:3353
void close()
Explicitly closes the cursor.
Definition mdbx.h++:4568
void abort(finalization_latency &latency)
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4091
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++:4394
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3743
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++:4459
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++:4026
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3287
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3297
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3299
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3294
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4285
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4368
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4330
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4574
::MDBX_dbi_state_t state
Definition mdbx.h++:2941
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3512
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4542
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++:3262
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4423
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++:4455
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4385
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4382
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4493
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3258
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2933
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3799
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2924
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++:4400
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3323
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3975
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++:6197
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4042
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++:3269
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++:3880
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2921
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++:4133
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++:4034
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++:4136
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++:2927
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++:4435
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4201
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4216
@ multi_exactkey_value_equal
Definition mdbx.h++:4233
@ pair_greater_or_equal
Definition mdbx.h++:4241
@ key_lesser_than
Definition mdbx.h++:4223
@ next
Definition mdbx.h++:4204
@ pair_exact
Definition mdbx.h++:4240
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4234
@ pair_lesser_or_equal
Definition mdbx.h++:4238
@ batch_samelength
Definition mdbx.h++:4244
@ seek_key
Definition mdbx.h++:4218
@ key_lowerbound
Definition mdbx.h++:4220
@ pair_lesser_than
Definition mdbx.h++:4237
@ pair_equal
Definition mdbx.h++:4239
@ key_greater_than
Definition mdbx.h++:4227
@ batch_samelength_next
Definition mdbx.h++:4245
@ multi_find_pair
Definition mdbx.h++:4215
@ key_greater_or_equal
Definition mdbx.h++:4226
@ key_exact
Definition mdbx.h++:4219
@ key_equal
Definition mdbx.h++:4225
@ multi_currentkey_prevvalue
Definition mdbx.h++:4210
@ key_lesser_or_equal
Definition mdbx.h++:4224
@ multi_nextkey_firstvalue
Definition mdbx.h++:4213
@ get_current
Definition mdbx.h++:4206
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4232
@ multi_prevkey_lastvalue
Definition mdbx.h++:4208
@ previous
Definition mdbx.h++:4205
@ last
Definition mdbx.h++:4203
@ pair_greater_than
Definition mdbx.h++:4242
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4231
@ multi_currentkey_firstvalue
Definition mdbx.h++:4209
@ first
Definition mdbx.h++:4202
@ batch_samelength_previous
Definition mdbx.h++:4246
@ multi_currentkey_nextvalue
Definition mdbx.h++:4211
@ seek_and_batch_samelength
Definition mdbx.h++:4247
@ multi_exactkey_value_greater
Definition mdbx.h++:4235
@ multi_currentkey_lastvalue
Definition mdbx.h++:4212
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++:4108
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4359
void insert(const pair &kv)
Definition mdbx.h++:4516
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3740
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++:4518
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4371
txn_managed & operator=(const txn_managed &)=delete
bool is_cooperative() const
Definition mdbx.h++:3347
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3900
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:5285
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4410
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++:4378
bool is_readonly() const
Definition mdbx.h++:3343
value_result try_insert(const pair &kv)
Definition mdbx.h++:4517
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++:4534
constexpr cursor() noexcept=default
bool is_exclusive() const
Definition mdbx.h++:3345
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4388
finalization_latency abort_get_latency()
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4094
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4432
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3266
MDBX_cursor * handle_
Definition mdbx.h++:4155
~cursor_managed() noexcept
Definition mdbx.h++:4592
bool is_readwite() const
Definition mdbx.h++:3351
MDBX_dbi dbi
Definition mdbx.h++:2908
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4404
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4375
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3754
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++:4416
txn_managed(const txn_managed &)=delete
friend int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept
Definition mdbx.h++:6193
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3314
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3264
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3977
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3976
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++:3908
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4391
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++:4364
friend class txn
Definition mdbx.h++:2976
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4175
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3260
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3757
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4304
Unmanaged cursor.
Definition mdbx.h++:4153
Managed cursor.
Definition mdbx.h++:4554
Unmanaged database environment.
Definition mdbx.h++:2975
Managed database environment.
Definition mdbx.h++:3621
Unmanaged database transaction.
Definition mdbx.h++:3703
Managed database transaction.
Definition mdbx.h++:4060
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++:5328
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5192
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4862
polymorphic_allocator default_allocator
Definition mdbx.h++:397
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4871
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4953
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++:5166
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++:5104
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++:5095
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5677
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++:5356
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4967
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4692
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++:6069
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6304
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2822
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4849
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:4649
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4947
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5710
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++:4839
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4727
void rethrow_captured() const
Definition mdbx.h++:4664
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4847
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6262
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6238
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5321
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5295
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++:5113
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6032
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5986
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5575
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++:5506
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6206
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++:5145
::mdbx::filesystem::path::string_type path_string
Definition mdbx.h++:445
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4869
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6142
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++:5171
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4894
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4795
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6310
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:466
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5979
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6154
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5807
void throw_on_failure() const
Definition mdbx.h++:4704
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6385
void update(const slice &key, const slice &value)
Definition mdbx.h++:6381
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:4646
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++:5878
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:5016
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4857
::MDBX_cmp_func comparator
Definition mdbx.h++:2953
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++:5160
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5679
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5642
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6193
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4993
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5439
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5866
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6371
bool is_clean() const noexcept
Definition mdbx.h++:4657
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2815
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4747
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++:5150
path_string::value_type path_char
Definition mdbx.h++:453
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5429
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2819
::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++:5481
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5314
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4937
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4671
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++:5176
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4600
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5047
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++:6097
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++:5613
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++:5578
void insert(const slice &key, slice value)
Definition mdbx.h++:6332
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6266
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++:5762
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:5241
::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++:2803
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++:5186
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4779
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:6156
~cursor() noexcept
Definition mdbx.h++:6177
~txn() noexcept
Definition mdbx.h++:5661
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5511
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:5140
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6258
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++:4875
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6312
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6357
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5306
map_handle map() const
Definition mdbx.h++:6317
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++:5522
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:4653
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6250
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5778
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6270
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2883
void success_or_throw() const
Definition mdbx.h++:4709
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5714
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4909
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5562
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4997
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6197
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6276
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4905
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5312
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4914
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5684
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6375
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5437
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2811
void capture() noexcept
Definition mdbx.h++:4659
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:5122
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++:5843
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6014
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4888
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2954
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6350
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++:5618
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++:5376
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++:5517
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:6130
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5443
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5803
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6148
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++:6106
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5447
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5729
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:5001
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6164
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5837
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6216
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++:5352
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++:5882
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5302
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5855
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6004
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4932
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4686
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++:5528
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4959
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4831
bool on_first() const
Definition mdbx.h++:6284
::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++:4867
bool eof() const
Definition mdbx.h++:6282
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5712
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5698
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5499
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6324
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5627
::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++:5135
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5651
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4899
bool seek(const slice &key)
Definition mdbx.h++:6274
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5551
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5501
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4921
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++:5420
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5805
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++:5540
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5257
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4882
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6337
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++:6438
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4732
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4680
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5696
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2962
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5197
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++:5181
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++:5532
::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++:5398
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5263
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4989
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++:5860
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6416
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5451
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5090
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5704
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5966
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition mdbx.h++:379
constexpr bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition mdbx.h++:4694
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:5117
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:5099
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6244
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4974
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:5108
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:5126
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6026
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5253
~env() noexcept
Definition mdbx.h++:5273
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2784
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5894
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4688
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4877
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++:6111
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6010
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4926
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2787
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5620
::mdbx::filesystem::path path
Definition mdbx.h++:444
bool on_last_multival() const
Definition mdbx.h++:6290
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5493
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5961
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5487
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++:5332
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5583
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6162
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5427
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5741
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2807
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5731
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5545
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4601
bool on_first_multival() const
Definition mdbx.h++:6288
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5953
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4722
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:5029
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4942
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5463
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:6000
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5310
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++:5155
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6397
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:5716
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6254
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4833
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4855
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++:5238
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5606
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:6045
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4684
bool on_last() const
Definition mdbx.h++:6286
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++:6076
#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++:5475
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5556
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++:6306
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:5131
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5289
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5747
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4678
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5069
constexpr bool is_success() const noexcept
Definition mdbx.h++:4682
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6403
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:5042
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5649
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5249
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5735
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++:5794
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++:5932
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5849
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4841
@ multi_reverse_samelength
Definition mdbx.h++:2855
@ multi_samelength
Definition mdbx.h++:2840
@ multi_ordinal
Definition mdbx.h++:2847
@ msgpack
Definition mdbx.h++:2870
@ single
Definition mdbx.h++:2823
@ multi
Definition mdbx.h++:2825
@ multi_reverse
Definition mdbx.h++:2832
@ upsert
Insert or update.
Definition mdbx.h++:2964
@ update
Update existing, don't insert new.
Definition mdbx.h++:2965
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2963
@ continue_loop
Definition mdbx.h++:2784
@ exit_loop
Definition mdbx.h++:2784
@ usual
Definition mdbx.h++:2788
@ ordinal
Definition mdbx.h++:2793
@ reverse
Definition mdbx.h++:2790
@ msgpack
Definition mdbx.h++:2798
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2907
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2418
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2131
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++:2009
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2036
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:706
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2101
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1991
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:719
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:682
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++:2273
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2314
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:673
buffer_pair_spec(const txn &transacton, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2704
const slice source
Definition mdbx.h++:1264
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++:2639
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++:2222
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:741
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:2052
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2345
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2049
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2427
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2297
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++:2024
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2158
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2398
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2311
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2043
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2163
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2671
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1567
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1037
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1241
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2349
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2076
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2528
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2072
buffer & append(const byte c)
Definition mdbx.h++:2482
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2322
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:759
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1018
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2327
buffer & operator=(const buffer &src)
Definition mdbx.h++:2444
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1036
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2550
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:2018
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2713
constexpr int64_t as_int64() const
Definition mdbx.h++:1043
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2069
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2629
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++:2204
const bool ignore_spaces
Definition mdbx.h++:1344
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:863
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++:2286
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++:2280
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2199
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2492
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2242
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++:1106
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Definition mdbx.h++:776
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2682
constexpr int16_t as_int16() const
Definition mdbx.h++:1045
slice value
Definition mdbx.h++:1070
::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++:2684
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2423
static buffer base58_decode(const slice &source, bool ignore_spaces=false, const allocator_type &alloc=allocator_type())
Decodes Base58 dump from the slice content to returned buffer.
Definition mdbx.h++:2266
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2649
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1212
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++:2292
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2196
slice value
Definition mdbx.h++:1084
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2675
::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++:1986
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2655
const slice source
Definition mdbx.h++:1343
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2693
const slice source
Definition mdbx.h++:1179
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++:2230
constexpr buffer & assign(buffer &&src) noexcept(allocation_aware_details::move_assign_alloc< silo, allocator_type >::is_nothrow())
Definition mdbx.h++:2386
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++:1326
const unsigned wrap_width
Definition mdbx.h++:1181
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2453
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2635
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:733
const slice & slice() const noexcept
Definition mdbx.h++:2667
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2406
const bool ignore_spaces
Definition mdbx.h++:1310
constexpr POD as_pod() const
Definition mdbx.h++:1020
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++:1133
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++:1410
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2688
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2394
constexpr buffer(const buffer &src)
Definition mdbx.h++:2141
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++:2259
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1033
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2467
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2089
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2641
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2337
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1182
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2690
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2524
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2621
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1532
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2174
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:755
std::pair< slice, slice > stl_pair
Definition mdbx.h++:1083
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2548
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:2003
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
@ pettiness_threshold
Definition mdbx.h++:1520
@ extra_inplace_storage
Definition mdbx.h++:1518
@ max_reserve
Definition mdbx.h++:1521
@ inplace_storage_size_rounding
Definition mdbx.h++:1519
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2653
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:696
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1345
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2448
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2520
constexpr int8_t as_int8() const
Definition mdbx.h++:1046
constexpr ::std::span< char > chars()
Definition mdbx.h++:708
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1065
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1283
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2126
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++:1524
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1255
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++:1401
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:1072
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2633
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1372
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2254
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2169
const slice source
Definition mdbx.h++:1222
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:1086
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2412
constexpr bool is_freestanding() const noexcept
Checks whether data chunk stored inside the buffer, otherwise buffer just refers to data located outs...
Definition mdbx.h++:1995
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2657
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:707
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1384
buffer_pair_spec & operator=(buffer_pair_spec &&src)
Definition mdbx.h++:2717
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2583
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++:1216
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1568
uint8_t as_uint8_adapt() const
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:687
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2647
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2120
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2450
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2733
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2500
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2571
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2532
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++:1362
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:738
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++:763
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1333
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:652
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++:2237
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2663
slice inherited
Definition mdbx.h++:1561
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:1134
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1311
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2659
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++:2661
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2316
static constexpr pair invalid() noexcept
Definition mdbx.h++:1099
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2109
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2402
bool done
Definition mdbx.h++:1132
::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++:1258
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:705
pair & operator=(pair &&couple)
Definition mdbx.h++:1090
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:721
allocation_aware_details::move_assign_alloc< silo, allocator_type > move_assign_alloc
Definition mdbx.h++:1984
const bool uppercase
Definition mdbx.h++:1180
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1985
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2056
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2365
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2490
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2536
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2701
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2063
const bool ignore_spaces
Definition mdbx.h++:1383
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1267
pair(const pair &) noexcept=default
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2615
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:1013
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++:1041
slice key
Definition mdbx.h++:1084
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2474
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:1085
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2707
const slice source
Definition mdbx.h++:1382
pair_result & operator=(const pair_result &) noexcept=default
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2472
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1300
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2665
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2464
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2673
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++:1044
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++:2216
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2145
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1563
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2637
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2029
pair & operator=(const stl_pair &couple)
Definition mdbx.h++:1101
int64_t as_int64_adapt() const
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2645
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2032
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++:2211
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2341
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2699
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1038
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2674
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2154
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1988
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2540
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2560
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1035
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2181
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++:2695
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2643
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++:2249
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2597
const unsigned wrap_width
Definition mdbx.h++:1223
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++:2516
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2193
const unsigned wrap_width
Definition mdbx.h++:1265
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2446
uint32_t as_uint32_adapt() const
constexpr bool is_valid() const noexcept
Checks the slice is not refers to null address or has zero length.
Definition mdbx.h++:1010
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2083
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++:2502
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2710
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++:714
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2509
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2149
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2626
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2672
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++:1304
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++:1225
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2137
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:716
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++:1197
bool done
Definition mdbx.h++:1071
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++:1309
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:2012
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2094
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1559
Definition mdbx.h++:2670
Type tag for delivered buffer template classes.
Definition mdbx.h++:1555
Definition mdbx.h++:1516
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1342
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1381
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1308
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:1082
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:1131
References a data located outside the slice.
Definition mdbx.h++:647
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1221
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1263
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1178
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:1069
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:564
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++:4680
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++:563
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++:532
laggard_reader(const ::mdbx::error &)
db_full(const ::mdbx::error &)
duplicated_lck_file(const ::mdbx::error &)
const ::mdbx::error error() const noexcept
Definition mdbx.h++:554
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++:565
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++:566
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++:4678
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++:491
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:476
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:572
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:4985
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:4989
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++:1418
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1420
The libmdbx C++ API namespace.
Definition mdbx.h++:323
STL namespace.
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6486
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1654
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1656
byte lastbyte_
Definition mdbx.h++:1655
Definition mdbx.h++:4266
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4268
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4267
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4270
Definition mdbx.h++:4254
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++:4258
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4256
Tagged type for output to std::ostream.
Definition mdbx.h++:3027
intptr_t bytes
Definition mdbx.h++:3028
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3029
Database geometry for size management.
Definition mdbx.h++:3003
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3051
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3063
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3010
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3006
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3009
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3018
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3007
@ default_value
Means "keep current or use default".
Definition mdbx.h++:3005
@ kB
bytes (0x03E8)
Definition mdbx.h++:3008
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3017
@ KiB
bytes (0x0400)
Definition mdbx.h++:3016
constexpr geometry() noexcept
Definition mdbx.h++:3067
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3054
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3039
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3057
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3034
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++:3070
Operate options.
Definition mdbx.h++:3107
bool disable_readahead
Definition mdbx.h++:3116
bool enable_validation
Definition mdbx.h++:3120
bool no_sticky_threads
Definition mdbx.h++:3109
constexpr operate_options() noexcept
Definition mdbx.h++:3121
bool disable_clear_memory
Definition mdbx.h++:3118
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3114
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
bool nested_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3112
Operate parameters.
Definition mdbx.h++:3129
env::durability durability
Definition mdbx.h++:3137
env::operate_options options
Definition mdbx.h++:3139
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++:3143
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++:3135
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3138
env::mode mode
Definition mdbx.h++:3136
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++:3132
constexpr operate_parameters() noexcept
Definition mdbx.h++:3141
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3535
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3538
uint64_t transaction_lag
Definition mdbx.h++:3541
size_t bytes_used
Definition mdbx.h++:3545
uint64_t transaction_id
Definition mdbx.h++:3539
int slot
The reader lock table slot number.
Definition mdbx.h++:3536
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3537
size_t bytes_retained
Definition mdbx.h++:3548
Garbage reclaiming options.
Definition mdbx.h++:3094
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
bool coalesce
Definition mdbx.h++:3098
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3099
bool lifo
Definition mdbx.h++:3096
Additional parameters for creating a new database.
Definition mdbx.h++:3644
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3646
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3647
env::geometry geometry
Definition mdbx.h++:3645
Definition mdbx.h++:2942
map_handle::state state
Definition mdbx.h++:2944
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2943
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6591
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6587
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6586
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6577
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6576
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6572
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6568
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6581
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6582
capacity_holder capacity_
Definition mdbx.h++:1660
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1693
allocator_pointer stub_ptr_
Definition mdbx.h++:1635
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1672
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1713
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1664
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1679
inplace_flag_holder inplace_
Definition mdbx.h++:1661
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1663
allocator_pointer allocated_ptr_
Definition mdbx.h++:1659
size_t stub_capacity_bytes_
Definition mdbx.h++:1636
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1732
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1649
size_t bytes_
Definition mdbx.h++:1650
constexpr const byte * address() const noexcept
Definition mdbx.h++:1726
constexpr bin() noexcept
Definition mdbx.h++:1707
@ inplace_size
Definition mdbx.h++:1644
@ inplace_signature_limit
Definition mdbx.h++:1641
@ inplace_size_rounding
Definition mdbx.h++:1643
constexpr byte * address() noexcept
Definition mdbx.h++:1729
@ lastbyte_poison
Definition mdbx.h++:1639
@ lastbyte_inplace_signature
Definition mdbx.h++:1639
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1722
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1681