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_);
456 std::pair<iterator, bool>
insert(
const key_type&
x) {
462 iterator
insert(iterator hint,
const key_type&
x) {
463 return tree_.
insert(hint, x);
468 template <
typename InputIterator>
469 void insert(InputIterator first, InputIterator last) {
470 InputIterator iter = first;
481 template <
typename Iterator>
499 size_type
erase(
const key_type& key) {
500 return tree_.
erase(key);
505 return tree_.
erase(iter);
508 #ifdef TLX_BTREE_TODO 511 void erase(iterator , iterator ) {
518 #ifdef TLX_BTREE_DEBUG 527 void print(std::ostream& os)
const {
532 void print_leaves(std::ostream& os)
const {
533 tree_.print_leaves(os);
556 #endif // !TLX_CONTAINER_BTREE_SET_HEADER const_iterator upper_bound(const key_type &key) const
iterator find(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().
static const unsigned short inner_slotmax
static const bool allow_duplicates
size_type erase(const key_type &key)
Erases all the key/data pairs associated with the given key.
key_compare key_comp() const
Constant access to the key comparison object sorting the B+ tree.
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_reverse_iterator rend() const
const_iterator begin() const
Compare_ key_compare
Second template parameter: Key comparison function object.
static const bool self_verify
iterator insert(iterator hint, const key_type &x)
btree_impl::size_type size_type
Size type used to count keys.
reverse_iterator rbegin()
btree_set(InputIterator first, InputIterator last, const key_compare &kcf, const allocator_type &alloc=allocator_type())
bool erase_one(const key_type &key)
bool operator>(const btree_set &other) const
Greater relation. Based on operator<.
value_compare value_comp() const
size_t size_type
Size type used to count keys.
iterator find(const key_type &key)
const struct tree_stats & get_stats() const
Return a const reference to the current statistics.
std::pair< iterator, iterator > equal_range(const key_type &key)
Searches the B+ tree and returns both lower_bound() and upper_bound().
const_reverse_iterator rbegin() const
bool empty() const
Returns true if there is at least one key in the B+ tree.
btree_impl::value_compare value_compare
Function class comparing two value_type keys.
void swap(btree_set &from)
Fast swapping of two identical B+ tree objects.
bool erase_one(const key_type &key)
const tree_stats & get_stats() const
Return a const reference to the current statistics.
void insert(InputIterator first, InputIterator last)
void clear()
Frees all keys and all nodes of the tree.
iterator upper_bound(const key_type &key)
void bulk_load(Iterator ibegin, Iterator iend)
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)
const_iterator lower_bound(const key_type &key) const
bool operator<(const btree_set &other) 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().
~btree_set()
Frees up all used B+ tree memory pages.
size_type size() const
Return the number of key/data pairs in the B+ tree.
reverse_iterator rbegin()
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)
static const bool self_verify
bool operator>=(const btree_set &other) const
Greater-equal relation. Based on operator<.
btree_set(const allocator_type &alloc=allocator_type())
bool exists(const key_type &key) const
void swap(CountingPtr< A, D > &a1, CountingPtr< A, D > &a2) noexcept
size_type max_size() const
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
size_type max_size() const
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
iterator lower_bound(const key_type &key)
btree_impl::const_iterator const_iterator
static const unsigned short leaf_slotmin
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.
allocator_type get_allocator() const
Return the base node allocator provided during construction.
size_type count(const key_type &key) const
key_compare key_comp() const
Constant access to the key comparison object sorting the B+ tree.
static const unsigned short inner_slotmin
btree_impl::iterator iterator
static const unsigned short leaf_slotmin
std::pair< iterator, bool > insert(const value_type &x)
value_compare value_comp() const
static const unsigned short inner_slotmax
btree_set(const key_compare &kcf, const allocator_type &alloc=allocator_type())
static const unsigned short inner_slotmin
bool operator!=(const btree_set &other) const
Inequality relation. Based on operator==.
size_type size() const
Return the number of keys in the B+ tree.
std::pair< iterator, bool > insert(const key_type &x)
size_type erase(const key_type &key)
bool operator<=(const btree_set &other) const
Less-equal relation. Based on operator<.
iterator lower_bound(const key_type &key)
bool operator==(const btree_set &other) const
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)
size_type count(const key_type &key) const
Specialized B+ tree template class implementing STL's set container.
const_iterator end() const
btree_impl tree_
The contained implementation object.
const_iterator find(const key_type &key) const
static const unsigned short leaf_slotmax
Base B+ tree parameter: The number of key slots in each leaf.