20 #ifndef _TPIE_BTREE_BASE_H_
21 #define _TPIE_BTREE_BASE_H_
47 const T & operator()(
const T & t)
const noexcept {
return t;}
54 template <
typename L,
typename R>
55 bool operator()(
const L & l,
const R & r)
const noexcept {
71 static const int f_internal = 1;
72 static const int f_static = 2;
73 static const int f_unordered = 4;
74 static const int f_serialized = 8;
87 template <
int a_,
int b_>
89 static const int a = a_;
90 static const int b = b_;
95 static const size_t bs = bs_;
110 enum btree_flags : uint64_t {
113 compress_snappy = 0x2,
115 compression_mask = 0xFF,
116 compression_level_mask = 0xFF00,
117 compress_level_default = 0x0000,
118 compress_level_1 = 0x0100,
119 compress_level_2 = 0x0200,
120 compress_level_3 = 0x0300,
121 compress_level_4 = 0x0400,
122 compress_level_5 = 0x0500,
123 compress_level_6 = 0x0600,
124 compress_level_7 = 0x0700,
125 compress_level_8 = 0x0800,
126 compress_level_9 = 0x0900,
127 compress_level_10 = 0x0A00,
128 compress_level_11 = 0x0B00,
129 compress_level_12 = 0x0C00,
130 compress_level_13 = 0x0D00,
131 compress_level_14 = 0x0E00,
132 compress_level_15 = 0x0F00,
133 compress_level_16 = 0x1000,
134 compress_level_17 = 0x1100,
135 compress_level_18 = 0x1200,
136 compress_level_19 = 0x1300,
137 compress_level_20 = 0x1400,
138 compress_level_21 = 0x1500,
139 compress_level_22 = 0x1600,
140 compress_default = compress_level_default | compress_lz4,
143 defaults = read | write,
144 defaults_v0 = read | write
147 inline constexpr btree_flags operator |(btree_flags f1, btree_flags f2) {
return static_cast<btree_flags
>(uint64_t(f1) | uint64_t(f2)); }
148 inline btree_flags & operator |=(btree_flags & f1, btree_flags f2) {
return f1 = f1 | f2; }
149 inline constexpr btree_flags operator &(btree_flags f1, btree_flags f2) {
return static_cast<btree_flags
>(uint64_t(f1) & uint64_t(f2)); }
150 inline btree_flags & operator &=(btree_flags & f1, btree_flags f2) {
return f1 = f1 & f2; }
151 inline constexpr btree_flags operator ~(btree_flags f1) {
return static_cast<btree_flags
>(~uint64_t(f1)); }
156 template <
int O_,
int a_,
int b_,
size_t bs_,
typename C_,
typename K_,
typename A_>
158 static const int O=O_;
159 static const int a=a_;
160 static const int b=b_;
161 static const size_t bs=bs_;
167 template <
typename ...
Opt>
175 template <
int i,
typename ... T>
181 template <
typename C,
typename ... T>
187 template <
typename K,
typename ... T>
193 template <
typename A,
typename ... T>
199 template <
int a,
int b,
typename ... T>
205 template <
size_t bs,
typename ... T>
220 template <
typename S>
224 template <
typename S>
236 template <
typename T,
247 template <
typename T,
typename O>
250 template <
typename,
bool>
253 template <
typename T,
typename A, std::
size_t a, std::
size_t b>
256 template <
typename T,
typename A, std::
size_t a, std::
size_t b, std::
size_t bs>
259 template <
typename T,
typename A, std::
size_t a, std::
size_t b, std::
size_t bs>
264 template <
typename X,
bool b>
270 template <
typename X,
bool b>
273 template <
typename T,
typename O>
276 static const bool is_internal = O::O & bbits::f_internal;
277 static const bool is_static = O::O & bbits::f_static;
278 static const bool is_ordered = ! (O::O & bbits::f_unordered);
279 static const bool is_serialized = O::O & bbits::f_serialized;
280 static_assert(!is_serialized || is_static,
"Serialized B-tree cannot be dynamic.");
282 typedef typename std::conditional<
285 no_key>::type keyextract_type;
287 typedef typename O::A augmenter_type;
289 typedef T value_type;
291 typedef typename std::decay<decltype(std::declval<augmenter_type>()(std::declval<value_type>()))>::type augment_type;
293 typedef typename std::decay<decltype(std::declval<keyextract_type>()(std::declval<value_type>()))>::type key_type;
301 ,
public augment_type {};
305 template <
typename N>
308 *
static_cast<augment_type*
>(&ans) = m_augmenter(node);
312 ? m_key_extract(node.value(0))
313 :
static_cast<const key_augment*
>(&node.get_combined_augmentation(0))->key;
319 keyextract_type key_extract)
320 : m_key_extract(std::move(key_extract))
321 , m_augmenter(std::move(a)) {}
323 keyextract_type m_key_extract;
324 augmenter_type m_augmenter;
327 typedef typename std::conditional<
330 typename std::conditional<
337 typedef typename store_type::internal_type internal_type;
338 typedef typename store_type::leaf_type leaf_type;
340 key_type min_key(internal_type node,
size_t i)
const {
341 return static_cast<const key_augment*
>(&m_store.augment(node, i))->key;
344 key_type min_key(leaf_type node,
size_t i)
const {
345 return m_augmenter.m_key_extract(m_store.get(node, i));
348 key_type min_key(T v)
const {
349 return m_augmenter.m_key_extract(v);
352 key_type min_key(internal_type v)
const {
353 return min_key(v, 0);
356 key_type min_key(leaf_type v)
const {
357 return min_key(v, 0);
360 const store_type & store()
const {
364 store_type & store() {
368 static const augment_type & user_augment(
const combined_augment & a) {
369 return *
static_cast<const augment_type *
>(&a);
372 tree_state(store_type store, augmenter_type augmenter, keyextract_type keyextract)
373 : m_augmenter(std::move(augmenter), std::move(keyextract))
374 , m_store(std::move(store)) {}
376 combined_augmenter m_augmenter;