Loading...
Searching...
No Matches
TfDenseHashMap< Key, Data, HashFn, EqualKey, Threshold > Class Template Reference

This is a space efficient container that mimics the TfHashMap API that uses a vector for storage when the size of the map is small. More...

#include <denseHashMap.h>

Public Types

typedef std::pair< const Key, Data > value_type
 
typedef Key key_type
 
typedef Data mapped_type
 
typedef _IteratorBase< value_type, typename _Vector::iterator > iterator
 An iterator type for this map.
 
typedef _IteratorBase< const value_type, typename _Vector::const_iterator > const_iterator
 An iterator type for this map.
 
typedef std::pair< iterator, bool > insert_result
 Return type for insert() method.
 

Public Member Functions

 TfDenseHashMap (const HashFn &hashFn=HashFn(), const EqualKey &equalKey=EqualKey())
 Ctor.
 
template<class Iterator >
 TfDenseHashMap (Iterator begin, Iterator end)
 Construct with range.
 
 TfDenseHashMap (std::initializer_list< value_type > l)
 Construct from an initializer_list.
 
 TfDenseHashMap (const TfDenseHashMap &rhs)
 Copy Ctor.
 
 TfDenseHashMap (TfDenseHashMap &&rhs)=default
 Move Ctor.
 
TfDenseHashMapoperator= (const TfDenseHashMap &rhs)
 Copy assignment operator.
 
TfDenseHashMapoperator= (TfDenseHashMap &&rhs)=default
 Move assignment operator.
 
TfDenseHashMapoperator= (std::initializer_list< value_type > l)
 Assignment from an initializer_list.
 
bool operator== (const TfDenseHashMap &rhs) const
 Equality operator.
 
bool operator!= (const TfDenseHashMap &rhs) const
 
void clear ()
 Erases all of the elements.
 
void swap (TfDenseHashMap &rhs)
 Swaps the contents of two maps.
 
bool empty () const
 true if the map's size is 0.
 
size_t size () const
 Returns the size of the map.
 
iterator begin ()
 Returns an const_iterator pointing to the beginning of the map.
 
iterator end ()
 Returns an const_iterator pointing to the end of the map.
 
const_iterator begin () const
 Returns an const_iterator pointing to the beginning of the map.
 
const_iterator end () const
 Returns an const_iterator pointing to the end of the map.
 
iterator find (const key_type &k)
 Finds the element with key k.
 
const_iterator find (const key_type &k) const
 Finds the element with key k.
 
size_t count (const key_type &k) const
 Returns the number of elements with key k.
 
insert_result insert (const value_type &v)
 Returns a pair of <iterator, bool> where iterator points to the element in the list and bool is true if a new element was inserted.
 
template<class IteratorType >
void insert (IteratorType i0, IteratorType i1)
 Insert a range into the hash map.
 
template<class Iterator >
void insert_unique (Iterator begin, Iterator end)
 Insert a range of unique elements into the container.
 
Data & operator[] (const key_type &key)
 Indexing operator.
 
size_t erase (const key_type &k)
 Erase element with key k.
 
void erase (const iterator &iter)
 Erases element pointed to by iter.
 
void erase (iterator i0, iterator i1)
 Erases a range from the map.
 
void shrink_to_fit ()
 Optimize storage space.
 
void reserve (size_t n)
 Reserve space.
 

Detailed Description

template<class Key, class Data, class HashFn, class EqualKey = std::equal_to<Key>, unsigned Threshold = 128>
class TfDenseHashMap< Key, Data, HashFn, EqualKey, Threshold >

This is a space efficient container that mimics the TfHashMap API that uses a vector for storage when the size of the map is small.

When the map gets bigger than Threshold a TfHashMap is allocated that is used to accelerate lookup in the vector.

Warning
This differs from a TfHashMap in so far that inserting and removing elements invalidate all iterators of the container.

Definition at line 57 of file denseHashMap.h.

Member Typedef Documentation

◆ const_iterator

typedef _IteratorBase<const value_type, typename _Vector::const_iterator> const_iterator

An iterator type for this map.

Note that it provides access to the This::value_type only.

Definition at line 244 of file denseHashMap.h.

◆ insert_result

typedef std::pair<iterator, bool> insert_result

Return type for insert() method.

Definition at line 247 of file denseHashMap.h.

◆ iterator

typedef _IteratorBase<value_type, typename _Vector::iterator> iterator

An iterator type for this map.

Note that it provides access to the This::value_type only.

Definition at line 238 of file denseHashMap.h.

◆ key_type

typedef Key key_type

Definition at line 62 of file denseHashMap.h.

◆ mapped_type

typedef Data mapped_type

Definition at line 63 of file denseHashMap.h.

◆ value_type

typedef std::pair<const Key, Data> value_type

Definition at line 61 of file denseHashMap.h.

Constructor & Destructor Documentation

◆ TfDenseHashMap() [1/5]

TfDenseHashMap ( const HashFn &  hashFn = HashFn(),
const EqualKey &  equalKey = EqualKey() 
)
inlineexplicit

Ctor.

Definition at line 253 of file denseHashMap.h.

◆ TfDenseHashMap() [2/5]

TfDenseHashMap ( Iterator  begin,
Iterator  end 
)
inline

Construct with range.

