0.4.1
Loading...
Searching...
No Matches
NAV::KeyedMap< KeyType, Scalar, unordered > Class Template Reference

Similar to KeyedMatrix, but memory is allocated in a map and therefore never reallocated. More...

Public Member Functions

void addKey (const KeyType &key)
 Adds a single element for the key to the data storage.
 
void addKey (const KeyType &key, const Scalar &value)
 Adds a single element for the key to the data storage.
 
void addKeys (std::span< const KeyType > keys)
 Adds a continuous vector for the keys to the data storage.
 
void addKeys (std::span< const KeyType > keys, std::span< const Scalar > values)
 Adds a continuous vector for the keys to the data storage.
 
void addKeys (std::span< const std::pair< KeyType, Scalar > > keyValues)
 Adds a continuous vector for the keys to the data storage.
 
Scalar & at (const KeyType &key)
 Returns a reference to the mapped value of the element with specified key. If no such element exists, an exception of type std::out_of_range is thrown.
 
const Scalar & at (const KeyType &key) const
 Returns a reference to the mapped value of the element with specified key. If no such element exists, an exception of type std::out_of_range is thrown.
 
std::vector< Scalar > & at (std::span< const KeyType > keys)
 Returns a reference to the mapped value of the element with specified keys. If no such element exists, an exception of type std::out_of_range is thrown.
 
const std::vector< Scalar > & at (std::span< const KeyType > keys) const
 Returns a reference to the mapped value of the element with specified keys. If no such element exists, an exception of type std::out_of_range is thrown.
 
decltype(auto) begin ()
 Returns an iterator to the first element.
 
decltype(auto) begin () const noexcept
 Returns an iterator to the first element.
 
decltype(auto) cbegin () const noexcept
 Returns an iterator to the first element.
 
decltype(auto) cend () const noexcept
 Returns an iterator to the element following the last element of.
 
void clear ()
 Erases all elements from the container. After this call, size() returns zero.
 
bool contains (const KeyType &key) const
 Checks if there is an element with key equivalent to key in the container.
 
bool contains (std::span< const KeyType > keys) const
 Checks if there are elements with keys equivalent to keys in the container.
 
bool empty () const
 Checks if the container has no elements.
 
decltype(auto) end ()
 Returns an iterator to the element following the last element of.
 
decltype(auto) end () const noexcept
 Returns an iterator to the element following the last element of.
 
std::vector< KeyType > keys () const
 Collect all keys.
 
size_t size () const
 Returns the number of elements in the container.
 
size_t size_of (const KeyType &key) const
 Returns the size of parameters represented by the key.
 

Private Attributes

std::conditional_t< unordered, unordered_map< KeyType, std::vector< Scalar > >, std::map< KeyType, std::vector< Scalar > > > _data
 Storage container.
 
unordered_map< KeyType, Scalar * > _lookup
 Lookup for individual keys.
 

Detailed Description

template<typename KeyType, typename Scalar, bool unordered = true>
class NAV::KeyedMap< KeyType, Scalar, unordered >

Similar to KeyedMatrix, but memory is allocated in a map and therefore never reallocated.

Template Parameters
KeyTypeType to use as keys
ScalarType to store in the map
unorderedWether an unordered_map or a std::map should be used

Definition at line 34 of file KeyedMap.hpp.

Member Function Documentation

◆ addKey() [1/2]

template<typename KeyType, typename Scalar, bool unordered = true>
void NAV::KeyedMap< KeyType, Scalar, unordered >::addKey ( const KeyType & key)
inline

Adds a single element for the key to the data storage.

Parameters
[in]keyKey to add

Definition at line 100 of file KeyedMap.hpp.

◆ addKey() [2/2]

template<typename KeyType, typename Scalar, bool unordered = true>
void NAV::KeyedMap< KeyType, Scalar, unordered >::addKey ( const KeyType & key,
const Scalar & value )
inline

Adds a single element for the key to the data storage.

Parameters
[in]keyKey to add
[in]valueValue for the key

Definition at line 105 of file KeyedMap.hpp.

◆ addKeys() [1/3]

template<typename KeyType, typename Scalar, bool unordered = true>
void NAV::KeyedMap< KeyType, Scalar, unordered >::addKeys ( std::span< const KeyType > keys)
inline

Adds a continuous vector for the keys to the data storage.

Parameters
[in]keysKeys to add

Definition at line 109 of file KeyedMap.hpp.

◆ addKeys() [2/3]

template<typename KeyType, typename Scalar, bool unordered = true>
void NAV::KeyedMap< KeyType, Scalar, unordered >::addKeys ( std::span< const KeyType > keys,
std::span< const Scalar > values )
inline

Adds a continuous vector for the keys to the data storage.

Parameters
[in]keysKeys to add
[in]valuesValues for the keys

Definition at line 123 of file KeyedMap.hpp.

◆ addKeys() [3/3]

template<typename KeyType, typename Scalar, bool unordered = true>
void NAV::KeyedMap< KeyType, Scalar, unordered >::addKeys ( std::span< const std::pair< KeyType, Scalar > > keyValues)
inline

Adds a continuous vector for the keys to the data storage.

Parameters
[in]keyValuesKeys and values to add

Definition at line 138 of file KeyedMap.hpp.

◆ at() [1/4]

template<typename KeyType, typename Scalar, bool unordered = true>
Scalar & NAV::KeyedMap< KeyType, Scalar, unordered >::at ( const KeyType & key)
inline

Returns a reference to the mapped value of the element with specified key. If no such element exists, an exception of type std::out_of_range is thrown.

Parameters
[in]keythe key of the element to find
Returns
A reference to the mapped value of the requested element.

Definition at line 163 of file KeyedMap.hpp.

◆ at() [2/4]

template<typename KeyType, typename Scalar, bool unordered = true>
const Scalar & NAV::KeyedMap< KeyType, Scalar, unordered >::at ( const KeyType & key) const
inlinenodiscard

Returns a reference to the mapped value of the element with specified key. If no such element exists, an exception of type std::out_of_range is thrown.

Parameters
[in]keythe key of the element to find
Returns
A reference to the mapped value of the requested element.

Definition at line 172 of file KeyedMap.hpp.

◆ at() [3/4]

template<typename KeyType, typename Scalar, bool unordered = true>
std::vector< Scalar > & NAV::KeyedMap< KeyType, Scalar, unordered >::at ( std::span< const KeyType > keys)
inline

Returns a reference to the mapped value of the element with specified keys. If no such element exists, an exception of type std::out_of_range is thrown.

Parameters
[in]keysthe keys of the element to find
Returns
A reference to the mapped value of the requested element.

Definition at line 181 of file KeyedMap.hpp.

◆ at() [4/4]

template<typename KeyType, typename Scalar, bool unordered = true>
const std::vector< Scalar > & NAV::KeyedMap< KeyType, Scalar, unordered >::at ( std::span< const KeyType > keys) const
inlinenodiscard

Returns a reference to the mapped value of the element with specified keys. If no such element exists, an exception of type std::out_of_range is thrown.

Parameters
[in]keysthe key of the element to find
Returns
A reference to the mapped value of the requested element.

Definition at line 193 of file KeyedMap.hpp.

◆ begin() [1/2]

template<typename KeyType, typename Scalar, bool unordered = true>
decltype(auto) NAV::KeyedMap< KeyType, Scalar, unordered >::begin ( )
inline

Returns an iterator to the first element.

If the buffer is empty, the returned iterator will be equal to end().

Definition at line 48 of file KeyedMap.hpp.

◆ begin() [2/2]

template<typename KeyType, typename Scalar, bool unordered = true>
decltype(auto) NAV::KeyedMap< KeyType, Scalar, unordered >::begin ( ) const
inlinenodiscardnoexcept

Returns an iterator to the first element.

If the buffer is empty, the returned iterator will be equal to end().

Definition at line 52 of file KeyedMap.hpp.

◆ cbegin()

template<typename KeyType, typename Scalar, bool unordered = true>
decltype(auto) NAV::KeyedMap< KeyType, Scalar, unordered >::cbegin ( ) const
inlinenodiscardnoexcept

Returns an iterator to the first element.

If the buffer is empty, the returned iterator will be equal to end().

Definition at line 56 of file KeyedMap.hpp.

◆ cend()

