diff --git a/Lib/Map.hpp b/Lib/Map.hpp index 77e1f2d5be..7f4e05a059 100644 --- a/Lib/Map.hpp +++ b/Lib/Map.hpp @@ -46,7 +46,7 @@ namespace Lib { * anything that can be hashed to an unsigned integer * and compared using == * @param Val values, can be anything - * @param Hash class containig the hash function for keys + * @param Hash class containing the "hash" and "equals" functions for keys */ template class Map @@ -124,13 +124,10 @@ class Map code = 1; } Entry* entry; - for (entry = firstEntryForCode(code); - entry->occupied(); - entry = nextEntry(entry)) { - if (entry->code == code && - entry->key == key) { - found = entry->value; - return true; + for (entry = firstEntryForCode(code); entry->occupied(); entry = nextEntry(entry)) { + if (entry->code == code && Hash::equals(entry->key,key)) { + found = entry->value; + return true; } } @@ -151,9 +148,7 @@ class Map code = 1; } Entry* entry; - for (entry = firstEntryForCode(code); - entry->key != key; - entry = nextEntry(entry)) { + for (entry = firstEntryForCode(code); !Hash::equals(entry->key,key); entry = nextEntry(entry)) { ASS(entry->occupied()); } ASS(entry->occupied()); @@ -216,12 +211,9 @@ class Map CALL("Map::insert/2"); Entry* entry; - for (entry = firstEntryForCode(code); - entry->occupied(); - entry = nextEntry(entry)) { - if (entry->code == code && - entry->key == key) { - return entry->value; + for (entry = firstEntryForCode(code); entry->occupied(); entry = nextEntry(entry)) { + if (entry->code == code && Hash::equals(entry->key,key)) { + return entry->value; } } // entry is not occupied @@ -252,11 +244,8 @@ class Map code = 1; } Entry* entry; - for (entry = firstEntryForCode(code); - entry->occupied(); - entry = nextEntry(entry)) { - if (entry->code == code && - entry->key == key) { + for (entry = firstEntryForCode(code); entry->occupied(); entry = nextEntry(entry)) { + if (entry->code == code && Hash::equals(entry->key, key)) { entry->value = val; return true; } @@ -288,13 +277,10 @@ class Map code = 1; } Entry* entry; - for (entry = firstEntryForCode(code); - entry->occupied(); - entry = nextEntry(entry)) { - if (entry->code == code && - entry->key == key) { - entry->value = val; - return; + for (entry = firstEntryForCode(code); entry->occupied(); entry = nextEntry(entry)) { + if (entry->code == code && Hash::equals(entry->key, key)) { + entry->value = val; + return; } } #if VDEBUG @@ -321,13 +307,10 @@ class Map code = 1; } Entry* entry; - for (entry = firstEntryForCode(code); - entry->occupied(); - entry = nextEntry(entry)) { - if (entry->code == code && - Lib::DefaultEq::equals(entry->key, key)) { - pval = &entry->value; - return false; + for (entry = firstEntryForCode(code); entry->occupied(); entry = nextEntry(entry)) { + if (entry->code == code && Hash::equals(entry->key, key)) { + pval = &entry->value; + return false; } } // entry is not occupied @@ -352,7 +335,7 @@ class Map for (int i = _capacity-1;i >= 0;i--) { Entry& e = _entries[i]; if (e.occupied()) { - delete e.value; + delete e.value; } } } // deleteAll @@ -376,7 +359,7 @@ class Map for (int i = _capacity-1;i >= 0;i--) { Entry& e = _entries[i]; if (e.occupied()) { - e.value->destroy(); + e.value->destroy(); } } } // destroyAll @@ -421,7 +404,7 @@ class Map while (remaining != 0) { // find first occupied entry while (! current->occupied()) { - current ++; + current ++; } // now current is occupied insert(current->key,current->value,current->code); @@ -443,8 +426,7 @@ class Map public: /** Create a new iterator */ inline Iterator(const Map& map) - : _next(map._entries), - _last(map._afterLast) + : _next(map._entries), _last(map._afterLast) { } // Map::Iterator @@ -455,10 +437,10 @@ class Map bool hasNext() { while (_next != _last) { - if (_next->occupied()) { - return true; - } - _next++; + if (_next->occupied()) { + return true; + } + _next++; } return false; }