bool Remove(const K& key) { if (_size == 0) { cout<<"HashTable Is Empty"<<endl; return false; } size_t pos = HashFunc1(key); while (_states[pos] != EMPTY) { if (_states[pos] != DELETE && _tables[pos] == key) { --_size; _states[pos] = DELETE; return true; } ++pos; if (pos == _capacity) { pos = 0; } } return false; }
int Find(const K& key) { if (_size == 0) { cout<<"HashTable Is Empty"<<endl; return false; } size_t pos = HashFunc1(key); while (_states[pos] != EMPTY) { if (_tables[pos] == key && _states[pos] == EXIST) { return pos; } ++pos; if (pos == _capacity) { pos = 0; } } return -1; }
bool Insert(const K& key) { if ((float)_size/(float)_capacity > 0.8) { //_CheckCapacity(); } if (_size == _capacity) { cout<<"HashTable Is Full"<<endl; return false; } size_t pos = HashFunc1(key); int i = 1; while (_states[pos] == EXIST) { if (_tables[pos] == key) { return false; } pos = HashFunc2(pos, i++); } _tables[pos] = key; _states[pos] = EXIST; ++_size; return true; }
void Set(const K& key) { size_t index1 = HashFunc1()(key); size_t index2 = HashFunc2()(key); size_t index3 = HashFunc3()(key); size_t index4 = HashFunc4()(key); size_t index5 = HashFunc5()(key); cout<<index1<<" "<<index2<<" "<<index3<<" "<<index4<<" "<<index5<<endl; _bitSet.Set(index1%_capacity); _bitSet.Set(index2%_capacity); _bitSet.Set(index3%_capacity); _bitSet.Set(index4%_capacity); _bitSet.Set(index5%_capacity); }
bool IsIn(const K& key) { size_t index1 = HashFunc1()(key); if (!_bitSet.Test(index1%_capacity)) return false; size_t index2 = HashFunc2()(key); if (!_bitSet.Test(index2%_capacity)) return false; size_t index3 = HashFunc3()(key); if (!_bitSet.Test(index3%_capacity)) return false; size_t index4 = HashFunc4()(key); if (!_bitSet.Test(index4%_capacity)) return false; size_t index5 = HashFunc5()(key); if (!_bitSet.Test(index5%_capacity)) return false; return true; }