Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::FlatMap< Key, T, Compare > Class Template Reference

Ordered map stored as two parallel sorted contiguous arrays. More...

#include <tpl_flat_map.H>

Collaboration diagram for Aleph::FlatMap< Key, T, Compare >:
[legend]

Classes

class  basic_iterator
 Random-access proxy iterator over (key, value) entries. More...
 

Public Types

using Item_Type = std::pair< Key, T >
 Aleph convention: element type.
 
using Key_Type = Key
 Aleph convention: key type.
 
using key_type = Key
 STL convention: key type.
 
using mapped_type = T
 STL convention: mapped type.
 
using value_type = std::pair< Key, T >
 STL convention: value type.
 
using key_compare = Compare
 STL convention: comparator type.
 
using size_type = size_t
 STL convention: size type.
 
using iterator = basic_iterator< false >
 Mutable-value iterator.
 
using const_iterator = basic_iterator< true >
 Const-value iterator.
 

Public Member Functions

 FlatMap (size_t cap=MemArray< Key >::Min_Dim)
 Construct an empty map.
 
 FlatMap (const Compare &cmp, size_t cap=MemArray< Key >::Min_Dim)
 Construct an empty map with a specific comparator.
 
template<class It >
requires requires(It first, It last, MemArray<Key> & ks, MemArray<T> & vs, const std::remove_reference_t<std::iter_reference_t<It>> & p) { static_cast<bool>(first != last); ++first; ks.put(p.first); vs.put(p.second); }
 FlatMap (It first, It last, const Compare &cmp=Compare())
 Construct from an iterator range of pairs.
 
 FlatMap (std::initializer_list< std::pair< Key, T > > l, const Compare &cmp=Compare())
 Construct from an initializer list of pairs.
 
 FlatMap (const FlatMap &)=default
 Copy constructor (requires copyable Key and T).
 
 FlatMap (FlatMap &&) noexcept=default
 Move constructor. The source is left valid but unspecified.
 
FlatMap & operator= (const FlatMap &)=default
 Copy assignment (requires copyable Key and T).
 
FlatMap & operator= (FlatMap &&) noexcept=default
 Move assignment. The source is left valid but unspecified.
 
 ~FlatMap ()=default
 
void swap (FlatMap &m) noexcept(std::is_nothrow_swappable_v< Compare >)
 Swap contents with m in O(1).
 
size_t size () const noexcept
 Return the number of stored entries. O(1).
 
bool is_empty () const noexcept
 Return true if the map holds no entries. O(1).
 
size_t capacity () const noexcept
 Return the capacity of the backing key array. O(1).
 
void reserve (size_t cap)
 Reserve capacity for at least cap entries.
 
void empty () noexcept
 Remove all entries (Aleph convention).
 
void clear () noexcept
 Remove all entries. Alias of empty(). Capacity is kept.
 
iterator find (const Key &k)
 Find the entry with key k.
 
const_iterator find (const Key &k) const
 
bool contains (const Key &k) const
 Test whether key k is mapped.
 
size_t count (const Key &k) const
 Count entries with key k (0 or 1).
 
iterator lower_bound (const Key &k)
 First entry whose key is not less than k.
 
const_iterator lower_bound (const Key &k) const
 
iterator upper_bound (const Key &k)
 First entry whose key is greater than k.
 
const_iterator upper_bound (const Key &k) const
 
std::pair< iterator, iterator > equal_range (const Key &k)
 Range of entries with key equivalent to k.
 
std::pair< const_iterator, const_iterator > equal_range (const Key &k) const
 
T & at (const Key &k)
 Checked access to the value mapped to k.
 
const T & at (const Key &k) const
 
T & operator[] (const Key &k)
 Access the value mapped to k, inserting a default if absent.
 
T & operator[] (Key &&k)
 Access the value mapped to k, inserting a default if absent.
 
const Key & nth_key (size_t i) const
 Key of the i-th entry in sorted order (checked).
 
T & nth_value (size_t i)
 Value of the i-th entry in sorted order (checked).
 
const T & nth_value (size_t i) const
 
std::pair< iterator, bool > insert (const Key &k, const T &v)
 Insert (k, v) if k is not mapped.
 
