1.1 --- a/src/Hash.cpp Sun Sep 20 15:14:12 2009 -0700
1.2 +++ b/src/Hash.cpp Thu Sep 24 10:28:50 2009 -0700
1.3 @@ -20,7 +20,7 @@
1.4 _value(value)
1.5 { }
1.6
1.7 - Key key() const {return _key;}
1.8 + const Key& key() const {return _key;}
1.9 HashCode hash() const {return _key.hash;}
1.10 Hash::Value value() const {return _key.bytes ?_value :NULL;}
1.11 void setValue (Hash::Value value) {_value = value;}
1.12 @@ -50,8 +50,7 @@
1.13 }
1.14
1.15 Hash::IndexEntry& Hash::_find (Key key) const {
1.16 - Key k = Key(key);
1.17 - IndexEntry newEntry(k);
1.18 + IndexEntry newEntry(key);
1.19 int index = newEntry.hash() % _tableSize;
1.20 IndexEntry *found = &_table[index];
1.21 int probe = 0;
1.22 @@ -78,7 +77,7 @@
1.23 }
1.24
1.25 void Hash::put(Key key, Hash::Value value) {
1.26 - IndexEntry newEntry = IndexEntry(Key(key),value);
1.27 + IndexEntry newEntry = IndexEntry(key,value);
1.28 IndexEntry &found = _findForPut(newEntry);
1.29 if (found.hasValue())
1.30 found.setValue(value);
1.31 @@ -90,15 +89,16 @@
1.32 }
1.33 }
1.34
1.35 - bool Hash::remove(Key key) {
1.36 + Hash::Value Hash::remove(Key key) {
1.37 IndexEntry &entry = _find(key);
1.38 - if (!entry.value())
1.39 - return false;
1.40 + Value formerValue = entry.value();
1.41 + if (!formerValue)
1.42 + return NULL;
1.43 entry.markDeleted();
1.44 _count--;
1.45 if (_count/(float)_tableSize < Dictionary::kMinLoadFactor)
1.46 _resize(_tableSize/2);
1.47 - return true;
1.48 + return formerValue;
1.49 }
1.50
1.51 void Hash::removeAll() {
1.52 @@ -109,7 +109,7 @@
1.53 void Hash::dump() const {
1.54 for (int index=0; index<_tableSize; index++)
1.55 if (_table[index].hasValue()) {
1.56 - Blob key = _table[index].key();
1.57 + const Key &key = _table[index].key();
1.58 printf("%3i: %*s -> %p\n",
1.59 index, (int)key.length,(const char*)key.bytes, _table[index].value());
1.60 }