btree_set¶
In platanus/btree_set.hpp,
namespace platanus {
template <
typename Key,
typename Compare = std::ranges::less,
typename Alloc = std::allocator<Key>,
std::size_t MaxNumOfValues = 512>
class btree_set;
}
Template parameters¶
| Parameter | Meaning |
|---|---|
Key |
Type of a key |
Compare |
Type of a func obj comparing two key in a weak order. If Key doesn't implement three-way comparison operator, the default type does using < and =. |
Alloc |
Type of an allocator. The default is std::allocator<Key>. |
MaxNumOfValues |
The max number of values per node. The default is 64. |
Member types¶
| Type | Meaning |
|---|---|
| key_type | Type of key, i.e. Key |
| value_type | Type of value, i.e. Key |
| key_compare | Type of comparer of key, i.e. Compare |
| value_compare | Type of comparer of value, i.e. Compare |
| allocator_type | Type of allocator, i.e. Alloc |
| pointer | Type of pointer to value, i.e. Key* |
| const_pointer | Type of pointer to const value, i.e. const Key* |
| reference | Type of reference to value, i.e. Key& |
| const_reference | Type of reference to const value, i.e. const Key& |
| size_type | Unsigned integer type of size of btree_set, i.e. std::size_t |
| difference_type | Signed integer type of the difference of two iterators |
| iterator | Type of iterator |
| const_iterator | Type of const iterator |
| reverse_iterator | Type of reverse iterator |
| const_reverse_iterator | Type of const reverse iterator |
Member function¶
Constructor¶
// (1)
btree_set();
// (2)
btree_set(const btree_set&);
// (3)
btree_set(btree_set&&);
// (4)
explicit btree_set(const key_compare& comp, const allocator_type& alloc = allocator_type());
// (5)
explicit btree_set(const allocator_type& alloc);
// (6)
template <class InputIterator>
btree_set(
InputIterator b,
InputIterator e,
const key_compare& comp = key_compare(),
const allocator_type& alloc = allocator_type()
);
// (7)
template <class InputIterator>
btree_set(InputIterator b, InputIterator e, const allocator_type& alloc);
// (8)
btree_set(const btree_set& x, const allocator_type& alloc);
// (9)
btree_set(btree_set&& x, const allocator_type& alloc);
// (10)
btree_set(
std::initializer_list<value_type> init,
const key_compare& comp = key_compare{},
const allocator_type& alloc = allocator_type{}
);
// (11)
btree_set(std::initializer_list<value_type> init, const allocator_type& alloc);
// (12)
btree_set& operator=(const btree_set& x);
// (13)
btree_set& operator=(btree_set&&) = default;
- Constructs an empty
btree_set. - Copy constructor. The allocator is copied by
std::allocator_traits::select_on_container_copy_construction. - Move constructor. The allocator is copied by
operator=. - Constructs an empty
btree_setwithcompandalloc. - Constructs an empty
btree_setwithalloc. - Constructs a
btree_setwithcompandallocby inserting values frombtoe(eisn't included). - Constructs a
btree_setwithallocby inserting values frombtoe(eisn't included). - Constructs a copy of
xwithalloc. - Constructs a
btree_setto whichxis moved withalloc. - Constructs a
btree_setwithcompandallocfrom an initializer list. - Constructs a
btree_setwithallocfrom an initializer list. - Assigns a copy of
xand return*this. Ifxis*this, does nothing. - Default move assignment operator.
Iterator¶
// (1)
iterator begin();
// (2)
const_iterator begin() const;
// (3)
const_iterator cbegin() const;
// (4)
iterator end();
// (5)
const_iterator end() const;
// (6)
const_iterator cend() const;
// (7)
reverse_iterator rbegin();
// (8)
const_reverse_iterator rbegin() const;
// (9)
const_reverse_iterator crbegin() const;
// (10)
reverse_iterator rend();
// (11)
const_reverse_iterator rend() const;
// (12)
const_reverse_iterator crend() const;
- Return the iterator pointing to the first value of
*this. - The
constversion of 1. - Return the const iterator pointing to the first value of
*this. - Return the iterator pointing to the next address of the last value of
*this. - The
constversion of 4. - Return the const iterator pointing to the next address of the last value of
*this. - Return the reverse iterator pointing to the last value of
*this. - The
constversion of 7. - Return the const reverse iterator pointing to the last value of
*this. - Return the reverse iterator pointing to the previous address of the first value of
*this. - The
constversion of 10. - Return the const reverse iterator pointing to the previous address of the first value of
*this.
Modifiers¶
// (1)
void clear();
// (2)
void swap(btree_set& x);
// (3)
void merge(btree_set& x);
// (4)
void merge(btree_set&& x);
- Clear
*this, i.e., delete all values in*this. - Swap
*thisforx. - Merge another
btree_set. The duplicated values will not be merged to*this. - Same as 3. This function is provided to receive an rvalue
btree_set, so no rvalue-specific optimization is done.
insert¶
// (1)
std::pair<iterator, bool> insert(const value_type& x);
// (2)
std::pair<iterator, bool> insert(value_type&& x);
// (3)
iterator insert(iterator hint, const value_type& x);
// (4)
iterator insert(iterator hint, value_type&& x);
// (5)
template <typename InputIterator>
void insert(InputIterator b, InputIterator e);
// (6)
void insert(std::initializer_list<value_type> list);
- If there is
xin*this, returns an iterator pointing toxin*thisandfalse. Otherwise, insertsxand returns an iterator pointing toxin*thisandtrue. - The rvalue version of 1.
- Does 1 with hint. If the value is placed immediately before
hintin the tree, the insertion will take amortized constant time. If not, the insertion will take amortized logarithmic time as if a call toinsert(x)were made. - The rvalue version of 3.
- Does 1 for each value from
btoe(eisn't included). - Does 1 for each value of
list.
erase¶
size_type erase(const key_type& key);
iterator erase(const iterator& iter);
void erase(const iterator& b, const iterator& e);
- Erases the specified key from
*thisand returns - Erases the specified iterator from
*this. The iterator must be valid (i.e. not equal to end()). Return an iterator pointing to the node after the one that was erased (or end() if none exists). - Erases a range from
btoe(eisn't included) and return the number of erased keys.
Lookup¶
// (1)
iterator lower_bound(const key_type& key);
// (2)
const_iterator lower_bound(const key_type& key) const;
// (3)
iterator upper_bound(const key_type& key);
// (4)
const_iterator upper_bound(const key_type& key) const;
// (5)
std::pair<iterator, iterator> equal_range(const key_type& key);
// (6)
std::pair<const_iterator, const_iterator> equal_range(const key_type& key) const;
// (7)
iterator find(const key_type& key);
// (8)
const_iterator find(const key_type& key) const;
// (9)
size_type count(const key_type& key) const;
// (10)
bool contains(const key_type& key) const;
- If
*thisis empty orkeyisn't found, returnsend(). Otherwise, returns an iterator which points to the minimum value in all values which are not less thankey. - The
constversion of 1. - If
*thisis empty orkeyisn't found, returnsend(). Otherwise, returns an iterator which points to the minimum value in all values which are greater thankey. - The
constversion of 3. - If
*thisis empty orkeyisn't found, returnsend(). Otherwise, returns a pair of the iterators which point to the fist value in all values which are equal tokeyand the value next to the last value in them in order. - The
constversion of 5. - If
*thisis empty orkeyisn't found, returnsend(). Otherwise, returns an iterator which points to the fist value in all values which are equal tokey. - The
constversion of 7. - If
*thisis empty orkeyisn't found, returns0. Otherwise, returns1. - If
*thisis empty orkeyisn't found, returnsfalse. Otherwise, returnstrue.
Capacity¶
- Returns the number of values.
- Returns the max number of values.
- Returns a bool whether
*thisis empty or not.
Observers¶
Returns the key_compare object used by *this.
non-STL¶
[WARNING] The following functions may be suddenly deleted.
// (1)
size_type height() const;
// (2)
size_type internal_nodes() const;
// (3)
size_type leaf_nodes() const;
// (4)
size_type nodes() const;
// (5)
size_type bytes_used() const;
// (6)
double average_bytes_per_value() const;
// (7)
double fullness() const;
// (8)
double overhead() const;
// (9)
void dump(std::ostream& os) const;
// (10)
void verify() const;
// (11)
static constexpr std::size_t sizeof_leaf_node();
// (12)
static constexpr std::size_t sizeof_internal_node();
- Returns the hight of
*this. - Returns the number of internal nodes.
- Returns the number of leaf nodes.
- Returns the total of internal nodes and leaf nodes.
- Returns the total of bytes used by
*this. - Returns the average bytes per value.
- Returns the fullness of
*this, which is computed as the number of elements in*thisdivided by the maximum number of elements a tree with the current number of nodes could hold. A value of 1 indicates perfect space utilization. Smaller values indicate space wastage. - Returns the overhead of the btree structure in bytes per node, which is computed as the total number of bytes used by
*thisminus the number of bytes used for storing elements divided by the number of values. - Dumps the btree to the specified ostream. Requires that
operator<<is defined for value. - Verifies the structure of
*this. - Returns the size of a leaf node.
- Returns the size of a internal node.
Non-member function¶
Swap¶
template <typename K, typename C, typename A, std::size_t N>
void swap(btree_set<K, C, A, N>& x, btree_set<K, C, A, N>& y);
Swap x for y using std::swap to swap each member variable of x for that of y.