11 #ifndef TLX_CONTAINER_BTREE_SET_HEADER 12 #define TLX_CONTAINER_BTREE_SET_HEADER 37 template <
typename Key_,
38 typename Compare_ = std::less<Key_>,
39 typename Traits_ = btree_default_traits<Key_, Key_>,
40 typename Alloc_ = std::allocator<Key_> >
81 static const key_type&
get(
const value_type& v) {
return v; }
181 template <
class InputIterator>
190 template <
class InputIterator>
191 btree_set(InputIterator first, InputIterator last,
const key_compare& kcf,
193 : tree_(kcf, alloc) {
254 return tree_.
begin();
266 return tree_.
begin();
271 const_iterator
end()
const {
295 const_reverse_iterator
rend()
const {
312 return tree_.
empty();
340 iterator
find(
const key_type& key) {
341 return tree_.
find(key);
346 const_iterator
find(
const key_type& key)
const {
347 return tree_.
find(key);
353 size_type
count(
const key_type& key)
const {
354 return tree_.
count(key);
388 const key_type& key)
const {
401 return (tree_ == other.
tree_);
406 return (tree_ != other.
tree_);
412 return (tree_ < other.
tree_);
417 return (tree_ > other.
tree_);
422 return (tree_ <= other.
tree_);
427 return (tree_ >= other.
tree_);
457 std::pair<iterator, bool>
insert(
const key_type& x) {
463 iterator
insert(iterator hint,
const key_type& x) {
464 return tree_.
insert(hint, x);
469 template <
typename InputIterator>
470 void insert(InputIterator first, InputIterator last) {
471 InputIterator iter = first;
482 template <
typename Iterator>
500 size_type
erase(
const key_type& key) {
501 return tree_.
erase(key);
506 return tree_.
erase(iter);
509 #ifdef TLX_BTREE_TODO 512 void erase(iterator , iterator ) {
519 #ifdef TLX_BTREE_DEBUG 528 void print(std::ostream& os)
const {
533 void print_leaves(std::ostream& os)
const {
534 tree_.print_leaves(os);
557 #endif // !TLX_CONTAINER_BTREE_SET_HEADER bool operator<=(const btree_set &other) const
Less-equal relation. Based on operator<.
iterator begin()
Constructs a read/data-write iterator that points to the first slot in the first leaf of the B+ tree...
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...
std::pair< iterator, iterator > equal_range(const key_type &key)
Searches the B+ tree and returns both lower_bound() and upper_bound().
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...
static const bool allow_duplicates
Sixth template parameter: Allow duplicate keys in the B+ tree.
size_type erase(const key_type &key)
Erases all the key/data pairs associated with the given key.
bool operator!=(const btree_set &other) const
Inequality relation. Based on operator==.
btree_set & operator=(const btree_set &other)
Assignment operator. All the keys are copied.
btree_impl::reverse_iterator reverse_iterator
create mutable reverse iterator by using STL magic
BTree< key_type, value_type, key_of_value, key_compare, traits, false, allocator_type > btree_impl
Implementation type of the btree_base.
const tree_stats & get_stats() const
Return a const reference to the current statistics.
size_type max_size() const
Returns the largest possible size of the B+ Tree.
key_compare key_comp() const
Constant access to the key comparison object sorting the B+ tree.
Traits_ traits
Third template parameter: Traits object used to define more parameters of the B+ tree.
static const bool debug
Debug parameter: Prints out lots of debug information about how the algorithms change the tree...
void verify() const
Run a thorough verification of all B+ tree invariants.
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...
Compare_ key_compare
Second template parameter: Key comparison function object.
static const bool self_verify
Debug parameter: Enables expensive and thorough checking of the B+ tree invariants after each insert/...
iterator insert(iterator hint, const key_type &x)
Attempt to insert a key into the B+ tree.
btree_impl::size_type size_type
Size type used to count keys.
reverse_iterator rbegin()
Constructs a read/data-write reverse iterator that points to the first invalid slot in the last leaf ...
void verify() const
Run a thorough verification of all B+ tree invariants.
bool empty() const
Returns true if there is at least one key in the B+ tree.
bool operator>=(const btree_set &other) const
Greater-equal relation. Based on operator<.
btree_set(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...
bool erase_one(const key_type &key)
Erases one (the first) of the key/data pairs associated with the given 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.
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.
const_reverse_iterator rbegin() const
Constructs a read-only reverse iterator that points to the first invalid slot in the last leaf of the...
iterator begin()
Constructs a read/data-write iterator that points to the first slot in the first leaf of the B+ tree...
bool empty() const
Returns true if there is at least one key/data pair in the B+ tree.
iterator find(const key_type &key)
Tries to locate a key in the B+ tree and returns an iterator to the key slot if found.
std::pair< iterator, iterator > equal_range(const key_type &key)
Searches the B+ tree and returns both lower_bound() and upper_bound().
btree_impl::value_compare value_compare
Function class comparing two value_type keys.
bool exists(const key_type &key) const
Non-STL function checking whether a key is in the B+ tree.
void swap(btree_set &from)
Fast swapping of two identical B+ tree objects.
bool erase_one(const key_type &key)
Erases the key from the set.
iterator end()
Constructs a read/data-write iterator that points to the first invalid slot in the last leaf of the B...
void insert(InputIterator first, InputIterator last)
Attempt to insert the range [first,last) of iterators dereferencing to key_type into the B+ tree...
void clear()
Frees all keys and all nodes of the tree.
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...
static const bool debug
Debug parameter: Prints out lots of debug information about how the algorithms change the tree...
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.
btree_set(InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type())
Constructor initializing a B+ tree with the range [first,last)
reverse_iterator rend()
Constructs a read/data-write reverse iterator that points to the first slot in the first leaf of the ...
~btree_set()
Frees up all used B+ tree memory pages.
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...
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 erase(iterator iter)
Erase the key/data pair referenced by the iterator.
key_type value_type
Construct the set value_type: the key_type.
void bulk_load(Iterator first, Iterator last)
Bulk load a sorted range [first,last).
bool operator>(const btree_set &other) const
Greater relation. Based on operator<.
static const bool self_verify
Debug parameter: Enables expensive and thorough checking of the B+ tree invariants after each insert/...
btree_set(const allocator_type &alloc=allocator_type())
Default constructor initializing an empty B+ tree with the standard key comparison function...
const_iterator begin() const
Constructs a read-only constant iterator that points to the first slot in the first leaf of the B+ tr...
value_compare value_comp() const
Constant access to a constructed value_type comparison object.
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 bool allow_duplicates
Operational parameter: Allow duplicate keys in the btree.
btree_impl::const_reverse_iterator const_reverse_iterator
create constant reverse iterator by using STL magic
iterator end()
Constructs a read/data-write iterator that points to the first invalid slot in the last leaf of the B...
static const unsigned short leaf_slotmax
Base B+ tree parameter: The number of key/data slots in each leaf.
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...
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...
btree_impl::const_iterator const_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.
bool operator==(const btree_set &other) const
Equality relation of B+ trees of the same type.
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...
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 slot if found...
static const unsigned short inner_slotmin
Computed B+ tree parameter: The minimum number of key slots used in an inner node.
const struct tree_stats & get_stats() const
Return a const reference to the current statistics.
size_type max_size() const
Returns the largest possible size of the B+ Tree.
TLX_BTREE_FRIENDS
The macro TLX_BTREE_FRIENDS can be used by outside class to access the B+ tree internals.
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...
size_type size() const
Return the number of keys in the B+ tree.
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 slots used in a leaf.
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...
bool operator<(const btree_set &other) const
Total ordering relation of B+ trees of the same type.
Key_ key_type
First template parameter: The key type of the B+ tree.
allocator_type get_allocator() const
Return the base node allocator provided during construction.
btree_set(const key_compare &kcf, const allocator_type &alloc=allocator_type())
Constructor initializing an empty B+ tree with a special key comparison object.
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().
static const unsigned short inner_slotmin
Computed B+ tree parameter: The minimum number of key slots used in an inner node.
reverse_iterator rend()
Constructs a read/data-write reverse iterator that points to the first slot in the first leaf of the ...
key_compare key_comp() const
Constant access to the key comparison object sorting the B+ tree.
std::pair< iterator, bool > insert(const key_type &x)
Attempt to insert a key into the B+ tree.
size_type erase(const key_type &key)
Erases all the key/data pairs associated with the given key.
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...
Alloc_ allocator_type
Fourth template parameter: STL allocator.
btree_impl::tree_stats tree_stats
Small structure containing statistics about the tree.
btree_set(const btree_set &other)
Copy constructor.
Specialized B+ tree template class implementing STL's set container.
btree_impl tree_
The contained implementation object.
const_iterator end() const
Constructs a read-only constant iterator that points to the first invalid slot in the last leaf of th...
static const unsigned short leaf_slotmax
Base B+ tree parameter: The number of key slots in each leaf.