std::pair< iterator, bool > insert (Key &&k, T &&v)
 
std::pair< iterator, bool > insert (const std::pair< Key, T > &p)
 Insert a (key, value) pair if the key is not mapped.
 
std::pair< iterator, bool > insert (std::pair< Key, T > &&p)
 
std::pair< iterator, bool > insert_or_assign (const Key &k, const T &v)
 Insert (k, v) or overwrite the value if k is mapped.
 
std::pair< iterator, bool > insert_or_assign (Key &&k, T &&v)
 
template<class... KArgs>
std::pair< iterator, bool > emplace (KArgs &&...kargs)
 Build a key from kargs and insert it with a default value.
 
size_t erase (const Key &k)
 Remove the entry with key k, if present.
 
iterator erase (const_iterator it)
 Remove the entry at iterator it.
 
iterator begin () noexcept
 Iterator to the entry with the smallest key. O(1).
 
iterator end () noexcept
 Iterator past the entry with the greatest key. O(1).
 
const_iterator begin () const noexcept
 Const iterator to the entry with the smallest key. O(1).
 
const_iterator end () const noexcept
 Const iterator past the entry with the greatest key. O(1).
 
const_iterator cbegin () const noexcept
 Const iterator to the entry with the smallest key. O(1).
 
const_iterator cend () const noexcept
 Const iterator past the entry with the greatest key. O(1).
 
const Key * keys_data () const noexcept
 Pointer to the sorted, contiguous key storage. O(1).
 
T * values_data () noexcept
 Pointer to the contiguous value storage (parallel to keys). O(1).
 
const T * values_data () const noexcept
 
DynList< Key > keys () const
 Copy all keys, in ascending order, into a DynList.
 
DynList< T > values () const
 Copy all values, in ascending key order, into a DynList.
 
template<class Operation >
bool traverse (Operation operation)
 Traverse entries in key order while operation returns true.
 
template<class Operation >
bool traverse (Operation operation) const
 Const traversal in key order while operation returns true.
 
bool operator== (const FlatMap &m) const
 Equality: same size and pairwise equal keys and values.
 
bool operator!= (const FlatMap &m) const
 Inequality: negation of operator==.
 

Private Member Functions

size_t lower_idx (const Key &k) const
 
size_t upper_idx (const Key &k) const
 
bool match_at (size_t pos, const Key &k) const
 
void make_room (const size_t pos)
 
void remove_at (const size_t pos)
 
void sort_and_unique ()
 

Private Attributes

MemArray< Key > keys_
 
MemArray< T > vals_
 
Compare cmp_
 

Detailed Description

template<typename Key, typename T, class Compare = Aleph::less<Key>>
class Aleph::FlatMap< Key, T, Compare >

Ordered map stored as two parallel sorted contiguous arrays.

Keys live in a sorted MemArray<Key>; the value associated with keys[i] lives at values[i]. Lookups binary-search the key array only. Keys equivalent under Compare are unique.

Template Parameters
KeyType of the keys. Must be default-constructible, move-constructible and move-assignable (from MemArray).
TType of the mapped values. Same base requirements.
CompareStrict weak ordering over Key. Defaults to Aleph::less<Key>.
Iterators
Random-access proxy iterators: *it is a lightweight object with public members first (a const Key &) and second (a T &, or const T & through const_iterator). Any insertion or removal invalidates all iterators.
Aleph conventions
Following the library convention (see Array), empty() clears the container and is_empty() is the emptiness predicate.
Exception Safety
insert and operator[] offer the strong guarantee up to the element shift; if a key/value assignment throws mid-shift the guarantee degrades to basic (the map remains valid). erase always removes the entry; a failed shrinking reallocation is ignored.
Thread Safety
Distinct instances may be used from distinct threads. Concurrent access to the same instance requires external synchronization.
Example
FlatMap<std::string, int> m = {{"b", 2}, {"a", 1}};
m["c"] = 3; // insert
m["a"] += 10; // update
for (auto [k, v] : m) // sorted by key: a, b, c
std::cout << k << " = " << v << "\n";
Ordered map stored as two parallel sorted contiguous arrays.
STL namespace.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
static int * k

