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:
Mark Olesen
2009-02-25 18:58:48 +01:00
parent 9c8432a002
commit e562aecb73
8 changed files with 94 additions and 48 deletions

View File

@ -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);
}
}
}