libuav original

Dependents:   UAVCAN UAVCAN_Subscriber

Embed: (wiki syntax)

« Back to documentation index

Map< Key, Value > Class Template Reference

Map< Key, Value > Class Template Reference

Slow but memory efficient KV container. More...

#include <map.hpp>

Inherits uavcan::Noncopyable.

Public Member Functions

Value * access (const Key &key)
 Returns null pointer if there's no such entry.
Value * insert (const Key &key, const Value &value)
 If entry with the same key already exists, it will be replaced.
void remove (const Key &key)
 Does nothing if there's no such entry.
template<typename Predicate >
void removeAllWhere (Predicate predicate)
 Removes entries where the predicate returns true.
template<typename Predicate >
const Key * find (Predicate predicate) const
 Returns first entry where the predicate returns true.
void clear ()
 Removes all items.
KVPair * getByIndex (unsigned index)
 Returns a key-value pair located at the specified position from the beginning.
bool isEmpty () const
 Complexity is O(1).
unsigned getSize () const
 Complexity is O(N).

Detailed Description

template<typename Key, typename Value>
class uavcan::Map< Key, Value >

Slow but memory efficient KV container.

KV pairs will be allocated in the node's memory pool.

Please be aware that this container does not perform any speed optimizations to minimize memory footprint, so the complexity of most operations is O(N).

Type requirements: Both key and value must be copyable, assignable and default constructible. Key must implement a comparison operator. Key's default constructor must initialize the object into invalid state. Size of Key + Value + padding must not exceed MemPoolBlockSize.

Definition at line 33 of file map.hpp.


Member Function Documentation

Value * access ( const Key &  key )

Returns null pointer if there's no such entry.

Definition at line 225 of file map.hpp.

void clear (  )

Removes all items.

Definition at line 327 of file map.hpp.

const Key * find ( Predicate  predicate ) const

Returns first entry where the predicate returns true.

Predicate prototype: bool (const Key& key, const Value& value)

Definition at line 302 of file map.hpp.

Map< Key, Value >::KVPair * getByIndex ( unsigned  index )

Returns a key-value pair located at the specified position from the beginning.

Note that any insertion or deletion may greatly disturb internal ordering, so use with care. If index is greater than or equal the number of pairs, null pointer will be returned.

Definition at line 333 of file map.hpp.

unsigned getSize (  ) const

Complexity is O(N).

Definition at line 367 of file map.hpp.

Value * insert ( const Key &  key,
const Value &  value 
)

If entry with the same key already exists, it will be replaced.

Definition at line 233 of file map.hpp.

bool isEmpty (  ) const

Complexity is O(1).

Definition at line 170 of file map.hpp.

void remove ( const Key &  key )

Does nothing if there's no such entry.

Definition at line 256 of file map.hpp.

void removeAllWhere ( Predicate  predicate )

Removes entries where the predicate returns true.

Predicate prototype: bool (Key& key, Value& value)

Definition at line 269 of file map.hpp.