Definition at line 127 of file tpl_flat_map.H.

Member Typedef Documentation

◆ const_iterator

template<typename Key , typename T , class Compare = Aleph::less<Key>>
using Aleph::FlatMap< Key, T, Compare >::const_iterator = basic_iterator<true>

Const-value iterator.

Definition at line 447 of file tpl_flat_map.H.

◆ Item_Type

template<typename Key , typename T , class Compare = Aleph::less<Key>>
using Aleph::FlatMap< Key, T, Compare >::Item_Type = std::pair<Key, T>

Aleph convention: element type.

Definition at line 253 of file tpl_flat_map.H.

◆ iterator

template<typename Key , typename T , class Compare = Aleph::less<Key>>
using Aleph::FlatMap< Key, T, Compare >::iterator = basic_iterator<false>

Mutable-value iterator.

Definition at line 446 of file tpl_flat_map.H.

◆ key_compare

template<typename Key , typename T , class Compare = Aleph::less<Key>>
using Aleph::FlatMap< Key, T, Compare >::key_compare = Compare

STL convention: comparator type.

Definition at line 258 of file tpl_flat_map.H.

◆ Key_Type

template<typename Key , typename T , class Compare = Aleph::less<Key>>
using Aleph::FlatMap< Key, T, Compare >::Key_Type = Key

Aleph convention: key type.

Definition at line 254 of file tpl_flat_map.H.

◆ key_type

template<typename Key , typename T , class Compare = Aleph::less<Key>>
using Aleph::FlatMap< Key, T, Compare >::key_type = Key

STL convention: key type.

Definition at line 255 of file tpl_flat_map.H.

◆ mapped_type

template<typename Key , typename T , class Compare = Aleph::less<Key>>
using Aleph::FlatMap< Key, T, Compare >::mapped_type = T

STL convention: mapped type.

Definition at line 256 of file tpl_flat_map.H.

◆ size_type

template<typename Key , typename T , class Compare = Aleph::less<Key>>
using Aleph::FlatMap< Key, T, Compare >::size_type = size_t

STL convention: size type.

Definition at line 259 of file tpl_flat_map.H.

◆ value_type

template<typename Key , typename T , class Compare = Aleph::less<Key>>
using Aleph::FlatMap< Key, T, Compare >::value_type = std::pair<Key, T>

STL convention: value type.

Definition at line 257 of file tpl_flat_map.H.

Constructor & Destructor Documentation

◆ FlatMap() [1/6]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::FlatMap ( size_t  cap = MemArray<Key>::Min_Dim)
inlineexplicit

Construct an empty map.

Parameters
capInitial capacity hint (rounded up to a power of two by the backing MemArrays).
Exceptions
std::bad_allocif the initial buffers cannot be allocated.

Definition at line 455 of file tpl_flat_map.H.

◆ FlatMap() [2/6]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::FlatMap ( const Compare &  cmp,
size_t  cap = MemArray<Key>::Min_Dim 
)
inlineexplicit

Construct an empty map with a specific comparator.

Parameters
cmpComparator instance to copy.
capInitial capacity hint.
Exceptions
std::bad_allocif the initial buffers cannot be allocated.

Definition at line 463 of file tpl_flat_map.H.

◆ FlatMap() [3/6]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
template<class It >
requires requires(It first, It last, MemArray<Key> & ks, MemArray<T> & vs, const std::remove_reference_t<std::iter_reference_t<It>> & p) { static_cast<bool>(first != last); ++first; ks.put(p.first); vs.put(p.second); }
Aleph::FlatMap< Key, T, Compare >::FlatMap ( It  first,
It  last,
const Compare &  cmp = Compare() 
)
inline

Construct from an iterator range of pairs.

Loads all entries, then sorts once by key and removes duplicate keys: O(m log m) for m input entries.

