Loading...
Searching...
No Matches
meshkit::plan::Map< K, V > Class Template Reference

Hash map with the QHash-style API the CDT kernel uses, over std::unordered_map<K, V, Hash<K>>. More...

#include <meshkit/detail/storage.hpp>

Collaboration diagram for meshkit::plan::Map< K, V >:

Classes

class  Iterator
 Forward iterator over a Map whose dereference yields the mapped value. More...
 

Public Types

using ConstIterator = Iterator<true>
 Read-only iterator; value() is const V &.
 
using MutableIterator = Iterator<false>
 Iterator whose value() is a modifiable V &.
 

Public Member Functions

void clear ()
 Remove all entries.
 
void reserve (std::size_t n)
 Prepare buckets for at least n entries (std::unordered_map::reserve).
 
bool isEmpty () const
 True when the map has no entries.
 
std::ptrdiff_t size () const
 Number of entries, as a signed count.
 
bool contains (const K &k) const
 Key lookup.
 
MutableIterator insert (const K &k, const V &v)
 Store v under k, overwriting any existing value (insert_or_assign).
 
bool remove (const K &k)
 Erase the entry for k.
 
V & operator[] (const K &k)
 Modifiable value for k, inserting a value-initialized V{} first when absent.
 
V value (const K &k, const V &fallback=V{}) const
 Copy of the value for k, without inserting.
 
MutableIterator find (const K &k)
 Mutable iterator to the entry for k.
 
MutableIterator begin ()
 Mutable iterator to the first entry (order unspecified).
 
ConstIterator begin () const
 Read-only iterator to the first entry; same as cbegin().
 
MutableIterator end ()
 Mutable past-the-end iterator.
 
ConstIterator end () const
 Read-only past-the-end iterator; same as cend().
 
ConstIterator constFind (const K &k) const
 Read-only iterator to the entry for k.
 
ConstIterator constEnd () const
 Read-only past-the-end iterator, to compare with constFind() results.
 
ConstIterator cbegin () const
 Read-only iterator to the first entry (order unspecified).
 
ConstIterator cend () const
 Read-only past-the-end iterator.
 

Detailed Description

template<class K, class V>
class meshkit::plan::Map< K, V >

Hash map with the QHash-style API the CDT kernel uses, over std::unordered_map<K, V, Hash<K>>.

Unlike std::unordered_map, its iterators dereference to the mapped value, not to a key/value pair (Iterator::key() gives the key), so a range-for visits values. Iteration order is unspecified. Invalidation follows std::unordered_map: an insertion may rehash and invalidate iterators but not references to values, and remove() invalidates only the removed entry. No internal synchronization.

Template Parameters
KKey type, hashed by Hash<K> and compared with operator==.
VMapped type.

Member Typedef Documentation

◆ ConstIterator

template<class K, class V>
using meshkit::detail::Map< K, V >::ConstIterator = Iterator<true>

Read-only iterator; value() is const V &.

◆ MutableIterator

template<class K, class V>
using meshkit::detail::Map< K, V >::MutableIterator = Iterator<false>

Iterator whose value() is a modifiable V &.

Member Function Documentation

◆ begin() [1/2]

template<class K, class V>
MutableIterator meshkit::detail::Map< K, V >::begin ( )
inline

Mutable iterator to the first entry (order unspecified).

◆ begin() [2/2]

template<class K, class V>
ConstIterator meshkit::detail::Map< K, V >::begin ( ) const
inline

Read-only iterator to the first entry; same as cbegin().

◆ cbegin()

template<class K, class V>
ConstIterator meshkit::detail::Map< K, V >::cbegin ( ) const
inline

Read-only iterator to the first entry (order unspecified).

◆ cend()

template<class K, class V>
ConstIterator meshkit::detail::Map< K, V >::cend ( ) const
inline

Read-only past-the-end iterator.

◆ clear()

template<class K, class V>
void meshkit::detail::Map< K, V >::clear ( )
inline

Remove all entries.

◆ constEnd()

template<class K, class V>
ConstIterator meshkit::detail::Map< K, V >::constEnd ( ) const
inline

Read-only past-the-end iterator, to compare with constFind() results.

◆ constFind()

template<class K, class V>
ConstIterator meshkit::detail::Map< K, V >::constFind ( const K & k) const
inline

Read-only iterator to the entry for k.

Parameters
[in]kKey.
Returns
Iterator to the entry, or constEnd() when k is absent.

◆ contains()

template<class K, class V>
bool meshkit::detail::Map< K, V >::contains ( const K & k) const
inline

Key lookup.

Parameters
[in]kKey to look for.
Returns
True when k has an entry.

◆ end() [1/2]

template<class K, class V>
MutableIterator meshkit::detail::Map< K, V >::end ( )
inline

Mutable past-the-end iterator.

◆ end() [2/2]

template<class K, class V>
ConstIterator meshkit::detail::Map< K, V >::end ( ) const
inline

Read-only past-the-end iterator; same as cend().

◆ find()

template<class K, class V>
MutableIterator meshkit::detail::Map< K, V >::find ( const K & k)
inline

Mutable iterator to the entry for k.

Parameters
[in]kKey.
Returns
Iterator to the entry, or end() when k is absent.

◆ insert()

template<class K, class V>
MutableIterator meshkit::detail::Map< K, V >::insert ( const K & k,
const V & v )
inline

Store v under k, overwriting any existing value (insert_or_assign).

Parameters
[in]kKey.
[in]vValue to copy.
Returns
Iterator to the entry.

◆ isEmpty()

template<class K, class V>
bool meshkit::detail::Map< K, V >::isEmpty ( ) const
inline

True when the map has no entries.

◆ operator[]()

template<class K, class V>
V & meshkit::detail::Map< K, V >::operator[] ( const K & k)
inline

Modifiable value for k, inserting a value-initialized V{} first when absent.

Parameters
[in]kKey.
Returns
Reference that stays valid until the entry is removed or the map is cleared or destroyed; rehashing does not move it.

◆ remove()

template<class K, class V>
bool meshkit::detail::Map< K, V >::remove ( const K & k)
inline

Erase the entry for k.

Parameters
[in]kKey.
Returns
True when an entry was removed, false when k was absent.

◆ reserve()

template<class K, class V>
void meshkit::detail::Map< K, V >::reserve ( std::size_t n)
inline

Prepare buckets for at least n entries (std::unordered_map::reserve).

Parameters
[in]nExpected number of entries.

◆ size()

template<class K, class V>
std::ptrdiff_t meshkit::detail::Map< K, V >::size ( ) const
inline

Number of entries, as a signed count.

◆ value()

template<class K, class V>
V meshkit::detail::Map< K, V >::value ( const K & k,
const V & fallback = V{} ) const
inline

Copy of the value for k, without inserting.

Parameters
[in]kKey.
[in]fallbackReturned when k is absent; defaults to V{}.
Returns
The stored value, or fallback.

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