ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
flat_map< Key, Value, Storage > Struct Template Reference

Flat associative map with pluggable storage. More...

#include "flat_map.hpp"

Public Types

using storage_t = Storage< std::pair< Key, Value > >
 Underlying container type.
 
using iterator = decltype(begin(std::declval< storage_t & >()))
 Mutable iterator.
 
using const_iterator = decltype(begin(std::declval< const storage_t & >()))
 Const iterator.
 

Public Member Functions

 flat_map ()=default
 
 flat_map (std::initializer_list< std::pair< Key, Value > > init)
 Construct from an initializer list of key-value pairs.
 
iterator begin ()
 Return iterator to the first element.
 
const_iterator begin () const
 Return const iterator to the first element.
 
const_iterator cbegin () const
 Return const iterator to the first element.
 
iterator end ()
 Return iterator past the last element.
 
const_iterator end () const
 Return const iterator past the last element.
 
const_iterator cend () const
 Return const iterator past the last element.
 
size_t size () const
 Return the number of key-value pairs.
 
bool empty () const
 Return true if the map contains no elements.
 
void reserve (size_t n)
 Reserve storage for at least n elements.
 
size_t capacity () const
 Return the current storage capacity.
 
template<class K , class = std::enable_if_t<std::is_convertible<K, Key>{}>>
Value & operator[] (K &&k)
 Access or insert the value for key k.
 
template<class K , class = std::enable_if_t<std::is_convertible<K, Key>{}>>
iterator find (K &&k)
 Find the element with key k.
 
template<class K , class = std::enable_if_t<std::is_convertible<K, Key>{}>>
const_iterator find (K &&k) const
 Find the element with key k (const overload).
 
iterator erase (const_iterator it)
 Remove the element at it.
 
template<class P , class = std::enable_if_t<std::is_convertible<P,std::pair<Key, Value>>{}>>
void insert (P &&value)
 Insert or update a key-value pair.
 
bool operator== (const flat_map &rhs) const
 Compare two flat_maps for equality.
 
bool operator< (const flat_map &rhs) const
 Lexicographic less-than comparison (order-independent on keys).
 

Public Attributes

storage_t storage
 Contiguous key-value storage.
 

Private Member Functions

template<class K , class = std::enable_if_t<std::is_convertible<K, Key>{}>>
auto key_match (K &k)
 Return a predicate matching key k.
 

Detailed Description

template<class Key, class Value, template< class... >class Storage = std::vector>
struct flat_map< Key, Value, Storage >

Flat associative map with pluggable storage.

Template Parameters
KeyKey type. Must be equality-comparable.
ValueMapped value type.
StorageContainer template used for storage (default: std::vector). Must support emplace_back, erase, begin, end, size, and empty.

Definition at line 49 of file flat_map.hpp.

Member Typedef Documentation

◆ const_iterator

template<class Key , class Value , template< class... >class Storage = std::vector>
using flat_map< Key, Value, Storage >::const_iterator = decltype(begin(std::declval<const storage_t&>()))

Const iterator.

Definition at line 54 of file flat_map.hpp.

◆ iterator

template<class Key , class Value , template< class... >class Storage = std::vector>
using flat_map< Key, Value, Storage >::iterator = decltype(begin(std::declval<storage_t&>()))

Mutable iterator.

Definition at line 53 of file flat_map.hpp.

◆ storage_t

template<class Key , class Value , template< class... >class Storage = std::vector>
using flat_map< Key, Value, Storage >::storage_t = Storage<std::pair<Key, Value> >

Underlying container type.

Definition at line 50 of file flat_map.hpp.

Constructor & Destructor Documentation

◆ flat_map() [1/2]

template<class Key , class Value , template< class... >class Storage = std::vector>
flat_map< Key, Value, Storage >::flat_map ( )
default

◆ flat_map() [2/2]

template<class Key , class Value , template< class... >class Storage = std::vector>
flat_map< Key, Value, Storage >::flat_map ( std::initializer_list< std::pair< Key, Value > >  init)
inline

Construct from an initializer list of key-value pairs.

Parameters
initInitializer list.

Definition at line 59 of file flat_map.hpp.

Member Function Documentation

◆ begin() [1/2]

template<class Key , class Value , template< class... >class Storage = std::vector>
iterator flat_map< Key, Value, Storage >::begin ( )
inline

Return iterator to the first element.

Returns
Mutable begin iterator.

Definition at line 63 of file flat_map.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [2/2]

template<class Key , class Value , template< class... >class Storage = std::vector>
const_iterator flat_map< Key, Value, Storage >::begin ( ) const
inline

Return const iterator to the first element.

Returns
Const begin iterator.

Definition at line 68 of file flat_map.hpp.

Here is the call graph for this function:

◆ capacity()

template<class Key , class Value , template< class... >class Storage = std::vector>
size_t flat_map< Key, Value, Storage >::capacity ( ) const
inline

Return the current storage capacity.

Returns
Number of elements that can be stored without reallocation.

Definition at line 106 of file flat_map.hpp.

◆ cbegin()

template<class Key , class Value , template< class... >class Storage = std::vector>
const_iterator flat_map< Key, Value, Storage >::cbegin ( ) const
inline

Return const iterator to the first element.

Returns
Const begin iterator.

Definition at line 73 of file flat_map.hpp.

Here is the call graph for this function:

◆ cend()

template<class Key , class Value , template< class... >class Storage = std::vector>
const_iterator flat_map< Key, Value, Storage >::cend ( ) const
inline

Return const iterator past the last element.

Returns
Const end iterator.

Definition at line 88 of file flat_map.hpp.

Here is the call graph for this function:

◆ empty()

template<class Key , class Value , template< class... >class Storage = std::vector>
bool flat_map< Key, Value, Storage >::empty ( ) const
inline

Return true if the map contains no elements.

Returns
true if empty.

Definition at line 97 of file flat_map.hpp.

◆ end() [1/2]

template<class Key , class Value , template< class... >class Storage = std::vector>
iterator flat_map< Key, Value, Storage >::end ( )
inline

Return iterator past the last element.

Returns
Mutable end iterator.

Definition at line 78 of file flat_map.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end() [2/2]

template<class Key , class Value , template< class... >class Storage = std::vector>
const_iterator flat_map< Key, Value, Storage >::end ( ) const
inline

Return const iterator past the last element.

Returns
Const end iterator.

Definition at line 83 of file flat_map.hpp.

Here is the call graph for this function:

◆ erase()

template<class Key , class Value , template< class... >class Storage = std::vector>
iterator flat_map< Key, Value, Storage >::erase ( const_iterator  it)
inline

Remove the element at it.

Parameters
itIterator to the element to remove.
Returns
Iterator to the element following the removed one.

Definition at line 154 of file flat_map.hpp.

◆ find() [1/2]

template<class Key , class Value , template< class... >class Storage = std::vector>
template<class K , class = std::enable_if_t<std::is_convertible<K, Key>{}>>
iterator flat_map< Key, Value, Storage >::find ( K &&  k)
inline

Find the element with key k.

Parameters
kKey to search for.
Returns
Iterator to the element, or end() if not found.

Definition at line 137 of file flat_map.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [2/2]

template<class Key , class Value , template< class... >class Storage = std::vector>
template<class K , class = std::enable_if_t<std::is_convertible<K, Key>{}>>
const_iterator flat_map< Key, Value, Storage >::find ( K &&  k) const
inline

Find the element with key k (const overload).

Parameters
kKey to search for.
Returns
Const iterator to the element, or end() if not found.

Definition at line 146 of file flat_map.hpp.

Here is the call graph for this function:

◆ insert()

template<class Key , class Value , template< class... >class Storage = std::vector>
template<class P , class = std::enable_if_t<std::is_convertible<P,std::pair<Key, Value>>{}>>
void flat_map< Key, Value, Storage >::insert ( P &&  value)
inline

Insert or update a key-value pair.

Parameters
valueKey-value pair to insert or update.

Definition at line 162 of file flat_map.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ key_match()

template<class Key , class Value , template< class... >class Storage = std::vector>
template<class K , class = std::enable_if_t<std::is_convertible<K, Key>{}>>
auto flat_map< Key, Value, Storage >::key_match ( K &  k)
inlineprivate

Return a predicate matching key k.

Parameters
kKey to match against.
Returns
Lambda matching pairs whose first element equals k.

Definition at line 125 of file flat_map.hpp.

Here is the caller graph for this function:

◆ operator<()

template<class Key , class Value , template< class... >class Storage = std::vector>
bool flat_map< Key, Value, Storage >::operator< ( const flat_map< Key, Value, Storage > &  rhs) const
inline

Lexicographic less-than comparison (order-independent on keys).

Parameters
rhsRight-hand side map.
Returns
true if this map is less than rhs.

Definition at line 196 of file flat_map.hpp.

Here is the call graph for this function:

◆ operator==()

template<class Key , class Value , template< class... >class Storage = std::vector>
bool flat_map< Key, Value, Storage >::operator== ( const flat_map< Key, Value, Storage > &  rhs) const
inline

Compare two flat_maps for equality.

Parameters
rhsRight-hand side map.
Returns
true if both maps contain the same key-value pairs.

Definition at line 176 of file flat_map.hpp.

Here is the call graph for this function:

◆ operator[]()

template<class Key , class Value , template< class... >class Storage = std::vector>
template<class K , class = std::enable_if_t<std::is_convertible<K, Key>{}>>
Value & flat_map< Key, Value, Storage >::operator[] ( K &&  k)
inline

Access or insert the value for key k.

Parameters
kKey to look up or insert.
Returns
Reference to the associated value.

Definition at line 116 of file flat_map.hpp.

Here is the call graph for this function:

◆ reserve()

template<class Key , class Value , template< class... >class Storage = std::vector>
void flat_map< Key, Value, Storage >::reserve ( size_t  n)
inline

Reserve storage for at least n elements.

Parameters
nMinimum capacity.

Definition at line 102 of file flat_map.hpp.

◆ size()

template<class Key , class Value , template< class... >class Storage = std::vector>
size_t flat_map< Key, Value, Storage >::size ( ) const
inline

Return the number of key-value pairs.

Returns
Number of elements.

Definition at line 93 of file flat_map.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ storage

template<class Key , class Value , template< class... >class Storage = std::vector>
storage_t flat_map< Key, Value, Storage >::storage

Contiguous key-value storage.

Definition at line 51 of file flat_map.hpp.


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