AGXDynamics  2.35.0.3
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 
177  typedef template_iterator< HashSetImplementation<KeyT, HashT, AllocatorT> > iterator;
178  typedef template_iterator< const HashSetImplementation<KeyT, HashT, AllocatorT> > const_iterator;
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_ */
agx::HashSetImplementation::Bucket::state
agx::UInt8 state
Definition: HashSet.h:508
agx::HashSetImplementation::HashSetImplementation
HashSetImplementation(const AllocatorT &allocator=AllocatorT())
Constructor.
Definition: HashSet.h:208
agx::HashSetImplementation::template_iterator::iterator_category
std::iterator_traits< T >::iterator_category iterator_category
Definition: HashSet.h:79
agx::HashSetImplementation::begin
iterator begin()
Iterator to first element in hash set.
Definition: HashSet.h:356
agx::HashSetImplementation::template_iterator::operator++
template_iterator< T > operator++(int)
Definition: HashSet.h:107
agxTerrain::Profiler::Bucket
std::pair< agx::Name, agx::Real > Bucket
Definition: ProfilingTools.h:33
Container.h
agx::Real
double Real
Definition: Real.h:42
agx::HashSetImplementation::end
iterator end()
Iterator marking end of hash set.
Definition: HashSet.h:366
agx::HashSetImplementation::Bucket::VALID
@ VALID
Definition: HashSet.h:500
agx::nextPrime
AGXCORE_EXPORT int nextPrime(int n)
agxAssert1
#define agxAssert1(expr, msg)
Definition: debug.h:144
HashFunction.h
Allocator.h
agx::Container::size
size_t size() const
Definition: Container.h:134
agx::HashSetImplementation::contains
bool contains(const KeyT &key) const
Boolean query to test existence of an element.
Definition: HashSet.h:310
AGX_HASH_SET_SHRINK_THRESHOLD
#define AGX_HASH_SET_SHRINK_THRESHOLD
Definition: HashSet.h:66
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agx::HashSetImplementation::Bucket::INACTIVE
@ INACTIVE
Definition: HashSet.h:498
agx::HashSetImplementation::buckets
Bucket * buckets() const
Definition: HashSet.h:523
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agx::HashSetImplementation::begin
const_iterator begin() const
Definition: HashSet.h:359
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
agx::Real32
float Real32
Definition: Real.h:44
agx::HashSetImplementation::template_iterator::operator--
template_iterator< T > operator--()
Definition: HashSet.h:116
agx::HashSetImplementation::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: HashSet.h:58
agx::HashSetImplementation::Bucket::Bucket
Bucket()
Definition: HashSet.h:503
agx::HashSet< agx::ref_ptr< KeyT >, HashT, AllocatorT >::find
const_iterator find(const KeyT *key) const
Definition: HashSet.h:697
agx::HashSetImplementation::template_iterator::operator++
template_iterator< T > & operator++()
Definition: HashSet.h:101
agx::HashSetImplementation::insert
insert_iterator insert(const KeyT &key)
Insert an element, overwriting if key already exists.
Definition: HashSet.h:246
agx::Container::SHRINK_BUFFER_AVERAGED
@ SHRINK_BUFFER_AVERAGED
Buffer is shrunk if a smoothing average (which is updated each clear call) goes below a threshold.
Definition: Container.h:45
agx::HashSetImplementation::template_iterator::operator=
template_iterator< T > & operator=(const template_iterator< T > &copy)
Definition: HashSet.h:147
agx::HashSetImplementation::template_iterator::operator--
template_iterator< T > operator--(int)
Definition: HashSet.h:122
agx::HashSetImplementation::numFilled
size_t numFilled() const
Definition: HashSet.h:525
agx::HashSetImplementation::template_iterator::template_iterator
template_iterator(T *hashSet, size_t startIndex=0)
Definition: HashSet.h:89
agx::HashSet< agx::ref_ptr< KeyT >, HashT, AllocatorT >::iterator
Implementation::iterator iterator
Definition: HashSet.h:679
agx::Container::SHRINK_BUFFER
@ SHRINK_BUFFER
Buffer is deallocated and replaced by an newly allocated empty buffer.
Definition: Container.h:44
agx::HashSetImplementation::template_iterator::HashSetT
T HashSetT
Definition: HashSet.h:78
agx::HashSetImplementation::findBucket
size_t findBucket(const T2 &key) const
Definition: HashSet.h:567
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agx::HashSetImplementation::Bucket::isValid
bool isValid() const
Definition: HashSet.h:513
AGX_HASH_SET_SHRINK_FACTOR
#define AGX_HASH_SET_SHRINK_FACTOR
Definition: HashSet.h:68
agx::HashSetImplementation::template_iterator::operator*
KeyT & operator*() const
Definition: HashSet.h:137
agx::HashSetImplementation::const_iterator
template_iterator< const HashSetImplementation< KeyT, HashT, AllocatorT > > const_iterator
Definition: HashSet.h:178
agx::Container::m_buffer
void * m_buffer
Definition: Container.h:96
agx::HashSetImplementation::value_type
KeyT value_type
Definition: HashSet.h:52
agx::HashSetImplementation::numBuckets
size_t numBuckets() const
Definition: HashSet.h:524
agx::HashSetImplementation::template_iterator
Definition: HashSet.h:75
AGX_HASH_SET_GROW_FACTOR
#define AGX_HASH_SET_GROW_FACTOR
Definition: HashSet.h:67
agx::HashSetImplementation::allocator
AllocatorT & allocator()
Definition: HashSet.h:484
agx::UInt16
uint16_t UInt16
Definition: Integer.h:39
agx::HashSetImplementation::size_type
size_t size_type
Definition: HashSet.h:57
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agx::UInt8
uint8_t UInt8
Definition: Integer.h:38
Math.h
agx::HashSetImplementation::insert_iterator::HashSetT
iterator::HashSetT HashSetT
Definition: HashSet.h:183
agx::HashSetImplementation::insert_iterator::insert_iterator
insert_iterator(HashSetT *hashSet, size_t startIndex, bool overwrite)
Definition: HashSet.h:191
agx::HashSetImplementation
Same as hash table, but only containing keys, not key-value pairs.
Definition: HashSet.h:49
Integer.h
agx::HashSetImplementation::operator[]
KeyT & operator[](const KeyT &key)
Index operator for accessing elements in the hash, inserting it if not found.
Definition: HashSet.h:321
agx::HashSetImplementation::operator[]
const KeyT & operator[](const KeyT &key) const
Definition: HashSet.h:330
agx::HashSet< agx::ref_ptr< KeyT >, HashT, AllocatorT >::find
iterator find(const KeyT *key)
Definition: HashSet.h:692
agx::Container::m_size
size_t m_size
Definition: Container.h:94
AGX_HASH_SET_MAX_PROBE_LENGTH
#define AGX_HASH_SET_MAX_PROBE_LENGTH
Definition: HashSet.h:70
AGX_HASH_SET_GROW_THRESHOLD
#define AGX_HASH_SET_GROW_THRESHOLD
Definition: HashSet.h:65
agx::HashSetImplementation::iterator
template_iterator< HashSetImplementation< KeyT, HashT, AllocatorT > > iterator
Iterators.
Definition: HashSet.h:177
agx::HashSetImplementation::find
iterator find(const KeyT &key)
Find an element.
Definition: HashSet.h:342
agx::HashSet< agx::ref_ptr< KeyT >, HashT, AllocatorT >::const_iterator
Implementation::const_iterator const_iterator
Definition: HashSet.h:680
agx::HashSetImplementation::template_iterator::difference_type
std::iterator_traits< T >::difference_type difference_type
Definition: HashSet.h:81
agx::HashSetImplementation::allocator
const AllocatorT & allocator() const
Definition: HashSet.h:485
agx::HashSetImplementation::insert_iterator::didOverwrite
bool didOverwrite() const
Definition: HashSet.h:198
agx::HashSetImplementation::Bucket::State
State
Definition: HashSet.h:496
agx::HashSetImplementation::erase
bool erase(const KeyT &key)
Erase an element from the hash set.
Definition: HashSet.h:377
AGX_HASH_SET_SMOOTHING_FACTOR
#define AGX_HASH_SET_SMOOTHING_FACTOR
Definition: HashSet.h:69
agx::HashSet
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:665
ref_ptr.h
agx::Container::m_capacity
size_t m_capacity
Definition: Container.h:95
agx.h
agx::Container::ClearPolicy
ClearPolicy
agxData::Values from this enumeration is passed to the subclasses' 'clear' method in order to control...
Definition: Container.h:42
agx::HashSet< agx::ref_ptr< KeyT >, HashT, AllocatorT >::HashSet
HashSet(const AllocatorT &allocator=AllocatorT())
Definition: HashSet.h:682
agx::HashSetImplementation::const_pointer
const typedef KeyT * const_pointer
Definition: HashSet.h:54
agx::HashSet< agx::ref_ptr< KeyT >, HashT, AllocatorT >::erase
bool erase(const KeyT *key)
Definition: HashSet.h:703
agx::HashSetImplementation::HashSetImplementation
HashSetImplementation(const HashSetImplementation< KeyT, HashT, AllocatorT > &other)
Copy constructor.
Definition: HashSet.h:212
agx::HashSet< agx::ref_ptr< KeyT >, HashT, AllocatorT >::Implementation
HashSetImplementation< agx::ref_ptr< KeyT >, HashT, AllocatorT > Implementation
Definition: HashSet.h:678
agx::HashSetImplementation::purge
void purge(T purger)
Purge the hash set.
Definition: HashSet.h:466
agx::HashSet::Implementation
HashSetImplementation< KeyT, HashT, AllocatorT > Implementation
Definition: HashSet.h:668
agx::HashSetImplementation::template_iterator::operator==
bool operator==(const template_iterator< T > &rhs)
Definition: HashSet.h:130
agx::HashSet< agx::ref_ptr< KeyT >, HashT, AllocatorT >::contains
bool contains(const KeyT *key) const
Definition: HashSet.h:686
agx::HashSetImplementation::numBuckets
size_t & numBuckets()
Definition: HashSet.h:520
agx::HashSetImplementation::template_iterator::pointer
std::iterator_traits< T >::pointer pointer
Definition: HashSet.h:83
agx::HashSetImplementation::~HashSetImplementation
~HashSetImplementation()
Destructor.
Definition: HashSet.h:233
agx::HashSetImplementation::const_reference
const typedef KeyT & const_reference
Definition: HashSet.h:56
agx::HashSetImplementation::pointer
KeyT * pointer
Definition: HashSet.h:53
agx::HashSetImplementation::reference
KeyT & reference
Definition: HashSet.h:55
agx::Container
The Container is the base class for several of the container classes proided by AGX,...
Definition: Container.h:34
agx::HashSetImplementation::template_iterator::operator->
KeyT * operator->() const
Definition: HashSet.h:143
agx::HashSetImplementation::operator=
HashSetImplementation< KeyT, HashT, AllocatorT > & operator=(const HashSetImplementation< KeyT, HashT, AllocatorT > &other)
Assignment operator.
Definition: HashSet.h:218
agx::HashSetImplementation::Bucket::ACTIVE
@ ACTIVE
Definition: HashSet.h:499
agx::HashSetImplementation::insert_iterator::insert_iterator
insert_iterator()
Definition: HashSet.h:187
AGX_HASH_SET_MIN_SIZE
#define AGX_HASH_SET_MIN_SIZE
Definition: HashSet.h:63
agx::HashSetImplementation::Bucket::isActive
bool isActive() const
Definition: HashSet.h:510
agx::HashSetImplementation::end
const_iterator end() const
Definition: HashSet.h:369
agx::HashSetImplementation::Bucket::key
KeyT key
Definition: HashSet.h:507
agx::HashSetImplementation::difference_type
size_t difference_type
Definition: HashSet.h:59
agx::HashSetImplementation::reserve
void reserve(size_t size)
Reserve capacity in the hash set.
Definition: HashSet.h:451
agx::HashSetImplementation::erase
iterator erase(const iterator &it)
Erase an element using an iterator.
Definition: HashSet.h:386
agx::HashSetImplementation::template_iterator::template_iterator
template_iterator()
Constructors.
Definition: HashSet.h:87
agx::Container::MAINTAIN_BUFFER
@ MAINTAIN_BUFFER
Buffer is maintained (normal stl behavior).
Definition: Container.h:46
agx::HashSetImplementation::eraseBucket
bool eraseBucket(size_t index)
Definition: HashSet.h:594
agx::HashSet::HashSet
HashSet(const AllocatorT &allocator=AllocatorT())
Definition: HashSet.h:670
agx::max
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:874
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agx::HashSetImplementation::Bucket
Definition: HashSet.h:493
agx::HashSetImplementation::template_iterator::value_type
std::iterator_traits< T >::value_type value_type
Definition: HashSet.h:80
agx::HashSetImplementation::clear
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements.
Definition: HashSet.h:395
agx::HashSetImplementation::rebuild
void rebuild(size_t size)
Rebuild, and optionally resize hash set.
Definition: HashSet.h:530
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::HashSetImplementation::find
const_iterator find(const KeyT &key) const
Definition: HashSet.h:347
agx::hashKeyEqual
bool hashKeyEqual(const T1 &key1, const T2 &key2)
Definition: HashFunction.h:77
agx::HashSetImplementation::template_iterator::operator!=
bool operator!=(const template_iterator< T > &rhs)
Definition: HashSet.h:133
agx::HashSetImplementation::template_iterator::reference
std::iterator_traits< T >::reference reference
Definition: HashSet.h:82
agx::HashSetImplementation::numFilled
size_t & numFilled()
Definition: HashSet.h:521
agx::HashSetImplementation::insert_iterator
Definition: HashSet.h:180