20 #ifndef _TPIE_BTREE_INTERNAL_STORE_H_
21 #define _TPIE_BTREE_INTERNAL_STORE_H_
24 #include <tpie/btree/base.h>
45 class internal_store {
47 static const size_t a = a_?a_:2;
48 static const size_t b = b_?b_:4;
61 typedef size_t size_type;
69 , m_height(o.m_height)
71 , m_metadata(o.m_metadata)
72 , m_bucket(o.m_bucket) {
79 std::swap(m_root, o.m_root);
80 std::swap(m_height, o.m_height);
81 std::swap(m_size, o.m_size);
82 std::swap(m_metadata, o.m_metadata);
83 std::swap(m_bucket, o.m_bucket);
92 m_root(nullptr), m_height(0), m_size(0), m_bucket(bucket) {}
95 struct internal_content {
102 internal_content values[b];
110 typedef internal * internal_type;
111 typedef leaf * leaf_type;
113 void dispose(
void * node,
size_t depth) {
114 if (depth + 1 == m_height) {
116 if (m_bucket) m_bucket->count -=
sizeof(leaf);
119 internal * in =
static_cast<internal*
>(node);
120 for (
size_t i=0; i != in->count; ++i)
121 dispose(in->values[i].ptr, depth + 1);
123 if (m_bucket) m_bucket->count -=
sizeof(
internal);
127 if (!m_root || !m_height)
return;
132 static constexpr
size_t min_internal_size() {
return a;}
133 static constexpr
size_t max_internal_size() {
return b;}
135 static constexpr
size_t min_leaf_size() {
return a;}
136 static constexpr
size_t max_leaf_size() {
return b;}
138 void move(internal_type src,
size_t src_i,
139 internal_type dst,
size_t dst_i) {
140 dst->values[dst_i] = src->values[src_i];
143 void move(leaf_type src,
size_t src_i,
144 leaf_type dst,
size_t dst_i) {
145 dst->values[dst_i] = src->values[src_i];
148 void set(leaf_type dst,
size_t dst_i, T c) {
149 dst->values[dst_i] = c;
152 void set(internal_type node,
size_t i, internal_type c) {
153 node->values[i].ptr = c;
156 void set(internal_type node,
size_t i, leaf_type c) {
157 node->values[i].ptr = c;
160 const T &
get(leaf_type l,
size_t i)
const {
164 size_t count(internal_type node)
const {
168 size_t count_child_leaf(internal_type node,
size_t i)
const {
169 return static_cast<leaf_type
>(node->values[i].ptr)->count;
172 size_t count_child_internal(internal_type node,
size_t i)
const {
173 return static_cast<internal_type
>(node->values[i].ptr)->count;
176 size_t count(leaf_type node)
const {
180 void set_count(internal_type node,
size_t i) {
184 void set_count(leaf_type node,
size_t i) {
188 leaf_type create_leaf() {
189 auto l = tpie_new<leaf>();
190 if (m_bucket) m_bucket->count +=
sizeof(leaf);
193 leaf_type create(leaf_type) {
return create_leaf();}
195 internal_type create_internal() {
196 auto i = tpie_new<internal>();
197 if (m_bucket) m_bucket->count +=
sizeof(
internal);
201 internal_type create(internal_type) {
return create_internal();}
203 void destroy(internal_type node) {
204 if (m_bucket && node) m_bucket->count -=
sizeof(
internal);
208 void destroy(leaf_type node) {
209 if (m_bucket && node) m_bucket->count -=
sizeof(leaf);
213 void set_root(internal_type node) {m_root = node;}
214 void set_root(leaf_type node) {m_root = node;}
216 internal_type get_root_internal()
const {
217 return static_cast<internal_type
>(m_root);
220 leaf_type get_root_leaf()
const {
221 return static_cast<leaf_type
>(m_root);
224 internal_type get_child_internal(internal_type node,
size_t i)
const {
225 return static_cast<internal_type
>(node->values[i].ptr);
228 leaf_type get_child_leaf(internal_type node,
size_t i)
const {
229 return static_cast<leaf_type
>(node->values[i].ptr);
232 size_t index(
void * child, internal_type node)
const {
233 for (
size_t i=0; i < node->count; ++i)
234 if (node->values[i].ptr == child)
return i;
239 void set_augment(
void * l, internal_type p,
augment_type ag) {
240 size_t idx=index(l, p);
241 p->values[idx].augment = ag;
244 const augment_type & augment(internal_type p,
size_t i)
const {
245 return p->values[i].augment;
248 size_t height()
const throw() {
252 void set_height(
size_t height)
throw() {
256 size_t size()
const throw() {
260 void set_size(
size_t size)
throw() {
265 void finalize_build() {}
267 void set_metadata(
const std::string & data) {
271 std::string get_metadata() {
278 std::string m_metadata;
279 memory_bucket_ref m_bucket;
282 friend class ::tpie::btree_node;
285 friend class ::tpie::btree_iterator;
287 template <
typename,
typename>
288 friend class bbits::tree;
290 template <
typename,
typename>
291 friend class bbits::tree_state;
293 template<
typename,
typename>
294 friend class bbits::builder;
A augment_type
Type of augmentation stored.
Defines the tp_assert macro.
Memory management subsystem.
Storage used for an internal btree.
This file contains a few deprecated definitions for legacy code.
Class storring a reference to a memory bucket.
T value_type
Type of value of items stored.
void tpie_delete(T *p)
Delete an object allocated with tpie_new.
#define tp_assert(condition, message)