RavEngine
Loading...
Searching...
No Matches
PxHashSet.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_HASHSET_H
30#define PX_HASHSET_H
31
32#include "foundation/PxHashInternals.h"
33
34// TODO: make this doxy-format
35
36// This header defines two hash sets. Hash sets
37// * support custom initial table sizes (rounded up internally to power-of-2)
38// * support custom static allocator objects
39// * auto-resize, based on a load factor (i.e. a 64-entry .75 load factor hash will resize
40// when the 49th element is inserted)
41// * are based on open hashing
42//
43// Sets have STL-like copying semantics, and properly initialize and destruct copies of objects
44//
45// There are two forms of set: coalesced and uncoalesced. Coalesced sets keep the entries in the
46// initial segment of an array, so are fast to iterate over; however deletion is approximately
47// twice as expensive.
48//
49// HashSet<T>:
50// bool insert(const T& k) amortized O(1) (exponential resize policy)
51// bool contains(const T& k) const; O(1)
52// bool erase(const T& k); O(1)
53// uint32_t size() const; constant
54// void reserve(uint32_t size); O(MAX(size, currentOccupancy))
55// void clear(); O(currentOccupancy) (with zero constant for objects without
56// destructors)
57// Iterator getIterator();
58//
59// Use of iterators:
60//
61// for(HashSet::Iterator iter = test.getIterator(); !iter.done(); ++iter)
62// myFunction(*iter);
63//
64// CoalescedHashSet<T> does not support getIterator, but instead supports
65// const Key *getEntries();
66//
67// insertion into a set already containing the element fails returning false, as does
68// erasure of an element not in the set
69//
70
71#if !PX_DOXYGEN
72namespace physx
73{
74#endif
75template <class Key, class HashFn = PxHash<Key>, class Allocator = PxAllocator>
76class PxHashSet : public physx::PxHashSetBase<Key, HashFn, Allocator, false>
77{
78 public:
80 typedef typename HashSetBase::Iterator Iterator;
81
82 PxHashSet(uint32_t initialTableSize = 64, float loadFactor = 0.75f) : HashSetBase(initialTableSize, loadFactor)
83 {
84 }
85 PxHashSet(uint32_t initialTableSize, float loadFactor, const Allocator& alloc)
86 : HashSetBase(initialTableSize, loadFactor, alloc)
87 {
88 }
89 PxHashSet(const Allocator& alloc) : HashSetBase(64, 0.75f, alloc)
90 {
91 }
92 Iterator getIterator()
93 {
94 return Iterator(HashSetBase::mBase);
95 }
96};
97
98template <class Key, class HashFn = PxHash<Key>, class Allocator = PxAllocator>
99class PxCoalescedHashSet : public physx::PxHashSetBase<Key, HashFn, Allocator, true>
100{
101 public:
103
104 PxCoalescedHashSet(uint32_t initialTableSize = 64, float loadFactor = 0.75f)
105 : HashSetBase(initialTableSize, loadFactor)
106 {
107 }
108
109 PxCoalescedHashSet(uint32_t initialTableSize, float loadFactor, const Allocator& alloc)
110 : HashSetBase(initialTableSize, loadFactor, alloc)
111 {
112 }
113 PxCoalescedHashSet(const Allocator& alloc) : HashSetBase(64, 0.75f, alloc)
114 {
115 }
116
117 const Key* getEntries() const
118 {
119 return HashSetBase::mBase.getEntries();
120 }
121};
122
123#if !PX_DOXYGEN
124} // namespace physx
125#endif
126
127#endif
128
Definition PxHashSet.h:100
Definition PxHashInternals.h:453
Definition PxHashInternals.h:628
Definition PxHashSet.h:77
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39