libmdbx 0.14.1.392 (2026-02-06T10:56:17+03:00)
One of the fastest compact embeddable key-value ACID storage engine without WAL.
Loading...
Searching...
No Matches
mdbx.h++
Go to the documentation of this file.
1
25
26#pragma once
27
28//
29// Tested with, since 2026:
30// - Elbrus LCC >= 1.28 (http://www.mcst.ru/lcc);
31// - GNU C++ >= 11.3;
32// - CLANG >= 14.0;
33// - MSVC >= 19.44 (Visual Studio 2022 toolchain v143),
34// before 2026:
35// - Elbrus LCC >= 1.23 (http://www.mcst.ru/lcc);
36// - GNU C++ >= 4.8;
37// - CLANG >= 3.9;
38// - MSVC >= 14.0 (Visual Studio 2015),
39// but 19.2x could hang due optimizer bug;
40// - AppleClang, but without C++20 concepts.
41//
42
43/* Workaround for modern libstdc++ with CLANG < 4.x */
44#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4
45#define __GLIBCXX_BITSIZE_INT_N_0 128
46#define __GLIBCXX_TYPE_INT_N_0 __int128
47#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
48
49#if !defined(__cplusplus) || __cplusplus < 201103L
50#if !defined(_MSC_VER) || _MSC_VER < 1900
51#error "C++11 compiler or better is required"
52#elif _MSC_VER >= 1910
53#error "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
54#endif /* MSVC is mad and don't define __cplusplus properly */
55#endif /* __cplusplus < 201103L */
56
57#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
58#error "CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
59#endif /* Windows */
60
61#ifndef __has_include
62#define __has_include(header) (0)
63#endif /* __has_include */
64
65#if __has_include(<version>)
66#include <version>
67#endif /* <version> */
68
69/* Disable min/max macros from C' headers */
70#ifndef NOMINMAX
71#define NOMINMAX
72#endif
73
74#include <algorithm> // for std::min/max
75#include <cassert> // for assert()
76#include <climits> // for CHAR_BIT
77#include <cstring> // for std::strlen, str:memcmp
78#include <exception> // for std::exception_ptr
79#include <ostream> // for std::ostream
80#include <sstream> // for std::ostringstream
81#include <stdexcept> // for std::invalid_argument
82#include <string> // for std::string
83#include <type_traits> // for std::is_pod<>, etc.
84#include <utility> // for std::make_pair
85#include <vector> // for std::vector<> as template args
86
87#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
88#include <memory_resource>
89#endif
90
91#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
92#include <string_view>
93#endif
94
95#ifndef MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
96#ifdef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
97#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
98#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && __cplusplus >= 201703L
99#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
100#elif (!defined(_MSC_VER) || __cplusplus >= 201403L || \
101 (defined(_MSC_VER) && defined(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING) && __cplusplus >= 201403L))
102#if defined(__cpp_lib_experimental_filesystem) && __cpp_lib_experimental_filesystem >= 201406L
103#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
104#elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && __has_include(<experimental/filesystem>)
105#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 1
106#else
107#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
108#endif
109#else
110#define MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM 0
111#endif
112#endif /* MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM */
113
114#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
115#include <experimental/filesystem>
116#elif defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
117#include <filesystem>
118#endif
119
120#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
121#include <span>
122#endif
123
124#if !defined(_MSC_VER) || defined(__clang__)
125#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class API_ATTRIBUTES __VA_ARGS__
126#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class __VA_ARGS__
127#else
128#define MDBX_EXTERN_API_TEMPLATE(API_ATTRIBUTES, ...) extern template class __VA_ARGS__
129#define MDBX_INSTALL_API_TEMPLATE(API_ATTRIBUTES, ...) template class API_ATTRIBUTES __VA_ARGS__
130#endif
131
132#if defined(_MSC_VER) && _MSC_VER >= 1900
133#define MDBX_MSVC_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
134#else
135#define MDBX_MSVC_DECLSPEC_EMPTY_BASES /* nope */
136#endif /* _MSC_VER >= 1900 */
137
138#if __cplusplus >= 201103L
139#include <chrono>
140#include <ratio>
141#endif
142
143#include "mdbx.h"
144
145#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
146 (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
147 (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
148 (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
149#include <bit>
150#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
151#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
152#define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
153#define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
154#define __BYTE_ORDER__ __BYTE_ORDER
155#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
156#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
157#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
158#define __BYTE_ORDER__ _BYTE_ORDER
159#else
160#define __ORDER_LITTLE_ENDIAN__ 1234
161#define __ORDER_BIG_ENDIAN__ 4321
162#if defined(__LITTLE_ENDIAN__) || (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || defined(__ARMEL__) || \
163 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
164 defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || defined(__elbrus_4c__) || defined(__elbrus_8c__) || \
165 defined(__bfin__) || defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \
166 defined(__ia64) || defined(_M_IA64) || defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
167 defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || defined(__WINDOWS__)
168#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
169#elif defined(__BIG_ENDIAN__) || (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || defined(__ARMEB__) || \
170 defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
171 defined(__m68k__) || defined(M68000) || defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
172 defined(__sparc__) || defined(__sparc) || defined(__370__) || defined(__THW_370__) || defined(__s390__) || \
173 defined(__s390x__) || defined(__SYSC_ZARCH__)
174#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
175#endif
176#endif
177#endif /* Byte Order */
178
180#if defined(DOXYGEN)
181#define MDBX_CXX17_CONSTEXPR constexpr
182#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
183 ((defined(_MSC_VER) && _MSC_VER >= 1915) || (defined(__clang__) && __clang_major__ > 5) || \
184 (defined(__GNUC__) && __GNUC__ > 7) || (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
185#define MDBX_CXX17_CONSTEXPR constexpr
186#else
187#define MDBX_CXX17_CONSTEXPR inline
188#endif /* MDBX_CXX17_CONSTEXPR */
189
191#if defined(DOXYGEN)
192#define MDBX_CXX20_CONSTEXPR constexpr
193#elif defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L && \
194 defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
195#define MDBX_CXX20_CONSTEXPR constexpr
196#else
197#define MDBX_CXX20_CONSTEXPR inline
198#endif /* MDBX_CXX20_CONSTEXPR */
199
200#if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
201#define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
202#define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
203#define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
204#define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
205#define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
206#else
207#define MDBX_CXX01_CONSTEXPR_ENUM inline
208#define MDBX_CXX11_CONSTEXPR_ENUM inline
209#define MDBX_CXX14_CONSTEXPR_ENUM inline
210#define MDBX_CXX17_CONSTEXPR_ENUM inline
211#define MDBX_CXX20_CONSTEXPR_ENUM inline
212#endif /* CONSTEXPR_ENUM_FLAGS_OPERATIONS */
213
215#if defined(CONSTEXPR_ASSERT)
216#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
217#elif defined NDEBUG
218#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
219#else
220#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
221#endif /* MDBX_CONSTEXPR_ASSERT */
222
223#ifndef MDBX_LIKELY
224#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
225#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
226#else
227#define MDBX_LIKELY(x) (x)
228#endif
229#endif /* MDBX_LIKELY */
230
231#ifndef MDBX_UNLIKELY
232#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
233#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
234#else
235#define MDBX_UNLIKELY(x) (x)
236#endif
237#endif /* MDBX_UNLIKELY */
238
240#if defined(DOXYGEN)
241#define MDBX_IF_CONSTEXPR constexpr
242#elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
243#define MDBX_IF_CONSTEXPR constexpr
244#else
245#define MDBX_IF_CONSTEXPR
246#endif /* MDBX_IF_CONSTEXPR */
247
248#if defined(DOXYGEN) || (__has_cpp_attribute(fallthrough) && (!defined(__clang__) || __clang__ > 4)) || \
249 __cplusplus >= 201703L
250#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
251#else
252#define MDBX_CXX17_FALLTHROUGH
253#endif /* MDBX_CXX17_FALLTHROUGH */
254
255#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
256#define MDBX_CXX20_LIKELY [[likely]]
257#else
258#define MDBX_CXX20_LIKELY
259#endif /* MDBX_CXX20_LIKELY */
260
261#ifndef MDBX_CXX20_UNLIKELY
262#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && (!defined(__GNUC__) || __GNUC__ > 9))
263#define MDBX_CXX20_UNLIKELY [[unlikely]]
264#else
265#define MDBX_CXX20_UNLIKELY
266#endif
267#endif /* MDBX_CXX20_UNLIKELY */
268
269#ifndef MDBX_HAVE_CXX20_CONCEPTS
270#if defined(__cpp_concepts) && __cpp_concepts >= 202002L && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
271#include <concepts>
272#define MDBX_HAVE_CXX20_CONCEPTS 1
273#elif defined(DOXYGEN)
274#define MDBX_HAVE_CXX20_CONCEPTS 1
275#else
276#define MDBX_HAVE_CXX20_CONCEPTS 0
277#endif /* <concepts> */
278#endif /* MDBX_HAVE_CXX20_CONCEPTS */
279
280#ifndef MDBX_CXX20_CONCEPT
281#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
282#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
283#else
284#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
285#endif
286#endif /* MDBX_CXX20_CONCEPT */
287
288#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
289#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
290#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) static_assert(CONCEPT<TYPE>)
291#else
292#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
293 static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
294#endif
295#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
296
297#ifdef _MSC_VER
298#pragma warning(push, 4)
299#pragma warning(disable : 4127) /* conditional expression is constant */
300#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
301 be used by clients of 'mdbx::BAR' */
302#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
303 base for dll-interface 'mdbx::BAR' */
304/* MSVC is mad and can generate this warning for its own intermediate
305 * automatically generated code, which becomes unreachable after some kinds of
306 * optimization (copy elision, etc). */
307#pragma warning(disable : 4702) /* unreachable code */
308#endif /* _MSC_VER (warnings) */
309
310#if defined(__LCC__) && __LCC__ >= 126
311#pragma diagnostic push
312#if __LCC__ < 127
313#pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
314 appearing in a constant expression `true` */
315#pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
316 appearing in a constant expression `false` */
317#endif
318#endif /* E2K LCC (warnings) */
319
320//------------------------------------------------------------------------------
323namespace mdbx {
324
327
345#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
346using byte = char8_t;
347#else
348// Avoid `std::byte` since it doesn't add features but inconvenient restrictions.
349using byte = unsigned char;
350#endif /* __cpp_char8_t >= 201811*/
351
352#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
353using endian = ::std::endian;
354#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
355enum class endian { little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ };
356#else
357#error "Please use a C++ compiler provides byte order information or C++20 support"
358#endif /* Byte Order enum */
359
368
370static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
371
373static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept;
375static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept;
376
379using legacy_allocator = ::std::string::allocator_type;
380
383#if defined(DOXYGEN)
384#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
385#elif !defined(MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR)
386#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L && \
387 (!defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI)
388#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 1
389#else
390#define MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR 0
391#endif
392#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
393
394#if defined(DOXYGEN) || MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
396using polymorphic_allocator = ::std::pmr::string::allocator_type;
398#else
400#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
401
402struct slice;
404template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
406class env;
407class env_managed;
408class txn;
409class txn_managed;
410class cursor;
411class cursor_managed;
412
414using txnid = uint64_t;
415
417template <class ALLOCATOR = default_allocator>
418using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
419
421#if MDBX_USING_CXX_EXPERIMETAL_FILESYSTEM
422#ifdef _MSC_VER
423namespace filesystem = ::std::experimental::filesystem::v1;
424#else
425namespace filesystem = ::std::experimental::filesystem;
426#endif
427#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
428#elif defined(DOXYGEN) || \
429 (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && defined(__cpp_lib_string_view) && \
430 __cpp_lib_string_view >= 201606L && \
431 (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
432 (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100)) && \
433 (!defined(_MSC_VER) || __cplusplus >= 201703L)
434namespace filesystem = ::std::filesystem;
440#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
441#endif /* MDBX_STD_FILESYSTEM_PATH */
442
443#ifdef MDBX_STD_FILESYSTEM_PATH
445#elif defined(_WIN32) || defined(_WIN64)
446using path = ::std::wstring;
447#else
448using path = ::std::string;
449#endif /* mdbx::path */
450
451#if defined(__SIZEOF_INT128__) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
452#ifndef MDBX_U128_TYPE
453#define MDBX_U128_TYPE __uint128_t
454#endif /* MDBX_U128_TYPE */
455#ifndef MDBX_I128_TYPE
456#define MDBX_I128_TYPE __int128_t
457#endif /* MDBX_I128_TYPE */
458#endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
459
460#if __cplusplus >= 201103L || defined(DOXYGEN)
462using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
463#endif /* Duration for C++11 */
464
467
473 ::std::exception_ptr captured_;
474
475public:
476 exception_thunk() noexcept = default;
479 exception_thunk &operator=(const exception_thunk &) = delete;
480 exception_thunk &operator=(exception_thunk &&) = delete;
481 inline bool is_clean() const noexcept;
482 inline void capture() noexcept;
483 inline void rethrow_captured() const;
484};
485
488 MDBX_error_t code_;
489 inline error &operator=(MDBX_error_t error_code) noexcept;
490
491public:
492 MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
493 error(const error &) = default;
494 error(error &&) = default;
495 error &operator=(const error &) = default;
496 error &operator=(error &&) = default;
497
498 MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a, const error &b) noexcept;
499 MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a, const error &b) noexcept;
500
501 MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
502 MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
503 MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
504 MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
505
507 MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
508
510 const char *what() const noexcept;
511
513 ::std::string message() const;
514
516 MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
518 [[noreturn]] void panic(const char *context_where_when, const char *func_who_what) const noexcept;
519 [[noreturn]] void throw_exception() const;
520 [[noreturn]] static inline void throw_exception(int error_code);
521 inline void throw_on_failure() const;
522 inline void success_or_throw() const;
523 inline void success_or_throw(const exception_thunk &) const;
524 inline void panic_on_failure(const char *context_where, const char *func_who) const noexcept;
525 inline void success_or_panic(const char *context_where, const char *func_who) const noexcept;
526 static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
527 static inline void success_or_throw(MDBX_error_t error_code);
528 static void success_or_throw(int error_code) { success_or_throw(static_cast<MDBX_error_t>(error_code)); }
529 static inline void throw_on_failure(int error_code);
530 static inline bool boolean_or_throw(int error_code);
531 static inline void success_or_throw(int error_code, const exception_thunk &);
532 static inline bool boolean_or_throw(int error_code, const exception_thunk &);
533 static inline void panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept;
534 static inline void success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept;
535};
536
539class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
540 using base = ::std::runtime_error;
541 ::mdbx::error error_;
542
543public:
544 exception(const ::mdbx::error &) noexcept;
545 exception(const exception &) = default;
546 exception(exception &&) = default;
547 exception &operator=(const exception &) = default;
549 virtual ~exception() noexcept;
550 const ::mdbx::error error() const noexcept { return error_; }
551};
552
555 using base = exception;
556
557public:
558 fatal(const ::mdbx::error &) noexcept;
559 fatal(const exception &src) noexcept : fatal(src.error()) {}
560 fatal(exception &&src) noexcept : fatal(src.error()) {}
561 fatal(const fatal &src) noexcept : fatal(src.error()) {}
562 fatal(fatal &&src) noexcept : fatal(src.error()) {}
563 fatal &operator=(fatal &&) = default;
564 fatal &operator=(const fatal &) = default;
565 virtual ~fatal() noexcept;
566};
567
568#define MDBX_DECLARE_EXCEPTION(NAME) \
569 struct LIBMDBX_API_TYPE NAME : public exception { \
570 NAME(const ::mdbx::error &); \
571 virtual ~NAME() noexcept; \
572 }
606#undef MDBX_DECLARE_EXCEPTION
607
610[[noreturn]] LIBMDBX_API void throw_out_range();
614
615static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
616 if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
617 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
618 return bytes;
619}
620
621static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload) {
622 return check_length(check_length(headroom) + check_length(payload));
623}
624
625MDBX_MAYBE_UNUSED static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload, size_t tailroom) {
626 return check_length(check_length(headroom, payload) + check_length(tailroom));
627}
628
630
631//------------------------------------------------------------------------------
632
635
647
648 enum : size_t { max_length = MDBX_MAXDATASIZE };
649
651 MDBX_CXX11_CONSTEXPR slice() noexcept;
652
654 MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
655
657 MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
658
660 template <size_t SIZE> MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
661 MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
662 }
663
664 explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
665
668 template <class CHAR, class T, class A>
669 explicit MDBX_CXX20_CONSTEXPR slice(const ::std::basic_string<CHAR, T, A> &str)
670 : slice(str.data(), str.length() * sizeof(CHAR)) {}
671
673 MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
675 MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
676
677#if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
678 template <typename POD> MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span) : slice(span.begin(), span.end()) {
679 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
680 "Must be a standard layout type!");
681 }
682
683 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
684 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
685 "Must be a standard layout type!");
686 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
688 return ::std::span<const POD>(static_cast<const POD *>(data()), size() / sizeof(POD));
690 }
691
692 template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
693 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
694 "Must be a standard layout type!");
695 if (MDBX_LIKELY(size() % sizeof(POD) == 0))
697 return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
699 }
700
701 MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const { return as_span<const byte>(); }
702 MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
703 MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const { return as_span<const char>(); }
704 MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
705#endif /* __cpp_lib_span >= 202002L */
706
707#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
709 template <class CHAR, class T>
710 MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv) : slice(sv.data(), sv.data() + sv.length()) {}
711
712 template <class CHAR, class T> slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) { sv = {}; }
713#endif /* __cpp_lib_string_view >= 201606L */
714
715 template <size_t SIZE> static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) { return slice(text); }
716
717 template <typename POD> MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
718 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
719 "Must be a standard layout type!");
720 return slice(&pod, sizeof(pod));
721 }
722
723 inline slice &assign(const void *ptr, size_t bytes);
724 inline slice &assign(const slice &src) noexcept;
725 inline slice &assign(const ::MDBX_val &src);
726 inline slice &assign(slice &&src) noexcept;
727 inline slice &assign(::MDBX_val &&src);
728 inline slice &assign(const void *begin, const void *end);
729 template <class CHAR, class T, class ALLOCATOR> slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
730 return assign(str.data(), str.length() * sizeof(CHAR));
731 }
732 inline slice &assign(const char *c_str);
733#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
734 template <class CHAR, class T> slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
735 return assign(view.begin(), view.end());
736 }
737 template <class CHAR, class T> slice &assign(::std::basic_string_view<CHAR, T> &&view) {
738 assign(view);
739 view = {};
740 return *this;
741 }
742#endif /* __cpp_lib_string_view >= 201606L */
743
744 slice &operator=(const slice &) noexcept = default;
745 inline slice &operator=(slice &&src) noexcept;
746 inline slice &operator=(::MDBX_val &&src);
747 operator MDBX_val *() noexcept { return this; }
748 operator const MDBX_val *() const noexcept { return this; }
749
750#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
751 template <class CHAR, class T> slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
752 return assign(view);
753 }
754
755 template <class CHAR, class T> slice &operator=(::std::basic_string_view<CHAR, T> &&view) { return assign(view); }
756
758 template <class CHAR = char, class T = ::std::char_traits<CHAR>>
759 MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T> string_view() const noexcept {
760 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
761 return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
762 }
763
765 template <class CHAR, class T>
766 MDBX_CXX11_CONSTEXPR explicit operator ::std::basic_string_view<CHAR, T>() const noexcept {
767 return this->string_view<CHAR, T>();
768 }
769#endif /* __cpp_lib_string_view >= 201606L */
770
771 template <class CHAR = char, class T = ::std::char_traits<CHAR>, class ALLOCATOR = default_allocator>
772 MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const {
773 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
774 return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(), alloc);
775 }
776
777 template <class CHAR, class T, class ALLOCATOR>
778 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
780 }
781
783 template <class ALLOCATOR = default_allocator>
784 inline string<ALLOCATOR> as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
785 const ALLOCATOR &alloc = ALLOCATOR()) const;
786
789 template <class ALLOCATOR = default_allocator>
790 inline string<ALLOCATOR> as_base58_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
791
794 template <class ALLOCATOR = default_allocator>
795 inline string<ALLOCATOR> as_base64_string(unsigned wrap_width = 0, const ALLOCATOR &alloc = ALLOCATOR()) const;
796
798 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
799 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_hex(bool uppercase = false, unsigned wrap_width = 0,
800 const ALLOCATOR &alloc = ALLOCATOR()) const;
801
804 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
805 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base58(unsigned wrap_width = 0,
806 const ALLOCATOR &alloc = ALLOCATOR()) const;
807
810 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
811 inline buffer<ALLOCATOR, CAPACITY_POLICY> encode_base64(unsigned wrap_width = 0,
812 const ALLOCATOR &alloc = ALLOCATOR()) const;
813
815 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
816 inline buffer<ALLOCATOR, CAPACITY_POLICY> hex_decode(bool ignore_spaces = false,
817 const ALLOCATOR &alloc = ALLOCATOR()) const;
818
821 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
822 inline buffer<ALLOCATOR, CAPACITY_POLICY> base58_decode(bool ignore_spaces = false,
823 const ALLOCATOR &alloc = ALLOCATOR()) const;
824
827 template <class ALLOCATOR = default_allocator, class CAPACITY_POLICY = default_capacity_policy>
828 inline buffer<ALLOCATOR, CAPACITY_POLICY> base64_decode(bool ignore_spaces = false,
829 const ALLOCATOR &alloc = ALLOCATOR()) const;
830
836 MDBX_NOTHROW_PURE_FUNCTION bool is_printable(bool disable_utf8 = false) const noexcept;
837
842 MDBX_NOTHROW_PURE_FUNCTION inline bool is_hex(bool ignore_spaces = false) const noexcept;
843
849 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base58(bool ignore_spaces = false) const noexcept;
850
856 MDBX_NOTHROW_PURE_FUNCTION inline bool is_base64(bool ignore_spaces = false) const noexcept;
857
858#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
859 template <class CHAR, class T> void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
860 static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
861 const auto temp = ::std::basic_string_view<CHAR, T>(*this);
862 *this = view;
863 view = temp;
864 }
865#endif /* __cpp_lib_string_view >= 201606L */
866
868 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
869 MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
870
872 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
873 MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
874
876 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
877 MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
878
880 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
881 MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
882
884 MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
885 MDBX_CXX11_CONSTEXPR void *data() noexcept;
886
888 MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
889 MDBX_CXX11_CONSTEXPR void *end() noexcept;
890
892 MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
893
895 MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
896
898 MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
899
901 MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
902
904 MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
905
907 MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
908
910 MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
911
913 MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
914
916 MDBX_CXX14_CONSTEXPR void clear() noexcept;
917
920 inline void remove_prefix(size_t n) noexcept;
921
924 inline void remove_suffix(size_t n) noexcept;
925
928 inline void safe_remove_prefix(size_t n);
929
932 inline void safe_remove_suffix(size_t n);
933
935 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool starts_with(const slice &prefix) const noexcept;
936
938 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool ends_with(const slice &suffix) const noexcept;
939
942 MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
943
946 MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
947
950 MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
951
954 MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
955
958 MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
959
962 MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
963
966 MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
967
970 MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
971
976 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t hash_value() const noexcept;
977
986 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const slice &a, const slice &b) noexcept;
987
993 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const slice &a,
994 const slice &b) noexcept;
995 friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a, const slice &b) noexcept;
996 friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a, const slice &b) noexcept;
997 friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a, const slice &b) noexcept;
998 friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
999 friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
1000 friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
1001#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1002 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
1003#endif /* __cpp_impl_three_way_comparison */
1004
1006 MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
1007
1010 return slice(/* using special constructor without length checking */ ~size_t(0));
1011 }
1012
1014 MDBX_CXX14_CONSTEXPR static slice null() noexcept { return slice(nullptr, size_t(0)); }
1015
1016 template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1017 static_assert(::std::is_standard_layout<POD>::value && !::std::is_pointer<POD>::value,
1018 "Must be a standard layout type!");
1019 if (MDBX_LIKELY(size() == sizeof(POD)))
1021 POD r;
1022 memcpy(&r, data(), sizeof(r));
1023 return r;
1024 }
1026 }
1027
1028#ifdef MDBX_U128_TYPE
1029 MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const { return as_pod<MDBX_U128_TYPE>(); }
1030#endif /* MDBX_U128_TYPE */
1031 MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1032 MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1033 MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1034 MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1035
1036#ifdef MDBX_I128_TYPE
1037 MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const { return as_pod<MDBX_I128_TYPE>(); }
1038#endif /* MDBX_I128_TYPE */
1039 MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1040 MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1041 MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1042 MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1043
1044#ifdef MDBX_U128_TYPE
1045 MDBX_U128_TYPE as_uint128_adapt() const;
1046#endif /* MDBX_U128_TYPE */
1047 uint64_t as_uint64_adapt() const;
1048 uint32_t as_uint32_adapt() const;
1049 uint16_t as_uint16_adapt() const;
1050 uint8_t as_uint8_adapt() const;
1051
1052#ifdef MDBX_I128_TYPE
1053 MDBX_I128_TYPE as_int128_adapt() const;
1054#endif /* MDBX_I128_TYPE */
1055 int64_t as_int64_adapt() const;
1056 int32_t as_int32_adapt() const;
1057 int16_t as_int16_adapt() const;
1058 int8_t as_int8_adapt() const;
1059
1060protected:
1061 MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept : ::MDBX_val({nullptr, invalid_length}) {}
1062};
1063
1067 bool done;
1068 value_result(const slice &value, bool done) noexcept : value(value), done(done) {}
1069 value_result(const value_result &) noexcept = default;
1070 value_result &operator=(const value_result &) noexcept = default;
1071 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1072 assert(!done || bool(value));
1073 return done;
1074 }
1075};
1076
1078struct pair {
1079 using stl_pair = std::pair<slice, slice>;
1081 MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept : key(key), value(value) {}
1082 MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept : key(couple.first), value(couple.second) {}
1083 MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept { return stl_pair(key, value); }
1084 pair(const pair &) noexcept = default;
1085 pair &operator=(const pair &) noexcept = default;
1086 pair &operator=(pair &&couple) {
1087 key.assign(std::move(couple.key));
1088 value.assign(std::move(couple.value));
1089 return *this;
1090 }
1091 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1092 assert(bool(key) == bool(value));
1093 return key;
1094 }
1096
1097 pair &operator=(const stl_pair &couple) {
1098 key.assign(couple.first);
1099 value.assign(couple.second);
1100 return *this;
1101 }
1103 key.assign(std::move(couple.first));
1104 value.assign(std::move(couple.second));
1105 return *this;
1106 }
1107
1109 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_fast(const pair &a, const pair &b) noexcept;
1110
1112 MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t compare_lexicographically(const pair &a,
1113 const pair &b) noexcept;
1114 friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a, const pair &b) noexcept;
1115 friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a, const pair &b) noexcept;
1116 friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a, const pair &b) noexcept;
1117 friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
1118 friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
1119 friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
1120#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
1121 friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
1122#endif /* __cpp_impl_three_way_comparison */
1123};
1124
1127struct pair_result : public pair {
1128 bool done;
1131 : pair(key, value), done(done) {}
1132 pair_result(const pair_result &) noexcept = default;
1133 pair_result &operator=(const pair_result &) noexcept = default;
1134 MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
1135 assert(!done || (bool(key) && bool(value)));
1136 return done;
1137 }
1138};
1139
1140#if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
1141
1145template <typename T>
1146concept MutableByteProducer = requires(T a, char array[42]) {
1147 { a.is_empty() } -> std::same_as<bool>;
1148 { a.envisage_result_length() } -> std::same_as<size_t>;
1149 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1150};
1151
1155template <typename T>
1156concept ImmutableByteProducer = requires(const T &a, char array[42]) {
1157 { a.is_empty() } -> std::same_as<bool>;
1158 { a.envisage_result_length() } -> std::same_as<size_t>;
1159 { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
1160};
1161
1165template <typename T>
1166concept SliceTranscoder = ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
1167 T(source);
1168 { a.is_erroneous() } -> std::same_as<bool>;
1169};
1170
1171#endif /* MDBX_HAVE_CXX20_CONCEPTS */
1172
1176 const bool uppercase = false;
1177 const unsigned wrap_width = 0;
1182
1184 template <class ALLOCATOR = default_allocator>
1185 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1186
1188 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1189 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1190
1194 const size_t bytes = source.length() << 1;
1195 return wrap_width ? bytes + bytes / wrap_width : bytes;
1196 }
1197
1200 char *write_bytes(char *dest, size_t dest_size) const;
1201
1204 ::std::ostream &output(::std::ostream &out) const;
1205
1208 bool is_empty() const noexcept { return source.empty(); }
1209
1212 bool is_erroneous() const noexcept { return false; }
1213};
1214
1219 const unsigned wrap_width = 0;
1224
1227 template <class ALLOCATOR = default_allocator>
1228 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1229
1232 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1233 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1234
1238 const size_t bytes = (source.length() * 11 + 7) / 8;
1239 return wrap_width ? bytes + bytes / wrap_width : bytes;
1240 }
1241
1244 char *write_bytes(char *dest, size_t dest_size) const;
1245
1248 ::std::ostream &output(::std::ostream &out) const;
1249
1251 bool is_empty() const noexcept { return source.empty(); }
1252
1254 bool is_erroneous() const noexcept { return false; }
1255};
1256
1261 const unsigned wrap_width = 0;
1266
1269 template <class ALLOCATOR = default_allocator>
1270 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1271
1274 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1275 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1276
1280 const size_t bytes = (source.length() + 2) / 3 * 4;
1281 return wrap_width ? bytes + bytes / wrap_width : bytes;
1282 }
1283
1287 char *write_bytes(char *dest, size_t dest_size) const;
1288
1292 ::std::ostream &output(::std::ostream &out) const;
1293
1296 bool is_empty() const noexcept { return source.empty(); }
1297
1300 bool is_erroneous() const noexcept { return false; }
1301};
1302
1306 const bool ignore_spaces = false;
1311
1313 template <class ALLOCATOR = default_allocator>
1314 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1315
1317 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1318 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1319
1322 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return source.length() >> 1; }
1323
1326 char *write_bytes(char *dest, size_t dest_size) const;
1327
1329 bool is_empty() const noexcept { return source.empty(); }
1330
1333 bool is_erroneous() const noexcept;
1334};
1335
1340 const bool ignore_spaces = false;
1345
1348 template <class ALLOCATOR = default_allocator>
1349 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1350
1353 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1354 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1355
1359 return source.length() /* могут быть все нули кодируемые один-к-одному */;
1360 }
1361
1365 char *write_bytes(char *dest, size_t dest_size) const;
1366
1368 bool is_empty() const noexcept { return source.empty(); }
1369
1372 bool is_erroneous() const noexcept;
1373};
1374
1379 const bool ignore_spaces = false;
1384
1387 template <class ALLOCATOR = default_allocator>
1388 inline string<ALLOCATOR> as_string(const ALLOCATOR &alloc = ALLOCATOR()) const;
1389
1392 template <class ALLOCATOR = default_allocator, typename CAPACITY_POLICY = default_capacity_policy>
1393 inline buffer<ALLOCATOR, CAPACITY_POLICY> as_buffer(const ALLOCATOR &alloc = ALLOCATOR()) const;
1394
1397 MDBX_CXX11_CONSTEXPR size_t envisage_result_length() const noexcept { return (source.length() + 3) / 4 * 3; }
1398
1402 char *write_bytes(char *dest, size_t dest_size) const;
1403
1406 bool is_empty() const noexcept { return source.empty(); }
1407
1411 bool is_erroneous() const noexcept;
1412};
1413
1415
1416template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1417#if defined(__cpp_lib_allocator_traits_is_always_equal) && __cpp_lib_allocator_traits_is_always_equal >= 201411L
1418 return ::std::allocator_traits<A>::is_always_equal::value;
1419#else
1420 return ::std::is_empty<A>::value;
1421#endif /* __cpp_lib_allocator_traits_is_always_equal */
1422}
1423
1424template <typename T, typename A = typename T::allocator_type,
1425 bool PoCMA = ::std::allocator_traits<A>::propagate_on_container_move_assignment::value>
1427
1428template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1429 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1430 static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1431 return allocator_is_always_equal<A>() || target->get_allocator() == source.get_allocator();
1432 }
1433 static MDBX_CXX20_CONSTEXPR void propagate(T *, T &) noexcept {}
1434};
1435
1436template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1437 static constexpr bool is_nothrow() noexcept {
1438 return allocator_is_always_equal<A>() || ::std::is_nothrow_move_assignable<A>::value;
1439 }
1440 static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1441 static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1442 target->get_allocator() = ::std::move(source.get_allocator());
1443 }
1444};
1445
1446template <typename T, typename A = typename T::allocator_type,
1447 bool PoCCA = ::std::allocator_traits<A>::propagate_on_container_copy_assignment::value>
1449
1450template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1451 static constexpr bool is_nothrow() noexcept { return false; }
1452 static MDBX_CXX20_CONSTEXPR void propagate(T *, const T &) noexcept {}
1453};
1454
1455template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1456 static constexpr bool is_nothrow() noexcept {
1457 return allocator_is_always_equal<A>() || ::std::is_nothrow_copy_assignable<A>::value;
1458 }
1459 static MDBX_CXX20_CONSTEXPR void propagate(T *target, const T &source) noexcept(is_nothrow()) {
1460 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1461 if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1462 MDBX_CXX20_UNLIKELY target->get_allocator() =
1463 ::std::allocator_traits<A>::select_on_container_copy_construction(source.get_allocator());
1464 } else {
1465 /* gag for buggy compilers */
1466 (void)target;
1467 (void)source;
1468 }
1469 }
1470};
1471
1472template <typename T, typename A = typename T::allocator_type,
1473 bool PoCS = ::std::allocator_traits<A>::propagate_on_container_swap::value>
1475
1476template <typename T, typename A> struct swap_alloc<T, A, false> {
1477 static constexpr bool is_nothrow() noexcept { return allocator_is_always_equal<A>(); }
1478 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1480 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1481 MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1482 } else {
1483 /* gag for buggy compilers */
1484 (void)left;
1485 (void)right;
1486 }
1487 }
1488};
1489
1490template <typename T, typename A> struct swap_alloc<T, A, true> {
1491 static constexpr bool is_nothrow() noexcept {
1492 return allocator_is_always_equal<A>() ||
1493#if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1494 ::std::is_nothrow_swappable<A>() ||
1495#endif /* __cpp_lib_is_swappable >= 201603L */
1496 (::std::is_nothrow_move_constructible<A>::value && ::std::is_nothrow_move_assignable<A>::value);
1497 }
1498 static MDBX_CXX20_CONSTEXPR void propagate(T &left, T &right) noexcept(is_nothrow()) {
1499 if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1500 if (MDBX_UNLIKELY(left.get_allocator() != right.get_allocator()))
1501 MDBX_CXX20_UNLIKELY ::std::swap(left.get_allocator(), right.get_allocator());
1502 } else {
1503 /* gag for buggy compilers */
1504 (void)left;
1505 (void)right;
1506 }
1507 }
1508};
1509
1510} // namespace allocation_aware_details
1511
1513 enum : size_t {
1518 };
1519
1520 static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1521 static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0, "pettiness_threshold must be a power of 2");
1522 static_assert(pettiness_threshold % 2 == 0, "pettiness_threshold must be even");
1523 static_assert(pettiness_threshold >= sizeof(uint64_t), "pettiness_threshold must be > 7");
1524 constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1525 return (value + pettiness_threshold - 1) & pettiness_mask;
1526 }
1527
1528 static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current, const size_t wanna, const size_t inplace) {
1529 static_assert(max_reserve % pettiness_threshold == 0, "max_reserve must be a multiple of pettiness_threshold");
1530 static_assert(max_reserve / 3 > pettiness_threshold, "max_reserve must be > pettiness_threshold * 3");
1531
1532 if (wanna <= inplace && (current <= inplace || current >= std::max(inplace + inplace, size_t(pettiness_threshold))))
1533 return inplace;
1534
1535 if (wanna > current)
1536 /* doubling capacity, but don't made reserve more than max_reserve */
1537 return round(wanna + ::std::min(size_t(max_reserve), current));
1538
1539 if (current - wanna >
1540 /* shrink if reserve will more than half of current or max_reserve,
1541 * but not less than pettiness_threshold */
1542 ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1543 return round(wanna);
1544
1545 /* keep unchanged */
1546 return current;
1547 }
1548};
1549
1551struct buffer_tag {};
1552
1554template <class ALLOCATOR, typename CAPACITY_POLICY>
1556public:
1558#if !defined(_MSC_VER) || _MSC_VER > 1900
1559 using allocator_type = typename ::std::allocator_traits<ALLOCATOR>::template rebind_alloc<uint64_t>;
1560#else
1561 using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1562#endif /* MSVC is mad */
1563 using allocator_traits = ::std::allocator_traits<allocator_type>;
1564 using reservation_policy = CAPACITY_POLICY;
1565 enum : size_t {
1567 max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1570 (alignof(max_align_t) * 2 > size_t(reservation_policy::inplace_storage_size_rounding))
1571 ? alignof(max_align_t) * 2
1574 };
1575
1576private:
1577 friend class txn;
1578 struct silo /* Empty Base Class Optimization */ : public allocator_type {
1579 MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept { return *this; }
1580 MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept { return *this; }
1581
1582 using allocator_pointer = typename allocator_traits::pointer;
1583 using allocator_const_pointer = typename allocator_traits::const_pointer;
1584
1585 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> allocate_storage(size_t bytes) {
1586 assert(bytes >= sizeof(bin));
1587 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1588 static_assert((unit & (unit - 1)) == 0, "size of ALLOCATOR::value_type should be a power of 2");
1589 static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1590 const size_t n = (bytes + unit - 1) / unit;
1591 return ::std::make_pair(allocator_traits::allocate(get_allocator(), n), n * unit);
1592 }
1593
1594 MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr, size_t bytes) {
1595 constexpr size_t unit = sizeof(typename allocator_type::value_type);
1596 assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1597 allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1598 }
1599
1600 MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t> provide_storage(size_t bytes) {
1601 const size_t capacity = bin::advise_capacity(0, bytes);
1602 return bin::is_suitable_for_inplace(capacity) ? ::std::pair<allocator_pointer, size_t>(nullptr, capacity)
1603 : allocate_storage(capacity);
1604 }
1605
1606 static MDBX_CXX17_CONSTEXPR void *to_address(allocator_pointer ptr) noexcept {
1607#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1608 return static_cast<void *>(::std::to_address(ptr));
1609#else
1610 return static_cast<void *>(::std::addressof(*ptr));
1611#endif /* __cpp_lib_to_address */
1612 }
1613
1614 static MDBX_CXX17_CONSTEXPR const void *to_address(allocator_const_pointer ptr) noexcept {
1615#if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1616 return static_cast<const void *>(::std::to_address(ptr));
1617#else
1618 return static_cast<const void *>(::std::addressof(*ptr));
1619#endif /* __cpp_lib_to_address */
1620 }
1621
1622#ifdef _MSC_VER
1623#pragma warning(push)
1624#pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
1625#endif /* _MSC_VER */
1626
1627 union alignas(max_align_t) bin {
1628 struct stub_allocated_holder /* используется только для вычисления (минимального необходимого) размера,
1629 с учетом выравнивания */
1630 {
1631 allocator_pointer stub_ptr_;
1633 };
1634
1636 enum : size_t {
1638 << (sizeof(size_t /* allocated::capacity_bytes_ */) - 1) * CHAR_BIT,
1642 };
1643
1645 byte pad_[inplace_size - sizeof(allocator_pointer)];
1646 size_t bytes_;
1647 };
1648
1650 byte buffer_[inplace_size - sizeof(byte)];
1652 MDBX_CXX11_CONSTEXPR inplace_flag_holder(byte signature) : lastbyte_(signature) {};
1653 };
1654
1655 allocator_pointer allocated_ptr_;
1658
1659 static constexpr size_t inplace_capacity() noexcept { return sizeof(inplace_flag_holder::buffer_); }
1660 static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1661 static_assert((size_t(reservation_policy::inplace_storage_size_rounding) &
1662 (size_t(reservation_policy::inplace_storage_size_rounding) - 1)) == 0,
1663 "CAPACITY_POLICY::inplace_storage_size_rounding must be power of 2");
1664 static_assert(sizeof(bin) == sizeof(inplace_) && sizeof(bin) == sizeof(capacity_), "WTF?");
1665 return capacity_bytes <= inplace_capacity();
1666 }
1667
1668 constexpr bool is_inplace() const noexcept {
1669 static_assert(size_t(inplace_signature_limit) > size_t(max_capacity), "WTF?");
1670 static_assert(std::numeric_limits<size_t>::max() - (std::numeric_limits<size_t>::max() >> CHAR_BIT) ==
1672 "WTF?");
1673 return inplace_.lastbyte_ == lastbyte_inplace_signature;
1674 }
1675 constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1676
1677 template <bool destroy_ptr> MDBX_CXX17_CONSTEXPR byte *make_inplace() noexcept {
1678 if (destroy_ptr) {
1680 /* properly destroy allocator::pointer */
1681 allocated_ptr_.~allocator_pointer();
1682 }
1685 return address();
1686 }
1687
1688 template <bool construct_ptr>
1689 MDBX_CXX17_CONSTEXPR byte *make_allocated(const ::std::pair<allocator_pointer, size_t> &pair) noexcept {
1691 if (construct_ptr) {
1693 new (&allocated_ptr_) allocator_pointer(pair.first);
1694 } else {
1696 allocated_ptr_ = pair.first;
1697 }
1698 capacity_.bytes_ = pair.second;
1699 MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(pair.first) && capacity() == pair.second);
1700 return address();
1701 }
1702
1704 if (::std::is_trivial<allocator_pointer>::value)
1705 /* workaround for "uninitialized" warning from some compilers */
1706 memset(&allocated_ptr_, 0, sizeof(allocated_ptr_));
1707 }
1708
1709 static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current, const size_t wanna) {
1710 if (MDBX_UNLIKELY(wanna > max_capacity))
1711 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1712
1713 const size_t advised = reservation_policy::advise(current, wanna, inplace_capacity());
1714 assert(advised >= wanna);
1715 return ::std::min(size_t(max_capacity), ::std::max(inplace_capacity(), advised));
1716 }
1717
1718 constexpr bool is_inplace(const void *ptr) const noexcept {
1719 return size_t(static_cast<const byte *>(ptr) - inplace_.buffer_) < inplace_capacity();
1720 }
1721
1722 constexpr const byte *address() const noexcept {
1723 return is_inplace() ? inplace_.buffer_ : static_cast<const byte *>(to_address(allocated_ptr_));
1724 }
1726 return is_inplace() ? inplace_.buffer_ : static_cast<byte *>(to_address(allocated_ptr_));
1727 }
1728 constexpr size_t capacity() const noexcept { return is_inplace() ? inplace_capacity() : capacity_.bytes_; }
1729 } bin_;
1730
1731#ifdef _MSC_VER
1732#pragma warning(pop)
1733#endif /* _MSC_VER */
1734
1735 constexpr bool is_inplace(const void *ptr) const noexcept { return bin_.is_inplace(ptr); }
1736
1737 MDBX_CXX20_CONSTEXPR void release() noexcept {
1738 if (bin_.is_allocated()) {
1739 deallocate_storage(bin_.allocated_ptr_, bin_.capacity_.bytes_);
1740 /* properly destroy allocator::pointer */
1741 bin_.allocated_ptr_.~allocator_pointer();
1742 bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1743 }
1744 }
1745
1746 template <bool external_content>
1747 MDBX_CXX20_CONSTEXPR void *reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1748 const void *const content, const size_t length) {
1749 assert(wanna_capacity >= wanna_headroom + length);
1750 const size_t old_capacity = bin_.capacity();
1751 const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity);
1752 if (MDBX_LIKELY(new_capacity == old_capacity))
1754 assert(bin_.is_inplace() == bin::is_suitable_for_inplace(new_capacity));
1755 byte *const new_place = bin_.address() + wanna_headroom;
1756 if (MDBX_LIKELY(length))
1758 if (external_content)
1759 memcpy(new_place, content, length);
1760 else {
1761 const size_t old_headroom = bin_.address() - static_cast<const byte *>(content);
1762 assert(old_capacity >= old_headroom + length);
1763 if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1764 MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content, length);
1765 }
1766 }
1767 return new_place;
1768 }
1769
1770 if (bin::is_suitable_for_inplace(new_capacity)) {
1771 assert(bin_.is_allocated());
1772 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1773 byte *const new_place = bin_.template make_inplace<true>() + wanna_headroom;
1774 if (MDBX_LIKELY(length))
1775 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1776 deallocate_storage(old_allocated, old_capacity);
1777 return new_place;
1778 }
1779
1780 if (bin_.is_inplace()) {
1781 const auto pair = allocate_storage(new_capacity);
1782 assert(pair.second >= new_capacity);
1783 byte *const new_place = static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1784 if (MDBX_LIKELY(length))
1785 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1786 bin_.template make_allocated<true>(pair);
1787 return new_place;
1788 }
1789
1790 const auto old_allocated = ::std::move(bin_.allocated_ptr_);
1791 if (external_content)
1792 deallocate_storage(old_allocated, old_capacity);
1793 const auto pair = allocate_storage(new_capacity);
1794 assert(pair.second >= new_capacity);
1795 byte *const new_place = bin_.template make_allocated<false>(pair) + wanna_headroom;
1796 if (MDBX_LIKELY(length))
1797 MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1798 if (!external_content)
1799 deallocate_storage(old_allocated, old_capacity);
1800 return new_place;
1801 }
1802
1803 MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1804 assert(capacity() >= offset);
1805 return bin_.address() + offset;
1806 }
1807 MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1808 assert(capacity() >= offset);
1809 return bin_.address() + offset;
1810 }
1811 MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr, size_t length) {
1812 assert(capacity() >= offset + length);
1813 return static_cast<byte *>(memcpy(get(offset), ptr, length));
1814 }
1815
1816 //--------------------------------------------------------------------------
1817
1818 MDBX_CXX20_CONSTEXPR silo(const allocator_type &alloc = allocator_type()) noexcept : allocator_type(alloc) {}
1819 MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc = allocator_type()) : silo(alloc) {
1820 if (!bin::is_suitable_for_inplace(capacity))
1821 bin_.template make_allocated<true>(provide_storage(capacity));
1822 }
1823
1824 silo(silo &&other) = delete;
1826 silo(silo &&other, bool is_reference = false) noexcept(::std::is_nothrow_move_constructible<allocator_type>::value)
1827 : allocator_type(::std::move(other.get_allocator())) {
1828 if (!is_reference) {
1829 if (other.bin_.is_inplace()) {
1830 memcpy(&bin_, &other.bin_, sizeof(bin));
1831 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1832 } else {
1833 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1834 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1835 /* properly destroy allocator::pointer.
1836 *
1837 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1838 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1839 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1840 * from the 11th). */
1841 /* coverity[use_after_move] */
1842 other.bin_.allocated_ptr_.~allocator_pointer();
1843 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1844 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1845 }
1846 }
1847 }
1848
1849 MDBX_CXX17_CONSTEXPR bool move(silo &&other) noexcept {
1850 if (other.bin_.is_inplace()) {
1851 memcpy(&bin_, &other.bin_, sizeof(bin));
1852 MDBX_CONSTEXPR_ASSERT(bin_.is_inplace());
1853 return /* buffer's slice fixup is needed */ true;
1854 }
1855 new (&bin_.allocated_ptr_) allocator_pointer(::std::move(other.bin_.allocated_ptr_));
1856 bin_.capacity_.bytes_ = other.bin_.capacity_.bytes_;
1857 /* properly destroy allocator::pointer.
1858 *
1859 * CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
1860 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
1861 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting
1862 * from the 11th). */
1863 /* coverity[use_after_move] */
1864 other.bin_.allocated_ptr_.~allocator_pointer();
1865 other.bin_.inplace_.lastbyte_ = bin::lastbyte_inplace_signature;
1866 MDBX_CONSTEXPR_ASSERT(bin_.is_allocated() && other.bin_.is_inplace());
1867 return false;
1868 }
1869
1870 MDBX_CXX17_CONSTEXPR bool assign_move(silo &&other, bool is_reference) noexcept {
1871 release();
1872 if (!allocation_aware_details::move_assign_alloc<silo, allocator_type>::is_moveable(this, other))
1873 allocation_aware_details::move_assign_alloc<silo, allocator_type>::propagate(this, other);
1874 return is_reference ? false : move(std::move(other));
1875 }
1876
1877 static MDBX_CXX20_CONSTEXPR std::pair<bool, bool>
1878 exchange(silo &left, const bool left_is_reference, silo &right, const bool right_is_reference) noexcept(
1879 allocation_aware_details::swap_alloc<silo, allocator_type>::is_nothrow()) {
1880 allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(left, right);
1881 bool left_need_fixup = false, right_need_fixup = false;
1882 if (left_is_reference || right_is_reference) {
1883 left_need_fixup = !right_is_reference && left.move(std::move(right));
1884 right_need_fixup = !left_is_reference && right.move(std::move(left));
1885 } else {
1886 silo temp(std::move(left), false);
1887 left_need_fixup = left.move(std::move(right));
1888 right_need_fixup = right.move(std::move(temp));
1889 }
1890 return std::make_pair(left_need_fixup, right_need_fixup);
1891 }
1892
1893 MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr, size_t length,
1894 const allocator_type &alloc = allocator_type())
1895 : silo(capacity, alloc) {
1896 assert(capacity >= headroom + length);
1897 if (length)
1898 put(headroom, ptr, length);
1899 }
1900
1901 MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length, const allocator_type &alloc = allocator_type())
1902 : silo(length, 0, ptr, length, alloc) {}
1903
1904 ~silo() { release(); }
1905
1906 //--------------------------------------------------------------------------
1907
1908 MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr, size_t length, size_t tailroom) {
1909 return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
1910 }
1911
1912 MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) { return assign(0, ptr, length, 0); }
1913
1914 MDBX_CXX20_CONSTEXPR void *clear() { return reshape<true>(0, 0, nullptr, 0); }
1915 MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, size_t headroom) {
1916 return reshape<false>(whole_capacity, headroom, nullptr, 0);
1917 }
1918
1919 MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) {
1920 content.iov_base = reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
1921 }
1922
1923 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR size_t capacity() const noexcept { return bin_.capacity(); }
1924 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR const void *data(size_t offset = 0) const noexcept {
1925 return get(offset);
1926 }
1927 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX11_CONSTEXPR void *data(size_t offset = 0) noexcept { return get(offset); }
1928 };
1929
1930 MDBX_CXX14_CONSTEXPR void fixup_import(const typename silo::bin &src) noexcept {
1931 auto ptr = inherited::byte_ptr();
1932 if (src.is_inplace(ptr)) {
1933 MDBX_CONSTEXPR_ASSERT(silo_.bin_.is_inplace());
1934 intptr_t offset = &silo_.bin_.inplace_.buffer_[0] - &src.inplace_.buffer_[0];
1935 iov_base = ptr + offset;
1936 MDBX_CONSTEXPR_ASSERT(is_freestanding());
1937 }
1938 }
1939
1940 silo silo_;
1941
1942 void insulate() {
1943 assert(is_reference());
1944 iov_base = silo_.assign(iov_base, iov_len);
1945 }
1946
1947 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_begin() const noexcept {
1948 return static_cast<const byte *>(silo_.data());
1949 }
1950
1951 MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX20_CONSTEXPR const byte *silo_end() const noexcept {
1952 return silo_begin() + silo_.capacity();
1953 }
1954
1955 struct data_preserver : public exception_thunk {
1956 buffer data;
1957 data_preserver(allocator_type &alloc) : data(alloc) {}
1958 static int callback(void *context, MDBX_val *target, const void *src, size_t bytes) noexcept {
1959 auto self = static_cast<data_preserver *>(context);
1960 assert(self->is_clean());
1961 assert(&self->data == target);
1962 (void)target;
1963 try {
1964 self->data.assign(src, bytes, false);
1965 return MDBX_RESULT_FALSE;
1966 } catch (... /* capture any exception to rethrow it over C code */) {
1967 self->capture();
1968 return MDBX_RESULT_TRUE;
1969 }
1970 }
1971 MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept { return callback; }
1972 MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept { return data; }
1973 MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
1974 };
1975
1976public:
1979
1983
1984 static constexpr bool is_swap_nothrow() noexcept { return swap_alloc::is_nothrow(); }
1985
1987 MDBX_CXX20_CONSTEXPR allocator_type get_allocator() const { return silo_.get_allocator(); }
1988
1992 static_assert(size_t(-intptr_t(max_length)) > max_length, "WTF?");
1993 return size_t(inherited::byte_ptr() - silo_begin()) < silo_.capacity();
1994 }
1995
2000 return silo_.is_inplace(inherited::data());
2001 }
2002
2006
2009 return is_freestanding() ? silo_.capacity() : 0;
2010 }
2011
2015 return is_freestanding() ? inherited::byte_ptr() - silo_begin() : 0;
2016 }
2017
2021 return is_freestanding() ? silo_end() - inherited::end_byte_ptr() : 0;
2022 }
2023
2025 MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept { return inherited::byte_ptr(); }
2026
2028 MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept { return inherited::end_byte_ptr(); }
2029
2036
2041 return const_cast<byte *>(inherited::end_byte_ptr());
2042 }
2043
2045 MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept { return inherited::char_ptr(); }
2046
2048 MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept { return inherited::end_char_ptr(); }
2049
2054 return const_cast<char *>(inherited::char_ptr());
2055 }
2056
2061 return const_cast<char *>(inherited::end_char_ptr());
2062 }
2063
2065 MDBX_CXX11_CONSTEXPR const void *data() const noexcept { return inherited::data(); }
2066
2068 MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return inherited::end(); }
2069
2072 MDBX_CXX11_CONSTEXPR void *data() noexcept {
2074 return const_cast<void *>(inherited::data());
2075 }
2076
2079 MDBX_CXX11_CONSTEXPR void *end() noexcept {
2081 return const_cast<void *>(inherited::end());
2082 }
2083
2088
2095
2098 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2099 return set_length(static_cast<const char *>(ptr) - char_ptr());
2100 }
2101
2106 if (is_reference())
2107 insulate();
2108 }
2109
2110 MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2111 MDBX_CXX20_CONSTEXPR buffer(const allocator_type &alloc) noexcept : silo_(alloc) {}
2112 MDBX_CXX20_CONSTEXPR buffer(const struct slice &src, bool make_reference,
2113 const allocator_type &alloc = allocator_type());
2114
2116 buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc = allocator_type())
2117 : buffer(inherited(ptr, bytes), make_reference, alloc) {}
2118
2119 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2120 template <class CHAR, class T, class A> buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2121
2122 buffer(const char *c_str, bool make_reference, const allocator_type &alloc = allocator_type())
2123 : buffer(inherited(c_str), make_reference, alloc) {}
2124
2125#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2126 template <class CHAR, class T>
2127 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2128 const allocator_type &alloc = allocator_type())
2129 : buffer(inherited(view), make_reference, alloc) {}
2130#endif /* __cpp_lib_string_view >= 201606L */
2131
2133 buffer(const struct slice &src, const allocator_type &alloc = allocator_type())
2134 : buffer(src, src.empty() || src.is_null(), alloc) {}
2135
2137 buffer(const buffer &src)
2138 : buffer(src, allocator_traits::select_on_container_copy_construction(src.get_allocator())) {}
2139
2141 buffer(const void *ptr, size_t bytes, const allocator_type &alloc = allocator_type())
2142 : buffer(inherited(ptr, bytes), alloc) {}
2143
2144 template <class CHAR, class T, class A>
2145 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string<CHAR, T, A> &str,
2146 const allocator_type &alloc = allocator_type())
2147 : buffer(inherited(str), alloc) {}
2148
2150 buffer(const char *c_str, const allocator_type &alloc = allocator_type()) : buffer(inherited(c_str), alloc) {}
2151
2152#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2153 template <class CHAR, class T>
2154 MDBX_CXX20_CONSTEXPR buffer(const ::std::basic_string_view<CHAR, T> &view,
2155 const allocator_type &alloc = allocator_type())
2156 : buffer(inherited(view), alloc) {}
2157#endif /* __cpp_lib_string_view >= 201606L */
2158
2159 buffer(size_t head_room, size_t tail_room, const allocator_type &alloc = allocator_type())
2160 : silo_(check_length(head_room, tail_room), alloc) {
2161 iov_base = silo_.get();
2162 assert(iov_len == 0);
2163 }
2164
2165 buffer(size_t capacity, const allocator_type &alloc = allocator_type()) : silo_(check_length(capacity), alloc) {
2166 iov_base = silo_.get();
2167 assert(iov_len == 0);
2168 }
2169
2170 buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc = allocator_type())
2171 : silo_(check_length(head_room, src.length(), tail_room), alloc) {
2172 iov_base = memcpy(silo_.get(), src.data(), iov_len = src.length());
2173 }
2174
2175 inline buffer(const txn &transaction, const slice &src, const allocator_type &alloc = allocator_type());
2176
2177 buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2178 : inherited(/* no move here */ src), silo_(::std::move(src.silo_), src.is_reference()) {
2179 /* CoverityScan issues an erroneous warning here about using an uninitialized object. Which is not true,
2180 * since in C++ (unlike Rust) an object remains initialized after a move-assignment operation; Moreover,
2181 * a destructor will be called for such an object (this is explicitly stated in all C++ standards, starting from the
2182 * 11th). */
2183 /* coverity[use_after_move] */
2184 fixup_import(src.silo_.bin_);
2185 src.invalidate();
2186 }
2187
2189 MDBX_CXX14_CONSTEXPR static buffer null() noexcept { return buffer(inherited::null()); }
2190
2193
2194 template <typename POD>
2195 static buffer wrap(const POD &pod, bool make_reference = false, const allocator_type &alloc = allocator_type()) {
2196 return buffer(inherited::wrap(pod), make_reference, alloc);
2197 }
2198
2200 static buffer hex(const slice &source, bool uppercase = false, unsigned wrap_width = 0,
2201 const allocator_type &alloc = allocator_type()) {
2202 return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2203 }
2204
2207 static buffer base58(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2208 return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2209 }
2210
2212 static buffer base64(const slice &source, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2213 return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2214 }
2215
2217 template <typename POD>
2218 static buffer hex(const POD &pod, bool uppercase = false, unsigned wrap_width = 0,
2219 const allocator_type &alloc = allocator_type()) {
2220 return hex(inherited::wrap(pod), uppercase, wrap_width, alloc);
2221 }
2222
2225 template <typename POD>
2226 static buffer base58(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2227 return base58(inherited::wrap(pod), wrap_width, alloc);
2228 }
2229
2232 template <typename POD>
2233 static buffer base64(const POD &pod, unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) {
2234 return base64(inherited::wrap(pod), wrap_width, alloc);
2235 }
2236
2238 buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2239 const allocator_type &alloc = allocator_type()) const {
2240 return inherited::template encode_hex<ALLOCATOR, CAPACITY_POLICY>(uppercase, wrap_width, alloc);
2241 }
2242
2245 buffer encode_base58(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2246 return inherited::template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2247 }
2248
2250 buffer encode_base64(unsigned wrap_width = 0, const allocator_type &alloc = allocator_type()) const {
2251 return inherited::template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width, alloc);
2252 }
2253
2255 static buffer hex_decode(const slice &source, bool ignore_spaces = false,
2256 const allocator_type &alloc = allocator_type()) {
2257 return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2258 }
2259
2262 static buffer base58_decode(const slice &source, bool ignore_spaces = false,
2263 const allocator_type &alloc = allocator_type()) {
2264 return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2265 }
2266
2269 static buffer base64_decode(const slice &source, bool ignore_spaces = false,
2270 const allocator_type &alloc = allocator_type()) {
2271 return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces, alloc);
2272 }
2273
2276 buffer hex_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2277 return hex_decode(*this, ignore_spaces, alloc);
2278 }
2279
2282 buffer base58_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2283 return base58_decode(*this, ignore_spaces, alloc);
2284 }
2285
2288 buffer base64_decode(bool ignore_spaces = false, const allocator_type &alloc = allocator_type()) const {
2289 return base64_decode(*this, ignore_spaces, alloc);
2290 }
2291
2293 void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2294 wanna_headroom = ::std::min(
2295 ::std::max(headroom(), wanna_headroom),
2296 (wanna_headroom < max_length - pettiness_threshold) ? wanna_headroom + pettiness_threshold : wanna_headroom);
2297 wanna_tailroom = ::std::min(
2298 ::std::max(tailroom(), wanna_tailroom),
2299 (wanna_tailroom < max_length - pettiness_threshold) ? wanna_tailroom + pettiness_threshold : wanna_tailroom);
2300 const size_t wanna_capacity = check_length(wanna_headroom, length(), wanna_tailroom);
2301 silo_.resize(wanna_capacity, wanna_headroom, *this);
2302 assert(headroom() >= wanna_headroom && headroom() <= wanna_headroom + pettiness_threshold);
2303 assert(tailroom() >= wanna_tailroom && tailroom() <= wanna_tailroom + pettiness_threshold);
2304 }
2305
2307 void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2308
2310 void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2311
2312 buffer &assign_reference(const void *ptr, size_t bytes) {
2313 silo_.clear();
2315 return *this;
2316 }
2317
2318 buffer &assign_freestanding(const void *ptr, size_t bytes) {
2319 inherited::assign(silo_.assign(static_cast<const typename silo::value_type *>(ptr), check_length(bytes)), bytes);
2320 return *this;
2321 }
2322
2323 MDBX_CXX20_CONSTEXPR void swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2324 const auto pair = silo::exchange(silo_, is_reference(), other.silo_, other.is_reference());
2325 std::swap(iov_base, other.iov_base);
2326 std::swap(iov_len, other.iov_len);
2327 if (pair.first)
2328 fixup_import(other.silo_.bin_);
2329 if (pair.second)
2330 other.fixup_import(silo_.bin_);
2331 }
2332
2333 MDBX_CXX20_CONSTEXPR friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow()) {
2334 left.swap(right);
2335 }
2336
2337 static buffer clone(const buffer &src, const allocator_type &alloc = allocator_type()) {
2338 return buffer(src.headroom(), src, src.tailroom(), alloc);
2339 }
2340
2342 return buffer(slice(), !is_inplace(), allocator_traits::select_on_container_copy_construction(get_allocator()));
2343 }
2344
2346 const size_t whole_capacity = check_length(headroom, src.length(), tailroom);
2347 invalidate();
2348 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2349 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2350 MDBX_CXX20_UNLIKELY {
2351 silo_.release();
2353 }
2354 }
2355
2356 iov_base = silo_.template reshape<true>(whole_capacity, headroom, src.data(), src.length());
2357 iov_len = src.length();
2358 return *this;
2359 }
2360
2361 MDBX_CXX20_CONSTEXPR buffer &assign(const buffer &src, bool make_reference = false) {
2362 invalidate();
2363 if MDBX_IF_CONSTEXPR (!allocation_aware_details::template allocator_is_always_equal<allocator_type>()) {
2364 if (MDBX_UNLIKELY(silo_.get_allocator() != src.silo_.get_allocator()))
2365 MDBX_CXX20_UNLIKELY {
2366 silo_.release();
2368 }
2369 }
2370
2371 if (make_reference) {
2372 silo_.release();
2373 iov_base = src.iov_base;
2374 } else {
2375 iov_base = silo_.template reshape<true>(src.length(), 0, src.data(), src.length());
2376 }
2377 iov_len = src.length();
2378 return *this;
2379 }
2380
2383 const bool is_reference = src.is_reference();
2384 inherited::assign(std::move(src));
2385 if (silo_.assign_move(std::move(src.silo_), is_reference))
2386 fixup_import(src.silo_.bin_);
2387 return *this;
2388 }
2389
2390 buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2391 return make_reference ? assign_reference(ptr, bytes) : assign_freestanding(ptr, bytes);
2392 }
2393
2394 buffer &assign(const struct slice &src, bool make_reference = false) {
2395 return assign(src.data(), src.length(), make_reference);
2396 }
2397
2398 buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2399 return assign(src.iov_base, src.iov_len, make_reference);
2400 }
2401
2402 buffer &assign(struct slice &&src, bool make_reference = false) {
2403 assign(src.data(), src.length(), make_reference);
2404 src.invalidate();
2405 return *this;
2406 }
2407
2408 buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2409 assign(src.iov_base, src.iov_len, make_reference);
2410 src.iov_base = nullptr;
2411 return *this;
2412 }
2413
2414 buffer &assign(const void *begin, const void *end, bool make_reference = false) {
2415 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin), make_reference);
2416 }
2417
2418 template <class CHAR, class T, class A>
2419 buffer &assign(const ::std::basic_string<CHAR, T, A> &str, bool make_reference = false) {
2420 return assign(str.data(), str.length(), make_reference);
2421 }
2422
2423 buffer &assign(const char *c_str, bool make_reference = false) {
2424 return assign(c_str, strlen(c_str), make_reference);
2425 }
2426
2427#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2428 template <class CHAR, class T>
2429 buffer &assign(const ::std::basic_string_view<CHAR, T> &view, bool make_reference = false) {
2430 return assign(view.data(), view.length(), make_reference);
2431 }
2432
2433 template <class CHAR, class T> buffer &assign(::std::basic_string_view<CHAR, T> &&view, bool make_reference = false) {
2434 assign(view.data(), view.length(), make_reference);
2435 view = {};
2436 return *this;
2437 }
2438#endif /* __cpp_lib_string_view >= 201606L */
2439
2440 buffer &operator=(const buffer &src) { return assign(src); }
2441
2442 buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) { return assign(::std::move(src)); }
2443
2444 buffer &operator=(const struct slice &src) { return assign(src); }
2445
2446 buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2447
2448#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2449 template <class CHAR, class T> buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2450 return assign(view.begin(), view.length());
2451 }
2452#endif /* __cpp_lib_string_view >= 201606L */
2453
2454 template <class CHAR, class T, class A>
2455 MDBX_CXX20_CONSTEXPR explicit operator ::std::basic_string<CHAR, T, A>() const {
2456 return as_string<CHAR, T, A>();
2457 }
2458
2460 void clear() noexcept { inherited::assign(silo_.clear(), size_t(0)); }
2461
2463 void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2464 inherited::assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2465 }
2466
2468 void shrink_to_fit() { silo_.resize(length(), 0, *this); }
2469
2470 buffer &append(const void *src, size_t bytes) {
2471 if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2472 MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2473 memcpy(end_byte_ptr(), src, bytes);
2474 iov_len += bytes;
2475 return *this;
2476 }
2477
2478 buffer &append(const byte c) {
2479 if (MDBX_UNLIKELY(tailroom() < 1))
2480 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2481 *end_byte_ptr() = c;
2482 iov_len += 1;
2483 return *this;
2484 }
2485
2486 buffer &append(const struct slice &chunk) { return append(chunk.data(), chunk.size()); }
2487
2488 buffer &add_header(const void *src, size_t bytes) {
2489 if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2490 MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2491 iov_base = memcpy(byte_ptr() - bytes, src, bytes);
2492 iov_len += bytes;
2493 return *this;
2494 }
2495
2496 buffer &add_header(const struct slice &chunk) { return add_header(chunk.data(), chunk.size()); }
2497
2498 template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)> buffer &append_producer(PRODUCER &producer) {
2499 const size_t wanna_bytes = producer.envisage_result_length();
2500 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2501 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2502 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2503 }
2504
2505 template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)> buffer &append_producer(const PRODUCER &producer) {
2506 const size_t wanna_bytes = producer.envisage_result_length();
2507 if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2508 MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2509 return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2510 }
2511
2512 buffer &append_hex(const struct slice &data, bool uppercase = false, unsigned wrap_width = 0) {
2513 return append_producer(to_hex(data, uppercase, wrap_width));
2514 }
2515
2516 buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2517 return append_producer(to_base58(data, wrap_width));
2518 }
2519
2520 buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2521 return append_producer(to_base64(data, wrap_width));
2522 }
2523
2524 buffer &append_decoded_hex(const struct slice &data, bool ignore_spaces = false) {
2525 return append_producer(from_hex(data, ignore_spaces));
2526 }
2527
2528 buffer &append_decoded_base58(const struct slice &data, bool ignore_spaces = false) {
2529 return append_producer(from_base58(data, ignore_spaces));
2530 }
2531
2532 buffer &append_decoded_base64(const struct slice &data, bool ignore_spaces = false) {
2533 return append_producer(from_base64(data, ignore_spaces));
2534 }
2535
2536 buffer &append_u8(uint_fast8_t u8) {
2537 if (MDBX_UNLIKELY(tailroom() < 1))
2538 MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2539 *end_byte_ptr() = uint8_t(u8);
2540 iov_len += 1;
2541 return *this;
2542 }
2543
2544 buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2545
2546 buffer &append_u16(uint_fast16_t u16) {
2547 if (MDBX_UNLIKELY(tailroom() < 2))
2548 MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2549 const auto ptr = end_byte_ptr();
2550 ptr[0] = uint8_t(u16);
2551 ptr[1] = uint8_t(u16 >> 8);
2552 iov_len += 2;
2553 return *this;
2554 }
2555
2556 buffer &append_u24(uint_fast32_t u24) {
2557 if (MDBX_UNLIKELY(tailroom() < 3))
2558 MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2559 const auto ptr = end_byte_ptr();
2560 ptr[0] = uint8_t(u24);
2561 ptr[1] = uint8_t(u24 >> 8);
2562 ptr[2] = uint8_t(u24 >> 16);
2563 iov_len += 3;
2564 return *this;
2565 }
2566
2567 buffer &append_u32(uint_fast32_t u32) {
2568 if (MDBX_UNLIKELY(tailroom() < 4))
2569 MDBX_CXX20_UNLIKELY reserve_tailroom(4);
2570 const auto ptr = end_byte_ptr();
2571 ptr[0] = uint8_t(u32);
2572 ptr[1] = uint8_t(u32 >> 8);
2573 ptr[2] = uint8_t(u32 >> 16);
2574 ptr[3] = uint8_t(u32 >> 24);
2575 iov_len += 4;
2576 return *this;
2577 }
2578
2579 buffer &append_u48(uint_fast64_t u48) {
2580 if (MDBX_UNLIKELY(tailroom() < 6))
2581 MDBX_CXX20_UNLIKELY reserve_tailroom(6);
2582 const auto ptr = end_byte_ptr();
2583 ptr[0] = uint8_t(u48);
2584 ptr[1] = uint8_t(u48 >> 8);
2585 ptr[2] = uint8_t(u48 >> 16);
2586 ptr[3] = uint8_t(u48 >> 24);
2587 ptr[4] = uint8_t(u48 >> 32);
2588 ptr[5] = uint8_t(u48 >> 40);
2589 iov_len += 6;
2590 return *this;
2591 }
2592
2593 buffer &append_u64(uint_fast64_t u64) {
2594 if (MDBX_UNLIKELY(tailroom() < 8))
2595 MDBX_CXX20_UNLIKELY reserve_tailroom(8);
2596 const auto ptr = end_byte_ptr();
2597 ptr[0] = uint8_t(u64);
2598 ptr[1] = uint8_t(u64 >> 8);
2599 ptr[2] = uint8_t(u64 >> 16);
2600 ptr[3] = uint8_t(u64 >> 24);
2601 ptr[4] = uint8_t(u64 >> 32);
2602 ptr[5] = uint8_t(u64 >> 40);
2603 ptr[6] = uint8_t(u64 >> 48);
2604 ptr[7] = uint8_t(u64 >> 56);
2605 iov_len += 8;
2606 return *this;
2607 }
2608
2609 //----------------------------------------------------------------------------
2610
2611 template <size_t SIZE> static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
2612 return buffer(inherited(text), make_reference);
2613 }
2614
2615#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2616 template <class CHAR, class T>
2617 static buffer key_from(const ::std::basic_string_view<CHAR, T> &src, bool make_reference = false) {
2618 return buffer(src, make_reference);
2619 }
2620#endif /* __cpp_lib_string_view >= 201606L */
2621
2622 static buffer key_from(const char *src, bool make_reference = false) { return buffer(src, make_reference); }
2623
2624 template <class CHAR, class T, class A>
2625 static buffer key_from(const ::std::basic_string<CHAR, T, A> &src, bool make_reference = false) {
2626 return buffer(src, make_reference);
2627 }
2628
2629 static buffer key_from(buffer &&src) noexcept { return buffer(::std::move(src)); }
2630
2631 static buffer key_from_double(const double ieee754_64bit) { return wrap(::mdbx_key_from_double(ieee754_64bit)); }
2632
2633 static buffer key_from(const double ieee754_64bit) { return key_from_double(ieee754_64bit); }
2634
2635 static buffer key_from(const double *ieee754_64bit) { return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit)); }
2636
2637 static buffer key_from_u64(const uint64_t unsigned_int64) { return wrap(unsigned_int64); }
2638
2639 static buffer key_from(const uint64_t unsigned_int64) { return key_from_u64(unsigned_int64); }
2640
2641 static buffer key_from_i64(const int64_t signed_int64) { return wrap(::mdbx_key_from_int64(signed_int64)); }
2642
2643 static buffer key_from(const int64_t signed_int64) { return key_from_i64(signed_int64); }
2644
2645 static buffer key_from_jsonInteger(const int64_t json_integer) {
2646 return wrap(::mdbx_key_from_jsonInteger(json_integer));
2647 }
2648
2649 static buffer key_from_float(const float ieee754_32bit) { return wrap(::mdbx_key_from_float(ieee754_32bit)); }
2650
2651 static buffer key_from(const float ieee754_32bit) { return key_from_float(ieee754_32bit); }
2652
2653 static buffer key_from(const float *ieee754_32bit) { return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit)); }
2654
2655 static buffer key_from_u32(const uint32_t unsigned_int32) { return wrap(unsigned_int32); }
2656
2657 static buffer key_from(const uint32_t unsigned_int32) { return key_from_u32(unsigned_int32); }
2658
2659 static buffer key_from_i32(const int32_t signed_int32) { return wrap(::mdbx_key_from_int32(signed_int32)); }
2660
2661 static buffer key_from(const int32_t signed_int32) { return key_from_i32(signed_int32); }
2662
2663 const slice &slice() const noexcept { return *this; }
2664};
2665
2666template <typename ALLOCATOR, typename CAPACITY_POLICY> struct buffer_pair_spec {
2670 using reservation_policy = CAPACITY_POLICY;
2671 using stl_pair = ::std::pair<buffer_type, buffer_type>;
2673
2676 buffer_pair_spec(const allocator_type &alloc) noexcept : key(alloc), value(alloc) {}
2677
2679 : key(key, alloc), value(value, alloc) {}
2680 buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference,
2681 const allocator_type &alloc = allocator_type())
2682 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2683
2685 : buffer_pair_spec(pair.first, pair.second, alloc) {}
2686 buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2687 : buffer_pair_spec(pair.first, pair.second, make_reference, alloc) {}
2688
2690 : key(key, alloc), value(value, alloc) {}
2691 buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
2692 const allocator_type &alloc = allocator_type())
2693 : key(key, make_reference, alloc), value(value, make_reference, alloc) {}
2694
2697 buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc = allocator_type())
2698 : buffer_pair_spec(pair.key, pair.value, make_reference, alloc) {}
2699
2700 buffer_pair_spec(const txn &transacton, const slice &key, const slice &value,
2701 const allocator_type &alloc = allocator_type())
2702 : key(transacton, key, alloc), value(transacton, value, alloc) {}
2703 buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc = allocator_type())
2704 : buffer_pair_spec(transaction, pair.key, pair.value, alloc) {}
2705
2706 buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2707 : key(::std::move(key)), value(::std::move(value)) {}
2709 buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
2710 : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
2711
2714 key.assign(std::move(src.key));
2715 value.assign(std::move(src.value));
2716 return *this;
2717 }
2718
2720 key.assign(src.key);
2721 value.assign(src.value);
2722 return *this;
2723 }
2725 key.assign(std::move(src.key));
2726 value.assign(std::move(src.value));
2727 return *this;
2728 }
2730 key.assign(src.first);
2731 value.assign(src.second);
2732 return *this;
2733 }
2735 key.assign(std::move(src.first));
2736 value.assign(std::move(src.second));
2737 return *this;
2738 }
2739
2743 return key.is_freestanding() && value.is_freestanding();
2744 }
2745
2748 return key.is_reference() || value.is_reference();
2749 }
2750
2754 key.make_freestanding();
2755 value.make_freestanding();
2756 }
2757
2758 operator pair() const noexcept { return pair(key, value); }
2759};
2760
2762
2765public:
2766 cache_entry() noexcept { reset(); }
2767 cache_entry(const cache_entry &) noexcept = default;
2768 cache_entry &operator=(const cache_entry &) noexcept = default;
2769 cache_entry(cache_entry &&other) noexcept {
2770 *this = other;
2771 other.reset();
2772 }
2773 void reset() noexcept { mdbx_cache_init(this); }
2774};
2775
2776//------------------------------------------------------------------------------
2777
2780enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
2781
2798
2800 return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
2801}
2802
2804 return (MDBX_db_flags_t(mode) & 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_REVERSEKEY) != 0;
2813}
2814
2816
2874
2878
2880 return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
2881}
2882
2884 return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
2885}
2886
2888 return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
2889}
2890
2892 return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
2893}
2894
2896
2907 map_handle(const map_handle &) noexcept = default;
2908 map_handle &operator=(const map_handle &) noexcept = default;
2909 operator bool() const noexcept { return dbi != 0; }
2910 operator MDBX_dbi() const { return dbi; }
2911
2912#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
2913 friend MDBX_CXX11_CONSTEXPR auto operator<=>(const map_handle &a, const map_handle &b) noexcept {
2914 return a.dbi <=> b.dbi;
2915 }
2916#endif /* __cpp_impl_three_way_comparison */
2917 friend MDBX_CXX14_CONSTEXPR bool operator==(const map_handle &a, const map_handle &b) noexcept {
2918 return a.dbi == b.dbi;
2919 }
2920 friend MDBX_CXX14_CONSTEXPR bool operator<(const map_handle &a, const map_handle &b) noexcept {
2921 return a.dbi < b.dbi;
2922 }
2923 friend MDBX_CXX14_CONSTEXPR bool operator>(const map_handle &a, const map_handle &b) noexcept {
2924 return a.dbi > b.dbi;
2925 }
2926 friend MDBX_CXX14_CONSTEXPR bool operator<=(const map_handle &a, const map_handle &b) noexcept {
2927 return a.dbi <= b.dbi;
2928 }
2929 friend MDBX_CXX14_CONSTEXPR bool operator>=(const map_handle &a, const map_handle &b) noexcept {
2930 return a.dbi >= b.dbi;
2931 }
2932 friend MDBX_CXX14_CONSTEXPR bool operator!=(const map_handle &a, const map_handle &b) noexcept {
2933 return a.dbi != b.dbi;
2934 }
2935
2947};
2948
2951 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2952}
2954 return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
2955}
2956
2963
2972 friend class txn;
2973
2974protected:
2976 MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
2977
2978public:
2979 MDBX_CXX11_CONSTEXPR env() noexcept = default;
2980 env(const env &) noexcept = default;
2981 env &operator=(const env &) noexcept = default;
2982 inline env &operator=(env &&) noexcept;
2983 inline env(env &&) noexcept;
2984 inline ~env() noexcept;
2985
2986 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
2987 MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
2988 MDBX_CXX14_CONSTEXPR operator MDBX_env *();
2989 friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept;
2990 friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept;
2991
2992 //----------------------------------------------------------------------------
2993
2998
3000 enum : intptr_t {
3003 maximal_value = INTPTR_MAX,
3004 kB = 1000,
3005 MB = kB * 1000,
3006 GB = MB * 1000,
3007#if INTPTR_MAX > 0x7fffFFFFl
3008 TB = GB * 1000,
3009 PB = TB * 1000,
3010 EB = PB * 1000,
3011#endif /* 64-bit intptr_t */
3012 KiB = 1024,
3013 MiB = KiB << 10,
3014 GiB = MiB << 10,
3015#if INTPTR_MAX > 0x7fffFFFFl
3016 TiB = GiB << 10,
3017 PiB = TiB << 10,
3018 EiB = PiB << 10,
3019#endif /* 64-bit intptr_t */
3020 };
3021
3023 struct size {
3024 intptr_t bytes;
3025 MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3026 MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3027 };
3028
3031
3036
3048
3051
3054
3060
3061 inline geometry &make_fixed(intptr_t size) noexcept;
3062 inline geometry &make_dynamic(intptr_t lower = default_value, intptr_t upper = default_value) noexcept;
3065 geometry(const geometry &) noexcept = default;
3071 };
3072
3080
3088
3101
3123
3128 unsigned max_maps{0};
3131 unsigned max_readers{0};
3136
3147 operate_parameters(const operate_parameters &) noexcept = default;
3149 MDBX_env_flags_t make_flags(bool accede = true,
3152 bool use_subdirectory = false
3153 ) const;
3157 inline static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept;
3158 };
3159
3163 inline env::mode get_mode() const;
3165 inline env::durability get_durability() const;
3169 inline env::operate_options get_options() const;
3170
3173 bool is_pristine() const;
3174
3176 bool is_empty() const;
3177
3179 static size_t default_pagesize() noexcept { return ::mdbx_default_pagesize(); }
3180
3181 struct limits {
3182 limits() = delete;
3184 static inline size_t pagesize_min() noexcept;
3186 static inline size_t pagesize_max() noexcept;
3188 static inline size_t dbsize_min(intptr_t pagesize);
3190 static inline size_t dbsize_max(intptr_t pagesize);
3192 static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3194 static inline size_t key_min(key_mode mode) noexcept;
3196 static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3198 static inline size_t key_max(intptr_t pagesize, key_mode mode);
3200 static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3202 static inline size_t key_max(const env &, key_mode mode);
3204 static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3206 static inline size_t value_min(value_mode) noexcept;
3207
3209 static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3211 static inline size_t value_max(intptr_t pagesize, value_mode);
3213 static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3215 static inline size_t value_max(const env &, value_mode);
3216
3219 static inline size_t pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3222 static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3225 static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3228 static inline size_t pairsize4page_max(const env &, value_mode);
3229
3232 static inline size_t valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags);
3235 static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3238 static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3241 static inline size_t valsize4page_max(const env &, value_mode);
3242
3245 static inline size_t transaction_size_max(intptr_t pagesize);
3246
3248 static inline size_t max_map_handles(void);
3249 };
3250
3252 size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3254 size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3256 size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3258 size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3260 size_t value_min(value_mode mode) const noexcept { return limits::value_min(mode); }
3262 size_t value_max(value_mode mode) const { return limits::value_max(*this, mode); }
3266
3269#ifdef MDBX_STD_FILESYSTEM_PATH
3270 env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size = false);
3271#endif /* MDBX_STD_FILESYSTEM_PATH */
3272#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3273 env &copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size = false);
3274 env &copy(const wchar_t *destination, bool compactify, bool force_dynamic_size = false);
3275#endif /* Windows */
3276 env &copy(const ::std::string &destination, bool compactify, bool force_dynamic_size = false);
3277 env &copy(const char *destination, bool compactify, bool force_dynamic_size = false);
3278
3280 env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3281
3297
3299#ifdef MDBX_STD_FILESYSTEM_PATH
3300 static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname, const remove_mode mode = just_remove);
3301#endif /* MDBX_STD_FILESYSTEM_PATH */
3302#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3303 static bool remove(const ::std::wstring &pathname, const remove_mode mode = just_remove);
3304 static bool remove(const wchar_t *pathname, const remove_mode mode = just_remove);
3305#endif /* Windows */
3306 static bool remove(const ::std::string &pathname, const remove_mode mode = just_remove);
3307 static bool remove(const char *pathname, const remove_mode mode = just_remove);
3308
3311
3314
3316 inline stat get_stat() const;
3317
3319 size_t get_pagesize() const { return get_stat().ms_psize; }
3320
3322 inline info get_info() const;
3323
3325 inline stat get_stat(const txn &) const;
3326
3328 inline info get_info(const txn &) const;
3329
3331 inline filehandle get_filehandle() const;
3332
3335
3337 inline MDBX_env_flags_t get_flags() const;
3338
3339 inline bool is_readonly() const { return (get_flags() & MDBX_RDONLY) != 0; }
3340
3341 inline bool is_exclusive() const { return (get_flags() & MDBX_EXCLUSIVE) != 0; }
3342
3343 inline bool is_cooperative() const { return !is_exclusive(); }
3344
3345 inline bool is_writemap() const { return (get_flags() & MDBX_WRITEMAP) != 0; }
3346
3347 inline bool is_readwite() const { return !is_readonly(); }
3348
3349 inline bool is_nested_transactions_available() const { return (get_flags() & (MDBX_WRITEMAP | MDBX_RDONLY)) == 0; }
3350
3353 inline unsigned max_readers() const;
3354
3357 inline unsigned max_maps() const;
3358
3360 inline void *get_context() const noexcept;
3361
3363 inline env &set_context(void *your_context);
3364
3379 inline env &set_sync_threshold(size_t bytes);
3380
3386 inline size_t sync_threshold() const;
3387
3388#if __cplusplus >= 201103L || defined(DOXYGEN)
3408 inline env &set_sync_period(const duration &period);
3409
3415 inline duration sync_period() const;
3416#endif
3417
3421 inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
3422
3425 inline unsigned sync_period__seconds_16dot16() const;
3426
3430 inline env &set_sync_period__seconds_double(double seconds);
3431
3434 inline double sync_period__seconds_double() const;
3435
3473
3475 inline env &set_extra_option(extra_runtime_option option, uint64_t value);
3476
3478 inline uint64_t extra_option(extra_runtime_option option) const;
3479
3481 inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
3482
3484 inline env &set_geometry(const geometry &size);
3485
3489 inline bool sync_to_disk(bool force = true, bool nonblock = false);
3490
3494 bool poll_sync_to_disk() { return sync_to_disk(false, true); }
3495
3514 inline void close_map(const map_handle &);
3515
3518 int slot;
3527 size_t bytes_used;
3536
3538 size_t used, size_t retained) noexcept;
3539 };
3540
3548 template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
3549
3552 inline unsigned check_readers();
3553
3572
3577 inline MDBX_hsr_func *get_HandleSlowReaders() const noexcept;
3578
3580 inline txn_managed start_read() const;
3581
3583 inline txn_managed prepare_read() const;
3584
3586 inline txn_managed start_write(txn &parent);
3587
3589 inline txn_managed start_write(bool dont_wait = false);
3590
3593};
3594
3603class LIBMDBX_API_TYPE env_managed : public env {
3604 using inherited = env;
3606 MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
3607 void setup(unsigned max_maps, unsigned max_readers = 0);
3608
3609public:
3610 MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
3611
3613#ifdef MDBX_STD_FILESYSTEM_PATH
3614 env_managed(const MDBX_STD_FILESYSTEM_PATH &pathname, const operate_parameters &, bool accede = true);
3615#endif /* MDBX_STD_FILESYSTEM_PATH */
3616#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3617 env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede = true);
3618 explicit env_managed(const wchar_t *pathname, const operate_parameters &, bool accede = true);
3619#endif /* Windows */
3620 env_managed(const ::std::string &pathname, const operate_parameters &, bool accede = true);
3621 explicit env_managed(const char *pathname, const operate_parameters &, bool accede = true);
3622
3633
3635#ifdef MDBX_STD_FILESYSTEM_PATH
3637 bool accede = true);
3638#endif /* MDBX_STD_FILESYSTEM_PATH */
3639#if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3640 env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &,
3641 bool accede = true);
3642 explicit env_managed(const wchar_t *pathname, const create_parameters &, const operate_parameters &,
3643 bool accede = true);
3644#endif /* Windows */
3645 env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3646 explicit env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede = true);
3647
3661 void close(bool dont_sync = false);
3662
3663 env_managed(env_managed &&) = default;
3664 env_managed &operator=(env_managed &&other) noexcept {
3666 MDBX_CXX20_UNLIKELY {
3667 assert(handle_ != other.handle_);
3668 close();
3669 }
3670 inherited::operator=(std::move(other));
3671 return *this;
3672 }
3673 env_managed(const env_managed &) = delete;
3674 env_managed &operator=(const env_managed &) = delete;
3675 virtual ~env_managed() noexcept;
3676};
3677
3686protected:
3687 friend class cursor;
3689 MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
3690
3691public:
3692 MDBX_CXX11_CONSTEXPR txn() noexcept = default;
3693 txn(const txn &) noexcept = default;
3694 txn &operator=(const txn &) noexcept = default;
3695 inline txn &operator=(txn &&) noexcept;
3696 inline txn(txn &&) noexcept;
3697 inline ~txn() noexcept;
3698
3699 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3700 MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
3701 MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
3702 friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept;
3703 friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept;
3704
3706 inline ::mdbx::env env() const noexcept;
3708 inline MDBX_txn_flags_t flags() const;
3710 inline uint64_t id() const;
3711
3713 inline void *get_context() const noexcept;
3714
3716 inline txn &set_context(void *your_context);
3717
3719 inline bool is_dirty(const void *ptr) const;
3720
3722 inline bool is_dirty(const slice &item) const { return item && is_dirty(item.data()); }
3723
3725 bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
3726
3728 bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
3729
3732 inline info get_info(bool scan_reader_lock_table = false) const;
3733
3736 size_t size_max() const { return env().transaction_size_max(); }
3737
3739 size_t size_current() const {
3740 assert(is_readwrite());
3741 return size_t(get_info().txn_space_dirty);
3742 }
3743
3744 //----------------------------------------------------------------------------
3745
3747 inline void reset_reading();
3748
3750 inline void renew_reading();
3751
3753 inline txn_managed clone(void *context = nullptr) const;
3754
3756 inline void clone(txn_managed &txn_for_renew_into_clone, void *context = nullptr) const;
3757
3759 inline void make_broken();
3760
3762 inline void park_reading(bool autounpark = true);
3763
3766 inline bool unpark_reading(bool restart_if_ousted = true);
3767
3770
3773
3775 inline cursor_managed open_cursor(map_handle map) const;
3776
3778 inline size_t release_all_cursors(bool unbind) const;
3779
3781 inline size_t close_all_cursors() const { return release_all_cursors(false); }
3782
3784 inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
3785
3787 inline map_handle open_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3788 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3790 inline map_handle open_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3791 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3793 inline map_handle open_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3794 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const;
3795
3797 inline map_handle open_map_accede(const char *name) const;
3799 inline map_handle open_map_accede(const ::std::string &name) const;
3801 inline map_handle open_map_accede(const slice &name) const;
3802
3804 inline map_handle create_map(const char *name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3805 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3807 inline map_handle create_map(const ::std::string &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3808 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3810 inline map_handle create_map(const slice &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3811 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single);
3812
3814 inline void drop_map(map_handle map);
3818 bool drop_map(const char *name, bool throw_if_absent = false);
3822 inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
3826 bool drop_map(const slice &name, bool throw_if_absent = false);
3827
3829 inline void clear_map(map_handle map);
3832 bool clear_map(const char *name, bool throw_if_absent = false);
3835 inline bool clear_map(const ::std::string &name, bool throw_if_absent = false);
3838 bool clear_map(const slice &name, bool throw_if_absent = false);
3839
3841 inline void rename_map(map_handle map, const char *new_name);
3843 inline void rename_map(map_handle map, const ::std::string &new_name);
3845 inline void rename_map(map_handle map, const slice &new_name);
3849 bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent = false);
3853 bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent = false);
3857 bool rename_map(const slice &old_name, const slice &new_name, bool throw_if_absent = false);
3858
3859#if defined(DOXYGEN) || (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3860
3862 inline map_handle open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3863 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) const {
3864 return open_map(slice(name), key_mode, value_mode);
3865 }
3866
3867 inline map_handle open_map_accede(const ::std::string_view &name) const;
3869 inline map_handle create_map(const ::std::string_view &name,
3870 const ::mdbx::key_mode key_mode = ::mdbx::key_mode::usual,
3871 const ::mdbx::value_mode value_mode = ::mdbx::value_mode::single) {
3872 return create_map(slice(name), key_mode, value_mode);
3873 }
3874
3877 bool drop_map(const ::std::string_view &name, bool throw_if_absent = false) {
3878 return drop_map(slice(name), throw_if_absent);
3879 }
3880
3882 bool clear_map(const ::std::string_view &name, bool throw_if_absent = false) {
3883 return clear_map(slice(name), throw_if_absent);
3884 }
3885
3886 inline void rename_map(map_handle map, const ::std::string_view &new_name);
3890 bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name,
3891 bool throw_if_absent = false) {
3892 return rename_map(slice(old_name), slice(new_name), throw_if_absent);
3893 }
3894#endif /* __cpp_lib_string_view >= 201606L */
3895
3898 inline map_stat get_map_stat(map_handle map) const;
3901 inline uint32_t get_tree_deepmask(map_handle map) const;
3903 inline map_handle::info get_map_flags(map_handle map) const;
3904
3907 inline txn &put_canary(const canary &);
3909 inline canary get_canary() const;
3910
3912 inline uint64_t sequence(map_handle map) const;
3914 inline uint64_t sequence(map_handle map, uint64_t increment);
3915
3917 inline int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept;
3919 inline int compare_values(map_handle map, const slice &a, const slice &b) const noexcept;
3921 inline int compare_keys(map_handle map, const pair &a, const pair &b) const noexcept;
3923 inline int compare_values(map_handle map, const pair &a, const pair &b) const noexcept;
3924
3926 inline slice get(map_handle map, const slice &key) const;
3928 inline slice get(map_handle map, slice key, size_t &values_count) const;
3930 inline slice get(map_handle map, const slice &key, const slice &value_at_absence) const;
3932 inline slice get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const;
3936 inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
3940 inline pair_result get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const;
3941
3942 inline MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
3943 inline void put(map_handle map, const slice &key, slice value, put_mode mode);
3944 inline void insert(map_handle map, const slice &key, slice value);
3945 inline value_result try_insert(map_handle map, const slice &key, slice value);
3946 inline slice insert_reserve(map_handle map, const slice &key, size_t value_length);
3947 inline value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length);
3948
3949 inline void upsert(map_handle map, const slice &key, const slice &value);
3950 inline slice upsert_reserve(map_handle map, const slice &key, size_t value_length);
3951
3952 inline void update(map_handle map, const slice &key, const slice &value);
3953 inline bool try_update(map_handle map, const slice &key, const slice &value);
3954 inline slice update_reserve(map_handle map, const slice &key, size_t value_length);
3955 inline value_result try_update_reserve(map_handle map, const slice &key, size_t value_length);
3956
3957 void put(map_handle map, const pair &kv, put_mode mode) { return put(map, kv.key, kv.value, mode); }
3958 void insert(map_handle map, const pair &kv) { return insert(map, kv.key, kv.value); }
3959 value_result try_insert(map_handle map, const pair &kv) { return try_insert(map, kv.key, kv.value); }
3960 void upsert(map_handle map, const pair &kv) { return upsert(map, kv.key, kv.value); }
3961
3963 inline bool erase(map_handle map, const slice &key);
3964
3966 inline bool erase(map_handle map, const slice &key, const slice &value);
3967
3969 inline void replace(map_handle map, const slice &key, slice old_value, const slice &new_value);
3970
3972 template <class ALLOCATOR, typename CAPACITY_POLICY>
3974 extract(map_handle map, const slice &key,
3977
3979 template <class ALLOCATOR, typename CAPACITY_POLICY>
3981 replace(map_handle map, const slice &key, const slice &new_value,
3984
3985 template <class ALLOCATOR, typename CAPACITY_POLICY>
3987 replace_reserve(map_handle map, const slice &key, slice &new_value,
3990
4007 inline void append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved = true);
4008 inline void append(map_handle map, const pair &kv, bool multivalue_order_preserved = true) {
4009 return append(map, kv.key, kv.value, multivalue_order_preserved);
4010 }
4011
4012 inline size_t put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
4013 const void *values_array, size_t values_count, put_mode mode,
4014 bool allow_partial = false);
4015 template <typename VALUE>
4016 size_t put_multiple_samelength(map_handle map, const slice &key, const VALUE *values_array, size_t values_count,
4017 put_mode mode, bool allow_partial = false) {
4018 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4019 !::std::is_array<VALUE>::value,
4020 "Must be a standard layout type!");
4021 return put_multiple_samelength(map, key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4022 }
4023 template <typename VALUE>
4024 void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4025 put_multiple_samelength(map, key, vector.data(), vector.size(), mode);
4026 }
4027
4028 inline ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const;
4029 inline ptrdiff_t estimate(map_handle map, const slice &from, const slice &to) const;
4030 inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4031 inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4032};
4033
4042class LIBMDBX_API_TYPE txn_managed : public txn {
4043 using inherited = txn;
4044 friend class env;
4045 friend class txn;
4047 MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4048
4049public:
4050 MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4051 txn_managed(txn_managed &&) = default;
4052 txn_managed &operator=(txn_managed &&other) noexcept {
4054 MDBX_CXX20_UNLIKELY {
4055 assert(handle_ != other.handle_);
4056 abort();
4057 }
4058 inherited::operator=(std::move(other));
4059 return *this;
4060 }
4061 txn_managed(const txn_managed &) = delete;
4062 txn_managed &operator=(const txn_managed &) = delete;
4063 ~txn_managed() noexcept;
4064
4065 //----------------------------------------------------------------------------
4067
4069 void abort();
4073 void abort(finalization_latency &latency) { return abort(&latency); }
4077 finalization_latency result;
4078 abort(&result);
4079 return result;
4080 }
4081
4083 void commit();
4087 void commit(finalization_latency &latency) { return commit(&latency); }
4091 finalization_latency result;
4092 commit(&result);
4093 return result;
4094 }
4095
4101 bool checkpoint(finalization_latency &latency) { return checkpoint(&latency); }
4104 std::pair<bool, finalization_latency> checkpoint_get_latency() {
4105 finalization_latency latency;
4106 bool result = checkpoint(&latency);
4107 return std::make_pair(result, latency);
4108 }
4109
4119 finalization_latency result;
4120 commit_embark_read(&result);
4121 return result;
4122 }
4123
4126 bool amend(bool dont_wait = false);
4127};
4128
4136protected:
4138
4139public:
4141 MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4142 cursor(const cursor &) noexcept = default;
4143 cursor &operator=(const cursor &) noexcept = default;
4144 inline cursor &operator=(cursor &&) noexcept;
4145 inline cursor(cursor &&) noexcept;
4146 inline ~cursor() noexcept;
4147 inline cursor_managed clone(void *your_context = nullptr) const;
4148 MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4149 MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4150 MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4151 friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept;
4152 friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept;
4153
4154 friend inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept;
4155 friend inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested);
4156
4157 bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4158 return compare_position(*this, other, ignore_nested) < 0;
4159 }
4160
4161 bool is_same_or_before_than(const cursor &other, bool ignore_nested = false) const {
4162 return compare_position(*this, other, ignore_nested) <= 0;
4163 }
4164
4165 bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4166 return compare_position(*this, other, ignore_nested) == 0;
4167 }
4168
4169 bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4170 return compare_position(*this, other, ignore_nested) > 0;
4171 }
4172
4173 bool is_same_or_after_than(const cursor &other, bool ignore_nested = false) const {
4174 return compare_position(*this, other, ignore_nested) >= 0;
4175 }
4176
4178 inline void *get_context() const noexcept;
4179
4181 inline cursor &set_context(void *your_context);
4182
4189
4196
4199
4203
4204 /* Doubtless cursor positioning at a specified key. */
4210
4211 /* Doubtless cursor positioning at a specified key-value pair
4212 * for dupsort/multi-value hives. */
4218
4225
4230 };
4231
4232 // TODO: добавить легковесный proxy-класс для замещения параметра throw_notfound более сложным набором опций,
4233 // в том числе с explicit-конструктором из bool, чтобы защититься от неявной конвертации ключей поиска
4234 // и других параметров в bool-throw_notfound.
4235
4236 struct move_result : public pair_result {
4237 inline move_result(const cursor &cursor, bool throw_notfound);
4238 move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4239 : move_result(cursor, operation, slice::invalid(), slice::invalid(), throw_notfound) {}
4240 move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
4241 : move_result(cursor, operation, key, slice::invalid(), throw_notfound) {}
4242 inline move_result(cursor &cursor, move_operation operation, const slice &key, const slice &value,
4243 bool throw_notfound);
4244 move_result(const move_result &) noexcept = default;
4245 move_result &operator=(const move_result &) noexcept = default;
4246 };
4247
4248 struct estimate_result : public pair {
4253 : estimate_result(cursor, operation, key, slice::invalid()) {}
4254 inline estimate_result(const cursor &cursor, move_operation operation, const slice &key, const slice &value);
4255 estimate_result(const estimate_result &) noexcept = default;
4256 estimate_result &operator=(const estimate_result &) noexcept = default;
4257 };
4258
4259protected:
4260 /* fake `const`, but for specific move/get operations */
4261 inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const;
4262
4263 inline ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const;
4264
4265public:
4266 template <typename CALLABLE_PREDICATE>
4267 bool scan(CALLABLE_PREDICATE predicate, move_operation start = first, move_operation turn = next) {
4268 struct wrapper : public exception_thunk {
4269 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4270 auto thunk = static_cast<wrapper *>(context);
4271 assert(thunk->is_clean());
4272 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4273 try {
4274 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4275 } catch (... /* capture any exception to rethrow it over C code */) {
4276 thunk->capture();
4277 return MDBX_RESULT_TRUE;
4278 }
4279 }
4280 } thunk;
4282 ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start), MDBX_cursor_op(turn), &predicate),
4283 thunk);
4284 }
4285
4286 template <typename CALLABLE_PREDICATE> bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4287 return scan(std::move(predicate), backward ? last : first, backward ? previous : next);
4288 }
4289
4290 template <typename CALLABLE_PREDICATE>
4291 bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start = key_greater_or_equal,
4292 move_operation turn = next) {
4293 struct wrapper : public exception_thunk {
4294 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4295 auto thunk = static_cast<wrapper *>(context);
4296 assert(thunk->is_clean());
4297 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4298 try {
4299 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4300 } catch (... /* capture any exception to rethrow it over C code */) {
4301 thunk->capture();
4302 return MDBX_RESULT_TRUE;
4303 }
4304 }
4305 } thunk;
4306 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4307 &from, nullptr, MDBX_cursor_op(turn), &predicate),
4308 thunk);
4309 }
4310
4311 template <typename CALLABLE_PREDICATE>
4312 bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start = pair_greater_or_equal,
4313 move_operation turn = next) {
4314 struct wrapper : public exception_thunk {
4315 static int probe(void *context, MDBX_val *key, MDBX_val *value, void *arg) noexcept {
4316 auto thunk = static_cast<wrapper *>(context);
4317 assert(thunk->is_clean());
4318 auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4319 try {
4320 return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE : MDBX_RESULT_FALSE;
4321 } catch (... /* capture any exception to rethrow it over C code */) {
4322 thunk->capture();
4323 return MDBX_RESULT_TRUE;
4324 }
4325 }
4326 } thunk;
4327 return error::boolean_or_throw(::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk, MDBX_cursor_op(start),
4328 &from.key, &from.value, MDBX_cursor_op(turn), &predicate),
4329 thunk);
4330 }
4331
4332 move_result move(move_operation operation, bool throw_notfound) {
4333 return move_result(*this, operation, throw_notfound);
4334 }
4335 move_result move(move_operation operation, const slice &key, bool throw_notfound) {
4336 return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4337 }
4338 move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound) {
4339 return move_result(*this, operation, key, value, throw_notfound);
4340 }
4341 bool move(move_operation operation, slice &key, slice &value, bool throw_notfound) {
4342 return move(operation, &key, &value, throw_notfound);
4343 }
4344
4345 move_result to_first(bool throw_notfound = true) { return move(first, throw_notfound); }
4346 move_result to_previous(bool throw_notfound = true) { return move(previous, throw_notfound); }
4347 move_result to_previous_last_multi(bool throw_notfound = true) {
4348 return move(multi_prevkey_lastvalue, throw_notfound);
4349 }
4350 move_result to_current_first_multi(bool throw_notfound = true) {
4351 return move(multi_currentkey_firstvalue, throw_notfound);
4352 }
4353 move_result to_current_prev_multi(bool throw_notfound = true) {
4354 return move(multi_currentkey_prevvalue, throw_notfound);
4355 }
4356 move_result current(bool throw_notfound = true) const { return move_result(*this, throw_notfound); }
4357 move_result to_current_next_multi(bool throw_notfound = true) {
4358 return move(multi_currentkey_nextvalue, throw_notfound);
4359 }
4360 move_result to_current_last_multi(bool throw_notfound = true) {
4361 return move(multi_currentkey_lastvalue, throw_notfound);
4362 }
4363 move_result to_next_first_multi(bool throw_notfound = true) { return move(multi_nextkey_firstvalue, throw_notfound); }
4364 move_result to_next(bool throw_notfound = true) { return move(next, throw_notfound); }
4365 move_result to_last(bool throw_notfound = true) { return move(last, throw_notfound); }
4366
4367 move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4368 return move(key_lesser_than, key, throw_notfound);
4369 }
4370 move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound = true) {
4371 return move(key_lesser_or_equal, key, throw_notfound);
4372 }
4373 move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4374 return move(key_equal, key, throw_notfound);
4375 }
4376 move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4377 return move(key_exact, key, throw_notfound);
4378 }
4379 move_result to_key_greater_or_equal(const slice &key, bool throw_notfound = true) {
4380 return move(key_greater_or_equal, key, throw_notfound);
4381 }
4382 move_result to_key_greater_than(const slice &key, bool throw_notfound = true) {
4383 return move(key_greater_than, key, throw_notfound);
4384 }
4385
4386 move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4387 return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
4388 }
4389 move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4390 return move(multi_exactkey_value_lesser_or_equal, key, value, throw_notfound);
4391 }
4392 move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4393 return move(multi_exactkey_value_equal, key, value, throw_notfound);
4394 }
4395 move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4396 return move(multi_exactkey_value_greater_or_equal, key, value, throw_notfound);
4397 }
4398 move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4399 return move(multi_exactkey_value_greater, key, value, throw_notfound);
4400 }
4401
4402 move_result to_pair_lesser_than(const slice &key, const slice &value, bool throw_notfound = true) {
4403 return move(pair_lesser_than, key, value, throw_notfound);
4404 }
4405 move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4406 return move(pair_lesser_or_equal, key, value, throw_notfound);
4407 }
4408 move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4409 return move(pair_equal, key, value, throw_notfound);
4410 }
4411 move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound = true) {
4412 return move(pair_exact, key, value, throw_notfound);
4413 }
4414 move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound = true) {
4415 return move(pair_greater_or_equal, key, value, throw_notfound);
4416 }
4417 move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound = true) {
4418 return move(pair_greater_than, key, value, throw_notfound);
4419 }
4420
4421 inline bool seek(const slice &key);
4422 inline move_result find(const slice &key, bool throw_notfound = true);
4423 inline move_result lower_bound(const slice &key, bool throw_notfound = false);
4424 inline move_result upper_bound(const slice &key, bool throw_notfound = false);
4425
4427 inline size_t count_multivalue() const;
4428
4429 inline move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound = true);
4430 inline move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4431 inline move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound = false);
4432
4433 inline move_result seek_multiple_samelength(const slice &key, bool throw_notfound = true) {
4434 return move(seek_and_batch_samelength, key, throw_notfound);
4435 }
4436
4437 inline move_result get_multiple_samelength(bool throw_notfound = false) {
4438 return move(batch_samelength, throw_notfound);
4439 }
4440
4441 inline move_result next_multiple_samelength(bool throw_notfound = false) {
4442 return move(batch_samelength_next, throw_notfound);
4443 }
4444
4445 inline move_result previous_multiple_samelength(bool throw_notfound = false) {
4446 return move(batch_samelength_previous, throw_notfound);
4447 }
4448
4449 inline bool eof() const;
4450 inline bool on_first() const;
4451 inline bool on_last() const;
4452 inline bool on_first_multival() const;
4453 inline bool on_last_multival() const;
4454 inline estimate_result estimate(const slice &key, const slice &value) const;
4455 inline estimate_result estimate(const slice &key) const;
4456 inline estimate_result estimate(move_operation operation) const;
4457 inline estimate_result estimate(move_operation operation, slice &key) const;
4458
4459 //----------------------------------------------------------------------------
4460
4462 inline void renew(::mdbx::txn &txn);
4463
4466
4468 inline void unbind();
4469
4471 inline ::mdbx::txn txn() const;
4472 inline map_handle map() const;
4473
4474 inline operator ::mdbx::txn() const { return txn(); }
4475 inline operator ::mdbx::map_handle() const { return map(); }
4476
4477 inline MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept;
4478 inline void put(const slice &key, slice value, put_mode mode);
4479 inline void insert(const slice &key, slice value);
4480 inline value_result try_insert(const slice &key, slice value);
4481 inline slice insert_reserve(const slice &key, size_t value_length);
4482 inline value_result try_insert_reserve(const slice &key, size_t value_length);
4483
4484 inline void upsert(const slice &key, const slice &value);
4485 inline slice upsert_reserve(const slice &key, size_t value_length);
4486
4488 void update_current(const slice &value);
4490 slice reverse_current(size_t value_length);
4491
4492 inline void update(const slice &key, const slice &value);
4493 inline bool try_update(const slice &key, const slice &value);
4494 inline slice update_reserve(const slice &key, size_t value_length);
4495 inline value_result try_update_reserve(const slice &key, size_t value_length);
4496
4497 void put(const pair &kv, put_mode mode) { return put(kv.key, kv.value, mode); }
4498 void insert(const pair &kv) { return insert(kv.key, kv.value); }
4499 value_result try_insert(const pair &kv) { return try_insert(kv.key, kv.value); }
4500 void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
4501
4503 inline bool erase(bool whole_multivalue = false);
4504
4507 inline bool erase(const slice &key, bool whole_multivalue = true);
4508
4511 inline bool erase(const slice &key, const slice &value);
4512
4513 inline size_t put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
4514 size_t values_count, put_mode mode, bool allow_partial = false);
4515 template <typename VALUE>
4516 size_t put_multiple_samelength(const slice &key, const VALUE *values_array, size_t values_count, put_mode mode,
4517 bool allow_partial = false) {
4518 static_assert(::std::is_standard_layout<VALUE>::value && !::std::is_pointer<VALUE>::value &&
4519 !::std::is_array<VALUE>::value,
4520 "Must be a standard layout type!");
4521 return put_multiple_samelength(key, sizeof(VALUE), values_array, values_count, mode, allow_partial);
4522 }
4523 template <typename VALUE>
4524 void put_multiple_samelength(const slice &key, const ::std::vector<VALUE> &vector, put_mode mode) {
4525 put_multiple_samelength(key, vector.data(), vector.size(), mode);
4526 }
4527};
4528
4536class LIBMDBX_API_TYPE cursor_managed : public cursor {
4537 using inherited = cursor;
4538 friend class txn;
4540 MDBX_CXX11_CONSTEXPR cursor_managed(MDBX_cursor *ptr) noexcept : inherited(ptr) {}
4541
4542public:
4544 cursor_managed(void *your_context = nullptr) : cursor_managed(::mdbx_cursor_create(your_context)) {
4545 if (MDBX_UNLIKELY(!handle_))
4546 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
4547 }
4548
4550 inline void close() {
4552 handle_ = nullptr;
4553 }
4554
4555 cursor_managed(cursor_managed &&) = default;
4556 cursor_managed &operator=(cursor_managed &&other) noexcept {
4558 MDBX_CXX20_UNLIKELY {
4559 assert(handle_ != other.handle_);
4560 close();
4561 }
4562 inherited::operator=(std::move(other));
4563 return *this;
4564 }
4565
4566 inline MDBX_cursor *withdraw_handle() noexcept {
4567 MDBX_cursor *handle = handle_;
4568 handle_ = nullptr;
4569 return handle;
4570 }
4571
4572 cursor_managed(const cursor_managed &) = delete;
4573 cursor_managed &operator=(const cursor_managed &) = delete;
4575};
4576
4577//==============================================================================
4578//
4579// Inline body of the libmdbx C++ API
4580//
4581
4582MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept { return ::mdbx_version; }
4583MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept { return ::mdbx_build; }
4584
4585static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
4586#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4587 if (::std::is_constant_evaluated()) {
4588 for (size_t i = 0; c_str; ++i)
4589 if (!c_str[i])
4590 return i;
4591 return 0;
4592 }
4593#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4594#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
4595 return c_str ? ::std::string_view(c_str).length() : 0;
4596#else
4597 return c_str ? ::std::strlen(c_str) : 0;
4598#endif
4599}
4600
4601MDBX_MAYBE_UNUSED static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src, size_t bytes) noexcept {
4602#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4603 if (::std::is_constant_evaluated()) {
4604 for (size_t i = 0; i < bytes; ++i)
4605 static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
4606 return dest;
4607 } else
4608#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4609 return ::std::memcpy(dest, src, bytes);
4610}
4611
4612static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b, size_t bytes) noexcept {
4613#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
4614 if (::std::is_constant_evaluated()) {
4615 for (size_t i = 0; i < bytes; ++i) {
4616 const int diff = int(static_cast<const byte *>(a)[i]) - int(static_cast<const byte *>(b)[i]);
4617 if (diff)
4618 return diff;
4619 }
4620 return 0;
4621 } else
4622#endif /* __cpp_lib_is_constant_evaluated >= 201811 */
4623 return ::std::memcmp(a, b, bytes);
4624}
4625
4626//------------------------------------------------------------------------------
4627
4630
4634
4638
4639inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
4640
4641inline void exception_thunk::capture() noexcept {
4642 assert(is_clean());
4643 captured_ = ::std::current_exception();
4644}
4645
4647 if (captured_)
4648 MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
4649}
4650
4651//------------------------------------------------------------------------------
4652
4653MDBX_CXX11_CONSTEXPR error::error(MDBX_error_t error_code) noexcept : code_(error_code) {}
4654
4655inline error &error::operator=(MDBX_error_t error_code) noexcept {
4656 code_ = error_code;
4657 return *this;
4658}
4659
4660MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept { return a.code_ == b.code_; }
4661
4662MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept { return !(a == b); }
4663
4664MDBX_CXX11_CONSTEXPR bool error::is_success() const noexcept { return code_ == MDBX_SUCCESS; }
4665
4666MDBX_CXX11_CONSTEXPR bool error::is_result_true() const noexcept { return code_ == MDBX_RESULT_FALSE; }
4667
4668MDBX_CXX11_CONSTEXPR bool error::is_result_false() const noexcept { return code_ == MDBX_RESULT_TRUE; }
4669
4671 return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
4672}
4673
4674MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
4675
4680
4681inline void error::throw_exception(int error_code) {
4682 const error trouble(static_cast<MDBX_error_t>(error_code));
4683 trouble.throw_exception();
4684}
4685
4686inline void error::throw_on_failure() const {
4688 MDBX_CXX20_UNLIKELY throw_exception();
4689}
4690
4691inline void error::success_or_throw() const {
4692 if (MDBX_UNLIKELY(!is_success()))
4693 MDBX_CXX20_UNLIKELY throw_exception();
4694}
4695
4696inline void error::success_or_throw(const exception_thunk &thunk) const {
4697 assert(thunk.is_clean() || code() != MDBX_SUCCESS);
4698 if (MDBX_UNLIKELY(!is_success())) {
4699 MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean())) thunk.rethrow_captured();
4700 else throw_exception();
4701 }
4702}
4703
4704inline void error::panic_on_failure(const char *context_where, const char *func_who) const noexcept {
4706 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4707}
4708
4709inline void error::success_or_panic(const char *context_where, const char *func_who) const noexcept {
4710 if (MDBX_UNLIKELY(!is_success()))
4711 MDBX_CXX20_UNLIKELY panic(context_where, func_who);
4712}
4713
4714inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
4715 if (MDBX_UNLIKELY(ptr == nullptr))
4716 MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
4717}
4718
4719inline void error::throw_on_failure(int error_code) {
4720 error rc(static_cast<MDBX_error_t>(error_code));
4721 rc.throw_on_failure();
4722}
4723
4724inline void error::success_or_throw(MDBX_error_t error_code) {
4725 error rc(error_code);
4726 rc.success_or_throw();
4727}
4728
4729inline bool error::boolean_or_throw(int error_code) {
4730 switch (error_code) {
4731 case MDBX_RESULT_FALSE:
4732 return false;
4733 case MDBX_RESULT_TRUE:
4734 return true;
4735 default:
4736 MDBX_CXX20_UNLIKELY throw_exception(error_code);
4737 }
4738}
4739
4740inline void error::success_or_throw(int error_code, const exception_thunk &thunk) {
4741 error rc(static_cast<MDBX_error_t>(error_code));
4742 rc.success_or_throw(thunk);
4743}
4744
4745inline void error::panic_on_failure(int error_code, const char *context_where, const char *func_who) noexcept {
4746 error rc(static_cast<MDBX_error_t>(error_code));
4747 rc.panic_on_failure(context_where, func_who);
4748}
4749
4750inline void error::success_or_panic(int error_code, const char *context_where, const char *func_who) noexcept {
4751 error rc(static_cast<MDBX_error_t>(error_code));
4752 rc.success_or_panic(context_where, func_who);
4753}
4754
4755inline bool error::boolean_or_throw(int error_code, const exception_thunk &thunk) {
4756 if (MDBX_UNLIKELY(!thunk.is_clean()))
4757 MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
4758 return boolean_or_throw(error_code);
4759}
4760
4761MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
4762
4764 : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
4765
4766MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
4767 : slice(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin)) {}
4768
4769MDBX_CXX17_CONSTEXPR slice::slice(const char *c_str) : slice(c_str, strlen(c_str)) {}
4770
4771MDBX_CXX14_CONSTEXPR slice::slice(const MDBX_val &src) : slice(src.iov_base, src.iov_len) {}
4772
4773MDBX_CXX14_CONSTEXPR slice::slice(MDBX_val &&src) : slice(src) { src.iov_base = nullptr; }
4774
4775MDBX_CXX14_CONSTEXPR slice::slice(slice &&src) noexcept : slice(src) { src.invalidate(); }
4776
4777inline slice &slice::assign(const void *ptr, size_t bytes) {
4778 iov_base = const_cast<void *>(ptr);
4779 iov_len = check_length(bytes);
4780 return *this;
4781}
4782
4783inline slice &slice::assign(const slice &src) noexcept {
4784 iov_base = src.iov_base;
4785 iov_len = src.iov_len;
4786 return *this;
4787}
4788
4789inline slice &slice::assign(const ::MDBX_val &src) { return assign(src.iov_base, src.iov_len); }
4790
4791slice &slice::assign(slice &&src) noexcept {
4792 assign(src);
4793 src.invalidate();
4794 return *this;
4795}
4796
4798 assign(src.iov_base, src.iov_len);
4799 src.iov_base = nullptr;
4800 return *this;
4801}
4802
4803inline slice &slice::assign(const void *begin, const void *end) {
4804 return assign(begin, static_cast<const byte *>(end) - static_cast<const byte *>(begin));
4805}
4806
4807inline slice &slice::assign(const char *c_str) { return assign(c_str, strlen(c_str)); }
4808
4809inline slice &slice::operator=(slice &&src) noexcept { return assign(::std::move(src)); }
4810
4811inline slice &slice::operator=(::MDBX_val &&src) { return assign(::std::move(src)); }
4812
4813MDBX_CXX11_CONSTEXPR const byte *slice::byte_ptr() const noexcept { return static_cast<const byte *>(iov_base); }
4814
4815MDBX_CXX11_CONSTEXPR const byte *slice::end_byte_ptr() const noexcept { return byte_ptr() + length(); }
4816
4817MDBX_CXX11_CONSTEXPR byte *slice::byte_ptr() noexcept { return static_cast<byte *>(iov_base); }
4818
4820
4821MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept { return static_cast<const char *>(iov_base); }
4822
4823MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept { return char_ptr() + length(); }
4824
4825MDBX_CXX11_CONSTEXPR char *slice::char_ptr() noexcept { return static_cast<char *>(iov_base); }
4826
4828
4829MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept { return iov_base; }
4830
4831MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept { return static_cast<const void *>(end_byte_ptr()); }
4832
4833MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
4834
4835MDBX_CXX11_CONSTEXPR void *slice::end() noexcept { return static_cast<void *>(end_byte_ptr()); }
4836
4837MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
4838
4840 iov_len = check_length(bytes);
4841 return *this;
4842}
4843
4845 MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
4846 return set_length(static_cast<const char *>(ptr) - char_ptr());
4847}
4848
4849MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept { return length() == 0; }
4850
4851MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept { return data() == nullptr; }
4852
4853MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
4854
4855MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept { return !is_null(); }
4856
4857MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
4858
4860 iov_base = nullptr;
4861 iov_len = 0;
4862}
4863
4864inline void slice::remove_prefix(size_t n) noexcept {
4865 assert(n <= size());
4866 iov_base = static_cast<byte *>(iov_base) + n;
4867 iov_len -= n;
4868}
4869
4870inline void slice::safe_remove_prefix(size_t n) {
4871 if (MDBX_UNLIKELY(n > size()))
4872 MDBX_CXX20_UNLIKELY throw_out_range();
4873 remove_prefix(n);
4874}
4875
4876inline void slice::remove_suffix(size_t n) noexcept {
4877 assert(n <= size());
4878 iov_len -= n;
4879}
4880
4881inline void slice::safe_remove_suffix(size_t n) {
4882 if (MDBX_UNLIKELY(n > size()))
4883 MDBX_CXX20_UNLIKELY throw_out_range();
4884 remove_suffix(n);
4885}
4886
4887MDBX_CXX14_CONSTEXPR bool slice::starts_with(const slice &prefix) const noexcept {
4888 return length() >= prefix.length() && memcmp(data(), prefix.data(), prefix.length()) == 0;
4889}
4890
4891MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
4892 return length() >= suffix.length() &&
4893 memcmp(byte_ptr() + length() - suffix.length(), suffix.data(), suffix.length()) == 0;
4894}
4895
4897 size_t h = length() * 3977471;
4898 for (size_t i = 0; i < length(); ++i)
4899 h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
4900 return h ^ 3863194411 * (h >> 11);
4901}
4902
4903MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
4905 return byte_ptr()[n];
4906}
4907
4908MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
4909 if (MDBX_UNLIKELY(n >= size()))
4910 MDBX_CXX20_UNLIKELY throw_out_range();
4911 return byte_ptr()[n];
4912}
4913
4914MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
4916 return slice(data(), n);
4917}
4918
4919MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
4921 return slice(char_ptr() + size() - n, n);
4922}
4923
4924MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
4925 MDBX_CONSTEXPR_ASSERT(from + n <= size());
4926 return slice(char_ptr() + from, n);
4927}
4928
4930 if (MDBX_UNLIKELY(n > size()))
4931 MDBX_CXX20_UNLIKELY throw_out_range();
4932 return head(n);
4933}
4934
4936 if (MDBX_UNLIKELY(n > size()))
4937 MDBX_CXX20_UNLIKELY throw_out_range();
4938 return tail(n);
4939}
4940
4941MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
4942 if (MDBX_UNLIKELY(n > max_length))
4943 MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
4944 if (MDBX_UNLIKELY(from + n > size()))
4945 MDBX_CXX20_UNLIKELY throw_out_range();
4946 return middle(from, n);
4947}
4948
4949MDBX_CXX14_CONSTEXPR intptr_t slice::compare_fast(const slice &a, const slice &b) noexcept {
4950 const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
4951 return diff ? diff
4952 : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data()) ? 0
4953 : memcmp(a.data(), b.data(), a.length());
4954}
4955
4957 const size_t shortest = ::std::min(a.length(), b.length());
4958 if (MDBX_LIKELY(shortest > 0))
4960 const intptr_t diff = memcmp(a.data(), b.data(), shortest);
4961 if (MDBX_LIKELY(diff != 0))
4962 MDBX_CXX20_LIKELY return diff;
4963 }
4964 return intptr_t(a.length()) - intptr_t(b.length());
4965}
4966
4968 return slice::compare_fast(a, b) == 0;
4969}
4970
4972 return slice::compare_lexicographically(a, b) < 0;
4973}
4974
4976 return slice::compare_lexicographically(a, b) > 0;
4977}
4978
4980 return slice::compare_lexicographically(a, b) <= 0;
4981}
4982
4984 return slice::compare_lexicographically(a, b) >= 0;
4985}
4986
4988 return slice::compare_fast(a, b) != 0;
4989}
4990
4991#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
4992MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
4994}
4995#endif /* __cpp_impl_three_way_comparison */
4996
4997template <class ALLOCATOR, typename CAPACITY_POLICY>
4999 const allocator_type &alloc)
5000 : inherited(src), silo_(alloc) {
5001 if (!make_reference)
5002 insulate();
5003}
5004
5005template <class ALLOCATOR, typename CAPACITY_POLICY>
5006inline buffer<ALLOCATOR, CAPACITY_POLICY>::buffer(const txn &transaction, const struct slice &src,
5007 const allocator_type &alloc)
5008 : buffer(src, !transaction.is_dirty(src.data()), alloc) {}
5009
5010template <class ALLOCATOR, typename CAPACITY_POLICY>
5011inline ::std::ostream &operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
5012 return (it.is_freestanding() ? out << "buf-" << it.headroom() << "." << it.tailroom() : out << "ref-") << it.slice();
5013}
5014
5015#if !(defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) || defined(LIBMDBX_EXPORTS)
5017
5018#if MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR
5020#endif /* MDBX_CXX_HAS_POLYMORPHIC_ALLOCATOR */
5021#endif /* !MinGW || MDBX_EXPORTS */
5022
5025
5026//------------------------------------------------------------------------------
5027
5028template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5029inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(PRODUCER &producer, const ALLOCATOR &alloc) {
5030 if (MDBX_LIKELY(!producer.is_empty()))
5032 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5033 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5034 return result;
5035 }
5037}
5038
5039template <class ALLOCATOR, class CAPACITY_POLICY, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5040inline buffer<ALLOCATOR, CAPACITY_POLICY> make_buffer(const PRODUCER &producer, const ALLOCATOR &alloc) {
5041 if (MDBX_LIKELY(!producer.is_empty()))
5043 buffer<ALLOCATOR, CAPACITY_POLICY> result(producer.envisage_result_length(), alloc);
5044 result.set_end(producer.write_bytes(result.end_char_ptr(), result.tailroom()));
5045 return result;
5046 }
5048}
5049
5050template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
5051inline string<ALLOCATOR> make_string(PRODUCER &producer, const ALLOCATOR &alloc) {
5052 string<ALLOCATOR> result(alloc);
5053 if (MDBX_LIKELY(!producer.is_empty()))
5055 result.resize(producer.envisage_result_length());
5056 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5057 }
5058 return result;
5059}
5060
5061template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
5062inline string<ALLOCATOR> make_string(const PRODUCER &producer, const ALLOCATOR &alloc) {
5063 string<ALLOCATOR> result(alloc);
5064 if (MDBX_LIKELY(!producer.is_empty()))
5066 result.resize(producer.envisage_result_length());
5067 result.resize(producer.write_bytes(const_cast<char *>(result.data()), result.capacity()) - result.data());
5068 }
5069 return result;
5070}
5071
5072template <class ALLOCATOR> string<ALLOCATOR> to_hex::as_string(const ALLOCATOR &alloc) const {
5073 return make_string<ALLOCATOR>(*this, alloc);
5074}
5075
5076template <class ALLOCATOR, typename CAPACITY_POLICY>
5078 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5079}
5080
5081template <class ALLOCATOR> string<ALLOCATOR> to_base58::as_string(const ALLOCATOR &alloc) const {
5082 return make_string<ALLOCATOR>(*this, alloc);
5083}
5084
5085template <class ALLOCATOR, typename CAPACITY_POLICY>
5087 return make_buffer<ALLOCATOR, CAPACITY_POLICY>(*this, alloc);
5088}
5089
5090template <class ALLOCATOR> string<ALLOCATOR> to_base64::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> from_hex::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> from_base58::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_base64::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>
5127inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &alloc) const {
5128 return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(alloc);
5129}
5130
5131template <class ALLOCATOR>
5132inline string<ALLOCATOR> slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5133 return to_base58(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5134}
5135
5136template <class ALLOCATOR>
5137inline string<ALLOCATOR> slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &alloc) const {
5138 return to_base64(*this, wrap_width).as_string<ALLOCATOR>(alloc);
5139}
5140
5141template <class ALLOCATOR, class CAPACITY_POLICY>
5142inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_hex(bool uppercase, unsigned wrap_width,
5143 const ALLOCATOR &alloc) const {
5144 return to_hex(*this, uppercase, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5145}
5146
5147template <class ALLOCATOR, class CAPACITY_POLICY>
5148inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base58(unsigned wrap_width, const ALLOCATOR &alloc) const {
5149 return to_base58(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5150}
5151
5152template <class ALLOCATOR, class CAPACITY_POLICY>
5153inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::encode_base64(unsigned wrap_width, const ALLOCATOR &alloc) const {
5154 return to_base64(*this, wrap_width).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5155}
5156
5157template <class ALLOCATOR, class CAPACITY_POLICY>
5158inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::hex_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5159 return from_hex(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5160}
5161
5162template <class ALLOCATOR, class CAPACITY_POLICY>
5163inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base58_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5164 return from_base58(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5165}
5166
5167template <class ALLOCATOR, class CAPACITY_POLICY>
5168inline buffer<ALLOCATOR, CAPACITY_POLICY> slice::base64_decode(bool ignore_spaces, const ALLOCATOR &alloc) const {
5169 return from_base64(*this, ignore_spaces).as_buffer<ALLOCATOR, CAPACITY_POLICY>(alloc);
5170}
5171
5172//------------------------------------------------------------------------------
5173
5174MDBX_CXX14_CONSTEXPR intptr_t pair::compare_fast(const pair &a, const pair &b) noexcept {
5175 const auto diff = slice::compare_fast(a.key, b.key);
5176 return diff ? diff : slice::compare_fast(a.value, b.value);
5177}
5178
5179MDBX_CXX14_CONSTEXPR intptr_t pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5180 const auto diff = slice::compare_lexicographically(a.key, b.key);
5181 return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5182}
5183
5185 return a.key.length() == b.key.length() && a.value.length() == b.value.length() &&
5186 memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5187 memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5188}
5189
5191 return pair::compare_lexicographically(a, b) < 0;
5192}
5193
5195 return pair::compare_lexicographically(a, b) > 0;
5196}
5197
5199 return pair::compare_lexicographically(a, b) <= 0;
5200}
5201
5203 return pair::compare_lexicographically(a, b) >= 0;
5204}
5205
5207 return a.key.length() != b.key.length() || a.value.length() != b.value.length() ||
5208 memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5209 memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5210}
5211
5212#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5213MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
5215}
5216#endif /* __cpp_impl_three_way_comparison */
5217
5219template <typename BUFFER>
5221
5224
5225//------------------------------------------------------------------------------
5226
5227inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) { return wrapper.output(out); }
5228inline ::std::ostream &operator<<(::std::ostream &out, const to_base58 &wrapper) { return wrapper.output(out); }
5229inline ::std::ostream &operator<<(::std::ostream &out, const to_base64 &wrapper) { return wrapper.output(out); }
5230
5231MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_hex(bool ignore_spaces) const noexcept {
5232 return !from_hex(*this, ignore_spaces).is_erroneous();
5233}
5234
5235MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base58(bool ignore_spaces) const noexcept {
5236 return !from_base58(*this, ignore_spaces).is_erroneous();
5237}
5238
5239MDBX_NOTHROW_PURE_FUNCTION inline bool slice::is_base64(bool ignore_spaces) const noexcept {
5240 return !from_base64(*this, ignore_spaces).is_erroneous();
5241}
5242
5243//------------------------------------------------------------------------------
5244
5246
5247inline env &env::operator=(env &&other) noexcept {
5248 handle_ = other.handle_;
5249 other.handle_ = nullptr;
5250 return *this;
5251}
5252
5253inline env::env(env &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5254
5255inline env::~env() noexcept {
5256#ifndef NDEBUG
5257 handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5258#endif
5259}
5260
5261MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept { return handle_ != nullptr; }
5262
5263MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5264
5265MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5266
5267MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept { return a.handle_ == b.handle_; }
5268
5269MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept { return a.handle_ != b.handle_; }
5270
5274 return *this;
5275}
5276
5277inline env::geometry &env::geometry::make_dynamic(intptr_t lower, intptr_t upper) noexcept {
5278 size_now = size_lower = lower;
5279 size_upper = upper;
5281 return *this;
5282}
5283
5287
5291
5292inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5293
5294inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5295
5296inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5297 const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5298 if (result < 0)
5299 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5300 return static_cast<size_t>(result);
5301}
5302
5303inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5304 const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5305 if (result < 0)
5306 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5307 return static_cast<size_t>(result);
5308}
5309
5310inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERKEY) ? 4 : 0; }
5311
5312inline size_t env::limits::key_min(key_mode mode) noexcept { return key_min(MDBX_db_flags_t(mode)); }
5313
5314inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5315 const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
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::key_max(intptr_t pagesize, key_mode mode) {
5322 return key_max(pagesize, MDBX_db_flags_t(mode));
5323}
5324
5325inline size_t env::limits::key_max(const env &env, MDBX_db_flags_t flags) {
5326 const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5327 if (result < 0)
5328 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5329 return static_cast<size_t>(result);
5330}
5331
5333
5334inline size_t env::limits::value_min(MDBX_db_flags_t flags) noexcept { return (flags & MDBX_INTEGERDUP) ? 4 : 0; }
5335
5337
5338inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5339 const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5340 if (result < 0)
5341 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5342 return static_cast<size_t>(result);
5343}
5344
5345inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5346 return value_max(pagesize, MDBX_db_flags_t(mode));
5347}
5348
5349inline size_t env::limits::value_max(const env &env, MDBX_db_flags_t flags) {
5350 const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
5351 if (result < 0)
5352 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5353 return static_cast<size_t>(result);
5354}
5355
5357
5358inline size_t env::limits::pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5359 const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
5360 if (result < 0)
5361 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5362 return static_cast<size_t>(result);
5363}
5364
5365inline size_t env::limits::pairsize4page_max(intptr_t pagesize, value_mode mode) {
5366 return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
5367}
5368
5370 const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
5371 if (result < 0)
5372 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5373 return static_cast<size_t>(result);
5374}
5375
5379
5380inline size_t env::limits::valsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5381 const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
5382 if (result < 0)
5383 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5384 return static_cast<size_t>(result);
5385}
5386
5387inline size_t env::limits::valsize4page_max(intptr_t pagesize, value_mode mode) {
5388 return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
5389}
5390
5392 const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
5393 if (result < 0)
5394 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5395 return static_cast<size_t>(result);
5396}
5397
5401
5402inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
5403 const intptr_t result = mdbx_limits_txnsize_max(pagesize);
5404 if (result < 0)
5405 MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5406 return static_cast<size_t>(result);
5407}
5408
5409inline size_t env::limits::max_map_handles(void) { return MDBX_MAX_DBI; }
5410
5418
5420
5424
5428
5432
5433inline env::stat env::get_stat() const {
5434 env::stat r;
5435 error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
5436 return r;
5437}
5438
5439inline env::stat env::get_stat(const txn &txn) const {
5440 env::stat r;
5442 return r;
5443}
5444
5445inline env::info env::get_info() const {
5446 env::info r;
5447 error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
5448 return r;
5449}
5450
5451inline env::info env::get_info(const txn &txn) const {
5452 env::info r;
5454 return r;
5455}
5456
5458 filehandle fd;
5460 return fd;
5461}
5462
5464 unsigned bits = 0;
5466 return MDBX_env_flags_t(bits);
5467}
5468
5469inline unsigned env::max_readers() const {
5470 unsigned r;
5472 return r;
5473}
5474
5475inline unsigned env::max_maps() const {
5476 unsigned r;
5478 return r;
5479}
5480
5481inline void *env::get_context() const noexcept { return mdbx_env_get_userctx(handle_); }
5482
5483inline env &env::set_context(void *ptr) {
5485 return *this;
5486}
5487
5488inline env &env::set_sync_threshold(size_t bytes) {
5490 return *this;
5491}
5492
5493inline size_t env::sync_threshold() const {
5494 size_t bytes;
5496 return bytes;
5497}
5498
5499inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
5501 return *this;
5502}
5503
5504inline unsigned env::sync_period__seconds_16dot16() const {
5505 unsigned seconds_16dot16;
5507 return seconds_16dot16;
5508}
5509
5511 return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
5512}
5513
5514inline double env::sync_period__seconds_double() const { return sync_period__seconds_16dot16() / 65536.0; }
5515
5516#if __cplusplus >= 201103L
5517inline env &env::set_sync_period(const duration &period) { return set_sync_period__seconds_16dot16(period.count()); }
5518
5520#endif
5521
5522inline env &env::set_extra_option(enum env::extra_runtime_option option, uint64_t value) {
5524 return *this;
5525}
5526
5527inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
5528 uint64_t value;
5530 return value;
5531}
5532
5533inline env &env::alter_flags(MDBX_env_flags_t flags, bool on_off) {
5535 return *this;
5536}
5537
5538inline env &env::set_geometry(const geometry &geo) {
5540 geo.growth_step, geo.shrink_threshold, geo.pagesize));
5541 return *this;
5542}
5543
5544inline bool env::sync_to_disk(bool force, bool nonblock) {
5545 const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
5546 switch (err) {
5547 case MDBX_SUCCESS /* flush done */:
5548 case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
5549 return true;
5550 case MDBX_BUSY /* the environment is used by other thread */:
5551 return false;
5552 default:
5553 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5554 }
5555}
5556
5557inline void env::close_map(const map_handle &handle) { error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi)); }
5558
5560env::reader_info::reader_info(int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
5561 size_t retained) noexcept
5563 bytes_retained(retained) {}
5564
5565template <typename VISITOR> inline int env::enumerate_readers(VISITOR &visitor) {
5566 struct reader_visitor_thunk : public exception_thunk {
5567 VISITOR &visitor_;
5568 static int cb(void *ctx, int number, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
5569 size_t used, size_t retained) noexcept {
5570 reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
5571 assert(thunk->is_clean());
5572 try {
5573 const reader_info info(slot, pid, thread, txnid, lag, used, retained);
5574 return loop_control(thunk->visitor_(info, number));
5575 } catch (... /* capture any exception to rethrow it over C code */) {
5576 thunk->capture();
5578 }
5579 }
5580 MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept : visitor_(visitor) {}
5581 };
5582 reader_visitor_thunk thunk(visitor);
5583 const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
5584 thunk.rethrow_captured();
5585 return rc;
5586}
5587
5588inline unsigned env::check_readers() {
5589 int dead_count;
5590 error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
5591 assert(dead_count >= 0);
5592 return static_cast<unsigned>(dead_count);
5593}
5594
5599
5600inline MDBX_hsr_func *env::get_HandleSlowReaders() const noexcept { return ::mdbx_env_get_hsr(handle_); }
5601
5603 ::MDBX_txn *ptr;
5605 assert(ptr != nullptr);
5606 return txn_managed(ptr);
5607}
5608
5610 ::MDBX_txn *ptr;
5612 assert(ptr != nullptr);
5613 return txn_managed(ptr);
5614}
5615
5616inline txn_managed env::start_write(bool dont_wait) {
5617 ::MDBX_txn *ptr;
5620 assert(ptr != nullptr || dont_wait);
5621 return txn_managed(ptr);
5622}
5623
5625 ::MDBX_txn *ptr;
5627 assert(ptr != nullptr);
5628 return txn_managed(ptr);
5629}
5630
5632
5634
5635inline txn &txn::operator=(txn &&other) noexcept {
5636 handle_ = other.handle_;
5637 other.handle_ = nullptr;
5638 return *this;
5639}
5640
5641inline txn::txn(txn &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
5642
5643inline txn::~txn() noexcept {
5644#ifndef NDEBUG
5645 handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
5646#endif
5647}
5648
5649MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept { return handle_ != nullptr; }
5650
5651MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
5652
5653MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
5654
5655MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept { return a.handle_ == b.handle_; }
5656
5657MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept { return a.handle_ != b.handle_; }
5658
5659inline void *txn::get_context() const noexcept { return mdbx_txn_get_userctx(handle_); }
5660
5661inline txn &txn::set_context(void *ptr) {
5663 return *this;
5664}
5665
5666inline bool txn::is_dirty(const void *ptr) const {
5667 int err = ::mdbx_is_dirty(handle_, ptr);
5668 switch (err) {
5669 default:
5670 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5671 case MDBX_RESULT_TRUE:
5672 return true;
5673 case MDBX_RESULT_FALSE:
5674 return false;
5675 }
5676}
5677
5678inline env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
5679
5681 const int bits = mdbx_txn_flags(handle_);
5683 return static_cast<MDBX_txn_flags_t>(bits);
5684}
5685
5686inline uint64_t txn::id() const {
5687 const uint64_t txnid = mdbx_txn_id(handle_);
5689 return txnid;
5690}
5691
5693
5695
5697
5698inline txn_managed txn::clone(void *context) const {
5699 MDBX_txn *ptr = nullptr;
5701 assert(ptr != nullptr);
5702 return txn_managed(ptr);
5703}
5704
5705inline void txn::clone(txn_managed &txn_for_renew_into_clone, void *context) const {
5706 error::throw_on_nullptr(txn_for_renew_into_clone.handle_, MDBX_BAD_TXN);
5707 error::success_or_throw(::mdbx_txn_clone(handle_, &txn_for_renew_into_clone.handle_, context));
5708 assert(txn_for_renew_into_clone.handle_ != nullptr);
5709}
5710
5711inline void txn::park_reading(bool autounpark) { error::success_or_throw(::mdbx_txn_park(handle_, autounpark)); }
5712
5713inline bool txn::unpark_reading(bool restart_if_ousted) {
5714 return error::boolean_or_throw(::mdbx_txn_unpark(handle_, restart_if_ousted));
5715}
5716
5717inline txn::info txn::get_info(bool scan_reader_lock_table) const {
5718 txn::info r;
5719 error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
5720 return r;
5721}
5722
5724 MDBX_cursor *ptr;
5726 return cursor_managed(ptr);
5727}
5728
5729inline size_t txn::release_all_cursors(bool unbind) const {
5730 size_t count;
5732 return count;
5733}
5734
5735inline map_handle txn::open_map(const slice &name, const ::mdbx::key_mode key_mode,
5736 const ::mdbx::value_mode value_mode) const {
5737 map_handle map;
5740 assert(map.dbi != 0);
5741 return map;
5742}
5743
5744inline map_handle txn::open_map(const char *name, const ::mdbx::key_mode key_mode,
5745 const ::mdbx::value_mode value_mode) const {
5746 map_handle map;
5749 assert(map.dbi != 0);
5750 return map;
5751}
5752
5753inline map_handle txn::open_map_accede(const slice &name) const {
5754 map_handle map;
5756 assert(map.dbi != 0);
5757 return map;
5758}
5759
5760inline map_handle txn::open_map_accede(const char *name) const {
5761 map_handle map;
5763 assert(map.dbi != 0);
5764 return map;
5765}
5766
5767inline map_handle txn::create_map(const slice &name, const ::mdbx::key_mode key_mode,
5768 const ::mdbx::value_mode value_mode) {
5769 map_handle map;
5772 assert(map.dbi != 0);
5773 return map;
5774}
5775
5776inline map_handle txn::create_map(const char *name, const ::mdbx::key_mode key_mode,
5777 const ::mdbx::value_mode value_mode) {
5778 map_handle map;
5781 assert(map.dbi != 0);
5782 return map;
5783}
5784
5786
5788
5789inline void txn::rename_map(map_handle map, const char *new_name) {
5791}
5792
5793inline void txn::rename_map(map_handle map, const slice &new_name) {
5795}
5796
5797inline map_handle txn::open_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5798 const ::mdbx::value_mode value_mode) const {
5799 return open_map(slice(name), key_mode, value_mode);
5800}
5801
5802inline map_handle txn::open_map_accede(const ::std::string &name) const { return open_map_accede(slice(name)); }
5803
5804inline map_handle txn::create_map(const ::std::string &name, const ::mdbx::key_mode key_mode,
5805 const ::mdbx::value_mode value_mode) {
5806 return create_map(slice(name), key_mode, value_mode);
5807}
5808
5809inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
5810 return drop_map(slice(name), throw_if_absent);
5811}
5812
5813inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
5814 return clear_map(slice(name), throw_if_absent);
5815}
5816
5817inline void txn::rename_map(map_handle map, const ::std::string &new_name) { return rename_map(map, slice(new_name)); }
5818
5820 txn::map_stat r;
5821 error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
5822 return r;
5823}
5824
5825inline uint32_t txn::get_tree_deepmask(map_handle map) const {
5826 uint32_t r;
5828 return r;
5829}
5830
5836
5841
5843 txn::canary r;
5845 return r;
5846}
5847
5848inline uint64_t txn::sequence(map_handle map) const {
5849 uint64_t result;
5851 return result;
5852}
5853
5854inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
5855 uint64_t result;
5856 error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
5857 return result;
5858}
5859
5860inline int txn::compare_keys(map_handle map, const slice &a, const slice &b) const noexcept {
5861 return ::mdbx_cmp(handle_, map.dbi, &a, &b);
5862}
5863
5864inline int txn::compare_values(map_handle map, const slice &a, const slice &b) const noexcept {
5865 return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
5866}
5867
5868inline int txn::compare_keys(map_handle map, const pair &a, const pair &b) const noexcept {
5869 return compare_keys(map, a.key, b.key);
5870}
5871
5872inline int txn::compare_values(map_handle map, const pair &a, const pair &b) const noexcept {
5873 return compare_values(map, a.value, b.value);
5874}
5875
5876inline slice txn::get(map_handle map, const slice &key) const {
5877 slice result;
5878 error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
5879 return result;
5880}
5881
5882inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
5883 slice result;
5884 error::success_or_throw(::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
5885 return result;
5886}
5887
5888inline slice txn::get(map_handle map, const slice &key, const slice &value_at_absence) const {
5889 slice result;
5890 const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
5891 switch (err) {
5892 case MDBX_SUCCESS:
5893 return result;
5894 case MDBX_NOTFOUND:
5895 return value_at_absence;
5896 default:
5897 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5898 }
5899}
5900
5901inline slice txn::get(map_handle map, slice key, size_t &values_count, const slice &value_at_absence) const {
5902 slice result;
5903 const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
5904 switch (err) {
5905 case MDBX_SUCCESS:
5906 return result;
5907 case MDBX_NOTFOUND:
5908 return value_at_absence;
5909 default:
5910 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5911 }
5912}
5913
5915 pair result(key, slice());
5916 bool exact = !error::boolean_or_throw(::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
5917 return pair_result(result.key, result.value, exact);
5918}
5919
5920inline pair_result txn::get_equal_or_great(map_handle map, const slice &key, const slice &value_at_absence) const {
5921 pair result{key, slice()};
5922 const int err = ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
5923 switch (err) {
5924 case MDBX_SUCCESS:
5925 return pair_result{result.key, result.value, true};
5926 case MDBX_RESULT_TRUE:
5927 return pair_result{result.key, result.value, false};
5928 case MDBX_NOTFOUND:
5929 return pair_result{key, value_at_absence, false};
5930 default:
5931 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5932 }
5933}
5934
5935inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
5936 return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
5937}
5938
5939inline void txn::put(map_handle map, const slice &key, slice value, put_mode mode) {
5940 error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
5941}
5942
5943inline void txn::insert(map_handle map, const slice &key, slice value) {
5944 error::success_or_throw(put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5946}
5947
5948inline value_result txn::try_insert(map_handle map, const slice &key, slice value) {
5949 const int err = put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
5951 switch (err) {
5952 case MDBX_SUCCESS:
5953 return value_result{slice(), true};
5954 case MDBX_KEYEXIST:
5955 return value_result{value, false};
5956 default:
5957 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5958 }
5959}
5960
5961inline slice txn::insert_reserve(map_handle map, const slice &key, size_t value_length) {
5962 slice result(nullptr, value_length);
5963 error::success_or_throw(put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5965 return result;
5966}
5967
5968inline value_result txn::try_insert_reserve(map_handle map, const slice &key, size_t value_length) {
5969 slice result(nullptr, value_length);
5970 const int err = put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
5972 switch (err) {
5973 case MDBX_SUCCESS:
5974 return value_result{result, true};
5975 case MDBX_KEYEXIST:
5976 return value_result{result, false};
5977 default:
5978 MDBX_CXX20_UNLIKELY error::throw_exception(err);
5979 }
5980}
5981
5982inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
5983 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
5984}
5985
5986inline slice txn::upsert_reserve(map_handle map, const slice &key, size_t value_length) {
5987 slice result(nullptr, value_length);
5989 return result;
5990}
5991
5992inline void txn::update(map_handle map, const slice &key, const slice &value) {
5993 error::success_or_throw(put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
5994}
5995
5996inline bool txn::try_update(map_handle map, const slice &key, const slice &value) {
5997 const int err = put(map, key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
5998 switch (err) {
5999 case MDBX_SUCCESS:
6000 return true;
6001 case MDBX_NOTFOUND:
6002 return false;
6003 default:
6004 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6005 }
6006}
6007
6008inline slice txn::update_reserve(map_handle map, const slice &key, size_t value_length) {
6009 slice result(nullptr, value_length);
6011 return result;
6012}
6013
6014inline value_result txn::try_update_reserve(map_handle map, const slice &key, size_t value_length) {
6015 slice result(nullptr, value_length);
6016 const int err = put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6017 switch (err) {
6018 case MDBX_SUCCESS:
6019 return value_result{result, true};
6020 case MDBX_NOTFOUND:
6021 return value_result{slice(), false};
6022 default:
6023 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6024 }
6025}
6026
6027inline bool txn::erase(map_handle map, const slice &key) {
6028 const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6029 switch (err) {
6030 case MDBX_SUCCESS:
6031 return true;
6032 case MDBX_NOTFOUND:
6033 return false;
6034 default:
6035 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6036 }
6037}
6038
6039inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6040 const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
6041 switch (err) {
6042 case MDBX_SUCCESS:
6043 return true;
6044 case MDBX_NOTFOUND:
6045 return false;
6046 default:
6047 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6048 }
6049}
6050
6051inline void txn::replace(map_handle map, const slice &key, slice old_value, const slice &new_value) {
6052 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6053 MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6054}
6055
6056template <class ALLOCATOR, typename CAPACITY_POLICY>
6060 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6062 ::mdbx_replace_ex(handle_, map.dbi, &key, nullptr, &result.slice_, MDBX_CURRENT, result, &result), result);
6063 return result;
6064}
6065
6066template <class ALLOCATOR, typename CAPACITY_POLICY>
6068txn::replace(map_handle map, const slice &key, const slice &new_value,
6070 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6071 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value), &result.slice_,
6072 MDBX_CURRENT, result, &result),
6073 result);
6074 return result;
6075}
6076
6077template <class ALLOCATOR, typename CAPACITY_POLICY>
6079txn::replace_reserve(map_handle map, const slice &key, slice &new_value,
6081 typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(alloc);
6082 error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6083 MDBX_CURRENT | MDBX_RESERVE, result, &result),
6084 result);
6085 return result;
6086}
6087
6088inline void txn::append(map_handle map, const slice &key, const slice &value, bool multivalue_order_preserved) {
6089 error::success_or_throw(::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6090 multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP) : MDBX_APPEND));
6091}
6092
6093inline size_t txn::put_multiple_samelength(map_handle map, const slice &key, const size_t value_length,
6094 const void *values_array, size_t values_count, put_mode mode,
6095 bool allow_partial) {
6096 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6097 const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6098 switch (err) {
6099 case MDBX_SUCCESS:
6100 MDBX_CXX20_LIKELY break;
6101 case MDBX_KEYEXIST:
6102 if (allow_partial)
6103 break;
6105 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6106 default:
6107 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6108 }
6109 return args[1].iov_len /* done item count */;
6110}
6111
6112inline ptrdiff_t txn::estimate(map_handle map, const pair &from, const pair &to) const {
6113 ptrdiff_t result;
6114 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6115 return result;
6116}
6117
6118inline ptrdiff_t txn::estimate(map_handle map, const slice &from, const slice &to) const {
6119 ptrdiff_t result;
6120 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, &to, nullptr, &result));
6121 return result;
6122}
6123
6124inline ptrdiff_t txn::estimate_from_first(map_handle map, const slice &to) const {
6125 ptrdiff_t result;
6126 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr, nullptr, &to, nullptr, &result));
6127 return result;
6128}
6129
6130inline ptrdiff_t txn::estimate_to_last(map_handle map, const slice &from) const {
6131 ptrdiff_t result;
6132 error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr, nullptr, nullptr, &result));
6133 return result;
6134}
6135
6137
6138inline cursor_managed cursor::clone(void *your_context) const {
6139 cursor_managed clone(your_context);
6141 return clone;
6142}
6143
6144inline void *cursor::get_context() const noexcept { return mdbx_cursor_get_userctx(handle_); }
6145
6146inline cursor &cursor::set_context(void *ptr) {
6148 return *this;
6149}
6150
6151inline cursor &cursor::operator=(cursor &&other) noexcept {
6152 handle_ = other.handle_;
6153 other.handle_ = nullptr;
6154 return *this;
6155}
6156
6157inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; }
6158
6159inline cursor::~cursor() noexcept {
6160#ifndef NDEBUG
6161 handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6162#endif
6163}
6164
6165MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept { return handle_ != nullptr; }
6166
6167MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const { return handle_; }
6168
6169MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6170
6171MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a, const cursor &b) noexcept { return a.handle_ == b.handle_; }
6172
6173MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a, const cursor &b) noexcept { return a.handle_ != b.handle_; }
6174
6175inline int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested = false) noexcept {
6176 return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6177}
6178
6179inline int compare_position(const cursor &left, const cursor &right, bool ignore_nested = false) {
6180 const auto diff = compare_position_nothrow(left, right, ignore_nested);
6181 assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6182 if (MDBX_LIKELY(int16_t(diff) == diff))
6183 MDBX_CXX20_LIKELY return int(diff);
6184 else
6186}
6187
6188inline cursor::move_result::move_result(const cursor &cursor, bool throw_notfound) : pair_result() {
6189 done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6190}
6191
6193 bool throw_notfound)
6194 : pair_result(key, value, false) {
6195 this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
6196}
6197
6198inline bool cursor::move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const {
6199 const int err = ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
6200 switch (err) {
6201 case MDBX_SUCCESS:
6202 MDBX_CXX20_LIKELY return true;
6203 case MDBX_RESULT_TRUE:
6204 return false;
6205 case MDBX_NOTFOUND:
6206 if (!throw_notfound)
6207 return false;
6208 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6209 default:
6210 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6211 }
6212}
6213
6215 const slice &value)
6216 : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
6217 approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
6218}
6219
6220inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const {
6221 ptrdiff_t result;
6222 error::success_or_throw(::mdbx_estimate_move(*this, key, value, MDBX_cursor_op(operation), &result));
6223 return result;
6224}
6225
6226inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
6227 ptrdiff_t result;
6229 return result;
6230}
6231
6232inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
6233 return move(key_exact, key, throw_notfound);
6234}
6235
6236inline cursor::move_result cursor::lower_bound(const slice &key, bool throw_notfound) {
6237 return move(key_lowerbound, key, throw_notfound);
6238}
6239
6240inline cursor::move_result cursor::upper_bound(const slice &key, bool throw_notfound) {
6241 return move(key_greater_than, key, throw_notfound);
6242}
6243
6244inline cursor::move_result cursor::find_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6245 return move(multi_find_pair, key, value, throw_notfound);
6246}
6247
6248inline cursor::move_result cursor::lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6249 return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
6250}
6251
6252inline cursor::move_result cursor::upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound) {
6253 return move(multi_exactkey_value_greater, key, value, throw_notfound);
6254}
6255
6256inline bool cursor::seek(const slice &key) { return move(seek_key, const_cast<slice *>(&key), nullptr, false); }
6257
6258inline size_t cursor::count_multivalue() const {
6259 size_t result;
6261 return result;
6262}
6263
6264inline bool cursor::eof() const { return error::boolean_or_throw(::mdbx_cursor_eof(*this)); }
6265
6267
6269
6271
6273
6274inline cursor::estimate_result cursor::estimate(const slice &key, const slice &value) const {
6275 return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
6276}
6277
6279 return estimate_result(*this, key_lowerbound, key);
6280}
6281
6283 return estimate_result(*this, operation);
6284}
6285
6287
6291
6293
6294inline txn cursor::txn() const {
6296 return ::mdbx::txn(txn);
6297}
6298
6299inline map_handle cursor::map() const {
6300 const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
6301 if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
6303 return map_handle(dbi);
6304}
6305
6306inline MDBX_error_t cursor::put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept {
6307 return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
6308}
6309
6310inline void cursor::put(const slice &key, slice value, put_mode mode) {
6311 error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
6312}
6313
6314inline void cursor::insert(const slice &key, slice value) {
6316 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique)));
6317}
6318
6319inline value_result cursor::try_insert(const slice &key, slice value) {
6320 const int err =
6321 put(key, &value /* takes the present value in case MDBX_KEYEXIST */, MDBX_put_flags_t(put_mode::insert_unique));
6322 switch (err) {
6323 case MDBX_SUCCESS:
6324 return value_result{slice(), true};
6325 case MDBX_KEYEXIST:
6326 return value_result{value, false};
6327 default:
6328 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6329 }
6330}
6331
6332inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
6333 slice result(nullptr, value_length);
6334 error::success_or_throw(put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6336 return result;
6337}
6338
6339inline value_result cursor::try_insert_reserve(const slice &key, size_t value_length) {
6340 slice result(nullptr, value_length);
6341 const int err = put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
6343 switch (err) {
6344 case MDBX_SUCCESS:
6345 return value_result{result, true};
6346 case MDBX_KEYEXIST:
6347 return value_result{result, false};
6348 default:
6349 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6350 }
6351}
6352
6353inline void cursor::upsert(const slice &key, const slice &value) {
6354 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::upsert)));
6355}
6356
6357inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
6358 slice result(nullptr, value_length);
6360 return result;
6361}
6362
6363inline void cursor::update(const slice &key, const slice &value) {
6364 error::success_or_throw(put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update)));
6365}
6366
6367inline bool cursor::try_update(const slice &key, const slice &value) {
6368 const int err = put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
6369 switch (err) {
6370 case MDBX_SUCCESS:
6371 return true;
6372 case MDBX_NOTFOUND:
6373 return false;
6374 default:
6375 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6376 }
6377}
6378
6379inline slice cursor::update_reserve(const slice &key, size_t value_length) {
6380 slice result(nullptr, value_length);
6382 return result;
6383}
6384
6385inline value_result cursor::try_update_reserve(const slice &key, size_t value_length) {
6386 slice result(nullptr, value_length);
6387 const int err = put(key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6388 switch (err) {
6389 case MDBX_SUCCESS:
6390 return value_result{result, true};
6391 case MDBX_NOTFOUND:
6392 return value_result{slice(), false};
6393 default:
6394 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6395 }
6396}
6397
6398inline bool cursor::erase(bool whole_multivalue) {
6399 const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS : MDBX_CURRENT);
6400 switch (err) {
6401 case MDBX_SUCCESS:
6402 MDBX_CXX20_LIKELY return true;
6403 case MDBX_NOTFOUND:
6404 return false;
6405 default:
6406 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6407 }
6408}
6409
6410inline bool cursor::erase(const slice &key, bool whole_multivalue) {
6411 bool found = seek(key);
6412 return found ? erase(whole_multivalue) : found;
6413}
6414
6415inline bool cursor::erase(const slice &key, const slice &value) {
6416 move_result data = find_multivalue(key, value, false);
6417 return data.done && erase();
6418}
6419
6420inline size_t cursor::put_multiple_samelength(const slice &key, const size_t value_length, const void *values_array,
6421 size_t values_count, put_mode mode, bool allow_partial) {
6422 MDBX_val args[2] = {{const_cast<void *>(values_array), value_length}, {nullptr, values_count}};
6423 const int err = ::mdbx_cursor_put(handle_, const_cast<slice *>(&key), args, MDBX_put_flags_t(mode) | MDBX_MULTIPLE);
6424 switch (err) {
6425 case MDBX_SUCCESS:
6426 MDBX_CXX20_LIKELY break;
6427 case MDBX_KEYEXIST:
6428 if (allow_partial)
6429 break;
6431 MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6432 default:
6433 MDBX_CXX20_UNLIKELY error::throw_exception(err);
6434 }
6435 return args[1].iov_len /* done item count */;
6436}
6437
6438//------------------------------------------------------------------------------
6439
6440LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
6441LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
6442LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
6443LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry::size &);
6444LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
6445LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_parameters &);
6446LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
6447LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::durability &);
6448LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::reclaiming_options &);
6449LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::operate_options &);
6450LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env_managed::create_parameters &);
6451
6452LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_log_level_t &);
6453LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const MDBX_debug_flags_t &);
6454LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
6455
6456inline ::std::ostream &operator<<(::std::ostream &out, const MDBX_error_t &errcode) { return out << error(errcode); }
6457
6459
6460} // namespace mdbx
6461
6462//------------------------------------------------------------------------------
6463
6466namespace std {
6467
6468inline string to_string(const ::mdbx::slice &value) {
6469 ostringstream out;
6470 out << value;
6471 return out.str();
6472}
6473
6474template <class ALLOCATOR, typename CAPACITY_POLICY>
6475inline string to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
6476 ostringstream out;
6477 out << buffer;
6478 return out.str();
6479}
6480
6481inline string to_string(const ::mdbx::pair &value) {
6482 ostringstream out;
6483 out << value;
6484 return out.str();
6485}
6486
6487inline string to_string(const ::mdbx::env::geometry &value) {
6488 ostringstream out;
6489 out << value;
6490 return out.str();
6491}
6492
6493inline string to_string(const ::mdbx::env::operate_parameters &value) {
6494 ostringstream out;
6495 out << value;
6496 return out.str();
6497}
6498
6499inline string to_string(const ::mdbx::env::mode &value) {
6500 ostringstream out;
6501 out << value;
6502 return out.str();
6503}
6504
6505inline string to_string(const ::mdbx::env::durability &value) {
6506 ostringstream out;
6507 out << value;
6508 return out.str();
6509}
6510
6511inline string to_string(const ::mdbx::env::reclaiming_options &value) {
6512 ostringstream out;
6513 out << value;
6514 return out.str();
6515}
6516
6517inline string to_string(const ::mdbx::env::operate_options &value) {
6518 ostringstream out;
6519 out << value;
6520 return out.str();
6521}
6522
6523inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
6524 ostringstream out;
6525 out << value;
6526 return out.str();
6527}
6528
6529inline string to_string(const ::MDBX_log_level_t &value) {
6530 ostringstream out;
6531 out << value;
6532 return out.str();
6533}
6534
6535inline string to_string(const ::MDBX_debug_flags_t &value) {
6536 ostringstream out;
6537 out << value;
6538 return out.str();
6539}
6540
6541inline string to_string(const ::mdbx::error &value) {
6542 ostringstream out;
6543 out << value;
6544 return out.str();
6545}
6546
6547inline string to_string(const ::MDBX_error_t &errcode) { return to_string(::mdbx::error(errcode)); }
6548
6549template <> struct hash<::mdbx::slice> {
6550 MDBX_CXX14_CONSTEXPR size_t operator()(const ::mdbx::slice &slice) const noexcept { return slice.hash_value(); }
6551};
6552
6553template <> struct hash<::mdbx::map_handle> {
6554 MDBX_CXX11_CONSTEXPR size_t operator()(const ::mdbx::map_handle &handle) const noexcept { return handle.dbi; }
6555};
6556
6557template <> struct hash<::mdbx::env> : public std::hash<const MDBX_env *> {
6558 using inherited = std::hash<const MDBX_env *>;
6559 size_t operator()(const ::mdbx::env &env) const noexcept { return inherited::operator()(env); }
6560};
6561
6562template <> struct hash<::mdbx::txn> : public std::hash<const MDBX_txn *> {
6563 using inherited = std::hash<const MDBX_txn *>;
6564 size_t operator()(const ::mdbx::txn &txn) const noexcept { return inherited::operator()(txn); }
6565};
6566
6567template <> struct hash<::mdbx::cursor> : public std::hash<const MDBX_cursor *> {
6568 using inherited = std::hash<const MDBX_cursor *>;
6569 size_t operator()(const ::mdbx::cursor &cursor) const noexcept { return inherited::operator()(cursor); }
6570};
6571
6572template <class ALLOCATOR, typename CAPACITY_POLICY> struct hash<::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY>> {
6573 size_t operator()(::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> const &buffer) const noexcept {
6574 return buffer.hash_value();
6575 }
6576};
6577
6578} // namespace std
6579
6580#if defined(__LCC__) && __LCC__ >= 126
6581#pragma diagnostic pop
6582#endif
6583
6584#ifdef _MSC_VER
6585#pragma warning(pop)
6586#endif
Definition mdbx.h++:1156
Definition mdbx.h++:1146
Definition mdbx.h++:1166
#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:5170
The fours integers markers (aka "canary") associated with the environment.
Definition mdbx.h:4663
Latency of commit stages in 1/65536 of seconds units.
Definition mdbx.h:4102
Information about the environment.
Definition mdbx.h:2796
Statistics for a table in the environment.
Definition mdbx.h:2750
Information about the transaction.
Definition mdbx.h:4004
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:5463
LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result, uint64_t increment)
Sequence generation for a table.
LIBMDBX_API int mdbx_get_equal_or_great(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data)
Get equal or great item from a table.
LIBMDBX_API int mdbx_cursor_scan(MDBX_cursor *cursor, MDBX_predicate_func *predicate, void *context, MDBX_cursor_op start_op, MDBX_cursor_op turn_op, void *arg)
Scans the table using the passed predicate, reducing the associated overhead.
LIBMDBX_API int mdbx_canary_put(MDBX_txn *txn, const MDBX_canary *canary)
Set integers markers (aka "canary") associated with the environment.
LIBMDBX_API int mdbx_canary_get(const MDBX_txn *txn, MDBX_canary *canary)
Returns fours integers markers (aka "canary") associated with the environment.
MDBX_put_flags_t
Data changing flags.
Definition mdbx.h:1629
LIBMDBX_API int mdbx_replace_ex(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *new_data, MDBX_val *old_data, MDBX_put_flags_t flags, MDBX_preserve_func preserver, void *preserver_context)
Replaces item in a table using preservation callback for an original data.
LIBMDBX_API int mdbx_cursor_count(const MDBX_cursor *cursor, size_t *count)
Return count values (aka duplicates) for current key.
LIBMDBX_API int mdbx_cursor_scan_from(MDBX_cursor *cursor, MDBX_predicate_func *predicate, void *context, MDBX_cursor_op from_op, MDBX_val *from_key, MDBX_val *from_value, MDBX_cursor_op turn_op, void *arg)
void mdbx_cache_init(MDBX_cache_entry_t *entry)
Initializes the cache entry before the first use.
Definition mdbx.h:5184
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:4723
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, const MDBX_val *data)
Delete items from a table.
LIBMDBX_API int mdbx_get_ex(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, size_t *values_count)
Get items from a table and optionally number of data items for a given key.
LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store by cursor.
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data, MDBX_put_flags_t flags)
Store items into a table.
LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del)
Empty or delete and close a table.
LIBMDBX_API int mdbx_cursor_get(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data, MDBX_cursor_op op)
Retrieve by cursor.
LIBMDBX_API int mdbx_get(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data)
Get items from a table.
@ MDBX_MULTIPLE
Definition mdbx.h:1666
@ MDBX_ALLDUPS
Definition mdbx.h:1649
@ MDBX_CURRENT
Definition mdbx.h:1644
@ MDBX_APPENDDUP
Definition mdbx.h:1662
@ MDBX_APPEND
Definition mdbx.h:1657
@ MDBX_UPSERT
Definition mdbx.h:1631
@ MDBX_RESERVE
Definition mdbx.h:1653
@ MDBX_NOOVERWRITE
Definition mdbx.h:1634
LIBMDBX_API int mdbx_cursor_on_first_dup(const MDBX_cursor *cursor)
Determines whether the cursor is on the first or single multi-value corresponding to the key.
LIBMDBX_API int mdbx_cursor_open(MDBX_txn *txn, MDBX_dbi dbi, MDBX_cursor **cursor)
Create a cursor handle for the specified transaction and DBI handle.
LIBMDBX_API int mdbx_cursor_unbind(MDBX_cursor *cursor)
Unbind cursor from a transaction.
LIBMDBX_API MDBX_cursor * mdbx_cursor_create(void *context)
Create a cursor handle but not bind it to transaction nor DBI-handle.
LIBMDBX_API MDBX_dbi mdbx_cursor_dbi(const MDBX_cursor *cursor)
Return the cursor's table handle.
MDBX_cursor_op
Cursor operationsThis is the set of all operations for retrieving data using a cursor.
Definition mdbx.h:1710
LIBMDBX_API int mdbx_cursor_compare(const MDBX_cursor *left, const MDBX_cursor *right, bool ignore_multival)
Compares the position of the cursors.
LIBMDBX_API int mdbx_cursor_on_last_dup(const MDBX_cursor *cursor)
Determines whether the cursor is on the last or single multi-value corresponding to the key.
LIBMDBX_API int mdbx_cursor_on_first(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to the first key-value pair or not.
LIBMDBX_API int mdbx_cursor_bind(MDBX_txn *txn, MDBX_cursor *cursor, MDBX_dbi dbi)
Bind cursor to specified transaction and DBI-handle.
LIBMDBX_API int mdbx_txn_release_all_cursors_ex(const MDBX_txn *txn, bool unbind, size_t *count)
Unbind or closes all cursors of a given transaction and of all its parent transactions if ones are.
struct MDBX_cursor MDBX_cursor
Opaque structure for navigating through a table.
Definition mdbx.h:743
LIBMDBX_API int mdbx_cursor_set_userctx(MDBX_cursor *cursor, void *ctx)
Set application information associated with the cursor.
LIBMDBX_API int mdbx_cursor_eof(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to a key-value pair or not, i.e. was not positioned or point...
LIBMDBX_API int mdbx_cursor_close2(MDBX_cursor *cursor)
Closes a cursor handle with returning error code.
LIBMDBX_API void * mdbx_cursor_get_userctx(const MDBX_cursor *cursor)
Get the application information associated with the MDBX_cursor.
LIBMDBX_API int mdbx_cursor_renew(MDBX_txn *txn, MDBX_cursor *cursor)
Renew a cursor handle for use within the given transaction.
LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor)
Closes a cursor handle without returning error code.
LIBMDBX_API MDBX_txn * mdbx_cursor_txn(const MDBX_cursor *cursor)
Return the cursor's transaction handle.
LIBMDBX_API int mdbx_cursor_on_last(const MDBX_cursor *cursor)
Determines whether the cursor is pointed to the last key-value pair or not.
LIBMDBX_API int mdbx_cursor_copy(const MDBX_cursor *src, MDBX_cursor *dest)
Copy cursor position and state.
@ MDBX_SEEK_AND_GET_MULTIPLE
Definition mdbx.h:1829
@ MDBX_GET_CURRENT
Definition mdbx.h:1725
@ MDBX_GET_BOTH
Definition mdbx.h:1718
@ MDBX_TO_KEY_EQUAL
Definition mdbx.h:1806
@ MDBX_GET_BOTH_RANGE
Definition mdbx.h:1722
@ MDBX_SET_KEY
Definition mdbx.h:1765
@ MDBX_FIRST_DUP
Definition mdbx.h:1715
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition mdbx.h:1805
@ MDBX_GET_MULTIPLE
Definition mdbx.h:1730
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition mdbx.h:1816
@ MDBX_NEXT_NODUP
Definition mdbx.h:1750
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition mdbx.h:1813
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition mdbx.h:1814
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition mdbx.h:1821
@ MDBX_PREV_MULTIPLE
Definition mdbx.h:1773
@ MDBX_SET_RANGE
Definition mdbx.h:1768
@ MDBX_LAST_DUP
Definition mdbx.h:1736
@ MDBX_PREV
Definition mdbx.h:1753
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition mdbx.h:1823
@ MDBX_TO_PAIR_GREATER_THAN
Definition mdbx.h:1824
@ MDBX_LAST
Definition mdbx.h:1733
@ MDBX_TO_KEY_LESSER_THAN
Definition mdbx.h:1804
@ MDBX_PREV_DUP
Definition mdbx.h:1756
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition mdbx.h:1812
@ MDBX_SET
Definition mdbx.h:1762
@ MDBX_NEXT
Definition mdbx.h:1739
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition mdbx.h:1807
@ MDBX_TO_PAIR_LESSER_THAN
Definition mdbx.h:1820
@ MDBX_NEXT_MULTIPLE
Definition mdbx.h:1747
@ MDBX_PREV_NODUP
Definition mdbx.h:1759
@ MDBX_TO_PAIR_EQUAL
Definition mdbx.h:1822
@ MDBX_NEXT_DUP
Definition mdbx.h:1742
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition mdbx.h:1815
@ MDBX_TO_KEY_GREATER_THAN
Definition mdbx.h:1808
@ MDBX_FIRST
Definition mdbx.h:1712
LIBMDBX_API int mdbx_dbi_rename(MDBX_txn *txn, MDBX_dbi dbi, const char *name)
Renames the table using the DBI descriptor.
LIBMDBX_API int mdbx_dbi_rename2(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *name)
Renames the table using the DBI descriptor.
LIBMDBX_API int mdbx_dbi_close(MDBX_env *env, MDBX_dbi dbi)
Close a table handle. Normally unnecessary.
LIBMDBX_API int mdbx_dbi_open(MDBX_txn *txn, const char *name, MDBX_db_flags_t flags, MDBX_dbi *dbi)
Open or Create a named table in the environment.
LIBMDBX_API int mdbx_dbi_open2(MDBX_txn *txn, const MDBX_val *name, MDBX_db_flags_t flags, MDBX_dbi *dbi)
Open or Create a named table in the environment.
uint32_t MDBX_dbi
A handle for an individual table (key-value spaces) in the environment.
Definition mdbx.h:736
MDBX_db_flags_t
Table flags.
Definition mdbx.h:1579
@ MDBX_INTEGERDUP
Definition mdbx.h:1603
@ MDBX_DB_ACCEDE
Definition mdbx.h:1621
@ MDBX_DB_DEFAULTS
Definition mdbx.h:1581
@ MDBX_REVERSEKEY
Definition mdbx.h:1584
@ MDBX_DUPFIXED
Definition mdbx.h:1598
@ MDBX_INTEGERKEY
Definition mdbx.h:1594
@ MDBX_REVERSEDUP
Definition mdbx.h:1606
@ MDBX_CREATE
Definition mdbx.h:1609
@ MDBX_DUPSORT
Definition mdbx.h:1587
MDBX_log_level_t
Definition mdbx.h:856
MDBX_debug_flags_t
Runtime debug flags.
Definition mdbx.h:915
LIBMDBX_API int mdbx_env_set_hsr(MDBX_env *env, MDBX_hsr_func *hsr_callback)
Sets a Handle-Slow-Readers callback to resolve database full/overflow issue due to a reader(s) which ...
int MDBX_hsr_func(const MDBX_env *env, const MDBX_txn *txn, mdbx_pid_t pid, mdbx_tid_t tid, uint64_t laggard, unsigned gap, size_t space, int retry) noexcept
A Handle-Slow-Readers callback function to resolve database full/overflow issue due to a reader(s) wh...
Definition mdbx.h:6754
MDBX_error_t
Errors and return codes.
Definition mdbx.h:1837
@ MDBX_FIRST_LMDB_ERRCODE
Definition mdbx.h:1851
@ MDBX_BAD_TXN
Definition mdbx.h:1916
@ MDBX_LAST_LMDB_ERRCODE
Definition mdbx.h:1930
@ MDBX_SUCCESS
Definition mdbx.h:1839
@ MDBX_NOTFOUND
Definition mdbx.h:1854
@ MDBX_RESULT_TRUE
Definition mdbx.h:1845
@ MDBX_BUSY
Definition mdbx.h:1934
@ MDBX_EINVAL
Definition mdbx.h:2010
@ MDBX_ENOMEM
Definition mdbx.h:2012
@ MDBX_FIRST_ADDED_ERRCODE
Definition mdbx.h:1937
@ MDBX_RESULT_FALSE
Definition mdbx.h:1842
@ MDBX_LAST_ADDED_ERRCODE
Definition mdbx.h:1989
@ 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:2532
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition mdbx.h:2527
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h:2530
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:3043
MDBX_option_t
MDBX environment extra runtime options.
Definition mdbx.h:2120
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:2982
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:2225
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h:2221
@ 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:2325
@ MDBX_opt_max_db
Controls the maximum number of named tables for the environment.
Definition mdbx.h:2129
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h:2292
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h:2152
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h:2257
@ 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:2280
@ 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:2192
@ 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:2179
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition mdbx.h:2146
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h:2241
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition mdbx.h:2158
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h:2206
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h:2320
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:3660
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:3063
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:3000
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:4985
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:3705
LIBMDBX_API intptr_t mdbx_limits_keysize_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal key size in bytes for given page size and table flags, or -1 if pagesize is invalid.
LIBMDBX_API int mdbx_reader_list(const MDBX_env *env, MDBX_reader_list_func *func, void *ctx)
Enumerate the entries in the reader lock table.
LIBMDBX_API intptr_t mdbx_limits_pairsize4page_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns maximal size of key-value pair to fit in a single page with the given size and table flags,...
LIBMDBX_API intptr_t mdbx_limits_dbsize_max(intptr_t pagesize)
Returns maximal database size in bytes for given page size, or -1 if pagesize is invalid.
LIBMDBX_API intptr_t mdbx_limits_dbsize_min(intptr_t pagesize)
Returns minimal database size in bytes for given page size, or -1 if pagesize is invalid.
LIBMDBX_API int mdbx_env_get_flags(const MDBX_env *env, unsigned *flags)
Get environment flags.
LIBMDBX_API int mdbx_dbi_flags_ex(const MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags, unsigned *state)
Retrieve the DB flags and status for a table handle.
LIBMDBX_API int mdbx_txn_break(MDBX_txn *txn)
Marks transaction as broken to prevent further operations.
LIBMDBX_API int mdbx_txn_set_userctx(MDBX_txn *txn, void *ctx)
Sets application information associated (a context pointer) with the transaction.
LIBMDBX_API int mdbx_txn_clone(const MDBX_txn *origin, MDBX_txn **in_out_clone, void *context)
Starts a read-only clone of a given transaction.
LIBMDBX_API int mdbx_txn_park(MDBX_txn *txn, bool autounpark)
Puts the reading transaction in a "parked" state.
LIBMDBX_API int mdbx_txn_unpark(MDBX_txn *txn, bool restart_if_ousted)
Unparks a previously parked reading transaction.
MDBX_txn_flags_t
Definition mdbx.h:1478
LIBMDBX_API void * mdbx_txn_get_userctx(const MDBX_txn *txn)
Returns an application information (a context pointer) associated with the transaction.
int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, MDBX_txn_flags_t flags, MDBX_txn **txn)
Create a transaction for use with the environment.
Definition mdbx.h:3921
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++:4087
friend class env
Definition mdbx.h++:4044
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
::MDBX_txn_info info
Definition mdbx.h++:3730
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition mdbx.h++:4544
~txn_managed() noexcept
::MDBX_stat map_stat
Definition mdbx.h++:3896
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++:3437
@ prefault_write_enable
Controls prevention of page-faults of reclaimed and allocated pages in the MDBX_WRITEMAP mode by clea...
Definition mdbx.h++:3471
@ spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition mdbx.h++:3463
@ spill_parent4child_denominator
Controls the in-process how much of the parent transaction dirty pages will be spilled while start ea...
Definition mdbx.h++:3465
@ writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition mdbx.h++:3469
@ sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition mdbx.h++:3446
@ dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition mdbx.h++:3457
@ dp_initial
Controls the in-process initial allocation size for dirty pages list of a write transaction....
Definition mdbx.h++:3459
@ spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition mdbx.h++:3461
@ merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition mdbx.h++:3467
@ 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++:3451
@ loose_limit
Controls the in-process limit to grow a cache of dirty pages for reuse in the current transaction.
Definition mdbx.h++:3453
@ dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition mdbx.h++:3455
env_managed & operator=(env_managed &&other) noexcept
Definition mdbx.h++:3664
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
Definition mdbx.h++:3877
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++:2936
path get_path() const
Return the path that was used for opening the environment.
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4389
move_result previous_multiple_samelength(bool throw_notfound=false)
Definition mdbx.h++:4445
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition mdbx.h++:2905
durability
Durability level.
Definition mdbx.h++:3082
@ lazy_weak_tail
Definition mdbx.h++:3085
@ robust_synchronous
Definition mdbx.h++:3083
@ whole_fragile
Definition mdbx.h++:3086
@ half_synchronous_weak_last
Definition mdbx.h++:3084
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++:2932
size_t dbsize_min() const
Returns the minimal database size in bytes for the environment.
Definition mdbx.h++:3252
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++:4433
bool checkpoint(finalization_latency &latency)
Commits all the operations of the transaction and immediately starts next without releasing any locks...
Definition mdbx.h++:4101
estimate_result estimate(move_operation operation, slice &key) const
cache_entry() noexcept
Definition mdbx.h++:2766
static bool remove(const char *pathname, const remove_mode mode=just_remove)
friend class cursor
Definition mdbx.h++:3687
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4408
::MDBX_canary canary
Definition mdbx.h++:3905
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++:4104
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++:3728
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++:4338
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++:4402
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++:5269
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4411
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++:2773
friend constexpr bool operator<=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2926
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition mdbx.h++:2906
void put(const pair &kv, put_mode mode)
Definition mdbx.h++:4497
move_result current(bool throw_notfound=true) const
Definition mdbx.h++:4356
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++:4347
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++:4173
size_t unbind_all_cursors() const
Unbind all cursors.
Definition mdbx.h++:3784
void upsert(map_handle map, const pair &kv)
Definition mdbx.h++:3960
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4379
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4165
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4169
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++:3869
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition mdbx.h++:3179
move_result to_next_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4363
MDBX_cursor * withdraw_handle() noexcept
Definition mdbx.h++:4566
MDBX_txn * handle_
Definition mdbx.h++:3688
void abort()
Abandon all the operations of the transaction instead of saving ones.
MDBX_commit_latency finalization_latency
Definition mdbx.h++:4066
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition mdbx.h++:4335
mode
Operation mode.
Definition mdbx.h++:3074
@ write_mapped_io
Definition mdbx.h++:3077
@ nested_transactions
Definition mdbx.h++:3078
@ readonly
Definition mdbx.h++:3075
@ write_file_io
Definition mdbx.h++:3076
bool is_writemap() const
Definition mdbx.h++:3345
move_result move(move_operation operation, bool throw_notfound)
Definition mdbx.h++:4332
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4291
::MDBX_envinfo info
Information about the environment.
Definition mdbx.h++:3313
operator::mdbx::txn() const
Definition mdbx.h++:4474
MDBX_env * handle_
Definition mdbx.h++:2975
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++:4395
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4161
move_result to_first(bool throw_notfound=true)
Definition mdbx.h++:4345
move_result to_last(bool throw_notfound=true)
Definition mdbx.h++:4365
cache_entry(cache_entry &&other) noexcept
Definition mdbx.h++:2769
bool is_nested_transactions_available() const
Definition mdbx.h++:3349
void close()
Explicitly closes the cursor.
Definition mdbx.h++:4550
void abort(finalization_latency &latency)
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4073
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++:4376
bool is_readonly() const
Checks whether the transaction is read-only.
Definition mdbx.h++:3725
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++:4441
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++:4008
cursor_managed & operator=(const cursor_managed &)=delete
remove_mode
Deletion modes for remove().
Definition mdbx.h++:3283
@ ensure_unused
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition mdbx.h++:3293
@ wait_for_unused
Wait until other processes closes the environment before deletion.
Definition mdbx.h++:3295
@ just_remove
Just delete the environment's files and directory if any.
Definition mdbx.h++:3290
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition mdbx.h++:4267
move_result to_current_first_multi(bool throw_notfound=true)
Definition mdbx.h++:4350
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition mdbx.h++:4312
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition mdbx.h++:4556
::MDBX_dbi_state_t state
Definition mdbx.h++:2937
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition mdbx.h++:3494
void put_multiple_samelength(const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4524
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++:3258
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4405
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++:4437
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4367
move_result to_next(bool throw_notfound=true)
Definition mdbx.h++:4364
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
operator::mdbx::map_handle() const
Definition mdbx.h++:4475
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition mdbx.h++:3254
friend constexpr bool operator>=(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2929
size_t close_all_cursors() const
Close all cursors.
Definition mdbx.h++:3781
friend constexpr bool operator<(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2920
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++:4382
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition mdbx.h++:3319
void put(map_handle map, const pair &kv, put_mode mode)
Definition mdbx.h++:3957
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++:6179
void put_multiple_samelength(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition mdbx.h++:4024
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++:3265
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++:3862
friend constexpr bool operator==(const map_handle &a, const map_handle &b) noexcept
Definition mdbx.h++:2917
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++:4115
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++:4016
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++:4118
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++:2923
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++:4417
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
move_operation
Definition mdbx.h++:4183
@ multi_exactkey_lowerboundvalue
Definition mdbx.h++:4198
@ multi_exactkey_value_equal
Definition mdbx.h++:4215
@ pair_greater_or_equal
Definition mdbx.h++:4223
@ key_lesser_than
Definition mdbx.h++:4205
@ next
Definition mdbx.h++:4186
@ pair_exact
Definition mdbx.h++:4222
@ multi_exactkey_value_greater_or_equal
Definition mdbx.h++:4216
@ pair_lesser_or_equal
Definition mdbx.h++:4220
@ batch_samelength
Definition mdbx.h++:4226
@ seek_key
Definition mdbx.h++:4200
@ key_lowerbound
Definition mdbx.h++:4202
@ pair_lesser_than
Definition mdbx.h++:4219
@ pair_equal
Definition mdbx.h++:4221
@ key_greater_than
Definition mdbx.h++:4209
@ batch_samelength_next
Definition mdbx.h++:4227
@ multi_find_pair
Definition mdbx.h++:4197
@ key_greater_or_equal
Definition mdbx.h++:4208
@ key_exact
Definition mdbx.h++:4201
@ key_equal
Definition mdbx.h++:4207
@ multi_currentkey_prevvalue
Definition mdbx.h++:4192
@ key_lesser_or_equal
Definition mdbx.h++:4206
@ multi_nextkey_firstvalue
Definition mdbx.h++:4195
@ get_current
Definition mdbx.h++:4188
@ multi_exactkey_value_lesser_or_equal
Definition mdbx.h++:4214
@ multi_prevkey_lastvalue
Definition mdbx.h++:4190
@ previous
Definition mdbx.h++:4187
@ last
Definition mdbx.h++:4185
@ pair_greater_than
Definition mdbx.h++:4224
@ multi_exactkey_value_lesser_than
Definition mdbx.h++:4213
@ multi_currentkey_firstvalue
Definition mdbx.h++:4191
@ first
Definition mdbx.h++:4184
@ batch_samelength_previous
Definition mdbx.h++:4228
@ multi_currentkey_nextvalue
Definition mdbx.h++:4193
@ seek_and_batch_samelength
Definition mdbx.h++:4229
@ multi_exactkey_value_greater
Definition mdbx.h++:4217
@ multi_currentkey_lastvalue
Definition mdbx.h++:4194
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++:4090
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition mdbx.h++:4341
void insert(const pair &kv)
Definition mdbx.h++:4498
bool is_dirty(const slice &item) const
Checks whether the given slice is on a dirty page.
Definition mdbx.h++:3722
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++:4500
move_result to_current_prev_multi(bool throw_notfound=true)
Definition mdbx.h++:4353
txn_managed & operator=(const txn_managed &)=delete
bool is_cooperative() const
Definition mdbx.h++:3343
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
Definition mdbx.h++:3882
friend constexpr bool operator==(const env &a, const env &b) noexcept
Definition mdbx.h++:5267
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4392
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++:4360
bool is_readonly() const
Definition mdbx.h++:3339
value_result try_insert(const pair &kv)
Definition mdbx.h++:4499
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++:4516
constexpr cursor() noexcept=default
bool is_exclusive() const
Definition mdbx.h++:3341
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4370
finalization_latency abort_get_latency()
Abandon all the operations of the transaction instead of saving ones with collecting latencies inform...
Definition mdbx.h++:4076
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4414
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition mdbx.h++:3262
MDBX_cursor * handle_
Definition mdbx.h++:4137
~cursor_managed() noexcept
Definition mdbx.h++:4574
bool is_readwite() const
Definition mdbx.h++:3347
MDBX_dbi dbi
Definition mdbx.h++:2904
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:4386
move_result to_current_next_multi(bool throw_notfound=true)
Definition mdbx.h++:4357
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition mdbx.h++:3736
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++:4398
txn_managed(const txn_managed &)=delete
friend int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested) noexcept
Definition mdbx.h++:6175
::MDBX_stat stat
Statistics for a database in the MDBX environment.
Definition mdbx.h++:3310
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition mdbx.h++:3260
cache_entry(const cache_entry &) noexcept=default
value_result try_insert(map_handle map, const pair &kv)
Definition mdbx.h++:3959
void insert(map_handle map, const pair &kv)
Definition mdbx.h++:3958
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++:3890
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:4373
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++:4346
friend class txn
Definition mdbx.h++:2972
bool is_before_than(const cursor &other, bool ignore_nested=false) const
Definition mdbx.h++:4157
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition mdbx.h++:3256
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition mdbx.h++:3739
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition mdbx.h++:4286
Unmanaged cursor.
Definition mdbx.h++:4135
Managed cursor.
Definition mdbx.h++:4536
Unmanaged database environment.
Definition mdbx.h++:2971
Managed database environment.
Definition mdbx.h++:3603
Unmanaged database transaction.
Definition mdbx.h++:3685
Managed database transaction.
Definition mdbx.h++:4042
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++:5310
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:5174
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition mdbx.h++:4844
polymorphic_allocator default_allocator
Definition mdbx.h++:397
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4853
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4935
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++:5148
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++:5595
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++:5086
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++:5077
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition mdbx.h++:5659
static size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags)
Returns the maximal value size in bytes for specified page size and table flags.
Definition mdbx.h++:5338
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition mdbx.h++:4949
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition mdbx.h++:4674
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++:6051
void renew(::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition mdbx.h++:6286
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition mdbx.h++:2818
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition mdbx.h++:4831
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition mdbx.h++:4631
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4929
void reset_reading()
Reset read-only transaction.
Definition mdbx.h++:5692
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++:4821
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4709
void rethrow_captured() const
Definition mdbx.h++:4646
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:4829
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition mdbx.h++:6244
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition mdbx.h++:6220
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition mdbx.h++:5303
geometry & make_dynamic(intptr_t lower=default_value, intptr_t upper=default_value) noexcept
Definition mdbx.h++:5277
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++:5095
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6014
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5968
void close_map(const map_handle &)
Close a key-value map (aka table) handle. Normally unnecessary.
Definition mdbx.h++:5557
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++:5488
move_result(const cursor &cursor, bool throw_notfound)
Definition mdbx.h++:6188
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++:5127
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition mdbx.h++:4851
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition mdbx.h++:6124
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++:5153
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4876
slice & assign(const void *ptr, size_t bytes)
Definition mdbx.h++:4777
void unbind()
Unbind cursor from a transaction.
Definition mdbx.h++:6292
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition mdbx.h++:462
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5961
constexpr cursor(MDBX_cursor *ptr) noexcept
Definition mdbx.h++:6136
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition mdbx.h++:5789
void throw_on_failure() const
Definition mdbx.h++:4686
bool try_update(const slice &key, const slice &value)
Definition mdbx.h++:6367
void update(const slice &key, const slice &value)
Definition mdbx.h++:6363
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition mdbx.h++:4628
int compare_keys(map_handle map, const slice &a, const slice &b) const noexcept
Compare two keys according to a particular key-value map (aka table).
Definition mdbx.h++:5860
constexpr buffer(const struct slice &src, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:4998
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition mdbx.h++:4839
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++:5142
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition mdbx.h++:5661
txn_managed start_write(txn &parent)
Starts write (read-write) transaction.
Definition mdbx.h++:5624
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition mdbx.h++:6175
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4975
env::durability get_durability() const
Returns current durability mode.
Definition mdbx.h++:5421
uint64_t sequence(map_handle map) const
Reads sequence generator associated with a key-value map (aka table).
Definition mdbx.h++:5848
void upsert(const slice &key, const slice &value)
Definition mdbx.h++:6353
bool is_clean() const noexcept
Definition mdbx.h++:4639
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition mdbx.h++:2811
static bool boolean_or_throw(int error_code)
Definition mdbx.h++:4729
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++:5132
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition mdbx.h++:5411
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition mdbx.h++:2815
::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++:5463
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition mdbx.h++:5296
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition mdbx.h++:4919
constexpr error(MDBX_error_t error_code) noexcept
Definition mdbx.h++:4653
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++:5158
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition mdbx.h++:4582
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5029
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++:6079
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++:5560
void insert(const slice &key, slice value)
Definition mdbx.h++:6314
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6248
map_handle open_map(const char *name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single) const
Open existing key-value map.
Definition mdbx.h++:5744
buffer_pair< default_buffer > default_buffer_pair
Default pair of buffers.
Definition mdbx.h++:5223
::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++:2799
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++:5600
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++:5168
constexpr slice() noexcept
Create an empty slice.
Definition mdbx.h++:4761
cursor_managed clone(void *your_context=nullptr) const
Definition mdbx.h++:6138
~cursor() noexcept
Definition mdbx.h++:6159
~txn() noexcept
Definition mdbx.h++:5643
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition mdbx.h++:5493
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition mdbx.h++:5122
move_result upper_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6240
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++:4857
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition mdbx.h++:6294
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6339
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5288
map_handle map() const
Definition mdbx.h++:6299
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++:5504
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition mdbx.h++:4635
move_result find(const slice &key, bool throw_notfound=true)
Definition mdbx.h++:6232
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition mdbx.h++:5760
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition mdbx.h++:6252
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition mdbx.h++:2879
void success_or_throw() const
Definition mdbx.h++:4691
void renew_reading()
Renew read-only transaction.
Definition mdbx.h++:5696
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition mdbx.h++:4891
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition mdbx.h++:5544
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4979
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition mdbx.h++:6179
size_t count_multivalue() const
Return count of duplicates for current key.
Definition mdbx.h++:6258
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition mdbx.h++:4887
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition mdbx.h++:5294
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition mdbx.h++:4896
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition mdbx.h++:5666
slice upsert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6357
env::mode get_mode() const
Returns current operation mode.
Definition mdbx.h++:5419
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition mdbx.h++:2807
void capture() noexcept
Definition mdbx.h++:4641
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition mdbx.h++:5104
uint32_t get_tree_deepmask(map_handle map) const
Returns depth (bitmask) information of nested dupsort (multi-value) B+trees for given table.
Definition mdbx.h++:5825
bool try_update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5996
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4870
comparator default_comparator(key_mode mode) noexcept
Definition mdbx.h++:2950
slice insert_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6332
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++:5358
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++:5499
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition mdbx.h++:6112
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition mdbx.h++:5425
void drop_map(map_handle map)
Drops key-value map using handle.
Definition mdbx.h++:5785
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition mdbx.h++:6130
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++:6088
env::operate_options get_options() const
Returns current operate options.
Definition mdbx.h++:5429
void park_reading(bool autounpark=true)
Park read-only transaction.
Definition mdbx.h++:5711
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4983
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition mdbx.h++:6146
map_stat get_map_stat(map_handle map) const
Returns statistics for a table.
Definition mdbx.h++:5819
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition mdbx.h++:6198
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++:5334
int compare_values(map_handle map, const slice &a, const slice &b) const noexcept
Compare two values according to a particular key-value map (aka table).
Definition mdbx.h++:5864
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition mdbx.h++:5284
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition mdbx.h++:5837
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:5986
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition mdbx.h++:4914
constexpr bool is_result_false() const noexcept
Definition mdbx.h++:4668
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++:5510
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4941
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:4813
bool on_first() const
Definition mdbx.h++:6266
::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++:4849
bool eof() const
Definition mdbx.h++:6264
void make_broken()
Marks transaction as broken to prevent further operations.
Definition mdbx.h++:5694
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition mdbx.h++:5680
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition mdbx.h++:5481
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:6306
txn_managed prepare_read() const
Creates but not start read transaction.
Definition mdbx.h++:5609
::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++:5117
constexpr txn(MDBX_txn *ptr) noexcept
Definition mdbx.h++:5633
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition mdbx.h++:4881
bool seek(const slice &key)
Definition mdbx.h++:6256
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition mdbx.h++:5533
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition mdbx.h++:5483
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition mdbx.h++:4903
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++:5402
void clear_map(map_handle map)
Clear key-value map.
Definition mdbx.h++:5787
env & set_extra_option(extra_runtime_option option, uint64_t value)
Sets the value of a extra runtime options for an environment.
Definition mdbx.h++:5522
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition mdbx.h++:5239
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition mdbx.h++:4864
value_result try_insert(const slice &key, slice value)
Definition mdbx.h++:6319
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++:6420
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition mdbx.h++:4714
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4662
::MDBX_cmp_func * comparator
Definition mdbx.h++:2949
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition mdbx.h++:5678
put_mode
Key-value pairs put mode.
Definition mdbx.h++:2958
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:5179
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++:5163
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++:5514
::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++:5380
constexpr env(MDBX_env *ptr) noexcept
Definition mdbx.h++:5245
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition mdbx.h++:4971
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++:5842
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition mdbx.h++:6398
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition mdbx.h++:5433
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition mdbx.h++:5072
uint64_t id() const
Return the transaction's ID.
Definition mdbx.h++:5686
value_result try_insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5948
::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++:4676
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition mdbx.h++:5099
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition mdbx.h++:5081
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition mdbx.h++:6226
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition mdbx.h++:4956
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition mdbx.h++:5090
string< ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition mdbx.h++:5108
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition mdbx.h++:6008
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition mdbx.h++:5235
~env() noexcept
Definition mdbx.h++:5255
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition mdbx.h++:2780
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka table).
Definition mdbx.h++:5876
constexpr bool is_failure() const noexcept
Definition mdbx.h++:4670
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition mdbx.h++:4859
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++:6093
void update(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5992
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition mdbx.h++:4908
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition mdbx.h++:2783
txn_managed start_read() const
Starts read (read-only) transaction.
Definition mdbx.h++:5602
::mdbx::filesystem::path path
Definition mdbx.h++:444
bool on_last_multival() const
Definition mdbx.h++:6272
unsigned max_maps() const
Returns the maximum number of named tables for the environment.
Definition mdbx.h++:5475
void insert(map_handle map, const slice &key, slice value)
Definition mdbx.h++:5943
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition mdbx.h++:5469
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++:5314
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition mdbx.h++:5565
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition mdbx.h++:6144
static size_t max_map_handles(void)
Returns the maximum opened map handles, aka DBI-handles.
Definition mdbx.h++:5409
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition mdbx.h++:5723
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition mdbx.h++:2803
bool unpark_reading(bool restart_if_ousted=true)
Resume parked read-only transaction.
Definition mdbx.h++:5713
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition mdbx.h++:5527
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition mdbx.h++:4583
bool on_first_multival() const
Definition mdbx.h++:6270
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition mdbx.h++:5935
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition mdbx.h++:4704
inline ::std::ostream & operator<<(::std::ostream &out, const buffer< ALLOCATOR, CAPACITY_POLICY > &it)
Definition mdbx.h++:5011
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition mdbx.h++:4924
info get_info() const
Return snapshot information about the MDBX environment.
Definition mdbx.h++:5445
void upsert(map_handle map, const slice &key, const slice &value)
Definition mdbx.h++:5982
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition mdbx.h++:5292
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++:5137
slice update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6379
txn_managed clone(void *context=nullptr) const
Clone read transaction.
Definition mdbx.h++:5698
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition mdbx.h++:6236
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:4815
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:4837
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++:5220
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition mdbx.h++:5588
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition mdbx.h++:6027
constexpr bool is_result_true() const noexcept
Definition mdbx.h++:4666
bool on_last() const
Definition mdbx.h++:6268
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++:6058
#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++:5457
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition mdbx.h++:5538
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++:6288
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &alloc=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition mdbx.h++:5113
geometry & make_fixed(intptr_t size) noexcept
Definition mdbx.h++:5271
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition mdbx.h++:5729
constexpr bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4660
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &alloc)
Definition mdbx.h++:5051
constexpr bool is_success() const noexcept
Definition mdbx.h++:4664
value_result try_update_reserve(const slice &key, size_t value_length)
Definition mdbx.h++:6385
buffer< default_allocator, default_capacity_policy > default_buffer
Default buffer.
Definition mdbx.h++:5024
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition mdbx.h++:5631
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition mdbx.h++:5231
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition mdbx.h++:5717
map_handle create_map(const char *name, const ::mdbx::key_mode key_mode=::mdbx::key_mode::usual, const ::mdbx::value_mode value_mode=::mdbx::value_mode::single)
Create new or open existing key-value map.
Definition mdbx.h++:5776
pair_result get_equal_or_great(map_handle map, const slice &key) const
Get value for equal or great key from a table.
Definition mdbx.h++:5914
map_handle::info get_map_flags(map_handle map) const
Returns information about key-value map (aka table) handle.
Definition mdbx.h++:5831
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:4823
@ multi_reverse_samelength
Definition mdbx.h++:2851
@ multi_samelength
Definition mdbx.h++:2836
@ multi_ordinal
Definition mdbx.h++:2843
@ msgpack
Definition mdbx.h++:2866
@ single
Definition mdbx.h++:2819
@ multi
Definition mdbx.h++:2821
@ multi_reverse
Definition mdbx.h++:2828
@ upsert
Insert or update.
Definition mdbx.h++:2960
@ update
Update existing, don't insert new.
Definition mdbx.h++:2961
@ insert_unique
Insert only unique keys.
Definition mdbx.h++:2959
@ continue_loop
Definition mdbx.h++:2780
@ exit_loop
Definition mdbx.h++:2780
@ usual
Definition mdbx.h++:2784
@ ordinal
Definition mdbx.h++:2789
@ reverse
Definition mdbx.h++:2786
@ msgpack
Definition mdbx.h++:2794
A handle for an individual table (aka key-value space, maps or sub-database) in the environment.
Definition mdbx.h++:2903
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition mdbx.h++:2414
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2127
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++:2005
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition mdbx.h++:2032
constexpr ::std::span< byte > bytes()
Definition mdbx.h++:702
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition mdbx.h++:2097
constexpr allocator_type get_allocator() const
Definition mdbx.h++:1987
static constexpr slice wrap(const char(&text)[SIZE])
Definition mdbx.h++:715
constexpr slice(const ::std::span< POD > &span)
Definition mdbx.h++:678
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++:2269
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition mdbx.h++:2310
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition mdbx.h++:669
buffer_pair_spec(const txn &transacton, const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2700
const slice source
Definition mdbx.h++:1260
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++:2635
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++:2218
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:737
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition mdbx.h++:2048
int8_t as_int8_adapt() const
constexpr buffer make_inplace_or_reference() const
Definition mdbx.h++:2341
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition mdbx.h++:2045
buffer & assign(const char *c_str, bool make_reference=false)
Definition mdbx.h++:2423
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition mdbx.h++:2293
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++:2020
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2154
buffer & assign(const struct slice &src, bool make_reference=false)
Definition mdbx.h++:2394
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition mdbx.h++:2307
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition mdbx.h++:2039
buffer(size_t head_room, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2159
buffer< ALLOCATOR, CAPACITY_POLICY > buffer_type
Definition mdbx.h++:2667
::std::allocator_traits< allocator_type > allocator_traits
Definition mdbx.h++:1563
constexpr uint16_t as_uint16() const
Definition mdbx.h++:1033
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition mdbx.h++:1237
constexpr buffer & assign(size_t headroom, const buffer &src, size_t tailroom)
Definition mdbx.h++:2345
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition mdbx.h++:2072
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2524
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition mdbx.h++:2068
buffer & append(const byte c)
Definition mdbx.h++:2478
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition mdbx.h++:2318
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition mdbx.h++:755
static constexpr slice null() noexcept
Build a null slice which zero length and refers to null address.
Definition mdbx.h++:1014
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition mdbx.h++:2323
buffer & operator=(const buffer &src)
Definition mdbx.h++:2440
constexpr uint32_t as_uint32() const
Definition mdbx.h++:1032
buffer & append_u16(uint_fast16_t u16)
Definition mdbx.h++:2546
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition mdbx.h++:2014
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2709
constexpr int64_t as_int64() const
Definition mdbx.h++:1039
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition mdbx.h++:2065
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition mdbx.h++:2625
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++:2200
const bool ignore_spaces
Definition mdbx.h++:1340
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:859
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++:2282
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++:2276
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2195
value_result & operator=(const value_result &) noexcept=default
buffer & add_header(const void *src, size_t bytes)
Definition mdbx.h++:2488
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2238
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++:1102
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &alloc=ALLOCATOR()) const
Definition mdbx.h++:772
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2678
constexpr int16_t as_int16() const
Definition mdbx.h++:1041
slice value
Definition mdbx.h++:1066
::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++:2680
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition mdbx.h++:2419
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++:2262
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition mdbx.h++:2645
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1208
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++:2288
static constexpr buffer invalid() noexcept
Build an invalid buffer which non-zero length and refers to null address.
Definition mdbx.h++:2192
slice value
Definition mdbx.h++:1080
::std::pair< buffer_type, buffer_type > stl_pair
Definition mdbx.h++:2671
::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++:1982
static buffer key_from(const float ieee754_32bit)
Definition mdbx.h++:2651
const slice source
Definition mdbx.h++:1339
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2689
const slice source
Definition mdbx.h++:1175
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++:2226
constexpr buffer & assign(buffer &&src) noexcept(allocation_aware_details::move_assign_alloc< silo, allocator_type >::is_nothrow())
Definition mdbx.h++:2382
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++:1322
const unsigned wrap_width
Definition mdbx.h++:1177
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition mdbx.h++:2449
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition mdbx.h++:2631
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition mdbx.h++:729
const slice & slice() const noexcept
Definition mdbx.h++:2663
buffer & assign(struct slice &&src, bool make_reference=false)
Definition mdbx.h++:2402
const bool ignore_spaces
Definition mdbx.h++:1306
constexpr POD as_pod() const
Definition mdbx.h++:1016
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++:1129
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++:1406
buffer_pair_spec(const stl_pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2684
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition mdbx.h++:2390
constexpr buffer(const buffer &src)
Definition mdbx.h++:2137
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++:2255
constexpr uint128_t as_uint128() const
Definition mdbx.h++:1029
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition mdbx.h++:2463
uint16_t as_uint16_adapt() const
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition mdbx.h++:2085
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition mdbx.h++:2637
constexpr friend void swap(buffer &left, buffer &right) noexcept(buffer::is_swap_nothrow())
Definition mdbx.h++:2333
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1178
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2686
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2520
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition mdbx.h++:2617
static constexpr size_t advise(const size_t current, const size_t wanna, const size_t inplace)
Definition mdbx.h++:1528
buffer(size_t head_room, const slice &src, size_t tail_room, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2170
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:751
std::pair< slice, slice > stl_pair
Definition mdbx.h++:1079
buffer & append_byte(uint_fast8_t byte)
Definition mdbx.h++:2544
constexpr bool is_inplace() const noexcept
Checks whether data chunk stored in place within the buffer instance itself, without reference outsid...
Definition mdbx.h++:1999
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
@ pettiness_threshold
Definition mdbx.h++:1516
@ extra_inplace_storage
Definition mdbx.h++:1514
@ max_reserve
Definition mdbx.h++:1517
@ inplace_storage_size_rounding
Definition mdbx.h++:1515
static buffer key_from_float(const float ieee754_32bit)
Definition mdbx.h++:2649
constexpr ::std::span< POD > as_span()
Definition mdbx.h++:692
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1341
buffer & operator=(const struct slice &src)
Definition mdbx.h++:2444
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition mdbx.h++:2516
constexpr int8_t as_int8() const
Definition mdbx.h++:1042
constexpr ::std::span< char > chars()
Definition mdbx.h++:704
constexpr slice(size_t invalid_length) noexcept
Definition mdbx.h++:1061
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition mdbx.h++:1279
buffer(const char *c_str, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2122
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++:1520
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1251
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++:1397
value_result(const slice &value, bool done) noexcept
Definition mdbx.h++:1068
static buffer key_from(buffer &&src) noexcept
Definition mdbx.h++:2629
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1368
buffer encode_base64(unsigned wrap_width=0, const allocator_type &alloc=allocator_type()) const
Definition mdbx.h++:2250
buffer(size_t capacity, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2165
const slice source
Definition mdbx.h++:1218
constexpr pair(const stl_pair &couple) noexcept
Definition mdbx.h++:1082
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition mdbx.h++:2408
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++:1991
static buffer key_from(const float *ieee754_32bit)
Definition mdbx.h++:2653
constexpr ::std::span< const char > chars() const
Definition mdbx.h++:703
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1380
buffer_pair_spec & operator=(buffer_pair_spec &&src)
Definition mdbx.h++:2713
buffer & append_u48(uint_fast64_t u48)
Definition mdbx.h++:2579
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++:1212
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:1564
uint8_t as_uint8_adapt() const
constexpr ::std::span< const POD > as_span() const
Definition mdbx.h++:683
static buffer key_from(const int64_t signed_int64)
Definition mdbx.h++:2643
constexpr buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2116
buffer & operator=(struct slice &&src)
Definition mdbx.h++:2446
buffer_pair_spec & operator=(const stl_pair &src)
Definition mdbx.h++:2729
buffer & add_header(const struct slice &chunk)
Definition mdbx.h++:2496
buffer & append_u32(uint_fast32_t u32)
Definition mdbx.h++:2567
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2528
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++:1358
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition mdbx.h++:734
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++:759
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1329
int32_t as_int32_adapt() const
@ max_length
Definition mdbx.h++:648
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++:2233
static buffer key_from_i32(const int32_t signed_int32)
Definition mdbx.h++:2659
slice inherited
Definition mdbx.h++:1557
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition mdbx.h++:1130
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition mdbx.h++:1307
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition mdbx.h++:2655
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++:2657
buffer & assign_reference(const void *ptr, size_t bytes)
Definition mdbx.h++:2312
static constexpr pair invalid() noexcept
Definition mdbx.h++:1095
void make_freestanding()
Makes buffer owning the data.
Definition mdbx.h++:2105
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition mdbx.h++:2398
bool done
Definition mdbx.h++:1128
::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++:1254
constexpr ::std::span< const byte > bytes() const
Definition mdbx.h++:701
pair & operator=(pair &&couple)
Definition mdbx.h++:1086
static constexpr slice wrap(const POD &pod)
Definition mdbx.h++:717
allocation_aware_details::move_assign_alloc< silo, allocator_type > move_assign_alloc
Definition mdbx.h++:1980
const bool uppercase
Definition mdbx.h++:1176
allocation_aware_details::copy_assign_alloc< silo, allocator_type > copy_assign_alloc
Definition mdbx.h++:1981
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition mdbx.h++:2052
constexpr buffer & assign(const buffer &src, bool make_reference=false)
Definition mdbx.h++:2361
buffer & append(const struct slice &chunk)
Definition mdbx.h++:2486
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition mdbx.h++:2532
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2697
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition mdbx.h++:2059
const bool ignore_spaces
Definition mdbx.h++:1379
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition mdbx.h++:1263
pair(const pair &) noexcept=default
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition mdbx.h++:2611
static constexpr slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition mdbx.h++:1009
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++:1037
slice key
Definition mdbx.h++:1080
buffer & append(const void *src, size_t bytes)
Definition mdbx.h++:2470
constexpr pair(const slice &key, const slice &value) noexcept
Definition mdbx.h++:1081
buffer_pair_spec(const txn &transaction, const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2703
const slice source
Definition mdbx.h++:1378
pair_result & operator=(const pair_result &) noexcept=default
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition mdbx.h++:2468
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition mdbx.h++:1296
static buffer key_from(const int32_t signed_int32)
Definition mdbx.h++:2661
void clear() noexcept
Clears the contents and storage.
Definition mdbx.h++:2460
typename buffer_type::allocator_traits allocator_traits
Definition mdbx.h++:2669
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++:1040
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++:2212
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2141
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition mdbx.h++:1559
static buffer key_from(const double ieee754_64bit)
Definition mdbx.h++:2633
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition mdbx.h++:2025
pair & operator=(const stl_pair &couple)
Definition mdbx.h++:1097
int64_t as_int64_adapt() const
static buffer key_from_i64(const int64_t signed_int64)
Definition mdbx.h++:2641
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition mdbx.h++:2028
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++:2207
static buffer clone(const buffer &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2337
buffer_pair_spec(const pair &pair, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2695
constexpr uint8_t as_uint8() const
Definition mdbx.h++:1034
CAPACITY_POLICY reservation_policy
Definition mdbx.h++:2670
constexpr buffer(const char *c_str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2150
static constexpr bool is_swap_nothrow() noexcept
Definition mdbx.h++:1984
buffer & append_u8(uint_fast8_t u8)
Definition mdbx.h++:2536
buffer & append_u24(uint_fast32_t u24)
Definition mdbx.h++:2556
constexpr uint64_t as_uint64() const
Definition mdbx.h++:1031
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2177
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++:2691
static buffer key_from(const uint64_t unsigned_int64)
Definition mdbx.h++:2639
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++:2245
buffer & append_u64(uint_fast64_t u64)
Definition mdbx.h++:2593
const unsigned wrap_width
Definition mdbx.h++:1219
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++:2512
static constexpr buffer null() noexcept
Build a null buffer which zero length and refers to null address.
Definition mdbx.h++:2189
const unsigned wrap_width
Definition mdbx.h++:1261
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition mdbx.h++:2442
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++:1006
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition mdbx.h++:2079
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++:2498
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition mdbx.h++:2706
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++:710
buffer & append_producer(const PRODUCER &producer)
Definition mdbx.h++:2505
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2145
int16_t as_int16_adapt() const
static buffer key_from(const char *src, bool make_reference=false)
Definition mdbx.h++:2622
typename buffer_type::allocator_type allocator_type
Definition mdbx.h++:2668
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++:1300
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++:1221
constexpr buffer(const struct slice &src, const allocator_type &alloc=allocator_type())
Definition mdbx.h++:2133
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition mdbx.h++:712
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++:1193
bool done
Definition mdbx.h++:1067
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++:1305
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition mdbx.h++:2008
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition mdbx.h++:2090
The chunk of data stored inside the buffer or located outside it.
Definition mdbx.h++:1555
Definition mdbx.h++:2666
Type tag for delivered buffer template classes.
Definition mdbx.h++:1551
Definition mdbx.h++:1512
Base58 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1338
Base64 decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1377
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1304
Combines pair of slices for key and value to represent result of certain operations.
Definition mdbx.h++:1078
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition mdbx.h++:1127
References a data located outside the slice.
Definition mdbx.h++:643
Base58 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1217
Base64 encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1259
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition mdbx.h++:1174
Combines data slice with boolean flag to represent result of certain operations.
Definition mdbx.h++:1065
incompatible_operation(const ::mdbx::error &)
fatal(exception &&src) noexcept
Definition mdbx.h++:560
remote_media(const ::mdbx::error &)
dangling_map_id(const ::mdbx::error &)
constexpr friend bool operator!=(const error &a, const error &b) noexcept
Definition mdbx.h++:4662
fatal(const ::mdbx::error &) noexcept
reader_slot_busy(const ::mdbx::error &)
exception(const exception &)=default
::std::string message() const
Returns message for any errors.
not_found(const ::mdbx::error &)
operation_not_permitted(const ::mdbx::error &)
key_exists(const ::mdbx::error &)
permission_denied_or_not_writeable(const ::mdbx::error &)
void throw_exception() const
fatal(const exception &src) noexcept
Definition mdbx.h++:559
no_data(const ::mdbx::error &)
transaction_full(const ::mdbx::error &)
exception(exception &&)=default
db_too_large(const ::mdbx::error &)
bad_map_id(const ::mdbx::error &)
transaction_overlapping(const ::mdbx::error &)
void panic(const char *context_where_when, const char *func_who_what) const noexcept
Panics on unrecoverable errors inside destructors etc.
static void success_or_throw(int error_code)
Definition mdbx.h++:528
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++:550
error(const error &)=default
virtual ~fatal() noexcept
something_busy(const ::mdbx::error &)
fatal & operator=(fatal &&)=default
const char * what() const noexcept
Returns message for MDBX's errors only and "SYSTEM" for others.
fatal(const fatal &src) noexcept
Definition mdbx.h++:561
transaction_ousted(const ::mdbx::error &)
key_mismatch(const ::mdbx::error &)
db_invalid(const ::mdbx::error &)
exception & operator=(exception &&)=default
db_wanna_write_for_recovery(const ::mdbx::error &)
error & operator=(error &&)=default
bad_transaction(const ::mdbx::error &)
internal_problem(const ::mdbx::error &)
multivalue(const ::mdbx::error &)
fatal(fatal &&src) noexcept
Definition mdbx.h++:562
fatal & operator=(const fatal &)=default
max_readers_reached(const ::mdbx::error &)
db_version_mismatch(const ::mdbx::error &)
exception_thunk() noexcept=default
exception & operator=(const exception &)=default
exception(const ::mdbx::error &) noexcept
db_unable_extend(const ::mdbx::error &)
constexpr friend bool operator==(const error &a, const error &b) noexcept
Definition mdbx.h++:4660
error & operator=(const error &)=default
virtual ~exception() noexcept
error(error &&)=default
thread_mismatch(const ::mdbx::error &)
db_corrupted(const ::mdbx::error &)
internal_page_full(const ::mdbx::error &)
mvcc_retarded(const ::mdbx::error &)
max_maps_reached(const ::mdbx::error &)
bad_value_size(const ::mdbx::error &)
Implements error information and throwing corresponding exceptions.
Definition mdbx.h++:487
Transfers C++ exceptions thru C callbacks.
Definition mdbx.h++:472
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition mdbx.h++:568
LIBMDBX_API void throw_incomparable_cursors()
LIBMDBX_API void throw_out_range()
LIBMDBX_API void throw_bad_value_size()
LIBMDBX_API void throw_max_length_exceeded()
LIBMDBX_API void throw_too_small_target_buffer()
uint64_t mdbx_key_from_int64(const int64_t i64)
Definition mdbx.h:4924
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:4928
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++:1414
constexpr bool allocator_is_always_equal() noexcept
Definition mdbx.h++:1416
The libmdbx C++ API namespace.
Definition mdbx.h++:323
STL namespace.
string to_string(const ::mdbx::slice &value)
Definition mdbx.h++:6468
byte buffer_[inplace_size - sizeof(byte)]
Definition mdbx.h++:1650
constexpr inplace_flag_holder(byte signature)
Definition mdbx.h++:1652
byte lastbyte_
Definition mdbx.h++:1651
Definition mdbx.h++:4248
estimate_result(const cursor &cursor, move_operation operation)
Definition mdbx.h++:4250
estimate_result & operator=(const estimate_result &) noexcept=default
ptrdiff_t approximate_quantity
Definition mdbx.h++:4249
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition mdbx.h++:4252
Definition mdbx.h++:4236
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++:4240
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition mdbx.h++:4238
Tagged type for output to std::ostream.
Definition mdbx.h++:3023
intptr_t bytes
Definition mdbx.h++:3024
constexpr size(intptr_t bytes) noexcept
Definition mdbx.h++:3025
Database geometry for size management.
Definition mdbx.h++:2999
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition mdbx.h++:3047
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition mdbx.h++:3059
@ GB
bytes (0x3B9A_CA00)
Definition mdbx.h++:3006
@ minimal_value
Means "minimal acceptable".
Definition mdbx.h++:3002
@ MB
bytes (0x000F_4240)
Definition mdbx.h++:3005
@ GiB
bytes (0x4000_0000)
Definition mdbx.h++:3014
@ maximal_value
Means "maximal acceptable".
Definition mdbx.h++:3003
@ default_value
Means "keep current or use default".
Definition mdbx.h++:3001
@ kB
bytes (0x03E8)
Definition mdbx.h++:3004
@ MiB
bytes (0x0010_0000)
Definition mdbx.h++:3013
@ KiB
bytes (0x0400)
Definition mdbx.h++:3012
constexpr geometry() noexcept
Definition mdbx.h++:3063
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition mdbx.h++:3050
intptr_t size_now
The size in bytes to setup the database size for now.
Definition mdbx.h++:3035
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition mdbx.h++:3053
intptr_t size_lower
The lower bound of database size in bytes.
Definition mdbx.h++:3030
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++:3066
Operate options.
Definition mdbx.h++:3103
bool disable_readahead
Definition mdbx.h++:3112
bool enable_validation
Definition mdbx.h++:3116
bool no_sticky_threads
Definition mdbx.h++:3105
constexpr operate_options() noexcept
Definition mdbx.h++:3117
bool disable_clear_memory
Definition mdbx.h++:3114
constexpr operate_options & operator=(const operate_options &) noexcept=default
bool exclusive
Definition mdbx.h++:3110
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
bool nested_transactions
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
Definition mdbx.h++:3108
Operate parameters.
Definition mdbx.h++:3125
env::durability durability
Definition mdbx.h++:3133
env::operate_options options
Definition mdbx.h++:3135
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++:3139
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++:3131
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition mdbx.h++:3134
env::mode mode
Definition mdbx.h++:3132
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++:3128
constexpr operate_parameters() noexcept
Definition mdbx.h++:3137
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition mdbx.h++:3517
mdbx_tid_t thread
The reader thread ID.
Definition mdbx.h++:3520
uint64_t transaction_lag
Definition mdbx.h++:3523
size_t bytes_used
Definition mdbx.h++:3527
uint64_t transaction_id
Definition mdbx.h++:3521
int slot
The reader lock table slot number.
Definition mdbx.h++:3518
mdbx_pid_t pid
The reader process ID.
Definition mdbx.h++:3519
size_t bytes_retained
Definition mdbx.h++:3530
Garbage reclaiming options.
Definition mdbx.h++:3090
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
bool coalesce
Definition mdbx.h++:3094
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
constexpr reclaiming_options() noexcept
Definition mdbx.h++:3095
bool lifo
Definition mdbx.h++:3092
Additional parameters for creating a new database.
Definition mdbx.h++:3626
mdbx_mode_t file_mode_bits
Definition mdbx.h++:3628
constexpr create_parameters() noexcept=default
bool use_subdirectory
Definition mdbx.h++:3629
env::geometry geometry
Definition mdbx.h++:3627
Definition mdbx.h++:2938
map_handle::state state
Definition mdbx.h++:2940
info(const info &) noexcept=default
map_handle::flags flags
Definition mdbx.h++:2939
info & operator=(const info &) noexcept=default
size_t operator()(::mdbx::buffer< ALLOCATOR, CAPACITY_POLICY > const &buffer) const noexcept
Definition mdbx.h++:6573
size_t operator()(const ::mdbx::cursor &cursor) const noexcept
Definition mdbx.h++:6569
std::hash< const MDBX_cursor * > inherited
Definition mdbx.h++:6568
size_t operator()(const ::mdbx::env &env) const noexcept
Definition mdbx.h++:6559
std::hash< const MDBX_env * > inherited
Definition mdbx.h++:6558
constexpr size_t operator()(const ::mdbx::map_handle &handle) const noexcept
Definition mdbx.h++:6554
constexpr size_t operator()(const ::mdbx::slice &slice) const noexcept
Definition mdbx.h++:6550
std::hash< const MDBX_txn * > inherited
Definition mdbx.h++:6563
size_t operator()(const ::mdbx::txn &txn) const noexcept
Definition mdbx.h++:6564
capacity_holder capacity_
Definition mdbx.h++:1656
constexpr byte * make_allocated(const ::std::pair< allocator_pointer, size_t > &pair) noexcept
Definition mdbx.h++:1689
allocator_pointer stub_ptr_
Definition mdbx.h++:1631
constexpr bool is_inplace() const noexcept
Definition mdbx.h++:1668
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition mdbx.h++:1709
static constexpr bool is_suitable_for_inplace(size_t capacity_bytes) noexcept
Definition mdbx.h++:1660
constexpr bool is_allocated() const noexcept
Definition mdbx.h++:1675
inplace_flag_holder inplace_
Definition mdbx.h++:1657
static constexpr size_t inplace_capacity() noexcept
Definition mdbx.h++:1659
allocator_pointer allocated_ptr_
Definition mdbx.h++:1655
size_t stub_capacity_bytes_
Definition mdbx.h++:1632
constexpr size_t capacity() const noexcept
Definition mdbx.h++:1728
byte pad_[inplace_size - sizeof(allocator_pointer)]
Definition mdbx.h++:1645
size_t bytes_
Definition mdbx.h++:1646
constexpr const byte * address() const noexcept
Definition mdbx.h++:1722
constexpr bin() noexcept
Definition mdbx.h++:1703
@ inplace_size
Definition mdbx.h++:1640
@ inplace_signature_limit
Definition mdbx.h++:1637
@ inplace_size_rounding
Definition mdbx.h++:1639
constexpr byte * address() noexcept
Definition mdbx.h++:1725
@ lastbyte_poison
Definition mdbx.h++:1635
@ lastbyte_inplace_signature
Definition mdbx.h++:1635
constexpr bool is_inplace(const void *ptr) const noexcept
Definition mdbx.h++:1718
constexpr byte * make_inplace() noexcept
Definition mdbx.h++:1677