E:/p4/sw/physx/PxShared/1.0/trunk/src/foundation/include/PsHashSet.h
Go to the documentation of this file.00001 // This code contains NVIDIA Confidential Information and is disclosed to you 00002 // under a form of NVIDIA software license agreement provided separately to you. 00003 // 00004 // Notice 00005 // NVIDIA Corporation and its licensors retain all intellectual property and 00006 // proprietary rights in and to this software and related documentation and 00007 // any modifications thereto. Any use, reproduction, disclosure, or 00008 // distribution of this software and related documentation without an express 00009 // license agreement from NVIDIA Corporation is strictly prohibited. 00010 // 00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES 00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, 00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. 00015 // 00016 // Information and code furnished is believed to be accurate and reliable. 00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such 00018 // information or for any infringement of patents or other rights of third parties that may 00019 // result from its use. No license is granted by implication or otherwise under any patent 00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice. 00021 // This code supersedes and replaces all information previously supplied. 00022 // NVIDIA Corporation products are not authorized for use as critical 00023 // components in life support devices or systems without express written approval of 00024 // NVIDIA Corporation. 00025 // 00026 // Copyright (c) 2008-2014 NVIDIA Corporation. All rights reserved. 00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. 00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. 00029 00030 #ifndef PSFOUNDATION_PSHASHSET_H 00031 #define PSFOUNDATION_PSHASHSET_H 00032 00033 #include "PsHashInternals.h" 00034 00035 // TODO: make this doxy-format 00036 00037 // This header defines two hash sets. Hash sets 00038 // * support custom initial table sizes (rounded up internally to power-of-2) 00039 // * support custom static allocator objects 00040 // * auto-resize, based on a load factor (i.e. a 64-entry .75 load factor hash will resize 00041 // when the 49th element is inserted) 00042 // * are based on open hashing 00043 // 00044 // Sets have STL-like copying semantics, and properly initialize and destruct copies of objects 00045 // 00046 // There are two forms of set: coalesced and uncoalesced. Coalesced sets keep the entries in the 00047 // initial segment of an array, so are fast to iterate over; however deletion is approximately 00048 // twice as expensive. 00049 // 00050 // HashSet<T>: 00051 // bool insert(const T& k) amortized O(1) (exponential resize policy) 00052 // bool contains(const T& k) const; O(1) 00053 // bool erase(const T& k); O(1) 00054 // uint32_t size() const; constant 00055 // void reserve(uint32_t size); O(MAX(size, currentOccupancy)) 00056 // void clear(); O(currentOccupancy) (with zero constant for objects without 00057 // destructors) 00058 // Iterator getIterator(); 00059 // 00060 // Use of iterators: 00061 // 00062 // for(HashSet::Iterator iter = test.getIterator(); !iter.done(); ++iter) 00063 // myFunction(*iter); 00064 // 00065 // CoalescedHashSet<T> does not support getIterator, but instead supports 00066 // const Key *getEntries(); 00067 // 00068 // insertion into a set already containing the element fails returning false, as does 00069 // erasure of an element not in the set 00070 // 00071 00072 namespace physx 00073 { 00074 namespace shdfnd 00075 { 00076 template <class Key, class HashFn = Hash<Key>, class Allocator = NonTrackingAllocator> 00077 class HashSet : public internal::HashSetBase<Key, HashFn, Allocator, false> 00078 { 00079 public: 00080 typedef internal::HashSetBase<Key, HashFn, Allocator, false> HashSetBase; 00081 typedef typename HashSetBase::Iterator Iterator; 00082 00083 HashSet(uint32_t initialTableSize = 64, float loadFactor = 0.75f) : HashSetBase(initialTableSize, loadFactor) 00084 { 00085 } 00086 HashSet(uint32_t initialTableSize, float loadFactor, const Allocator& alloc) 00087 : HashSetBase(initialTableSize, loadFactor, alloc) 00088 { 00089 } 00090 HashSet(const Allocator& alloc) : HashSetBase(64, 0.75f, alloc) 00091 { 00092 } 00093 Iterator getIterator() 00094 { 00095 return Iterator(HashSetBase::mBase); 00096 } 00097 }; 00098 00099 template <class Key, class HashFn = Hash<Key>, class Allocator = NonTrackingAllocator> 00100 class CoalescedHashSet : public internal::HashSetBase<Key, HashFn, Allocator, true> 00101 { 00102 public: 00103 typedef typename internal::HashSetBase<Key, HashFn, Allocator, true> HashSetBase; 00104 00105 CoalescedHashSet(uint32_t initialTableSize = 64, float loadFactor = 0.75f) 00106 : HashSetBase(initialTableSize, loadFactor) 00107 { 00108 } 00109 00110 CoalescedHashSet(uint32_t initialTableSize, float loadFactor, const Allocator& alloc) 00111 : HashSetBase(initialTableSize, loadFactor, alloc) 00112 { 00113 } 00114 CoalescedHashSet(const Allocator& alloc) : HashSetBase(64, 0.75f, alloc) 00115 { 00116 } 00117 00118 const Key* getEntries() const 00119 { 00120 return HashSetBase::mBase.getEntries(); 00121 } 00122 }; 00123 00124 } // namespace shdfnd 00125 } // namespace physx 00126 00127 #endif // #ifndef PSFOUNDATION_PSHASHSET_H
Generated on Tue Jul 28 14:21:55 2015 for NVIDIA(R) PsFoundation Reference by
![doxygen](doxygen.png)