template<typename KeyType, typename Scalar, bool unordered = true>
decltype(auto) NAV::KeyedMap< KeyType, Scalar, unordered >::cend ( ) const
inlinenodiscardnoexcept

Returns an iterator to the element following the last element of.

This element acts as a placeholder; attempting to access it results in undefined behavior.

Definition at line 69 of file KeyedMap.hpp.

◆ clear()

template<typename KeyType, typename Scalar, bool unordered = true>
void NAV::KeyedMap< KeyType, Scalar, unordered >::clear ( )
inline

Erases all elements from the container. After this call, size() returns zero.

Definition at line 92 of file KeyedMap.hpp.

◆ contains() [1/2]

template<typename KeyType, typename Scalar, bool unordered = true>
bool NAV::KeyedMap< KeyType, Scalar, unordered >::contains ( const KeyType & key) const
inlinenodiscard

Checks if there is an element with key equivalent to key in the container.

Parameters
[in]keykey value of the element to search for
Returns
true if there is such an element, otherwise false.

Definition at line 204 of file KeyedMap.hpp.

◆ contains() [2/2]

template<typename KeyType, typename Scalar, bool unordered = true>
bool NAV::KeyedMap< KeyType, Scalar, unordered >::contains ( std::span< const KeyType > keys) const
inlinenodiscard

Checks if there are elements with keys equivalent to keys in the container.

Parameters
[in]keyskeys the elements to search for
Returns
true if there is such an element, otherwise false.

Definition at line 212 of file KeyedMap.hpp.

◆ empty()

template<typename KeyType, typename Scalar, bool unordered = true>
bool NAV::KeyedMap< KeyType, Scalar, unordered >::empty ( ) const
inlinenodiscard

Checks if the container has no elements.

Definition at line 76 of file KeyedMap.hpp.

◆ end() [1/2]

template<typename KeyType, typename Scalar, bool unordered = true>
decltype(auto) NAV::KeyedMap< KeyType, Scalar, unordered >::end ( )
inline

Returns an iterator to the element following the last element of.

This element acts as a placeholder; attempting to access it results in undefined behavior.

Definition at line 61 of file KeyedMap.hpp.

◆ end() [2/2]

template<typename KeyType, typename Scalar, bool unordered = true>
decltype(auto) NAV::KeyedMap< KeyType, Scalar, unordered >::end ( ) const
inlinenodiscardnoexcept

Returns an iterator to the element following the last element of.

This element acts as a placeholder; attempting to access it results in undefined behavior.

Definition at line 65 of file KeyedMap.hpp.

◆ keys()

template<typename KeyType, typename Scalar, bool unordered = true>
std::vector< KeyType > NAV::KeyedMap< KeyType, Scalar, unordered >::keys ( ) const
inlinenodiscard

Collect all keys.

Returns
The keys stored

Definition at line 232 of file KeyedMap.hpp.

◆ size()

template<typename KeyType, typename Scalar, bool unordered = true>
size_t NAV::KeyedMap< KeyType, Scalar, unordered >::size ( ) const
inlinenodiscard

Returns the number of elements in the container.

Definition at line 82 of file KeyedMap.hpp.

◆ size_of()

template<typename KeyType, typename Scalar, bool unordered = true>
size_t NAV::KeyedMap< KeyType, Scalar, unordered >::size_of ( const KeyType & key) const
inlinenodiscard

Returns the size of parameters represented by the key.

Parameters
[in]keykey value of the element to search for

Definition at line 221 of file KeyedMap.hpp.

Field Documentation

◆ _data

template<typename KeyType, typename Scalar, bool unordered = true>
std::conditional_t<unordered, unordered_map<KeyType, std::vector<Scalar> >, std::map<KeyType, std::vector<Scalar> > > NAV::KeyedMap< KeyType, Scalar, unordered >::_data
private

Storage container.

Definition at line 251 of file KeyedMap.hpp.

◆ _lookup

template<typename KeyType, typename Scalar, bool unordered = true>
unordered_map<KeyType, Scalar*> NAV::KeyedMap< KeyType, Scalar, unordered >::_lookup
private

Lookup for individual keys.

Definition at line 245 of file KeyedMap.hpp.


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