ImFusion SDK 4.3
OrderedMap< KeyType, ValueType > Class Template Reference

#include <ImFusion/ML/OrderedMap.h>

Class for an insertion ordered map in order to mimic a python dictionary in C++ This is a convenience class which provides a similar interface to std::map and std::unordered_map It should be only used if there are not many elements to store or performance is not critical Due to its simple implementation it performs lookup only in O(N) More...

Detailed Description

template<typename KeyType, typename ValueType>
class ImFusion::ML::OrderedMap< KeyType, ValueType >

Class for an insertion ordered map in order to mimic a python dictionary in C++ This is a convenience class which provides a similar interface to std::map and std::unordered_map It should be only used if there are not many elements to store or performance is not critical Due to its simple implementation it performs lookup only in O(N)

Public Types

using KVPType = std::pair<KeyType, ValueType>
 
using iterator = typename std::vector<KVPType>::iterator
 
using const_iterator = typename std::vector<KVPType>::const_iterator
 

Public Member Functions

 OrderedMap (std::initializer_list< KVPType > list)
 
const_iterator begin () const
 const_iterator to the beginning of the map
 
const_iterator end () const
 const_iterator to the end of the map
 
iterator begin ()
 iterator to the beginning of the map
 
iterator end ()
 iterator to the end of the map
 
const_iterator cbegin () const
 const_iterator to the beginning of the map
 
const_iterator cend () const
 const_iterator to the end of the map
 
void insert (const std::pair< KeyType, ValueType > &element)
 Insert key-value pair to map only if key does not exist, otherwise overwrite existing value with new one.
 
void insert (std::pair< KeyType, ValueType > &&element)
 Move insert key-value pair to map only if key does not exist, otherwise overwrite existing value with new one.
 
std::vector< std::pair< KeyType, ValueType > >::size_type erase (const KeyType &key)
 Erase element if key was found.
 
iterator erase (iterator element)
 Erase element by iterator.
 
size_t size () const
 Number of elements in map.
 
const_iterator find (const KeyType &key) const
 Find element by key.
 
iterator find (const KeyType &key)
 Find element by key.
 
const ValueType & at (const KeyType &key) const
 Getter for value with specific key that throws if key is not found.
 
ValueType & at (const KeyType &key)
 Getter for value reference with specific key that throws if key is not found.
 
bool empty () const
 Check if map is empty.
 
void clear ()
 Deletes all elements from the map.
 
std::vector< std::pair< KeyType, ValueType > >::size_type count (KeyType key) const
 Count the number of elements with a specific key.
 
ValueType & operator[] (const KeyType &key)
 Access element by key.
 
bool operator== (const OrderedMap< KeyType, ValueType > &other)
 Operator to compare equality with other OrderedMap.
 

Member Function Documentation

◆ erase()

template<typename KeyType, typename ValueType>
std::vector< std::pair< KeyType, ValueType > >::size_type erase ( const KeyType & key)
inline

Erase element if key was found.

Returns
Number of removed elements

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close