mirror of
https://github.com/libretro/scummvm.git
synced 2025-05-13 09:36:21 +00:00
Rename BaseNodeFunc to BaseNodeType
svn-id: r23627
This commit is contained in:
parent
066aa14f97
commit
b3a66e817f
@ -118,14 +118,14 @@ uint nextTableSize(uint x);
|
|||||||
* triggered instead. Hence if you are not sure whether a key is contained in
|
* triggered instead. Hence if you are not sure whether a key is contained in
|
||||||
* the map, use contains() first to check for its presence.
|
* the map, use contains() first to check for its presence.
|
||||||
*/
|
*/
|
||||||
template <class Key, class Val, class HashFunc = Hash<Key>, class EqualFunc = EqualTo<Key>, class BaseNodeFunc = BaseNode<Key, Val> >
|
template <class Key, class Val, class HashFunc = Hash<Key>, class EqualFunc = EqualTo<Key>, class BaseNodeType = BaseNode<Key, Val> >
|
||||||
class HashMap {
|
class HashMap {
|
||||||
private:
|
private:
|
||||||
#if defined (_WIN32_WCE) || defined (_MSC_VER) || defined (__SYMBIAN32__) || defined (PALMOS_MODE) || defined (__MINT__)
|
#if defined (_WIN32_WCE) || defined (_MSC_VER) || defined (__SYMBIAN32__) || defined (PALMOS_MODE) || defined (__MINT__)
|
||||||
//FIXME evc4, msvc6,msvc7 & GCC 2.9x doesn't like it as private member
|
//FIXME evc4, msvc6,msvc7 & GCC 2.9x doesn't like it as private member
|
||||||
public:
|
public:
|
||||||
#endif
|
#endif
|
||||||
BaseNodeFunc **_arr; // hashtable of size arrsize.
|
BaseNodeType **_arr; // hashtable of size arrsize.
|
||||||
uint _arrsize, _nele;
|
uint _arrsize, _nele;
|
||||||
|
|
||||||
HashFunc _hash;
|
HashFunc _hash;
|
||||||
@ -140,16 +140,16 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
class const_iterator {
|
class const_iterator {
|
||||||
typedef const HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc> * hashmap_t;
|
typedef const HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType> * hashmap_t;
|
||||||
friend class HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>;
|
friend class HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>;
|
||||||
protected:
|
protected:
|
||||||
hashmap_t _hashmap;
|
hashmap_t _hashmap;
|
||||||
uint _idx;
|
uint _idx;
|
||||||
const_iterator(uint idx, hashmap_t hashmap) : _idx(idx), _hashmap(hashmap) {}
|
const_iterator(uint idx, hashmap_t hashmap) : _idx(idx), _hashmap(hashmap) {}
|
||||||
|
|
||||||
const BaseNodeFunc *deref() const {
|
const BaseNodeType *deref() const {
|
||||||
assert(_hashmap != 0);
|
assert(_hashmap != 0);
|
||||||
BaseNodeFunc *node = _hashmap->_arr[_idx];
|
BaseNodeType *node = _hashmap->_arr[_idx];
|
||||||
assert(node != 0);
|
assert(node != 0);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -157,8 +157,8 @@ public:
|
|||||||
public:
|
public:
|
||||||
const_iterator() : _idx(0), _hashmap(0) {}
|
const_iterator() : _idx(0), _hashmap(0) {}
|
||||||
|
|
||||||
const BaseNodeFunc &operator *() const { return *deref(); }
|
const BaseNodeType &operator *() const { return *deref(); }
|
||||||
const BaseNodeFunc *operator->() const { return deref(); }
|
const BaseNodeType *operator->() const { return deref(); }
|
||||||
bool operator ==(const const_iterator &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; }
|
bool operator ==(const const_iterator &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; }
|
||||||
bool operator !=(const const_iterator &iter) const { return !(*this == iter); }
|
bool operator !=(const const_iterator &iter) const { return !(*this == iter); }
|
||||||
const_iterator operator ++() {
|
const_iterator operator ++() {
|
||||||
@ -217,12 +217,12 @@ public:
|
|||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
// HashMap functions
|
// HashMap functions
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::HashMap() {
|
HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::HashMap() {
|
||||||
_arrsize = nextTableSize(0);
|
_arrsize = nextTableSize(0);
|
||||||
_arr = new BaseNodeFunc *[_arrsize];
|
_arr = new BaseNodeType *[_arrsize];
|
||||||
assert(_arr != NULL);
|
assert(_arr != NULL);
|
||||||
memset(_arr, 0, _arrsize * sizeof(BaseNodeFunc *));
|
memset(_arr, 0, _arrsize * sizeof(BaseNodeType *));
|
||||||
|
|
||||||
_nele = 0;
|
_nele = 0;
|
||||||
|
|
||||||
@ -232,8 +232,8 @@ HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::HashMap() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::~HashMap() {
|
HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::~HashMap() {
|
||||||
uint ctr;
|
uint ctr;
|
||||||
|
|
||||||
for (ctr = 0; ctr < _arrsize; ctr++)
|
for (ctr = 0; ctr < _arrsize; ctr++)
|
||||||
@ -243,8 +243,8 @@ HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::~HashMap() {
|
|||||||
delete[] _arr;
|
delete[] _arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::clear(bool shrinkArray) {
|
void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::clear(bool shrinkArray) {
|
||||||
for (uint ctr = 0; ctr < _arrsize; ctr++) {
|
for (uint ctr = 0; ctr < _arrsize; ctr++) {
|
||||||
if (_arr[ctr] != NULL) {
|
if (_arr[ctr] != NULL) {
|
||||||
delete _arr[ctr];
|
delete _arr[ctr];
|
||||||
@ -256,18 +256,18 @@ void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::clear(bool shrinkArra
|
|||||||
delete[] _arr;
|
delete[] _arr;
|
||||||
|
|
||||||
_arrsize = nextTableSize(0);
|
_arrsize = nextTableSize(0);
|
||||||
_arr = new BaseNodeFunc *[_arrsize];
|
_arr = new BaseNodeType *[_arrsize];
|
||||||
assert(_arr != NULL);
|
assert(_arr != NULL);
|
||||||
memset(_arr, 0, _arrsize * sizeof(BaseNodeFunc *));
|
memset(_arr, 0, _arrsize * sizeof(BaseNodeType *));
|
||||||
}
|
}
|
||||||
|
|
||||||
_nele = 0;
|
_nele = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::expand_array(uint newsize) {
|
void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::expand_array(uint newsize) {
|
||||||
assert(newsize > _arrsize);
|
assert(newsize > _arrsize);
|
||||||
BaseNodeFunc **old_arr;
|
BaseNodeType **old_arr;
|
||||||
uint old_arrsize, old_nele, ctr, dex;
|
uint old_arrsize, old_nele, ctr, dex;
|
||||||
|
|
||||||
old_nele = _nele;
|
old_nele = _nele;
|
||||||
@ -276,9 +276,9 @@ void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::expand_array(uint new
|
|||||||
|
|
||||||
// allocate a new array
|
// allocate a new array
|
||||||
_arrsize = newsize;
|
_arrsize = newsize;
|
||||||
_arr = new BaseNodeFunc *[_arrsize];
|
_arr = new BaseNodeType *[_arrsize];
|
||||||
assert(_arr != NULL);
|
assert(_arr != NULL);
|
||||||
memset(_arr, 0, _arrsize * sizeof(BaseNodeFunc *));
|
memset(_arr, 0, _arrsize * sizeof(BaseNodeType *));
|
||||||
|
|
||||||
_nele = 0;
|
_nele = 0;
|
||||||
|
|
||||||
@ -308,8 +308,8 @@ void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::expand_array(uint new
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
int HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::lookup(const Key &key) const {
|
int HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::lookup(const Key &key) const {
|
||||||
uint ctr = _hash(key) % _arrsize;
|
uint ctr = _hash(key) % _arrsize;
|
||||||
|
|
||||||
while (_arr[ctr] != NULL && !_equal(_arr[ctr]->_key, key)) {
|
while (_arr[ctr] != NULL && !_equal(_arr[ctr]->_key, key)) {
|
||||||
@ -330,18 +330,18 @@ int HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::lookup(const Key &key)
|
|||||||
return ctr;
|
return ctr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
bool HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::contains(const Key &key) const {
|
bool HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::contains(const Key &key) const {
|
||||||
uint ctr = lookup(key);
|
uint ctr = lookup(key);
|
||||||
return (_arr[ctr] != NULL);
|
return (_arr[ctr] != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::operator [](const Key &key) {
|
Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::operator [](const Key &key) {
|
||||||
uint ctr = lookup(key);
|
uint ctr = lookup(key);
|
||||||
|
|
||||||
if (_arr[ctr] == NULL) {
|
if (_arr[ctr] == NULL) {
|
||||||
_arr[ctr] = new BaseNodeFunc(key);
|
_arr[ctr] = new BaseNodeType(key);
|
||||||
_nele++;
|
_nele++;
|
||||||
|
|
||||||
// Keep the load factor below 75%.
|
// Keep the load factor below 75%.
|
||||||
@ -354,20 +354,20 @@ Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::operator [](const Key
|
|||||||
return _arr[ctr]->_value;
|
return _arr[ctr]->_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
const Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::operator [](const Key &key) const {
|
const Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::operator [](const Key &key) const {
|
||||||
return queryVal(key);
|
return queryVal(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
const Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::queryVal(const Key &key) const {
|
const Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::queryVal(const Key &key) const {
|
||||||
uint ctr = lookup(key);
|
uint ctr = lookup(key);
|
||||||
assert(_arr[ctr] != NULL);
|
assert(_arr[ctr] != NULL);
|
||||||
return _arr[ctr]->_value;
|
return _arr[ctr]->_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||||
size_t HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::erase(const Key &key) {
|
size_t HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::erase(const Key &key) {
|
||||||
// This is based on code in the Wikipedia article on Hash tables.
|
// This is based on code in the Wikipedia article on Hash tables.
|
||||||
uint i = lookup(key);
|
uint i = lookup(key);
|
||||||
if (_arr[i] == NULL)
|
if (_arr[i] == NULL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user