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
|
||||
* 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 {
|
||||
private:
|
||||
#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
|
||||
public:
|
||||
#endif
|
||||
BaseNodeFunc **_arr; // hashtable of size arrsize.
|
||||
BaseNodeType **_arr; // hashtable of size arrsize.
|
||||
uint _arrsize, _nele;
|
||||
|
||||
HashFunc _hash;
|
||||
@ -140,16 +140,16 @@ public:
|
||||
|
||||
public:
|
||||
class const_iterator {
|
||||
typedef const HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc> * hashmap_t;
|
||||
friend class HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>;
|
||||
typedef const HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType> * hashmap_t;
|
||||
friend class HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>;
|
||||
protected:
|
||||
hashmap_t _hashmap;
|
||||
uint _idx;
|
||||
const_iterator(uint idx, hashmap_t hashmap) : _idx(idx), _hashmap(hashmap) {}
|
||||
|
||||
const BaseNodeFunc *deref() const {
|
||||
const BaseNodeType *deref() const {
|
||||
assert(_hashmap != 0);
|
||||
BaseNodeFunc *node = _hashmap->_arr[_idx];
|
||||
BaseNodeType *node = _hashmap->_arr[_idx];
|
||||
assert(node != 0);
|
||||
return node;
|
||||
}
|
||||
@ -157,8 +157,8 @@ public:
|
||||
public:
|
||||
const_iterator() : _idx(0), _hashmap(0) {}
|
||||
|
||||
const BaseNodeFunc &operator *() const { return *deref(); }
|
||||
const BaseNodeFunc *operator->() const { return deref(); }
|
||||
const BaseNodeType &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 !(*this == iter); }
|
||||
const_iterator operator ++() {
|
||||
@ -217,12 +217,12 @@ public:
|
||||
//-------------------------------------------------------
|
||||
// HashMap functions
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::HashMap() {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::HashMap() {
|
||||
_arrsize = nextTableSize(0);
|
||||
_arr = new BaseNodeFunc *[_arrsize];
|
||||
_arr = new BaseNodeType *[_arrsize];
|
||||
assert(_arr != NULL);
|
||||
memset(_arr, 0, _arrsize * sizeof(BaseNodeFunc *));
|
||||
memset(_arr, 0, _arrsize * sizeof(BaseNodeType *));
|
||||
|
||||
_nele = 0;
|
||||
|
||||
@ -232,8 +232,8 @@ HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::HashMap() {
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::~HashMap() {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::~HashMap() {
|
||||
uint ctr;
|
||||
|
||||
for (ctr = 0; ctr < _arrsize; ctr++)
|
||||
@ -243,8 +243,8 @@ HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::~HashMap() {
|
||||
delete[] _arr;
|
||||
}
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::clear(bool shrinkArray) {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::clear(bool shrinkArray) {
|
||||
for (uint ctr = 0; ctr < _arrsize; ctr++) {
|
||||
if (_arr[ctr] != NULL) {
|
||||
delete _arr[ctr];
|
||||
@ -256,18 +256,18 @@ void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::clear(bool shrinkArra
|
||||
delete[] _arr;
|
||||
|
||||
_arrsize = nextTableSize(0);
|
||||
_arr = new BaseNodeFunc *[_arrsize];
|
||||
_arr = new BaseNodeType *[_arrsize];
|
||||
assert(_arr != NULL);
|
||||
memset(_arr, 0, _arrsize * sizeof(BaseNodeFunc *));
|
||||
memset(_arr, 0, _arrsize * sizeof(BaseNodeType *));
|
||||
}
|
||||
|
||||
_nele = 0;
|
||||
}
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::expand_array(uint newsize) {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::expand_array(uint newsize) {
|
||||
assert(newsize > _arrsize);
|
||||
BaseNodeFunc **old_arr;
|
||||
BaseNodeType **old_arr;
|
||||
uint old_arrsize, old_nele, ctr, dex;
|
||||
|
||||
old_nele = _nele;
|
||||
@ -276,9 +276,9 @@ void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::expand_array(uint new
|
||||
|
||||
// allocate a new array
|
||||
_arrsize = newsize;
|
||||
_arr = new BaseNodeFunc *[_arrsize];
|
||||
_arr = new BaseNodeType *[_arrsize];
|
||||
assert(_arr != NULL);
|
||||
memset(_arr, 0, _arrsize * sizeof(BaseNodeFunc *));
|
||||
memset(_arr, 0, _arrsize * sizeof(BaseNodeType *));
|
||||
|
||||
_nele = 0;
|
||||
|
||||
@ -308,8 +308,8 @@ void HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::expand_array(uint new
|
||||
return;
|
||||
}
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
int HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::lookup(const Key &key) const {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
int HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::lookup(const Key &key) const {
|
||||
uint ctr = _hash(key) % _arrsize;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
bool HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::contains(const Key &key) const {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
bool HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::contains(const Key &key) const {
|
||||
uint ctr = lookup(key);
|
||||
return (_arr[ctr] != NULL);
|
||||
}
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::operator [](const Key &key) {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::operator [](const Key &key) {
|
||||
uint ctr = lookup(key);
|
||||
|
||||
if (_arr[ctr] == NULL) {
|
||||
_arr[ctr] = new BaseNodeFunc(key);
|
||||
_arr[ctr] = new BaseNodeType(key);
|
||||
_nele++;
|
||||
|
||||
// Keep the load factor below 75%.
|
||||
@ -354,20 +354,20 @@ Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::operator [](const Key
|
||||
return _arr[ctr]->_value;
|
||||
}
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
const Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::operator [](const Key &key) const {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
const Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::operator [](const Key &key) const {
|
||||
return queryVal(key);
|
||||
}
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
const Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::queryVal(const Key &key) const {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
const Val &HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::queryVal(const Key &key) const {
|
||||
uint ctr = lookup(key);
|
||||
assert(_arr[ctr] != NULL);
|
||||
return _arr[ctr]->_value;
|
||||
}
|
||||
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeFunc>
|
||||
size_t HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeFunc>::erase(const Key &key) {
|
||||
template <class Key, class Val, class HashFunc, class EqualFunc, class BaseNodeType>
|
||||
size_t HashMap<Key, Val, HashFunc, EqualFunc, BaseNodeType>::erase(const Key &key) {
|
||||
// This is based on code in the Wikipedia article on Hash tables.
|
||||
uint i = lookup(key);
|
||||
if (_arr[i] == NULL)
|
||||
|
Loading…
x
Reference in New Issue
Block a user