[Scummvm-cvs-logs] SF.net SVN: scummvm: [31305] scummvm/trunk/common/hashmap.h
tramboi at users.sourceforge.net
tramboi at users.sourceforge.net
Sun Mar 30 00:04:10 CET 2008
Revision: 31305
http://scummvm.svn.sourceforge.net/scummvm/?rev=31305&view=rev
Author: tramboi
Date: 2008-03-29 16:04:10 -0700 (Sat, 29 Mar 2008)
Log Message:
-----------
Centralized the way the hashmaps allocate and free nodes (in order to instrument and maybe use a pool allocator later)
Modified Paths:
--------------
scummvm/trunk/common/hashmap.h
Modified: scummvm/trunk/common/hashmap.h
===================================================================
--- scummvm/trunk/common/hashmap.h 2008-03-29 21:17:43 UTC (rev 31304)
+++ scummvm/trunk/common/hashmap.h 2008-03-29 23:04:10 UTC (rev 31305)
@@ -98,6 +98,16 @@
Node(const Key &key) : _key(key), _value() {}
};
+ Node* allocNode(const Key& key)
+ {
+ return new Node(key);
+ }
+
+ void freeNode(Node* node)
+ {
+ delete node;
+ }
+
Node **_arr; // hashtable of size arrsize.
uint _arrsize, _nele;
@@ -353,7 +363,7 @@
HashMap<Key, Val, HashFunc, EqualFunc>::~HashMap() {
for (uint ctr = 0; ctr < _arrsize; ++ctr)
if (_arr[ctr] != NULL)
- delete _arr[ctr];
+ freeNode(_arr[ctr]);
delete[] _arr;
}
@@ -376,7 +386,7 @@
_nele = 0;
for (uint ctr = 0; ctr < _arrsize; ++ctr) {
if (map._arr[ctr] != NULL) {
- _arr[ctr] = new Node(*map._arr[ctr]);
+ _arr[ctr] = allocNode(map._arr[ctr]->_key);
_nele++;
}
}
@@ -389,7 +399,7 @@
void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) {
for (uint ctr = 0; ctr < _arrsize; ++ctr) {
if (_arr[ctr] != NULL) {
- delete _arr[ctr];
+ freeNode(_arr[ctr]);
_arr[ctr] = NULL;
}
}
@@ -476,7 +486,7 @@
uint ctr = lookup(key);
if (_arr[ctr] == NULL) {
- _arr[ctr] = new Node(key);
+ _arr[ctr] = allocNode(key);
_nele++;
// Keep the load factor below 75%.
@@ -538,7 +548,7 @@
// If we remove a key, we must check all subsequent keys and possibly
// reinsert them.
uint j = i;
- delete _arr[i];
+ freeNode(_arr[i]);
_arr[i] = NULL;
while (true) {
// Look at the next table slot
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list