Loading...
Searching...
No Matches
TfDenseHashSet< Element, HashFn, EqualElement, Threshold > Class Template Reference

A hash set with contiguous storage, suitable for use with TfSpan, e.g. More...

#include <denseHashSet.h>

Public Types

using value_type = Element
 
using pointer = value_type*
 
using const_pointer = const value_type*
 
typedef _Vector::const_iterator iterator
 An iterator type for this set.
 
typedef _Vector::const_iterator const_iterator
 A const_iterator type for this set.
 
typedef std::pair< const_iterator, bool > insert_result
 Return type for insert() method.
 

Public Member Functions

 TfDenseHashSet (const HashFn &hashFn=HashFn(), const EqualElement &equalElement=EqualElement())
 Ctor.
 
 TfDenseHashSet (const TfDenseHashSet &rhs)
 Copy Ctor.
 
 TfDenseHashSet (TfDenseHashSet &&rhs)=default
 Move Ctor.
 
template<class Iterator >
 TfDenseHashSet (Iterator begin, Iterator end)
 Construct from range.
 
 TfDenseHashSet (std::initializer_list< Element > l)
 Construct from an initializer_list.
 
TfDenseHashSetoperator= (const TfDenseHashSet &rhs)
 Copy assignment operator.
 
TfDenseHashSetoperator= (TfDenseHashSet &&rhs)=default
 Move assignment operator.
 
TfDenseHashSetoperator= (std::initializer_list< Element > l)
 Assignment from an initializer_list.
 
bool operator== (const TfDenseHashSet &rhs) const
 Equality operator.
 
bool operator!= (const TfDenseHashSet &rhs) const
 
void clear ()
 Erases all of the elements.
 
void swap (TfDenseHashSet &rhs)
 Swaps the contents of two sets.
 
bool empty () const
 true if the set's size is 0.
 
size_t size () const
 Returns the size of the set.
 
const_iterator begin () const
 Returns a const_iterator pointing to the beginning of the set.
 
const_iterator end () const
 Returns a const_iterator pointing to the end of the set.
 
const_iterator cbegin () const
 Returns a const_iterator pointing to the beginning of the set.
 
const_iterator cend () const
 Returns a const_iterator pointing to the end of the set.
 
pointer data ()
 Returns a pointer to the set's data.
 
const_pointer data () const
 Returns a const pointer to the set's data.
 
const_pointer cdata () const
 Returns a const pointer to the set's data.
 
const_iterator find (const Element &k) const
 Finds the element with key k.
 
