Fix HashTable/HashMap bugs, and add a clear() method.
Fix HashTable/HashMap bugs, and add a clear() method.
1.1 --- a/include/am-hashmap.h Sat Aug 24 01:31:41 2013 -0700
1.2 +++ b/include/am-hashmap.h Sat Aug 24 02:36:11 2013 -0700
1.3 @@ -131,6 +131,10 @@
1.4 return table_.add(i);
1.5 }
1.6
1.7 + void clear() {
1.8 + table_.clear();
1.9 + }
1.10 +
1.11 size_t estimateMemoryUse() const {
1.12 return table_.estimateMemoryUse();
1.13 }
2.1 --- a/include/am-hashtable.h Sat Aug 24 01:31:41 2013 -0700
2.2 +++ b/include/am-hashtable.h Sat Aug 24 02:36:11 2013 -0700
2.3 @@ -60,6 +60,10 @@
2.4 destruct();
2.5 hash_ = kRemovedHash;
2.6 }
2.7 + void setFree() {
2.8 + destruct();
2.9 + hash_ = kFreeHash;
2.10 + }
2.11 void initialize() {
2.12 hash_ = kFreeHash;
2.13 }
2.14 @@ -432,6 +436,14 @@
2.15 return true;
2.16 }
2.17
2.18 + void clear() {
2.19 + for (size_t i = 0; i < capacity_; i++) {
2.20 + table_[i].setFree();
2.21 + }
2.22 + ndeleted_ = 0;
2.23 + nelements_ = 0;
2.24 + }
2.25 +
2.26 size_t estimateMemoryUse() const {
2.27 return sizeof(Entry) * capacity_;
2.28 }