Public Member Functions | Private Attributes | List of all members
lvr2::VectorMap< HandleT, ValueT > Class Template Reference

A map with constant lookup overhead using small-ish integer-keys. More...

#include <VectorMap.hpp>

Inheritance diagram for lvr2::VectorMap< HandleT, ValueT >:
Inheritance graph
[legend]

Public Member Functions

AttributeMapHandleIteratorPtr< HandleT > begin () const final
 Returns an iterator over all keys of this map. The order of iteration is unspecified. More...
 
void clear () final
 Removes all values from the map. More...
 
bool containsKey (HandleT key) const final
 Returns true iff the map contains a value associated with the given key. More...
 
AttributeMapHandleIteratorPtr< HandleT > end () const final
 Returns an iterator to the end of all keys. More...
 
boost::optional< ValueT > erase (HandleT key) final
 Removes the value associated with the given key. More...
 
boost::optional< const ValueT & > get (HandleT key) const final
 Returns the value associated with the given key or None if there is no associated value. More...
 
boost::optional< ValueT & > get (HandleT key) final
 Returns the value associated with the given key or None if there is no associated value. More...
 
boost::optional< ValueT > insert (HandleT key, const ValueT &value) final
 Inserts the given value at the given key position. More...
 
size_t numValues () const final
 Returns the number of values in this map. More...
 
void reserve (size_t newCap)
 
 VectorMap ()
 Creates an empty map without default element set. More...
 
 VectorMap (const ValueT &defaultValue)
 Creates a map with a given default value. More...
 
 VectorMap (size_t countElements, const boost::shared_array< ValueT > &values)
 
 VectorMap (size_t countElements, const ValueT &defaultValue)
 Creates a map with a given default value and calls reserve. More...
 
- Public Member Functions inherited from lvr2::AttributeMap< HandleT, ValueT >
ValueT & operator[] (HandleT key)
 Returns the value associated with the given key or panics if there is no associated value. More...
 
const ValueT & operator[] (HandleT key) const
 Returns the value associated with the given key or panics if there is no associated value. More...
 

Private Attributes

boost::optional< ValueT > m_default
 
StableVector< HandleT, ValueT > m_vec
 The underlying storage. More...
 

Additional Inherited Members

- Public Types inherited from lvr2::AttributeMap< HandleT, ValueT >
typedef HandleT HandleType
 The type of the handle used as key in this map. More...
 
typedef ValueT ValueType
 The type of the value stored in this map. More...
 

Detailed Description

template<typename HandleT, typename ValueT>
class lvr2::VectorMap< HandleT, ValueT >

A map with constant lookup overhead using small-ish integer-keys.

It stores the given values in a vector, they key is simply the index within the vector. This means that the space requirement is O(largest_key). See StableVector for more information.

Definition at line 60 of file VectorMap.hpp.

Constructor & Destructor Documentation

◆ VectorMap() [1/4]

template<typename HandleT , typename ValueT >
lvr2::VectorMap< HandleT, ValueT >::VectorMap ( )
inline

Creates an empty map without default element set.

Definition at line 66 of file VectorMap.hpp.

◆ VectorMap() [2/4]

template<typename HandleT , typename ValueT >
lvr2::VectorMap< HandleT, ValueT >::VectorMap ( const ValueT &  defaultValue)

Creates a map with a given default value.

Whenever you request a value for a key and there isn't a value associated with that key, the default value is returned. Note that if you set a default value (which you do by calling this constructor), you can't remove it. Neither erase() nor clear() will do it. Calls to get() will always return a non-none value and operator[] won't ever panic.

One additional important detail: if you call get() to obtain a mutable reference, the default value is inserted into the map. This is the only sane way to return a mutably reference.

◆ VectorMap() [3/4]

template<typename HandleT , typename ValueT >
lvr2::VectorMap< HandleT, ValueT >::VectorMap ( size_t  countElements,
const ValueT &  defaultValue 
)

Creates a map with a given default value and calls reserve.

This works exactly as the VectorMap(const Value&) constructor, but also calls reserve(countElements) immediately afterwards.

