11 #ifndef TLX_CONTAINER_BTREE_MAP_HEADER 12 #define TLX_CONTAINER_BTREE_MAP_HEADER 34 template <
typename Key_,
typename Data_,
35 typename Compare_ = std::less<Key_>,
37 btree_default_traits<Key_, std::pair<Key_, Data_> >,
38 typename Alloc_ = std::allocator<std::pair<Key_, Data_> > >
85 static const key_type&
get(
const value_type& v) {
return v.first; }
185 template <
class InputIterator>
188 : tree_(first, last, alloc)
193 template <
class InputIterator>
194 btree_map(InputIterator first, InputIterator last,
const key_compare& kcf,
196 : tree_(first, last, kcf, alloc)
256 return tree_.
begin();
268 return tree_.
begin();
273 const_iterator
end()
const {
297 const_reverse_iterator
rend()
const {
314 return tree_.
empty();
342 iterator
find(
const key_type& key) {
343 return tree_.
find(key);
348 const_iterator
find(
const key_type& key)
const {
349 return tree_.
find(key);
355 size_type
count(
const key_type& key)
const {
356 return tree_.
count(key);
389 std::pair<const_iterator, const_iterator>
403 return (tree_ == other.
tree_);
408 return (tree_ != other.
tree_);
414 return (tree_ < other.
tree_);
419 return (tree_ > other.
tree_);
424 return (tree_ <= other.
tree_);
429 return (tree_ >= other.
tree_);
459 std::pair<iterator, bool>
insert(
const value_type&
x) {
466 const key_type& key,
const data_type& data) {
472 iterator
insert(iterator hint,
const value_type&
x) {
473 return tree_.
insert(hint, x);
479 const key_type& key,
const data_type& data) {
493 template <
typename InputIterator>
494 void insert(InputIterator first, InputIterator last) {
495 return tree_.
insert(first, last);
501 template <
typename Iterator>
520 size_type
erase(
const key_type& key) {
521 return tree_.
erase(key);
526 return tree_.
erase(iter);
529 #ifdef TLX_BTREE_TODO 532 void erase(iterator , iterator ) {
539 #ifdef TLX_BTREE_DEBUG 548 void print(std::ostream& os)
const {
553 void print_leaves(std::ostream& os)
const {
554 tree_.print_leaves(os);
577 #endif // !TLX_CONTAINER_BTREE_MAP_HEADER
btree_impl::size_type size_type
Size type used to count keys.
btree_impl::value_compare value_compare
Function class comparing two value_type pairs.
iterator find(const key_type &key)
btree_impl::reverse_iterator reverse_iterator
create mutable reverse iterator by using STL magic
btree_impl::const_iterator const_iterator
std::pair< iterator, iterator > equal_range(const key_type &key)
Searches the B+ tree and returns both lower_bound() and upper_bound().
iterator find(const key_type &key)
static const bool allow_duplicates
void insert(InputIterator first, InputIterator last)
iterator insert(iterator hint, const value_type &x)
key_compare key_comp() const
Constant access to the key comparison object sorting the B+ tree.
bool operator==(const btree_map &other) const
static const unsigned short inner_slotmax
bool operator<(const btree_map &other) const
~btree_map()
Frees up all used B+ tree memory pages.
size_type erase(const key_type &key)
const_reverse_iterator rend() const
iterator insert2(iterator hint, const key_type &key, const data_type &data)
const_reverse_iterator rbegin() const
static const bool self_verify
allocator_type get_allocator() const
Return the base node allocator provided during construction.
void swap(btree_map &from)
Fast swapping of two identical B+ tree objects.
static const bool allow_duplicates
Operational parameter: Allow duplicate keys in the btree.
bool erase_one(const key_type &key)
data_type & operator[](const key_type &key)
const_iterator begin() const
std::pair< const_iterator, const_iterator > equal_range(const key_type &key) const
Searches the B+ tree and returns both lower_bound() and upper_bound().
bool empty() const
Returns true if there is at least one key/data pair in the B+ tree.
key_compare key_comp() const
Constant access to the key comparison object sorting the B+ tree.
btree_impl::tree_stats tree_stats
Small structure containing statistics about the tree.
std::pair< iterator, bool > insert2(const key_type &key, const data_type &data)
iterator lower_bound(const key_type &key)
size_t size_type
Size type used to count keys.
BTree< key_type, value_type, key_of_value, key_compare, traits, false, allocator_type > btree_impl
Implementation type of the btree_base.
btree_impl::const_reverse_iterator const_reverse_iterator
create constant reverse iterator by using STL magic
btree_impl tree_
The contained implementation object.
const struct tree_stats & get_stats() const
Return a const reference to the current statistics.
Specialized B+ tree template class implementing STL's map container.
const_iterator lower_bound(const key_type &key) const
bool erase_one(const key_type &key)
const_iterator find(const key_type &key) const
const_iterator upper_bound(const key_type &key) const
std::pair< key_type, data_type > value_type
static const bool self_verify
void bulk_load(Iterator ibegin, Iterator iend)
void clear()
Frees all key/data pairs and all nodes of the tree.
Compare_ key_compare
Third template parameter: Key comparison function object.
size_type size() const
Return the number of key/data pairs in the B+ tree.
reverse_iterator rbegin()
bool operator<=(const btree_map &other) const
Less-equal relation. Based on operator<.
void clear()
Frees all key/data pairs and all nodes of the tree.
void swap(CountingPtr< A, D > &a1, CountingPtr< A, D > &a2) noexcept
size_type max_size() const
size_type size() const
Return the number of key/data pairs in the B+ tree.
static const unsigned short leaf_slotmin
value_compare value_comp() const
iterator upper_bound(const key_type &key)
static const unsigned short leaf_slotmax
Base B+ tree parameter: The number of key/data slots in each leaf.
bool exists(const key_type &key) const
bool exists(const key_type &key) const
btree_impl::iterator iterator
bool operator>(const btree_map &other) const
Greater relation. Based on operator<.
static const unsigned short leaf_slotmin
btree_map(InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type())
Constructor initializing a B+ tree with the range [first,last)
Basic class implementing a B+ tree data structure in memory.
iterator upper_bound(const key_type &key)
bool empty() const
Returns true if there is at least one key/data pair in the B+ tree.
allocator_type get_allocator() const
Return the base node allocator provided during construction.
size_type count(const key_type &key) const
Alloc_ allocator_type
Fifth template parameter: STL allocator.
static const unsigned short inner_slotmin
void erase(iterator iter)
Erase the key/data pair referenced by the iterator.
btree_map(InputIterator first, InputIterator last, const key_compare &kcf, const allocator_type &alloc=allocator_type())
size_type max_size() const
std::pair< iterator, bool > insert(const value_type &x)
value_compare value_comp() const
static const unsigned short inner_slotmax
bool operator!=(const btree_map &other) const
Inequality relation. Based on operator==.
const_iterator end() const
size_type count(const key_type &key) const
size_type erase(const key_type &key)
btree_map(const btree_map &other)
iterator lower_bound(const key_type &key)
std::pair< iterator, iterator > equal_range(const key_type &key)
Searches the B+ tree and returns both lower_bound() and upper_bound().
bool operator>=(const btree_map &other) const
Greater-equal relation. Based on operator<.
btree_map(const key_compare &kcf, const allocator_type &alloc=allocator_type())
std::pair< iterator, bool > insert(const value_type &x)
static const unsigned short leaf_slotmax
Base B+ tree parameter: The number of key/data slots in each leaf.
const tree_stats & get_stats() const
Return a const reference to the current statistics.
btree_map(const allocator_type &alloc=allocator_type())
btree_map & operator=(const btree_map &other)
Assignment operator. All the key/data pairs are copied.
void bulk_load(Iterator first, Iterator last)
reverse_iterator rbegin()
static const unsigned short inner_slotmin