Template Parameters
ItIterator whose dereferenced entry exposes first and second convertible to Key and T (a std::pair, or this map's own (key, value) proxy).
Parameters
firstBeginning of the range.
lastEnd of the range.
cmpComparator instance (defaulted).
Exceptions
std::bad_allocif memory allocation fails.
Note
On duplicate (equivalent) keys the first occurrence wins.

Definition at line 493 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::keys_, Aleph::MemArray< T >::put(), Aleph::FlatMap< Key, T, Compare >::sort_and_unique(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ FlatMap() [4/6]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::FlatMap ( std::initializer_list< std::pair< Key, T > >  l,
const Compare &  cmp = Compare() 
)
inline

Construct from an initializer list of pairs.

Parameters
lEntries to load; duplicate keys are dropped (first wins).
cmpComparator instance (defaulted).
Exceptions
std::bad_allocif memory allocation fails.

Definition at line 511 of file tpl_flat_map.H.

◆ FlatMap() [5/6]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::FlatMap ( const FlatMap< Key, T, Compare > &  )
default

Copy constructor (requires copyable Key and T).

◆ FlatMap() [6/6]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::FlatMap ( FlatMap< Key, T, Compare > &&  )
defaultnoexcept

Move constructor. The source is left valid but unspecified.

◆ ~FlatMap()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::~FlatMap ( )
default

Member Function Documentation

◆ at() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::at ( const Key &  k)
inline

Checked access to the value mapped to k.

Parameters
kKey to search for.
Returns
Mutable reference to the mapped value.
Exceptions
std::out_of_rangeif k is not mapped.
Note
Complexity: O(log n).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 679 of file tpl_flat_map.H.

References ah_out_of_range_error_if, Aleph::blossom_maximum_cardinality_matching(), k, Aleph::FlatMap< Key, T, Compare >::lower_idx(), Aleph::FlatMap< Key, T, Compare >::match_at(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ at() [2/2]

◆ begin() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const_iterator Aleph::FlatMap< Key, T, Compare >::begin ( ) const
inlinenoexcept

Const iterator to the entry with the smallest key. O(1).

Definition at line 906 of file tpl_flat_map.H.

References Aleph::MemArray< T >::get_ptr(), Aleph::FlatMap< Key, T, Compare >::keys_, and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ begin() [2/2]

◆ capacity()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
size_t Aleph::FlatMap< Key, T, Compare >::capacity ( ) const
inlinenoexcept

Return the capacity of the backing key array. O(1).

Definition at line 554 of file tpl_flat_map.H.

References Aleph::MemArray< T >::capacity(), and Aleph::FlatMap< Key, T, Compare >::keys_.

◆ cbegin()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const_iterator Aleph::FlatMap< Key, T, Compare >::cbegin ( ) const
inlinenoexcept

Const iterator to the entry with the smallest key. O(1).

Definition at line 918 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::begin().

◆ cend()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const_iterator Aleph::FlatMap< Key, T, Compare >::cend ( ) const
inlinenoexcept

Const iterator past the entry with the greatest key. O(1).

Definition at line 924 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::end().

◆ clear()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
void Aleph::FlatMap< Key, T, Compare >::clear ( )
inlinenoexcept

Remove all entries. Alias of empty(). Capacity is kept.

Definition at line 580 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::empty().

◆ contains()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
bool Aleph::FlatMap< Key, T, Compare >::contains ( const Key &  k) const
inline

Test whether key k is mapped.

Parameters
kKey to search for.
Returns
true if an equivalent key is stored.
Note
Complexity: O(log n).

Definition at line 610 of file tpl_flat_map.H.

References k, Aleph::FlatMap< Key, T, Compare >::lower_idx(), and Aleph::FlatMap< Key, T, Compare >::match_at().

Referenced by Aleph::FlatMap< Key, T, Compare >::count().

◆ count()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
size_t Aleph::FlatMap< Key, T, Compare >::count ( const Key &  k) const
inline

Count entries with key k (0 or 1).

Parameters
kKey to search for.
Returns
1 if present, 0 otherwise.
Note
Complexity: O(log n).

Definition at line 620 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::contains(), and k.

◆ emplace()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
template<class... KArgs>
std::pair< iterator, bool > Aleph::FlatMap< Key, T, Compare >::emplace ( KArgs &&...  kargs)
inline

Build a key from kargs and insert it with a default value.

Convenience over insert(Key(kargs...), T()): the key is constructed once and moved into position; the value is default-constructed.

Template Parameters
KArgsArgument types forwarded to Key's constructor.
Parameters
kargsArguments for the key.
Returns
Pair of (iterator to the entry, insertion flag).
Exceptions
std::bad_allocif a growing reallocation fails.

Definition at line 857 of file tpl_flat_map.H.

References Aleph::blossom_maximum_cardinality_matching(), and Aleph::FlatMap< Key, T, Compare >::insert().

◆ empty()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
void Aleph::FlatMap< Key, T, Compare >::empty ( )
inlinenoexcept

Remove all entries (Aleph convention).

Capacity is kept.

Note
Following the Aleph container convention (see Array::empty()), this mutates the map; use is_empty() to test for emptiness.

Definition at line 573 of file tpl_flat_map.H.

References Aleph::MemArray< T >::empty(), Aleph::FlatMap< Key, T, Compare >::keys_, and Aleph::FlatMap< Key, T, Compare >::vals_.

Referenced by Aleph::FlatMap< Key, T, Compare >::clear().

◆ end() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const_iterator Aleph::FlatMap< Key, T, Compare >::end ( ) const
inlinenoexcept

Const iterator past the entry with the greatest key. O(1).

Definition at line 912 of file tpl_flat_map.H.

References Aleph::MemArray< T >::get_ptr(), Aleph::FlatMap< Key, T, Compare >::keys_, Aleph::FlatMap< Key, T, Compare >::size(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ end() [2/2]

◆ equal_range() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::equal_range ( const Key &  k)
inline

Range of entries with key equivalent to k.

Parameters
kKey to bound.
Returns
Pair {lower_bound(k), upper_bound(k)} (length 0 or 1).
Note
Complexity: O(log n).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 662 of file tpl_flat_map.H.

References k, Aleph::FlatMap< Key, T, Compare >::lower_bound(), and Aleph::FlatMap< Key, T, Compare >::upper_bound().

◆ equal_range() [2/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
std::pair< const_iterator, const_iterator > Aleph::FlatMap< Key, T, Compare >::equal_range ( const Key &  k) const
inline

◆ erase() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
size_t Aleph::FlatMap< Key, T, Compare >::erase ( const Key &  k)
inline

Remove the entry with key k, if present.

Parameters
kKey to remove.
Returns
Number of removed entries (0 or 1).
Note
Complexity: O(log n) search + O(n) shift. Never throws on the removal itself; failed shrinking reallocations are ignored.

Definition at line 868 of file tpl_flat_map.H.

References Aleph::blossom_maximum_cardinality_matching(), k, Aleph::FlatMap< Key, T, Compare >::lower_idx(), Aleph::FlatMap< Key, T, Compare >::match_at(), and Aleph::FlatMap< Key, T, Compare >::remove_at().

◆ erase() [2/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
iterator Aleph::FlatMap< Key, T, Compare >::erase ( const_iterator  it)
inline

Remove the entry at iterator it.

Parameters
itValid dereferenceable iterator into this map.
Returns
Iterator to the entry following the removed one.
Exceptions
std::out_of_rangeif it does not point into the map.
Note
Complexity: O(n) shift. All other iterators are invalidated.

Definition at line 883 of file tpl_flat_map.H.

References ah_out_of_range_error_if, Aleph::FlatMap< Key, T, Compare >::begin(), Aleph::MemArray< T >::get_ptr(), Aleph::FlatMap< Key, T, Compare >::basic_iterator< IsConst >::key_ptr(), Aleph::FlatMap< Key, T, Compare >::keys_, Aleph::FlatMap< Key, T, Compare >::remove_at(), and Aleph::FlatMap< Key, T, Compare >::size().

◆ find() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::find ( const Key &  k)
inline

Find the entry with key k.

Parameters
kKey to search for.
Returns
Iterator to the matching entry, or end() if absent.
Note
Complexity: O(log n) over the contiguous key array.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 592 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::begin(), Aleph::FlatMap< Key, T, Compare >::end(), k, Aleph::FlatMap< Key, T, Compare >::lower_idx(), and Aleph::FlatMap< Key, T, Compare >::match_at().

◆ find() [2/2]

◆ insert() [1/4]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::insert ( const Key &  k,
const T &  v 
)
inline

Insert (k, v) if k is not mapped.

Parameters
kKey to insert.
vValue to associate.
Returns
Pair of (iterator to the entry, true if inserted / false if the key was already mapped — the existing value is kept).
Exceptions
std::bad_allocif a growing reallocation fails.
Note
Complexity: O(log n) search + O(n) shift.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 770 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::begin(), Aleph::MemArray< T >::get_ptr(), k, Aleph::FlatMap< Key, T, Compare >::keys_, Aleph::FlatMap< Key, T, Compare >::lower_idx(), Aleph::FlatMap< Key, T, Compare >::make_room(), Aleph::FlatMap< Key, T, Compare >::match_at(), and Aleph::FlatMap< Key, T, Compare >::vals_.

Referenced by Aleph::FlatMap< Key, T, Compare >::emplace(), Aleph::FlatMap< Key, T, Compare >::insert(), and Aleph::FlatMap< Key, T, Compare >::insert().

◆ insert() [2/4]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::insert ( const std::pair< Key, T > &  p)
inline

Insert a (key, value) pair if the key is not mapped.

Parameters
pPair to insert.
Returns
Pair of (iterator to the entry, insertion flag).
Exceptions
std::bad_allocif a growing reallocation fails.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 798 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::insert().

◆ insert() [3/4]

◆ insert() [4/4]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
std::pair< iterator, bool > Aleph::FlatMap< Key, T, Compare >::insert ( std::pair< Key, T > &&  p)
inline

Definition at line 804 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::insert().

◆ insert_or_assign() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::insert_or_assign ( const Key &  k,
const T &  v 
)
inline

Insert (k, v) or overwrite the value if k is mapped.

Parameters
kKey to insert or update.
vValue to associate.
Returns
Pair of (iterator to the entry, true if inserted / false if an existing value was overwritten).
Exceptions
std::bad_allocif a growing reallocation fails.
Note
Complexity: O(log n) on update, O(n) on insertion.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 817 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::begin(), Aleph::MemArray< T >::get_ptr(), k, Aleph::FlatMap< Key, T, Compare >::keys_, Aleph::FlatMap< Key, T, Compare >::lower_idx(), Aleph::FlatMap< Key, T, Compare >::make_room(), Aleph::FlatMap< Key, T, Compare >::match_at(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ insert_or_assign() [2/2]

◆ is_empty()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
bool Aleph::FlatMap< Key, T, Compare >::is_empty ( ) const
inlinenoexcept

Return true if the map holds no entries. O(1).

Definition at line 548 of file tpl_flat_map.H.

References Aleph::MemArray< T >::is_empty(), and Aleph::FlatMap< Key, T, Compare >::keys_.

◆ keys()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
DynList< Key > Aleph::FlatMap< Key, T, Compare >::keys ( ) const
inline

Copy all keys, in ascending order, into a DynList.

Returns
List of keys sorted according to Compare.
Exceptions
std::bad_allocif memory allocation fails.
Note
Complexity: O(n) copies.

Definition at line 952 of file tpl_flat_map.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::MemArray< T >::get_ptr(), Aleph::FlatMap< Key, T, Compare >::keys_, and Aleph::FlatMap< Key, T, Compare >::size().

◆ keys_data()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const Key * Aleph::FlatMap< Key, T, Compare >::keys_data ( ) const
inlinenoexcept

Pointer to the sorted, contiguous key storage. O(1).

Definition at line 930 of file tpl_flat_map.H.

References Aleph::MemArray< T >::get_ptr(), and Aleph::FlatMap< Key, T, Compare >::keys_.

◆ lower_bound() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::lower_bound ( const Key &  k)
inline

First entry whose key is not less than k.

Parameters
kKey to bound.
Returns
Iterator to the bound, or end().
Note
Complexity: O(log n).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 630 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::begin(), k, and Aleph::FlatMap< Key, T, Compare >::lower_idx().

Referenced by Aleph::FlatMap< Key, T, Compare >::equal_range(), and Aleph::FlatMap< Key, T, Compare >::equal_range().

◆ lower_bound() [2/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const_iterator Aleph::FlatMap< Key, T, Compare >::lower_bound ( const Key &  k) const
inline

◆ lower_idx()

◆ make_room()

◆ match_at()

◆ nth_key()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const Key & Aleph::FlatMap< Key, T, Compare >::nth_key ( size_t  i) const
inline

Key of the i-th entry in sorted order (checked).

Parameters
iZero-based rank.
Returns
Const reference to the i-th key.
Exceptions
std::out_of_rangeif i >= size().
Note
Complexity: O(1).

Definition at line 738 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::keys_.

◆ nth_value() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::nth_value ( size_t  i)
inline

Value of the i-th entry in sorted order (checked).

Parameters
iZero-based rank.
Returns
Mutable reference to the i-th value.
Exceptions
std::out_of_rangeif i >= size().
Note
Complexity: O(1).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 749 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::vals_.

◆ nth_value() [2/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const T & Aleph::FlatMap< Key, T, Compare >::nth_value ( size_t  i) const
inline

Definition at line 755 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::vals_.

◆ operator!=()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
bool Aleph::FlatMap< Key, T, Compare >::operator!= ( const FlatMap< Key, T, Compare > &  m) const
inline

Inequality: negation of operator==.

Definition at line 1029 of file tpl_flat_map.H.

References Aleph::blossom_maximum_cardinality_matching(), and m.

◆ operator=() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
FlatMap & Aleph::FlatMap< Key, T, Compare >::operator= ( const FlatMap< Key, T, Compare > &  )
default

Copy assignment (requires copyable Key and T).

◆ operator=() [2/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
FlatMap & Aleph::FlatMap< Key, T, Compare >::operator= ( FlatMap< Key, T, Compare > &&  )
defaultnoexcept

Move assignment. The source is left valid but unspecified.

◆ operator==()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
bool Aleph::FlatMap< Key, T, Compare >::operator== ( const FlatMap< Key, T, Compare > &  m) const
inline

Equality: same size and pairwise equal keys and values.

Parameters
mMap to compare against.
Returns
true if both maps hold equal entries in the same order.
Note
Complexity: O(n). Requires Key and T equality comparable.

Definition at line 1021 of file tpl_flat_map.H.

References Aleph::and, Aleph::MemArray< T >::get_ptr(), Aleph::FlatMap< Key, T, Compare >::keys_, m, OhashCommon< HashTbl, Key >::size(), Aleph::FlatMap< Key, T, Compare >::size(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ operator[]() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
T & Aleph::FlatMap< Key, T, Compare >::operator[] ( const Key &  k)
inline

Access the value mapped to k, inserting a default if absent.

Parameters
kKey to search for or insert.
Returns
Mutable reference to the mapped value.
Exceptions
std::bad_allocif a growing reallocation fails.
Note
Complexity: O(log n) on hit, O(n) on insertion.

Definition at line 700 of file tpl_flat_map.H.

References Aleph::MemArray< T >::get_ptr(), k, Aleph::FlatMap< Key, T, Compare >::keys_, Aleph::FlatMap< Key, T, Compare >::lower_idx(), Aleph::FlatMap< Key, T, Compare >::make_room(), Aleph::FlatMap< Key, T, Compare >::match_at(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ operator[]() [2/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
T & Aleph::FlatMap< Key, T, Compare >::operator[] ( Key &&  k)
inline

Access the value mapped to k, inserting a default if absent.

Same as the const-reference overload, but moves k on insertion.

Parameters
kKey to search for or insert (moved on insertion).
Returns
Mutable reference to the mapped value.
Exceptions
std::bad_allocif a growing reallocation fails.

Definition at line 719 of file tpl_flat_map.H.

References Aleph::MemArray< T >::get_ptr(), k, Aleph::FlatMap< Key, T, Compare >::keys_, Aleph::FlatMap< Key, T, Compare >::lower_idx(), Aleph::FlatMap< Key, T, Compare >::make_room(), Aleph::FlatMap< Key, T, Compare >::match_at(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ remove_at()

◆ reserve()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
void Aleph::FlatMap< Key, T, Compare >::reserve ( size_t  cap)
inline

Reserve capacity for at least cap entries.

Parameters
capDesired capacity (rounded up to a power of two).
Exceptions
std::bad_allocif memory allocation fails.

Definition at line 563 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::keys_, Aleph::MemArray< T >::reserve(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ size()

◆ sort_and_unique()

◆ swap()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
void Aleph::FlatMap< Key, T, Compare >::swap ( FlatMap< Key, T, Compare > &  m)
inlinenoexcept

Swap contents with m in O(1).

Parameters
mMap to swap with.

Definition at line 532 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::cmp_, Aleph::FlatMap< Key, T, Compare >::keys_, m, Aleph::MemArray< T >::swap(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ traverse() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
template<class Operation >
bool Aleph::FlatMap< Key, T, Compare >::traverse ( Operation  operation)
inline

Traverse entries in key order while operation returns true.

Aleph-style bounded traversal: operation receives (const Key &, T &) in ascending key order; returning false stops the walk.

Template Parameters
OperationCallable bool(const Key &, T &).
Parameters
operationOperation to apply.
Returns
true if all entries were visited, false if stopped early.

Definition at line 985 of file tpl_flat_map.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::MemArray< T >::get_ptr(), Aleph::FlatMap< Key, T, Compare >::keys_, m, Aleph::FlatMap< Key, T, Compare >::size(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ traverse() [2/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
template<class Operation >
bool Aleph::FlatMap< Key, T, Compare >::traverse ( Operation  operation) const
inline

Const traversal in key order while operation returns true.

Template Parameters
OperationCallable bool(const Key &, const T &).
Parameters
operationOperation to apply.
Returns
true if all entries were visited, false if stopped early.

Definition at line 1003 of file tpl_flat_map.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::MemArray< T >::get_ptr(), Aleph::FlatMap< Key, T, Compare >::keys_, m, Aleph::FlatMap< Key, T, Compare >::size(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ upper_bound() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::upper_bound ( const Key &  k)
inline

First entry whose key is greater than k.

Parameters
kKey to bound.
Returns
Iterator to the bound, or end().
Note
Complexity: O(log n).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 646 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::begin(), k, and Aleph::FlatMap< Key, T, Compare >::upper_idx().

Referenced by Aleph::FlatMap< Key, T, Compare >::equal_range(), and Aleph::FlatMap< Key, T, Compare >::equal_range().

◆ upper_bound() [2/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const_iterator Aleph::FlatMap< Key, T, Compare >::upper_bound ( const Key &  k) const
inline

◆ upper_idx()

◆ values()

template<typename Key , typename T , class Compare = Aleph::less<Key>>
DynList< T > Aleph::FlatMap< Key, T, Compare >::values ( ) const
inline

Copy all values, in ascending key order, into a DynList.

Returns
List of values ordered by their keys.
Exceptions
std::bad_allocif memory allocation fails.
Note
Complexity: O(n) copies.

Definition at line 966 of file tpl_flat_map.H.

References Aleph::DynList< T >::append(), Aleph::blossom_maximum_cardinality_matching(), Aleph::FlatMap< Key, T, Compare >::size(), and Aleph::FlatMap< Key, T, Compare >::vals_.

◆ values_data() [1/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
const T * Aleph::FlatMap< Key, T, Compare >::values_data ( ) const
inlinenoexcept

Definition at line 942 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::vals_.

◆ values_data() [2/2]

template<typename Key , typename T , class Compare = Aleph::less<Key>>
Aleph::FlatMap< Key, T, Compare >::values_data ( )
inlinenoexcept

Pointer to the contiguous value storage (parallel to keys). O(1).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 936 of file tpl_flat_map.H.

References Aleph::FlatMap< Key, T, Compare >::vals_.

Member Data Documentation

◆ cmp_

◆ keys_

template<typename Key , typename T , class Compare = Aleph::less<Key>>
MemArray<Key> Aleph::FlatMap< Key, T, Compare >::keys_
private

◆ vals_


The documentation for this class was generated from the following file: