AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
agx::HashSet< KeyT, HashT, AllocatorT > Class Template Reference

Inheritance with partial specialization due to bug with ref_ptr containers. More...

#include <HashSet.h>

+ Inheritance diagram for agx::HashSet< KeyT, HashT, AllocatorT >:

Public Types

typedef HashSetImplementation< KeyT, HashT, AllocatorT > Implementation
 
- Public Types inherited from agx::HashSetImplementation< KeyT, HashT, AllocatorT >
typedef template_iterator< const HashSetImplementation< KeyT, HashT, AllocatorT > > const_iterator
 
typedef const KeyT * const_pointer
 
typedef const KeyT & const_reference
 
typedef size_t difference_type
 
typedef template_iterator< HashSetImplementation< KeyT, HashT, AllocatorT > > iterator
 Iterators.
 
typedef std::bidirectional_iterator_tag iterator_category
 
typedef KeyT * pointer
 
typedef KeyT & reference
 
typedef size_t size_type
 
typedef KeyT value_type
 
- Public Types inherited from agx::Container
enum  ClearPolicy { SHRINK_BUFFER , SHRINK_BUFFER_AVERAGED , MAINTAIN_BUFFER }
 agxData::Values from this enumeration is passed to the subclasses' 'clear' method in order to control what should become of the container's memory. More...
 

Public Member Functions

 HashSet (const AllocatorT &allocator=AllocatorT())
 
- Public Member Functions inherited from agx::HashSetImplementation< KeyT, HashT, AllocatorT >
 HashSetImplementation (const AllocatorT &allocator=AllocatorT())
 Constructor.
 
 HashSetImplementation (const HashSetImplementation< KeyT, HashT, AllocatorT > &other)
 Copy constructor.
 
 ~HashSetImplementation ()
 Destructor.
 
AllocatorT & allocator ()
 
const AllocatorT & allocator () const
 
iterator begin ()
 Iterator to first element in hash set.
 
const_iterator begin () const
 
void clear (ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
 Remove all elements.
 
bool contains (const KeyT &key) const
 Boolean query to test existence of an element.
 
iterator end ()
 Iterator marking end of hash set.
 
const_iterator end () const
 
iterator erase (const iterator &it)
 Erase an element using an iterator.
 
bool erase (const KeyT &key)
 Erase an element from the hash set.
 
iterator find (const KeyT &key)
 Find an element.
 
const_iterator find (const KeyT &key) const
 
insert_iterator insert (const KeyT &key)
 Insert an element, overwriting if key already exists.
 
HashSetImplementation< KeyT, HashT, AllocatorT > & operator= (const HashSetImplementation< KeyT, HashT, AllocatorT > &other)
 Assignment operator.
 
KeyT & operator[] (const KeyT &key)
 Index operator for accessing elements in the hash, inserting it if not found.
 
const KeyT & operator[] (const KeyT &key) const
 
template<typename T >
void purge (T purger)
 Purge the hash set.
 
void reserve (size_t size)
 Reserve capacity in the hash set.
 
- Public Member Functions inherited from agx::Container
size_t capacity () const
 Returns the size of the memory are used by the container to store its elements.
 
bool empty () const
 
void * ptr ()
 
const void * ptr () const
 
size_t size () const
 

Additional Inherited Members

- Protected Member Functions inherited from agx::HashSetImplementation< KeyT, HashT, AllocatorT >
Bucketbuckets () const
 
bool eraseBucket (size_t index)
 
template<typename T2 >
size_t findBucket (const T2 &key) const
 
size_t & numBuckets ()
 
size_t numBuckets () const
 
size_t & numFilled ()
 
size_t numFilled () const
 
void rebuild (size_t size)
 Rebuild, and optionally resize hash set.
 
- Protected Member Functions inherited from agx::Container
 Container ()
 
 Container (const Container &other)
 
 Container (Container &&other)
 
 ~Container ()
 
- Protected Attributes inherited from agx::Container
void * m_buffer
 
size_t m_capacity
 
size_t m_size
 

Detailed Description

template<typename KeyT, typename HashT = HashFn<KeyT>, typename AllocatorT = ByteAllocator>
class agx::HashSet< KeyT, HashT, AllocatorT >

Inheritance with partial specialization due to bug with ref_ptr containers.

And partial specialization only works on classes, not methods (which would have been a cleaner solution).

example:

HashSet<RigidBodyRef> bodySet; RigidBody *body = new RigidBody(); if (bodySet.contains(body)) // <----------— the call to contains will deallocate body due to creation of temporary ref_ptr { ... }

Also, even if we have another reference somewhere which will prevent the deallocation, we still create a temporary ref_ptr and perform two atomic operations just for a table lookup.

And note that we can not use the same solution as in Vector, which is to add another template for the type being compared. so instead of

bool contains(const KeyT& key) const

we would have

template <typename T2> bool contains(const T2& key) const

but this is not safe for hash tables since another hash function may be called, example:

HashSet<UInt64> set; set.insert(123); if (set.contains(UInt32(123))) <------— would be false due to a different hash function being used { ... }

Definition at line 669 of file agx/HashSet.h.

Member Typedef Documentation

◆ Implementation

template<typename KeyT , typename HashT = HashFn<KeyT>, typename AllocatorT = ByteAllocator>
typedef HashSetImplementation<KeyT, HashT, AllocatorT> agx::HashSet< KeyT, HashT, AllocatorT >::Implementation

Definition at line 672 of file agx/HashSet.h.

Constructor & Destructor Documentation

◆ HashSet()

template<typename KeyT , typename HashT = HashFn<KeyT>, typename AllocatorT = ByteAllocator>
agx::HashSet< KeyT, HashT, AllocatorT >::HashSet ( const AllocatorT &  allocator = AllocatorT())
inline

Definition at line 674 of file agx/HashSet.h.


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