Definition at line 264 of file denseHashMap.h.

◆ TfDenseHashMap() [3/5]

TfDenseHashMap ( std::initializer_list< value_type >  l)
inline

Construct from an initializer_list.

Definition at line 270 of file denseHashMap.h.

◆ TfDenseHashMap() [4/5]

TfDenseHashMap ( const TfDenseHashMap< Key, Data, HashFn, EqualKey, Threshold > &  rhs)
inline

Copy Ctor.

Definition at line 276 of file denseHashMap.h.

◆ TfDenseHashMap() [5/5]

TfDenseHashMap ( TfDenseHashMap< Key, Data, HashFn, EqualKey, Threshold > &&  rhs)
default

Move Ctor.

Member Function Documentation

◆ begin() [1/2]

iterator begin ( )
inline

Returns an const_iterator pointing to the beginning of the map.

Definition at line 361 of file denseHashMap.h.

◆ begin() [2/2]

const_iterator begin ( ) const
inline

Returns an const_iterator pointing to the beginning of the map.

Definition at line 373 of file denseHashMap.h.

◆ clear()

void clear ( )
inline

Erases all of the elements.

Definition at line 335 of file denseHashMap.h.

◆ count()

size_t count ( const key_type &  k) const
inline

Returns the number of elements with key k.

Which is either 0 or 1.

Definition at line 413 of file denseHashMap.h.

◆ empty()

bool empty ( ) const
inline

true if the map's size is 0.

Definition at line 349 of file denseHashMap.h.

◆ end() [1/2]

iterator end ( )
inline

Returns an const_iterator pointing to the end of the map.

Definition at line 367 of file denseHashMap.h.

◆ end() [2/2]

const_iterator end ( ) const
inline

Returns an const_iterator pointing to the end of the map.

Definition at line 379 of file denseHashMap.h.

◆ erase() [1/3]

void erase ( const iterator iter)
inline

Erases element pointed to by iter.

Definition at line 498 of file denseHashMap.h.

◆ erase() [2/3]

size_t erase ( const key_type &  k)
inline

Erase element with key k.

Returns the number of elements erased.

Definition at line 486 of file denseHashMap.h.

◆ erase() [3/3]

void erase ( iterator  i0,
iterator  i1 
)
inline

Erases a range from the map.

Definition at line 524 of file denseHashMap.h.

◆ find() [1/2]

iterator find ( const key_type &  k)
inline

Finds the element with key k.

Definition at line 385 of file denseHashMap.h.

◆ find() [2/2]

const_iterator find ( const key_type &  k) const
inline

Finds the element with key k.

Definition at line 399 of file denseHashMap.h.

◆ insert() [1/2]

insert_result insert ( const value_type &  v)
inline

Returns a pair of <iterator, bool> where iterator points to the element in the list and bool is true if a new element was inserted.

Definition at line 420 of file denseHashMap.h.

◆ insert() [2/2]

void insert ( IteratorType  i0,
IteratorType  i1 
)
inline

Insert a range into the hash map.

Note that i0 and i1 can't point into the hash map.

Definition at line 447 of file denseHashMap.h.

◆ insert_unique()

void insert_unique ( Iterator  begin,
Iterator  end 
)
inline

Insert a range of unique elements into the container.

[begin, end) must not contain any duplicate elements.

Definition at line 464 of file denseHashMap.h.

◆ operator!=()

bool operator!= ( const TfDenseHashMap< Key, Data, HashFn, EqualKey, Threshold > &  rhs) const
inline

Definition at line 329 of file denseHashMap.h.

◆ operator=() [1/3]

TfDenseHashMap & operator= ( const TfDenseHashMap< Key, Data, HashFn, EqualKey, Threshold > &  rhs)
inline

Copy assignment operator.

Definition at line 288 of file denseHashMap.h.

◆ operator=() [2/3]

TfDenseHashMap & operator= ( std::initializer_list< value_type >  l)
inline

Assignment from an initializer_list.

Definition at line 302 of file denseHashMap.h.

◆ operator=() [3/3]

TfDenseHashMap & operator= ( TfDenseHashMap< Key, Data, HashFn, EqualKey, Threshold > &&  rhs)
default

Move assignment operator.

◆ operator==()

bool operator== ( const TfDenseHashMap< Key, Data, HashFn, EqualKey, Threshold > &  rhs) const
inline

Equality operator.

Definition at line 310 of file denseHashMap.h.

◆ operator[]()

Data & operator[] ( const key_type &  key)
inline

Indexing operator.

Inserts a default constructed DataType() for key if there is no value for key already.

Returns a reference to the value type for key.

Definition at line 480 of file denseHashMap.h.

◆ reserve()

void reserve ( size_t  n)
inline

Reserve space.

Definition at line 568 of file denseHashMap.h.

◆ shrink_to_fit()

void shrink_to_fit ( )
inline

Optimize storage space.

Definition at line 542 of file denseHashMap.h.

◆ size()

size_t size ( ) const
inline

Returns the size of the map.

Definition at line 355 of file denseHashMap.h.

◆ swap()

void swap ( TfDenseHashMap< Key, Data, HashFn, EqualKey, Threshold > &  rhs)
inline

Swaps the contents of two maps.

Definition at line 342 of file denseHashMap.h.


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