mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
HashTable performance: find(), found() check nElmts_ instead of tableSize_
- much better performance on empty tables (4-6x speedup), neutral performance change on filled tables. Since tableSize_ is non-zero when nElmts_ is, there is no modulus zero problem.
This commit is contained in:
@ -101,14 +101,17 @@ Foam::StaticHashTable<T, Key, Hash>::~StaticHashTable()
|
||||
template<class T, class Key, class Hash>
|
||||
bool Foam::StaticHashTable<T, Key, Hash>::found(const Key& key) const
|
||||
{
|
||||
label hashIdx = Hash()(key, keys_.size());
|
||||
const List<Key>& localKeys = keys_[hashIdx];
|
||||
|
||||
forAll(localKeys, elemIdx)
|
||||
if (nElmts_)
|
||||
{
|
||||
if (key == localKeys[elemIdx])
|
||||
label hashIdx = Hash()(key, keys_.size());
|
||||
const List<Key>& localKeys = keys_[hashIdx];
|
||||
|
||||
forAll(localKeys, elemIdx)
|
||||
{
|
||||
return true;
|
||||
if (key == localKeys[elemIdx])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,14 +134,17 @@ Foam::StaticHashTable<T, Key, Hash>::find
|
||||
const Key& key
|
||||
)
|
||||
{
|
||||
label hashIdx = Hash()(key, keys_.size());
|
||||
const List<Key>& localKeys = keys_[hashIdx];
|
||||
|
||||
forAll(localKeys, elemIdx)
|
||||
if (nElmts_)
|
||||
{
|
||||
if (key == localKeys[elemIdx])
|
||||
label hashIdx = Hash()(key, keys_.size());
|
||||
const List<Key>& localKeys = keys_[hashIdx];
|
||||
|
||||
forAll(localKeys, elemIdx)
|
||||
{
|
||||
return iterator(*this, hashIdx, elemIdx);
|
||||
if (key == localKeys[elemIdx])
|
||||
{
|
||||
return iterator(*this, hashIdx, elemIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user