libmdbx  0.13.0.37 (2024-04-04T17:32:49+03:00)
One of the fastest compact embeddable key-value ACID database without WAL.
mdbx.h++
Go to the documentation of this file.
1 
23 
24 #pragma once
25 
26 /* Workaround for modern libstdc++ with CLANG < 4.x */
27 #if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && \
28  defined(__clang__) && __clang_major__ < 4
29 #define __GLIBCXX_BITSIZE_INT_N_0 128
30 #define __GLIBCXX_TYPE_INT_N_0 __int128
31 #endif /* Workaround for modern libstdc++ with CLANG < 4.x */
32 
33 #if !defined(__cplusplus) || __cplusplus < 201103L
34 #if !defined(_MSC_VER) || _MSC_VER < 1900
35 #error "C++11 compiler or better is required"
36 #elif _MSC_VER >= 1910
37 #error \
38  "Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
39 #endif /* MSVC is mad and don't define __cplusplus properly */
40 #endif /* __cplusplus < 201103L */
41 
42 #if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
43 #error \
44  "CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
45 #endif /* Windows */
46 
47 #ifndef __has_include
48 #define __has_include(header) (0)
49 #endif /* __has_include */
50 
51 #if __has_include(<version>)
52 #include <version>
53 #endif /* <version> */
54 
55 /* Disable min/max macros from C' headers */
56 #ifndef NOMINMAX
57 #define NOMINMAX
58 #endif
59 
60 #include <algorithm> // for std::min/max
61 #include <cassert> // for assert()
62 #include <climits> // for CHAR_BIT
63 #include <cstring> // for std::strlen, str:memcmp
64 #include <exception> // for std::exception_ptr
65 #include <ostream> // for std::ostream
66 #include <sstream> // for std::ostringstream
67 #include <stdexcept> // for std::invalid_argument
68 #include <string> // for std::string
69 #include <type_traits> // for std::is_pod<>, etc.
70 #include <utility> // for std::make_pair
71 #include <vector> // for std::vector<> as template args
72 
73 #if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
74 #include <memory_resource>
75 #endif
76 
77 #if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
78 #include <string_view>
79 #endif
80 
81 #if defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
82 #include <filesystem>
83 #elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && \
84  __has_include(<experimental/filesystem>)
85 #include <experimental/filesystem>
86 #endif
87 
88 #if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
89 #include <span>
90 #endif
91 
92 #if __cplusplus >= 201103L
93 #include <chrono>
94 #include <ratio>
95 #endif
96 
97 #include "mdbx.h"
98 
99 #if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
100  (defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
101  (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
102  (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
103 #include <bit>
104 #elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
105  defined(__ORDER_BIG_ENDIAN__))
106 #if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
107 #define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
108 #define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
109 #define __BYTE_ORDER__ __BYTE_ORDER
110 #elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
111 #define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
112 #define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
113 #define __BYTE_ORDER__ _BYTE_ORDER
114 #else
115 #define __ORDER_LITTLE_ENDIAN__ 1234
116 #define __ORDER_BIG_ENDIAN__ 4321
117 #if defined(__LITTLE_ENDIAN__) || \
118  (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || \
119  defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
120  defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
121  defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || \
122  defined(__elbrus_4c__) || defined(__elbrus_8c__) || defined(__bfin__) || \
123  defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || \
124  defined(__IA64__) || defined(__ia64) || defined(_M_IA64) || \
125  defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
126  defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || \
127  defined(__WINDOWS__)
128 #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
129 #elif defined(__BIG_ENDIAN__) || \
130  (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || \
131  defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
132  defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
133  defined(__m68k__) || defined(M68000) || defined(__hppa__) || \
134  defined(__hppa) || defined(__HPPA__) || defined(__sparc__) || \
135  defined(__sparc) || defined(__370__) || defined(__THW_370__) || \
136  defined(__s390__) || defined(__s390x__) || defined(__SYSC_ZARCH__)
137 #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
138 #endif
139 #endif
140 #endif /* Byte Order */
141 
144 #if defined(DOXYGEN)
145 #define MDBX_CXX17_CONSTEXPR constexpr
146 #elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
147  ((defined(_MSC_VER) && _MSC_VER >= 1915) || \
148  (defined(__clang__) && __clang_major__ > 5) || \
149  (defined(__GNUC__) && __GNUC__ > 7) || \
150  (!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
151 #define MDBX_CXX17_CONSTEXPR constexpr
152 #else
153 #define MDBX_CXX17_CONSTEXPR inline
154 #endif /* MDBX_CXX17_CONSTEXPR */
155 
158 #if defined(DOXYGEN)
159 #define MDBX_CXX20_CONSTEXPR constexpr
160 #elif defined(__cpp_lib_is_constant_evaluated) && \
161  __cpp_lib_is_constant_evaluated >= 201811L && \
162  defined(__cpp_lib_constexpr_string) && \
163  __cpp_lib_constexpr_string >= 201907L
164 #define MDBX_CXX20_CONSTEXPR constexpr
165 #else
166 #define MDBX_CXX20_CONSTEXPR inline
167 #endif /* MDBX_CXX20_CONSTEXPR */
168 
169 #if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
170 #define MDBX_CXX01_CONSTEXPR_ENUM MDBX_CXX01_CONSTEXPR
171 #define MDBX_CXX11_CONSTEXPR_ENUM MDBX_CXX11_CONSTEXPR
172 #define MDBX_CXX14_CONSTEXPR_ENUM MDBX_CXX14_CONSTEXPR
173 #define MDBX_CXX17_CONSTEXPR_ENUM MDBX_CXX17_CONSTEXPR
174 #define MDBX_CXX20_CONSTEXPR_ENUM MDBX_CXX20_CONSTEXPR
175 #else
176 #define MDBX_CXX01_CONSTEXPR_ENUM inline
177 #define MDBX_CXX11_CONSTEXPR_ENUM inline
178 #define MDBX_CXX14_CONSTEXPR_ENUM inline
179 #define MDBX_CXX17_CONSTEXPR_ENUM inline
180 #define MDBX_CXX20_CONSTEXPR_ENUM inline
181 #endif /* CONSTEXPR_ENUM_FLAGS_OPERATIONS */
182 
185 #if defined(CONSTEXPR_ASSERT)
186 #define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
187 #elif defined NDEBUG
188 #define MDBX_CONSTEXPR_ASSERT(expr) void(0)
189 #else
190 #define MDBX_CONSTEXPR_ASSERT(expr) \
191  ((expr) ? void(0) : [] { assert(!#expr); }())
192 #endif /* MDBX_CONSTEXPR_ASSERT */
193 
194 #ifndef MDBX_LIKELY
195 #if defined(DOXYGEN) || \
196  (defined(__GNUC__) || __has_builtin(__builtin_expect)) && \
197  !defined(__COVERITY__)
198 #define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
199 #else
200 #define MDBX_LIKELY(x) (x)
201 #endif
202 #endif /* MDBX_LIKELY */
203 
204 #ifndef MDBX_UNLIKELY
205 #if defined(DOXYGEN) || \
206  (defined(__GNUC__) || __has_builtin(__builtin_expect)) && \
207  !defined(__COVERITY__)
208 #define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
209 #else
210 #define MDBX_UNLIKELY(x) (x)
211 #endif
212 #endif /* MDBX_UNLIKELY */
213 
216 #if defined(DOXYGEN)
217 #define MDBX_IF_CONSTEXPR constexpr
218 #elif defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
219 #define MDBX_IF_CONSTEXPR constexpr
220 #else
221 #define MDBX_IF_CONSTEXPR
222 #endif /* MDBX_IF_CONSTEXPR */
223 
224 #if defined(DOXYGEN) || \
225  (__has_cpp_attribute(fallthrough) && \
226  (!defined(__clang__) || __clang__ > 4)) || \
227  __cplusplus >= 201703L
228 #define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
229 #else
230 #define MDBX_CXX17_FALLTHROUGH
231 #endif /* MDBX_CXX17_FALLTHROUGH */
232 
233 #if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && \
234  (!defined(__GNUC__) || __GNUC__ > 9))
235 #define MDBX_CXX20_LIKELY [[likely]]
236 #else
237 #define MDBX_CXX20_LIKELY
238 #endif /* MDBX_CXX20_LIKELY */
239 
240 #ifndef MDBX_CXX20_UNLIKELY
241 #if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && \
242  (!defined(__GNUC__) || __GNUC__ > 9))
243 #define MDBX_CXX20_UNLIKELY [[unlikely]]
244 #else
245 #define MDBX_CXX20_UNLIKELY
246 #endif
247 #endif /* MDBX_CXX20_UNLIKELY */
248 
249 #ifndef MDBX_HAVE_CXX20_CONCEPTS
250 #if defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
251 #include <concepts>
252 #define MDBX_HAVE_CXX20_CONCEPTS 1
253 #elif defined(DOXYGEN)
254 #define MDBX_HAVE_CXX20_CONCEPTS 1
255 #else
256 #define MDBX_HAVE_CXX20_CONCEPTS 0
257 #endif /* <concepts> */
258 #endif /* MDBX_HAVE_CXX20_CONCEPTS */
259 
260 #ifndef MDBX_CXX20_CONCEPT
261 #if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
262 #define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
263 #else
264 #define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
265 #endif
266 #endif /* MDBX_CXX20_CONCEPT */
267 
268 #ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
269 #if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
270 #define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) \
271  static_assert(CONCEPT<TYPE>)
272 #else
273 #define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
274  static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
275 #endif
276 #endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
277 
278 #ifdef _MSC_VER
279 #pragma warning(push, 4)
280 #pragma warning(disable : 4127) /* conditional expression is constant */
281 #pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
282  be used by clients of 'mdbx::BAR' */
283 #pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
284  base for dll-interface 'mdbx::BAR' */
285 /* MSVC is mad and can generate this warning for its own intermediate
286  * automatically generated code, which becomes unreachable after some kinds of
287  * optimization (copy elision, etc). */
288 #pragma warning(disable : 4702) /* unreachable code */
289 #endif /* _MSC_VER (warnings) */
290 
291 #if defined(__LCC__) && __LCC__ >= 126
292 #pragma diagnostic push
293 #if __LCC__ < 127
294 #pragma diag_suppress 3058 /* workaround: call to is_constant_evaluated() \
295  appearing in a constant expression `true` */
296 #pragma diag_suppress 3060 /* workaround: call to is_constant_evaluated() \
297  appearing in a constant expression `false` */
298 #endif
299 #endif /* E2K LCC (warnings) */
300 
301 //------------------------------------------------------------------------------
304 namespace mdbx {
305 
308 
309 // Functions whose signature depends on the `mdbx::byte` type
310 // must be strictly defined as inline!
311 #if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
312 // To enable all kinds of an compiler optimizations we use a byte-like type
313 // that don't presumes aliases for pointers as does the `char` type and its
314 // derivatives/typedefs.
315 // Please see https://libmdbx.dqdkfa.ru/dead-github/issues/263
316 // for reasoning of the use of `char8_t` type and switching to `__restrict__`.
317 using byte = char8_t;
318 #else
319 // Avoid `std::byte` since it doesn't add features but inconvenient
320 // restrictions.
321 using byte = unsigned char;
322 #endif /* __cpp_char8_t >= 201811*/
323 
324 #if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
325 using endian = ::std::endian;
326 #elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
327  defined(__ORDER_BIG_ENDIAN__)
328 enum class endian {
329  little = __ORDER_LITTLE_ENDIAN__,
330  big = __ORDER_BIG_ENDIAN__,
331  native = __BYTE_ORDER__
332 };
333 #else
334 #error \
335  "Please use a C++ compiler provides byte order information or C++20 support"
336 #endif /* Byte Order enum */
337 
345 MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept;
346 
348 static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
349 
351 static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src,
352  size_t bytes) noexcept;
354 static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b,
355  size_t bytes) noexcept;
356 
359 using legacy_allocator = ::std::string::allocator_type;
360 
361 #if defined(DOXYGEN) || \
362  (defined(__cpp_lib_memory_resource) && \
363  __cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI)
365 using polymorphic_allocator = ::std::pmr::string::allocator_type;
367 #else
369 #endif /* __cpp_lib_memory_resource >= 201603L */
370 
371 struct slice;
373 template <class ALLOCATOR = default_allocator,
374  class CAPACITY_POLICY = default_capacity_policy>
375 class buffer;
376 class env;
377 class env_managed;
378 class txn;
379 class txn_managed;
380 class cursor;
381 class cursor_managed;
382 
385 
387 template <class ALLOCATOR = default_allocator>
388 using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
389 
391 #if defined(DOXYGEN) || \
392  (defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && \
393  defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L && \
394  (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || \
395  __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
396  (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || \
397  __IPHONE_OS_VERSION_MIN_REQUIRED >= 130100))
398 namespace filesystem = ::std::filesystem;
405 #define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
406 #elif defined(__cpp_lib_experimental_filesystem) && \
407  __cpp_lib_experimental_filesystem >= 201406L
408 namespace filesystem = ::std::experimental::filesystem;
409 #define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
410 #endif /* MDBX_STD_FILESYSTEM_PATH */
411 
412 #ifdef MDBX_STD_FILESYSTEM_PATH
414 #elif defined(_WIN32) || defined(_WIN64)
415 using path = ::std::wstring;
416 #else
417 using path = ::std::string;
418 #endif /* mdbx::path */
419 
420 #if defined(__SIZEOF_INT128__) || \
421  (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
422 #ifndef MDBX_U128_TYPE
423 #define MDBX_U128_TYPE __uint128_t
424 #endif /* MDBX_U128_TYPE */
425 #ifndef MDBX_I128_TYPE
426 #define MDBX_I128_TYPE __int128_t
427 #endif /* MDBX_I128_TYPE */
428 #endif /* __SIZEOF_INT128__ || _INTEGRAL_MAX_BITS >= 128 */
429 
430 #if __cplusplus >= 201103L || defined(DOXYGEN)
432 using duration = ::std::chrono::duration<unsigned, ::std::ratio<1, 65536>>;
433 #endif /* Duration for C++11 */
434 
437 
443  ::std::exception_ptr captured_;
444 
445 public:
446  exception_thunk() noexcept = default;
447  exception_thunk(const exception_thunk &) = delete;
449  exception_thunk &operator=(const exception_thunk &) = delete;
450  exception_thunk &operator=(exception_thunk &&) = delete;
451  inline bool is_clean() const noexcept;
452  inline void capture() noexcept;
453  inline void rethrow_captured() const;
454 };
455 
458  MDBX_error_t code_;
459  inline error &operator=(MDBX_error_t error_code) noexcept;
460 
461 public:
462  MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
463  error(const error &) = default;
464  error(error &&) = default;
465  error &operator=(const error &) = default;
466  error &operator=(error &&) = default;
467 
468  MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a,
469  const error &b) noexcept;
470  MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a,
471  const error &b) noexcept;
472 
473  MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
474  MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
475  MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
476  MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
477 
479  MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
480 
482  const char *what() const noexcept;
483 
485  ::std::string message() const;
486 
488  MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
490  [[noreturn]] void panic(const char *context_where_when,
491  const char *func_who_what) const noexcept;
492  [[noreturn]] void throw_exception() const;
493  [[noreturn]] static inline void throw_exception(int error_code);
494  inline void throw_on_failure() const;
495  inline void success_or_throw() const;
496  inline void success_or_throw(const exception_thunk &) const;
497  inline void panic_on_failure(const char *context_where,
498  const char *func_who) const noexcept;
499  inline void success_or_panic(const char *context_where,
500  const char *func_who) const noexcept;
501  static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
502  static inline void success_or_throw(MDBX_error_t error_code);
503  static void success_or_throw(int error_code) {
504  success_or_throw(static_cast<MDBX_error_t>(error_code));
505  }
506  static inline void throw_on_failure(int error_code);
507  static inline bool boolean_or_throw(int error_code);
508  static inline void success_or_throw(int error_code, const exception_thunk &);
509  static inline bool boolean_or_throw(int error_code, const exception_thunk &);
510  static inline void panic_on_failure(int error_code, const char *context_where,
511  const char *func_who) noexcept;
512  static inline void success_or_panic(int error_code, const char *context_where,
513  const char *func_who) noexcept;
514 };
515 
520 class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
521  using base = ::std::runtime_error;
522  ::mdbx::error error_;
523 
524 public:
525  exception(const ::mdbx::error &) noexcept;
526  exception(const exception &) = default;
527  exception(exception &&) = default;
528  exception &operator=(const exception &) = default;
529  exception &operator=(exception &&) = default;
530  virtual ~exception() noexcept;
531  const ::mdbx::error error() const noexcept { return error_; }
532 };
533 
537  using base = exception;
538 
539 public:
540  fatal(const ::mdbx::error &) noexcept;
541  fatal(const exception &src) noexcept : fatal(src.error()) {}
542  fatal(exception &&src) noexcept : fatal(src.error()) {}
543  fatal(const fatal &src) noexcept : fatal(src.error()) {}
544  fatal(fatal &&src) noexcept : fatal(src.error()) {}
545  fatal &operator=(fatal &&) = default;
546  fatal &operator=(const fatal &) = default;
547  virtual ~fatal() noexcept;
548 };
549 
550 #define MDBX_DECLARE_EXCEPTION(NAME) \
551  struct LIBMDBX_API_TYPE NAME : public exception { \
552  NAME(const ::mdbx::error &); \
553  virtual ~NAME() noexcept; \
554  }
585 #undef MDBX_DECLARE_EXCEPTION
586 
589 [[noreturn]] LIBMDBX_API void throw_out_range();
591 [[noreturn]] LIBMDBX_API void throw_bad_value_size();
593 static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes);
594 static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom,
595  size_t payload);
596 static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload,
597  size_t tailroom);
598 
600 
601 //------------------------------------------------------------------------------
602 
605 
606 #if MDBX_HAVE_CXX20_CONCEPTS || defined(DOXYGEN)
607 
611 template <typename T>
612 concept MutableByteProducer = requires(T a, char array[42]) {
613  { a.is_empty() } -> std::same_as<bool>;
614  { a.envisage_result_length() } -> std::same_as<size_t>;
615  { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
616 };
617 
621 template <typename T>
622 concept ImmutableByteProducer = requires(const T &a, char array[42]) {
623  { a.is_empty() } -> std::same_as<bool>;
624  { a.envisage_result_length() } -> std::same_as<size_t>;
625  { a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
626 };
627 
631 template <typename T>
633  ImmutableByteProducer<T> && requires(const slice &source, const T &a) {
634  T(source);
635  { a.is_erroneous() } -> std::same_as<bool>;
636  };
637 
638 #endif /* MDBX_HAVE_CXX20_CONCEPTS */
639 
640 template <class ALLOCATOR = default_allocator,
641  typename CAPACITY_POLICY = default_capacity_policy,
642  MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
643 inline buffer<ALLOCATOR, CAPACITY_POLICY>
644 make_buffer(PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
645 
646 template <class ALLOCATOR = default_allocator,
647  typename CAPACITY_POLICY = default_capacity_policy,
648  MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
649 inline buffer<ALLOCATOR, CAPACITY_POLICY>
650 make_buffer(const PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
651 
652 template <class ALLOCATOR = default_allocator,
653  MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
654 inline string<ALLOCATOR> make_string(PRODUCER &producer,
655  const ALLOCATOR &allocator = ALLOCATOR());
656 
657 template <class ALLOCATOR = default_allocator,
658  MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
659 inline string<ALLOCATOR> make_string(const PRODUCER &producer,
660  const ALLOCATOR &allocator = ALLOCATOR());
661 
673 
674  enum { max_length = MDBX_MAXDATASIZE };
675 
677  MDBX_CXX11_CONSTEXPR slice() noexcept;
678 
681  MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
682 
684  MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
685 
687  template <size_t SIZE>
688  MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
689  MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
690  }
692  explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
693 
696  template <class CHAR, class T, class A>
697  explicit MDBX_CXX20_CONSTEXPR
698  slice(const ::std::basic_string<CHAR, T, A> &str)
699  : slice(str.data(), str.length() * sizeof(CHAR)) {}
700 
701  MDBX_CXX14_CONSTEXPR slice(const MDBX_val &src);
702  MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
704  MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
705 
706 #if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
707  template <typename POD>
708  MDBX_CXX14_CONSTEXPR slice(const ::std::span<POD> &span)
709  : slice(span.begin(), span.end()) {
710  static_assert(::std::is_standard_layout<POD>::value &&
711  !::std::is_pointer<POD>::value,
712  "Must be a standard layout type!");
713  }
714 
715  template <typename POD>
716  MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
717  static_assert(::std::is_standard_layout<POD>::value &&
718  !::std::is_pointer<POD>::value,
719  "Must be a standard layout type!");
720  if (MDBX_LIKELY(size() % sizeof(POD) == 0))
722  return ::std::span<const POD>(static_cast<const POD *>(data()),
723  size() / sizeof(POD));
725  }
726 
727  template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
728  static_assert(::std::is_standard_layout<POD>::value &&
729  !::std::is_pointer<POD>::value,
730  "Must be a standard layout type!");
731  if (MDBX_LIKELY(size() % sizeof(POD) == 0))
733  return ::std::span<POD>(static_cast<POD *>(data()), size() / sizeof(POD));
735  }
736 
737  MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const {
738  return as_span<const byte>();
739  }
740  MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
741  MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const {
742  return as_span<const char>();
743  }
744  MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
745 #endif /* __cpp_lib_span >= 202002L */
746 
747 #if defined(DOXYGEN) || \
748  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
750  template <class CHAR, class T>
751  MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv)
752  : slice(sv.data(), sv.data() + sv.length()) {}
753 
754  template <class CHAR, class T>
755  slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) {
756  sv = {};
757  }
758 #endif /* __cpp_lib_string_view >= 201606L */
759 
760  template <size_t SIZE>
761  static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) {
762  return slice(text);
763  }
764 
765  template <typename POD>
766  MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
767  static_assert(::std::is_standard_layout<POD>::value &&
768  !::std::is_pointer<POD>::value,
769  "Must be a standard layout type!");
770  return slice(&pod, sizeof(pod));
771  }
772 
773  inline slice &assign(const void *ptr, size_t bytes);
774  inline slice &assign(const slice &src) noexcept;
775  inline slice &assign(const ::MDBX_val &src);
776  inline slice &assign(slice &&src) noexcept;
777  inline slice &assign(::MDBX_val &&src);
778  inline slice &assign(const void *begin, const void *end);
779  template <class CHAR, class T, class ALLOCATOR>
780  slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
781  return assign(str.data(), str.length() * sizeof(CHAR));
782  }
783  inline slice &assign(const char *c_str);
784 #if defined(DOXYGEN) || \
785  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
786  template <class CHAR, class T>
787  slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
788  return assign(view.begin(), view.end());
789  }
790  template <class CHAR, class T>
791  slice &assign(::std::basic_string_view<CHAR, T> &&view) {
792  assign(view);
793  view = {};
794  return *this;
795  }
796 #endif /* __cpp_lib_string_view >= 201606L */
797 
798  slice &operator=(const slice &) noexcept = default;
799  inline slice &operator=(slice &&src) noexcept;
800  inline slice &operator=(::MDBX_val &&src);
801  operator MDBX_val *() noexcept { return this; }
802  operator const MDBX_val *() const noexcept { return this; }
803 
804 #if defined(DOXYGEN) || \
805  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
806  template <class CHAR, class T>
807  slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
808  return assign(view);
809  }
810 
811  template <class CHAR, class T>
812  slice &operator=(::std::basic_string_view<CHAR, T> &&view) {
813  return assign(view);
814  }
815 
817  template <class CHAR = char, class T = ::std::char_traits<CHAR>>
818  MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T>
819  string_view() const noexcept {
820  static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
821  return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
822  }
823 
825  template <class CHAR, class T>
826  MDBX_CXX11_CONSTEXPR explicit
827  operator ::std::basic_string_view<CHAR, T>() const noexcept {
828  return this->string_view<CHAR, T>();
829  }
830 #endif /* __cpp_lib_string_view >= 201606L */
831 
832  template <class CHAR = char, class T = ::std::char_traits<CHAR>,
833  class ALLOCATOR = default_allocator>
834  MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR>
835  as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
836  static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
837  return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(),
838  allocator);
839  }
840 
841  template <class CHAR, class T, class ALLOCATOR>
842  MDBX_CXX20_CONSTEXPR explicit
843  operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
844  return as_string<CHAR, T, ALLOCATOR>();
845  }
846 
848  template <class ALLOCATOR = default_allocator>
849  inline string<ALLOCATOR>
850  as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
851  const ALLOCATOR &allocator = ALLOCATOR()) const;
852 
855  template <class ALLOCATOR = default_allocator>
856  inline string<ALLOCATOR>
857  as_base58_string(unsigned wrap_width = 0,
858  const ALLOCATOR &allocator = ALLOCATOR()) const;
859 
862  template <class ALLOCATOR = default_allocator>
863  inline string<ALLOCATOR>
864  as_base64_string(unsigned wrap_width = 0,
865  const ALLOCATOR &allocator = ALLOCATOR()) const;
866 
868  template <class ALLOCATOR = default_allocator,
869  class CAPACITY_POLICY = default_capacity_policy>
870  inline buffer<ALLOCATOR, CAPACITY_POLICY>
871  encode_hex(bool uppercase = false, unsigned wrap_width = 0,
872  const ALLOCATOR &allocator = ALLOCATOR()) const;
873 
876  template <class ALLOCATOR = default_allocator,
877  class CAPACITY_POLICY = default_capacity_policy>
878  inline buffer<ALLOCATOR, CAPACITY_POLICY>
879  encode_base58(unsigned wrap_width = 0,
880  const ALLOCATOR &allocator = ALLOCATOR()) const;
881 
884  template <class ALLOCATOR = default_allocator,
885  class CAPACITY_POLICY = default_capacity_policy>
886  inline buffer<ALLOCATOR, CAPACITY_POLICY>
887  encode_base64(unsigned wrap_width = 0,
888  const ALLOCATOR &allocator = ALLOCATOR()) const;
889 
891  template <class ALLOCATOR = default_allocator,
892  class CAPACITY_POLICY = default_capacity_policy>
893  inline buffer<ALLOCATOR, CAPACITY_POLICY>
894  hex_decode(bool ignore_spaces = false,
895  const ALLOCATOR &allocator = ALLOCATOR()) const;
896 
899  template <class ALLOCATOR = default_allocator,
900  class CAPACITY_POLICY = default_capacity_policy>
901  inline buffer<ALLOCATOR, CAPACITY_POLICY>
902  base58_decode(bool ignore_spaces = false,
903  const ALLOCATOR &allocator = ALLOCATOR()) const;
904 
907  template <class ALLOCATOR = default_allocator,
908  class CAPACITY_POLICY = default_capacity_policy>
909  inline buffer<ALLOCATOR, CAPACITY_POLICY>
910  base64_decode(bool ignore_spaces = false,
911  const ALLOCATOR &allocator = ALLOCATOR()) const;
912 
919  is_printable(bool disable_utf8 = false) const noexcept;
920 
925  inline MDBX_NOTHROW_PURE_FUNCTION bool
926  is_hex(bool ignore_spaces = false) const noexcept;
927 
933  inline MDBX_NOTHROW_PURE_FUNCTION bool
934  is_base58(bool ignore_spaces = false) const noexcept;
935 
941  inline MDBX_NOTHROW_PURE_FUNCTION bool
942  is_base64(bool ignore_spaces = false) const noexcept;
943 
944  inline void swap(slice &other) noexcept;
945 
946 #if defined(DOXYGEN) || \
947  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
948  template <class CHAR, class T>
949  void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
950  static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
951  const auto temp = ::std::basic_string_view<CHAR, T>(*this);
952  *this = view;
953  view = temp;
954  }
955 #endif /* __cpp_lib_string_view >= 201606L */
956 
958  MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
959  MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
960 
962  MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
963  MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
964 
966  MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
967  MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
968 
970  MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
971  MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
972 
974  MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
975  MDBX_CXX11_CONSTEXPR void *data() noexcept;
976 
978  MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
979  MDBX_CXX11_CONSTEXPR void *end() noexcept;
980 
982  MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
983 
985  MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
986 
988  MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
989 
991  MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
992 
994  MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
995 
997  MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
998 
1000  MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
1001 
1003  MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
1004 
1006  MDBX_CXX14_CONSTEXPR void clear() noexcept;
1007 
1010  inline void remove_prefix(size_t n) noexcept;
1011 
1014  inline void remove_suffix(size_t n) noexcept;
1015 
1018  inline void safe_remove_prefix(size_t n);
1019 
1022  inline void safe_remove_suffix(size_t n);
1023 
1026  starts_with(const slice &prefix) const noexcept;
1027 
1030  ends_with(const slice &suffix) const noexcept;
1031 
1034  MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
1035 
1038  MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
1039 
1042  MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
1043 
1046  MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
1047 
1050  MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
1051 
1054  MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
1055 
1058  MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
1059 
1062  MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
1063 
1069  hash_value() const noexcept;
1070 
1080  compare_fast(const slice &a, const slice &b) noexcept;
1081 
1088  compare_lexicographically(const slice &a, const slice &b) noexcept;
1089  friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a,
1090  const slice &b) noexcept;
1091  friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a,
1092  const slice &b) noexcept;
1093  friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a,
1094  const slice &b) noexcept;
1095  friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a,
1096  const slice &b) noexcept;
1097  friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a,
1098  const slice &b) noexcept;
1099  friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a,
1100  const slice &b) noexcept;
1101 
1103  MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept {
1104  return !(iov_base == nullptr && iov_len != 0);
1105  }
1106 
1109  MDBX_CXX14_CONSTEXPR static slice invalid() noexcept {
1110  return slice(size_t(-1));
1111  }
1112 
1113  template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
1114  static_assert(::std::is_standard_layout<POD>::value &&
1115  !::std::is_pointer<POD>::value,
1116  "Must be a standard layout type!");
1117  if (MDBX_LIKELY(size() == sizeof(POD)))
1119  POD r;
1120  memcpy(&r, data(), sizeof(r));
1121  return r;
1122  }
1124  }
1125 
1126 #ifdef MDBX_U128_TYPE
1127  MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const {
1128  return as_pod<MDBX_U128_TYPE>();
1129  }
1130 #endif /* MDBX_U128_TYPE */
1131  MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const { return as_pod<uint64_t>(); }
1132  MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const { return as_pod<uint32_t>(); }
1133  MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const { return as_pod<uint16_t>(); }
1134  MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return as_pod<uint8_t>(); }
1135 
1136 #ifdef MDBX_I128_TYPE
1137  MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const {
1138  return as_pod<MDBX_I128_TYPE>();
1139  }
1140 #endif /* MDBX_I128_TYPE */
1141  MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return as_pod<int64_t>(); }
1142  MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return as_pod<int32_t>(); }
1143  MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return as_pod<int16_t>(); }
1144  MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return as_pod<int8_t>(); }
1145 
1146 #ifdef MDBX_U128_TYPE
1147  MDBX_U128_TYPE as_uint128_adapt() const;
1148 #endif /* MDBX_U128_TYPE */
1149  uint64_t as_uint64_adapt() const;
1150  uint32_t as_uint32_adapt() const;
1151  uint16_t as_uint16_adapt() const;
1152  uint8_t as_uint8_adapt() const;
1153 
1154 #ifdef MDBX_I128_TYPE
1155  MDBX_I128_TYPE as_int128_adapt() const;
1156 #endif /* MDBX_I128_TYPE */
1157  int64_t as_int64_adapt() const;
1158  int32_t as_int32_adapt() const;
1159  int16_t as_int16_adapt() const;
1160  int8_t as_int8_adapt() const;
1161 
1162 protected:
1163  MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept
1164  : ::MDBX_val({nullptr, invalid_length}) {}
1165 };
1166 
1167 //------------------------------------------------------------------------------
1168 
1169 namespace allocation_aware_details {
1170 
1171 template <typename A> constexpr bool allocator_is_always_equal() noexcept {
1172 #if defined(__cpp_lib_allocator_traits_is_always_equal) && \
1173  __cpp_lib_allocator_traits_is_always_equal >= 201411L
1174  return ::std::allocator_traits<A>::is_always_equal::value;
1175 #else
1176  return ::std::is_empty<A>::value;
1177 #endif /* __cpp_lib_allocator_traits_is_always_equal */
1178 }
1179 
1180 template <typename T, typename A = typename T::allocator_type,
1181  bool PoCMA = ::std::allocator_traits<
1182  A>::propagate_on_container_move_assignment::value>
1184 
1185 template <typename T, typename A> struct move_assign_alloc<T, A, false> {
1186  static constexpr bool is_nothrow() noexcept {
1187  return allocator_is_always_equal<A>();
1188  }
1189  static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
1190  return allocator_is_always_equal<A>() ||
1191  target->get_allocator() == source.get_allocator();
1192  }
1193  static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
1194  assert(target->get_allocator() != source.get_allocator());
1195  (void)target;
1196  (void)source;
1197  }
1198 };
1199 
1200 template <typename T, typename A> struct move_assign_alloc<T, A, true> {
1201  static constexpr bool is_nothrow() noexcept {
1202  return allocator_is_always_equal<A>() ||
1203  ::std::is_nothrow_move_assignable<A>::value;
1204  }
1205  static constexpr bool is_moveable(T *, T &) noexcept { return true; }
1206  static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) {
1207  assert(target->get_allocator() != source.get_allocator());
1208  target->get_allocator() = ::std::move(source.get_allocator());
1209  }
1210 };
1211 
1212 template <typename T, typename A = typename T::allocator_type,
1213  bool PoCCA = ::std::allocator_traits<
1214  A>::propagate_on_container_copy_assignment::value>
1216 
1217 template <typename T, typename A> struct copy_assign_alloc<T, A, false> {
1218  static constexpr bool is_nothrow() noexcept { return false; }
1219  static MDBX_CXX20_CONSTEXPR void propagate(T *target,
1220  const T &source) noexcept {
1221  assert(target->get_allocator() != source.get_allocator());
1222  (void)target;
1223  (void)source;
1224  }
1225 };
1226 
1227 template <typename T, typename A> struct copy_assign_alloc<T, A, true> {
1228  static constexpr bool is_nothrow() noexcept {
1229  return allocator_is_always_equal<A>() ||
1230  ::std::is_nothrow_copy_assignable<A>::value;
1231  }
1232  static MDBX_CXX20_CONSTEXPR void
1233  propagate(T *target, const T &source) noexcept(is_nothrow()) {
1234  if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1235  if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1236  MDBX_CXX20_UNLIKELY target->get_allocator() =
1237  ::std::allocator_traits<A>::select_on_container_copy_construction(
1238  source.get_allocator());
1239  } else {
1240  /* gag for buggy compilers */
1241  (void)target;
1242  (void)source;
1243  }
1244  }
1245 };
1246 
1247 template <typename T, typename A = typename T::allocator_type,
1248  bool PoCS =
1249  ::std::allocator_traits<A>::propagate_on_container_swap::value>
1250 struct swap_alloc;
1251 
1252 template <typename T, typename A> struct swap_alloc<T, A, false> {
1253  static constexpr bool is_nothrow() noexcept {
1254  return allocator_is_always_equal<A>();
1255  }
1256  static MDBX_CXX20_CONSTEXPR void propagate(T *target,
1257  T &source) noexcept(is_nothrow()) {
1258  if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1259  if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1260  MDBX_CXX20_UNLIKELY throw_allocators_mismatch();
1261  } else {
1262  /* gag for buggy compilers */
1263  (void)target;
1264  (void)source;
1265  }
1266  }
1267 };
1268 
1269 template <typename T, typename A> struct swap_alloc<T, A, true> {
1270  static constexpr bool is_nothrow() noexcept {
1271  return allocator_is_always_equal<A>() ||
1272 #if defined(__cpp_lib_is_swappable) && __cpp_lib_is_swappable >= 201603L
1273  ::std::is_nothrow_swappable<A>() ||
1274 #endif /* __cpp_lib_is_swappable >= 201603L */
1275  (::std::is_nothrow_move_constructible<A>::value &&
1276  ::std::is_nothrow_move_assignable<A>::value);
1277  }
1278  static MDBX_CXX20_CONSTEXPR void propagate(T *target,
1279  T &source) noexcept(is_nothrow()) {
1280  if MDBX_IF_CONSTEXPR (!allocator_is_always_equal<A>()) {
1281  if (MDBX_UNLIKELY(target->get_allocator() != source.get_allocator()))
1282  MDBX_CXX20_UNLIKELY ::std::swap(*target, source);
1283  } else {
1284  /* gag for buggy compilers */
1285  (void)target;
1286  (void)source;
1287  }
1288  }
1289 };
1290 
1291 } // namespace allocation_aware_details
1292 
1294  enum : size_t {
1295  extra_inplace_storage = 0,
1296  pettiness_threshold = 64,
1297  max_reserve = 65536
1298  };
1299 
1300  static MDBX_CXX11_CONSTEXPR size_t round(const size_t value) {
1301  static_assert((pettiness_threshold & (pettiness_threshold - 1)) == 0,
1302  "pettiness_threshold must be a power of 2");
1303  static_assert(pettiness_threshold % 2 == 0,
1304  "pettiness_threshold must be even");
1305  static_assert(pettiness_threshold >= sizeof(uint64_t),
1306  "pettiness_threshold must be > 7");
1307  constexpr const auto pettiness_mask = ~size_t(pettiness_threshold - 1);
1308  return (value + pettiness_threshold - 1) & pettiness_mask;
1309  }
1310 
1311  static MDBX_CXX11_CONSTEXPR size_t advise(const size_t current,
1312  const size_t wanna) {
1313  static_assert(max_reserve % pettiness_threshold == 0,
1314  "max_reserve must be a multiple of pettiness_threshold");
1315  static_assert(max_reserve / 3 > pettiness_threshold,
1316  "max_reserve must be > pettiness_threshold * 3");
1317  if (wanna > current)
1318  /* doubling capacity, but don't made reserve more than max_reserve */
1319  return round(wanna + ::std::min(size_t(max_reserve), current));
1320 
1321  if (current - wanna >
1322  /* shrink if reserve will more than half of current or max_reserve,
1323  * but not less than pettiness_threshold */
1324  ::std::min(wanna + pettiness_threshold, size_t(max_reserve)))
1325  return round(wanna);
1326 
1327  /* keep unchanged */
1328  return current;
1329  }
1330 };
1331 
1334  const slice source;
1335  const bool uppercase = false;
1336  const unsigned wrap_width = 0;
1337  MDBX_CXX11_CONSTEXPR to_hex(const slice &source, bool uppercase = false,
1338  unsigned wrap_width = 0) noexcept
1339  : source(source), uppercase(uppercase), wrap_width(wrap_width) {
1341  }
1342 
1344  template <class ALLOCATOR = default_allocator>
1345  string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1346  return make_string<ALLOCATOR>(*this, allocator);
1347  }
1348 
1350  template <class ALLOCATOR = default_allocator,
1351  typename CAPACITY_POLICY = default_capacity_policy>
1353  as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1354  return make_buffer<ALLOCATOR>(*this, allocator);
1355  }
1356 
1360  const size_t bytes = source.length() << 1;
1361  return wrap_width ? bytes + bytes / wrap_width : bytes;
1362  }
1363 
1366  char *write_bytes(char *dest, size_t dest_size) const;
1367 
1371  ::std::ostream &output(::std::ostream &out) const;
1372 
1375  bool is_empty() const noexcept { return source.empty(); }
1376 
1379  bool is_erroneous() const noexcept { return false; }
1380 };
1381 
1385  const slice source;
1386  const unsigned wrap_width = 0;
1388  to_base58(const slice &source, unsigned wrap_width = 0) noexcept
1389  : source(source), wrap_width(wrap_width) {
1391  }
1392 
1395  template <class ALLOCATOR = default_allocator>
1396  string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1397  return make_string<ALLOCATOR>(*this, allocator);
1398  }
1399 
1402  template <class ALLOCATOR = default_allocator,
1403  typename CAPACITY_POLICY = default_capacity_policy>
1405  as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1406  return make_buffer<ALLOCATOR>(*this, allocator);
1407  }
1408 
1412  const size_t bytes = (source.length() * 11 + 7) / 8;
1413  return wrap_width ? bytes + bytes / wrap_width : bytes;
1414  }
1415 
1419  char *write_bytes(char *dest, size_t dest_size) const;
1420 
1425  ::std::ostream &output(::std::ostream &out) const;
1426 
1429  bool is_empty() const noexcept { return source.empty(); }
1430 
1433  bool is_erroneous() const noexcept { return false; }
1434 };
1435 
1439  const slice source;
1440  const unsigned wrap_width = 0;
1442  to_base64(const slice &source, unsigned wrap_width = 0) noexcept
1443  : source(source), wrap_width(wrap_width) {
1445  }
1446 
1449  template <class ALLOCATOR = default_allocator>
1450  string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1451  return make_string<ALLOCATOR>(*this, allocator);
1452  }
1453 
1456  template <class ALLOCATOR = default_allocator,
1457  typename CAPACITY_POLICY = default_capacity_policy>
1459  as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1460  return make_buffer<ALLOCATOR>(*this, allocator);
1461  }
1462 
1466  const size_t bytes = (source.length() + 2) / 3 * 4;
1467  return wrap_width ? bytes + bytes / wrap_width : bytes;
1468  }
1469 
1473  char *write_bytes(char *dest, size_t dest_size) const;
1474 
1479  ::std::ostream &output(::std::ostream &out) const;
1480 
1483  bool is_empty() const noexcept { return source.empty(); }
1484 
1487  bool is_erroneous() const noexcept { return false; }
1488 };
1489 
1490 inline ::std::ostream &operator<<(::std::ostream &out, const to_hex &wrapper) {
1491  return wrapper.output(out);
1492 }
1493 inline ::std::ostream &operator<<(::std::ostream &out,
1494  const to_base58 &wrapper) {
1495  return wrapper.output(out);
1496 }
1497 inline ::std::ostream &operator<<(::std::ostream &out,
1498  const to_base64 &wrapper) {
1499  return wrapper.output(out);
1500 }
1501 
1504  const slice source;
1505  const bool ignore_spaces = false;
1507  bool ignore_spaces = false) noexcept
1508  : source(source), ignore_spaces(ignore_spaces) {
1510  }
1511 
1513  template <class ALLOCATOR = default_allocator>
1514  string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1515  return make_string<ALLOCATOR>(*this, allocator);
1516  }
1517 
1519  template <class ALLOCATOR = default_allocator,
1520  typename CAPACITY_POLICY = default_capacity_policy>
1522  as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1523  return make_buffer<ALLOCATOR>(*this, allocator);
1524  }
1525 
1529  return source.length() >> 1;
1530  }
1531 
1535  char *write_bytes(char *dest, size_t dest_size) const;
1536 
1539  bool is_empty() const noexcept { return source.empty(); }
1540 
1543  bool is_erroneous() const noexcept;
1544 };
1545 
1549  const slice source;
1550  const bool ignore_spaces = false;
1552  bool ignore_spaces = false) noexcept
1553  : source(source), ignore_spaces(ignore_spaces) {
1555  }
1556 
1559  template <class ALLOCATOR = default_allocator>
1560  string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1561  return make_string<ALLOCATOR>(*this, allocator);
1562  }
1563 
1566  template <class ALLOCATOR = default_allocator,
1567  typename CAPACITY_POLICY = default_capacity_policy>
1569  as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1570  return make_buffer<ALLOCATOR>(*this, allocator);
1571  }
1572 
1577  return source.length() /* могут быть все нули кодируемые один-к-одному */;
1578  }
1579 
1583  char *write_bytes(char *dest, size_t dest_size) const;
1584 
1587  bool is_empty() const noexcept { return source.empty(); }
1588 
1592  bool is_erroneous() const noexcept;
1593 };
1594 
1598  const slice source;
1599  const bool ignore_spaces = false;
1601  bool ignore_spaces = false) noexcept
1602  : source(source), ignore_spaces(ignore_spaces) {
1604  }
1605 
1608  template <class ALLOCATOR = default_allocator>
1609  string<ALLOCATOR> as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
1610  return make_string<ALLOCATOR>(*this, allocator);
1611  }
1612 
1615  template <class ALLOCATOR = default_allocator,
1616  typename CAPACITY_POLICY = default_capacity_policy>
1618  as_buffer(const ALLOCATOR &allocator = ALLOCATOR()) const {
1619  return make_buffer<ALLOCATOR>(*this, allocator);
1620  }
1621 
1626  return (source.length() + 3) / 4 * 3;
1627  }
1628 
1632  char *write_bytes(char *dest, size_t dest_size) const;
1633 
1636  bool is_empty() const noexcept { return source.empty(); }
1637 
1641  bool is_erroneous() const noexcept;
1642 };
1643 
1645 template <class ALLOCATOR, typename CAPACITY_POLICY> class buffer {
1646 public:
1647 #if !defined(_MSC_VER) || _MSC_VER > 1900
1648  using allocator_type = typename ::std::allocator_traits<
1649  ALLOCATOR>::template rebind_alloc<uint64_t>;
1650 #else
1651  using allocator_type = typename ALLOCATOR::template rebind<uint64_t>::other;
1652 #endif /* MSVC is mad */
1653  using allocator_traits = ::std::allocator_traits<allocator_type>;
1654  using reservation_policy = CAPACITY_POLICY;
1655  enum : size_t {
1656  max_length = MDBX_MAXDATASIZE,
1657  max_capacity = (max_length / 3u * 4u + 1023u) & ~size_t(1023),
1658  extra_inplace_storage = reservation_policy::extra_inplace_storage,
1659  pettiness_threshold = reservation_policy::pettiness_threshold
1660  };
1661 
1662 private:
1663  friend class txn;
1664  struct silo;
1666  struct silo /* Empty Base Class Optimization */ : public allocator_type {
1667  MDBX_CXX20_CONSTEXPR const allocator_type &get_allocator() const noexcept {
1668  return *this;
1669  }
1670  MDBX_CXX20_CONSTEXPR allocator_type &get_allocator() noexcept {
1671  return *this;
1672  }
1673 
1674  using allocator_pointer = typename allocator_traits::pointer;
1675  using allocator_const_pointer = typename allocator_traits::const_pointer;
1676 
1677  MDBX_CXX20_CONSTEXPR ::std::pair<allocator_pointer, size_t>
1678  allocate_storage(size_t bytes) {
1679  assert(bytes >= sizeof(bin));
1680  constexpr size_t unit = sizeof(typename allocator_type::value_type);
1681  static_assert((unit & (unit - 1)) == 0,
1682  "size of ALLOCATOR::value_type should be a power of 2");
1683  static_assert(unit > 0, "size of ALLOCATOR::value_type must be > 0");
1684  const size_t n = (bytes + unit - 1) / unit;
1685  return ::std::make_pair(allocator_traits::allocate(get_allocator(), n),
1686  n * unit);
1687  }
1688  MDBX_CXX20_CONSTEXPR void deallocate_storage(allocator_pointer ptr,
1689  size_t bytes) {
1690  constexpr size_t unit = sizeof(typename allocator_type::value_type);
1691  assert(ptr && bytes >= sizeof(bin) && bytes >= unit && bytes % unit == 0);
1692  allocator_traits::deallocate(get_allocator(), ptr, bytes / unit);
1693  }
1694 
1695  static MDBX_CXX17_CONSTEXPR void *
1696  to_address(allocator_pointer ptr) noexcept {
1697 #if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1698  return static_cast<void *>(::std::to_address(ptr));
1699 #else
1700  return static_cast<void *>(::std::addressof(*ptr));
1701 #endif /* __cpp_lib_to_address */
1702  }
1703  static MDBX_CXX17_CONSTEXPR const void *
1704  to_address(allocator_const_pointer ptr) noexcept {
1705 #if defined(__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L
1706  return static_cast<const void *>(::std::to_address(ptr));
1707 #else
1708  return static_cast<const void *>(::std::addressof(*ptr));
1709 #endif /* __cpp_lib_to_address */
1710  }
1711 
1712  union bin {
1713  struct allocated {
1714  allocator_pointer ptr_;
1716  constexpr allocated(allocator_pointer ptr, size_t bytes) noexcept
1717  : ptr_(ptr), capacity_bytes_(bytes) {}
1718  constexpr allocated(const allocated &) noexcept = default;
1719  constexpr allocated(allocated &&) noexcept = default;
1721  operator=(const allocated &) noexcept = default;
1723  operator=(allocated &&) noexcept = default;
1724  };
1725 
1726  allocated allocated_;
1727  uint64_t align_hint_;
1728  byte inplace_[(sizeof(allocated) + extra_inplace_storage + 7u) &
1729  ~size_t(7)];
1730 
1731  static constexpr bool
1732  is_suitable_for_inplace(size_t capacity_bytes) noexcept {
1733  static_assert(sizeof(bin) == sizeof(inplace_), "WTF?");
1734  return capacity_bytes < sizeof(bin);
1735  }
1736 
1737  enum : byte {
1738  /* Little Endian:
1739  * last byte is the most significant byte of u_.allocated.cap,
1740  * so use higher bit of capacity as the inplace-flag */
1741  le_lastbyte_mask = 0x80,
1742  /* Big Endian:
1743  * last byte is the least significant byte of u_.allocated.cap,
1744  * so use lower bit of capacity as the inplace-flag. */
1745  be_lastbyte_mask = 0x01
1746  };
1747 
1748  static constexpr byte inplace_lastbyte_mask() noexcept {
1749  static_assert(
1750  endian::native == endian::little || endian::native == endian::big,
1751  "Only the little-endian or big-endian bytes order are supported");
1752  return (endian::native == endian::little) ? le_lastbyte_mask
1753  : be_lastbyte_mask;
1754  }
1755  constexpr byte lastbyte() const noexcept {
1756  return inplace_[sizeof(bin) - 1];
1757  }
1758  MDBX_CXX17_CONSTEXPR byte &lastbyte() noexcept {
1759  return inplace_[sizeof(bin) - 1];
1760  }
1761 
1762  constexpr bool is_inplace() const noexcept {
1763  return (lastbyte() & inplace_lastbyte_mask()) != 0;
1764  }
1765  constexpr bool is_allocated() const noexcept { return !is_inplace(); }
1766 
1767  template <bool destroy_ptr>
1769  if (destroy_ptr) {
1770  MDBX_CONSTEXPR_ASSERT(is_allocated());
1771  /* properly destroy allocator::pointer */
1772  allocated_.~allocated();
1773  }
1774  if (::std::is_trivial<allocator_pointer>::value)
1775  /* workaround for "uninitialized" warning from some compilers */
1776  ::std::memset(&allocated_.ptr_, 0, sizeof(allocated_.ptr_));
1777  lastbyte() = inplace_lastbyte_mask();
1778  MDBX_CONSTEXPR_ASSERT(is_inplace() && address() == inplace_ &&
1779  is_suitable_for_inplace(capacity()));
1780  return address();
1781  }
1782 
1783  template <bool construct_ptr>
1784  MDBX_CXX17_CONSTEXPR byte *
1785  make_allocated(allocator_pointer ptr, size_t capacity_bytes) noexcept {
1787  (capacity_bytes & be_lastbyte_mask) == 0 &&
1788  ((capacity_bytes >>
1789  (sizeof(allocated_.capacity_bytes_) - 1) * CHAR_BIT) &
1790  le_lastbyte_mask) == 0);
1791  if (construct_ptr)
1792  /* properly construct allocator::pointer */
1793  new (&allocated_) allocated(ptr, capacity_bytes);
1794  else {
1795  MDBX_CONSTEXPR_ASSERT(is_allocated());
1796  allocated_.ptr_ = ptr;
1797  allocated_.capacity_bytes_ = capacity_bytes;
1798  }
1799  MDBX_CONSTEXPR_ASSERT(is_allocated() && address() == to_address(ptr) &&
1800  capacity() == capacity_bytes);
1801  return address();
1802  }
1803 
1804  MDBX_CXX20_CONSTEXPR bin(size_t capacity_bytes = 0) noexcept {
1805  MDBX_CONSTEXPR_ASSERT(is_suitable_for_inplace(capacity_bytes));
1806  make_inplace<false>();
1807  (void)capacity_bytes;
1808  }
1809  MDBX_CXX20_CONSTEXPR bin(allocator_pointer ptr,
1810  size_t capacity_bytes) noexcept {
1811  MDBX_CONSTEXPR_ASSERT(!is_suitable_for_inplace(capacity_bytes));
1812  make_allocated<true>(ptr, capacity_bytes);
1813  }
1815  if (is_allocated())
1816  /* properly destroy allocator::pointer */
1817  allocated_.~allocated();
1818  }
1819  MDBX_CXX20_CONSTEXPR bin(bin &&ditto) noexcept {
1820  if (ditto.is_inplace()) {
1821  // micro-optimization: don't use make_inplace<> here
1822  // since memcpy() will copy the flag.
1823  memcpy(inplace_, ditto.inplace_, sizeof(inplace_));
1824  MDBX_CONSTEXPR_ASSERT(is_inplace());
1825  } else {
1826  new (&allocated_) allocated(::std::move(ditto.allocated_));
1827  ditto.make_inplace<true>();
1828  MDBX_CONSTEXPR_ASSERT(is_allocated());
1829  }
1830  }
1831 
1832  MDBX_CXX17_CONSTEXPR bin &operator=(const bin &ditto) noexcept {
1833  if (ditto.is_inplace()) {
1834  // micro-optimization: don't use make_inplace<> here
1835  // since memcpy() will copy the flag.
1836  if (is_allocated())
1837  /* properly destroy allocator::pointer */
1838  allocated_.~allocated();
1839  memcpy(inplace_, ditto.inplace_, sizeof(inplace_));
1840  MDBX_CONSTEXPR_ASSERT(is_inplace());
1841  } else if (is_inplace())
1842  make_allocated<true>(ditto.allocated_.ptr_,
1843  ditto.allocated_.capacity_bytes_);
1844  else
1845  make_allocated<false>(ditto.allocated_.ptr_,
1846  ditto.allocated_.capacity_bytes_);
1847  return *this;
1848  }
1849 
1850  MDBX_CXX17_CONSTEXPR bin &operator=(bin &&ditto) noexcept {
1851  operator=(const_cast<const bin &>(ditto));
1852  if (ditto.is_allocated())
1853  ditto.make_inplace<true>();
1854  return *this;
1855  }
1856 
1857  static MDBX_CXX20_CONSTEXPR size_t advise_capacity(const size_t current,
1858  const size_t wanna) {
1859  if (MDBX_UNLIKELY(wanna > max_capacity))
1860  MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
1861 
1862  const size_t advised = reservation_policy::advise(current, wanna);
1863  assert(advised >= wanna);
1864  return ::std::min(size_t(max_capacity),
1865  ::std::max(sizeof(bin) - 1, advised));
1866  }
1867 
1868  constexpr const byte *address() const noexcept {
1869  return is_inplace()
1870  ? inplace_
1871  : static_cast<const byte *>(to_address(allocated_.ptr_));
1872  }
1873  MDBX_CXX17_CONSTEXPR byte *address() noexcept {
1874  return is_inplace() ? inplace_
1875  : static_cast<byte *>(to_address(allocated_.ptr_));
1876  }
1877  constexpr size_t capacity() const noexcept {
1878  return is_inplace() ? sizeof(bin) - 1 : allocated_.capacity_bytes_;
1879  }
1880  } bin_;
1881 
1882  MDBX_CXX20_CONSTEXPR void *init(size_t capacity) {
1883  capacity = bin::advise_capacity(0, capacity);
1884  if (bin_.is_suitable_for_inplace(capacity))
1885  new (&bin_) bin();
1886  else {
1887  const auto pair = allocate_storage(capacity);
1888  assert(pair.second >= capacity);
1889  new (&bin_) bin(pair.first, pair.second);
1890  }
1891  return bin_.address();
1892  }
1893 
1894  MDBX_CXX20_CONSTEXPR void release() noexcept {
1895  if (bin_.is_allocated()) {
1896  deallocate_storage(bin_.allocated_.ptr_,
1897  bin_.allocated_.capacity_bytes_);
1898  bin_.template make_inplace<true>();
1899  }
1900  }
1901 
1902  template <bool external_content>
1903  MDBX_CXX20_CONSTEXPR void *
1904  reshape(const size_t wanna_capacity, const size_t wanna_headroom,
1905  const void *const content, const size_t length) {
1906  assert(wanna_capacity >= wanna_headroom + length);
1907  const size_t old_capacity = bin_.capacity();
1908  const size_t new_capacity =
1909  bin::advise_capacity(old_capacity, wanna_capacity);
1910  if (MDBX_LIKELY(new_capacity == old_capacity))
1912  assert(bin_.is_inplace() ==
1913  bin::is_suitable_for_inplace(new_capacity));
1914  byte *const new_place = bin_.address() + wanna_headroom;
1915  if (MDBX_LIKELY(length))
1917  if (external_content)
1918  memcpy(new_place, content, length);
1919  else {
1920  const size_t old_headroom =
1921  bin_.address() - static_cast<const byte *>(content);
1922  assert(old_capacity >= old_headroom + length);
1923  if (MDBX_UNLIKELY(old_headroom != wanna_headroom))
1924  MDBX_CXX20_UNLIKELY ::std::memmove(new_place, content,
1925  length);
1926  }
1927  }
1928  return new_place;
1929  }
1930 
1931  if (bin::is_suitable_for_inplace(new_capacity)) {
1932  assert(bin_.is_allocated());
1933  const auto old_allocated = ::std::move(bin_.allocated_.ptr_);
1934  byte *const new_place =
1935  bin_.template make_inplace<true>() + wanna_headroom;
1936  if (MDBX_LIKELY(length))
1937  MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1938  deallocate_storage(old_allocated, old_capacity);
1939  return new_place;
1940  }
1941 
1942  if (!bin_.is_allocated()) {
1943  const auto pair = allocate_storage(new_capacity);
1944  assert(pair.second >= new_capacity);
1945  byte *const new_place =
1946  static_cast<byte *>(to_address(pair.first)) + wanna_headroom;
1947  if (MDBX_LIKELY(length))
1948  MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1949  bin_.template make_allocated<true>(pair.first, pair.second);
1950  return new_place;
1951  }
1952 
1953  const auto old_allocated = ::std::move(bin_.allocated_.ptr_);
1954  if (external_content)
1955  deallocate_storage(old_allocated, old_capacity);
1956  const auto pair = allocate_storage(new_capacity);
1957  assert(pair.second >= new_capacity);
1958  byte *const new_place =
1959  bin_.template make_allocated<false>(pair.first, pair.second) +
1960  wanna_headroom;
1961  if (MDBX_LIKELY(length))
1962  MDBX_CXX20_LIKELY memcpy(new_place, content, length);
1963  if (!external_content)
1964  deallocate_storage(old_allocated, old_capacity);
1965  return new_place;
1966  }
1967 
1968  MDBX_CXX20_CONSTEXPR const byte *get(size_t offset = 0) const noexcept {
1969  assert(capacity() >= offset);
1970  return bin_.address() + offset;
1971  }
1972  MDBX_CXX20_CONSTEXPR byte *get(size_t offset = 0) noexcept {
1973  assert(capacity() >= offset);
1974  return bin_.address() + offset;
1975  }
1976  MDBX_CXX20_CONSTEXPR byte *put(size_t offset, const void *ptr,
1977  size_t length) {
1978  assert(capacity() >= offset + length);
1979  return static_cast<byte *>(memcpy(get(offset), ptr, length));
1980  }
1981 
1982  //--------------------------------------------------------------------------
1983 
1985  silo() noexcept : allocator_type() { init(0); }
1987  silo(const allocator_type &alloc) noexcept : allocator_type(alloc) {
1988  init(0);
1989  }
1990  MDBX_CXX20_CONSTEXPR silo(size_t capacity) { init(capacity); }
1991  MDBX_CXX20_CONSTEXPR silo(size_t capacity, const allocator_type &alloc)
1992  : silo(alloc) {
1993  init(capacity);
1994  }
1995 
1996  MDBX_CXX20_CONSTEXPR silo(silo &&ditto) noexcept(
1997  ::std::is_nothrow_move_constructible<allocator_type>::value)
1998  : allocator_type(::std::move(ditto.get_allocator())),
1999  bin_(::std::move(ditto.bin_)) {}
2000 
2001  MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr,
2002  size_t length)
2003  : silo(capacity) {
2004  assert(capacity >= headroom + length);
2005  if (length)
2006  put(headroom, ptr, length);
2007  }
2008 
2009  // select_on_container_copy_construction()
2010  MDBX_CXX20_CONSTEXPR silo(size_t capacity, size_t headroom, const void *ptr,
2011  size_t length, const allocator_type &alloc)
2012  : silo(capacity, alloc) {
2013  assert(capacity >= headroom + length);
2014  if (length)
2015  put(headroom, ptr, length);
2016  }
2017 
2018  MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length)
2019  : silo(length, 0, ptr, length) {}
2020  MDBX_CXX20_CONSTEXPR silo(const void *ptr, size_t length,
2021  const allocator_type &alloc)
2022  : silo(length, 0, ptr, length, alloc) {}
2023 
2024  ~silo() { release(); }
2025 
2026  //--------------------------------------------------------------------------
2027 
2028  MDBX_CXX20_CONSTEXPR void *assign(size_t headroom, const void *ptr,
2029  size_t length, size_t tailroom) {
2030  return reshape<true>(headroom + length + tailroom, headroom, ptr, length);
2031  }
2032  MDBX_CXX20_CONSTEXPR void *assign(const void *ptr, size_t length) {
2033  return assign(0, ptr, length, 0);
2034  }
2035 
2036  MDBX_CXX20_CONSTEXPR silo &assign(const silo &ditto, size_t headroom,
2037  slice &content) {
2038  assert(ditto.get() + headroom == content.byte_ptr());
2039  if MDBX_IF_CONSTEXPR (!allocation_aware_details::
2040  allocator_is_always_equal<allocator_type>()) {
2041  if (MDBX_UNLIKELY(get_allocator() != ditto.get_allocator()))
2042  MDBX_CXX20_UNLIKELY {
2043  release();
2044  allocation_aware_details::copy_assign_alloc<
2045  silo, allocator_type>::propagate(this, ditto);
2046  }
2047  }
2048  content.iov_base = reshape<true>(ditto.capacity(), headroom,
2049  content.data(), content.length());
2050  return *this;
2051  }
2052 
2053  MDBX_CXX20_CONSTEXPR silo &
2054  assign(silo &&ditto, size_t headroom, slice &content) noexcept(
2055  allocation_aware_details::move_assign_alloc<
2056  silo, allocator_type>::is_nothrow()) {
2057  assert(ditto.get() + headroom == content.byte_ptr());
2058  if (allocation_aware_details::move_assign_alloc<
2059  silo, allocator_type>::is_moveable(this, ditto)) {
2060  release();
2061  allocation_aware_details::move_assign_alloc<
2062  silo, allocator_type>::propagate(this, ditto);
2063  /* no reallocation nor copying required */
2064  bin_ = ::std::move(ditto.bin_);
2065  assert(get() + headroom == content.byte_ptr());
2066  } else {
2067  /* copy content since allocators are different */
2068  content.iov_base = reshape<true>(ditto.capacity(), headroom,
2069  content.data(), content.length());
2070  ditto.release();
2071  }
2072  return *this;
2073  }
2074 
2075  MDBX_CXX20_CONSTEXPR void *clear() {
2076  return reshape<true>(0, 0, nullptr, 0);
2077  }
2078  MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity,
2079  size_t headroom) {
2080  return reshape<false>(whole_capacity, headroom, nullptr, 0);
2081  }
2082  MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom,
2083  slice &content) {
2084  content.iov_base =
2085  reshape<false>(capacity, headroom, content.iov_base, content.iov_len);
2086  }
2087  MDBX_CXX20_CONSTEXPR void swap(silo &ditto) noexcept(
2088  allocation_aware_details::swap_alloc<silo,
2089  allocator_type>::is_nothrow()) {
2090  allocation_aware_details::swap_alloc<silo, allocator_type>::propagate(
2091  this, ditto);
2092  ::std::swap(bin_, ditto.bin_);
2093  }
2094 
2095  /* MDBX_CXX20_CONSTEXPR void shrink_to_fit() { TODO } */
2096 
2098  capacity() const noexcept {
2099  return bin_.capacity();
2100  }
2102  data(size_t offset = 0) const noexcept {
2103  return get(offset);
2104  }
2106  data(size_t offset = 0) noexcept {
2107  return get(offset);
2108  }
2109  };
2110 
2111  silo silo_;
2112  ::mdbx::slice slice_;
2113 
2114  void insulate() {
2115  assert(is_reference());
2116  silo_.assign(slice_.char_ptr(), slice_.length());
2117  slice_.iov_base = silo_.data();
2118  }
2119 
2121  silo_begin() const noexcept {
2122  return static_cast<const byte *>(silo_.data());
2123  }
2124 
2126  silo_end() const noexcept {
2127  return silo_begin() + silo_.capacity();
2128  }
2129 
2130  struct data_preserver : public exception_thunk {
2131  buffer data;
2132  data_preserver(allocator_type &allocator) : data(allocator) {}
2133  static int callback(void *context, MDBX_val *target, const void *src,
2134  size_t bytes) noexcept {
2135  auto self = static_cast<data_preserver *>(context);
2136  assert(self->is_clean());
2137  assert(&self->data.slice_ == target);
2138  (void)target;
2139  try {
2140  self->data.assign(src, bytes, false);
2141  return MDBX_RESULT_FALSE;
2142  } catch (... /* capture any exception to rethrow it over C code */) {
2143  self->capture();
2144  return MDBX_RESULT_TRUE;
2145  }
2146  }
2147  MDBX_CXX11_CONSTEXPR operator MDBX_preserve_func() const noexcept {
2148  return callback;
2149  }
2150  MDBX_CXX11_CONSTEXPR operator const buffer &() const noexcept {
2151  return data;
2152  }
2153  MDBX_CXX11_CONSTEXPR operator buffer &() noexcept { return data; }
2154  };
2155 
2156 public:
2160 
2165 
2168  return silo_.get_allocator();
2169  }
2170 
2174  is_freestanding() const noexcept {
2175  static_assert(size_t(-long(max_length)) > max_length, "WTF?");
2176  return size_t(byte_ptr() - silo_begin()) < silo_.capacity();
2177  }
2178 
2182  is_reference() const noexcept {
2183  return !is_freestanding();
2184  }
2185 
2189  capacity() const noexcept {
2190  return is_freestanding() ? silo_.capacity() : 0;
2191  }
2192 
2196  headroom() const noexcept {
2197  return is_freestanding() ? slice_.byte_ptr() - silo_begin() : 0;
2198  }
2199 
2203  tailroom() const noexcept {
2204  return is_freestanding() ? capacity() - headroom() - slice_.length() : 0;
2205  }
2206 
2208  MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept {
2209  return slice_.byte_ptr();
2210  }
2211 
2213  MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept {
2214  return slice_.end_byte_ptr();
2215  }
2216 
2220  MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept {
2221  MDBX_CONSTEXPR_ASSERT(is_freestanding());
2222  return const_cast<byte *>(slice_.byte_ptr());
2223  }
2224 
2229  MDBX_CONSTEXPR_ASSERT(is_freestanding());
2230  return const_cast<byte *>(slice_.end_byte_ptr());
2231  }
2232 
2234  MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept {
2235  return slice_.char_ptr();
2236  }
2237 
2239  MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept {
2240  return slice_.end_char_ptr();
2241  }
2242 
2246  MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept {
2247  MDBX_CONSTEXPR_ASSERT(is_freestanding());
2248  return const_cast<char *>(slice_.char_ptr());
2249  }
2250 
2255  MDBX_CONSTEXPR_ASSERT(is_freestanding());
2256  return const_cast<char *>(slice_.end_char_ptr());
2257  }
2258 
2260  MDBX_CXX11_CONSTEXPR const void *data() const noexcept {
2261  return slice_.data();
2262  }
2263 
2265  MDBX_CXX11_CONSTEXPR const void *end() const noexcept { return slice_.end(); }
2266 
2270  MDBX_CXX11_CONSTEXPR void *data() noexcept {
2271  MDBX_CONSTEXPR_ASSERT(is_freestanding());
2272  return const_cast<void *>(slice_.data());
2273  }
2274 
2278  MDBX_CXX11_CONSTEXPR void *end() noexcept {
2279  MDBX_CONSTEXPR_ASSERT(is_freestanding());
2280  return const_cast<void *>(slice_.end());
2281  }
2282 
2285  length() const noexcept {
2286  return MDBX_CONSTEXPR_ASSERT(is_reference() ||
2287  slice_.length() + headroom() <=
2288  silo_.capacity()),
2289  slice_.length();
2290  }
2291 
2294  MDBX_CONSTEXPR_ASSERT(is_reference() ||
2295  bytes + headroom() <= silo_.capacity());
2296  slice_.set_length(bytes);
2297  return *this;
2298  }
2299 
2302  MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
2303  return set_length(static_cast<const char *>(ptr) - char_ptr());
2304  }
2305 
2310  if (is_reference())
2311  insulate();
2312  }
2313 
2314  MDBX_CXX20_CONSTEXPR buffer() noexcept = default;
2315  MDBX_CXX20_CONSTEXPR buffer(const allocator_type &allocator) noexcept
2316  : silo_(allocator) {}
2317 
2318  buffer(const struct slice &src, bool make_reference,
2319  const allocator_type &allocator = allocator_type())
2320  : silo_(allocator), slice_(src) {
2321  if (!make_reference)
2322  insulate();
2323  }
2324 
2325  buffer(const buffer &src, bool make_reference,
2326  const allocator_type &allocator = allocator_type())
2327  : buffer(src.slice_, make_reference, allocator) {}
2328 
2329  buffer(const void *ptr, size_t bytes, bool make_reference,
2330  const allocator_type &allocator = allocator_type())
2331  : buffer(::mdbx::slice(ptr, bytes), make_reference, allocator) {}
2332 
2333  template <class CHAR, class T, class A>
2334  buffer(const ::std::basic_string<CHAR, T, A> &) = delete;
2335  template <class CHAR, class T, class A>
2336  buffer(const ::std::basic_string<CHAR, T, A> &&) = delete;
2337 
2338  buffer(const char *c_str, bool make_reference,
2339  const allocator_type &allocator = allocator_type())
2340  : buffer(::mdbx::slice(c_str), make_reference, allocator) {}
2341 
2342 #if defined(DOXYGEN) || \
2343  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2344  template <class CHAR, class T>
2345  buffer(const ::std::basic_string_view<CHAR, T> &view, bool make_reference,
2346  const allocator_type &allocator = allocator_type())
2347  : buffer(::mdbx::slice(view), make_reference, allocator) {}
2348 #endif /* __cpp_lib_string_view >= 201606L */
2349 
2351  buffer(const struct slice &src,
2352  const allocator_type &allocator = allocator_type())
2353  : silo_(src.data(), src.length(), allocator),
2354  slice_(silo_.data(), src.length()) {}
2355 
2357  buffer(const buffer &src, const allocator_type &allocator = allocator_type())
2358  : buffer(src.slice_, allocator) {}
2359 
2361  buffer(const void *ptr, size_t bytes,
2362  const allocator_type &allocator = allocator_type())
2363  : buffer(::mdbx::slice(ptr, bytes), allocator) {}
2364 
2365  template <class CHAR, class T, class A>
2367  buffer(const ::std::basic_string<CHAR, T, A> &str,
2368  const allocator_type &allocator = allocator_type())
2369  : buffer(::mdbx::slice(str), allocator) {}
2370 
2372  buffer(const char *c_str, const allocator_type &allocator = allocator_type())
2373  : buffer(::mdbx::slice(c_str), allocator) {}
2374 
2375 #if defined(DOXYGEN) || \
2376  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2377  template <class CHAR, class T>
2379  buffer(const ::std::basic_string_view<CHAR, T> &view,
2380  const allocator_type &allocator = allocator_type())
2381  : buffer(::mdbx::slice(view), allocator) {}
2382 #endif /* __cpp_lib_string_view >= 201606L */
2383 
2384  buffer(size_t head_room, size_t tail_room,
2385  const allocator_type &allocator = allocator_type())
2386  : silo_(allocator) {
2387  slice_.iov_base = silo_.init(check_length(head_room, tail_room));
2388  assert(slice_.iov_len == 0);
2389  }
2390 
2391  buffer(size_t capacity, const allocator_type &allocator = allocator_type())
2392  : silo_(allocator) {
2393  slice_.iov_base = silo_.init(check_length(capacity));
2394  assert(slice_.iov_len == 0);
2395  }
2396 
2397  buffer(size_t head_room, const struct slice &src, size_t tail_room,
2398  const allocator_type &allocator = allocator_type())
2399  : silo_(allocator) {
2400  slice_.iov_base =
2401  silo_.init(check_length(head_room, src.length(), tail_room));
2402  slice_.iov_len = src.length();
2403  memcpy(slice_.iov_base, src.data(), src.length());
2404  }
2405 
2406  buffer(size_t head_room, const buffer &src, size_t tail_room,
2407  const allocator_type &allocator = allocator_type())
2408  : buffer(head_room, src.slice_, tail_room, allocator) {}
2409 
2410  inline buffer(const ::mdbx::txn &txn, const struct slice &src,
2411  const allocator_type &allocator = allocator_type());
2412 
2413  buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
2414  : silo_(::std::move(src.silo_)), slice_(::std::move(src.slice_)) {}
2415 
2416  MDBX_CXX11_CONSTEXPR const struct slice &slice() const noexcept {
2417  return slice_;
2418  }
2419 
2420  MDBX_CXX11_CONSTEXPR operator const struct slice &() const noexcept {
2421  return slice_;
2422  }
2423 
2424 #if defined(DOXYGEN) || (defined(__cpp_lib_span) && __cpp_lib_span >= 202002L)
2425  template <typename POD>
2426  MDBX_CXX14_CONSTEXPR buffer(const ::std::span<POD> &span)
2427  : buffer(span.begin(), span.end()) {
2428  static_assert(::std::is_standard_layout<POD>::value &&
2429  !::std::is_pointer<POD>::value,
2430  "Must be a standard layout type!");
2431  }
2432 
2433  template <typename POD>
2434  MDBX_CXX14_CONSTEXPR ::std::span<const POD> as_span() const {
2435  return slice_.template as_span<const POD>();
2436  }
2437  template <typename POD> MDBX_CXX14_CONSTEXPR ::std::span<POD> as_span() {
2438  return slice_.template as_span<POD>();
2439  }
2440 
2441  MDBX_CXX14_CONSTEXPR ::std::span<const byte> bytes() const {
2442  return as_span<const byte>();
2443  }
2444  MDBX_CXX14_CONSTEXPR ::std::span<byte> bytes() { return as_span<byte>(); }
2445  MDBX_CXX14_CONSTEXPR ::std::span<const char> chars() const {
2446  return as_span<const char>();
2447  }
2448  MDBX_CXX14_CONSTEXPR ::std::span<char> chars() { return as_span<char>(); }
2449 #endif /* __cpp_lib_span >= 202002L */
2450 
2451  template <typename POD>
2452  static buffer wrap(const POD &pod, bool make_reference = false,
2453  const allocator_type &allocator = allocator_type()) {
2454  return buffer(::mdbx::slice::wrap(pod), make_reference, allocator);
2455  }
2456 
2457  template <typename POD> MDBX_CXX14_CONSTEXPR POD as_pod() const {
2458  return slice_.as_pod<POD>();
2459  }
2460 
2461 #ifdef MDBX_U128_TYPE
2462  MDBX_CXX14_CONSTEXPR MDBX_U128_TYPE as_uint128() const {
2463  return slice().as_uint128();
2464  }
2465 #endif /* MDBX_U128_TYPE */
2466  MDBX_CXX14_CONSTEXPR uint64_t as_uint64() const {
2467  return slice().as_uint64();
2468  }
2469  MDBX_CXX14_CONSTEXPR uint32_t as_uint32() const {
2470  return slice().as_uint32();
2471  }
2472  MDBX_CXX14_CONSTEXPR uint16_t as_uint16() const {
2473  return slice().as_uint16();
2474  }
2475  MDBX_CXX14_CONSTEXPR uint8_t as_uint8() const { return slice().as_uint8(); }
2476 
2477 #ifdef MDBX_I128_TYPE
2478  MDBX_CXX14_CONSTEXPR MDBX_I128_TYPE as_int128() const {
2479  return slice().as_int128();
2480  }
2481 #endif /* MDBX_I128_TYPE */
2482  MDBX_CXX14_CONSTEXPR int64_t as_int64() const { return slice().as_int64(); }
2483  MDBX_CXX14_CONSTEXPR int32_t as_int32() const { return slice().as_int32(); }
2484  MDBX_CXX14_CONSTEXPR int16_t as_int16() const { return slice().as_int16(); }
2485  MDBX_CXX14_CONSTEXPR int8_t as_int8() const { return slice().as_int8(); }
2486 
2487 #ifdef MDBX_U128_TYPE
2488  MDBX_U128_TYPE as_uint128_adapt() const { return slice().as_uint128_adapt(); }
2489 #endif /* MDBX_U128_TYPE */
2490  uint64_t as_uint64_adapt() const { return slice().as_uint64_adapt(); }
2491  uint32_t as_uint32_adapt() const { return slice().as_uint32_adapt(); }
2492  uint16_t as_uint16_adapt() const { return slice().as_uint16_adapt(); }
2493  uint8_t as_uint8_adapt() const { return slice().as_uint8_adapt(); }
2494 
2495 #ifdef MDBX_I128_TYPE
2496  MDBX_I128_TYPE as_int128_adapt() const { return slice().as_int128_adapt(); }
2497 #endif /* MDBX_I128_TYPE */
2498  int64_t as_int64_adapt() const { return slice().as_int64_adapt(); }
2499  int32_t as_int32_adapt() const { return slice().as_int32_adapt(); }
2500  int16_t as_int16_adapt() const { return slice().as_int16_adapt(); }
2501  int8_t as_int8_adapt() const { return slice().as_int8_adapt(); }
2502 
2504  static buffer hex(const ::mdbx::slice &source, bool uppercase = false,
2505  unsigned wrap_width = 0,
2506  const allocator_type &allocator = allocator_type()) {
2507  return source.template encode_hex<ALLOCATOR, CAPACITY_POLICY>(
2508  uppercase, wrap_width, allocator);
2509  }
2510 
2513  static buffer base58(const ::mdbx::slice &source, unsigned wrap_width = 0,
2514  const allocator_type &allocator = allocator_type()) {
2515  return source.template encode_base58<ALLOCATOR, CAPACITY_POLICY>(wrap_width,
2516  allocator);
2517  }
2520  static buffer base64(const ::mdbx::slice &source, unsigned wrap_width = 0,
2521  const allocator_type &allocator = allocator_type()) {
2522  return source.template encode_base64<ALLOCATOR, CAPACITY_POLICY>(wrap_width,
2523  allocator);
2524  }
2525 
2527  template <typename POD>
2528  static buffer hex(const POD &pod, bool uppercase = false,
2529  unsigned wrap_width = 0,
2530  const allocator_type &allocator = allocator_type()) {
2531  return hex(mdbx::slice::wrap(pod), uppercase, wrap_width, allocator);
2532  }
2533 
2536  template <typename POD>
2537  static buffer base58(const POD &pod, unsigned wrap_width = 0,
2538  const allocator_type &allocator = allocator_type()) {
2539  return base58(mdbx::slice::wrap(pod), wrap_width, allocator);
2540  }
2541 
2544  template <typename POD>
2545  static buffer base64(const POD &pod, unsigned wrap_width = 0,
2546  const allocator_type &allocator = allocator_type()) {
2547  return base64(mdbx::slice::wrap(pod), wrap_width, allocator);
2548  }
2549 
2551  buffer encode_hex(bool uppercase = false, unsigned wrap_width = 0,
2552  const allocator_type &allocator = allocator_type()) const {
2553  return slice().template encode_hex<ALLOCATOR, CAPACITY_POLICY>(
2554  uppercase, wrap_width, allocator);
2555  }
2556 
2559  buffer
2560  encode_base58(unsigned wrap_width = 0,
2561  const allocator_type &allocator = allocator_type()) const {
2562  return slice().template encode_base58<ALLOCATOR, CAPACITY_POLICY>(
2563  wrap_width, allocator);
2564  }
2567  buffer
2568  encode_base64(unsigned wrap_width = 0,
2569  const allocator_type &allocator = allocator_type()) const {
2570  return slice().template encode_base64<ALLOCATOR, CAPACITY_POLICY>(
2571  wrap_width, allocator);
2572  }
2573 
2575  static buffer hex_decode(const ::mdbx::slice &source,
2576  bool ignore_spaces = false,
2577  const allocator_type &allocator = allocator_type()) {
2578  return source.template hex_decode<ALLOCATOR, CAPACITY_POLICY>(ignore_spaces,
2579  allocator);
2580  }
2581 
2584  static buffer
2585  base58_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2586  const allocator_type &allocator = allocator_type()) {
2587  return source.template base58_decode<ALLOCATOR, CAPACITY_POLICY>(
2588  ignore_spaces, allocator);
2589  }
2590 
2593  static buffer
2594  base64_decode(const ::mdbx::slice &source, bool ignore_spaces = false,
2595  const allocator_type &allocator = allocator_type()) {
2596  return source.template base64_decode<ALLOCATOR, CAPACITY_POLICY>(
2597  ignore_spaces, allocator);
2598  }
2599 
2602  buffer hex_decode(bool ignore_spaces = false,
2603  const allocator_type &allocator = allocator_type()) const {
2604  return hex_decode(slice(), ignore_spaces, allocator);
2605  }
2606 
2609  buffer
2610  base58_decode(bool ignore_spaces = false,
2611  const allocator_type &allocator = allocator_type()) const {
2612  return base58_decode(slice(), ignore_spaces, allocator);
2613  }
2614 
2617  buffer
2618  base64_decode(bool ignore_spaces = false,
2619  const allocator_type &allocator = allocator_type()) const {
2620  return base64_decode(slice(), ignore_spaces, allocator);
2621  }
2622 
2624  void reserve(size_t wanna_headroom, size_t wanna_tailroom) {
2625  wanna_headroom = ::std::min(::std::max(headroom(), wanna_headroom),
2626  wanna_headroom + pettiness_threshold);
2627  wanna_tailroom = ::std::min(::std::max(tailroom(), wanna_tailroom),
2628  wanna_tailroom + pettiness_threshold);
2629  const size_t wanna_capacity =
2630  check_length(wanna_headroom, slice_.length(), wanna_tailroom);
2631  silo_.resize(wanna_capacity, wanna_headroom, slice_);
2632  assert(headroom() >= wanna_headroom &&
2633  headroom() <= wanna_headroom + pettiness_threshold);
2634  assert(tailroom() >= wanna_tailroom &&
2635  tailroom() <= wanna_tailroom + pettiness_threshold);
2636  }
2637 
2639  void reserve_headroom(size_t wanna_headroom) { reserve(wanna_headroom, 0); }
2640 
2642  void reserve_tailroom(size_t wanna_tailroom) { reserve(0, wanna_tailroom); }
2643 
2644  buffer &assign_reference(const void *ptr, size_t bytes) {
2645  silo_.clear();
2646  slice_.assign(ptr, bytes);
2647  return *this;
2648  }
2649 
2650  buffer &assign_freestanding(const void *ptr, size_t bytes) {
2651  silo_.assign(static_cast<const typename silo::value_type *>(ptr),
2652  check_length(bytes));
2653  slice_.assign(silo_.data(), bytes);
2654  return *this;
2655  }
2656 
2658  swap(buffer &other) noexcept(swap_alloc::is_nothrow()) {
2659  silo_.swap(other.silo_);
2660  slice_.swap(other.slice_);
2661  }
2662 
2663  static buffer clone(const buffer &src,
2664  const allocator_type &allocator = allocator_type()) {
2665  return buffer(src.headroom(), src.slice_, src.tailroom(), allocator);
2666  }
2667 
2668  buffer &assign(const buffer &src, bool make_reference = false) {
2669  return assign(src.slice_, make_reference);
2670  }
2671 
2672  buffer &assign(const void *ptr, size_t bytes, bool make_reference = false) {
2673  return make_reference ? assign_reference(ptr, bytes)
2674  : assign_freestanding(ptr, bytes);
2675  }
2676 
2677  buffer &assign(const struct slice &src, bool make_reference = false) {
2678  return assign(src.data(), src.length(), make_reference);
2679  }
2680 
2681  buffer &assign(const ::MDBX_val &src, bool make_reference = false) {
2682  return assign(src.iov_base, src.iov_len, make_reference);
2683  }
2684 
2685  buffer &assign(struct slice &&src, bool make_reference = false) {
2686  assign(src.data(), src.length(), make_reference);
2687  src.invalidate();
2688  return *this;
2689  }
2690 
2691  buffer &assign(::MDBX_val &&src, bool make_reference = false) {
2692  assign(src.iov_base, src.iov_len, make_reference);
2693  src.iov_base = nullptr;
2694  return *this;
2695  }
2696 
2697  buffer &assign(const void *begin, const void *end,
2698  bool make_reference = false) {
2699  return assign(begin,
2700  static_cast<const byte *>(end) -
2701  static_cast<const byte *>(begin),
2702  make_reference);
2703  }
2704 
2705  template <class CHAR, class T, class A>
2706  buffer &assign(const ::std::basic_string<CHAR, T, A> &str,
2707  bool make_reference = false) {
2708  return assign(str.data(), str.length(), make_reference);
2709  }
2710 
2711  buffer &assign(const char *c_str, bool make_reference = false) {
2712  return assign(c_str, ::mdbx::strlen(c_str), make_reference);
2713  }
2714 
2715 #if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
2716  template <class CHAR, class T>
2717  buffer &assign(const ::std::basic_string_view<CHAR, T> &view,
2718  bool make_reference = false) {
2719  return assign(view.data(), view.length(), make_reference);
2720  }
2721 
2722  template <class CHAR, class T>
2723  buffer &assign(::std::basic_string_view<CHAR, T> &&view,
2724  bool make_reference = false) {
2725  assign(view.data(), view.length(), make_reference);
2726  view = {};
2727  return *this;
2728  }
2729 #endif /* __cpp_lib_string_view >= 201606L */
2730 
2731  buffer &operator=(const buffer &src) { return assign(src); }
2732 
2733  buffer &operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow()) {
2734  return assign(::std::move(src));
2735  }
2736 
2737  buffer &operator=(const struct slice &src) { return assign(src); }
2738 
2739  buffer &operator=(struct slice &&src) { return assign(::std::move(src)); }
2740 
2741 #if defined(DOXYGEN) || \
2742  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
2743  template <class CHAR, class T>
2744  buffer &operator=(const ::std::basic_string_view<CHAR, T> &view) noexcept {
2745  return assign(view);
2746  }
2747 
2749  template <class CHAR = char, class T = ::std::char_traits<CHAR>>
2750  ::std::basic_string_view<CHAR, T> string_view() const noexcept {
2751  return slice_.string_view<CHAR, T>();
2752  }
2753 
2755  template <class CHAR, class T>
2756  operator ::std::basic_string_view<CHAR, T>() const noexcept {
2757  return string_view<CHAR, T>();
2758  }
2759 #endif /* __cpp_lib_string_view >= 201606L */
2760 
2763  return length() == 0;
2764  }
2765 
2767  MDBX_CXX11_CONSTEXPR bool is_null() const noexcept {
2768  return data() == nullptr;
2769  }
2770 
2773  return length();
2774  }
2775 
2781  hash_value() const noexcept {
2782  return slice_.hash_value();
2783  }
2784 
2785  template <class CHAR = char, class T = ::std::char_traits<CHAR>,
2786  class A = legacy_allocator>
2787  MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, A>
2788  as_string(const A &allocator = A()) const {
2789  return slice_.as_string<CHAR, T, A>(allocator);
2790  }
2791 
2792  template <class CHAR, class T, class A>
2793  MDBX_CXX20_CONSTEXPR explicit
2794  operator ::std::basic_string<CHAR, T, A>() const {
2795  return as_string<CHAR, T, A>();
2796  }
2797 
2800  starts_with(const struct slice &prefix) const noexcept {
2801  return slice_.starts_with(prefix);
2802  }
2803 
2806  ends_with(const struct slice &suffix) const noexcept {
2807  return slice_.ends_with(suffix);
2808  }
2809 
2811  void clear() noexcept { slice_.assign(silo_.clear(), size_t(0)); }
2812 
2814  void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept {
2815  slice_.assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0));
2816  }
2817 
2819  void shrink_to_fit() { reserve(0, 0); }
2820 
2823  void remove_prefix(size_t n) noexcept { slice_.remove_prefix(n); }
2824 
2827  void remove_suffix(size_t n) noexcept { slice_.remove_suffix(n); }
2828 
2831  void safe_remove_prefix(size_t n) { slice_.safe_remove_prefix(n); }
2832 
2835  void safe_remove_suffix(size_t n) { slice_.safe_remove_suffix(n); }
2836 
2839  MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept {
2840  MDBX_CONSTEXPR_ASSERT(n < size());
2841  return slice_[n];
2842  }
2843 
2846  MDBX_CXX11_CONSTEXPR byte &operator[](size_t n) noexcept {
2847  MDBX_CONSTEXPR_ASSERT(n < size());
2848  return byte_ptr()[n];
2849  }
2850 
2853  MDBX_CXX14_CONSTEXPR byte at(size_t n) const { return slice_.at(n); }
2854 
2857  MDBX_CXX14_CONSTEXPR byte &at(size_t n) {
2858  if (MDBX_UNLIKELY(n >= size()))
2859  MDBX_CXX20_UNLIKELY throw_out_range();
2860  return byte_ptr()[n];
2861  }
2862 
2865  MDBX_CXX14_CONSTEXPR struct slice head(size_t n) const noexcept {
2866  return slice_.head(n);
2867  }
2868 
2871  MDBX_CXX14_CONSTEXPR struct slice tail(size_t n) const noexcept {
2872  return slice_.tail(n);
2873  }
2874 
2877  MDBX_CXX14_CONSTEXPR struct slice middle(size_t from,
2878  size_t n) const noexcept {
2879  return slice_.middle(from, n);
2880  }
2881 
2884  MDBX_CXX14_CONSTEXPR struct slice safe_head(size_t n) const {
2885  return slice_.safe_head(n);
2886  }
2887 
2890  MDBX_CXX14_CONSTEXPR struct slice safe_tail(size_t n) const {
2891  return slice_.safe_tail(n);
2892  }
2893 
2896  MDBX_CXX14_CONSTEXPR struct slice safe_middle(size_t from, size_t n) const {
2897  return slice_.safe_middle(from, n);
2898  }
2899 
2900  buffer &append(const void *src, size_t bytes) {
2901  if (MDBX_UNLIKELY(tailroom() < check_length(bytes)))
2902  MDBX_CXX20_UNLIKELY reserve_tailroom(bytes);
2903  memcpy(slice_.byte_ptr() + size(), src, bytes);
2904  slice_.iov_len += bytes;
2905  return *this;
2906  }
2907 
2908  buffer &append(const struct slice &chunk) {
2909  return append(chunk.data(), chunk.size());
2910  }
2911 
2912  buffer &add_header(const void *src, size_t bytes) {
2913  if (MDBX_UNLIKELY(headroom() < check_length(bytes)))
2914  MDBX_CXX20_UNLIKELY reserve_headroom(bytes);
2915  slice_.iov_base =
2916  memcpy(static_cast<char *>(slice_.iov_base) - bytes, src, bytes);
2917  slice_.iov_len += bytes;
2918  return *this;
2919  }
2920 
2921  buffer &add_header(const struct slice &chunk) {
2922  return add_header(chunk.data(), chunk.size());
2923  }
2924 
2925  template <MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
2926  buffer &append_producer(PRODUCER &producer) {
2927  const size_t wanna_bytes = producer.envisage_result_length();
2928  if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2929  MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2930  return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2931  }
2932 
2933  template <MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
2934  buffer &append_producer(const PRODUCER &producer) {
2935  const size_t wanna_bytes = producer.envisage_result_length();
2936  if (MDBX_UNLIKELY(tailroom() < check_length(wanna_bytes)))
2937  MDBX_CXX20_UNLIKELY reserve_tailroom(wanna_bytes);
2938  return set_end(producer.write_bytes(end_char_ptr(), tailroom()));
2939  }
2940 
2941  buffer &append_hex(const struct slice &data, bool uppercase = false,
2942  unsigned wrap_width = 0) {
2943  return append_producer(to_hex(data, uppercase, wrap_width));
2944  }
2945 
2946  buffer &append_base58(const struct slice &data, unsigned wrap_width = 0) {
2947  return append_producer(to_base58(data, wrap_width));
2948  }
2949 
2950  buffer &append_base64(const struct slice &data, unsigned wrap_width = 0) {
2951  return append_producer(to_base64(data, wrap_width));
2952  }
2953 
2954  buffer &append_decoded_hex(const struct slice &data,
2955  bool ignore_spaces = false) {
2956  return append_producer(from_hex(data, ignore_spaces));
2957  }
2958 
2959  buffer &append_decoded_base58(const struct slice &data,
2960  bool ignore_spaces = false) {
2961  return append_producer(from_base58(data, ignore_spaces));
2962  }
2963 
2964  buffer &append_decoded_base64(const struct slice &data,
2965  bool ignore_spaces = false) {
2966  return append_producer(from_base64(data, ignore_spaces));
2967  }
2968 
2969  buffer &append_u8(uint_fast8_t u8) {
2970  if (MDBX_UNLIKELY(tailroom() < 1))
2971  MDBX_CXX20_UNLIKELY reserve_tailroom(1);
2972  *slice_.byte_ptr() = u8;
2973  slice_.iov_len += 1;
2974  return *this;
2975  }
2976 
2977  buffer &append_byte(uint_fast8_t byte) { return append_u8(byte); }
2978 
2979  buffer &append_u16(uint_fast16_t u16) {
2980  if (MDBX_UNLIKELY(tailroom() < 2))
2981  MDBX_CXX20_UNLIKELY reserve_tailroom(2);
2982  const auto ptr = slice_.byte_ptr();
2983  ptr[0] = uint8_t(u16);
2984  ptr[1] = uint8_t(u16 >> 8);
2985  slice_.iov_len += 2;
2986  return *this;
2987  }
2988 
2989  buffer &append_u24(uint_fast32_t u24) {
2990  if (MDBX_UNLIKELY(tailroom() < 3))
2991  MDBX_CXX20_UNLIKELY reserve_tailroom(3);
2992  const auto ptr = slice_.byte_ptr();
2993  ptr[0] = uint8_t(u24);
2994  ptr[1] = uint8_t(u24 >> 8);
2995  ptr[2] = uint8_t(u24 >> 16);
2996  slice_.iov_len += 3;
2997  return *this;
2998  }
2999 
3000  buffer &append_u32(uint_fast32_t u32) {
3001  if (MDBX_UNLIKELY(tailroom() < 4))
3002  MDBX_CXX20_UNLIKELY reserve_tailroom(4);
3003  const auto ptr = slice_.byte_ptr();
3004  ptr[0] = uint8_t(u32);
3005  ptr[1] = uint8_t(u32 >> 8);
3006  ptr[2] = uint8_t(u32 >> 16);
3007  ptr[3] = uint8_t(u32 >> 24);
3008  slice_.iov_len += 4;
3009  return *this;
3010  }
3011 
3012  buffer &append_u48(uint_fast64_t u48) {
3013  if (MDBX_UNLIKELY(tailroom() < 6))
3014  MDBX_CXX20_UNLIKELY reserve_tailroom(6);
3015  const auto ptr = slice_.byte_ptr();
3016  ptr[0] = uint8_t(u48);
3017  ptr[1] = uint8_t(u48 >> 8);
3018  ptr[2] = uint8_t(u48 >> 16);
3019  ptr[3] = uint8_t(u48 >> 24);
3020  ptr[4] = uint8_t(u48 >> 32);
3021  ptr[5] = uint8_t(u48 >> 40);
3022  slice_.iov_len += 6;
3023  return *this;
3024  }
3025 
3026  buffer &append_u64(uint_fast64_t u64) {
3027  if (MDBX_UNLIKELY(tailroom() < 8))
3028  MDBX_CXX20_UNLIKELY reserve_tailroom(8);
3029  const auto ptr = slice_.byte_ptr();
3030  ptr[0] = uint8_t(u64);
3031  ptr[1] = uint8_t(u64 >> 8);
3032  ptr[2] = uint8_t(u64 >> 16);
3033  ptr[3] = uint8_t(u64 >> 24);
3034  ptr[4] = uint8_t(u64 >> 32);
3035  ptr[5] = uint8_t(u64 >> 40);
3036  ptr[6] = uint8_t(u64 >> 48);
3037  ptr[7] = uint8_t(u64 >> 56);
3038  slice_.iov_len += 8;
3039  return *this;
3040  }
3041 
3042  //----------------------------------------------------------------------------
3043 
3044  template <size_t SIZE>
3045  static buffer key_from(const char (&text)[SIZE], bool make_reference = true) {
3046  return buffer(::mdbx::slice(text), make_reference);
3047  }
3048 
3049 #if defined(DOXYGEN) || \
3050  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
3051  template <class CHAR, class T>
3052  static buffer key_from(const ::std::basic_string_view<CHAR, T> &src,
3053  bool make_reference = false) {
3054  return buffer(src, make_reference);
3055  }
3056 #endif /* __cpp_lib_string_view >= 201606L */
3057 
3058  static buffer key_from(const char *src, bool make_reference = false) {
3059  return buffer(src, make_reference);
3060  }
3061 
3062  template <class CHAR, class T, class A>
3063  static buffer key_from(const ::std::basic_string<CHAR, T, A> &src,
3064  bool make_reference = false) {
3065  return buffer(src, make_reference);
3066  }
3067 
3068  static buffer key_from(silo &&src) noexcept {
3069  return buffer(::std::move(src));
3070  }
3071 
3072  static buffer key_from_double(const double ieee754_64bit) {
3073  return wrap(::mdbx_key_from_double(ieee754_64bit));
3074  }
3075 
3076  static buffer key_from(const double ieee754_64bit) {
3077  return key_from_double(ieee754_64bit);
3078  }
3079 
3080  static buffer key_from(const double *ieee754_64bit) {
3081  return wrap(::mdbx_key_from_ptrdouble(ieee754_64bit));
3082  }
3083 
3084  static buffer key_from_u64(const uint64_t unsigned_int64) {
3085  return wrap(unsigned_int64);
3086  }
3087 
3088  static buffer key_from(const uint64_t unsigned_int64) {
3089  return key_from_u64(unsigned_int64);
3090  }
3091 
3092  static buffer key_from_i64(const int64_t signed_int64) {
3093  return wrap(::mdbx_key_from_int64(signed_int64));
3094  }
3095 
3096  static buffer key_from(const int64_t signed_int64) {
3097  return key_from_i64(signed_int64);
3098  }
3099 
3100  static buffer key_from_jsonInteger(const int64_t json_integer) {
3101  return wrap(::mdbx_key_from_jsonInteger(json_integer));
3102  }
3103 
3104  static buffer key_from_float(const float ieee754_32bit) {
3105  return wrap(::mdbx_key_from_float(ieee754_32bit));
3106  }
3107 
3108  static buffer key_from(const float ieee754_32bit) {
3109  return key_from_float(ieee754_32bit);
3110  }
3111 
3112  static buffer key_from(const float *ieee754_32bit) {
3113  return wrap(::mdbx_key_from_ptrfloat(ieee754_32bit));
3114  }
3115 
3116  static buffer key_from_u32(const uint32_t unsigned_int32) {
3117  return wrap(unsigned_int32);
3118  }
3119 
3120  static buffer key_from(const uint32_t unsigned_int32) {
3121  return key_from_u32(unsigned_int32);
3122  }
3123 
3124  static buffer key_from_i32(const int32_t signed_int32) {
3125  return wrap(::mdbx_key_from_int32(signed_int32));
3126  }
3127 
3128  static buffer key_from(const int32_t signed_int32) {
3129  return key_from_i32(signed_int32);
3130  }
3131 };
3132 
3133 template <class ALLOCATOR, class CAPACITY_POLICY,
3134  MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
3135 inline buffer<ALLOCATOR, CAPACITY_POLICY>
3136 make_buffer(PRODUCER &producer, const ALLOCATOR &allocator) {
3137  if (MDBX_LIKELY(!producer.is_empty()))
3140  producer.envisage_result_length(), allocator);
3141  result.set_end(
3142  producer.write_bytes(result.end_char_ptr(), result.tailroom()));
3143  return result;
3144  }
3145  return buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
3146 }
3147 
3148 template <class ALLOCATOR, class CAPACITY_POLICY,
3149  MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
3150 inline buffer<ALLOCATOR, CAPACITY_POLICY>
3151 make_buffer(const PRODUCER &producer, const ALLOCATOR &allocator) {
3152  if (MDBX_LIKELY(!producer.is_empty()))
3155  producer.envisage_result_length(), allocator);
3156  result.set_end(
3157  producer.write_bytes(result.end_char_ptr(), result.tailroom()));
3158  return result;
3159  }
3160  return buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
3161 }
3162 
3163 template <class ALLOCATOR, MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
3164 inline string<ALLOCATOR> make_string(PRODUCER &producer,
3165  const ALLOCATOR &allocator) {
3166  string<ALLOCATOR> result(allocator);
3167  if (MDBX_LIKELY(!producer.is_empty()))
3169  result.resize(producer.envisage_result_length());
3170  result.resize(producer.write_bytes(const_cast<char *>(result.data()),
3171  result.capacity()) -
3172  result.data());
3173  }
3174  return result;
3175 }
3176 
3177 template <class ALLOCATOR, MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
3178 inline string<ALLOCATOR> make_string(const PRODUCER &producer,
3179  const ALLOCATOR &allocator) {
3180  string<ALLOCATOR> result(allocator);
3181  if (MDBX_LIKELY(!producer.is_empty()))
3183  result.resize(producer.envisage_result_length());
3184  result.resize(producer.write_bytes(const_cast<char *>(result.data()),
3185  result.capacity()) -
3186  result.data());
3187  }
3188  return result;
3189 }
3190 
3195  bool done;
3196  value_result(const slice &value, bool done) noexcept
3197  : value(value), done(done) {}
3198  value_result(const value_result &) noexcept = default;
3199  value_result &operator=(const value_result &) noexcept = default;
3200  MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
3201  assert(!done || bool(value));
3202  return done;
3203  }
3204 };
3205 
3208 struct pair {
3209  using stl_pair = std::pair<slice, slice>;
3210  slice key, value;
3211  MDBX_CXX11_CONSTEXPR pair(const slice &key, const slice &value) noexcept
3212  : key(key), value(value) {}
3213  MDBX_CXX11_CONSTEXPR pair(const stl_pair &couple) noexcept
3214  : key(couple.first), value(couple.second) {}
3215  MDBX_CXX11_CONSTEXPR operator stl_pair() const noexcept {
3216  return stl_pair(key, value);
3217  }
3218  pair(const pair &) noexcept = default;
3219  pair &operator=(const pair &) noexcept = default;
3220  MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
3221  assert(bool(key) == bool(value));
3222  return key;
3223  }
3224  MDBX_CXX14_CONSTEXPR static pair invalid() noexcept {
3225  return pair(slice::invalid(), slice::invalid());
3226  }
3227 
3230  compare_fast(const pair &a, const pair &b) noexcept;
3231 
3234  compare_lexicographically(const pair &a, const pair &b) noexcept;
3235  friend MDBX_CXX14_CONSTEXPR bool operator==(const pair &a,
3236  const pair &b) noexcept;
3237  friend MDBX_CXX14_CONSTEXPR bool operator<(const pair &a,
3238  const pair &b) noexcept;
3239  friend MDBX_CXX14_CONSTEXPR bool operator>(const pair &a,
3240  const pair &b) noexcept;
3241  friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a,
3242  const pair &b) noexcept;
3243  friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a,
3244  const pair &b) noexcept;
3245  friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a,
3246  const pair &b) noexcept;
3247 };
3248 
3251 struct pair_result : public pair {
3252  bool done;
3254  : pair(pair::invalid()), done(false) {}
3255  MDBX_CXX11_CONSTEXPR pair_result(const slice &key, const slice &value,
3256  bool done) noexcept
3257  : pair(key, value), done(done) {}
3258  pair_result(const pair_result &) noexcept = default;
3259  pair_result &operator=(const pair_result &) noexcept = default;
3260  MDBX_CXX14_CONSTEXPR operator bool() const noexcept {
3261  assert(!done || (bool(key) && bool(value)));
3262  return done;
3263  }
3264 };
3265 
3266 template <typename ALLOCATOR, typename CAPACITY_POLICY>
3271  using reservation_policy = CAPACITY_POLICY;
3272  using stl_pair = ::std::pair<buffer_type, buffer_type>;
3274 
3277  buffer_pair_spec(const allocator_type &allocator) noexcept
3278  : key(allocator), value(allocator) {}
3279 
3280  buffer_pair_spec(const buffer_type &key, const buffer_type &value,
3281  const allocator_type &allocator = allocator_type())
3282  : key(key, allocator), value(value, allocator) {}
3283  buffer_pair_spec(const buffer_type &key, const buffer_type &value,
3284  bool make_reference,
3285  const allocator_type &allocator = allocator_type())
3286  : key(key, make_reference, allocator),
3287  value(value, make_reference, allocator) {}
3288 
3290  const allocator_type &allocator = allocator_type())
3291  : buffer_pair_spec(pair.first, pair.second, allocator) {}
3292  buffer_pair_spec(const stl_pair &pair, bool make_reference,
3293  const allocator_type &allocator = allocator_type())
3294  : buffer_pair_spec(pair.first, pair.second, make_reference, allocator) {}
3295 
3296  buffer_pair_spec(const slice &key, const slice &value,
3297  const allocator_type &allocator = allocator_type())
3298  : key(key, allocator), value(value, allocator) {}
3299  buffer_pair_spec(const slice &key, const slice &value, bool make_reference,
3300  const allocator_type &allocator = allocator_type())
3301  : key(key, make_reference, allocator),
3302  value(value, make_reference, allocator) {}
3303 
3305  const allocator_type &allocator = allocator_type())
3306  : buffer_pair_spec(pair.key, pair.value, allocator) {}
3307  buffer_pair_spec(const pair &pair, bool make_reference,
3308  const allocator_type &allocator = allocator_type())
3309  : buffer_pair_spec(pair.key, pair.value, make_reference, allocator) {}
3310 
3311  buffer_pair_spec(const txn &txn, const slice &key, const slice &value,
3312  const allocator_type &allocator = allocator_type())
3313  : key(txn, key, allocator), value(txn, value, allocator) {}
3315  const allocator_type &allocator = allocator_type())
3316  : buffer_pair_spec(txn, pair.key, pair.value, allocator) {}
3317 
3318  buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(
3319  buffer_type::move_assign_alloc::is_nothrow())
3320  : key(::std::move(key)), value(::std::move(value)) {}
3322  buffer_type::move_assign_alloc::is_nothrow())
3323  : buffer_pair_spec(::std::move(pair.key), ::std::move(pair.value)) {}
3324 
3328  is_freestanding() const noexcept {
3329  return key.is_freestanding() && value.is_freestanding();
3330  }
3334  is_reference() const noexcept {
3335  return key.is_reference() || value.is_reference();
3336  }
3341  key.make_freestanding();
3342  value.make_freestanding();
3343  }
3344 
3345  operator pair() const noexcept { return pair(key, value); }
3346 };
3347 
3348 template <typename BUFFER>
3349 using buffer_pair = buffer_pair_spec<typename BUFFER::allocator_type,
3350  typename BUFFER::reservation_policy>;
3351 
3353 
3354 //------------------------------------------------------------------------------
3355 
3358 enum loop_control { continue_loop = 0, exit_loop = INT32_MIN };
3359 
3361 enum class key_mode {
3372  msgpack = -1
3375 };
3376 
3378  return (MDBX_db_flags_t(mode) & (MDBX_REVERSEKEY | MDBX_INTEGERKEY)) == 0;
3379 }
3380 
3382  return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
3383 }
3384 
3386  return (MDBX_db_flags_t(mode) & MDBX_INTEGERKEY) != 0;
3387 }
3388 
3390  return (MDBX_db_flags_t(mode) & MDBX_REVERSEKEY) != 0;
3391 }
3392 
3394  return mode == key_mode::msgpack;
3395 }
3396 
3399 enum class value_mode {
3402  multi =
3403  MDBX_DUPSORT,
3409 #if CONSTEXPR_ENUM_FLAGS_OPERATIONS || defined(DOXYGEN)
3410  multi_reverse =
3411  MDBX_DUPSORT |
3412  MDBX_REVERSEDUP,
3421  MDBX_DUPSORT |
3422  MDBX_DUPFIXED,
3429  multi_ordinal =
3431  MDBX_INTEGERDUP,
3441  MDBX_DUPFIXED,
3449 #else
3450  multi_reverse = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_REVERSEDUP),
3451  multi_samelength = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_DUPFIXED),
3452  multi_ordinal = uint32_t(MDBX_DUPSORT) | uint32_t(MDBX_DUPFIXED) |
3453  uint32_t(MDBX_INTEGERDUP),
3455  uint32_t(MDBX_REVERSEDUP) |
3456  uint32_t(MDBX_DUPFIXED),
3457 #endif
3458  msgpack = -1
3465 };
3466 
3468  return (MDBX_db_flags_t(mode) & (MDBX_DUPSORT | MDBX_INTEGERDUP |
3469  MDBX_DUPFIXED | MDBX_REVERSEDUP)) == 0;
3470 }
3471 
3473  return (MDBX_db_flags_t(mode) & MDBX_DUPSORT) != 0;
3474 }
3475 
3477  return (MDBX_db_flags_t(mode) & MDBX_INTEGERDUP) != 0;
3478 }
3479 
3481  return (MDBX_db_flags_t(mode) & MDBX_DUPFIXED) != 0;
3482 }
3483 
3485  return (MDBX_db_flags_t(mode) & MDBX_REVERSEDUP) != 0;
3486 }
3487 
3489  return mode == value_mode::msgpack;
3490 }
3491 
3500  MDBX_dbi dbi{0};
3502  MDBX_CXX11_CONSTEXPR map_handle(MDBX_dbi dbi) noexcept : dbi(dbi) {}
3503  map_handle(const map_handle &) noexcept = default;
3504  map_handle &operator=(const map_handle &) noexcept = default;
3505  operator bool() const noexcept { return dbi != 0; }
3506  operator MDBX_dbi() const { return dbi; }
3507 
3514  map_handle::state state) noexcept;
3515  info(const info &) noexcept = default;
3516  info &operator=(const info &) noexcept = default;
3519  };
3520 };
3521 
3523 inline comparator default_comparator(key_mode mode) noexcept {
3524  return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
3525 }
3527  return ::mdbx_get_keycmp(static_cast<MDBX_db_flags_t>(mode));
3528 }
3529 
3531 enum put_mode {
3535 };
3536 
3546  friend class txn;
3547 
3548 protected:
3549  MDBX_env *handle_{nullptr};
3550  MDBX_CXX11_CONSTEXPR env(MDBX_env *ptr) noexcept;
3551 
3552 public:
3553  MDBX_CXX11_CONSTEXPR env() noexcept = default;
3554  env(const env &) noexcept = default;
3555  inline env &operator=(env &&other) noexcept;
3556  inline env(env &&other) noexcept;
3557  inline ~env() noexcept;
3558 
3559  MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
3560  MDBX_CXX14_CONSTEXPR operator const MDBX_env *() const;
3561  MDBX_CXX14_CONSTEXPR operator MDBX_env *();
3562  friend MDBX_CXX11_CONSTEXPR bool operator==(const env &a,
3563  const env &b) noexcept;
3564  friend MDBX_CXX11_CONSTEXPR bool operator!=(const env &a,
3565  const env &b) noexcept;
3566 
3567  //----------------------------------------------------------------------------
3568 
3573 
3575  enum : int64_t {
3576  default_value = -1,
3577  minimal_value = 0,
3578  maximal_value = INTPTR_MAX,
3579  kB = 1000,
3580  MB = kB * 1000,
3581  GB = MB * 1000,
3582  TB = GB * 1000,
3583  PB = TB * 1000,
3584  EB = PB * 1000,
3585  KiB = 1024,
3586  MiB = KiB << 10,
3587  GiB = MiB << 10,
3588  TiB = GiB << 10,
3589  PiB = TiB << 10,
3590  EiB = PiB << 10,
3591  };
3592 
3594  struct size {
3595  intptr_t bytes;
3596  MDBX_CXX11_CONSTEXPR size(intptr_t bytes) noexcept : bytes(bytes) {}
3597  MDBX_CXX11_CONSTEXPR operator intptr_t() const noexcept { return bytes; }
3598  };
3599 
3601  intptr_t size_lower{minimal_value};
3602 
3606  intptr_t size_now{default_value};
3607 
3618  intptr_t size_upper{maximal_value};
3619 
3622  intptr_t growth_step{default_value};
3623 
3626  intptr_t shrink_threshold{default_value};
3627 
3632  intptr_t pagesize{default_value};
3633 
3634  inline geometry &make_fixed(intptr_t size) noexcept;
3635  inline geometry &make_dynamic(intptr_t lower = minimal_value,
3636  intptr_t upper = maximal_value) noexcept;
3639  geometry(const geometry &) noexcept = default;
3640  MDBX_CXX11_CONSTEXPR geometry(intptr_t size_lower,
3641  intptr_t size_now = default_value,
3642  intptr_t size_upper = maximal_value,
3643  intptr_t growth_step = default_value,
3644  intptr_t shrink_threshold = default_value,
3645  intptr_t pagesize = default_value) noexcept
3646  : size_lower(size_lower), size_now(size_now), size_upper(size_upper),
3647  growth_step(growth_step), shrink_threshold(shrink_threshold),
3648  pagesize(pagesize) {}
3649  };
3650 
3652  enum mode {
3654  write_file_io, // don't available on OpenBSD
3655  write_mapped_io
3656  };
3657 
3659  enum durability {
3663  whole_fragile
3664  };
3665 
3669  bool lifo{false};
3671  bool coalesce{false};
3674  reclaiming_options(const reclaiming_options &) noexcept = default;
3676  operator=(const reclaiming_options &) noexcept = default;
3678  };
3679 
3683  bool no_sticky_threads{false};
3686  bool nested_write_transactions{false};
3688  bool exclusive{false};
3690  bool disable_readahead{false};
3692  bool disable_clear_memory{false};
3695  operate_options(const operate_options &) noexcept = default;
3697  operator=(const operate_options &) noexcept = default;
3699  };
3700 
3705  unsigned max_maps{0};
3708  unsigned max_readers{0};
3709  env::mode mode{write_mapped_io};
3710  env::durability durability{robust_synchronous};
3713 
3717  const unsigned max_maps, const unsigned max_readers = 0,
3718  const env::mode mode = env::mode::write_mapped_io,
3719  env::durability durability = env::durability::robust_synchronous,
3720  const env::reclaiming_options &reclaiming = env::reclaiming_options(),
3721  const env::operate_options &options = env::operate_options()) noexcept
3722  : max_maps(max_maps), max_readers(max_readers), mode(mode),
3723  durability(durability), reclaiming(reclaiming), options(options) {}
3725  operate_parameters(const operate_parameters &) noexcept = default;
3727  operator=(const operate_parameters &) noexcept = default;
3729  bool accede = true,
3732  bool use_subdirectory =
3733  false
3734  ) const;
3737  inline static env::reclaiming_options
3738  reclaiming_from_flags(MDBX_env_flags_t flags) noexcept;
3739  inline static env::operate_options
3740  options_from_flags(MDBX_env_flags_t flags) noexcept;
3741  };
3742 
3744  inline env::operate_parameters get_operation_parameters() const;
3746  inline env::mode get_mode() const;
3748  inline env::durability get_durability() const;
3750  inline env::reclaiming_options get_reclaiming() const;
3752  inline env::operate_options get_options() const;
3753 
3756  bool is_pristine() const;
3757 
3759  bool is_empty() const;
3760 
3762  static size_t default_pagesize() noexcept {
3764  }
3765 
3766  struct limits {
3767  limits() = delete;
3769  static inline size_t pagesize_min() noexcept;
3771  static inline size_t pagesize_max() noexcept;
3774  static inline size_t dbsize_min(intptr_t pagesize);
3777  static inline size_t dbsize_max(intptr_t pagesize);
3780  static inline size_t key_min(MDBX_db_flags_t flags) noexcept;
3782  static inline size_t key_min(key_mode mode) noexcept;
3785  static inline size_t key_max(intptr_t pagesize, MDBX_db_flags_t flags);
3788  static inline size_t key_max(intptr_t pagesize, key_mode mode);
3791  static inline size_t key_max(const env &, MDBX_db_flags_t flags);
3794  static inline size_t key_max(const env &, key_mode mode);
3797  static inline size_t value_min(MDBX_db_flags_t flags) noexcept;
3800  static inline size_t value_min(value_mode) noexcept;
3801 
3804  static inline size_t value_max(intptr_t pagesize, MDBX_db_flags_t flags);
3807  static inline size_t value_max(intptr_t pagesize, value_mode);
3810  static inline size_t value_max(const env &, MDBX_db_flags_t flags);
3813  static inline size_t value_max(const env &, value_mode);
3814 
3817  static inline size_t pairsize4page_max(intptr_t pagesize,
3818  MDBX_db_flags_t flags);
3821  static inline size_t pairsize4page_max(intptr_t pagesize, value_mode);
3824  static inline size_t pairsize4page_max(const env &, MDBX_db_flags_t flags);
3827  static inline size_t pairsize4page_max(const env &, value_mode);
3828 
3831  static inline size_t valsize4page_max(intptr_t pagesize,
3832  MDBX_db_flags_t flags);
3835  static inline size_t valsize4page_max(intptr_t pagesize, value_mode);
3838  static inline size_t valsize4page_max(const env &, MDBX_db_flags_t flags);
3841  static inline size_t valsize4page_max(const env &, value_mode);
3842 
3845  static inline size_t transaction_size_max(intptr_t pagesize);
3846  };
3847 
3849  size_t dbsize_min() const { return limits::dbsize_min(this->get_pagesize()); }
3851  size_t dbsize_max() const { return limits::dbsize_max(this->get_pagesize()); }
3853  size_t key_min(key_mode mode) const noexcept { return limits::key_min(mode); }
3855  size_t key_max(key_mode mode) const { return limits::key_max(*this, mode); }
3857  size_t value_min(value_mode mode) const noexcept {
3858  return limits::value_min(mode);
3859  }
3861  size_t value_max(value_mode mode) const {
3862  return limits::value_max(*this, mode);
3863  }
3866  size_t transaction_size_max() const {
3867  return limits::transaction_size_max(this->get_pagesize());
3868  }
3869 
3872 #ifdef MDBX_STD_FILESYSTEM_PATH
3873  env &copy(const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify,
3874  bool force_dynamic_size = false);
3875 #endif /* MDBX_STD_FILESYSTEM_PATH */
3876 #if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3877  env &copy(const ::std::wstring &destination, bool compactify,
3878  bool force_dynamic_size = false);
3879  env &copy(const wchar_t *destination, bool compactify,
3880  bool force_dynamic_size = false);
3881 #endif /* Windows */
3882  env &copy(const ::std::string &destination, bool compactify,
3883  bool force_dynamic_size = false);
3884  env &copy(const char *destination, bool compactify,
3885  bool force_dynamic_size = false);
3886 
3888  env &copy(filehandle fd, bool compactify, bool force_dynamic_size = false);
3889 
3898  just_remove = MDBX_ENV_JUST_DELETE,
3901  ensure_unused = MDBX_ENV_ENSURE_UNUSED,
3904  wait_for_unused = MDBX_ENV_WAIT_FOR_UNUSED
3905  };
3906 
3909 #ifdef MDBX_STD_FILESYSTEM_PATH
3910  static bool remove(const MDBX_STD_FILESYSTEM_PATH &pathname,
3911  const remove_mode mode = just_remove);
3912 #endif /* MDBX_STD_FILESYSTEM_PATH */
3913 #if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
3914  static bool remove(const ::std::wstring &pathname,
3915  const remove_mode mode = just_remove);
3916  static bool remove(const wchar_t *pathname,
3917  const remove_mode mode = just_remove);
3918 #endif /* Windows */
3919  static bool remove(const ::std::string &pathname,
3920  const remove_mode mode = just_remove);
3921  static bool remove(const char *pathname,
3922  const remove_mode mode = just_remove);
3923 
3926 
3929 
3931  inline stat get_stat() const;
3932 
3934  size_t get_pagesize() const { return get_stat().ms_psize; }
3935 
3937  inline info get_info() const;
3938 
3941  inline stat get_stat(const txn &) const;
3942 
3945  inline info get_info(const txn &) const;
3946 
3948  inline filehandle get_filehandle() const;
3949 
3951  path get_path() const;
3952 
3954  inline MDBX_env_flags_t get_flags() const;
3955 
3959  inline unsigned max_readers() const;
3960 
3963  inline unsigned max_maps() const;
3964 
3966  inline void *get_context() const noexcept;
3967 
3969  inline env &set_context(void *your_context);
3970 
3985  inline env &set_sync_threshold(size_t bytes);
3986 
3992  inline size_t sync_threshold() const;
3993 
3994 #if __cplusplus >= 201103L || defined(DOXYGEN)
4014  inline env &set_sync_period(const duration &period);
4015 
4021  inline duration sync_period() const;
4022 #endif
4023 
4027  inline env &set_sync_period__seconds_16dot16(unsigned seconds_16dot16);
4028 
4031  inline unsigned sync_period__seconds_16dot16() const;
4032 
4036  inline env &set_sync_period__seconds_double(double seconds);
4037 
4040  inline double sync_period__seconds_double() const;
4041 
4046  max_maps = MDBX_opt_max_db,
4049  max_readers = MDBX_opt_max_readers,
4052  sync_bytes = MDBX_opt_sync_bytes,
4055  sync_period = MDBX_opt_sync_period,
4057  rp_augment_limit = MDBX_opt_rp_augment_limit,
4059  loose_limit = MDBX_opt_loose_limit,
4061  dp_reserve_limit = MDBX_opt_dp_reserve_limit,
4063  dp_limit = MDBX_opt_txn_dp_limit,
4065  dp_initial = MDBX_opt_txn_dp_initial,
4067  spill_max_denominator = MDBX_opt_spill_max_denominator,
4069  spill_min_denominator = MDBX_opt_spill_min_denominator,
4071  spill_parent4child_denominator = MDBX_opt_spill_parent4child_denominator,
4073  merge_threshold_16dot16_percent = MDBX_opt_merge_threshold_16dot16_percent,
4075  writethrough_threshold = MDBX_opt_writethrough_threshold,
4077  prefault_write_enable = MDBX_opt_prefault_write_enable,
4078  };
4079 
4081  inline env &set_extra_option(extra_runtime_option option, uint64_t value);
4082 
4084  inline uint64_t extra_option(extra_runtime_option option) const;
4085 
4087  inline env &alter_flags(MDBX_env_flags_t flags, bool on_off);
4088 
4090  inline env &set_geometry(const geometry &size);
4091 
4095  inline bool sync_to_disk(bool force = true, bool nonblock = false);
4096 
4100  bool poll_sync_to_disk() { return sync_to_disk(false, true); }
4101 
4120  inline void close_map(const map_handle &);
4121 
4123  struct reader_info {
4124  int slot;
4127  uint64_t transaction_id;
4129  uint64_t transaction_lag;
4133  size_t bytes_used;
4142 
4144  mdbx_tid_t thread, uint64_t txnid,
4145  uint64_t lag, size_t used,
4146  size_t retained) noexcept;
4147  };
4148 
4156  template <typename VISITOR> inline int enumerate_readers(VISITOR &visitor);
4157 
4160  inline unsigned check_readers();
4161 
4179  inline env &set_HandleSlowReaders(MDBX_hsr_func *);
4180 
4185  inline MDBX_hsr_func *get_HandleSlowReaders() const noexcept;
4186 
4188  inline txn_managed start_read() const;
4189 
4191  inline txn_managed prepare_read() const;
4192 
4194  inline txn_managed start_write(bool dont_wait = false);
4195 
4197  inline txn_managed try_start_write();
4198 };
4199 
4209  using inherited = env;
4211  MDBX_CXX11_CONSTEXPR env_managed(MDBX_env *ptr) noexcept : inherited(ptr) {}
4212  void setup(unsigned max_maps, unsigned max_readers = 0);
4213 
4214 public:
4215  MDBX_CXX11_CONSTEXPR env_managed() noexcept = default;
4216 
4218 #ifdef MDBX_STD_FILESYSTEM_PATH
4220  const operate_parameters &, bool accede = true);
4221 #endif /* MDBX_STD_FILESYSTEM_PATH */
4222 #if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
4223  env_managed(const ::std::wstring &pathname, const operate_parameters &,
4224  bool accede = true);
4225  explicit env_managed(const wchar_t *pathname, const operate_parameters &,
4226  bool accede = true);
4227 #endif /* Windows */
4229  bool accede = true);
4230  explicit env_managed(const char *pathname, const operate_parameters &,
4231  bool accede = true);
4232 
4238  mdbx_mode_t file_mode_bits{0640};
4239  bool use_subdirectory{false};
4241  create_parameters(const create_parameters &) noexcept = default;
4242  };
4243 
4245 #ifdef MDBX_STD_FILESYSTEM_PATH
4247  const create_parameters &, const operate_parameters &,
4248  bool accede = true);
4249 #endif /* MDBX_STD_FILESYSTEM_PATH */
4250 #if defined(_WIN32) || defined(_WIN64) || defined(DOXYGEN)
4251  env_managed(const ::std::wstring &pathname, const create_parameters &,
4252  const operate_parameters &, bool accede = true);
4253  explicit env_managed(const wchar_t *pathname, const create_parameters &,
4254  const operate_parameters &, bool accede = true);
4255 #endif /* Windows */
4257  const operate_parameters &, bool accede = true);
4258  explicit env_managed(const char *pathname, const create_parameters &,
4259  const operate_parameters &, bool accede = true);
4260 
4274  void close(bool dont_sync = false);
4275 
4276  env_managed(env_managed &&) = default;
4277  env_managed &operator=(env_managed &&other) noexcept {
4278  if (MDBX_UNLIKELY(handle_))
4279  MDBX_CXX20_UNLIKELY {
4280  assert(handle_ != other.handle_);
4281  close();
4282  }
4283  inherited::operator=(std::move(other));
4284  return *this;
4285  }
4286  env_managed(const env_managed &) = delete;
4287  env_managed &operator=(const env_managed &) = delete;
4288  virtual ~env_managed() noexcept;
4289 };
4290 
4300 protected:
4301  friend class cursor;
4302  MDBX_txn *handle_{nullptr};
4303  MDBX_CXX11_CONSTEXPR txn(MDBX_txn *ptr) noexcept;
4304 
4305 public:
4306  MDBX_CXX11_CONSTEXPR txn() noexcept = default;
4307  txn(const txn &) noexcept = default;
4308  inline txn &operator=(txn &&other) noexcept;
4309  inline txn(txn &&other) noexcept;
4310  inline ~txn() noexcept;
4311 
4312  MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4313  MDBX_CXX14_CONSTEXPR operator const MDBX_txn *() const;
4314  MDBX_CXX14_CONSTEXPR operator MDBX_txn *();
4315  friend MDBX_CXX11_CONSTEXPR bool operator==(const txn &a,
4316  const txn &b) noexcept;
4317  friend MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a,
4318  const txn &b) noexcept;
4319 
4321  inline ::mdbx::env env() const noexcept;
4323  inline MDBX_txn_flags_t flags() const;
4325  inline uint64_t id() const;
4326 
4328  inline void *get_context() const noexcept;
4329 
4331  inline txn &set_context(void *your_context);
4332 
4334  inline bool is_dirty(const void *ptr) const;
4335 
4337  bool is_readonly() const { return (flags() & MDBX_TXN_RDONLY) != 0; }
4338 
4340  bool is_readwrite() const { return (flags() & MDBX_TXN_RDONLY) == 0; }
4341 
4344  inline info get_info(bool scan_reader_lock_table = false) const;
4345 
4348  size_t size_max() const { return env().transaction_size_max(); }
4349 
4352  size_t size_current() const {
4353  assert(is_readwrite());
4354  return size_t(get_info().txn_space_dirty);
4355  }
4356 
4357  //----------------------------------------------------------------------------
4358 
4360  inline void reset_reading();
4361 
4363  inline void renew_reading();
4364 
4367 
4369  inline cursor_managed open_cursor(map_handle map) const;
4370 
4372  inline size_t release_all_cursors(bool unbind) const;
4373 
4375  inline size_t close_all_cursors() const { return release_all_cursors(false); }
4376 
4378  inline size_t unbind_all_cursors() const { return release_all_cursors(true); }
4379 
4381  inline map_handle open_map(
4382  const char *name,
4386  inline map_handle open_map(
4387  const ::std::string &name,
4390 
4392  inline map_handle open_map_accede(const char *name) const;
4394  inline map_handle open_map_accede(const ::std::string &name) const;
4395 
4397  inline map_handle
4398  create_map(const char *name,
4402  inline map_handle
4403  create_map(const ::std::string &name,
4406 
4408  inline void drop_map(map_handle map);
4412  bool drop_map(const char *name, bool throw_if_absent = false);
4416  inline bool drop_map(const ::std::string &name, bool throw_if_absent = false);
4417 
4419  inline void clear_map(map_handle map);
4422  bool clear_map(const char *name, bool throw_if_absent = false);
4425  inline bool clear_map(const ::std::string &name,
4426  bool throw_if_absent = false);
4427 
4429  inline void rename_map(map_handle map, const char *new_name);
4431  inline void rename_map(map_handle map, const ::std::string &new_name);
4435  bool rename_map(const char *old_name, const char *new_name,
4436  bool throw_if_absent = false);
4441  bool throw_if_absent = false);
4442 
4443 #if defined(DOXYGEN) || \
4444  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
4445 
4447  inline map_handle open_map(
4448  const ::std::string_view &name,
4452  inline map_handle open_map_accede(const ::std::string_view &name) const;
4454  inline map_handle
4455  create_map(const ::std::string_view &name,
4461  bool drop_map(const ::std::string_view &name, bool throw_if_absent = false);
4464  bool clear_map(const ::std::string_view &name, bool throw_if_absent = false);
4466  inline void rename_map(map_handle map, const ::std::string_view &new_name);
4470  bool rename_map(const ::std::string_view &old_name,
4471  const ::std::string_view &new_name,
4472  bool throw_if_absent = false);
4473 
4474 #endif /* __cpp_lib_string_view >= 201606L */
4475 
4478  inline map_stat get_map_stat(map_handle map) const;
4481  inline uint32_t get_tree_deepmask(map_handle map) const;
4483  inline map_handle::info get_handle_info(map_handle map) const;
4484 
4488  inline txn &put_canary(const canary &);
4491  inline canary get_canary() const;
4492 
4495  inline uint64_t sequence(map_handle map) const;
4498  inline uint64_t sequence(map_handle map, uint64_t increment);
4499 
4502  inline int compare_keys(map_handle map, const slice &a,
4503  const slice &b) const noexcept;
4506  inline int compare_values(map_handle map, const slice &a,
4507  const slice &b) const noexcept;
4510  inline int compare_keys(map_handle map, const pair &a,
4511  const pair &b) const noexcept;
4514  inline int compare_values(map_handle map, const pair &a,
4515  const pair &b) const noexcept;
4516 
4518  inline slice get(map_handle map, const slice &key) const;
4521  inline slice get(map_handle map, slice key, size_t &values_count) const;
4523  inline slice get(map_handle map, const slice &key,
4524  const slice &value_at_absence) const;
4527  inline slice get(map_handle map, slice key, size_t &values_count,
4528  const slice &value_at_absence) const;
4532  inline pair_result get_equal_or_great(map_handle map, const slice &key) const;
4536  inline pair_result get_equal_or_great(map_handle map, const slice &key,
4537  const slice &value_at_absence) const;
4538 
4539  inline MDBX_error_t put(map_handle map, const slice &key, slice *value,
4540  MDBX_put_flags_t flags) noexcept;
4541  inline void put(map_handle map, const slice &key, slice value, put_mode mode);
4542  inline void insert(map_handle map, const slice &key, slice value);
4543  inline value_result try_insert(map_handle map, const slice &key, slice value);
4544  inline slice insert_reserve(map_handle map, const slice &key,
4545  size_t value_length);
4546  inline value_result try_insert_reserve(map_handle map, const slice &key,
4547  size_t value_length);
4548 
4549  inline void upsert(map_handle map, const slice &key, const slice &value);
4550  inline slice upsert_reserve(map_handle map, const slice &key,
4551  size_t value_length);
4552 
4553  inline void update(map_handle map, const slice &key, const slice &value);
4554  inline bool try_update(map_handle map, const slice &key, const slice &value);
4555  inline slice update_reserve(map_handle map, const slice &key,
4556  size_t value_length);
4557  inline value_result try_update_reserve(map_handle map, const slice &key,
4558  size_t value_length);
4559 
4561  inline bool erase(map_handle map, const slice &key);
4562 
4564  inline bool erase(map_handle map, const slice &key, const slice &value);
4565 
4567  inline void replace(map_handle map, const slice &key, slice old_value,
4568  const slice &new_value);
4569 
4571  template <class ALLOCATOR, typename CAPACITY_POLICY>
4573  extract(map_handle map, const slice &key,
4576 
4578  template <class ALLOCATOR, typename CAPACITY_POLICY>
4580  replace(map_handle map, const slice &key, const slice &new_value,
4583 
4584  template <class ALLOCATOR, typename CAPACITY_POLICY>
4585  inline buffer<ALLOCATOR, CAPACITY_POLICY> replace_reserve(
4586  map_handle map, const slice &key, slice &new_value,
4589 
4606  inline void append(map_handle map, const slice &key, const slice &value,
4607  bool multivalue_order_preserved = true);
4608 
4609  size_t put_multiple(map_handle map, const slice &key,
4610  const size_t value_length, const void *values_array,
4611  size_t values_count, put_mode mode,
4612  bool allow_partial = false);
4613  template <typename VALUE>
4614  size_t put_multiple(map_handle map, const slice &key,
4615  const VALUE *values_array, size_t values_count,
4616  put_mode mode, bool allow_partial = false) {
4617  static_assert(::std::is_standard_layout<VALUE>::value &&
4618  !::std::is_pointer<VALUE>::value &&
4619  !::std::is_array<VALUE>::value,
4620  "Must be a standard layout type!");
4621  return put_multiple(map, key, sizeof(VALUE), values_array, values_count,
4622  mode, allow_partial);
4623  }
4624  template <typename VALUE>
4625  void put_multiple(map_handle map, const slice &key,
4626  const ::std::vector<VALUE> &vector, put_mode mode) {
4627  put_multiple(map, key, vector.data(), vector.size(), mode);
4628  }
4629 
4630  inline ptrdiff_t estimate(map_handle map, const pair &from,
4631  const pair &to) const;
4632  inline ptrdiff_t estimate(map_handle map, const slice &from,
4633  const slice &to) const;
4634  inline ptrdiff_t estimate_from_first(map_handle map, const slice &to) const;
4635  inline ptrdiff_t estimate_to_last(map_handle map, const slice &from) const;
4636 };
4637 
4647  using inherited = txn;
4648  friend class env;
4649  friend class txn;
4651  MDBX_CXX11_CONSTEXPR txn_managed(MDBX_txn *ptr) noexcept : inherited(ptr) {}
4652 
4653 public:
4654  MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
4655  txn_managed(txn_managed &&) = default;
4656  txn_managed &operator=(txn_managed &&other) noexcept {
4657  if (MDBX_UNLIKELY(handle_))
4658  MDBX_CXX20_UNLIKELY {
4659  assert(handle_ != other.handle_);
4660  abort();
4661  }
4662  inherited::operator=(std::move(other));
4663  return *this;
4664  }
4665  txn_managed(const txn_managed &) = delete;
4666  txn_managed &operator=(const txn_managed &) = delete;
4667  ~txn_managed() noexcept;
4668 
4669  //----------------------------------------------------------------------------
4670 
4673  void abort();
4674 
4676  void commit();
4677 
4680  void commit_embark_read();
4681 
4683 
4686  void commit(commit_latency *);
4687 
4690  void commit(commit_latency &latency) { return commit(&latency); }
4691 
4696  commit_latency result;
4697  commit(&result);
4698  return result;
4699  }
4700 };
4701 
4710 protected:
4711  MDBX_cursor *handle_{nullptr};
4712  MDBX_CXX11_CONSTEXPR cursor(MDBX_cursor *ptr) noexcept;
4713 
4714 public:
4715  MDBX_CXX11_CONSTEXPR cursor() noexcept = default;
4716  cursor(const cursor &) noexcept = default;
4717  inline cursor &operator=(cursor &&other) noexcept;
4718  inline cursor(cursor &&other) noexcept;
4719  inline ~cursor() noexcept;
4720  inline cursor_managed clone(void *your_context = nullptr) const;
4721  MDBX_CXX14_CONSTEXPR operator bool() const noexcept;
4722  MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const;
4723  MDBX_CXX14_CONSTEXPR operator MDBX_cursor *();
4724  friend MDBX_CXX11_CONSTEXPR bool operator==(const cursor &a,
4725  const cursor &b) noexcept;
4726  friend MDBX_CXX11_CONSTEXPR bool operator!=(const cursor &a,
4727  const cursor &b) noexcept;
4728 
4729  friend inline int compare_position_nothrow(const cursor &left,
4730  const cursor &right,
4731  bool ignore_nested) noexcept;
4732  friend inline int compare_position(const cursor &left, const cursor &right,
4733  bool ignore_nested);
4734 
4735  bool is_before_than(const cursor &other, bool ignore_nested = false) const {
4736  return compare_position(*this, other, ignore_nested) < 0;
4737  }
4738 
4739  bool is_same_or_before_than(const cursor &other,
4740  bool ignore_nested = false) const {
4741  return compare_position(*this, other, ignore_nested) <= 0;
4742  }
4743 
4744  bool is_same_position(const cursor &other, bool ignore_nested = false) const {
4745  return compare_position(*this, other, ignore_nested) == 0;
4746  }
4747 
4748  bool is_after_than(const cursor &other, bool ignore_nested = false) const {
4749  return compare_position(*this, other, ignore_nested) > 0;
4750  }
4751 
4752  bool is_same_or_after_than(const cursor &other,
4753  bool ignore_nested = false) const {
4754  return compare_position(*this, other, ignore_nested) >= 0;
4755  }
4756 
4758  inline void *get_context() const noexcept;
4759 
4761  inline cursor &set_context(void *your_context);
4762 
4764  first = MDBX_FIRST,
4765  last = MDBX_LAST,
4766  next = MDBX_NEXT,
4767  previous = MDBX_PREV,
4768  get_current = MDBX_GET_CURRENT,
4769 
4770  multi_prevkey_lastvalue = MDBX_PREV_NODUP,
4771  multi_currentkey_firstvalue = MDBX_FIRST_DUP,
4772  multi_currentkey_prevvalue = MDBX_PREV_DUP,
4773  multi_currentkey_nextvalue = MDBX_NEXT_DUP,
4774  multi_currentkey_lastvalue = MDBX_LAST_DUP,
4775  multi_nextkey_firstvalue = MDBX_NEXT_NODUP,
4776 
4777  multi_find_pair = MDBX_GET_BOTH,
4778  multi_exactkey_lowerboundvalue = MDBX_GET_BOTH_RANGE,
4779 
4780  seek_key = MDBX_SET,
4781  key_exact = MDBX_SET_KEY,
4782  key_lowerbound = MDBX_SET_RANGE,
4783 
4784  /* Doubtless cursor positioning at a specified key. */
4785  key_lesser_than = MDBX_TO_KEY_LESSER_THAN,
4786  key_lesser_or_equal = MDBX_TO_KEY_LESSER_OR_EQUAL,
4787  key_equal = MDBX_TO_KEY_EQUAL,
4788  key_greater_or_equal = MDBX_TO_KEY_GREATER_OR_EQUAL,
4789  key_greater_than = MDBX_TO_KEY_GREATER_THAN,
4790 
4791  /* Doubtless cursor positioning at a specified key-value pair
4792  * for dupsort/multi-value hives. */
4793  multi_exactkey_value_lesser_than = MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN,
4794  multi_exactkey_value_lesser_or_equal =
4796  multi_exactkey_value_equal = MDBX_TO_EXACT_KEY_VALUE_EQUAL,
4797  multi_exactkey_value_greater_or_equal =
4799  multi_exactkey_value_greater = MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN,
4800 
4801  pair_lesser_than = MDBX_TO_PAIR_LESSER_THAN,
4802  pair_lesser_or_equal = MDBX_TO_PAIR_LESSER_OR_EQUAL,
4803  pair_equal = MDBX_TO_PAIR_EQUAL,
4804  pair_exact = pair_equal,
4805  pair_greater_or_equal = MDBX_TO_PAIR_GREATER_OR_EQUAL,
4806  pair_greater_than = MDBX_TO_PAIR_GREATER_THAN,
4807  };
4808 
4809  struct move_result : public pair_result {
4810  inline move_result(const cursor &cursor, bool throw_notfound);
4811  move_result(cursor &cursor, move_operation operation, bool throw_notfound)
4812  : move_result(cursor, operation, slice::invalid(), slice::invalid(),
4813  throw_notfound) {}
4814  move_result(cursor &cursor, move_operation operation, const slice &key,
4815  bool throw_notfound)
4816  : move_result(cursor, operation, key, slice::invalid(),
4817  throw_notfound) {}
4818  inline move_result(cursor &cursor, move_operation operation,
4819  const slice &key, const slice &value,
4820  bool throw_notfound);
4821  move_result(const move_result &) noexcept = default;
4822  move_result &operator=(const move_result &) noexcept = default;
4823  };
4824 
4825  struct estimate_result : public pair {
4828  : estimate_result(cursor, operation, slice::invalid(),
4829  slice::invalid()) {}
4831  const slice &key)
4832  : estimate_result(cursor, operation, key, slice::invalid()) {}
4833  inline estimate_result(const cursor &cursor, move_operation operation,
4834  const slice &key, const slice &value);
4835  estimate_result(const estimate_result &) noexcept = default;
4836  estimate_result &operator=(const estimate_result &) noexcept = default;
4837  };
4838 
4839 protected:
4840  /* fake const, i.e. for some move/get operations */
4841  inline bool move(move_operation operation, MDBX_val *key, MDBX_val *value,
4842  bool throw_notfound) const;
4843 
4844  inline ptrdiff_t estimate(move_operation operation, MDBX_val *key,
4845  MDBX_val *value) const;
4846 
4847 public:
4848  template <typename CALLABLE_PREDICATE>
4849  bool scan(CALLABLE_PREDICATE predicate, move_operation start = first,
4850  move_operation turn = next) {
4851  struct wrapper : public exception_thunk {
4852  static int probe(void *context, MDBX_val *key, MDBX_val *value,
4853  void *arg) noexcept {
4854  auto thunk = static_cast<wrapper *>(context);
4855  assert(thunk->is_clean());
4856  auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4857  try {
4858  return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE
4860  } catch (... /* capture any exception to rethrow it over C code */) {
4861  thunk->capture();
4862  return MDBX_RESULT_TRUE;
4863  }
4864  }
4865  } thunk;
4866  return error::boolean_or_throw(
4867  ::mdbx_cursor_scan(handle_, wrapper::probe, &thunk,
4868  MDBX_cursor_op(start), MDBX_cursor_op(turn),
4869  &predicate),
4870  thunk);
4871  }
4872 
4873  template <typename CALLABLE_PREDICATE>
4874  bool fullscan(CALLABLE_PREDICATE predicate, bool backward = false) {
4875  return scan(std::move(predicate), backward ? last : first,
4876  backward ? previous : next);
4877  }
4878 
4879  template <typename CALLABLE_PREDICATE>
4880  bool scan_from(CALLABLE_PREDICATE predicate, slice &from,
4881  move_operation start = key_greater_or_equal,
4882  move_operation turn = next) {
4883  struct wrapper : public exception_thunk {
4884  static int probe(void *context, MDBX_val *key, MDBX_val *value,
4885  void *arg) noexcept {
4886  auto thunk = static_cast<wrapper *>(context);
4887  assert(thunk->is_clean());
4888  auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4889  try {
4890  return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE
4892  } catch (... /* capture any exception to rethrow it over C code */) {
4893  thunk->capture();
4894  return MDBX_RESULT_TRUE;
4895  }
4896  }
4897  } thunk;
4898  return error::boolean_or_throw(
4899  ::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk,
4900  MDBX_cursor_op(start), &from, nullptr,
4901  MDBX_cursor_op(turn), &predicate),
4902  thunk);
4903  }
4904 
4905  template <typename CALLABLE_PREDICATE>
4906  bool scan_from(CALLABLE_PREDICATE predicate, pair &from,
4907  move_operation start = pair_greater_or_equal,
4908  move_operation turn = next) {
4909  struct wrapper : public exception_thunk {
4910  static int probe(void *context, MDBX_val *key, MDBX_val *value,
4911  void *arg) noexcept {
4912  auto thunk = static_cast<wrapper *>(context);
4913  assert(thunk->is_clean());
4914  auto &predicate = *static_cast<CALLABLE_PREDICATE *>(arg);
4915  try {
4916  return predicate(pair(*key, *value)) ? MDBX_RESULT_TRUE
4918  } catch (... /* capture any exception to rethrow it over C code */) {
4919  thunk->capture();
4920  return MDBX_RESULT_TRUE;
4921  }
4922  }
4923  } thunk;
4924  return error::boolean_or_throw(
4925  ::mdbx_cursor_scan_from(handle_, wrapper::probe, &thunk,
4926  MDBX_cursor_op(start), &from.key, &from.value,
4927  MDBX_cursor_op(turn), &predicate),
4928  thunk);
4929  }
4930 
4931  move_result move(move_operation operation, bool throw_notfound) {
4932  return move_result(*this, operation, throw_notfound);
4933  }
4934  move_result move(move_operation operation, const slice &key,
4935  bool throw_notfound) {
4936  return move_result(*this, operation, key, slice::invalid(), throw_notfound);
4937  }
4938  move_result move(move_operation operation, const slice &key,
4939  const slice &value, bool throw_notfound) {
4940  return move_result(*this, operation, key, value, throw_notfound);
4941  }
4942  bool move(move_operation operation, slice &key, slice &value,
4943  bool throw_notfound) {
4944  return move(operation, &key, &value, throw_notfound);
4945  }
4946 
4947  move_result to_first(bool throw_notfound = true) {
4948  return move(first, throw_notfound);
4949  }
4950  move_result to_previous(bool throw_notfound = true) {
4951  return move(previous, throw_notfound);
4952  }
4953  move_result to_previous_last_multi(bool throw_notfound = true) {
4954  return move(multi_prevkey_lastvalue, throw_notfound);
4955  }
4956  move_result to_current_first_multi(bool throw_notfound = true) {
4957  return move(multi_currentkey_firstvalue, throw_notfound);
4958  }
4959  move_result to_current_prev_multi(bool throw_notfound = true) {
4960  return move(multi_currentkey_prevvalue, throw_notfound);
4961  }
4962  move_result current(bool throw_notfound = true) const {
4963  return move_result(*this, throw_notfound);
4964  }
4965  move_result to_current_next_multi(bool throw_notfound = true) {
4966  return move(multi_currentkey_nextvalue, throw_notfound);
4967  }
4968  move_result to_current_last_multi(bool throw_notfound = true) {
4969  return move(multi_currentkey_lastvalue, throw_notfound);
4970  }
4971  move_result to_next_first_multi(bool throw_notfound = true) {
4972  return move(multi_nextkey_firstvalue, throw_notfound);
4973  }
4974  move_result to_next(bool throw_notfound = true) {
4975  return move(next, throw_notfound);
4976  }
4977  move_result to_last(bool throw_notfound = true) {
4978  return move(last, throw_notfound);
4979  }
4980 
4981  move_result to_key_lesser_than(const slice &key, bool throw_notfound = true) {
4982  return move(key_lesser_than, key, throw_notfound);
4983  }
4985  bool throw_notfound = true) {
4986  return move(key_lesser_or_equal, key, throw_notfound);
4987  }
4988  move_result to_key_equal(const slice &key, bool throw_notfound = true) {
4989  return move(key_equal, key, throw_notfound);
4990  }
4991  move_result to_key_exact(const slice &key, bool throw_notfound = true) {
4992  return move(key_exact, key, throw_notfound);
4993  }
4995  bool throw_notfound = true) {
4996  return move(key_greater_or_equal, key, throw_notfound);
4997  }
4999  bool throw_notfound = true) {
5000  return move(key_greater_than, key, throw_notfound);
5001  }
5002 
5004  const slice &value,
5005  bool throw_notfound = true) {
5006  return move(multi_exactkey_value_lesser_than, key, value, throw_notfound);
5007  }
5009  const slice &value,
5010  bool throw_notfound = true) {
5011  return move(multi_exactkey_value_lesser_or_equal, key, value,
5012  throw_notfound);
5013  }
5015  bool throw_notfound = true) {
5016  return move(multi_exactkey_value_equal, key, value, throw_notfound);
5017  }
5019  const slice &value,
5020  bool throw_notfound = true) {
5021  return move(multi_exactkey_value_greater_or_equal, key, value,
5022  throw_notfound);
5023  }
5025  const slice &value,
5026  bool throw_notfound = true) {
5027  return move(multi_exactkey_value_greater, key, value, throw_notfound);
5028  }
5029 
5030  move_result to_pair_lesser_than(const slice &key, const slice &value,
5031  bool throw_notfound = true) {
5032  return move(pair_lesser_than, key, value, throw_notfound);
5033  }
5035  bool throw_notfound = true) {
5036  return move(pair_lesser_or_equal, key, value, throw_notfound);
5037  }
5038  move_result to_pair_equal(const slice &key, const slice &value,
5039  bool throw_notfound = true) {
5040  return move(pair_equal, key, value, throw_notfound);
5041  }
5042  move_result to_pair_exact(const slice &key, const slice &value,
5043  bool throw_notfound = true) {
5044  return move(pair_exact, key, value, throw_notfound);
5045  }
5047  bool throw_notfound = true) {
5048  return move(pair_greater_or_equal, key, value, throw_notfound);
5049  }
5050  move_result to_pair_greater_than(const slice &key, const slice &value,
5051  bool throw_notfound = true) {
5052  return move(pair_greater_than, key, value, throw_notfound);
5053  }
5054 
5055  inline bool seek(const slice &key);
5056  inline move_result find(const slice &key, bool throw_notfound = true);
5057  inline move_result lower_bound(const slice &key, bool throw_notfound = false);
5058  inline move_result upper_bound(const slice &key, bool throw_notfound = false);
5059 
5061  inline size_t count_multivalue() const;
5062 
5063  inline move_result find_multivalue(const slice &key, const slice &value,
5064  bool throw_notfound = true);
5065  inline move_result lower_bound_multivalue(const slice &key,
5066  const slice &value,
5067  bool throw_notfound = false);
5069  const slice &value,
5070  bool throw_notfound = false);
5071 
5072  inline bool eof() const;
5073  inline bool on_first() const;
5074  inline bool on_last() const;
5075  inline bool on_first_multival() const;
5076  inline bool on_last_multival() const;
5077  inline estimate_result estimate(const slice &key, const slice &value) const;
5078  inline estimate_result estimate(const slice &key) const;
5079  inline estimate_result estimate(move_operation operation) const;
5080  inline estimate_result estimate(move_operation operation, slice &key) const;
5081 
5082  //----------------------------------------------------------------------------
5083 
5086  inline void renew(const ::mdbx::txn &txn);
5087 
5090  inline void bind(const ::mdbx::txn &txn, ::mdbx::map_handle map_handle);
5091 
5093  inline void unbind();
5094 
5096  inline ::mdbx::txn txn() const;
5097  inline map_handle map() const;
5098 
5099  inline operator ::mdbx::txn() const { return txn(); }
5100  inline operator ::mdbx::map_handle() const { return map(); }
5101 
5102  inline MDBX_error_t put(const slice &key, slice *value,
5103  MDBX_put_flags_t flags) noexcept;
5104  inline void insert(const slice &key, slice value);
5105  inline value_result try_insert(const slice &key, slice value);
5106  inline slice insert_reserve(const slice &key, size_t value_length);
5107  inline value_result try_insert_reserve(const slice &key, size_t value_length);
5108 
5109  inline void upsert(const slice &key, const slice &value);
5110  inline slice upsert_reserve(const slice &key, size_t value_length);
5111 
5112  inline void update(const slice &key, const slice &value);
5113  inline bool try_update(const slice &key, const slice &value);
5114  inline slice update_reserve(const slice &key, size_t value_length);
5115  inline value_result try_update_reserve(const slice &key, size_t value_length);
5116 
5119  inline bool erase(bool whole_multivalue = false);
5120 
5124  inline bool erase(const slice &key, bool whole_multivalue = true);
5125 
5128  inline bool erase(const slice &key, const slice &value);
5129 };
5130 
5139  using inherited = cursor;
5140  friend class txn;
5143  : inherited(ptr) {}
5144 
5145 public:
5147  cursor_managed(void *your_context = nullptr)
5148  : cursor_managed(::mdbx_cursor_create(your_context)) {
5149  if (MDBX_UNLIKELY(!handle_))
5150  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM);
5151  }
5152 
5154  void close();
5155 
5158  if (MDBX_UNLIKELY(handle_))
5159  MDBX_CXX20_UNLIKELY {
5160  assert(handle_ != other.handle_);
5161  close();
5162  }
5163  inherited::operator=(std::move(other));
5164  return *this;
5165  }
5166 
5167  cursor_managed(const cursor_managed &) = delete;
5169  ~cursor_managed() noexcept { ::mdbx_cursor_close(handle_); }
5170 };
5171 
5172 //------------------------------------------------------------------------------
5173 
5174 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const slice &);
5175 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair &);
5176 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const pair_result &);
5177 template <class ALLOCATOR, typename CAPACITY_POLICY>
5178 inline ::std::ostream &
5179 operator<<(::std::ostream &out, const buffer<ALLOCATOR, CAPACITY_POLICY> &it) {
5180  return (it.is_freestanding()
5181  ? out << "buf-" << it.headroom() << "." << it.tailroom()
5182  : out << "ref-")
5183  << it.slice();
5184 }
5185 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5186  const env::geometry::size &);
5187 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::geometry &);
5188 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5189  const env::operate_parameters &);
5190 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const env::mode &);
5191 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5192  const env::durability &);
5193 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5194  const env::reclaiming_options &);
5195 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5196  const env::operate_options &);
5197 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5199 
5200 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5201  const MDBX_log_level_t &);
5202 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &,
5203  const MDBX_debug_flags_t &);
5204 LIBMDBX_API ::std::ostream &operator<<(::std::ostream &, const error &);
5205 inline ::std::ostream &operator<<(::std::ostream &out,
5206  const MDBX_error_t &errcode) {
5207  return out << error(errcode);
5208 }
5209 
5210 //==============================================================================
5211 //
5212 // Inline body of the libmdbx C++ API
5213 //
5214 
5217 }
5220 }
5221 
5222 static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept {
5223 #if defined(__cpp_lib_is_constant_evaluated) && \
5224  __cpp_lib_is_constant_evaluated >= 201811L
5225  if (::std::is_constant_evaluated()) {
5226  for (size_t i = 0; c_str; ++i)
5227  if (!c_str[i])
5228  return i;
5229  return 0;
5230  }
5231 #endif /* __cpp_lib_is_constant_evaluated >= 201811 */
5232 #if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
5233  return c_str ? ::std::string_view(c_str).length() : 0;
5234 #else
5235  return c_str ? ::std::strlen(c_str) : 0;
5236 #endif
5237 }
5238 
5240 memcpy(void *dest, const void *src, size_t bytes) noexcept {
5241 #if defined(__cpp_lib_is_constant_evaluated) && \
5242  __cpp_lib_is_constant_evaluated >= 201811L
5243  if (::std::is_constant_evaluated()) {
5244  for (size_t i = 0; i < bytes; ++i)
5245  static_cast<byte *>(dest)[i] = static_cast<const byte *>(src)[i];
5246  return dest;
5247  } else
5248 #endif /* __cpp_lib_is_constant_evaluated >= 201811 */
5249  return ::std::memcpy(dest, src, bytes);
5250 }
5251 
5252 static MDBX_CXX20_CONSTEXPR int memcmp(const void *a, const void *b,
5253  size_t bytes) noexcept {
5254 #if defined(__cpp_lib_is_constant_evaluated) && \
5255  __cpp_lib_is_constant_evaluated >= 201811L
5256  if (::std::is_constant_evaluated()) {
5257  for (size_t i = 0; i < bytes; ++i) {
5258  const int diff = int(static_cast<const byte *>(a)[i]) -
5259  int(static_cast<const byte *>(b)[i]);
5260  if (diff)
5261  return diff;
5262  }
5263  return 0;
5264  } else
5265 #endif /* __cpp_lib_is_constant_evaluated >= 201811 */
5266  return ::std::memcmp(a, b, bytes);
5267 }
5268 
5269 static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes) {
5270  if (MDBX_UNLIKELY(bytes > size_t(MDBX_MAXDATASIZE)))
5271  MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
5272  return bytes;
5273 }
5274 
5275 static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom,
5276  size_t payload) {
5277  return check_length(check_length(headroom) + check_length(payload));
5278 }
5279 
5281 check_length(size_t headroom, size_t payload, size_t tailroom) {
5282  return check_length(check_length(headroom, payload) + check_length(tailroom));
5283 }
5284 
5285 inline bool exception_thunk::is_clean() const noexcept { return !captured_; }
5286 
5287 inline void exception_thunk::capture() noexcept {
5288  assert(is_clean());
5289  captured_ = ::std::current_exception();
5290 }
5291 
5293  if (captured_)
5294  MDBX_CXX20_UNLIKELY ::std::rethrow_exception(captured_);
5295 }
5296 
5297 //------------------------------------------------------------------------------
5298 
5300  : code_(error_code) {}
5301 
5302 inline error &error::operator=(MDBX_error_t error_code) noexcept {
5303  code_ = error_code;
5304  return *this;
5305 }
5306 
5307 MDBX_CXX11_CONSTEXPR bool operator==(const error &a, const error &b) noexcept {
5308  return a.code_ == b.code_;
5309 }
5310 
5311 MDBX_CXX11_CONSTEXPR bool operator!=(const error &a, const error &b) noexcept {
5312  return !(a == b);
5313 }
5314 
5316  return code_ == MDBX_SUCCESS;
5317 }
5318 
5320  return code_ == MDBX_RESULT_FALSE;
5321 }
5322 
5324  return code_ == MDBX_RESULT_TRUE;
5325 }
5326 
5328  return code_ != MDBX_SUCCESS && code_ != MDBX_RESULT_TRUE;
5329 }
5330 
5331 MDBX_CXX11_CONSTEXPR MDBX_error_t error::code() const noexcept { return code_; }
5332 
5334  return (code() >= MDBX_FIRST_LMDB_ERRCODE &&
5335  code() <= MDBX_LAST_LMDB_ERRCODE) ||
5336  (code() >= MDBX_FIRST_ADDED_ERRCODE &&
5337  code() <= MDBX_LAST_ADDED_ERRCODE);
5338 }
5339 
5340 inline void error::throw_exception(int error_code) {
5341  const error trouble(static_cast<MDBX_error_t>(error_code));
5342  trouble.throw_exception();
5343 }
5344 
5345 inline void error::throw_on_failure() const {
5346  if (MDBX_UNLIKELY(is_failure()))
5347  MDBX_CXX20_UNLIKELY throw_exception();
5348 }
5349 
5350 inline void error::success_or_throw() const {
5351  if (MDBX_UNLIKELY(!is_success()))
5352  MDBX_CXX20_UNLIKELY throw_exception();
5353 }
5354 
5355 inline void error::success_or_throw(const exception_thunk &thunk) const {
5356  assert(thunk.is_clean() || code() != MDBX_SUCCESS);
5357  if (MDBX_UNLIKELY(!is_success())) {
5358  MDBX_CXX20_UNLIKELY if (MDBX_UNLIKELY(!thunk.is_clean()))
5359  thunk.rethrow_captured();
5360  else throw_exception();
5361  }
5362 }
5363 
5364 inline void error::panic_on_failure(const char *context_where,
5365  const char *func_who) const noexcept {
5366  if (MDBX_UNLIKELY(is_failure()))
5367  MDBX_CXX20_UNLIKELY panic(context_where, func_who);
5368 }
5369 
5370 inline void error::success_or_panic(const char *context_where,
5371  const char *func_who) const noexcept {
5372  if (MDBX_UNLIKELY(!is_success()))
5373  MDBX_CXX20_UNLIKELY panic(context_where, func_who);
5374 }
5375 
5376 inline void error::throw_on_nullptr(const void *ptr, MDBX_error_t error_code) {
5377  if (MDBX_UNLIKELY(ptr == nullptr))
5378  MDBX_CXX20_UNLIKELY error(error_code).throw_exception();
5379 }
5380 
5381 inline void error::throw_on_failure(int error_code) {
5382  error rc(static_cast<MDBX_error_t>(error_code));
5383  rc.throw_on_failure();
5384 }
5385 
5386 inline void error::success_or_throw(MDBX_error_t error_code) {
5387  error rc(error_code);
5388  rc.success_or_throw();
5389 }
5390 
5391 inline bool error::boolean_or_throw(int error_code) {
5392  switch (error_code) {
5393  case MDBX_RESULT_FALSE:
5394  return false;
5395  case MDBX_RESULT_TRUE:
5396  return true;
5397  default:
5398  MDBX_CXX20_UNLIKELY throw_exception(error_code);
5399  }
5400 }
5401 
5402 inline void error::success_or_throw(int error_code,
5403  const exception_thunk &thunk) {
5404  error rc(static_cast<MDBX_error_t>(error_code));
5405  rc.success_or_throw(thunk);
5406 }
5407 
5408 inline void error::panic_on_failure(int error_code, const char *context_where,
5409  const char *func_who) noexcept {
5410  error rc(static_cast<MDBX_error_t>(error_code));
5411  rc.panic_on_failure(context_where, func_who);
5412 }
5413 
5414 inline void error::success_or_panic(int error_code, const char *context_where,
5415  const char *func_who) noexcept {
5416  error rc(static_cast<MDBX_error_t>(error_code));
5417  rc.success_or_panic(context_where, func_who);
5418 }
5419 
5420 inline bool error::boolean_or_throw(int error_code,
5421  const exception_thunk &thunk) {
5422  if (MDBX_UNLIKELY(!thunk.is_clean()))
5423  MDBX_CXX20_UNLIKELY thunk.rethrow_captured();
5424  return boolean_or_throw(error_code);
5425 }
5426 
5427 //------------------------------------------------------------------------------
5428 
5429 MDBX_CXX11_CONSTEXPR slice::slice() noexcept : ::MDBX_val({nullptr, 0}) {}
5430 
5431 MDBX_CXX14_CONSTEXPR slice::slice(const void *ptr, size_t bytes)
5432  : ::MDBX_val({const_cast<void *>(ptr), check_length(bytes)}) {}
5433 
5434 MDBX_CXX14_CONSTEXPR slice::slice(const void *begin, const void *end)
5435  : slice(begin, static_cast<const byte *>(end) -
5436  static_cast<const byte *>(begin)) {}
5437 
5439  : slice(c_str, ::mdbx::strlen(c_str)) {}
5440 
5442  : slice(src.iov_base, src.iov_len) {}
5443 
5445  src.iov_base = nullptr;
5446 }
5447 
5449  src.invalidate();
5450 }
5451 
5452 inline slice &slice::assign(const void *ptr, size_t bytes) {
5453  iov_base = const_cast<void *>(ptr);
5454  iov_len = check_length(bytes);
5455  return *this;
5456 }
5457 
5458 inline slice &slice::assign(const slice &src) noexcept {
5459  iov_base = src.iov_base;
5460  iov_len = src.iov_len;
5461  return *this;
5462 }
5463 
5465  return assign(src.iov_base, src.iov_len);
5466 }
5467 
5468 slice &slice::assign(slice &&src) noexcept {
5469  assign(src);
5470  src.invalidate();
5471  return *this;
5472 }
5473 
5474 inline slice &slice::assign(::MDBX_val &&src) {
5475  assign(src.iov_base, src.iov_len);
5476  src.iov_base = nullptr;
5477  return *this;
5478 }
5479 
5480 inline slice &slice::assign(const void *begin, const void *end) {
5481  return assign(begin, static_cast<const byte *>(end) -
5482  static_cast<const byte *>(begin));
5483 }
5484 
5485 inline slice &slice::assign(const char *c_str) {
5486  return assign(c_str, ::mdbx::strlen(c_str));
5487 }
5488 
5489 inline slice &slice::operator=(slice &&src) noexcept {
5490  return assign(::std::move(src));
5491 }
5492 
5493 inline slice &slice::operator=(::MDBX_val &&src) {
5494  return assign(::std::move(src));
5495 }
5496 
5497 inline void slice::swap(slice &other) noexcept {
5498  const auto temp = *this;
5499  *this = other;
5500  other = temp;
5501 }
5502 
5504  return static_cast<const byte *>(iov_base);
5505 }
5506 
5508  return byte_ptr() + length();
5509 }
5510 
5512  return static_cast<byte *>(iov_base);
5513 }
5514 
5516  return byte_ptr() + length();
5517 }
5518 
5519 MDBX_CXX11_CONSTEXPR const char *slice::char_ptr() const noexcept {
5520  return static_cast<const char *>(iov_base);
5521 }
5522 
5523 MDBX_CXX11_CONSTEXPR const char *slice::end_char_ptr() const noexcept {
5524  return char_ptr() + length();
5525 }
5526 
5528  return static_cast<char *>(iov_base);
5529 }
5530 
5532  return char_ptr() + length();
5533 }
5534 
5535 MDBX_CXX11_CONSTEXPR const void *slice::data() const noexcept {
5536  return iov_base;
5537 }
5538 
5539 MDBX_CXX11_CONSTEXPR const void *slice::end() const noexcept {
5540  return static_cast<const void *>(end_byte_ptr());
5541 }
5542 
5543 MDBX_CXX11_CONSTEXPR void *slice::data() noexcept { return iov_base; }
5544 
5546  return static_cast<void *>(end_byte_ptr());
5547 }
5548 
5549 MDBX_CXX11_CONSTEXPR size_t slice::length() const noexcept { return iov_len; }
5550 
5552  iov_len = check_length(bytes);
5553  return *this;
5554 }
5555 
5557  MDBX_CONSTEXPR_ASSERT(static_cast<const char *>(ptr) >= char_ptr());
5558  return set_length(static_cast<const char *>(ptr) - char_ptr());
5559 }
5560 
5561 MDBX_CXX11_CONSTEXPR bool slice::empty() const noexcept {
5562  return length() == 0;
5563 }
5564 
5565 MDBX_CXX11_CONSTEXPR bool slice::is_null() const noexcept {
5566  return data() == nullptr;
5567 }
5568 
5569 MDBX_CXX11_CONSTEXPR size_t slice::size() const noexcept { return length(); }
5570 
5571 MDBX_CXX11_CONSTEXPR slice::operator bool() const noexcept {
5572  return !is_null();
5573 }
5574 
5575 MDBX_CXX14_CONSTEXPR void slice::invalidate() noexcept { iov_base = nullptr; }
5576 
5578  iov_base = nullptr;
5579  iov_len = 0;
5580 }
5581 
5582 inline void slice::remove_prefix(size_t n) noexcept {
5583  assert(n <= size());
5584  iov_base = static_cast<byte *>(iov_base) + n;
5585  iov_len -= n;
5586 }
5587 
5588 inline void slice::safe_remove_prefix(size_t n) {
5589  if (MDBX_UNLIKELY(n > size()))
5590  MDBX_CXX20_UNLIKELY throw_out_range();
5591  remove_prefix(n);
5592 }
5593 
5594 inline void slice::remove_suffix(size_t n) noexcept {
5595  assert(n <= size());
5596  iov_len -= n;
5597 }
5598 
5599 inline void slice::safe_remove_suffix(size_t n) {
5600  if (MDBX_UNLIKELY(n > size()))
5601  MDBX_CXX20_UNLIKELY throw_out_range();
5602  remove_suffix(n);
5603 }
5604 
5606 slice::starts_with(const slice &prefix) const noexcept {
5607  return length() >= prefix.length() &&
5608  memcmp(data(), prefix.data(), prefix.length()) == 0;
5609 }
5610 
5611 MDBX_CXX14_CONSTEXPR bool slice::ends_with(const slice &suffix) const noexcept {
5612  return length() >= suffix.length() &&
5613  memcmp(byte_ptr() + length() - suffix.length(), suffix.data(),
5614  suffix.length()) == 0;
5615 }
5616 
5618 slice::hash_value() const noexcept {
5619  size_t h = length() * 3977471;
5620  for (size_t i = 0; i < length(); ++i)
5621  h = (h ^ static_cast<const uint8_t *>(data())[i]) * 1664525 + 1013904223;
5622  return h ^ 3863194411 * (h >> 11);
5623 }
5624 
5625 MDBX_CXX11_CONSTEXPR byte slice::operator[](size_t n) const noexcept {
5626  MDBX_CONSTEXPR_ASSERT(n < size());
5627  return byte_ptr()[n];
5628 }
5629 
5630 MDBX_CXX11_CONSTEXPR byte slice::at(size_t n) const {
5631  if (MDBX_UNLIKELY(n >= size()))
5632  MDBX_CXX20_UNLIKELY throw_out_range();
5633  return byte_ptr()[n];
5634 }
5635 
5636 MDBX_CXX14_CONSTEXPR slice slice::head(size_t n) const noexcept {
5637  MDBX_CONSTEXPR_ASSERT(n <= size());
5638  return slice(data(), n);
5639 }
5640 
5641 MDBX_CXX14_CONSTEXPR slice slice::tail(size_t n) const noexcept {
5642  MDBX_CONSTEXPR_ASSERT(n <= size());
5643  return slice(char_ptr() + size() - n, n);
5644 }
5645 
5646 MDBX_CXX14_CONSTEXPR slice slice::middle(size_t from, size_t n) const noexcept {
5647  MDBX_CONSTEXPR_ASSERT(from + n <= size());
5648  return slice(char_ptr() + from, n);
5649 }
5650 
5652  if (MDBX_UNLIKELY(n > size()))
5653  MDBX_CXX20_UNLIKELY throw_out_range();
5654  return head(n);
5655 }
5656 
5658  if (MDBX_UNLIKELY(n > size()))
5659  MDBX_CXX20_UNLIKELY throw_out_range();
5660  return tail(n);
5661 }
5662 
5663 MDBX_CXX14_CONSTEXPR slice slice::safe_middle(size_t from, size_t n) const {
5664  if (MDBX_UNLIKELY(n > max_length))
5665  MDBX_CXX20_UNLIKELY throw_max_length_exceeded();
5666  if (MDBX_UNLIKELY(from + n > size()))
5667  MDBX_CXX20_UNLIKELY throw_out_range();
5668  return middle(from, n);
5669 }
5670 
5672  const slice &b) noexcept {
5673  const intptr_t diff = intptr_t(a.length()) - intptr_t(b.length());
5674  return diff ? diff
5675  : MDBX_UNLIKELY(a.length() == 0 || a.data() == b.data())
5676  ? 0
5677  : memcmp(a.data(), b.data(), a.length());
5678 }
5679 
5680 MDBX_CXX14_CONSTEXPR intptr_t
5681 slice::compare_lexicographically(const slice &a, const slice &b) noexcept {
5682  const size_t shortest = ::std::min(a.length(), b.length());
5683  if (MDBX_LIKELY(shortest > 0))
5685  const intptr_t diff = memcmp(a.data(), b.data(), shortest);
5686  if (MDBX_LIKELY(diff != 0))
5687  MDBX_CXX20_LIKELY return diff;
5688  }
5689  return intptr_t(a.length()) - intptr_t(b.length());
5690 }
5691 
5693 operator==(const slice &a, const slice &b) noexcept {
5694  return slice::compare_fast(a, b) == 0;
5695 }
5696 
5698 operator<(const slice &a, const slice &b) noexcept {
5699  return slice::compare_lexicographically(a, b) < 0;
5700 }
5701 
5703 operator>(const slice &a, const slice &b) noexcept {
5704  return slice::compare_lexicographically(a, b) > 0;
5705 }
5706 
5708 operator<=(const slice &a, const slice &b) noexcept {
5709  return slice::compare_lexicographically(a, b) <= 0;
5710 }
5711 
5713 operator>=(const slice &a, const slice &b) noexcept {
5714  return slice::compare_lexicographically(a, b) >= 0;
5715 }
5716 
5718 operator!=(const slice &a, const slice &b) noexcept {
5719  return slice::compare_fast(a, b) != 0;
5720 }
5721 
5722 template <class ALLOCATOR>
5723 inline string<ALLOCATOR>
5724 slice::as_hex_string(bool uppercase, unsigned wrap_width,
5725  const ALLOCATOR &allocator) const {
5726  return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(allocator);
5727 }
5728 
5729 template <class ALLOCATOR>
5730 inline string<ALLOCATOR>
5731 slice::as_base58_string(unsigned wrap_width, const ALLOCATOR &allocator) const {
5732  return to_base58(*this, wrap_width).as_string<ALLOCATOR>(allocator);
5733 }
5734 
5735 template <class ALLOCATOR>
5736 inline string<ALLOCATOR>
5737 slice::as_base64_string(unsigned wrap_width, const ALLOCATOR &allocator) const {
5738  return to_base64(*this, wrap_width).as_string<ALLOCATOR>(allocator);
5739 }
5740 
5741 template <class ALLOCATOR, class CAPACITY_POLICY>
5743 slice::encode_hex(bool uppercase, unsigned wrap_width,
5744  const ALLOCATOR &allocator) const {
5745  return to_hex(*this, uppercase, wrap_width)
5746  .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5747 }
5748 
5749 template <class ALLOCATOR, class CAPACITY_POLICY>
5751 slice::encode_base58(unsigned wrap_width, const ALLOCATOR &allocator) const {
5752  return to_base58(*this, wrap_width)
5753  .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5754 }
5755 
5756 template <class ALLOCATOR, class CAPACITY_POLICY>
5758 slice::encode_base64(unsigned wrap_width, const ALLOCATOR &allocator) const {
5759  return to_base64(*this, wrap_width)
5760  .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5761 }
5762 
5763 template <class ALLOCATOR, class CAPACITY_POLICY>
5765 slice::hex_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5766  return from_hex(*this, ignore_spaces)
5767  .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5768 }
5769 
5770 template <class ALLOCATOR, class CAPACITY_POLICY>
5772 slice::base58_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5773  return from_base58(*this, ignore_spaces)
5774  .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5775 }
5776 
5777 template <class ALLOCATOR, class CAPACITY_POLICY>
5779 slice::base64_decode(bool ignore_spaces, const ALLOCATOR &allocator) const {
5780  return from_base64(*this, ignore_spaces)
5781  .as_buffer<ALLOCATOR, CAPACITY_POLICY>(allocator);
5782 }
5783 
5784 inline MDBX_NOTHROW_PURE_FUNCTION bool
5785 slice::is_hex(bool ignore_spaces) const noexcept {
5786  return !from_hex(*this, ignore_spaces).is_erroneous();
5787 }
5788 
5789 inline MDBX_NOTHROW_PURE_FUNCTION bool
5790 slice::is_base58(bool ignore_spaces) const noexcept {
5791  return !from_base58(*this, ignore_spaces).is_erroneous();
5792 }
5793 
5794 inline MDBX_NOTHROW_PURE_FUNCTION bool
5795 slice::is_base64(bool ignore_spaces) const noexcept {
5796  return !from_base64(*this, ignore_spaces).is_erroneous();
5797 }
5798 
5799 //------------------------------------------------------------------------------
5800 
5802  const pair &b) noexcept {
5803  const auto diff = slice::compare_fast(a.key, b.key);
5804  return diff ? diff : slice::compare_fast(a.value, b.value);
5805 }
5806 
5807 MDBX_CXX14_CONSTEXPR intptr_t
5808 pair::compare_lexicographically(const pair &a, const pair &b) noexcept {
5809  const auto diff = slice::compare_lexicographically(a.key, b.key);
5810  return diff ? diff : slice::compare_lexicographically(a.value, b.value);
5811 }
5812 
5814 operator==(const pair &a, const pair &b) noexcept {
5815  return a.key.length() == b.key.length() &&
5816  a.value.length() == b.value.length() &&
5817  memcmp(a.key.data(), b.key.data(), a.key.length()) == 0 &&
5818  memcmp(a.value.data(), b.value.data(), a.value.length()) == 0;
5819 }
5820 
5822 operator<(const pair &a, const pair &b) noexcept {
5823  return pair::compare_lexicographically(a, b) < 0;
5824 }
5825 
5827 operator>(const pair &a, const pair &b) noexcept {
5828  return pair::compare_lexicographically(a, b) > 0;
5829 }
5830 
5832 operator<=(const pair &a, const pair &b) noexcept {
5833  return pair::compare_lexicographically(a, b) <= 0;
5834 }
5835 
5837 operator>=(const pair &a, const pair &b) noexcept {
5838  return pair::compare_lexicographically(a, b) >= 0;
5839 }
5840 
5842 operator!=(const pair &a, const pair &b) noexcept {
5843  return a.key.length() != b.key.length() ||
5844  a.value.length() != b.value.length() ||
5845  memcmp(a.key.data(), b.key.data(), a.key.length()) != 0 ||
5846  memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
5847 }
5848 
5849 //------------------------------------------------------------------------------
5850 
5851 template <class ALLOCATOR, typename CAPACITY_POLICY>
5853  const txn &txn, const struct slice &src, const allocator_type &allocator)
5854  : buffer(src, !txn.is_dirty(src.data()), allocator) {}
5855 
5856 //------------------------------------------------------------------------------
5857 
5859  map_handle::state state) noexcept
5860  : flags(flags), state(state) {}
5861 
5863 map_handle::info::key_mode() const noexcept {
5865 }
5866 
5871 }
5872 
5873 //------------------------------------------------------------------------------
5874 
5875 MDBX_CXX11_CONSTEXPR env::env(MDBX_env *ptr) noexcept : handle_(ptr) {}
5876 
5877 inline env &env::operator=(env &&other) noexcept {
5878  handle_ = other.handle_;
5879  other.handle_ = nullptr;
5880  return *this;
5881 }
5882 
5883 inline env::env(env &&other) noexcept : handle_(other.handle_) {
5884  other.handle_ = nullptr;
5885 }
5886 
5887 inline env::~env() noexcept {
5888 #ifndef NDEBUG
5889  handle_ = reinterpret_cast<MDBX_env *>(uintptr_t(0xDeadBeef));
5890 #endif
5891 }
5892 
5893 MDBX_CXX14_CONSTEXPR env::operator bool() const noexcept {
5894  return handle_ != nullptr;
5895 }
5896 
5897 MDBX_CXX14_CONSTEXPR env::operator const MDBX_env *() const { return handle_; }
5898 
5899 MDBX_CXX14_CONSTEXPR env::operator MDBX_env *() { return handle_; }
5900 
5901 MDBX_CXX11_CONSTEXPR bool operator==(const env &a, const env &b) noexcept {
5902  return a.handle_ == b.handle_;
5903 }
5904 
5905 MDBX_CXX11_CONSTEXPR bool operator!=(const env &a, const env &b) noexcept {
5906  return a.handle_ != b.handle_;
5907 }
5908 
5909 inline env::geometry &env::geometry::make_fixed(intptr_t size) noexcept {
5910  size_lower = size_now = size_upper = size;
5911  growth_step = shrink_threshold = 0;
5912  return *this;
5913 }
5914 
5916  intptr_t upper) noexcept {
5917  size_now = size_lower = lower;
5918  size_upper = upper;
5919  growth_step = shrink_threshold = default_value;
5920  return *this;
5921 }
5922 
5924  MDBX_env_flags_t flags) noexcept {
5925  return reclaiming_options(flags);
5926 }
5927 
5928 inline env::operate_options
5930  return operate_options(flags);
5931 }
5932 
5933 inline size_t env::limits::pagesize_min() noexcept { return MDBX_MIN_PAGESIZE; }
5934 
5935 inline size_t env::limits::pagesize_max() noexcept { return MDBX_MAX_PAGESIZE; }
5936 
5937 inline size_t env::limits::dbsize_min(intptr_t pagesize) {
5938  const intptr_t result = mdbx_limits_dbsize_min(pagesize);
5939  if (result < 0)
5940  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5941  return static_cast<size_t>(result);
5942 }
5943 
5944 inline size_t env::limits::dbsize_max(intptr_t pagesize) {
5945  const intptr_t result = mdbx_limits_dbsize_max(pagesize);
5946  if (result < 0)
5947  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5948  return static_cast<size_t>(result);
5949 }
5950 
5951 inline size_t env::limits::key_min(MDBX_db_flags_t flags) noexcept {
5952  return (flags & MDBX_INTEGERKEY) ? 4 : 0;
5953 }
5954 
5955 inline size_t env::limits::key_min(key_mode mode) noexcept {
5956  return key_min(MDBX_db_flags_t(mode));
5957 }
5958 
5959 inline size_t env::limits::key_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5960  const intptr_t result = mdbx_limits_keysize_max(pagesize, flags);
5961  if (result < 0)
5962  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5963  return static_cast<size_t>(result);
5964 }
5965 
5966 inline size_t env::limits::key_max(intptr_t pagesize, key_mode mode) {
5967  return key_max(pagesize, MDBX_db_flags_t(mode));
5968 }
5969 
5971  const intptr_t result = mdbx_env_get_maxkeysize_ex(env, flags);
5972  if (result < 0)
5973  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5974  return static_cast<size_t>(result);
5975 }
5976 
5977 inline size_t env::limits::key_max(const env &env, key_mode mode) {
5978  return key_max(env, MDBX_db_flags_t(mode));
5979 }
5980 
5982  return (flags & MDBX_INTEGERDUP) ? 4 : 0;
5983 }
5984 
5985 inline size_t env::limits::value_min(value_mode mode) noexcept {
5986  return value_min(MDBX_db_flags_t(mode));
5987 }
5988 
5989 inline size_t env::limits::value_max(intptr_t pagesize, MDBX_db_flags_t flags) {
5990  const intptr_t result = mdbx_limits_valsize_max(pagesize, flags);
5991  if (result < 0)
5992  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
5993  return static_cast<size_t>(result);
5994 }
5995 
5996 inline size_t env::limits::value_max(intptr_t pagesize, value_mode mode) {
5997  return value_max(pagesize, MDBX_db_flags_t(mode));
5998 }
5999 
6001  const intptr_t result = mdbx_env_get_maxvalsize_ex(env, flags);
6002  if (result < 0)
6003  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6004  return static_cast<size_t>(result);
6005 }
6006 
6008  return value_max(env, MDBX_db_flags_t(mode));
6009 }
6010 
6011 inline size_t env::limits::pairsize4page_max(intptr_t pagesize,
6013  const intptr_t result = mdbx_limits_pairsize4page_max(pagesize, flags);
6014  if (result < 0)
6015  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6016  return static_cast<size_t>(result);
6017 }
6018 
6019 inline size_t env::limits::pairsize4page_max(intptr_t pagesize,
6020  value_mode mode) {
6021  return pairsize4page_max(pagesize, MDBX_db_flags_t(mode));
6022 }
6023 
6026  const intptr_t result = mdbx_env_get_pairsize4page_max(env, flags);
6027  if (result < 0)
6028  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6029  return static_cast<size_t>(result);
6030 }
6031 
6033  return pairsize4page_max(env, MDBX_db_flags_t(mode));
6034 }
6035 
6036 inline size_t env::limits::valsize4page_max(intptr_t pagesize,
6038  const intptr_t result = mdbx_limits_valsize4page_max(pagesize, flags);
6039  if (result < 0)
6040  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6041  return static_cast<size_t>(result);
6042 }
6043 
6044 inline size_t env::limits::valsize4page_max(intptr_t pagesize,
6045  value_mode mode) {
6046  return valsize4page_max(pagesize, MDBX_db_flags_t(mode));
6047 }
6048 
6051  const intptr_t result = mdbx_env_get_valsize4page_max(env, flags);
6052  if (result < 0)
6053  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6054  return static_cast<size_t>(result);
6055 }
6056 
6058  return valsize4page_max(env, MDBX_db_flags_t(mode));
6059 }
6060 
6061 inline size_t env::limits::transaction_size_max(intptr_t pagesize) {
6062  const intptr_t result = mdbx_limits_txnsize_max(pagesize);
6063  if (result < 0)
6064  MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
6065  return static_cast<size_t>(result);
6066 }
6067 
6069  const auto flags = get_flags();
6070  return operate_parameters(max_maps(), max_readers(),
6071  operate_parameters::mode_from_flags(flags),
6072  operate_parameters::durability_from_flags(flags),
6073  operate_parameters::reclaiming_from_flags(flags),
6074  operate_parameters::options_from_flags(flags));
6075 }
6076 
6077 inline env::mode env::get_mode() const {
6078  return operate_parameters::mode_from_flags(get_flags());
6079 }
6080 
6083 }
6084 
6087 }
6088 
6090  return env::operate_parameters::options_from_flags(get_flags());
6091 }
6092 
6093 inline env::stat env::get_stat() const {
6094  env::stat r;
6095  error::success_or_throw(::mdbx_env_stat_ex(handle_, nullptr, &r, sizeof(r)));
6096  return r;
6097 }
6098 
6099 inline env::stat env::get_stat(const txn &txn) const {
6100  env::stat r;
6101  error::success_or_throw(::mdbx_env_stat_ex(handle_, txn, &r, sizeof(r)));
6102  return r;
6103 }
6104 
6105 inline env::info env::get_info() const {
6106  env::info r;
6107  error::success_or_throw(::mdbx_env_info_ex(handle_, nullptr, &r, sizeof(r)));
6108  return r;
6109 }
6110 
6111 inline env::info env::get_info(const txn &txn) const {
6112  env::info r;
6113  error::success_or_throw(::mdbx_env_info_ex(handle_, txn, &r, sizeof(r)));
6114  return r;
6115 }
6116 
6118  filehandle fd;
6119  error::success_or_throw(::mdbx_env_get_fd(handle_, &fd));
6120  return fd;
6121 }
6122 
6124  unsigned bits = 0;
6125  error::success_or_throw(::mdbx_env_get_flags(handle_, &bits));
6126  return MDBX_env_flags_t(bits);
6127 }
6128 
6129 inline unsigned env::max_readers() const {
6130  unsigned r;
6132  return r;
6133 }
6134 
6135 inline unsigned env::max_maps() const {
6136  unsigned r;
6138  return r;
6139 }
6140 
6141 inline void *env::get_context() const noexcept {
6142  return mdbx_env_get_userctx(handle_);
6143 }
6144 
6145 inline env &env::set_context(void *ptr) {
6147  return *this;
6148 }
6149 
6150 inline env &env::set_sync_threshold(size_t bytes) {
6152  return *this;
6153 }
6154 
6155 inline size_t env::sync_threshold() const {
6156  size_t bytes;
6157  error::success_or_throw(::mdbx_env_get_syncbytes(handle_, &bytes));
6158  return bytes;
6159 }
6160 
6161 inline env &env::set_sync_period__seconds_16dot16(unsigned seconds_16dot16) {
6162  error::success_or_throw(::mdbx_env_set_syncperiod(handle_, seconds_16dot16));
6163  return *this;
6164 }
6165 
6166 inline unsigned env::sync_period__seconds_16dot16() const {
6167  unsigned seconds_16dot16;
6168  error::success_or_throw(::mdbx_env_get_syncperiod(handle_, &seconds_16dot16));
6169  return seconds_16dot16;
6170 }
6171 
6173  return set_sync_period__seconds_16dot16(unsigned(seconds * 65536));
6174 }
6175 
6176 inline double env::sync_period__seconds_double() const {
6177  return sync_period__seconds_16dot16() / 65536.0;
6178 }
6179 
6180 #if __cplusplus >= 201103L
6181 inline env &env::set_sync_period(const duration &period) {
6182  return set_sync_period__seconds_16dot16(period.count());
6183 }
6184 
6185 inline duration env::sync_period() const {
6186  return duration(sync_period__seconds_16dot16());
6187 }
6188 #endif
6189 
6191  uint64_t value) {
6193  ::mdbx_env_set_option(handle_, ::MDBX_option_t(option), value));
6194  return *this;
6195 }
6196 
6197 inline uint64_t env::extra_option(enum env::extra_runtime_option option) const {
6198  uint64_t value;
6200  ::mdbx_env_get_option(handle_, ::MDBX_option_t(option), &value));
6201  return value;
6202 }
6203 
6205  error::success_or_throw(::mdbx_env_set_flags(handle_, flags, on_off));
6206  return *this;
6207 }
6208 
6209 inline env &env::set_geometry(const geometry &geo) {
6211  handle_, geo.size_lower, geo.size_now, geo.size_upper, geo.growth_step,
6212  geo.shrink_threshold, geo.pagesize));
6213  return *this;
6214 }
6215 
6216 inline bool env::sync_to_disk(bool force, bool nonblock) {
6217  const int err = ::mdbx_env_sync_ex(handle_, force, nonblock);
6218  switch (err) {
6219  case MDBX_SUCCESS /* flush done */:
6220  case MDBX_RESULT_TRUE /* no data pending for flush to disk */:
6221  return true;
6222  case MDBX_BUSY /* the environment is used by other thread */:
6223  return false;
6224  default:
6225  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6226  }
6227 }
6228 
6229 inline void env::close_map(const map_handle &handle) {
6230  error::success_or_throw(::mdbx_dbi_close(*this, handle.dbi));
6231 }
6232 
6235  uint64_t txnid, uint64_t lag, size_t used,
6236  size_t retained) noexcept
6237  : slot(slot), pid(pid), thread(thread), transaction_id(txnid),
6238  transaction_lag(lag), bytes_used(used), bytes_retained(retained) {}
6239 
6240 template <typename VISITOR>
6241 inline int env::enumerate_readers(VISITOR &visitor) {
6242  struct reader_visitor_thunk : public exception_thunk {
6243  VISITOR &visitor_;
6244  static int cb(void *ctx, int number, int slot, mdbx_pid_t pid,
6245  mdbx_tid_t thread, uint64_t txnid, uint64_t lag, size_t used,
6246  size_t retained) noexcept {
6247  reader_visitor_thunk *thunk = static_cast<reader_visitor_thunk *>(ctx);
6248  assert(thunk->is_clean());
6249  try {
6250  const reader_info info(slot, pid, thread, txnid, lag, used, retained);
6251  return loop_control(thunk->visitor_(info, number));
6252  } catch (... /* capture any exception to rethrow it over C code */) {
6253  thunk->capture();
6254  return loop_control::exit_loop;
6255  }
6256  }
6257  MDBX_CXX11_CONSTEXPR reader_visitor_thunk(VISITOR &visitor) noexcept
6258  : visitor_(visitor) {}
6259  };
6260  reader_visitor_thunk thunk(visitor);
6261  const auto rc = ::mdbx_reader_list(*this, thunk.cb, &thunk);
6262  thunk.rethrow_captured();
6263  return rc;
6264 }
6265 
6266 inline unsigned env::check_readers() {
6267  int dead_count;
6268  error::throw_on_failure(::mdbx_reader_check(*this, &dead_count));
6269  assert(dead_count >= 0);
6270  return static_cast<unsigned>(dead_count);
6271 }
6272 
6274  error::success_or_throw(::mdbx_env_set_hsr(handle_, cb));
6275  return *this;
6276 }
6277 
6278 inline MDBX_hsr_func *env::get_HandleSlowReaders() const noexcept {
6279  return ::mdbx_env_get_hsr(handle_);
6280 }
6281 
6283  ::MDBX_txn *ptr;
6285  ::mdbx_txn_begin(handle_, nullptr, MDBX_TXN_RDONLY, &ptr));
6286  assert(ptr != nullptr);
6287  return txn_managed(ptr);
6288 }
6289 
6291  ::MDBX_txn *ptr;
6293  ::mdbx_txn_begin(handle_, nullptr, MDBX_TXN_RDONLY_PREPARE, &ptr));
6294  assert(ptr != nullptr);
6295  return txn_managed(ptr);
6296 }
6297 
6298 inline txn_managed env::start_write(bool dont_wait) {
6299  ::MDBX_txn *ptr;
6301  handle_, nullptr, dont_wait ? MDBX_TXN_TRY : MDBX_TXN_READWRITE, &ptr));
6302  assert(ptr != nullptr);
6303  return txn_managed(ptr);
6304 }
6305 
6306 inline txn_managed env::try_start_write() { return start_write(true); }
6307 
6308 //------------------------------------------------------------------------------
6309 
6310 MDBX_CXX11_CONSTEXPR txn::txn(MDBX_txn *ptr) noexcept : handle_(ptr) {}
6311 
6312 inline txn &txn::operator=(txn &&other) noexcept {
6313  handle_ = other.handle_;
6314  other.handle_ = nullptr;
6315  return *this;
6316 }
6317 
6318 inline txn::txn(txn &&other) noexcept : handle_(other.handle_) {
6319  other.handle_ = nullptr;
6320 }
6321 
6322 inline txn::~txn() noexcept {
6323 #ifndef NDEBUG
6324  handle_ = reinterpret_cast<MDBX_txn *>(uintptr_t(0xDeadBeef));
6325 #endif
6326 }
6327 
6328 MDBX_CXX14_CONSTEXPR txn::operator bool() const noexcept {
6329  return handle_ != nullptr;
6330 }
6331 
6332 MDBX_CXX14_CONSTEXPR txn::operator const MDBX_txn *() const { return handle_; }
6333 
6334 MDBX_CXX14_CONSTEXPR txn::operator MDBX_txn *() { return handle_; }
6335 
6336 MDBX_CXX11_CONSTEXPR bool operator==(const txn &a, const txn &b) noexcept {
6337  return a.handle_ == b.handle_;
6338 }
6339 
6340 MDBX_CXX11_CONSTEXPR bool operator!=(const txn &a, const txn &b) noexcept {
6341  return a.handle_ != b.handle_;
6342 }
6343 
6344 inline void *txn::get_context() const noexcept {
6345  return mdbx_txn_get_userctx(handle_);
6346 }
6347 
6348 inline txn &txn::set_context(void *ptr) {
6350  return *this;
6351 }
6352 
6353 inline bool txn::is_dirty(const void *ptr) const {
6354  int err = ::mdbx_is_dirty(handle_, ptr);
6355  switch (err) {
6356  default:
6357  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6358  case MDBX_RESULT_TRUE:
6359  return true;
6360  case MDBX_RESULT_FALSE:
6361  return false;
6362  }
6363 }
6364 
6365 inline ::mdbx::env txn::env() const noexcept { return ::mdbx_txn_env(handle_); }
6366 
6368  const int bits = mdbx_txn_flags(handle_);
6370  return static_cast<MDBX_txn_flags_t>(bits);
6371 }
6372 
6373 inline uint64_t txn::id() const {
6374  const uint64_t txnid = mdbx_txn_id(handle_);
6376  return txnid;
6377 }
6378 
6379 inline void txn::reset_reading() {
6381 }
6382 
6383 inline void txn::renew_reading() {
6385 }
6386 
6387 inline txn::info txn::get_info(bool scan_reader_lock_table) const {
6388  txn::info r;
6389  error::success_or_throw(::mdbx_txn_info(handle_, &r, scan_reader_lock_table));
6390  return r;
6391 }
6392 
6394  MDBX_cursor *ptr;
6395  error::success_or_throw(::mdbx_cursor_open(handle_, map.dbi, &ptr));
6396  return cursor_managed(ptr);
6397 }
6398 
6399 inline size_t txn::release_all_cursors(bool unbind) const {
6400  int err = ::mdbx_txn_release_all_cursors(handle_, unbind);
6401  if (MDBX_UNLIKELY(err < 0))
6402  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6403  return size_t(err);
6404 }
6405 
6406 inline ::mdbx::map_handle
6409  ::mdbx::map_handle map;
6412  &map.dbi));
6413  assert(map.dbi != 0);
6414  return map;
6415 }
6416 
6417 inline ::mdbx::map_handle txn::open_map_accede(const char *name) const {
6418  ::mdbx::map_handle map;
6420  ::mdbx_dbi_open(handle_, name, MDBX_DB_ACCEDE, &map.dbi));
6421  assert(map.dbi != 0);
6422  return map;
6423 }
6424 
6425 inline ::mdbx::map_handle txn::create_map(const char *name,
6428  ::mdbx::map_handle map;
6430  handle_, name,
6432  &map.dbi));
6433  assert(map.dbi != 0);
6434  return map;
6435 }
6436 
6437 inline void txn::drop_map(map_handle map) {
6438  error::success_or_throw(::mdbx_drop(handle_, map.dbi, true));
6439 }
6440 
6441 inline void txn::clear_map(map_handle map) {
6442  error::success_or_throw(::mdbx_drop(handle_, map.dbi, false));
6443 }
6444 
6445 inline void txn::rename_map(map_handle map, const char *new_name) {
6446  error::success_or_throw(::mdbx_dbi_rename(handle_, map, new_name));
6447 }
6448 
6449 #if defined(DOXYGEN) || \
6450  (defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
6451 
6452 inline ::mdbx::map_handle
6453 txn::open_map(const ::std::string_view &name, const ::mdbx::key_mode key_mode,
6455  ::mdbx::map_handle map;
6457  handle_, ::mdbx::slice(name),
6459  assert(map.dbi != 0);
6460  return map;
6461 }
6462 
6463 inline ::mdbx::map_handle
6464 txn::open_map_accede(const ::std::string_view &name) const {
6465  ::mdbx::map_handle map;
6467  ::mdbx_dbi_open2(handle_, ::mdbx::slice(name), MDBX_DB_ACCEDE, &map.dbi));
6468  assert(map.dbi != 0);
6469  return map;
6470 }
6471 
6472 inline ::mdbx::map_handle txn::create_map(const ::std::string_view &name,
6475  ::mdbx::map_handle map;
6477  handle_, ::mdbx::slice(name),
6479  &map.dbi));
6480  assert(map.dbi != 0);
6481  return map;
6482 }
6483 
6484 inline void txn::rename_map(map_handle map,
6485  const ::std::string_view &new_name) {
6487  ::mdbx_dbi_rename2(handle_, map, ::mdbx::slice(new_name)));
6488 }
6489 
6490 inline ::mdbx::map_handle
6493  return open_map(::std::string_view(name), key_mode, value_mode);
6494 }
6495 
6496 inline ::mdbx::map_handle
6498  return open_map_accede(::std::string_view(name));
6499 }
6500 
6501 inline ::mdbx::map_handle txn::create_map(const ::std::string &name,
6504  return create_map(::std::string_view(name), key_mode, value_mode);
6505 }
6506 
6507 inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
6508  return drop_map(::std::string_view(name), throw_if_absent);
6509 }
6510 
6511 inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
6512  return clear_map(::std::string_view(name), throw_if_absent);
6513 }
6514 
6515 inline void txn::rename_map(map_handle map, const ::std::string &new_name) {
6516  return rename_map(map, ::std::string_view(new_name));
6517 }
6518 
6519 #else
6520 
6521 inline ::mdbx::map_handle
6524  return open_map(name.c_str(), key_mode, value_mode);
6525 }
6526 
6527 inline ::mdbx::map_handle
6529  return open_map_accede(name.c_str());
6530 }
6531 
6532 inline ::mdbx::map_handle txn::create_map(const ::std::string &name,
6535  return create_map(name.c_str(), key_mode, value_mode);
6536 }
6537 
6538 inline bool txn::drop_map(const ::std::string &name, bool throw_if_absent) {
6539  return drop_map(name.c_str(), throw_if_absent);
6540 }
6541 
6542 inline bool txn::clear_map(const ::std::string &name, bool throw_if_absent) {
6543  return clear_map(name.c_str(), throw_if_absent);
6544 }
6545 
6546 inline void txn::rename_map(map_handle map, const ::std::string &new_name) {
6547  return rename_map(map, new_name.c_str());
6548 }
6549 
6550 #endif /* __cpp_lib_string_view >= 201606L */
6551 
6553  txn::map_stat r;
6554  error::success_or_throw(::mdbx_dbi_stat(handle_, map.dbi, &r, sizeof(r)));
6555  return r;
6556 }
6557 
6558 inline uint32_t txn::get_tree_deepmask(map_handle map) const {
6559  uint32_t r;
6561  return r;
6562 }
6563 
6565  unsigned flags, state;
6567  ::mdbx_dbi_flags_ex(handle_, map.dbi, &flags, &state));
6569 }
6570 
6573  return *this;
6574 }
6575 
6577  txn::canary r;
6578  error::success_or_throw(::mdbx_canary_get(handle_, &r));
6579  return r;
6580 }
6581 
6582 inline uint64_t txn::sequence(map_handle map) const {
6583  uint64_t result;
6584  error::success_or_throw(::mdbx_dbi_sequence(handle_, map.dbi, &result, 0));
6585  return result;
6586 }
6587 
6588 inline uint64_t txn::sequence(map_handle map, uint64_t increment) {
6589  uint64_t result;
6591  ::mdbx_dbi_sequence(handle_, map.dbi, &result, increment));
6592  return result;
6593 }
6594 
6595 inline int txn::compare_keys(map_handle map, const slice &a,
6596  const slice &b) const noexcept {
6597  return ::mdbx_cmp(handle_, map.dbi, &a, &b);
6598 }
6599 
6600 inline int txn::compare_values(map_handle map, const slice &a,
6601  const slice &b) const noexcept {
6602  return ::mdbx_dcmp(handle_, map.dbi, &a, &b);
6603 }
6604 
6605 inline int txn::compare_keys(map_handle map, const pair &a,
6606  const pair &b) const noexcept {
6607  return compare_keys(map, a.key, b.key);
6608 }
6609 
6610 inline int txn::compare_values(map_handle map, const pair &a,
6611  const pair &b) const noexcept {
6612  return compare_values(map, a.value, b.value);
6613 }
6614 
6615 inline slice txn::get(map_handle map, const slice &key) const {
6616  slice result;
6617  error::success_or_throw(::mdbx_get(handle_, map.dbi, &key, &result));
6618  return result;
6619 }
6620 
6621 inline slice txn::get(map_handle map, slice key, size_t &values_count) const {
6622  slice result;
6624  ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count));
6625  return result;
6626 }
6627 
6628 inline slice txn::get(map_handle map, const slice &key,
6629  const slice &value_at_absence) const {
6630  slice result;
6631  const int err = ::mdbx_get(handle_, map.dbi, &key, &result);
6632  switch (err) {
6633  case MDBX_SUCCESS:
6634  return result;
6635  case MDBX_NOTFOUND:
6636  return value_at_absence;
6637  default:
6638  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6639  }
6640 }
6641 
6642 inline slice txn::get(map_handle map, slice key, size_t &values_count,
6643  const slice &value_at_absence) const {
6644  slice result;
6645  const int err = ::mdbx_get_ex(handle_, map.dbi, &key, &result, &values_count);
6646  switch (err) {
6647  case MDBX_SUCCESS:
6648  return result;
6649  case MDBX_NOTFOUND:
6650  return value_at_absence;
6651  default:
6652  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6653  }
6654 }
6655 
6657  const slice &key) const {
6658  pair result(key, slice());
6659  bool exact = !error::boolean_or_throw(
6660  ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value));
6661  return pair_result(result.key, result.value, exact);
6662 }
6663 
6664 inline pair_result
6666  const slice &value_at_absence) const {
6667  pair result{key, slice()};
6668  const int err =
6669  ::mdbx_get_equal_or_great(handle_, map.dbi, &result.key, &result.value);
6670  switch (err) {
6671  case MDBX_SUCCESS:
6672  return pair_result{result.key, result.value, true};
6673  case MDBX_RESULT_TRUE:
6674  return pair_result{result.key, result.value, false};
6675  case MDBX_NOTFOUND:
6676  return pair_result{key, value_at_absence, false};
6677  default:
6678  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6679  }
6680 }
6681 
6682 inline MDBX_error_t txn::put(map_handle map, const slice &key, slice *value,
6683  MDBX_put_flags_t flags) noexcept {
6684  return MDBX_error_t(::mdbx_put(handle_, map.dbi, &key, value, flags));
6685 }
6686 
6687 inline void txn::put(map_handle map, const slice &key, slice value,
6688  put_mode mode) {
6689  error::success_or_throw(put(map, key, &value, MDBX_put_flags_t(mode)));
6690 }
6691 
6692 inline void txn::insert(map_handle map, const slice &key, slice value) {
6694  put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
6696 }
6697 
6699  slice value) {
6700  const int err =
6701  put(map, key, &value /* takes the present value in case MDBX_KEYEXIST */,
6703  switch (err) {
6704  case MDBX_SUCCESS:
6705  return value_result{slice(), true};
6706  case MDBX_KEYEXIST:
6707  return value_result{value, false};
6708  default:
6709  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6710  }
6711 }
6712 
6714  size_t value_length) {
6715  slice result(nullptr, value_length);
6717  put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
6719  return result;
6720 }
6721 
6723  size_t value_length) {
6724  slice result(nullptr, value_length);
6725  const int err =
6726  put(map, key, &result /* takes the present value in case MDBX_KEYEXIST */,
6728  switch (err) {
6729  case MDBX_SUCCESS:
6730  return value_result{result, true};
6731  case MDBX_KEYEXIST:
6732  return value_result{result, false};
6733  default:
6734  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6735  }
6736 }
6737 
6738 inline void txn::upsert(map_handle map, const slice &key, const slice &value) {
6739  error::success_or_throw(put(map, key, const_cast<slice *>(&value),
6741 }
6742 
6744  size_t value_length) {
6745  slice result(nullptr, value_length);
6747  map, key, &result, MDBX_put_flags_t(put_mode::upsert) | MDBX_RESERVE));
6748  return result;
6749 }
6750 
6751 inline void txn::update(map_handle map, const slice &key, const slice &value) {
6752  error::success_or_throw(put(map, key, const_cast<slice *>(&value),
6754 }
6755 
6756 inline bool txn::try_update(map_handle map, const slice &key,
6757  const slice &value) {
6758  const int err = put(map, key, const_cast<slice *>(&value),
6760  switch (err) {
6761  case MDBX_SUCCESS:
6762  return true;
6763  case MDBX_NOTFOUND:
6764  return false;
6765  default:
6766  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6767  }
6768 }
6769 
6771  size_t value_length) {
6772  slice result(nullptr, value_length);
6774  map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE));
6775  return result;
6776 }
6777 
6779  size_t value_length) {
6780  slice result(nullptr, value_length);
6781  const int err =
6782  put(map, key, &result, MDBX_put_flags_t(put_mode::update) | MDBX_RESERVE);
6783  switch (err) {
6784  case MDBX_SUCCESS:
6785  return value_result{result, true};
6786  case MDBX_NOTFOUND:
6787  return value_result{slice(), false};
6788  default:
6789  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6790  }
6791 }
6792 
6793 inline bool txn::erase(map_handle map, const slice &key) {
6794  const int err = ::mdbx_del(handle_, map.dbi, &key, nullptr);
6795  switch (err) {
6796  case MDBX_SUCCESS:
6797  return true;
6798  case MDBX_NOTFOUND:
6799  return false;
6800  default:
6801  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6802  }
6803 }
6804 
6805 inline bool txn::erase(map_handle map, const slice &key, const slice &value) {
6806  const int err = ::mdbx_del(handle_, map.dbi, &key, &value);
6807  switch (err) {
6808  case MDBX_SUCCESS:
6809  return true;
6810  case MDBX_NOTFOUND:
6811  return false;
6812  default:
6813  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6814  }
6815 }
6816 
6817 inline void txn::replace(map_handle map, const slice &key, slice old_value,
6818  const slice &new_value) {
6820  handle_, map.dbi, &key, const_cast<slice *>(&new_value), &old_value,
6821  MDBX_CURRENT | MDBX_NOOVERWRITE, nullptr, nullptr));
6822 }
6823 
6824 template <class ALLOCATOR, typename CAPACITY_POLICY>
6828  &allocator) {
6829  typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
6830  error::success_or_throw(::mdbx_replace_ex(handle_, map.dbi, &key, nullptr,
6831  &result.slice_, MDBX_CURRENT,
6832  result, &result),
6833  result);
6834  return result;
6835 }
6836 
6837 template <class ALLOCATOR, typename CAPACITY_POLICY>
6839 txn::replace(map_handle map, const slice &key, const slice &new_value,
6841  &allocator) {
6842  typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
6844  ::mdbx_replace_ex(handle_, map.dbi, &key, const_cast<slice *>(&new_value),
6845  &result.slice_, MDBX_CURRENT, result, &result),
6846  result);
6847  return result;
6848 }
6849 
6850 template <class ALLOCATOR, typename CAPACITY_POLICY>
6852  map_handle map, const slice &key, slice &new_value,
6854  &allocator) {
6855  typename buffer<ALLOCATOR, CAPACITY_POLICY>::data_preserver result(allocator);
6857  ::mdbx_replace_ex(handle_, map.dbi, &key, &new_value, &result.slice_,
6858  MDBX_CURRENT | MDBX_RESERVE, result, &result),
6859  result);
6860  return result;
6861 }
6862 
6863 inline void txn::append(map_handle map, const slice &key, const slice &value,
6864  bool multivalue_order_preserved) {
6866  handle_, map.dbi, const_cast<slice *>(&key), const_cast<slice *>(&value),
6867  multivalue_order_preserved ? (MDBX_APPEND | MDBX_APPENDDUP)
6868  : MDBX_APPEND));
6869 }
6870 
6871 inline size_t txn::put_multiple(map_handle map, const slice &key,
6872  const size_t value_length,
6873  const void *values_array, size_t values_count,
6874  put_mode mode, bool allow_partial) {
6875  MDBX_val args[2] = {{const_cast<void *>(values_array), value_length},
6876  {nullptr, values_count}};
6877  const int err = ::mdbx_put(handle_, map.dbi, const_cast<slice *>(&key), args,
6879  switch (err) {
6880  case MDBX_SUCCESS:
6881  MDBX_CXX20_LIKELY break;
6882  case MDBX_KEYEXIST:
6883  if (allow_partial)
6884  break;
6885  mdbx_txn_break(handle_);
6886  MDBX_CXX17_FALLTHROUGH /* fallthrough */;
6887  default:
6888  MDBX_CXX20_UNLIKELY error::throw_exception(err);
6889  }
6890  return args[1].iov_len /* done item count */;
6891 }
6892 
6893 inline ptrdiff_t txn::estimate(map_handle map, const pair &from,
6894  const pair &to) const {
6895  ptrdiff_t result;
6897  handle_, map.dbi, &from.key, &from.value, &to.key, &to.value, &result));
6898  return result;
6899 }
6900 
6901 inline ptrdiff_t txn::estimate(map_handle map, const slice &from,
6902  const slice &to) const {
6903  ptrdiff_t result;
6904  error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr,
6905  &to, nullptr, &result));
6906  return result;
6907 }
6908 
6910  const slice &to) const {
6911  ptrdiff_t result;
6912  error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, nullptr,
6913  nullptr, &to, nullptr, &result));
6914  return result;
6915 }
6916 
6917 inline ptrdiff_t txn::estimate_to_last(map_handle map,
6918  const slice &from) const {
6919  ptrdiff_t result;
6920  error::success_or_throw(mdbx_estimate_range(handle_, map.dbi, &from, nullptr,
6921  nullptr, nullptr, &result));
6922  return result;
6923 }
6924 
6925 //------------------------------------------------------------------------------
6926 
6927 MDBX_CXX11_CONSTEXPR cursor::cursor(MDBX_cursor *ptr) noexcept : handle_(ptr) {}
6928 
6929 inline cursor_managed cursor::clone(void *your_context) const {
6930  cursor_managed clone(your_context);
6932  return clone;
6933 }
6934 
6935 inline void *cursor::get_context() const noexcept {
6936  return mdbx_cursor_get_userctx(handle_);
6937 }
6938 
6939 inline cursor &cursor::set_context(void *ptr) {
6941  return *this;
6942 }
6943 
6944 inline cursor &cursor::operator=(cursor &&other) noexcept {
6945  handle_ = other.handle_;
6946  other.handle_ = nullptr;
6947  return *this;
6948 }
6949 
6950 inline cursor::cursor(cursor &&other) noexcept : handle_(other.handle_) {
6951  other.handle_ = nullptr;
6952 }
6953 
6954 inline cursor::~cursor() noexcept {
6955 #ifndef NDEBUG
6956  handle_ = reinterpret_cast<MDBX_cursor *>(uintptr_t(0xDeadBeef));
6957 #endif
6958 }
6959 
6960 MDBX_CXX14_CONSTEXPR cursor::operator bool() const noexcept {
6961  return handle_ != nullptr;
6962 }
6963 
6964 MDBX_CXX14_CONSTEXPR cursor::operator const MDBX_cursor *() const {
6965  return handle_;
6966 }
6967 
6968 MDBX_CXX14_CONSTEXPR cursor::operator MDBX_cursor *() { return handle_; }
6969 
6971  const cursor &b) noexcept {
6972  return a.handle_ == b.handle_;
6973 }
6974 
6976  const cursor &b) noexcept {
6977  return a.handle_ != b.handle_;
6978 }
6979 
6980 inline int compare_position_nothrow(const cursor &left, const cursor &right,
6981  bool ignore_nested = false) noexcept {
6982  return mdbx_cursor_compare(left.handle_, right.handle_, ignore_nested);
6983 }
6984 
6985 inline int compare_position(const cursor &left, const cursor &right,
6986  bool ignore_nested = false) {
6987  const auto diff = compare_position_nothrow(left, right, ignore_nested);
6988  assert(compare_position_nothrow(right, left, ignore_nested) == -diff);
6989  if (MDBX_LIKELY(int16_t(diff) == diff))
6990  MDBX_CXX20_LIKELY return int(diff);
6991  else
6993 }
6994 
6996  bool throw_notfound)
6997  : pair_result() {
6998  done = cursor.move(get_current, &this->key, &this->value, throw_notfound);
6999 }
7000 
7002  move_operation operation,
7003  const slice &key, const slice &value,
7004  bool throw_notfound)
7005  : pair_result(key, value, false) {
7006  this->done = cursor.move(operation, &this->key, &this->value, throw_notfound);
7007 }
7008 
7009 inline bool cursor::move(move_operation operation, MDBX_val *key,
7010  MDBX_val *value, bool throw_notfound) const {
7011  const int err =
7012  ::mdbx_cursor_get(handle_, key, value, MDBX_cursor_op(operation));
7013  switch (err) {
7014  case MDBX_SUCCESS:
7015  MDBX_CXX20_LIKELY return true;
7016  case MDBX_RESULT_TRUE:
7017  return false;
7018  case MDBX_NOTFOUND:
7019  if (!throw_notfound)
7020  return false;
7021  MDBX_CXX17_FALLTHROUGH /* fallthrough */;
7022  default:
7023  MDBX_CXX20_UNLIKELY error::throw_exception(err);
7024  }
7025 }
7026 
7028  move_operation operation,
7029  const slice &key,
7030  const slice &value)
7031  : pair(key, value), approximate_quantity(PTRDIFF_MIN) {
7032  approximate_quantity = cursor.estimate(operation, &this->key, &this->value);
7033 }
7034 
7035 inline ptrdiff_t cursor::estimate(move_operation operation, MDBX_val *key,
7036  MDBX_val *value) const {
7037  ptrdiff_t result;
7039  *this, key, value, MDBX_cursor_op(operation), &result));
7040  return result;
7041 }
7042 
7043 inline ptrdiff_t estimate(const cursor &from, const cursor &to) {
7044  ptrdiff_t result;
7045  error::success_or_throw(mdbx_estimate_distance(from, to, &result));
7046  return result;
7047 }
7048 
7049 inline cursor::move_result cursor::find(const slice &key, bool throw_notfound) {
7050  return move(key_exact, key, throw_notfound);
7051 }
7052 
7054  bool throw_notfound) {
7055  return move(key_lowerbound, key, throw_notfound);
7056 }
7057 
7059  const slice &value,
7060  bool throw_notfound) {
7061  return move(multi_find_pair, key, value, throw_notfound);
7062 }
7063 
7065  const slice &value,
7066  bool throw_notfound) {
7067  return move(multi_exactkey_lowerboundvalue, key, value, throw_notfound);
7068 }
7069 
7070 inline bool cursor::seek(const slice &key) {
7071  return move(seek_key, const_cast<slice *>(&key), nullptr, false);
7072 }
7073 
7074 inline size_t cursor::count_multivalue() const {
7075  size_t result;
7076  error::success_or_throw(::mdbx_cursor_count(*this, &result));
7077  return result;
7078 }
7079 
7080 inline bool cursor::eof() const {
7081  return error::boolean_or_throw(::mdbx_cursor_eof(*this));
7082 }
7083 
7084 inline bool cursor::on_first() const {
7086 }
7087 
7088 inline bool cursor::on_last() const {
7090 }
7091 
7092 inline bool cursor::on_first_multival() const {
7094 }
7095 
7096 inline bool cursor::on_last_multival() const {
7098 }
7099 
7101  const slice &value) const {
7102  return estimate_result(*this, multi_exactkey_lowerboundvalue, key, value);
7103 }
7104 
7106  return estimate_result(*this, key_lowerbound, key);
7107 }
7108 
7111  return estimate_result(*this, operation);
7112 }
7113 
7114 inline void cursor::renew(const ::mdbx::txn &txn) {
7116 }
7117 
7118 inline void cursor::bind(const ::mdbx::txn &txn,
7121 }
7122 
7123 inline void cursor::unbind() {
7125 }
7126 
7127 inline txn cursor::txn() const {
7130  return ::mdbx::txn(txn);
7131 }
7132 
7133 inline map_handle cursor::map() const {
7134  const MDBX_dbi dbi = ::mdbx_cursor_dbi(handle_);
7135  if (MDBX_UNLIKELY(dbi > MDBX_MAX_DBI))
7137  return map_handle(dbi);
7138 }
7139 
7140 inline MDBX_error_t cursor::put(const slice &key, slice *value,
7141  MDBX_put_flags_t flags) noexcept {
7142  return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
7143 }
7144 
7145 inline void cursor::insert(const slice &key, slice value) {
7147  put(key, &value /* takes the present value in case MDBX_KEYEXIST */,
7149 }
7150 
7151 inline value_result cursor::try_insert(const slice &key, slice value) {
7152  const int err =
7153  put(key, &value /* takes the present value in case MDBX_KEYEXIST */,
7155  switch (err) {
7156  case MDBX_SUCCESS:
7157  return value_result{slice(), true};
7158  case MDBX_KEYEXIST:
7159  return value_result{value, false};
7160  default:
7161  MDBX_CXX20_UNLIKELY error::throw_exception(err);
7162  }
7163 }
7164 
7165 inline slice cursor::insert_reserve(const slice &key, size_t value_length) {
7166  slice result(nullptr, value_length);
7168  put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
7170  return result;
7171 }
7172 
7174  size_t value_length) {
7175  slice result(nullptr, value_length);
7176  const int err =
7177  put(key, &result /* takes the present value in case MDBX_KEYEXIST */,
7179  switch (err) {
7180  case MDBX_SUCCESS:
7181  return value_result{result, true};
7182  case MDBX_KEYEXIST:
7183  return value_result{result, false};
7184  default:
7185  MDBX_CXX20_UNLIKELY error::throw_exception(err);
7186  }
7187 }
7188 
7189 inline void cursor::upsert(const slice &key, const slice &value) {
7190  error::success_or_throw(put(key, const_cast<slice *>(&value),
7192 }
7193 
7194 inline slice cursor::upsert_reserve(const slice &key, size_t value_length) {
7195  slice result(nullptr, value_length);
7198  return result;
7199 }
7200 
7201 inline void cursor::update(const slice &key, const slice &value) {
7202  error::success_or_throw(put(key, const_cast<slice *>(&value),
7204 }
7205 
7206 inline bool cursor::try_update(const slice &key, const slice &value) {
7207  const int err =
7208  put(key, const_cast<slice *>(&value), MDBX_put_flags_t(put_mode::update));
7209  switch (err) {
7210  case MDBX_SUCCESS:
7211  return true;
7212  case MDBX_NOTFOUND:
7213  return false;
7214  default:
7215  MDBX_CXX20_UNLIKELY error::throw_exception(err);
7216  }
7217 }
7218 
7219 inline slice cursor::update_reserve(const slice &key, size_t value_length) {
7220  slice result(nullptr, value_length);
7223  return result;
7224 }
7225 
7227  size_t value_length) {
7228  slice result(nullptr, value_length);
7229  const int err =
7231  switch (err) {
7232  case MDBX_SUCCESS:
7233  return value_result{result, true};
7234  case MDBX_NOTFOUND:
7235  return value_result{slice(), false};
7236  default:
7237  MDBX_CXX20_UNLIKELY error::throw_exception(err);
7238  }
7239 }
7240 
7241 inline bool cursor::erase(bool whole_multivalue) {
7242  const int err = ::mdbx_cursor_del(handle_, whole_multivalue ? MDBX_ALLDUPS
7243  : MDBX_CURRENT);
7244  switch (err) {
7245  case MDBX_SUCCESS:
7246  MDBX_CXX20_LIKELY return true;
7247  case MDBX_NOTFOUND:
7248  return false;
7249  default:
7250  MDBX_CXX20_UNLIKELY error::throw_exception(err);
7251  }
7252 }
7253 
7254 inline bool cursor::erase(const slice &key, bool whole_multivalue) {
7255  bool found = seek(key);
7256  return found ? erase(whole_multivalue) : found;
7257 }
7258 
7259 inline bool cursor::erase(const slice &key, const slice &value) {
7260  move_result data = find_multivalue(key, value, false);
7261  return data.done && erase();
7262 }
7263 
7265 } // namespace mdbx
7266 
7267 //------------------------------------------------------------------------------
7268 
7271 namespace std {
7272 
7275 
7276 inline string to_string(const ::mdbx::slice &value) {
7277  ostringstream out;
7278  out << value;
7279  return out.str();
7280 }
7281 
7282 template <class ALLOCATOR, typename CAPACITY_POLICY>
7283 inline string
7284 to_string(const ::mdbx::buffer<ALLOCATOR, CAPACITY_POLICY> &buffer) {
7285  ostringstream out;
7286  out << buffer;
7287  return out.str();
7288 }
7289 
7290 inline string to_string(const ::mdbx::pair &value) {
7291  ostringstream out;
7292  out << value;
7293  return out.str();
7294 }
7295 
7296 inline string to_string(const ::mdbx::env::geometry &value) {
7297  ostringstream out;
7298  out << value;
7299  return out.str();
7300 }
7301 
7302 inline string to_string(const ::mdbx::env::operate_parameters &value) {
7303  ostringstream out;
7304  out << value;
7305  return out.str();
7306 }
7307 
7308 inline string to_string(const ::mdbx::env::mode &value) {
7309  ostringstream out;
7310  out << value;
7311  return out.str();
7312 }
7313 
7314 inline string to_string(const ::mdbx::env::durability &value) {
7315  ostringstream out;
7316  out << value;
7317  return out.str();
7318 }
7319 
7320 inline string to_string(const ::mdbx::env::reclaiming_options &value) {
7321  ostringstream out;
7322  out << value;
7323  return out.str();
7324 }
7325 
7326 inline string to_string(const ::mdbx::env::operate_options &value) {
7327  ostringstream out;
7328  out << value;
7329  return out.str();
7330 }
7331 
7332 inline string to_string(const ::mdbx::env_managed::create_parameters &value) {
7333  ostringstream out;
7334  out << value;
7335  return out.str();
7336 }
7337 
7338 inline string to_string(const ::MDBX_log_level_t &value) {
7339  ostringstream out;
7340  out << value;
7341  return out.str();
7342 }
7343 
7344 inline string to_string(const ::MDBX_debug_flags_t &value) {
7345  ostringstream out;
7346  out << value;
7347  return out.str();
7348 }
7349 
7350 inline string to_string(const ::mdbx::error &value) {
7351  ostringstream out;
7352  out << value;
7353  return out.str();
7354 }
7355 
7356 inline string to_string(const ::MDBX_error_t &errcode) {
7357  return to_string(::mdbx::error(errcode));
7358 }
7359 
7360 template <> struct hash<::mdbx::slice> {
7361  MDBX_CXX14_CONSTEXPR size_t
7362  operator()(::mdbx::slice const &slice) const noexcept {
7363  return slice.hash_value();
7364  }
7365 };
7366 
7368 } // namespace std
7369 
7370 #if defined(__LCC__) && __LCC__ >= 126
7371 #pragma diagnostic pop
7372 #endif
7373 
7374 #ifdef _MSC_VER
7375 #pragma warning(pop)
7376 #endif
#define MDBX_CXX11_CONSTEXPR
Definition: mdbx.h:460
#define MDBX_MAYBE_UNUSED
Definition: mdbx.h:536
#define MDBX_CXX14_CONSTEXPR
Definition: mdbx.h:482
#define MDBX_NOTHROW_PURE_FUNCTION
The 'pure nothrow' function attribute for optimization.
Definition: mdbx.h:270
mode_t mdbx_mode_t
Definition: mdbx.h:211
int(* MDBX_preserve_func)(void *context, MDBX_val *target, const void *src, size_t bytes)
Definition: mdbx.h:4846
#define LIBMDBX_API
Definition: mdbx.h:648
#define LIBMDBX_API_TYPE
Definition: mdbx.h:659
struct iovec MDBX_val
Generic structure used for passing keys and data in and out of the database. .
Definition: mdbx.h:816
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)
LIBMDBX_API int mdbx_dbi_rename2(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *name)
Переименовает таблицу по DBI-хендлу.
LIBMDBX_VERINFO_API const struct MDBX_version_info mdbx_version
libmdbx version information
pthread_t mdbx_tid_t
Definition: mdbx.h:210
LIBMDBX_VERINFO_API const struct MDBX_build_info mdbx_build
libmdbx build information
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 database in the environment.
LIBMDBX_API MDBX_hsr_func * mdbx_env_get_hsr(const MDBX_env *env)
Gets current Handle-Slow-Readers callback used to resolve database full/overflow issue due to a reade...
struct MDBX_env MDBX_env
Opaque structure for a database environment.
Definition: mdbx.h:748
int mdbx_filehandle_t
Definition: mdbx.h:208
pid_t mdbx_pid_t
Definition: mdbx.h:209
@ MDBX_MAX_PAGESIZE
Definition: mdbx.h:830
@ MDBX_MAXDATASIZE
Definition: mdbx.h:824
@ MDBX_MAX_DBI
Definition: mdbx.h:821
@ MDBX_MIN_PAGESIZE
Definition: mdbx.h:827
libmdbx build information
Definition: mdbx.h:686
The fours integers markers (aka "canary") associated with the environment.
Definition: mdbx.h:4247
Latency of commit stages in 1/65536 of seconds units.
Definition: mdbx.h:3991
Information about the environment.
Definition: mdbx.h:2682
Statistics for a database in the environment.
Definition: mdbx.h:2634
Information about the transaction.
Definition: mdbx.h:3890
libmdbx version information
Definition: mdbx.h:669
LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, MDBX_put_flags_t flags)
Delete current key/data pair.
LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result, uint64_t increment)
Sequence generation for a database.
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 database.
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)
Сканирует таблицу с использованием передаваемого предиката, с уменьшением сопутствующих накладных рас...
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:1696
int() MDBX_cmp_func(const MDBX_val *a, const MDBX_val *b) noexcept
A callback function used to compare two keys in a database.
Definition: mdbx.h:4307
LIBMDBX_API int mdbx_cursor_scan_from(MDBX_cursor *cursor, MDBX_predicate_func *predicate, void *context, MDBX_cursor_op from_op, MDBX_val *from_key, MDBX_val *from_value, MDBX_cursor_op turn_op, void *arg)
LIBMDBX_API int mdbx_cmp(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a, const MDBX_val *b)
Compare two keys according to a particular database.
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, const MDBX_val *data)
Delete items from a database.
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 database and optionally number of data items for a given key.
LIBMDBX_API int mdbx_cursor_count(const MDBX_cursor *cursor, size_t *pcount)
Return count of duplicates for current 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 database.
LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del)
Empty or delete and close a database.
LIBMDBX_API int mdbx_dcmp(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a, const MDBX_val *b)
Compare two data items according to a particular database.
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 database.
@ MDBX_MULTIPLE
Definition: mdbx.h:1733
@ MDBX_ALLDUPS
Definition: mdbx.h:1716
@ MDBX_CURRENT
Definition: mdbx.h:1711
@ MDBX_APPENDDUP
Definition: mdbx.h:1729
@ MDBX_APPEND
Definition: mdbx.h:1724
@ MDBX_UPSERT
Definition: mdbx.h:1698
@ MDBX_RESERVE
Definition: mdbx.h:1720
@ MDBX_NOOVERWRITE
Definition: mdbx.h:1701
LIBMDBX_API int mdbx_cursor_on_first_dup(const MDBX_cursor *cursor)
Определяет стоит ли курсор на первом или единственном мульти-значении соответствующем ключу.
LIBMDBX_API MDBX_txn * mdbx_cursor_txn(const MDBX_cursor *cursor)
Return the cursor's transaction handle.
LIBMDBX_API MDBX_cursor * mdbx_cursor_create(void *context)
Create a cursor handle but not bind it to transaction nor DBI-handle.
LIBMDBX_API int mdbx_cursor_renew(const MDBX_txn *txn, MDBX_cursor *cursor)
Renew a cursor handle for use within the given transaction.
LIBMDBX_API int mdbx_cursor_unbind(MDBX_cursor *cursor)
Unbind cursor from a transaction.
LIBMDBX_API void * mdbx_cursor_get_userctx(const MDBX_cursor *cursor)
Get the application information associated with the MDBX_cursor.
LIBMDBX_API MDBX_dbi mdbx_cursor_dbi(const MDBX_cursor *cursor)
Return the cursor's database handle.
MDBX_cursor_op
Cursor operationsThis is the set of all operations for retrieving data using a cursor.
Definition: mdbx.h:1766
LIBMDBX_API int mdbx_cursor_compare(const MDBX_cursor *left, const MDBX_cursor *right, bool ignore_multival)
Сравнивает позицию курсоров.
LIBMDBX_API int mdbx_cursor_on_last_dup(const MDBX_cursor *cursor)
Определяет стоит ли курсор на последнем или единственном мульти-значении соответствующем ключу.
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.
struct MDBX_cursor MDBX_cursor
Opaque structure for navigating through a database.
Definition: mdbx.h:778
LIBMDBX_API int mdbx_cursor_set_userctx(MDBX_cursor *cursor, void *ctx)
Set application information associated with the cursor.
LIBMDBX_API int mdbx_cursor_open(const 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_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_bind(const MDBX_txn *txn, MDBX_cursor *cursor, MDBX_dbi dbi)
Bind cursor to specified transaction and DBI-handle.
LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor)
Close a cursor handle.
LIBMDBX_API int mdbx_txn_release_all_cursors(const MDBX_txn *txn, bool unbind)
Unbind or closes all cursors of a given transaction.
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_GET_CURRENT
Definition: mdbx.h:1781
@ MDBX_GET_BOTH
Definition: mdbx.h:1774
@ MDBX_TO_KEY_EQUAL
Definition: mdbx.h:1861
@ MDBX_GET_BOTH_RANGE
Definition: mdbx.h:1778
@ MDBX_SET_KEY
Definition: mdbx.h:1821
@ MDBX_FIRST_DUP
Definition: mdbx.h:1771
@ MDBX_TO_KEY_LESSER_OR_EQUAL
Definition: mdbx.h:1860
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN
Definition: mdbx.h:1871
@ MDBX_NEXT_NODUP
Definition: mdbx.h:1806
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL
Definition: mdbx.h:1868
@ MDBX_TO_EXACT_KEY_VALUE_EQUAL
Definition: mdbx.h:1869
@ MDBX_TO_PAIR_LESSER_OR_EQUAL
Definition: mdbx.h:1874
@ MDBX_SET_RANGE
Definition: mdbx.h:1824
@ MDBX_LAST_DUP
Definition: mdbx.h:1792
@ MDBX_PREV
Definition: mdbx.h:1809
@ MDBX_TO_PAIR_GREATER_OR_EQUAL
Definition: mdbx.h:1876
@ MDBX_TO_PAIR_GREATER_THAN
Definition: mdbx.h:1877
@ MDBX_LAST
Definition: mdbx.h:1789
@ MDBX_TO_KEY_LESSER_THAN
Definition: mdbx.h:1859
@ MDBX_PREV_DUP
Definition: mdbx.h:1812
@ MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN
Definition: mdbx.h:1867
@ MDBX_SET
Definition: mdbx.h:1818
@ MDBX_NEXT
Definition: mdbx.h:1795
@ MDBX_TO_KEY_GREATER_OR_EQUAL
Definition: mdbx.h:1862
@ MDBX_TO_PAIR_LESSER_THAN
Definition: mdbx.h:1873
@ MDBX_PREV_NODUP
Definition: mdbx.h:1815
@ MDBX_TO_PAIR_EQUAL
Definition: mdbx.h:1875
@ MDBX_NEXT_DUP
Definition: mdbx.h:1798
@ MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL
Definition: mdbx.h:1870
@ MDBX_TO_KEY_GREATER_THAN
Definition: mdbx.h:1863
@ MDBX_FIRST
Definition: mdbx.h:1768
LIBMDBX_API int mdbx_dbi_rename(MDBX_txn *txn, MDBX_dbi dbi, const char *name)
Переименовает таблицу по DBI-хендлу.
LIBMDBX_API int mdbx_dbi_close(MDBX_env *env, MDBX_dbi dbi)
Close a database 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 database in the environment.
uint32_t MDBX_dbi
A handle for an individual database (key-value spaces) in the environment.
Definition: mdbx.h:771
MDBX_db_flags_t
Database flags.
Definition: mdbx.h:1641
@ MDBX_INTEGERDUP
Definition: mdbx.h:1665
@ MDBX_DB_ACCEDE
Definition: mdbx.h:1683
@ MDBX_DB_DEFAULTS
Definition: mdbx.h:1643
@ MDBX_REVERSEKEY
Definition: mdbx.h:1646
@ MDBX_DUPFIXED
Definition: mdbx.h:1660
@ MDBX_INTEGERKEY
Definition: mdbx.h:1656
@ MDBX_REVERSEDUP
Definition: mdbx.h:1668
@ MDBX_CREATE
Definition: mdbx.h:1671
@ MDBX_DUPSORT
Definition: mdbx.h:1649
MDBX_log_level_t
Definition: mdbx.h:891
MDBX_debug_flags_t
Runtime debug flags.
Definition: mdbx.h:951
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:5999
MDBX_error_t
Errors and return codes.
Definition: mdbx.h:1889
@ MDBX_FIRST_LMDB_ERRCODE
Definition: mdbx.h:1903
@ MDBX_BAD_TXN
Definition: mdbx.h:1969
@ MDBX_LAST_LMDB_ERRCODE
Definition: mdbx.h:1983
@ MDBX_SUCCESS
Definition: mdbx.h:1891
@ MDBX_NOTFOUND
Definition: mdbx.h:1906
@ MDBX_RESULT_TRUE
Definition: mdbx.h:1897
@ MDBX_BUSY
Definition: mdbx.h:1987
@ MDBX_EINVAL
Definition: mdbx.h:2053
@ MDBX_ENOMEM
Definition: mdbx.h:2055
@ MDBX_FIRST_ADDED_ERRCODE
Definition: mdbx.h:1990
@ MDBX_RESULT_FALSE
Definition: mdbx.h:1894
@ MDBX_LAST_ADDED_ERRCODE
Definition: mdbx.h:2032
@ MDBX_KEYEXIST
Definition: mdbx.h:1900
LIBMDBX_API int mdbx_reader_check(MDBX_env *env, int *dead)
Check for stale entries in the reader lock table.
LIBMDBX_API MDBX_cmp_func * mdbx_get_keycmp(MDBX_db_flags_t flags)
Returns default internal key's comparator for given database flags.
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:2524
@ MDBX_ENV_JUST_DELETE
Just delete the environment's files and directory if any.
Definition: mdbx.h:2518
@ MDBX_ENV_ENSURE_UNUSED
Make sure that the environment is not being used by other processes, or return an error otherwise.
Definition: mdbx.h:2521
MDBX_env_flags_t
Environment flags.
Definition: mdbx.h:1089
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:2929
MDBX_option_t
MDBX environment extra runtime options.
Definition: mdbx.h:2161
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:2868
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:2265
@ MDBX_opt_txn_dp_limit
Controls the in-process limit of dirty pages for a write transaction.
Definition: mdbx.h:2261
@ 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:2364
@ MDBX_opt_max_db
Controls the maximum number of named databases for the environment.
Definition: mdbx.h:2170
@ MDBX_opt_merge_threshold_16dot16_percent
Controls the in-process threshold of semi-empty pages merge.
Definition: mdbx.h:2331
@ MDBX_opt_sync_bytes
Controls interprocess/shared threshold to force flush the data buffers to disk, if MDBX_SAFE_NOSYNC i...
Definition: mdbx.h:2193
@ MDBX_opt_spill_min_denominator
Controls the in-process how minimal part of the dirty pages should be spilled when necessary.
Definition: mdbx.h:2297
@ 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:2320
@ 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:2233
@ 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:2220
@ MDBX_opt_max_readers
Defines the maximum number of threads/reader slots for all processes interacting with the database.
Definition: mdbx.h:2187
@ MDBX_opt_spill_max_denominator
Controls the in-process how maximal part of the dirty pages may be spilled when necessary.
Definition: mdbx.h:2281
@ MDBX_opt_sync_period
Controls interprocess/shared relative period since the last unsteady commit to force flush the data b...
Definition: mdbx.h:2199
@ MDBX_opt_dp_reserve_limit
Controls the in-process limit of a pre-allocated memory items for dirty pages.
Definition: mdbx.h:2247
@ MDBX_opt_writethrough_threshold
Controls the choosing between use write-through disk writes and usual ones with followed flush by the...
Definition: mdbx.h:2359
LIBMDBX_API int mdbx_dbi_stat(const MDBX_txn *txn, MDBX_dbi dbi, MDBX_stat *stat, size_t bytes)
Retrieve statistics for a database.
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 database flags, or -1 if pagesize is inval...
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:3584
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:2949
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 database flags.
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_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:2886
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 overflow/large-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 database.
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:4541
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 overflow/large-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.
int mdbx_env_get_maxdbs(const MDBX_env *env, MDBX_dbi *dbs)
Get the maximum number of named databases for the environment.
Definition: mdbx.h:3629
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 database flags, or -1 if pagesize is invali...
LIBMDBX_API size_t mdbx_default_pagesize(void)
Returns the default size of database page for the current system.
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 database 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 database handle.
LIBMDBX_API int mdbx_txn_break(MDBX_txn *txn)
Marks transaction as broken.
LIBMDBX_API void * mdbx_txn_get_userctx(const MDBX_txn *txn)
Returns an application information (a context pointer) associated with the transaction.
LIBMDBX_API int mdbx_txn_set_userctx(MDBX_txn *txn, void *ctx)
Sets application information associated (a context pointer) with the transaction.
LIBMDBX_API MDBX_env * mdbx_txn_env(const MDBX_txn *txn)
Returns the transaction's MDBX_env.
LIBMDBX_API int mdbx_txn_flags(const MDBX_txn *txn)
Return the transaction's flags.
MDBX_txn_flags_t
Definition: mdbx.h:1558
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:3857
struct MDBX_txn MDBX_txn
Opaque structure for a transaction handle.
Definition: mdbx.h:759
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.
@ MDBX_TXN_RDONLY
Definition: mdbx.h:1569
@ MDBX_TXN_RDONLY_PREPARE
Definition: mdbx.h:1578
@ MDBX_TXN_READWRITE
Definition: mdbx.h:1563
@ MDBX_TXN_TRY
Definition: mdbx.h:1584
buffer(size_t head_room, const struct slice &src, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2397
env_managed(const char *pathname, const operate_parameters &, bool accede=true)
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++:2182
cursor_managed(void *your_context=nullptr)
Creates a new managed cursor with underlying object.
Definition: mdbx.h++:5147
~txn_managed() noexcept
txn_managed start_nested()
Start nested write transaction.
extra_runtime_option
Definition: mdbx.h++:4043
static buffer key_from(silo &&src) noexcept
Definition: mdbx.h++:3068
buffer & append_u64(uint_fast64_t u64)
Definition: mdbx.h++:3026
constexpr allocator_type get_allocator() const
Returns the associated allocator.
Definition: mdbx.h++:2167
bool drop_map(const ::std::string_view &name, bool throw_if_absent=false)
Drop key-value map.
env_managed(const char *pathname, const create_parameters &, const operate_parameters &, bool accede=true)
map_handle(const map_handle &) noexcept=default
void reserve_tailroom(size_t wanna_tailroom)
Reserves space after the payload.
Definition: mdbx.h++:2642
::MDBX_db_flags_t flags
Definition: mdbx.h++:3508
path get_path() const
Return the path that was used for opening the environment.
static buffer hex_decode(const ::mdbx::slice &source, bool ignore_spaces=false, const allocator_type &allocator=allocator_type())
Decodes hexadecimal dump from the slice content to returned buffer.
Definition: mdbx.h++:2575
int64_t as_int64_adapt() const
Definition: mdbx.h++:2498
move_result to_exact_key_value_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5008
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to const pointer to byte an end of data.
Definition: mdbx.h++:2213
buffer encode_base64(unsigned wrap_width=0, const allocator_type &allocator=allocator_type()) const
Returns a new buffer with a Base64 dump of the slice content.
Definition: mdbx.h++:2568
static buffer key_from(const double *ieee754_64bit)
Definition: mdbx.h++:3080
static buffer base58(const POD &pod, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base58 dump of the given pod.
Definition: mdbx.h++:2537
static bool remove(const ::std::wstring &pathname, const remove_mode mode=just_remove)
constexpr const char * end_char_ptr() const noexcept
Returns casted to const pointer to char an end of data.
Definition: mdbx.h++:2239
constexpr char * end_char_ptr() noexcept
Returns casted to pointer to char an end of data.
Definition: mdbx.h++:2254
buffer & assign(const buffer &src, bool make_reference=false)
Definition: mdbx.h++:2668
void reserve(size_t wanna_headroom, size_t wanna_tailroom)
Reserves storage space.
Definition: mdbx.h++:2624
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++:2203
cursor_managed & operator=(const cursor_managed &)=delete
void reserve_headroom(size_t wanna_headroom)
Reserves space before the payload.
Definition: mdbx.h++:2639
constexpr txn() noexcept=default
constexpr map_handle() noexcept
Definition: mdbx.h++:3501
env & copy(const char *destination, bool compactify, bool force_dynamic_size=false)
durability
Durability level.
Definition: mdbx.h++:3659
@ lazy_weak_tail
Definition: mdbx.h++:3662
@ robust_synchronous
Definition: mdbx.h++:3660
@ half_synchronous_weak_last
Definition: mdbx.h++:3661
constexpr buffer(const buffer &src, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2357
::std::allocator_traits< allocator_type > allocator_traits
Definition: mdbx.h++:1653
constexpr byte operator[](size_t n) const noexcept
Accesses the specified byte of data chunk.
Definition: mdbx.h++:2839
static buffer base64_decode(const ::mdbx::slice &source, bool ignore_spaces=false, const allocator_type &allocator=allocator_type())
Decodes Base64 dump from the slice content to returned buffer.
Definition: mdbx.h++:2594
duration sync_period() const
Gets relative period since the last unsteady commit that used to force flush the data buffers to disk...
buffer(const ::std::basic_string_view< CHAR, T > &view, bool make_reference, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2345
constexpr int32_t as_int32() const
Definition: mdbx.h++:2483
constexpr void swap(buffer &other) noexcept(swap_alloc::is_nothrow())
Definition: mdbx.h++:2658
estimate_result estimate(move_operation operation, slice &key) const
uint16_t as_uint16_adapt() const
Definition: mdbx.h++:2492
constexpr char * char_ptr() noexcept
Returns casted to pointer to char an address of data.
Definition: mdbx.h++:2246
static bool remove(const char *pathname, const remove_mode mode=just_remove)
constexpr size_t headroom() const noexcept
Returns the number of bytes that available in currently allocated storage ahead the currently beginni...
Definition: mdbx.h++:2196
move_result to_pair_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5038
constexpr buffer & set_length(size_t bytes)
Set length of data.
Definition: mdbx.h++:2293
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from the data chunk.
Definition: mdbx.h++:2835
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from the data chunk.
Definition: mdbx.h++:2831
bool is_readwrite() const
Checks whether the transaction is read-write.
Definition: mdbx.h++:4340
move_result move(move_operation operation, const slice &key, const slice &value, bool throw_notfound)
Definition: mdbx.h++:4938
buffer & assign(const void *begin, const void *end, bool make_reference=false)
Definition: mdbx.h++:2697
static buffer key_from(const ::std::basic_string< CHAR, T, A > &src, bool make_reference=false)
Definition: mdbx.h++:3063
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.
buffer & assign_reference(const void *ptr, size_t bytes)
Definition: mdbx.h++:2644
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++:5030
buffer base64_decode(bool ignore_spaces=false, const allocator_type &allocator=allocator_type()) const
Decodes Base64 dump from the buffer content to new returned buffer.
Definition: mdbx.h++:2618
bool clear_map(const char *name, bool throw_if_absent=false)
constexpr env() noexcept=default
buffer & assign_freestanding(const void *ptr, size_t bytes)
Definition: mdbx.h++:2650
uint8_t as_uint8_adapt() const
Definition: mdbx.h++:2493
move_result to_pair_exact(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5042
buffer & operator=(const ::std::basic_string_view< CHAR, T > &view) noexcept
Definition: mdbx.h++:2744
buffer & operator=(struct slice &&src)
Definition: mdbx.h++:2739
buffer encode_base58(unsigned wrap_width=0, const allocator_type &allocator=allocator_type()) const
Returns a new buffer with a Base58 dump of the slice content.
Definition: mdbx.h++:2560
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition: mdbx.h++:2772
size_t put_multiple(map_handle map, const slice &key, const VALUE *values_array, size_t values_count, put_mode mode, bool allow_partial=false)
Definition: mdbx.h++:4614
typename ::std::allocator_traits< ALLOCATOR >::template rebind_alloc< uint64_t > allocator_type
Definition: mdbx.h++:1649
constexpr const byte * byte_ptr() const noexcept
Returns casted to const pointer to byte an address of data.
Definition: mdbx.h++:2208
buffer(size_t head_room, const buffer &src, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2406
constexpr ::std::span< const POD > as_span() const
Definition: mdbx.h++:2434
env_managed(const ::mdbx::filesystem::path &pathname, const operate_parameters &, bool accede=true)
Open existing database.
constexpr int16_t as_int16() const
Definition: mdbx.h++:2484
static buffer key_from_jsonInteger(const int64_t json_integer)
Definition: mdbx.h++:3100
static buffer hex(const POD &pod, bool uppercase=false, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a hexadecimal dump of the given pod.
Definition: mdbx.h++:2528
constexpr ::std::span< const byte > bytes() const
Definition: mdbx.h++:2441
buffer & assign(const struct slice &src, bool make_reference=false)
Definition: mdbx.h++:2677
env & copy(const ::std::string &destination, bool compactify, bool force_dynamic_size=false)
static bool remove(const ::std::string &pathname, const remove_mode mode=just_remove)
constexpr map_handle(MDBX_dbi dbi) noexcept
Definition: mdbx.h++:3502
move_result current(bool throw_notfound=true) const
Definition: mdbx.h++:4962
constexpr void * data() noexcept
Return a pointer to the beginning of the referenced data.
Definition: mdbx.h++:2270
move_result to_previous_last_multi(bool throw_notfound=true)
Definition: mdbx.h++:4953
static buffer key_from(const float ieee754_32bit)
Definition: mdbx.h++:3108
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.
buffer & assign(::MDBX_val &&src, bool make_reference=false)
Definition: mdbx.h++:2691
bool drop_map(const char *name, bool throw_if_absent=false)
Drops key-value map using name.
bool is_same_or_after_than(const cursor &other, bool ignore_nested=false) const
Definition: mdbx.h++:4752
size_t unbind_all_cursors() const
Unbind all cursors.
Definition: mdbx.h++:4378
static buffer hex(const ::mdbx::slice &source, bool uppercase=false, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a hexadecimal dump of the slice content.
Definition: mdbx.h++:2504
move_result to_key_greater_or_equal(const slice &key, bool throw_notfound=true)
Definition: mdbx.h++:4994
constexpr bool empty() const noexcept
Checks whether the string is empty.
Definition: mdbx.h++:2762
bool is_same_position(const cursor &other, bool ignore_nested=false) const
Definition: mdbx.h++:4744
buffer(const buffer &src, bool make_reference, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2325
bool is_after_than(const cursor &other, bool ignore_nested=false) const
Definition: mdbx.h++:4748
static buffer base58_decode(const ::mdbx::slice &source, bool ignore_spaces=false, const allocator_type &allocator=allocator_type())
Decodes Base58 dump from the slice content to returned buffer.
Definition: mdbx.h++:2585
uint32_t as_uint32_adapt() const
Definition: mdbx.h++:2491
buffer(size_t head_room, size_t tail_room, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2384
constexpr buffer() noexcept=default
static buffer key_from_double(const double ieee754_64bit)
Definition: mdbx.h++:3072
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from the data chunk.
Definition: mdbx.h++:2827
constexpr void * end() noexcept
Return a pointer to the end of the referenced data.
Definition: mdbx.h++:2278
static size_t default_pagesize() noexcept
Returns default page size for current system/platform.
Definition: mdbx.h++:3762
buffer & assign(const ::MDBX_val &src, bool make_reference=false)
Definition: mdbx.h++:2681
move_result to_next_first_multi(bool throw_notfound=true)
Definition: mdbx.h++:4971
void clear_and_reserve(size_t whole_capacity, size_t headroom=0) noexcept
Clears the contents and reserve storage.
Definition: mdbx.h++:2814
static buffer base64(const POD &pod, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base64 dump of the given pod.
Definition: mdbx.h++:2545
MDBX_txn * handle_
Definition: mdbx.h++:4302
bool starts_with(const struct slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition: mdbx.h++:2800
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition: mdbx.h++:2285
static buffer key_from_u64(const uint64_t unsigned_int64)
Definition: mdbx.h++:3084
move_result move(move_operation operation, const slice &key, bool throw_notfound)
Definition: mdbx.h++:4934
mode
Operation mode.
Definition: mdbx.h++:3652
@ readonly
Definition: mdbx.h++:3653
@ write_file_io
Definition: mdbx.h++:3654
move_result move(move_operation operation, bool throw_notfound)
Definition: mdbx.h++:4931
constexpr byte at(size_t n) const
Accesses the specified byte of data chunk with bounds checking.
Definition: mdbx.h++:2853
bool scan_from(CALLABLE_PREDICATE predicate, slice &from, move_operation start=key_greater_or_equal, move_operation turn=next)
Definition: mdbx.h++:4880
operator::mdbx::txn() const
Definition: mdbx.h++:5099
constexpr int8_t as_int8() const
Definition: mdbx.h++:2485
MDBX_env * handle_
Definition: mdbx.h++:3549
static buffer key_from(const ::std::basic_string_view< CHAR, T > &src, bool make_reference=false)
Definition: mdbx.h++:3052
move_result to_exact_key_value_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5018
commit_latency commit_get_latency()
Commit all the operations of a transaction into the database and return latency information.
Definition: mdbx.h++:4695
static buffer base58(const ::mdbx::slice &source, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base58 dump of the slice content.
Definition: mdbx.h++:2513
bool is_same_or_before_than(const cursor &other, bool ignore_nested=false) const
Definition: mdbx.h++:4739
bool ends_with(const struct slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition: mdbx.h++:2806
constexpr POD as_pod() const
Definition: mdbx.h++:2457
buffer & assign(const ::std::basic_string< CHAR, T, A > &str, bool make_reference=false)
Definition: mdbx.h++:2706
env_managed & operator=(const env_managed &)=delete
constexpr ::std::span< POD > as_span()
Definition: mdbx.h++:2437
static buffer key_from_float(const float ieee754_32bit)
Definition: mdbx.h++:3104
buffer(const struct slice &src, bool make_reference, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2318
move_result to_first(bool throw_notfound=true)
Definition: mdbx.h++:4947
buffer hex_decode(bool ignore_spaces=false, const allocator_type &allocator=allocator_type()) const
Decodes hexadecimal dump from the buffer content to new returned buffer.
Definition: mdbx.h++:2602
buffer & append_decoded_hex(const struct slice &data, bool ignore_spaces=false)
Definition: mdbx.h++:2954
move_result to_last(bool throw_notfound=true)
Definition: mdbx.h++:4977
buffer & append_byte(uint_fast8_t byte)
Definition: mdbx.h++:2977
constexpr buffer(const void *ptr, size_t bytes, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2361
buffer(const ::mdbx::txn &txn, const struct slice &src, const allocator_type &allocator=allocator_type())
constexpr const void * end() const noexcept
Return a const pointer to the end of the referenced data.
Definition: mdbx.h++:2265
void close()
Explicitly closes the cursor.
env & set_sync_period(const duration &period)
Sets relative period since the last unsteady commit to force flush the data buffers to disk,...
map_handle & operator=(const map_handle &) noexcept=default
constexpr buffer(const ::std::basic_string< CHAR, T, A > &str, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2367
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++:4991
constexpr byte * byte_ptr() noexcept
Returns casted to pointer to byte an address of data.
Definition: mdbx.h++:2220
constexpr const char * char_ptr() const noexcept
Returns casted to const pointer to char an address of data.
Definition: mdbx.h++:2234
constexpr ::std::span< char > chars()
Definition: mdbx.h++:2448
constexpr txn_managed() noexcept=default
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++:2174
static buffer key_from(const float *ieee754_32bit)
Definition: mdbx.h++:3112
buffer & append_u24(uint_fast32_t u24)
Definition: mdbx.h++:2989
constexpr buffer(const ::std::basic_string_view< CHAR, T > &view, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2379
env_managed & operator=(env_managed &&other) noexcept
Definition: mdbx.h++:4277
env_managed(const ::std::wstring &pathname, const operate_parameters &, bool accede=true)
buffer & append_decoded_base64(const struct slice &data, bool ignore_spaces=false)
Definition: mdbx.h++:2964
constexpr ::std::span< const char > chars() const
Definition: mdbx.h++:2445
buffer & append_base58(const struct slice &data, unsigned wrap_width=0)
Definition: mdbx.h++:2946
CAPACITY_POLICY reservation_policy
Definition: mdbx.h++:1654
buffer & append_u48(uint_fast64_t u48)
Definition: mdbx.h++:3012
remove_mode
Deletion modes for remove().
Definition: mdbx.h++:3891
buffer & assign(const void *ptr, size_t bytes, bool make_reference=false)
Definition: mdbx.h++:2672
static buffer key_from(const int64_t signed_int64)
Definition: mdbx.h++:3096
bool scan(CALLABLE_PREDICATE predicate, move_operation start=first, move_operation turn=next)
Definition: mdbx.h++:4849
move_result to_current_first_multi(bool throw_notfound=true)
Definition: mdbx.h++:4956
buffer & add_header(const void *src, size_t bytes)
Definition: mdbx.h++:2912
env & copy(const wchar_t *destination, bool compactify, bool force_dynamic_size=false)
bool scan_from(CALLABLE_PREDICATE predicate, pair &from, move_operation start=pair_greater_or_equal, move_operation turn=next)
Definition: mdbx.h++:4906
buffer & operator=(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition: mdbx.h++:2733
uint128_t as_uint128_adapt() const
Definition: mdbx.h++:2488
env & copy(filehandle fd, bool compactify, bool force_dynamic_size=false)
Copy an environment to the specified file descriptor.
::MDBX_dbi_state_t state
Definition: mdbx.h++:3509
env_managed(env_managed &&)=default
bool poll_sync_to_disk()
Performs non-blocking polling of sync-to-disk thresholds.
Definition: mdbx.h++:4100
constexpr uint32_t as_uint32() const
Definition: mdbx.h++:2469
cursor_managed(cursor_managed &&)=default
void commit(commit_latency &latency)
Commit all the operations of a transaction into the database and collect latency information.
Definition: mdbx.h++:4690
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++:3855
constexpr size_t hash_value() const noexcept
Returns the hash value of the data.
Definition: mdbx.h++:2781
move_result to_pair_lesser_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5034
constexpr ::std::basic_string< CHAR, T, A > as_string(const A &allocator=A()) const
Definition: mdbx.h++:2788
static buffer key_from_i32(const int32_t signed_int32)
Definition: mdbx.h++:3124
move_result to_key_lesser_than(const slice &key, bool throw_notfound=true)
Definition: mdbx.h++:4981
move_result to_next(bool throw_notfound=true)
Definition: mdbx.h++:4974
env_managed(const ::std::string &pathname, const operate_parameters &, bool accede=true)
size_t dbsize_max() const
Returns the maximal database size in bytes for the environment.
Definition: mdbx.h++:3851
buffer encode_hex(bool uppercase=false, unsigned wrap_width=0, const allocator_type &allocator=allocator_type()) const
Returns a new buffer with a hexadecimal dump of the slice content.
Definition: mdbx.h++:2551
static buffer wrap(const POD &pod, bool make_reference=false, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2452
buffer & append(const void *src, size_t bytes)
Definition: mdbx.h++:2900
static buffer key_from_u32(const uint32_t unsigned_int32)
Definition: mdbx.h++:3116
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from the data chunk.
Definition: mdbx.h++:2823
size_t close_all_cursors() const
Close all cursors.
Definition: mdbx.h++:4375
static buffer key_from(const uint32_t unsigned_int32)
Definition: mdbx.h++:3120
constexpr byte & operator[](size_t n) noexcept
Accesses the specified byte of data chunk.
Definition: mdbx.h++:2846
move_result to_key_greater_than(const slice &key, bool throw_notfound=true)
Definition: mdbx.h++:4998
buffer & append_decoded_base58(const struct slice &data, bool ignore_spaces=false)
Definition: mdbx.h++:2959
size_t get_pagesize() const
Returns pagesize of this MDBX environment.
Definition: mdbx.h++:3934
void make_freestanding()
Makes buffer owning the data.
Definition: mdbx.h++:2309
buffer & append_hex(const struct slice &data, bool uppercase=false, unsigned wrap_width=0)
Definition: mdbx.h++:2941
env_managed(const ::std::string &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
buffer(const char *c_str, bool make_reference, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2338
buffer & append_producer(PRODUCER &producer)
Definition: mdbx.h++:2926
constexpr buffer(const struct slice &src, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2351
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++:3866
buffer & append(const struct slice &chunk)
Definition: mdbx.h++:2908
int32_t as_int32_adapt() const
Definition: mdbx.h++:2499
constexpr const struct slice & slice() const noexcept
Definition: mdbx.h++:2416
constexpr ::std::span< byte > bytes()
Definition: mdbx.h++:2444
bool rename_map(const ::std::string &old_name, const ::std::string &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
buffer(const void *ptr, size_t bytes, bool make_reference, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2329
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.
constexpr byte & at(size_t n)
Accesses the specified byte of data chunk with bounds checking.
Definition: mdbx.h++:2857
move_result to_pair_greater_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5050
move_result upper_bound(const slice &key, bool throw_notfound=false)
move_operation
Definition: mdbx.h++:4763
@ multi_exactkey_lowerboundvalue
Definition: mdbx.h++:4778
@ seek_key
Definition: mdbx.h++:4780
@ key_lowerbound
Definition: mdbx.h++:4782
@ multi_find_pair
Definition: mdbx.h++:4777
@ key_exact
Definition: mdbx.h++:4781
@ get_current
Definition: mdbx.h++:4768
virtual ~env_managed() noexcept
bool move(move_operation operation, slice &key, slice &value, bool throw_notfound)
Definition: mdbx.h++:4942
static buffer key_from(const char(&text)[SIZE], bool make_reference=true)
Definition: mdbx.h++:3045
cursor_managed(const cursor_managed &)=delete
constexpr const void * data() const noexcept
Return a const pointer to the beginning of the referenced data.
Definition: mdbx.h++:2260
env_managed(const ::std::wstring &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
buffer & assign(struct slice &&src, bool make_reference=false)
Definition: mdbx.h++:2685
move_result to_current_prev_multi(bool throw_notfound=true)
Definition: mdbx.h++:4959
void shrink_to_fit()
Reduces memory usage by freeing unused storage space.
Definition: mdbx.h++:2819
int16_t as_int16_adapt() const
Definition: mdbx.h++:2500
static buffer key_from(const int32_t signed_int32)
Definition: mdbx.h++:3128
constexpr size_t operator()(::mdbx::slice const &slice) const noexcept
Definition: mdbx.h++:7362
void clear() noexcept
Clears the contents and storage.
Definition: mdbx.h++:2811
static buffer base64(const ::mdbx::slice &source, unsigned wrap_width=0, const allocator_type &allocator=allocator_type())
Returns a new buffer with a Base64 dump of the slice content.
Definition: mdbx.h++:2520
constexpr int64_t as_int64() const
Definition: mdbx.h++:2482
bool clear_map(const ::std::string_view &name, bool throw_if_absent=false)
move_result to_exact_key_value_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5014
bool rename_map(const char *old_name, const char *new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
env_managed(const env_managed &)=delete
static buffer key_from(const double ieee754_64bit)
Definition: mdbx.h++:3076
move_result to_current_last_multi(bool throw_notfound=true)
Definition: mdbx.h++:4968
constexpr uint128_t as_uint128() const
Definition: mdbx.h++:2462
constexpr cursor() noexcept=default
move_result to_key_lesser_or_equal(const slice &key, bool throw_notfound=true)
Definition: mdbx.h++:4984
static buffer key_from_i64(const int64_t signed_int64)
Definition: mdbx.h++:3092
buffer & append_u16(uint_fast16_t u16)
Definition: mdbx.h++:2979
move_result to_pair_greater_or_equal(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5046
uint64_t as_uint64_adapt() const
Definition: mdbx.h++:2490
size_t value_max(value_mode mode) const
Returns the maximal value size in bytes for specified values mode.
Definition: mdbx.h++:3861
MDBX_cursor * handle_
Definition: mdbx.h++:4711
buffer & operator=(const struct slice &src)
Definition: mdbx.h++:2737
constexpr byte * end_byte_ptr() noexcept
Returns casted to pointer to byte an end of data.
Definition: mdbx.h++:2228
~cursor_managed() noexcept
Definition: mdbx.h++:5169
constexpr uint8_t as_uint8() const
Definition: mdbx.h++:2475
buffer(buffer &&src) noexcept(move_assign_alloc::is_nothrow())
Definition: mdbx.h++:2413
MDBX_dbi dbi
Definition: mdbx.h++:3500
buffer(const ::std::basic_string< CHAR, T, A > &&)=delete
constexpr uint64_t as_uint64() const
Definition: mdbx.h++:2466
move_result to_exact_key_value_lesser_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5003
env & copy(const ::std::wstring &destination, bool compactify, bool force_dynamic_size=false)
static buffer key_from(const uint64_t unsigned_int64)
Definition: mdbx.h++:3088
move_result to_current_next_multi(bool throw_notfound=true)
Definition: mdbx.h++:4965
constexpr int128_t as_int128() const
Definition: mdbx.h++:2478
move_result upper_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
buffer(const ::std::basic_string< CHAR, T, A > &)=delete
buffer & append_u8(uint_fast8_t u8)
Definition: mdbx.h++:2969
constexpr uint16_t as_uint16() const
Definition: mdbx.h++:2472
size_t size_max() const
Returns maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
Definition: mdbx.h++:4348
buffer & assign(const char *c_str, bool make_reference=false)
Definition: mdbx.h++:2711
buffer & append_base64(const struct slice &data, unsigned wrap_width=0)
Definition: mdbx.h++:2950
cursor_managed & operator=(cursor_managed &&other) noexcept
Definition: mdbx.h++:5157
constexpr bool is_null() const noexcept
Checks whether the data pointer of the buffer is nullptr.
Definition: mdbx.h++:2767
move_result to_exact_key_value_greater_than(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:5024
txn_managed(const txn_managed &)=delete
buffer & add_header(const struct slice &chunk)
Definition: mdbx.h++:2921
static buffer clone(const buffer &src, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2663
buffer(size_t capacity, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2391
txn_managed & operator=(const txn_managed &)=delete
constexpr buffer(const ::std::span< POD > &span)
Definition: mdbx.h++:2426
buffer & append_u32(uint_fast32_t u32)
Definition: mdbx.h++:3000
size_t value_min(value_mode mode) const noexcept
Returns the minimal value size in bytes for specified values mode.
Definition: mdbx.h++:3857
int128_t as_int128_adapt() const
Definition: mdbx.h++:2496
env_managed(const ::mdbx::filesystem::path &pathname, const create_parameters &, const operate_parameters &, bool accede=true)
Create new or open existing database.
static buffer key_from(const char *src, bool make_reference=false)
Definition: mdbx.h++:3058
bool rename_map(const ::std::string_view &old_name, const ::std::string_view &new_name, bool throw_if_absent=false)
Переименовывает таблицу ключ-значение.
move_result to_key_equal(const slice &key, bool throw_notfound=true)
Definition: mdbx.h++:4988
constexpr buffer & set_end(const void *ptr)
Sets the length by specifying the end of the data.
Definition: mdbx.h++:2301
move_result to_previous(bool throw_notfound=true)
Definition: mdbx.h++:4950
buffer & append_producer(const PRODUCER &producer)
Definition: mdbx.h++:2934
constexpr buffer(const char *c_str, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:2372
void put_multiple(map_handle map, const slice &key, const ::std::vector< VALUE > &vector, put_mode mode)
Definition: mdbx.h++:4625
size_t key_min(key_mode mode) const noexcept
Returns the minimal key size in bytes for specified keys mode.
Definition: mdbx.h++:3853
int8_t as_int8_adapt() const
Definition: mdbx.h++:2501
buffer & operator=(const buffer &src)
Definition: mdbx.h++:2731
constexpr size_t capacity() const noexcept
Returns the number of bytes that can be held in currently allocated storage.
Definition: mdbx.h++:2189
size_t size_current() const
Returns current write transaction size (i.e.summary volume of dirty pages) in bytes.
Definition: mdbx.h++:4352
buffer base58_decode(bool ignore_spaces=false, const allocator_type &allocator=allocator_type()) const
Decodes Base58 dump from the buffer content to new returned buffer.
Definition: mdbx.h++:2610
constexpr env_managed() noexcept=default
bool fullscan(CALLABLE_PREDICATE predicate, bool backward=false)
Definition: mdbx.h++:4874
The chunk of data stored inside the buffer or located outside it.
Definition: mdbx.h++:1645
Unmanaged cursor.
Definition: mdbx.h++:4709
Managed cursor.
Definition: mdbx.h++:5138
Unmanaged database environment.
Definition: mdbx.h++:3545
Managed database environment.
Definition: mdbx.h++:4208
Unmanaged database transaction.
Definition: mdbx.h++:4299
Managed database transaction.
Definition: mdbx.h++:4646
static size_t key_min(MDBX_db_flags_t flags) noexcept
Returns the minimal key size in bytes for specified database flags.
Definition: mdbx.h++:5951
static constexpr intptr_t compare_fast(const pair &a, const pair &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition: mdbx.h++:5801
constexpr slice & set_end(const void *ptr)
Sets the length by specifying the end of the slice data.
Definition: mdbx.h++:5556
constexpr size_t size() const noexcept
Returns the number of bytes.
Definition: mdbx.h++:5569
constexpr slice safe_tail(size_t n) const
Returns the last "n" bytes of the slice.
Definition: mdbx.h++:5657
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base58(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base58 dump of the slice content.
Definition: mdbx.h++:5751
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++:6273
void * get_context() const noexcept
Returns the application context associated with the transaction.
Definition: mdbx.h++:6344
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 database flags.
Definition: mdbx.h++:5989
static constexpr intptr_t compare_fast(const slice &a, const slice &b) noexcept
Three-way fast non-lexicographically length-based comparison.
Definition: mdbx.h++:5671
constexpr MDBX_error_t code() const noexcept
Returns error code.
Definition: mdbx.h++:5331
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++:6817
value_mode
Kind of the values and sorted multi-values with corresponding comparison.
Definition: mdbx.h++:3399
constexpr const void * end() const noexcept
Return a pointer to the ending of the referenced data.
Definition: mdbx.h++:5539
MDBX_CXX11_CONSTEXPR_ENUM mdbx::key_mode key_mode() const noexcept
Definition: mdbx.h++:5863
constexpr slice safe_head(size_t n) const
Returns the first "n" bytes of the slice.
Definition: mdbx.h++:5651
void reset_reading()
Reset a read-only transaction.
Definition: mdbx.h++:6379
constexpr const char * char_ptr() const noexcept
Returns casted to pointer to char an address of data.
Definition: mdbx.h++:5519
void success_or_panic(const char *context_where, const char *func_who) const noexcept
Definition: mdbx.h++:5370
void rethrow_captured() const
Definition: mdbx.h++:5292
constexpr const void * data() const noexcept
Return a pointer to the beginning of the referenced data.
Definition: mdbx.h++:5535
move_result find_multivalue(const slice &key, const slice &value, bool throw_notfound=true)
Definition: mdbx.h++:7058
ptrdiff_t estimate(move_operation operation, MDBX_val *key, MDBX_val *value) const
Definition: mdbx.h++:7035
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++:6425
static size_t dbsize_max(intptr_t pagesize)
Returns the maximal database size in bytes for specified page size.
Definition: mdbx.h++:5944
::std::string::allocator_type legacy_allocator
Legacy allocator but it is recommended to use polymorphic_allocator.
Definition: mdbx.h++:359
value_result try_update_reserve(map_handle map, const slice &key, size_t value_length)
Definition: mdbx.h++:6778
value_result try_insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition: mdbx.h++:6722
void close_map(const map_handle &)
Close a key-value map (aka sub-database) handle. Normally unnecessary.
Definition: mdbx.h++:6229
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++:6150
move_result(const cursor &cursor, bool throw_notfound)
Definition: mdbx.h++:6995
constexpr bool operator!=(const error &a, const error &b) noexcept
Definition: mdbx.h++:5311
constexpr bool is_null() const noexcept
Checks whether the slice data pointer is nullptr.
Definition: mdbx.h++:5565
ptrdiff_t estimate_from_first(map_handle map, const slice &to) const
Definition: mdbx.h++:6909
void remove_suffix(size_t n) noexcept
Drops the last "n" bytes from this slice.
Definition: mdbx.h++:5594
slice & assign(const void *ptr, size_t bytes)
Definition: mdbx.h++:5452
env & operator=(env &&other) noexcept
Definition: mdbx.h++:5877
void unbind()
Unbind cursor from a transaction.
Definition: mdbx.h++:7123
constexpr const byte * end_byte_ptr() const noexcept
Returns casted to pointer to byte an end of data.
Definition: mdbx.h++:5507
slice insert_reserve(map_handle map, const slice &key, size_t value_length)
Definition: mdbx.h++:6713
string< ALLOCATOR > as_hex_string(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a hexadecimal dump of the slice content.
Definition: mdbx.h++:5724
void rename_map(map_handle map, const char *new_name)
Переименовывает таблицу ключ-значение.
Definition: mdbx.h++:6445
void throw_on_failure() const
Definition: mdbx.h++:5345
bool try_update(const slice &key, const slice &value)
Definition: mdbx.h++:7206
void update(const slice &key, const slice &value)
Definition: mdbx.h++:7201
constexpr info(map_handle::flags flags, map_handle::state state) noexcept
Definition: mdbx.h++:5858
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 sub-database).
Definition: mdbx.h++:6595
constexpr slice & set_length(size_t bytes)
Set slice length.
Definition: mdbx.h++:5551
txn & set_context(void *your_context)
Sets the application context associated with the transaction.
Definition: mdbx.h++:6348
env::durability get_durability() const
Returns current durability mode.
Definition: mdbx.h++:6081
uint64_t sequence(map_handle map) const
Definition: mdbx.h++:6582
void upsert(const slice &key, const slice &value)
Definition: mdbx.h++:7189
bool is_clean() const noexcept
Definition: mdbx.h++:5285
string< ALLOCATOR > as_base58_string(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition: mdbx.h++:5731
::std::pmr::string::allocator_type polymorphic_allocator
Default polymorphic allocator for modern code.
Definition: mdbx.h++:365
MDBX_CXX01_CONSTEXPR_ENUM bool is_reverse(key_mode mode) noexcept
Definition: mdbx.h++:3389
static bool boolean_or_throw(int error_code)
Definition: mdbx.h++:5391
void swap(slice &other) noexcept
Definition: mdbx.h++:5497
::mdbx_filehandle_t filehandle
Definition: mdbx.h++:390
env::operate_parameters get_operation_parameters() const
Returns current operation parameters.
Definition: mdbx.h++:6068
void bind(const ::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++:7118
MDBX_CXX01_CONSTEXPR_ENUM bool is_msgpack(key_mode mode) noexcept
Definition: mdbx.h++:3393
MDBX_env_flags_t get_flags() const
Returns environment flags.
Definition: mdbx.h++:6123
static size_t dbsize_min(intptr_t pagesize)
Returns the minimal database size in bytes for specified page size.
Definition: mdbx.h++:5937
constexpr slice tail(size_t n) const noexcept
Returns the last "n" bytes of the slice.
Definition: mdbx.h++:5641
constexpr error(MDBX_error_t error_code) noexcept
Definition: mdbx.h++:5299
constexpr const version_info & get_version() noexcept
Returns libmdbx version information.
Definition: mdbx.h++:5215
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++:6234
constexpr bool operator>(const slice &a, const slice &b) noexcept
Definition: mdbx.h++:5703
void insert(const slice &key, slice value)
Definition: mdbx.h++:7145
move_result lower_bound_multivalue(const slice &key, const slice &value, bool throw_notfound=false)
Definition: mdbx.h++:7064
MDBX_CXX01_CONSTEXPR_ENUM bool is_usual(key_mode mode) noexcept
Definition: mdbx.h++:3377
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++:6278
constexpr slice() noexcept
Create an empty slice.
Definition: mdbx.h++:5429
cursor_managed clone(void *your_context=nullptr) const
Definition: mdbx.h++:6929
~cursor() noexcept
Definition: mdbx.h++:6954
~txn() noexcept
Definition: mdbx.h++:6322
size_t sync_threshold() const
Gets threshold used to force flush the data buffers to disk, for non-sync durability modes.
Definition: mdbx.h++:6155
txn_managed start_write(bool dont_wait=false)
Starts write (read-write) transaction.
Definition: mdbx.h++:6298
constexpr void invalidate() noexcept
Depletes content of slice and make it invalid.
Definition: mdbx.h++:5575
inline ::mdbx::txn txn() const
Returns the cursor's transaction.
Definition: mdbx.h++:7127
value_result try_insert_reserve(const slice &key, size_t value_length)
Definition: mdbx.h++:7173
static env::operate_options options_from_flags(MDBX_env_flags_t flags) noexcept
Definition: mdbx.h++:5929
map_handle map() const
Definition: mdbx.h++:7133
unsigned sync_period__seconds_16dot16() const
Gets relative period since the last unsteady commit that used to force flush the data buffers to disk...
Definition: mdbx.h++:6166
MDBX_CXX11_CONSTEXPR_ENUM mdbx::value_mode value_mode() const noexcept
Definition: mdbx.h++:5868
move_result find(const slice &key, bool throw_notfound=true)
Definition: mdbx.h++:7049
MDBX_CXX01_CONSTEXPR_ENUM bool is_multi(value_mode mode) noexcept
Definition: mdbx.h++:3472
void success_or_throw() const
Definition: mdbx.h++:5350
buffer< ALLOCATOR, CAPACITY_POLICY > encode_base64(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base64 dump of the slice content.
Definition: mdbx.h++:5758
void renew_reading()
Renew a read-only transaction.
Definition: mdbx.h++:6383
buffer< ALLOCATOR, CAPACITY_POLICY > base64_decode(bool ignore_spaces=false, const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from the slice content to returned buffer.
Definition: mdbx.h++:5779
constexpr bool ends_with(const slice &suffix) const noexcept
Checks if the data ends with the given suffix.
Definition: mdbx.h++:5611
bool sync_to_disk(bool force=true, bool nonblock=false)
Flush the environment data buffers.
Definition: mdbx.h++:6216
int compare_position(const cursor &left, const cursor &right, bool ignore_nested=false)
Definition: mdbx.h++:6985
constexpr bool operator==(const error &a, const error &b) noexcept
Definition: mdbx.h++:5307
size_t count_multivalue() const
Return count of duplicates for current key.
Definition: mdbx.h++:7074
constexpr bool starts_with(const slice &prefix) const noexcept
Checks if the data starts with the given prefix.
Definition: mdbx.h++:5606
static size_t pagesize_max() noexcept
Returns the maximal database page size in bytes.
Definition: mdbx.h++:5935
constexpr size_t hash_value() const noexcept
Returns the hash value of referenced data.
Definition: mdbx.h++:5618
bool is_dirty(const void *ptr) const
Checks whether the given data is on a dirty page.
Definition: mdbx.h++:6353
slice upsert_reserve(const slice &key, size_t value_length)
Definition: mdbx.h++:7194
env::mode get_mode() const
Returns current operation mode.
Definition: mdbx.h++:6077
MDBX_CXX01_CONSTEXPR_ENUM bool is_samelength(key_mode mode) noexcept
Definition: mdbx.h++:3385
void capture() noexcept
Definition: mdbx.h++:5287
inline ::mdbx::env env() const noexcept
Returns the transaction's environment.
Definition: mdbx.h++:6365
uint32_t get_tree_deepmask(map_handle map) const
Returns depth (bitmask) information of nested dupsort (multi-value) B+trees for given database.
Definition: mdbx.h++:6558
bool try_update(map_handle map, const slice &key, const slice &value)
Definition: mdbx.h++:6756
void safe_remove_prefix(size_t n)
Drops the first "n" bytes from this slice.
Definition: mdbx.h++:5588
comparator default_comparator(key_mode mode) noexcept
Definition: mdbx.h++:3523
slice insert_reserve(const slice &key, size_t value_length)
Definition: mdbx.h++:7165
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 database flags.
Definition: mdbx.h++:6011
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++:6161
ptrdiff_t estimate(map_handle map, const pair &from, const pair &to) const
Definition: mdbx.h++:6893
env::reclaiming_options get_reclaiming() const
Returns current reclaiming options.
Definition: mdbx.h++:6085
void drop_map(map_handle map)
Drops key-value map using handle.
Definition: mdbx.h++:6437
ptrdiff_t estimate_to_last(map_handle map, const slice &from) const
Definition: mdbx.h++:6917
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++:6863
constexpr bool operator<(const slice &a, const slice &b) noexcept
Definition: mdbx.h++:5698
env::operate_options get_options() const
Returns current operate options.
Definition: mdbx.h++:6089
buffer< ALLOCATOR, CAPACITY_POLICY > extract(map_handle map, const slice &key, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &allocator=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Removes and return a value of the key.
Definition: mdbx.h++:6826
cursor & set_context(void *your_context)
Sets the application context associated with the cursor.
Definition: mdbx.h++:6939
map_stat get_map_stat(map_handle map) const
Returns statistics for a sub-database.
Definition: mdbx.h++:6552
bool move(move_operation operation, MDBX_val *key, MDBX_val *value, bool throw_notfound) const
Definition: mdbx.h++:7009
static size_t value_min(MDBX_db_flags_t flags) noexcept
Returns the minimal values size in bytes for specified database flags.
Definition: mdbx.h++:5981
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 sub-database).
Definition: mdbx.h++:6600
static env::reclaiming_options reclaiming_from_flags(MDBX_env_flags_t flags) noexcept
Definition: mdbx.h++:5923
buffer< ALLOCATOR, CAPACITY_POLICY > encode_hex(bool uppercase=false, unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of the slice content.
Definition: mdbx.h++:5743
cursor & operator=(cursor &&other) noexcept
Definition: mdbx.h++:6944
txn & put_canary(const canary &)
Set integers markers (aka "canary") associated with the environment.
Definition: mdbx.h++:6571
slice upsert_reserve(map_handle map, const slice &key, size_t value_length)
Definition: mdbx.h++:6743
buffer< ALLOCATOR, CAPACITY_POLICY > hex_decode(bool ignore_spaces=false, const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from the slice content to returned buffer.
Definition: mdbx.h++:5765
constexpr slice head(size_t n) const noexcept
Returns the first "n" bytes of the slice.
Definition: mdbx.h++:5636
constexpr bool is_result_false() const noexcept
Definition: mdbx.h++:5323
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++:6172
constexpr slice safe_middle(size_t from, size_t n) const
Returns the middle "n" bytes of the slice.
Definition: mdbx.h++:5663
bool on_first() const
Definition: mdbx.h++:7084
string to_string(const ::MDBX_error_t &errcode)
Definition: mdbx.h++:7356
::std::basic_string< char, ::std::char_traits< char >, ALLOCATOR > string
Default single-byte string.
Definition: mdbx.h++:388
constexpr bool empty() const noexcept
Checks whether the slice is empty.
Definition: mdbx.h++:5561
bool eof() const
Definition: mdbx.h++:7080
int compare_position_nothrow(const cursor &left, const cursor &right, bool ignore_nested=false) noexcept
Definition: mdbx.h++:6980
MDBX_txn_flags_t flags() const
Returns transaction's flags.
Definition: mdbx.h++:6367
void * get_context() const noexcept
Returns the application context associated with the environment.
Definition: mdbx.h++:6141
MDBX_error_t put(const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition: mdbx.h++:7140
map_handle open_map_accede(const char *name) const
Open existing key-value map.
Definition: mdbx.h++:6417
txn_managed prepare_read() const
Creates but not start read transaction.
Definition: mdbx.h++:6290
void safe_remove_suffix(size_t n)
Drops the last "n" bytes from this slice.
Definition: mdbx.h++:5599
bool seek(const slice &key)
Definition: mdbx.h++:7070
env & alter_flags(MDBX_env_flags_t flags, bool on_off)
Alter environment flags.
Definition: mdbx.h++:6204
env & set_context(void *your_context)
Sets the application context associated with the environment.
Definition: mdbx.h++:6145
constexpr byte operator[](size_t n) const noexcept
Returns the nth byte in the referenced data.
Definition: mdbx.h++:5625
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++:6061
void clear_map(map_handle map)
Clear key-value map.
Definition: mdbx.h++:6441
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++:6190
bool is_base64(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base64 dump.
Definition: mdbx.h++:5795
void remove_prefix(size_t n) noexcept
Drops the first "n" bytes from this slice.
Definition: mdbx.h++:5582
value_result try_insert(const slice &key, slice value)
Definition: mdbx.h++:7151
static void throw_on_nullptr(const void *ptr, MDBX_error_t error_code)
Definition: mdbx.h++:5376
string< ALLOCATOR > as_base64_string(unsigned wrap_width=0, const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base58 dump of the slice content.
Definition: mdbx.h++:5737
put_mode
Key-value pairs put mode.
Definition: mdbx.h++:3531
static constexpr intptr_t compare_lexicographically(const pair &a, const pair &b) noexcept
Three-way lexicographically comparison.
Definition: mdbx.h++:5808
double sync_period__seconds_double() const
Gets relative period since the last unsteady commit that used to force flush the data buffers to disk...
Definition: mdbx.h++:6176
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 overflow/large-page for specified ...
Definition: mdbx.h++:6036
canary get_canary() const
Returns fours integers markers (aka "canary") associated with the environment.
Definition: mdbx.h++:6576
txn & operator=(txn &&other) noexcept
Definition: mdbx.h++:6312
bool erase(bool whole_multivalue=false)
Removes single key-value pair or all multi-values at the current cursor position.
Definition: mdbx.h++:7241
buffer< ALLOCATOR, CAPACITY_POLICY > replace_reserve(map_handle map, const slice &key, slice &new_value, const typename buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type &allocator=buffer< ALLOCATOR, CAPACITY_POLICY >::allocator_type())
Definition: mdbx.h++:6851
stat get_stat() const
Returns snapshot statistics about the MDBX environment.
Definition: mdbx.h++:6093
uint64_t id() const
Return the transaction's ID.
Definition: mdbx.h++:6373
value_result try_insert(map_handle map, const slice &key, slice value)
Definition: mdbx.h++:6698
constexpr bool is_mdbx_error() const noexcept
Returns true for MDBX's errors.
Definition: mdbx.h++:5333
constexpr bool operator>=(const slice &a, const slice &b) noexcept
Definition: mdbx.h++:5713
ptrdiff_t estimate(const cursor &from, const cursor &to)
Definition: mdbx.h++:7043
static constexpr intptr_t compare_lexicographically(const slice &a, const slice &b) noexcept
Three-way lexicographically comparison.
Definition: mdbx.h++:5681
slice update_reserve(map_handle map, const slice &key, size_t value_length)
Definition: mdbx.h++:6770
bool is_base58(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a Base58 dump.
Definition: mdbx.h++:5790
~env() noexcept
Definition: mdbx.h++:5887
loop_control
Loop control constants for readers enumeration functor and other cases.
Definition: mdbx.h++:3358
slice get(map_handle map, const slice &key) const
Get value by key from a key-value map (aka sub-database).
Definition: mdbx.h++:6615
constexpr bool is_failure() const noexcept
Definition: mdbx.h++:5327
constexpr void clear() noexcept
Makes the slice empty and referencing to nothing.
Definition: mdbx.h++:5577
void update(map_handle map, const slice &key, const slice &value)
Definition: mdbx.h++:6751
geometry & make_dynamic(intptr_t lower=minimal_value, intptr_t upper=maximal_value) noexcept
Definition: mdbx.h++:5915
constexpr byte at(size_t n) const
Returns the nth byte in the referenced data with bounds checking.
Definition: mdbx.h++:5630
key_mode
Kinds of the keys and corresponding modes of comparing it.
Definition: mdbx.h++:3361
txn_managed start_read() const
Starts read (read-only) transaction.
Definition: mdbx.h++:6282
bool on_last_multival() const
Definition: mdbx.h++:7096
unsigned max_maps() const
Returns the maximum number of named databases for the environment.
Definition: mdbx.h++:6135
void insert(map_handle map, const slice &key, slice value)
Definition: mdbx.h++:6692
::std::chrono::duration< unsigned, ::std::ratio< 1, 65536 > > duration
Duration in 1/65536 units of second.
Definition: mdbx.h++:432
unsigned max_readers() const
Returns the maximum number of threads/reader slots for the environment.
Definition: mdbx.h++:6129
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 database flags.
Definition: mdbx.h++:5959
int enumerate_readers(VISITOR &visitor)
Enumerate readers.
Definition: mdbx.h++:6241
void * get_context() const noexcept
Returns the application context associated with the cursor.
Definition: mdbx.h++:6935
cursor_managed open_cursor(map_handle map) const
Opens cursor for specified key-value map handle.
Definition: mdbx.h++:6393
MDBX_CXX01_CONSTEXPR_ENUM bool is_ordinal(key_mode mode) noexcept
Definition: mdbx.h++:3381
uint64_t extra_option(extra_runtime_option option) const
Gets the value of extra runtime options from an environment.
Definition: mdbx.h++:6197
constexpr const build_info & get_build() noexcept
Returns libmdbx build information.
Definition: mdbx.h++:5218
char8_t byte
Definition: mdbx.h++:317
bool on_first_multival() const
Definition: mdbx.h++:7092
MDBX_error_t put(map_handle map, const slice &key, slice *value, MDBX_put_flags_t flags) noexcept
Definition: mdbx.h++:6682
void panic_on_failure(const char *context_where, const char *func_who) const noexcept
Definition: mdbx.h++:5364
constexpr slice middle(size_t from, size_t n) const noexcept
Returns the middle "n" bytes of the slice.
Definition: mdbx.h++:5646
info get_info() const
Return snapshot information about the MDBX environment.
Definition: mdbx.h++:6105
void upsert(map_handle map, const slice &key, const slice &value)
Definition: mdbx.h++:6738
static size_t pagesize_min() noexcept
Returns the minimal database page size in bytes.
Definition: mdbx.h++:5933
constexpr bool operator<=(const slice &a, const slice &b) noexcept
Definition: mdbx.h++:5708
slice update_reserve(const slice &key, size_t value_length)
Definition: mdbx.h++:7219
move_result lower_bound(const slice &key, bool throw_notfound=false)
Definition: mdbx.h++:7053
::MDBX_cmp_func * comparator
Definition: mdbx.h++:3522
constexpr size_t length() const noexcept
Returns the number of bytes.
Definition: mdbx.h++:5549
polymorphic_allocator default_allocator
Definition: mdbx.h++:366
unsigned check_readers()
Checks for stale readers in the lock table and return number of cleared slots.
Definition: mdbx.h++:6266
bool erase(map_handle map, const slice &key)
Removes all values for given key.
Definition: mdbx.h++:6793
constexpr bool is_result_true() const noexcept
Definition: mdbx.h++:5319
bool on_last() const
Definition: mdbx.h++:7088
size_t put_multiple(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++:6871
#define MDBX_STD_FILESYSTEM_PATH
Defined if mdbx::filesystem::path is available.
Definition: mdbx.h++:405
constexpr const byte * byte_ptr() const noexcept
Returns casted to pointer to byte an address of data.
Definition: mdbx.h++:5503
buffer< ALLOCATOR, CAPACITY_POLICY > base58_decode(bool ignore_spaces=false, const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from the slice content to returned buffer.
Definition: mdbx.h++:5772
filehandle get_filehandle() const
Returns the file descriptor for the DXB file of MDBX environment.
Definition: mdbx.h++:6117
env & set_geometry(const geometry &size)
Set all size-related parameters of environment.
Definition: mdbx.h++:6209
map_handle::info get_handle_info(map_handle map) const
Returns information about key-value map (aka sub-database) handle.
Definition: mdbx.h++:6564
void renew(const ::mdbx::txn &txn)
Renew/bind a cursor with a new transaction and previously used key-value map handle.
Definition: mdbx.h++:7114
geometry & make_fixed(intptr_t size) noexcept
Definition: mdbx.h++:5909
size_t release_all_cursors(bool unbind) const
Unbind or close all cursors.
Definition: mdbx.h++:6399
constexpr bool is_success() const noexcept
Definition: mdbx.h++:5315
value_result try_update_reserve(const slice &key, size_t value_length)
Definition: mdbx.h++:7226
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++:6407
::mdbx::filesystem::path path
Definition: mdbx.h++:413
txn_managed try_start_write()
Tries to start write (read-write) transaction without blocking.
Definition: mdbx.h++:6306
bool is_hex(bool ignore_spaces=false) const noexcept
Checks whether the content of the slice is a hexadecimal dump.
Definition: mdbx.h++:5785
info get_info(bool scan_reader_lock_table=false) const
Returns information about the MDBX transaction.
Definition: mdbx.h++:6387
pair_result get_equal_or_great(map_handle map, const slice &key) const
Get value for equal or great key from a database.
Definition: mdbx.h++:6656
constexpr const char * end_char_ptr() const noexcept
Returns casted to pointer to char an end of data.
Definition: mdbx.h++:5523
@ upsert
Insert or update.
Definition: mdbx.h++:3533
@ update
Update existing, don't insert new.
Definition: mdbx.h++:3534
@ insert_unique
Insert only unique keys.
Definition: mdbx.h++:3532
@ continue_loop
Definition: mdbx.h++:3358
@ exit_loop
Definition: mdbx.h++:3358
A handle for an individual database (key-value spaces) in the environment.
Definition: mdbx.h++:3499
::std::ostream & output(::std::ostream &out) const
Output Base58 dump of passed slice to the std::ostream.
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base58 dump of a passed slice.
Definition: mdbx.h++:1405
constexpr static slice wrap(const POD &pod)
Definition: mdbx.h++:766
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++:819
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from Base64 dump from a passed slice.
static constexpr slice wrap(const char(&text)[SIZE])
Definition: mdbx.h++:761
constexpr slice(const ::std::span< POD > &span)
Definition: mdbx.h++:708
constexpr slice(const ::std::basic_string< CHAR, T, A > &str)
Create a slice that refers to the contents of "str".
Definition: mdbx.h++:698
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a hexadecimal dump of a passed slice.
Definition: mdbx.h++:1345
const slice source
Definition: mdbx.h++:1439
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base58 dump, and therefore there could be dec...
constexpr ::std::span< const char > chars() const
Definition: mdbx.h++:741
int8_t as_int8_adapt() const
constexpr uint16_t as_uint16() const
Definition: mdbx.h++:1133
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base58 dump of passed slice.
Definition: mdbx.h++:1411
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from Base58 dump from a passed slice.
constexpr static slice invalid() noexcept
Build an invalid slice which non-zero length and refers to null address.
Definition: mdbx.h++:1109
constexpr uint32_t as_uint32() const
Definition: mdbx.h++:1132
buffer_pair_spec(buffer_pair_spec &&pair) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition: mdbx.h++:3321
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by Base64 dump of passed slice.
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by hexadecimal dump of a passed slice.
constexpr int64_t as_int64() const
Definition: mdbx.h++:1141
@ max_length
Definition: mdbx.h++:674
void swap(::std::basic_string_view< CHAR, T > &view) noexcept
Definition: mdbx.h++:949
pair_result & operator=(const pair_result &) noexcept=default
slice & operator=(const ::std::basic_string_view< CHAR, T > &view)
Definition: mdbx.h++:807
bool is_printable(bool disable_utf8=false) const noexcept
Checks whether the content of the slice is printable.
int128_t as_int128_adapt() const
constexpr int16_t as_int16() const
Definition: mdbx.h++:1143
slice value
Definition: mdbx.h++:3194
slice & assign(const ::std::basic_string< CHAR, T, ALLOCATOR > &str)
Definition: mdbx.h++:780
constexpr bool is_reference() const noexcept
Checks whether one of the buffers just refers to data located outside the buffer, rather than stores ...
Definition: mdbx.h++:3334
char * write_bytes(char *dest, size_t dest_size) const
Fills the buffer by Base58 dump of passed slice.
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition: mdbx.h++:1375
buffer_pair_spec(const slice &key, const slice &value, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3296
slice value
Definition: mdbx.h++:3210
::std::pair< buffer_type, buffer_type > stl_pair
Definition: mdbx.h++:3272
pair_result(const pair_result &) noexcept=default
const slice source
Definition: mdbx.h++:1549
const slice source
Definition: mdbx.h++:1334
constexpr static pair invalid() noexcept
Definition: mdbx.h++:3224
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++:1528
buffer_pair_spec(const txn &txn, const pair &pair, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3314
slice & assign(::std::basic_string_view< CHAR, T > &&view)
Definition: mdbx.h++:791
slice & assign(const ::std::basic_string_view< CHAR, T > &view)
Definition: mdbx.h++:787
constexpr bool is_freestanding() const noexcept
Checks whether data chunk stored inside the buffers both, otherwise at least one of buffers just refe...
Definition: mdbx.h++:3328
constexpr POD as_pod() const
Definition: mdbx.h++:1113
constexpr pair_result() noexcept
Definition: mdbx.h++:3253
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition: mdbx.h++:1636
constexpr uint128_t as_uint128() const
Definition: mdbx.h++:1127
uint16_t as_uint16_adapt() const
constexpr to_hex(const slice &source, bool uppercase=false, unsigned wrap_width=0) noexcept
Definition: mdbx.h++:1337
buffer_pair_spec(const slice &key, const slice &value, bool make_reference, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3299
std::pair< slice, slice > stl_pair
Definition: mdbx.h++:3209
value_result & operator=(const value_result &) noexcept=default
value_result(const value_result &) noexcept=default
constexpr slice(const slice &) noexcept=default
pair & operator=(const pair &) noexcept=default
slice & operator=(const slice &) noexcept=default
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned string.
Definition: mdbx.h++:1609
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base64 dump of a passed slice.
Definition: mdbx.h++:1450
constexpr from_base58(const slice &source, bool ignore_spaces=false) noexcept
Definition: mdbx.h++:1551
buffer_pair_spec(const stl_pair &pair, bool make_reference, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3292
buffer_type key
Definition: mdbx.h++:3273
constexpr int8_t as_int8() const
Definition: mdbx.h++:1144
constexpr slice(size_t invalid_length) noexcept
Definition: mdbx.h++:1163
constexpr size_t envisage_result_length() const noexcept
Returns the buffer size in bytes needed for Base64 dump of passed slice.
Definition: mdbx.h++:1465
static constexpr size_t round(const size_t value)
Definition: mdbx.h++:1300
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition: mdbx.h++:1429
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++:1625
value_result(const slice &value, bool done) noexcept
Definition: mdbx.h++:3196
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition: mdbx.h++:1587
const slice source
Definition: mdbx.h++:1385
constexpr pair(const stl_pair &couple) noexcept
Definition: mdbx.h++:3213
constexpr from_base64(const slice &source, bool ignore_spaces=false) noexcept
Definition: mdbx.h++:1600
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned string.
Definition: mdbx.h++:1514
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++:1379
uint8_t as_uint8_adapt() const
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++:1576
buffer_pair_spec(const txn &txn, const slice &key, const slice &value, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3311
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition: mdbx.h++:1539
int32_t as_int32_adapt() const
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes hexadecimal dump from a passed slice to returned buffer.
Definition: mdbx.h++:1522
constexpr pair_result(const slice &key, const slice &value, bool done) noexcept
Definition: mdbx.h++:3255
constexpr ::std::span< byte > bytes()
Definition: mdbx.h++:740
constexpr from_hex(const slice &source, bool ignore_spaces=false) noexcept
Definition: mdbx.h++:1506
buffer_pair_spec(const buffer_type &key, const buffer_type &value, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3280
constexpr ::std::span< POD > as_span()
Definition: mdbx.h++:727
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a string with a Base58 dump of a passed slice.
Definition: mdbx.h++:1396
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a Base64 dump of a passed slice.
Definition: mdbx.h++:1459
bool done
Definition: mdbx.h++:3252
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++:1433
buffer_pair_spec(const pair &pair, bool make_reference, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3307
constexpr ::std::basic_string< CHAR, T, ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Definition: mdbx.h++:835
void make_freestanding()
Makes buffers owning the data.
Definition: mdbx.h++:3340
constexpr to_base64(const slice &source, unsigned wrap_width=0) noexcept
Definition: mdbx.h++:1442
pair(const pair &) noexcept=default
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid Base64 dump, and therefore there could be dec...
uint128_t as_uint128_adapt() const
constexpr int128_t as_int128() const
Definition: mdbx.h++:1137
slice key
Definition: mdbx.h++:3210
constexpr pair(const slice &key, const slice &value) noexcept
Definition: mdbx.h++:3211
const slice source
Definition: mdbx.h++:1598
bool is_empty() const noexcept
Checks whether a passed slice is empty, and therefore there will be no output bytes.
Definition: mdbx.h++:1483
typename buffer_type::allocator_traits allocator_traits
Definition: mdbx.h++:3270
::std::ostream & output(::std::ostream &out) const
Output hexadecimal dump of passed slice to the std::ostream.
static constexpr size_t advise(const size_t current, const size_t wanna)
Definition: mdbx.h++:1311
constexpr int32_t as_int32() const
Definition: mdbx.h++:1142
string< ALLOCATOR > as_string(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned string.
Definition: mdbx.h++:1560
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Returns a buffer with a hexadecimal dump of a passed slice.
Definition: mdbx.h++:1353
constexpr ::std::span< const POD > as_span() const
Definition: mdbx.h++:716
int64_t as_int64_adapt() const
buffer_pair_spec(const stl_pair &pair, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3289
constexpr uint8_t as_uint8() const
Definition: mdbx.h++:1134
CAPACITY_POLICY reservation_policy
Definition: mdbx.h++:3271
constexpr ::std::span< char > chars()
Definition: mdbx.h++:744
constexpr uint64_t as_uint64() const
Definition: mdbx.h++:1131
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base64 dump from a passed slice to returned buffer.
Definition: mdbx.h++:1618
bool is_erroneous() const noexcept
Checks whether the content of a passed slice is a valid hexadecimal dump, and therefore there could b...
char * write_bytes(char *dest, size_t dest_size) const
Fills the destination with data decoded from hexadecimal dump from a passed slice.
::std::ostream & output(::std::ostream &out) const
Output Base64 dump of passed slice to the std::ostream.
constexpr ::std::span< const byte > bytes() const
Definition: mdbx.h++:737
uint32_t as_uint32_adapt() const
buffer_pair_spec(const pair &pair, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3304
slice & operator=(::std::basic_string_view< CHAR, T > &&view)
Definition: mdbx.h++:812
buffer_pair_spec(buffer_type &&key, buffer_type &&value) noexcept(buffer_type::move_assign_alloc::is_nothrow())
Definition: mdbx.h++:3318
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++:751
int16_t as_int16_adapt() const
typename buffer_type::allocator_type allocator_type
Definition: mdbx.h++:3269
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++:1487
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++:1388
buffer_pair_spec(const buffer_type &key, const buffer_type &value, bool make_reference, const allocator_type &allocator=allocator_type())
Definition: mdbx.h++:3283
slice(::std::basic_string_view< CHAR, T > &&sv)
Definition: mdbx.h++:755
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++:1359
bool done
Definition: mdbx.h++:3195
const slice source
Definition: mdbx.h++:1504
buffer< ALLOCATOR, CAPACITY_POLICY > as_buffer(const ALLOCATOR &allocator=ALLOCATOR()) const
Decodes Base58 dump from a passed slice to returned buffer.
Definition: mdbx.h++:1569
buffer< ALLOCATOR, CAPACITY_POLICY > make_buffer(PRODUCER &producer, const ALLOCATOR &allocator=ALLOCATOR())
Definition: mdbx.h++:3136
string< ALLOCATOR > make_string(PRODUCER &producer, const ALLOCATOR &allocator=ALLOCATOR())
Definition: mdbx.h++:3164
inline ::std::ostream & operator<<(::std::ostream &out, const to_hex &wrapper)
Definition: mdbx.h++:1490
ImmutableByteProducer C++20 concept.
MutableByteProducer C++20 concept.
SliceTranscoder C++20 concept.
Definition: mdbx.h++:3267
Definition: mdbx.h++:1293
Base58 decoder which satisfy SliceTranscoder concept.
Definition: mdbx.h++:1548
Base64 decoder which satisfy SliceTranscoder concept.
Definition: mdbx.h++:1597
Hexadecimal decoder which satisfy SliceTranscoder concept.
Definition: mdbx.h++:1503
Combines pair of slices for key and value to represent result of certain operations.
Definition: mdbx.h++:3208
Combines pair of slices for key and value with boolean flag to represent result of certain operations...
Definition: mdbx.h++:3251
References a data located outside the slice.
Definition: mdbx.h++:669
Base58 encoder which satisfy SliceTranscoder concept.
Definition: mdbx.h++:1384
Base64 encoder which satisfy SliceTranscoder concept.
Definition: mdbx.h++:1438
Hexadecimal encoder which satisfy SliceTranscoder concept.
Definition: mdbx.h++:1333
Combines data slice with boolean flag to represent result of certain operations.
Definition: mdbx.h++:3193
error & operator=(const error &)=default
fatal(exception &&src) noexcept
Definition: mdbx.h++:542
fatal(const ::mdbx::error &) noexcept
exception(const exception &)=default
void throw_exception() const
error & operator=(error &&)=default
fatal(const exception &src) noexcept
Definition: mdbx.h++:541
exception(exception &&)=default
error(const error &)=default
virtual ~fatal() noexcept
fatal(const fatal &src) noexcept
Definition: mdbx.h++:543
fatal & operator=(const fatal &)=default
fatal(fatal &&src) noexcept
Definition: mdbx.h++:544
exception_thunk() noexcept=default
exception(const ::mdbx::error &) noexcept
virtual ~exception() noexcept
error(error &&)=default
fatal & operator=(fatal &&)=default
Implements error information and throwing corresponding exceptions.
Definition: mdbx.h++:457
Base class for all libmdbx's exceptions that are corresponds to libmdbx errors.
Definition: mdbx.h++:520
Transfers C++ exceptions thru C callbacks.
Definition: mdbx.h++:442
Fatal exception that lead termination anyway in dangerous unrecoverable cases.
Definition: mdbx.h++:536
LIBMDBX_API void throw_allocators_mismatch()
#define MDBX_DECLARE_EXCEPTION(NAME)
Definition: mdbx.h++:550
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()
Definition: mdbx.h++:555
Definition: mdbx.h++:556
Definition: mdbx.h++:557
Definition: mdbx.h++:584
Definition: mdbx.h++:558
Definition: mdbx.h++:559
Definition: mdbx.h++:560
Definition: mdbx.h++:561
Definition: mdbx.h++:562
Definition: mdbx.h++:563
Definition: mdbx.h++:564
Definition: mdbx.h++:583
Definition: mdbx.h++:565
Definition: mdbx.h++:566
Definition: mdbx.h++:567
Definition: mdbx.h++:568
Definition: mdbx.h++:569
Definition: mdbx.h++:570
Definition: mdbx.h++:571
Definition: mdbx.h++:572
Definition: mdbx.h++:573
Definition: mdbx.h++:574
Definition: mdbx.h++:575
Definition: mdbx.h++:577
Definition: mdbx.h++:578
Definition: mdbx.h++:579
Definition: mdbx.h++:580
Definition: mdbx.h++:581
Definition: mdbx.h++:582
uint64_t mdbx_key_from_int64(const int64_t i64)
Definition: mdbx.h:4473
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:4477
LIBMDBX_API uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer)
#define MDBX_CXX20_CONSTEXPR
Definition: mdbx.h++:159
#define MDBX_CXX17_FALLTHROUGH
Definition: mdbx.h++:228
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE)
Definition: mdbx.h++:270
#define MDBX_LIKELY(cond)
Definition: mdbx.h++:198
#define MDBX_CXX11_CONSTEXPR_ENUM
Definition: mdbx.h++:171
#define MDBX_UNLIKELY(cond)
Definition: mdbx.h++:208
#define MDBX_CXX17_CONSTEXPR
Definition: mdbx.h++:145
#define MDBX_CONSTEXPR_ASSERT(expr)
Definition: mdbx.h++:190
#define MDBX_IF_CONSTEXPR
Definition: mdbx.h++:217
#define MDBX_CXX01_CONSTEXPR_ENUM
Definition: mdbx.h++:170
#define MDBX_CXX20_LIKELY
Definition: mdbx.h++:235
The libmdbx C API header file.
constexpr bool allocator_is_always_equal() noexcept
Definition: mdbx.h++:1171
The libmdbx C++ API namespace.
Definition: mdbx.h++:304
Definition: mdbx.h++:1713
constexpr allocated(allocator_pointer ptr, size_t bytes) noexcept
Definition: mdbx.h++:1716
constexpr allocated(const allocated &) noexcept=default
constexpr allocated(allocated &&) noexcept=default
allocator_pointer ptr_
Definition: mdbx.h++:1714
size_t capacity_bytes_
Definition: mdbx.h++:1715
Definition: mdbx.h++:4825
estimate_result(const cursor &cursor, move_operation operation)
Definition: mdbx.h++:4827
ptrdiff_t approximate_quantity
Definition: mdbx.h++:4826
estimate_result(const estimate_result &) noexcept=default
estimate_result(const cursor &cursor, move_operation operation, const slice &key)
Definition: mdbx.h++:4830
estimate_result & operator=(const estimate_result &) noexcept=default
Definition: mdbx.h++:4809
move_result(const move_result &) noexcept=default
move_result(cursor &cursor, move_operation operation, const slice &key, bool throw_notfound)
Definition: mdbx.h++:4814
move_result & operator=(const move_result &) noexcept=default
move_result(cursor &cursor, move_operation operation, bool throw_notfound)
Definition: mdbx.h++:4811
Tagged type for output to std::ostream.
Definition: mdbx.h++:3594
intptr_t bytes
Definition: mdbx.h++:3595
constexpr size(intptr_t bytes) noexcept
Definition: mdbx.h++:3596
Database geometry for size management.
Definition: mdbx.h++:3574
constexpr geometry(intptr_t size_lower, intptr_t size_now=default_value, intptr_t size_upper=maximal_value, intptr_t growth_step=default_value, intptr_t shrink_threshold=default_value, intptr_t pagesize=default_value) noexcept
Definition: mdbx.h++:3640
constexpr geometry(const geometry &) noexcept=default
intptr_t size_upper
The upper bound of database size in bytes.
Definition: mdbx.h++:3618
intptr_t pagesize
The database page size for new database creation or default_value otherwise.
Definition: mdbx.h++:3632
constexpr geometry() noexcept
Definition: mdbx.h++:3637
intptr_t growth_step
The growth step in bytes, must be greater than zero to allow the database to grow.
Definition: mdbx.h++:3622
intptr_t size_now
The size in bytes to setup the database size for now.
Definition: mdbx.h++:3606
intptr_t shrink_threshold
The shrink threshold in bytes, must be greater than zero to allow the database to shrink.
Definition: mdbx.h++:3626
intptr_t size_lower
The lower bound of database size in bytes.
Definition: mdbx.h++:3601
Definition: mdbx.h++:3766
Operate options.
Definition: mdbx.h++:3681
constexpr operate_options() noexcept
Definition: mdbx.h++:3693
constexpr operate_options(const operate_options &) noexcept=default
operate_options(MDBX_env_flags_t) noexcept
constexpr operate_options & operator=(const operate_options &) noexcept=default
Operate parameters.
Definition: mdbx.h++:3702
constexpr operate_parameters & operator=(const operate_parameters &) noexcept=default
env::operate_options options
Definition: mdbx.h++:3712
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++:3716
static env::mode mode_from_flags(MDBX_env_flags_t) noexcept
constexpr operate_parameters(const operate_parameters &) noexcept=default
env::reclaiming_options reclaiming
Definition: mdbx.h++:3711
static env::durability durability_from_flags(MDBX_env_flags_t) noexcept
constexpr operate_parameters() noexcept
Definition: mdbx.h++:3714
MDBX_env_flags_t make_flags(bool accede=true, bool use_subdirectory=false) const
Reader information.
Definition: mdbx.h++:4123
mdbx_tid_t thread
The reader thread ID.
Definition: mdbx.h++:4126
uint64_t transaction_lag
Definition: mdbx.h++:4129
size_t bytes_used
Definition: mdbx.h++:4133
uint64_t transaction_id
Definition: mdbx.h++:4127
int slot
The reader lock table slot number.
Definition: mdbx.h++:4124
mdbx_pid_t pid
The reader process ID.
Definition: mdbx.h++:4125
size_t bytes_retained
Definition: mdbx.h++:4136
Garbage reclaiming options.
Definition: mdbx.h++:3667
constexpr reclaiming_options(const reclaiming_options &) noexcept=default
constexpr reclaiming_options & operator=(const reclaiming_options &) noexcept=default
reclaiming_options(MDBX_env_flags_t) noexcept
constexpr reclaiming_options() noexcept
Definition: mdbx.h++:3672
Additional parameters for creating a new database.
Definition: mdbx.h++:4236
constexpr create_parameters() noexcept=default
env::geometry geometry
Definition: mdbx.h++:4237
Definition: mdbx.h++:3510
map_handle::state state
Definition: mdbx.h++:3512
info(const info &) noexcept=default
map_handle::flags flags
Definition: mdbx.h++:3511
info & operator=(const info &) noexcept=default
Definition: mdbx.h++:1712
constexpr bin & operator=(bin &&ditto) noexcept
Definition: mdbx.h++:1850
constexpr byte * address() noexcept
Definition: mdbx.h++:1873
constexpr bool is_inplace() const noexcept
Definition: mdbx.h++:1762
constexpr byte * make_allocated(allocator_pointer ptr, size_t capacity_bytes) noexcept
Definition: mdbx.h++:1785
static constexpr size_t advise_capacity(const size_t current, const size_t wanna)
Definition: mdbx.h++:1857
constexpr bin(size_t capacity_bytes=0) noexcept
Definition: mdbx.h++:1804
constexpr bool is_allocated() const noexcept
Definition: mdbx.h++:1765
constexpr byte & lastbyte() noexcept
Definition: mdbx.h++:1758
constexpr bin(bin &&ditto) noexcept
Definition: mdbx.h++:1819
constexpr bin(allocator_pointer ptr, size_t capacity_bytes) noexcept
Definition: mdbx.h++:1809
constexpr size_t capacity() const noexcept
Definition: mdbx.h++:1877
constexpr ~bin()
Definition: mdbx.h++:1814
constexpr byte * make_inplace() noexcept
Definition: mdbx.h++:1768
constexpr byte lastbyte() const noexcept
Definition: mdbx.h++:1755
static constexpr byte inplace_lastbyte_mask() noexcept
Definition: mdbx.h++:1748
constexpr bin & operator=(const bin &ditto) noexcept
Definition: mdbx.h++:1832
constexpr const byte * address() const noexcept
Definition: mdbx.h++:1868