◆ VectorMap() [4/4]

template<typename HandleT , typename ValueT >
lvr2::VectorMap< HandleT, ValueT >::VectorMap ( size_t  countElements,
const boost::shared_array< ValueT > &  values 
)

Member Function Documentation

◆ begin()

template<typename HandleT , typename ValueT >
AttributeMapHandleIteratorPtr<HandleT> lvr2::VectorMap< HandleT, ValueT >::begin ( ) const
finalvirtual

Returns an iterator over all keys of this map. The order of iteration is unspecified.

You can simply iterate over all keys of this map with a range-based for-loop:

for (auto handle: attributeMap) { ... }

Implements lvr2::AttributeMap< HandleT, ValueT >.

◆ clear()

template<typename HandleT , typename ValueT >
void lvr2::VectorMap< HandleT, ValueT >::clear ( )
finalvirtual

Removes all values from the map.

Implements lvr2::AttributeMap< HandleT, ValueT >.

◆ containsKey()

template<typename HandleT , typename ValueT >
bool lvr2::VectorMap< HandleT, ValueT >::containsKey ( HandleT  key) const
finalvirtual

Returns true iff the map contains a value associated with the given key.

Implements lvr2::AttributeMap< HandleT, ValueT >.

◆ end()

template<typename HandleT , typename ValueT >
AttributeMapHandleIteratorPtr<HandleT> lvr2::VectorMap< HandleT, ValueT >::end ( ) const
finalvirtual

Returns an iterator to the end of all keys.

Implements lvr2::AttributeMap< HandleT, ValueT >.

◆ erase()

template<typename HandleT , typename ValueT >
boost::optional<ValueT> lvr2::VectorMap< HandleT, ValueT >::erase ( HandleT  key)
finalvirtual

Removes the value associated with the given key.

Returns
If there was a value associated with the key, it is returned. None otherwise.

Implements lvr2::AttributeMap< HandleT, ValueT >.

◆ get() [1/2]

template<typename HandleT , typename ValueT >
boost::optional<const ValueT&> lvr2::VectorMap< HandleT, ValueT >::get ( HandleT  key) const
finalvirtual

Returns the value associated with the given key or None if there is no associated value.

Note: this method can not be used to insert a new value. It only allows reading an already inserted value.

Implements lvr2::AttributeMap< HandleT, ValueT >.

◆ get() [2/2]

template<typename HandleT , typename ValueT >
boost::optional<ValueT&> lvr2::VectorMap< HandleT, ValueT >::get ( HandleT  key)
finalvirtual

Returns the value associated with the given key or None if there is no associated value.

Note: this method can not be used to insert a new value. It only allows reading and modifying an already inserted value.

Implements lvr2::AttributeMap< HandleT, ValueT >.

◆ insert()

template<typename HandleT , typename ValueT >
boost::optional<ValueT> lvr2::VectorMap< HandleT, ValueT >::insert ( HandleT  key,
const ValueT &  value 
)
finalvirtual

Inserts the given value at the given key position.

Returns
If there was a value associated with the given key before inserting the new value, the old value is returned. None otherwise.

Implements lvr2::AttributeMap< HandleT, ValueT >.

◆ numValues()

template<typename HandleT , typename ValueT >
size_t lvr2::VectorMap< HandleT, ValueT >::numValues ( ) const
finalvirtual

Returns the number of values in this map.

Implements lvr2::AttributeMap< HandleT, ValueT >.

◆ reserve()

template<typename HandleT , typename ValueT >
void lvr2::VectorMap< HandleT, ValueT >::reserve ( size_t  newCap)

Member Data Documentation

◆ m_default

template<typename HandleT , typename ValueT >
boost::optional<ValueT> lvr2::VectorMap< HandleT, ValueT >::m_default
private

Definition at line 117 of file VectorMap.hpp.

◆ m_vec

template<typename HandleT , typename ValueT >
StableVector<HandleT, ValueT> lvr2::VectorMap< HandleT, ValueT >::m_vec
private

The underlying storage.

Definition at line 116 of file VectorMap.hpp.


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


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:28