HASH: 计算哈希地址时 % 改为 & 运算

实测效率几乎没有影响
This commit is contained in:
CalciteM Team 2019-07-14 19:46:04 +08:00
parent 86b9443c2f
commit 08f50641df
2 changed files with 5 additions and 4 deletions

View File

@ -42,7 +42,7 @@ namespace CTSL //Concurrent Thread Safe Library
//If key is not found, function returns false.
bool find(const K &key, V &value) const
{
size_t hashValue = hashFn(key) % hashSize ;
size_t hashValue = hashFn(key) & (hashSize - 1) ;
return hashTable[hashValue].find(key, value);
}
@ -50,14 +50,14 @@ namespace CTSL //Concurrent Thread Safe Library
//If key already exists, update the value, else insert a new node in the bucket with the <key, value> pair.
void insert(const K &key, const V &value)
{
size_t hashValue = hashFn(key) % hashSize ;
size_t hashValue = hashFn(key) & (hashSize - 1);
hashTable[hashValue].insert(key, value);
}
//Function to remove an entry from the bucket, if found
void erase(const K &key)
{
size_t hashValue = hashFn(key) % hashSize ;
size_t hashValue = hashFn(key) & (hashSize - 1);
hashTable[hashValue].erase(key);
}

View File

@ -18,7 +18,8 @@
using namespace CTSL;
#ifdef HASH_MAP_ENABLE
HashMap<uint64_t, NineChessAi_ab::HashValue> hashmap(1024 * 1024 * 16);
static constexpr int hashsize = 0x1000000; // 16M
HashMap<uint64_t, NineChessAi_ab::HashValue> hashmap(hashsize);
#endif
NineChessAi_ab::NineChessAi_ab() :