size_t count (const Element &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 set.
 
template<class Iterator >
void insert_unique (Iterator begin, Iterator end)
 Insert a range of unique elements into the container.
 
size_t erase (const Element &k)
 Erase element with key k.
 
void erase (const iterator &iter)
 Erases element pointed to by iter.
 
void erase (const iterator &i0, const iterator &i1)
 Erases a range from the set.
 
void shrink_to_fit ()
 Optimize storage space.
 
const Element & operator[] (size_t index) const
 Index into set via index.
 

Detailed Description

template<class Element, class HashFn, class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
class TfDenseHashSet< Element, HashFn, EqualElement, Threshold >

A hash set with contiguous storage, suitable for use with TfSpan, e.g.

When the number of elements in the set is small, search operations are done by linear search. When the size surpassees Threshold, a hash table is allocated and used to accelerate lookup.

Note
Inserting and removing elements invalidates iterators.

Definition at line 39 of file denseHashSet.h.

Member Typedef Documentation

◆ const_iterator

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
_Vector::const_iterator const_iterator

A const_iterator type for this set.

Definition at line 67 of file denseHashSet.h.

◆ const_pointer

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
using const_pointer = const value_type*

Definition at line 45 of file denseHashSet.h.

◆ insert_result

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
std::pair<const_iterator, bool> insert_result

Return type for insert() method.

Definition at line 70 of file denseHashSet.h.

◆ iterator

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
_Vector::const_iterator iterator

An iterator type for this set.

Note that this one is const as well, as we can't allow in-place modification of elements due to the potentially allocated hash map.

Definition at line 64 of file denseHashSet.h.

◆ pointer

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
using pointer = value_type*

Definition at line 44 of file denseHashSet.h.

◆ value_type

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
using value_type = Element

Definition at line 43 of file denseHashSet.h.

Constructor & Destructor Documentation

◆ TfDenseHashSet() [1/5]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
TfDenseHashSet ( const HashFn & hashFn = HashFn(),
const EqualElement & equalElement = EqualElement() )
inlineexplicit

Ctor.

Definition at line 76 of file denseHashSet.h.

◆ TfDenseHashSet() [2/5]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
TfDenseHashSet ( const TfDenseHashSet< Element, HashFn, EqualElement, Threshold > & rhs)
inline

Copy Ctor.

Definition at line 86 of file denseHashSet.h.

◆ TfDenseHashSet() [3/5]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
TfDenseHashSet ( TfDenseHashSet< Element, HashFn, EqualElement, Threshold > && rhs)
default

Move Ctor.

◆ TfDenseHashSet() [4/5]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
template<class Iterator >
TfDenseHashSet ( Iterator begin,
Iterator end )
inline

Construct from range.

Definition at line 100 of file denseHashSet.h.

◆ TfDenseHashSet() [5/5]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
TfDenseHashSet ( std::initializer_list< Element > l)
inline

Construct from an initializer_list.

Definition at line 106 of file denseHashSet.h.

Member Function Documentation

◆ begin()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
const_iterator begin ( ) const
inline

Returns a const_iterator pointing to the beginning of the set.

Definition at line 182 of file denseHashSet.h.

◆ cbegin()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
const_iterator cbegin ( ) const
inline

Returns a const_iterator pointing to the beginning of the set.

Definition at line 194 of file denseHashSet.h.

◆ cdata()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
const_pointer cdata ( ) const
inline

Returns a const pointer to the set's data.

Definition at line 218 of file denseHashSet.h.

◆ cend()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
const_iterator cend ( ) const
inline

Returns a const_iterator pointing to the end of the set.

Definition at line 200 of file denseHashSet.h.

◆ clear()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
void clear ( )
inline

Erases all of the elements.

Definition at line 156 of file denseHashSet.h.

◆ count()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
size_t count ( const Element & k) const
inline

Returns the number of elements with key k.

Which is either 0 or 1.

Definition at line 245 of file denseHashSet.h.

◆ data() [1/2]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
pointer data ( )
inline

Returns a pointer to the set's data.

Definition at line 206 of file denseHashSet.h.

◆ data() [2/2]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
const_pointer data ( ) const
inline

Returns a const pointer to the set's data.

Definition at line 212 of file denseHashSet.h.

◆ empty()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
bool empty ( ) const
inline

true if the set's size is 0.

Definition at line 170 of file denseHashSet.h.

◆ end()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
const_iterator end ( ) const
inline

Returns a const_iterator pointing to the end of the set.

Definition at line 188 of file denseHashSet.h.

◆ erase() [1/3]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
size_t erase ( const Element & k)
inline

Erase element with key k.

Returns the number of elements erased.

Definition at line 314 of file denseHashSet.h.

◆ erase() [2/3]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
void erase ( const iterator & i0,
const iterator & i1 )
inline

Erases a range from the set.

Definition at line 351 of file denseHashSet.h.

◆ erase() [3/3]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
void erase ( const iterator & iter)
inline

Erases element pointed to by iter.

Definition at line 326 of file denseHashSet.h.

◆ find()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
const_iterator find ( const Element & k) const
inline

Finds the element with key k.

Definition at line 224 of file denseHashSet.h.

◆ insert() [1/2]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
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 252 of file denseHashSet.h.

◆ insert() [2/2]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
template<class IteratorType >
void insert ( IteratorType i0,
IteratorType i1 )
inline

Insert a range into the hash set.

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

Definition at line 284 of file denseHashSet.h.

◆ insert_unique()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
template<class Iterator >
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 301 of file denseHashSet.h.

◆ operator!=()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
bool operator!= ( const TfDenseHashSet< Element, HashFn, EqualElement, Threshold > & rhs) const
inline

Definition at line 150 of file denseHashSet.h.

◆ operator=() [1/3]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
TfDenseHashSet & operator= ( const TfDenseHashSet< Element, HashFn, EqualElement, Threshold > & rhs)
inline

Copy assignment operator.

Definition at line 112 of file denseHashSet.h.

◆ operator=() [2/3]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
TfDenseHashSet & operator= ( std::initializer_list< Element > l)
inline

Assignment from an initializer_list.

Definition at line 126 of file denseHashSet.h.

◆ operator=() [3/3]

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
TfDenseHashSet & operator= ( TfDenseHashSet< Element, HashFn, EqualElement, Threshold > && rhs)
default

Move assignment operator.

◆ operator==()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
bool operator== ( const TfDenseHashSet< Element, HashFn, EqualElement, Threshold > & rhs) const
inline

Equality operator.

Definition at line 134 of file denseHashSet.h.

◆ operator[]()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
const Element & operator[] ( size_t index) const
inline

Index into set via index.

Definition at line 394 of file denseHashSet.h.

◆ shrink_to_fit()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
void shrink_to_fit ( )
inline

Optimize storage space.

Definition at line 368 of file denseHashSet.h.

◆ size()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
size_t size ( ) const
inline

Returns the size of the set.

Definition at line 176 of file denseHashSet.h.

◆ swap()

template<class Element , class HashFn , class EqualElement = std::equal_to<Element>, unsigned Threshold = 128>
void swap ( TfDenseHashSet< Element, HashFn, EqualElement, Threshold > & rhs)
inline

Swaps the contents of two sets.

Definition at line 163 of file denseHashSet.h.


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