29 # pragma warning (push)
31 # pragma warning (disable : 4786)
100 template<
class Key,
class Value,
class HashFunc = HashTrait<Key>,
class EqualsFunc = EqualsTrait<Key> >
135 : entry(k, v), hashCode(h), next(n) {
140 : entry(k), hashCode(h), next(n) {
148 return new (node)
Node(k, v, h, n);
153 return new (node)
Node(k, hashCode, n);
175 while (node !=
NULL) {
202 return m_memoryManager->alloc(s);
206 return m_memoryManager->free(p);
218 m_bucket = (Node**)
alloc(
sizeof(Node*) * newSize);
219 alwaysAssertM(m_bucket !=
NULL,
"MemoryManager::alloc returned NULL. Out of memory.");
224 Node* node = oldBucket[b];
227 while (node !=
NULL) {
229 Node* nextNode = node->next;
232 size_t i = node->hashCode % newSize;
233 node->next = m_bucket[i];
246 this->m_numBuckets = newSize;
281 Node* node = m_bucket[b];
282 while (node !=
NULL) {
283 Node*
next = node->next;
320 if (s > m_numBuckets) {
365 Node* node = m_bucket[b];
366 while (node !=
NULL) {
371 if (count > deepest) {
386 Node* node = m_bucket[b];
392 return (
float)((double)
size() / num);
444 m_numBuckets(numBuckets),
447 if (m_numBuckets == 0) {
460 node = m_bucket[
index];
472 while (node ==
NULL) {
474 if (index >= m_numBuckets) {
480 node = m_bucket[
index];
489 return !(*
this == other);
493 if (other.
isDone || isDone) {
495 return (isDone == other.
isDone);
497 return (node == other.
node) && (index == other.
index);
538 return &(node->
entry);
543 return &(node->
entry);
563 return Iterator(m_numBuckets, m_bucket);
570 const Iterator
end()
const {
606 bool remove(
const Key& key, Key& removedKey,
Value& removedValue,
bool updateRemoved) {
607 if (m_numBuckets == 0) {
615 Node* n = m_bucket[b];
625 if ((code == n->hashCode) && EqualsFunc::equals(n->entry.key, key)) {
629 if (previous ==
NULL) {
630 m_bucket[b] = n->next;
632 previous->next = n->next;
636 removedKey = n->entry.key;
637 removedValue = n->entry.value;
661 return remove(key, removedKey, removedValue,
true);
668 bool remove(
const Key& key) {
671 return remove(key,
x, v,
false);
677 if (m_numBuckets == 0) {
684 Node* node = m_bucket[b];
686 while (node !=
NULL) {
687 if ((node->hashCode == code) && EqualsFunc::equals(node->entry.key, key)) {
688 return &(node->entry);
732 if (m_numBuckets == 0) {
739 Node* node = m_bucket[b];
741 while (node !=
NULL) {
742 if ((node->hashCode == code) && EqualsFunc::equals(node->entry.key, key)) {
744 return &(node->entry.value);
757 bool get(
const Key& key,
Value& val)
const {
775 if (m_numBuckets == 0) {
783 Node* n = m_bucket[b];
791 return m_bucket[b]->entry;
794 size_t bucketLength = 1;
799 bool allSameCode =
true;
803 allSameCode = allSameCode && (code == n->hashCode);
805 if ((code == n->hashCode) && EqualsFunc::equals(n->entry.key, key)) {
816 const int bucketsPerElement =
817 (m_size > 50000) ? 3 :
818 ((m_size > 10000) ? 5 :
819 ((m_size > 5000) ? 10 : 15));
821 const size_t maxBucketLength = 3;
824 if ((bucketLength > maxBucketLength) &&
826 (m_numBuckets < m_size * bucketsPerElement)) {
835 if (m_numBuckets > 1000000) {
837 }
else if (m_numBuckets > 100000) {
840 int newSize =
iMax((
int)(m_numBuckets * f) + 1, (
int)(m_size * f));
846 m_bucket[b] =
Node::create(key, code, m_bucket[b], m_memoryManager);
851 return m_bucket[b]->entry;
875 if (m_numBuckets == 0) {
882 Node* node = m_bucket[b];
884 while (node !=
NULL) {
885 if ((node->hashCode == code) && EqualsFunc::equals(node->entry.key, key)) {
916 Node* node = m_bucket[i];
917 while (node !=
NULL) {
918 keyArray.
append(node->entry.key);
928 Node* node = m_bucket[i];
929 while (node !=
NULL) {
930 valueArray.
append(node->entry.value);
941 Node* node = m_bucket[i];
942 while (node !=
NULL) {
943 delete node->entry.key;
944 node->entry.key =
NULL;
961 Node* node = m_bucket[i];
962 while (node !=
NULL) {
963 delete node->entry.value;
964 node->entry.value =
NULL;
970 template<
class H,
class E>
978 if ((v ==
NULL) || (*v != it->value)) {
990 template<
class H,
class E>
992 return ! (*
this == other);
1005 # pragma warning (pop)
static void destroy(Node *n, MemoryManager::Ref &mm)
Definition: Table.h:156
std::string __cdecl debugPrintf(const char *fmt...) G3D_CHECK_PRINTF_ARGS
Definition: debugAssert.cpp:355
const Value & value() const
Definition: Table.h:528
Value * getPointer(const Key &key) const
Definition: Table.h:731
Value & getCreate(const Key &key, bool &created)
Definition: Table.h:866
static void memset(void *dst, uint8 value, size_t numBytes)
Definition: System.cpp:695
size_t m_numBuckets
Definition: Table.h:430
bool operator==(const Entry &peer) const
Definition: Table.h:114
float debugGetAverageBucketSize() const
Definition: Table.h:382
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
Entry()
Definition: Table.h:111
void setSizeHint(size_t n)
Definition: Table.h:318
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
bool getRemove(const Key &key, Key &removedKey, Value &removedValue)
Definition: Table.h:660
size_t hashCode() const
Definition: Vector2unorm16.h:76
static Node * create(const Key &k, const Value &v, size_t h, Node *n, MemoryManager::Ref &mm)
Definition: Table.h:146
void free(void *p) const
Definition: Table.h:205
Entry * operator->() const
Definition: Table.h:536
size_t index
Definition: Table.h:423
int next(int i, int n)
Definition: RecastContour.cpp:469
void clear()
Definition: Table.h:578
size_t size() const
Definition: Table.h:589
Iterator(size_t numBuckets, Node **m_bucket)
Definition: Table.h:441
Dynamic 1D array tuned for performance.
Definition: Array.h:95
double debugGetLoad() const
Definition: Table.h:402
Iterator begin() const
Definition: Table.h:562
arena_t NULL
Definition: jemalloc_internal.h:624
size_t m_size
Definition: Table.h:184
size_t hashCode
Definition: Table.h:128
bool operator==(const Iterator &other) const
Definition: Table.h:492
Node ** m_bucket
Definition: Table.h:192
uint64_t uint64
Definition: g3dmath.h:170
bool operator==(const Table< Key, Value, H, E > &other) const
Definition: Table.h:971
shared_ptr< class MemoryManager > Ref
Definition: MemoryManager.h:31
void set(const Key &key, const Value &value)
Definition: Table.h:599
bool hasMore() const
Definition: Table.h:551
void checkIntegrity() const
Definition: Table.h:169
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
const Entry & operator*() const
Definition: Table.h:524
void deleteKeys()
Definition: Table.h:939
bool operator!=(const Iterator &other) const
Definition: Table.h:488
bool operator!=(const Entry &peer) const
Definition: Table.h:115
Node * node
Definition: Table.h:428
Entry
Definition: boss_headless_horseman.cpp:50
virtual ~Table()
Definition: Table.h:331
const bool DONT_SHRINK_UNDERLYING_ARRAY
Definition: Array.h:43
size_t debugGetDeepestBucketSize() const
Definition: Table.h:360
void getKeys(Array< Key > &keyArray) const
Definition: Table.h:913
#define debugAssert(exp)
Definition: debugAssert.h:160
Table()
Definition: Table.h:300
Key key
Definition: Table.h:109
void getValues(Array< Value > &valueArray) const
Definition: Table.h:925
Node(const Key &k, const Value &v, size_t h, Node *n)
Definition: Table.h:134
uint32_t previous(octet_iterator &it, octet_iterator pass_start)
Deprecated in versions that include "prior".
Definition: checked.h:179
Table< Key, Value, HashFunc, EqualsFunc > ThisType
Definition: Table.h:120
Entry(const Key &k)
Definition: Table.h:112
Entry & getCreateEntry(const Key &key, bool &created)
Definition: Table.h:772
void resize(size_t newSize)
Definition: Table.h:212
static Node * create(const Key &k, size_t hashCode, Node *n, MemoryManager::Ref &mm)
Definition: Table.h:151
const Key & key() const
Definition: Table.h:532
Value & getCreate(const Key &key)
Definition: Table.h:861
void freeMemory()
Definition: Table.h:277
Node ** m_bucket
Definition: Table.h:431
Definition: inftrees.h:24
void deleteValues()
Definition: Table.h:959
const Iterator end() const
Definition: Table.h:570
Iterator operator++(int)
Definition: Table.h:518
void * alloc(size_t s) const
Definition: Table.h:201
Value value
Definition: Table.h:110
Node * next
Definition: Table.h:129
Array< Key > getKeys() const
Definition: Table.h:907
const Key * getKeyPointer(const Key &key) const
Definition: Table.h:701
Entry entry
Definition: Table.h:127
bool isDone
Definition: Table.h:432
Node(const Key &k, size_t h, Node *n)
Definition: Table.h:139
void copyFrom(const ThisType &h)
Definition: Table.h:252
void debugPrintStatus()
Definition: Table.h:995
const FieldDescriptor value
Definition: descriptor.h:1522
Table & operator=(const ThisType &h)
Definition: Table.h:346
void clearAndSetMemoryManager(const MemoryManager::Ref &m)
Definition: Table.h:309
Entry & getCreateEntry(const Key &key)
Definition: Table.h:854
G3D::int16 x
Definition: Vector2int16.h:37
int iMax(int x, int y)
Definition: g3dmath.h:759
Iterator & operator++()
Definition: Table.h:504
void findNext()
Definition: Table.h:471
void append(const T &value)
Definition: Array.h:583
size_t debugGetNumBuckets() const
Definition: Table.h:409
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165
Entry * getEntryPointer(const Key &key) const
Definition: Table.h:676
Entry(const Key &k, const Value &v)
Definition: Table.h:113
bool operator!=(const Table< Key, Value, H, E > &other) const
Definition: Table.h:991
bool isValidHeapPointer(const void *x)
Definition: debug.h:38
bool containsKey(const Key &key) const
Definition: Table.h:874
Iterator()
Definition: Table.h:437
bool isValid() const
Definition: Table.h:546
Table(const ThisType &h)
Definition: Table.h:336
Value & operator[](const Key &key) const
Definition: Table.h:898
Node * clone(MemoryManager::Ref &mm)
Definition: Table.h:164
MemoryManager::Ref m_memoryManager
Definition: Table.h:199
size_t m_numBuckets
Definition: Table.h:197