btree_map¶
In platanus/btree_map.hpp,
namespace platanus {
template <
typename Key,
typename Value,
typename Compare = std::ranges::less,
typename Alloc = std::allocator<Key>,
std::size_t MaxNumOfValues = 512>
class btree_map;
}
Template parameters¶
| Parameter | Meaning |
|---|---|
Key |
Type of a key |
Value |
Type of a value |
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. std::pair<const Key, Value> |
| mapped_type | Type of mapped value, i.e. Value |
| key_compare | Type of comparer of key, i.e. Compare |
| allocator_type | Type of allocator, i.e. Alloc |
| pointer | Type of pointer to value, i.e. value_type* |
| const_pointer | Type of pointer to const value, i.e. const value_type* |
| reference | Type of reference to value, i.e. value_type& |
| const_reference | Type of reference to const value, i.e. const value_type& |
| size_type | Unsigned integer type of size of btree_map, 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_map();
// (2)
btree_map(const btree_map&);
// (3)
btree_map(btree_map&&);
// (4)
explicit btree_map(const key_compare& comp, const allocator_type& alloc = allocator_type());
// (5)
explicit btree_map(const allocator_type& alloc);
// (6)
template <class InputIterator>
btree_map(
InputIterator b,
InputIterator e,
const key_compare& comp = key_compare(),
const allocator_type& alloc = allocator_type()
);
// (7)
template <class InputIterator>
btree_map(InputIterator b, InputIterator e, const allocator_type& alloc);
// (8)
btree_map(const btree_map& x, const allocator_type& alloc);
// (9)
btree_map(btree_map&& x, const allocator_type& alloc);
// (10)
btree_map(
std::initializer_list<value_type> init,
const key_compare& comp = key_compare{},
const allocator_type& alloc = allocator_type{}
);
// (11)
btree_map(std::initializer_list<value_type> init, const allocator_type& alloc);
// (12)
btree_map& operator=(const btree_map& x);
// (13)
btree_map& operator=(btree_map&&) = default;
- Constructs an empty
btree_map. - 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_mapwithcompandalloc. - Constructs an empty
btree_mapwithalloc. - Constructs a
btree_mapwithcompandallocby inserting values frombtoe(eisn't included). - Constructs a
btree_mapwithallocby inserting values frombtoe(eisn't included). - Constructs a copy of
xwithalloc. - Constructs a
btree_mapto whichxis moved withalloc. - Constructs a
btree_mapwithcompandallocfrom an initializer list. - Constructs a
btree_mapwithallocfrom 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_map& x);
// (3)
void merge(btree_map& x);
// (4)
void merge(btree_map&& x);
// (5)
mapped_type& operator[](const key_type& key);
// (6)
mapped_type& operator[](key_type&& key);
// (7)
mapped_type& at(const key_type& key);
// (8)
const mapped_type& at(const key_type& key) const;
- Clear
*this, i.e., delete all values in*this. - Swap
*thisforx. - Merge another
btree_map. The duplicated values will not be merged to*this. - Same as 3. This function is provided to receive an rvalue
btree_map, so no rvalue-specific optimization is done. - Return the reference of the value mapped to
key. Ifkeydoesn't exist, insertkeyand default constructedmapped_value. - The rvalue version of 5.
- Return the reference of the value mapped to
key. Ifkeydoesn't exist, throwstd::out_of_range. - The const version of 7.
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, returnsstd::make_pair(end(), end()). 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¶
1. Returns the number of values. 1. Returns the max number of values. 1. Returns a bool whether*this is empty or not.
Observers¶
Returns thekey_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_map<K, C, A, N>& x, btree_map<K, C, A, N>& y);
Swap x for y using std::swap to swap each member variable of x for that of y.