AGX Dynamics  2.35.0.1
agx/HashSet.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_HASHSET_H
18 #define AGX_HASHSET_H
19 
20 #include <agx/agx.h>
21 #include <agx/ref_ptr.h>
22 
23 #include <agx/Math.h>
24 
25 #include <agx/HashFunction.h>
26 #include <agx/Container.h>
27 #include <agx/Allocator.h>
28 #include <agx/Integer.h>
29 
30 #include <algorithm> // For std::max
31 
32 #define AGX_DECLARE_HASHSET_TYPES(type) \
33 typedef agx::HashSet<type ## Ref> type ## RefSet; \
34 typedef agx::HashSet<type ## Observer> type ## ObserverSet; \
35 typedef agx::HashSet<type *> type ## PtrSet
36 
37 #ifdef _MSC_VER
38 # pragma warning(push)
39 # pragma warning(disable: 6011) // Disable warningC6011: dereferencing nullptr pointer
40 #endif
41 
42 
43 namespace agx
44 {
48  template <typename KeyT, typename HashT = HashFn<KeyT>, typename AllocatorT = ByteAllocator>
50  {
51  public:
52  typedef KeyT value_type;
53  typedef KeyT* pointer;
54  typedef const KeyT* const_pointer;
55  typedef KeyT& reference;
56  typedef const KeyT& const_reference;
57  typedef size_t size_type;
58  typedef std::bidirectional_iterator_tag iterator_category;
59  typedef size_t difference_type;
60 
61 
62  private:
63  #define AGX_HASH_SET_MIN_SIZE 1
64 
65  #define AGX_HASH_SET_GROW_THRESHOLD 0.8
66  #define AGX_HASH_SET_SHRINK_THRESHOLD 0.25
67  #define AGX_HASH_SET_GROW_FACTOR 2.0
68  #define AGX_HASH_SET_SHRINK_FACTOR 0.5
69  #define AGX_HASH_SET_SMOOTHING_FACTOR 0.8
70  #define AGX_HASH_SET_MAX_PROBE_LENGTH 10
71 
72  public:
73 
74  template<typename T>
76  {
77  public:
78  typedef T HashSetT;
79  typedef typename std::iterator_traits<T>::iterator_category iterator_category;
80  typedef typename std::iterator_traits<T>::value_type value_type;
81  typedef typename std::iterator_traits<T>::difference_type difference_type;
82  typedef typename std::iterator_traits<T>::reference reference;
83  typedef typename std::iterator_traits<T>::pointer pointer;
84 
85  public:
87  AGX_FORCE_INLINE template_iterator() : m_hashSet(0), m_currentIndex(0) {}
88 
89  AGX_FORCE_INLINE template_iterator(T* hashSet, size_t startIndex = 0) : m_hashSet(hashSet), m_currentIndex(startIndex-1)
90  { this->gotoNextElement(); }
91 
94  {
96  constIt.m_hashSet = m_hashSet;
97  constIt.m_currentIndex = m_currentIndex;
98  return constIt;
99  }
100 
102  {
103  this->gotoNextElement();
104  return *this;
105  }
106 
108  {
109  size_t oldIndex = m_currentIndex;
110  this->gotoNextElement();
111 
112  return template_iterator<T>(m_hashSet, oldIndex);
113  }
114 
115 
117  {
118  this->gotoPreviousElement();
119  return *this;
120  }
121 
123  {
124  size_t oldIndex = m_currentIndex;
125  this->gotoPreviousElement();
126 
127  return template_iterator<T>(m_hashSet, oldIndex);
128  }
129 
131  { return this->m_currentIndex == rhs.m_currentIndex && this->m_hashSet == rhs.m_hashSet; }
132 
134  { return this->m_currentIndex != rhs.m_currentIndex || this->m_hashSet != rhs.m_hashSet; }
135 
136 
138  {
139  agxAssert1(m_hashSet && m_currentIndex != m_hashSet->numBuckets(), "Can not dereference an invalid bucket!");
140  return m_hashSet->buckets()[m_currentIndex].key;
141  }
142 
144  { return &(operator*()); }
145 
146 
148  {
149  m_hashSet = copy.m_hashSet;
150  m_currentIndex = copy.m_currentIndex;
151  return *this;
152  }
153 
154  private:
155  AGX_FORCE_INLINE void gotoNextElement()
156  {
157  m_currentIndex++;
158  while (m_currentIndex < m_hashSet->numBuckets() && !m_hashSet->buckets()[m_currentIndex].isValid())
159  m_currentIndex++;
160  }
161 
162  AGX_FORCE_INLINE void gotoPreviousElement()
163  {
164  if (m_currentIndex > 0) {
165  m_currentIndex--;
166  while (m_currentIndex > 0 && !m_hashSet->buckets()[m_currentIndex].isValid())
167  m_currentIndex--;
168  }
169  }
170  private:
171  friend class HashSetImplementation;
172  HashSetT* m_hashSet;
173  size_t m_currentIndex;
174  };
175 
179 
180  class insert_iterator : public iterator
181  {
182  public:
183  typedef typename iterator::HashSetT HashSetT;
184 
185  public:
186 
187  AGX_FORCE_INLINE insert_iterator() : iterator(), m_overwrite(false)
188  {
189  }
190 
191  AGX_FORCE_INLINE insert_iterator(HashSetT* hashSet, size_t startIndex, bool overwrite) : iterator(hashSet, startIndex), m_overwrite(overwrite)
192  {
193  }
194 
199  {
200  return m_overwrite;
201  }
202 
203  private:
204  bool m_overwrite;
205  };
206 
208  AGX_FORCE_INLINE HashSetImplementation(const AllocatorT& allocator = AllocatorT()) : m_smoothingAverage(0), m_maxProbeLength(0), m_allocator(allocator)
209  { m_allocator.setContainer(this); }
210 
212  AGX_FORCE_INLINE HashSetImplementation(const HashSetImplementation<KeyT, HashT, AllocatorT>& other) : m_smoothingAverage(0), m_maxProbeLength(0)
213  {
214  *this = other;
215  }
216 
219  {
220  m_allocator = other.m_allocator;
221  m_allocator.setContainer(this);
222 
223  this->clear(MAINTAIN_BUFFER);
224  this->reserve(other.size());
225 
226  for (const_iterator it = other.begin(); it != other.end(); ++it)
227  this->insert(*it);
228 
229  return *this;
230  }
231 
234  {
235  for (size_t i = 0; i < numBuckets(); ++i)
236  buckets()[i].~Bucket();
237 
238  m_allocator.deallocateBytes(m_buffer, m_capacity * sizeof(Bucket));
239  }
240 
241 
246  insert_iterator insert(const KeyT& key)
247  {
248  UInt32 hashValue = m_hashFunctor(key);
249  Bucket *bucket;
250  Bucket *targetBucket = 0;
251  size_t offset = 0;
252 
253  /* Check if we should grow and rebuild hash table */
254  if (numFilled() >= (size_t)((float)numBuckets() * AGX_HASH_SET_GROW_THRESHOLD))
255  this->rebuild((size_t)((float)(numBuckets()+1) * AGX_HASH_SET_GROW_FACTOR));
256 
257  /* Iterate until target bucket is found */
258  bool goon=true;
259  do
260  {
261  bucket = &buckets()[(hashValue + offset * offset) % numBuckets()];
262 
263  /* Check if inactive bucket or overwriting previous insertion with same key */
264  if (!bucket->isActive() || (bucket->isValid() && hashKeyEqual(bucket->key, key)))
265  {
266  targetBucket = bucket;
267  break;
268  }
269 
270  /* Tag first free slot */
271  if (!bucket->isValid() && !targetBucket)
272  targetBucket = bucket;
273 
274  /* If we have found a free bucket we can stop iterating when we are sure that the key was not previously inserted */
275  if (targetBucket && offset >= m_maxProbeLength)
276  break;
277 
278  /* Go to next bucket */
279  offset++;
280 
281  /* Resize and rebuild table if it takes too long to find a free slot */
282  if (offset > AGX_HASH_SET_MAX_PROBE_LENGTH)
283  {
284  this->rebuild((size_t)((float)numBuckets() * AGX_HASH_SET_GROW_FACTOR));
285  return this->insert(key);
286  }
287  } while (goon);
288 
289  agxAssert(targetBucket);
290 
291  if (offset > m_maxProbeLength)
292  m_maxProbeLength = (UInt16)offset;
293 
294  targetBucket->key = key;
295 
296  /* Check if inserting a new value rather than overwriting an old entry*/
297  bool overwrite = targetBucket->isValid();
298  if (!overwrite)
299  {
300  numFilled()++;
301  targetBucket->state = Bucket::VALID;
302  }
303 
304  return insert_iterator(this, targetBucket - buckets(), overwrite);
305  }
306 
310  AGX_FORCE_INLINE bool contains(const KeyT& key) const
311  {
312  return this->findBucket(key) != numBuckets();
313  }
314 
315 
321  AGX_FORCE_INLINE KeyT& operator[](const KeyT& key )
322  {
323  iterator it = find( key );
324  if (it == end() ){
325  it = insert( key );
326  }
327  return *it;
328  }
329 
330  AGX_FORCE_INLINE const KeyT& operator[](const KeyT& key ) const
331  {
332  iterator it = find( key );
333  if (it == end() ){
334  it = insert( key );
335  }
336  return *it;
337  }
338 
342  AGX_FORCE_INLINE iterator find(const KeyT& key)
343  {
344  return iterator(this, this->findBucket(key));
345  }
346 
347  AGX_FORCE_INLINE const_iterator find(const KeyT& key) const
348  {
349  return const_iterator(this, this->findBucket(key));
350  }
351 
352 
357  { return iterator(this); }
358 
360  { return const_iterator(this); }
361 
362 
367  { return iterator(this, numBuckets()); }
368 
370  { return const_iterator(this, numBuckets()); }
371 
372 
377  AGX_FORCE_INLINE bool erase(const KeyT& key)
378  {
379  return this->eraseBucket(this->findBucket(key));
380  }
381 
387  {
388  this->eraseBucket(it.m_currentIndex);
389  return iterator(this, it.m_currentIndex);
390  }
391 
396  {
397  if (policy == MAINTAIN_BUFFER)
398  {
399  for (size_t i = 0; i < numBuckets(); i++)
400  buckets()[i] = Bucket();
401  }
402  else if (policy == SHRINK_BUFFER)
403  {
404  for (size_t i = 0; i < numBuckets(); ++i)
405  buckets()[i].~Bucket();
406 
407  m_allocator.deallocateBytes(m_buffer, m_capacity * sizeof(Bucket));
409  m_buffer = m_allocator.allocateBytes(numBuckets() * sizeof(Bucket));
410  for (size_t i = 0; i < numBuckets(); ++i)
411  ::new (&(buckets()[i])) Bucket();
412 
413  m_smoothingAverage = 0.0;
414  }
415  else //if (policy == SHRINK_BUFFER_AVERAGED)
416  {
417  /* Smoothing average is never less than current size */
418  if ((Real32)numFilled() > m_smoothingAverage)
419  m_smoothingAverage = Real32(numFilled());
420 
421  /* Update smoothing average */
422  m_smoothingAverage = Real32(AGX_HASH_SET_SMOOTHING_FACTOR * m_smoothingAverage + (1.0-AGX_HASH_SET_SMOOTHING_FACTOR) * (float)numFilled());
423 
424  /* Reallocate buffer if the smoothing average is sufficiently below the current capacity */
425  if (m_smoothingAverage < AGX_HASH_SET_SHRINK_THRESHOLD * (float)numBuckets() && m_smoothingAverage >= AGX_HASH_SET_MIN_SIZE)
426  {
427  for (size_t i = 0; i < numBuckets(); ++i)
428  buckets()[i].~Bucket();
429 
430  m_allocator.deallocateBytes(m_buffer, m_capacity * sizeof(Bucket));
431  numBuckets() = agx::nextPrime((int)m_smoothingAverage);
432  m_buffer = m_allocator.allocateBytes(numBuckets() * sizeof(Bucket));
433  for (size_t i = 0; i < numBuckets(); ++i)
434  ::new (&(buckets()[i])) Bucket();
435  }
436  else
437  {
438  for (size_t i = 0; i < numBuckets(); i++)
439  buckets()[i] = Bucket();
440  }
441  }
442 
443 
444  numFilled() = 0;
445  m_maxProbeLength = 0;
446  }
447 
451  void reserve(size_t size)
452  {
453  if ((double)size <= (double)numBuckets() * AGX_HASH_SET_GROW_THRESHOLD)
454  return;
455 
456  this->rebuild((size_t)((double)size / AGX_HASH_SET_GROW_THRESHOLD));
457  }
458 
465  template<typename T>
466  void purge(T purger)
467  {
468  for (size_t i = 0; i < numBuckets(); i++)
469  {
470  Bucket& bucket = buckets()[i];
471 
472  if (bucket.isValid() && purger(bucket.key))
473  {
474  bucket = Bucket();
475  bucket.state = Bucket::ACTIVE;
476  numFilled()--;
477  }
478  }
479 
481  this->rebuild( size_t(numFilled() * AGX_HASH_SET_GROW_FACTOR) );
482  }
483 
484  AllocatorT& allocator() { return m_allocator; }
485  const AllocatorT& allocator() const { return m_allocator; }
486 
487 
489  AGX_FORCE_INLINE size_t getNumActiveElements() const { return numBuckets(); }
491 
492  public:
493  class Bucket
494  {
495  public:
496  enum State
497  {
500  VALID
501  };
502 
503  AGX_FORCE_INLINE Bucket() : key(), state(INACTIVE)
504  {
505  }
506 
507  KeyT key;
509 
511  { return state >= ACTIVE; }
512 
514  { return state == VALID; }
515  };
516 
517 
518  protected:
519  // Access to Container members
520  AGX_FORCE_INLINE size_t& numBuckets() { return m_capacity; }
521  AGX_FORCE_INLINE size_t& numFilled() { return m_size; }
522 
523  AGX_FORCE_INLINE Bucket *buckets() const { return static_cast<Bucket *>(m_buffer); }
524  AGX_FORCE_INLINE size_t numBuckets() const { return m_capacity; }
525  AGX_FORCE_INLINE size_t numFilled() const { return m_size; }
526 
530  void rebuild(size_t size)
531  {
532  size = std::max( size, size_t(AGX_HASH_SET_MIN_SIZE) );
533  //LOGGER_DEBUG() << "HashTable: Rebuilding and resizing from " << numBuckets() << " to " << agx::nextPrime((int)(numBuckets() * resizeFactor)) << " buckets.\n" << LOGGER_END();
534  agxAssert(size >= numFilled());
535  const size_t oldNumBuckets = numBuckets();
536  Bucket *oldBuckets = buckets();
537 
538  // Do not set numBuckets directly, since allocateBytes might Throw an exception,
539  // after which we want to be able to recover.
540  const size_t desiredNumBuckets = (size_t)agx::nextPrime((int)size);
541  const size_t desiredNumBytes = desiredNumBuckets * sizeof(Bucket);
542 
543  m_buffer = m_allocator.allocateBytes(desiredNumBytes);
544  for (size_t i = 0; i < desiredNumBuckets; ++i)
545  ::new (&(buckets()[i])) Bucket();
546 
547  numBuckets() = desiredNumBuckets;
548  numFilled() = 0;
549  m_maxProbeLength = 0;
550 
551  for (size_t i = 0; i < oldNumBuckets; i++)
552  {
553  Bucket& bucket = oldBuckets[i];
554 
555  if (bucket.isValid())
556  this->insert(bucket.key);
557  }
558 
559  for (size_t i = 0; i < oldNumBuckets; ++i)
560  oldBuckets[i].~Bucket();
561 
562  m_allocator.deallocateBytes((void *)oldBuckets, oldNumBuckets * sizeof(Bucket));
563  }
564 
565 
566  template <typename T2>
567  AGX_FORCE_INLINE size_t findBucket(const T2& key) const
568  {
569  if (!buckets())
570  return numBuckets();
571 
572  UInt32 hashValue = m_hashFunctor(key);
573  size_t index = hashValue % numBuckets();
574  Bucket *bucket = &buckets()[index];
575 
576  /* First test is outside for-loop, hopefully getting better branch prediction */
577  if (bucket->isValid() && hashKeyEqual(bucket->key, key))
578  return index;
579 
580 
581  for (size_t offset = 1; bucket->isActive() && offset <= m_maxProbeLength; offset++)
582  {
583  index = (hashValue + offset * offset) % numBuckets();
584  bucket = &buckets()[index];
585 
586  if (bucket->isValid() && hashKeyEqual(bucket->key, key))
587  return index;
588  }
589 
590  /* Not found */
591  return numBuckets();
592  }
593 
594  bool eraseBucket(size_t index)
595  {
596  if (index >= numBuckets())
597  return false;
598 
599  Bucket *bucket = &buckets()[index];
600  if (!bucket->isValid())
601  return false;
602 
603  numFilled()--;
604 
605  // Replace bucket by a new one (otherwise, if key or data is ref_ptr their ref count won't decrease)
606  *bucket = Bucket();
607 
608  // Bucket does not become inactive since it might be in the middle of a probing chain
609  bucket->state = Bucket::ACTIVE;
610 
611  /* Check if we should shrink and rebuild hash set */
612  // if (numBuckets() * AGX_HASH_SET_SHRINK_FACTOR >= AGX_HASH_SET_MIN_SIZE && numFilled()/(Real)numBuckets() < AGX_HASH_SET_SHRINK_THRESHOLD)
613  // this->rebuild(AGX_HASH_SET_SHRINK_FACTOR);
614 
615  return true;
616  }
617 
618  private:
619  Real32 m_smoothingAverage;
620  UInt16 m_maxProbeLength;
621  AllocatorT m_allocator;
622  HashT m_hashFunctor;
623  };
624 
625 
626 
664  template <typename KeyT, typename HashT = HashFn<KeyT>, typename AllocatorT = ByteAllocator>
665  class HashSet : public HashSetImplementation<KeyT, HashT, AllocatorT>
666  {
667  public:
669 
670  AGX_FORCE_INLINE HashSet(const AllocatorT& allocator = AllocatorT()) : Implementation(allocator)
671  {}
672  };
673 
674  template <typename KeyT, typename HashT, typename AllocatorT>
675  class HashSet< agx::ref_ptr<KeyT>, HashT, AllocatorT > : public HashSetImplementation<agx::ref_ptr<KeyT>, HashT, AllocatorT>
676  {
677  public:
681 
682  AGX_FORCE_INLINE HashSet(const AllocatorT& allocator = AllocatorT()) : Implementation(allocator)
683  {}
684 
686  AGX_FORCE_INLINE bool contains(const KeyT *key) const
687  {
688  return this->findBucket(key) != this->numBuckets();
689  }
690 
691  using Implementation::find;
692  AGX_FORCE_INLINE iterator find(const KeyT *key)
693  {
694  return iterator(this, this->findBucket(key));
695  }
696 
697  AGX_FORCE_INLINE const_iterator find(const KeyT *key) const
698  {
699  return const_iterator(this, this->findBucket(key));
700  }
701 
702  using Implementation::erase;
703  AGX_FORCE_INLINE bool erase(const KeyT *key)
704  {
705  return this->eraseBucket(this->findBucket(key));
706  }
707 
708  };
709 
710 }
711 
712 #ifdef _MSC_VER
713 # pragma warning(pop)
714 #endif
715 
716 #endif /* _AGX_HASHSET_H_ */
#define AGX_HASH_SET_SHRINK_THRESHOLD
Definition: agx/HashSet.h:66
#define AGX_HASH_SET_SMOOTHING_FACTOR
Definition: agx/HashSet.h:69
#define AGX_HASH_SET_MIN_SIZE
Definition: agx/HashSet.h:63
#define AGX_HASH_SET_MAX_PROBE_LENGTH
Definition: agx/HashSet.h:70
#define AGX_HASH_SET_SHRINK_FACTOR
Definition: agx/HashSet.h:68
#define AGX_HASH_SET_GROW_FACTOR
Definition: agx/HashSet.h:67
#define AGX_HASH_SET_GROW_THRESHOLD
Definition: agx/HashSet.h:65
The Container is the base class for several of the container classes proided by AGX,...
Definition: Container.h:35
size_t m_size
Definition: Container.h:94
size_t m_capacity
Definition: Container.h:95
ClearPolicy
agxData::Values from this enumeration is passed to the subclasses' 'clear' method in order to control...
Definition: Container.h:43
@ SHRINK_BUFFER
Buffer is deallocated and replaced by an newly allocated empty buffer.
Definition: Container.h:44
@ MAINTAIN_BUFFER
Buffer is maintained (normal stl behavior).
Definition: Container.h:46
@ SHRINK_BUFFER_AVERAGED
Buffer is shrunk if a smoothing average (which is updated each clear call) goes below a threshold.
Definition: Container.h:45
void * m_buffer
Definition: Container.h:96
size_t size() const
Definition: Container.h:134
insert_iterator(HashSetT *hashSet, size_t startIndex, bool overwrite)
Definition: agx/HashSet.h:191
bool operator==(const template_iterator< T > &rhs)
Definition: agx/HashSet.h:130
template_iterator< T > operator--(int)
Definition: agx/HashSet.h:122
template_iterator< T > & operator=(const template_iterator< T > &copy)
Definition: agx/HashSet.h:147
template_iterator< T > operator++(int)
Definition: agx/HashSet.h:107
std::iterator_traits< T >::difference_type difference_type
Definition: agx/HashSet.h:81
std::iterator_traits< T >::iterator_category iterator_category
Definition: agx/HashSet.h:79
template_iterator(T *hashSet, size_t startIndex=0)
Definition: agx/HashSet.h:89
std::iterator_traits< T >::reference reference
Definition: agx/HashSet.h:82
std::iterator_traits< T >::pointer pointer
Definition: agx/HashSet.h:83
std::iterator_traits< T >::value_type value_type
Definition: agx/HashSet.h:80
bool operator!=(const template_iterator< T > &rhs)
Definition: agx/HashSet.h:133
Same as hash table, but only containing keys, not key-value pairs.
Definition: agx/HashSet.h:50
const_iterator end() const
Definition: agx/HashSet.h:369
const_iterator find(const KeyT &key) const
Definition: agx/HashSet.h:347
size_t findBucket(const T2 &key) const
Definition: agx/HashSet.h:567
HashSetImplementation(const HashSetImplementation< KeyT, HashT, AllocatorT > &other)
Copy constructor.
Definition: agx/HashSet.h:212
KeyT & operator[](const KeyT &key)
Index operator for accessing elements in the hash, inserting it if not found.
Definition: agx/HashSet.h:321
size_t numFilled() const
Definition: agx/HashSet.h:525
void purge(T purger)
Purge the hash set.
Definition: agx/HashSet.h:466
iterator begin()
Iterator to first element in hash set.
Definition: agx/HashSet.h:356
~HashSetImplementation()
Destructor.
Definition: agx/HashSet.h:233
void rebuild(size_t size)
Rebuild, and optionally resize hash set.
Definition: agx/HashSet.h:530
const_iterator begin() const
Definition: agx/HashSet.h:359
HashSetImplementation(const AllocatorT &allocator=AllocatorT())
Constructor.
Definition: agx/HashSet.h:208
const AllocatorT & allocator() const
Definition: agx/HashSet.h:485
template_iterator< HashSetImplementation< KeyT, HashT, AllocatorT > > iterator
Iterators.
Definition: agx/HashSet.h:177
void reserve(size_t size)
Reserve capacity in the hash set.
Definition: agx/HashSet.h:451
HashSetImplementation< KeyT, HashT, AllocatorT > & operator=(const HashSetImplementation< KeyT, HashT, AllocatorT > &other)
Assignment operator.
Definition: agx/HashSet.h:218
Bucket * buckets() const
Definition: agx/HashSet.h:523
iterator erase(const iterator &it)
Erase an element using an iterator.
Definition: agx/HashSet.h:386
const KeyT & operator[](const KeyT &key) const
Definition: agx/HashSet.h:330
std::bidirectional_iterator_tag iterator_category
Definition: agx/HashSet.h:58
bool eraseBucket(size_t index)
Definition: agx/HashSet.h:594
iterator find(const KeyT &key)
Find an element.
Definition: agx/HashSet.h:342
const KeyT * const_pointer
Definition: agx/HashSet.h:54
iterator end()
Iterator marking end of hash set.
Definition: agx/HashSet.h:366
bool erase(const KeyT &key)
Erase an element from the hash set.
Definition: agx/HashSet.h:377
size_t numBuckets() const
Definition: agx/HashSet.h:524
const KeyT & const_reference
Definition: agx/HashSet.h:56
bool contains(const KeyT &key) const
Boolean query to test existence of an element.
Definition: agx/HashSet.h:310
AllocatorT & allocator()
Definition: agx/HashSet.h:484
template_iterator< const HashSetImplementation< KeyT, HashT, AllocatorT > > const_iterator
Definition: agx/HashSet.h:178
insert_iterator insert(const KeyT &key)
Insert an element, overwriting if key already exists.
Definition: agx/HashSet.h:246
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements.
Definition: agx/HashSet.h:395
const_iterator find(const KeyT *key) const
Definition: agx/HashSet.h:697
HashSet(const AllocatorT &allocator=AllocatorT())
Definition: agx/HashSet.h:682
HashSetImplementation< agx::ref_ptr< KeyT >, HashT, AllocatorT > Implementation
Definition: agx/HashSet.h:678
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: agx/HashSet.h:666
HashSet(const AllocatorT &allocator=AllocatorT())
Definition: agx/HashSet.h:670
HashSetImplementation< KeyT, HashT, AllocatorT > Implementation
Definition: agx/HashSet.h:668
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define agxAssert1(expr, msg)
Definition: debug.h:144
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
#define AGX_FORCE_INLINE
Definition: macros.h:58
std::pair< agx::Name, agx::Real > Bucket
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint16_t UInt16
Definition: Integer.h:39
uint32_t UInt32
Definition: Integer.h:40
AGXCORE_EXPORT int nextPrime(int n)
double Real
Definition: Real.h:42
uint8_t UInt8
Definition: Integer.h:38
float Real32
Definition: Real.h:44
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:874
bool hashKeyEqual(const T1 &key1, const T2 &key2)
Definition: HashFunction.h:77