0.3.0
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

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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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().

◆ 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().

◆ 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().

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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

◆ 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

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