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 iterator begin()
Constructs a read/data-write iterator that points to the first slot in the first leaf of the B+ tree...
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.
bool operator>(const btree_map &other) const
Greater relation. Based on operator<.
iterator find(const key_type &key)
Tries to locate a key in the B+ tree and returns an iterator to the key/data slot if found...
btree_impl::reverse_iterator reverse_iterator
create mutable reverse iterator by using STL magic
btree_impl::const_iterator const_iterator
STL-like iterator object for B+ tree items.
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)
Tries to locate a key in the B+ tree and returns an iterator to the key/data slot if found...
static const bool allow_duplicates
Sixth template parameter: Allow duplicate keys in the B+ tree.
void insert(InputIterator first, InputIterator last)
Attempt to insert the range [first,last) of value_type pairs into the B+ tree.
iterator insert(iterator hint, const value_type &x)
Attempt to insert a key/data pair into the B+ tree.
const_iterator find(const key_type &key) const
Tries to locate a key in the B+ tree and returns an constant iterator to the key/data slot if found...
size_type count(const key_type &key) const
Tries to locate a key in the B+ tree and returns the number of identical key entries found...
static const unsigned short inner_slotmax
Base B+ tree parameter: The number of key slots in each inner node, this can differ from slots in eac...
bool empty() const
Returns true if there is at least one key/data pair in the B+ tree.
const_iterator end() const
Constructs a read-only constant iterator that points to the first invalid slot in the last leaf of th...
size_type max_size() const
Returns the largest possible size of the B+ Tree.
Key_ key_type
First template parameter: The key type of the btree.
~btree_map()
Frees up all used B+ tree memory pages.
size_type erase(const key_type &key)
Erases all the key/data pairs associated with the given key.
iterator insert2(iterator hint, const key_type &key, const data_type &data)
Attempt to insert a key/data pair into the B+ tree.
static const bool debug
Debug parameter: Prints out lots of debug information about how the algorithms change the tree...
bool operator==(const btree_map &other) const
Equality relation of B+ trees of the same type.
void verify() const
Run a thorough verification of all B+ tree invariants.
static const bool debug
Debug parameter: Prints out lots of debug information about how the algorithms change the tree...
static const bool self_verify
Debug parameter: Enables expensive and thorough checking of the B+ tree invariants after each insert/...
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)
Erases one (the first) of the key/data pairs associated with the given key.
data_type & operator[](const key_type &key)
Returns a reference to the object that is associated with a particular key.
allocator_type get_allocator() const
Return the base node allocator provided during construction.
size_type size() const
Return the number of key/data pairs in the B+ tree.
btree_impl::tree_stats tree_stats
Small structure containing statistics about the tree.
bool exists(const key_type &key) const
Non-STL function checking whether a key is in the B+ tree.
std::pair< iterator, bool > insert2(const key_type &key, const data_type &data)
Attempt to insert a key/data pair into the B+ tree.
iterator lower_bound(const key_type &key)
Searches the B+ tree and returns an iterator to the first pair equal to or greater than key...
const_reverse_iterator rbegin() const
Constructs a read-only reverse iterator that points to the first invalid slot in the last leaf of the...
value_compare value_comp() const
Constant access to a constructed value_type comparison object.
bool exists(const key_type &key) const
Non-STL function checking whether a key is in the B+ tree.
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.
const_reverse_iterator rend() const
Constructs a read-only reverse iterator that points to the first slot in the first leaf of the B+ tre...
btree_impl::const_reverse_iterator const_reverse_iterator
create constant reverse iterator by using STL magic
size_type max_size() const
Returns the largest possible size of the B+ Tree.
btree_impl tree_
The contained implementation object.
bool empty() const
Returns true if there is at least one key/data pair in the B+ tree.
Specialized B+ tree template class implementing STL's map container.
Data_ data_type
Second template parameter: The value type associated with each key.
bool erase_one(const key_type &key)
Erases the key/data pairs associated with the given key.
std::pair< key_type, data_type > value_type
Construct the STL-required value_type as a composition pair of key and data types.
reverse_iterator rend()
Constructs a read/data-write reverse iterator that points to the first slot in the first leaf of the ...
static const bool self_verify
Debug parameter: Enables expensive and thorough checking of the B+ tree invariants after each insert/...
const_iterator upper_bound(const key_type &key) const
Searches the B+ tree and returns a constant iterator to the first pair greater than key...
void bulk_load(Iterator ibegin, Iterator iend)
Bulk load a sorted range.
void clear()
Frees all key/data pairs and all nodes of the tree.
Traits_ traits
Fourth template parameter: Traits object used to define more parameters of the B+ tree...
reverse_iterator rend()
Constructs a read/data-write reverse iterator that points to the first slot in the first leaf of the ...
Compare_ key_compare
Third template parameter: Key comparison function object.
reverse_iterator rbegin()
Constructs a read/data-write reverse iterator that points to the first invalid slot in the last leaf ...
size_type count(const key_type &key) const
Tries to locate a key in the B+ tree and returns the number of identical key entries found...
void clear()
Frees all key/data pairs and all nodes of the tree.
void swap(CountingPtr< A, D > &a1, CountingPtr< A, D > &a2) noexcept
swap enclosed object with another counting pointer (no reference counts need change) ...
static const unsigned short leaf_slotmin
Computed B+ tree parameter: The minimum number of key/data slots used in a leaf.
value_compare value_comp() const
Constant access to a constructed value_type comparison object.
bool operator<=(const btree_map &other) const
Less-equal relation. Based on operator<.
iterator end()
Constructs a read/data-write iterator that points to the first invalid slot in the last leaf of the B...
allocator_type get_allocator() const
Return the base node allocator provided during construction.
iterator upper_bound(const key_type &key)
Searches the B+ tree and returns an iterator to the first pair greater than key, or end() if all keys...
iterator begin()
Constructs a read/data-write iterator that points to the first slot in the first leaf of the B+ tree...
static const unsigned short leaf_slotmax
Base B+ tree parameter: The number of key/data slots in each leaf.
bool operator<(const btree_map &other) const
Total ordering relation of B+ trees of the same type.
btree_impl::iterator iterator
STL-like iterator object for B+ tree items.
static const unsigned short leaf_slotmin
Computed B+ tree parameter: The minimum number of key/data slots used in a leaf.
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)
Searches the B+ tree and returns an iterator to the first pair greater than key, or end() if all keys...
iterator end()
Constructs a read/data-write iterator that points to the first invalid slot in the last leaf of the B...
Alloc_ allocator_type
Fifth template parameter: STL allocator.
static const unsigned short inner_slotmin
Computed B+ tree parameter: The minimum number of key slots used in an inner node.
void erase(iterator iter)
Erase the key/data pair referenced by the iterator.
const struct tree_stats & get_stats() const
Return a const reference to the current statistics.
btree_map(InputIterator first, InputIterator last, const key_compare &kcf, const allocator_type &alloc=allocator_type())
Constructor initializing a B+ tree with the range [first,last) and a special key comparison object...
key_compare key_comp() const
Constant access to the key comparison object sorting the B+ tree.
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 operator!=(const btree_map &other) const
Inequality relation. Based on operator==.
std::pair< iterator, bool > insert(const value_type &x)
Attempt to insert a key/data pair into the B+ tree.
static const unsigned short inner_slotmax
Base B+ tree parameter: The number of key slots in each inner node, this can differ from slots in eac...
key_compare key_comp() const
Constant access to the key comparison object sorting the B+ tree.
size_type erase(const key_type &key)
Erases all the key/data pairs associated with the given key.
const_iterator begin() const
Constructs a read-only constant iterator that points to the first slot in the first leaf of the B+ tr...
btree_map(const btree_map &other)
Copy constructor.
iterator lower_bound(const key_type &key)
Searches the B+ tree and returns an iterator to the first pair equal to or greater than 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())
Constructor initializing an empty B+ tree with a special key comparison object.
const_iterator lower_bound(const key_type &key) const
Searches the B+ tree and returns a constant iterator to the first pair equal to or greater than key...
std::pair< iterator, bool > insert(const value_type &x)
Attempt to insert a key/data pair into the B+ tree.
void verify() const
Run a thorough verification of all B+ tree invariants.
static const unsigned short leaf_slotmax
Base B+ tree parameter: The number of key/data slots in each leaf.
btree_map(const allocator_type &alloc=allocator_type())
Default constructor initializing an empty B+ tree with the standard key comparison function...
const tree_stats & get_stats() const
Return a const reference to the current statistics.
btree_map & operator=(const btree_map &other)
Assignment operator. All the key/data pairs are copied.
void bulk_load(Iterator first, Iterator last)
Bulk load a sorted range [first,last).
reverse_iterator rbegin()
Constructs a read/data-write reverse iterator that points to the first invalid slot in the last leaf ...
size_type size() const
Return the number of key/data pairs in the B+ tree.
static const unsigned short inner_slotmin
Computed B+ tree parameter: The minimum number of key slots used in an inner node.