HashTable minor/cosmetic changes

This commit is contained in:
Mark Olesen
2009-03-04 12:15:01 +01:00
parent 17548296be
commit 9b8de83ab4
5 changed files with 52 additions and 55 deletions

View File

@ -290,7 +290,7 @@ public:
// Private data // Private data
//- Reference to the HashTable this is an iterator for //- Reference to the HashTable this is an iterator for
HashTable<T, Key, Hash>& curHashTable_; HashTable<T, Key, Hash>& hashTable_;
//- Current element //- Current element
hashedEntry* elmtPtr_; hashedEntry* elmtPtr_;
@ -298,7 +298,6 @@ public:
//- Current hash index //- Current hash index
label hashIndex_; label hashIndex_;
public: public:
// Constructors // Constructors
@ -311,7 +310,6 @@ public:
label hashIndex label hashIndex
); );
// Member operators // Member operators
inline void operator=(const iterator&); inline void operator=(const iterator&);
@ -328,7 +326,7 @@ public:
inline iterator& operator++(); inline iterator& operator++();
inline iterator operator++(int); inline iterator operator++(int);
inline const Key& key(); inline const Key& key() const;
}; };
@ -349,7 +347,7 @@ public:
// Private data // Private data
//- Reference to the HashTable this is an iterator for //- Reference to the HashTable this is an iterator for
const HashTable<T, Key, Hash>& curHashTable_; const HashTable<T, Key, Hash>& hashTable_;
//- Current element //- Current element
const hashedEntry* elmtPtr_; const hashedEntry* elmtPtr_;
@ -390,7 +388,7 @@ public:
inline const_iterator& operator++(); inline const_iterator& operator++();
inline const_iterator operator++(int); inline const_iterator operator++(int);
inline const Key& key(); inline const Key& key() const;
}; };

View File

@ -157,12 +157,12 @@ inline T& Foam::HashTable<T, Key, Hash>::operator()(const Key& key)
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::iterator::iterator inline Foam::HashTable<T, Key, Hash>::iterator::iterator
( (
HashTable<T, Key, Hash>& curHashTable, HashTable<T, Key, Hash>& hashTbl,
hashedEntry* elmt, hashedEntry* elmt,
label hashIndex label hashIndex
) )
: :
curHashTable_(curHashTable), hashTable_(hashTbl),
elmtPtr_(elmt), elmtPtr_(elmt),
hashIndex_(hashIndex) hashIndex_(hashIndex)
{} {}
@ -252,12 +252,12 @@ Foam::HashTable<T, Key, Hash>::iterator::operator++()
// Step to the next table entry // Step to the next table entry
while while
( (
++hashIndex_ < curHashTable_.tableSize_ ++hashIndex_ < hashTable_.tableSize_
&& !(elmtPtr_ = curHashTable_.table_[hashIndex_]) && !(elmtPtr_ = hashTable_.table_[hashIndex_])
) )
{} {}
if (hashIndex_ == curHashTable_.tableSize_) if (hashIndex_ == hashTable_.tableSize_)
{ {
// make end iterator // make end iterator
elmtPtr_ = 0; elmtPtr_ = 0;
@ -282,7 +282,7 @@ Foam::HashTable<T, Key, Hash>::iterator::operator++
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
inline inline
const Key& Foam::HashTable<T, Key, Hash>::iterator::key() const Key& Foam::HashTable<T, Key, Hash>::iterator::key() const
{ {
return elmtPtr_->key_; return elmtPtr_->key_;
} }
@ -335,12 +335,12 @@ Foam::HashTable<T, Key, Hash>::end()
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
( (
const HashTable<T, Key, Hash>& curHashTable, const HashTable<T, Key, Hash>& hashTbl,
const hashedEntry* elmt, const hashedEntry* elmt,
label hashIndex label hashIndex
) )
: :
curHashTable_(curHashTable), hashTable_(hashTbl),
elmtPtr_(elmt), elmtPtr_(elmt),
hashIndex_(hashIndex) hashIndex_(hashIndex)
{} {}
@ -352,7 +352,7 @@ inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
const iterator& iter const iterator& iter
) )
: :
curHashTable_(iter.curHashTable_), hashTable_(iter.hashTable_),
elmtPtr_(iter.elmtPtr_), elmtPtr_(iter.elmtPtr_),
hashIndex_(iter.hashIndex_) hashIndex_(iter.hashIndex_)
{} {}
@ -431,14 +431,14 @@ Foam::HashTable<T, Key, Hash>::const_iterator::operator++()
if if
( (
!(elmtPtr_ = elmtPtr_->next_) !(elmtPtr_ = elmtPtr_->next_)
&& ++hashIndex_ < curHashTable_.tableSize_ && ++hashIndex_ < hashTable_.tableSize_
&& !(elmtPtr_ = curHashTable_.table_[hashIndex_]) && !(elmtPtr_ = hashTable_.table_[hashIndex_])
) )
{ {
while while
( (
++hashIndex_ < curHashTable_.tableSize_ ++hashIndex_ < hashTable_.tableSize_
&& !(elmtPtr_ = curHashTable_.table_[hashIndex_]) && !(elmtPtr_ = hashTable_.table_[hashIndex_])
) )
{} {}
} }
@ -462,7 +462,7 @@ Foam::HashTable<T, Key, Hash>::const_iterator::operator++
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
inline inline
const Key& Foam::HashTable<T, Key, Hash>::const_iterator::key() const Key& Foam::HashTable<T, Key, Hash>::const_iterator::key() const
{ {
return elmtPtr_->key_; return elmtPtr_->key_;
} }

View File

@ -304,7 +304,7 @@ bool Foam::StaticHashTable<T, Key, Hash>::erase(const iterator& cit)
List<T>& localObjects = objects_[cit.hashIndex_]; List<T>& localObjects = objects_[cit.hashIndex_];
// Copy down // Copy down
for (label i = cit.elementIndex_+1; i < localKeys.size(); i++) for (label i = cit.elemIndex_+1; i < localKeys.size(); i++)
{ {
localKeys[i-1] = localKeys[i]; localKeys[i-1] = localKeys[i];
localObjects[i-1] = localObjects[i]; localObjects[i-1] = localObjects[i];
@ -315,8 +315,8 @@ bool Foam::StaticHashTable<T, Key, Hash>::erase(const iterator& cit)
// adjust iterator after erase // adjust iterator after erase
iterator& it = const_cast<iterator&>(cit); iterator& it = const_cast<iterator&>(cit);
it.elementIndex_--; it.elemIndex_--;
if (it.elementIndex_ < 0) if (it.elemIndex_ < 0)
{ {
// No previous element in the local list // No previous element in the local list
@ -327,7 +327,7 @@ bool Foam::StaticHashTable<T, Key, Hash>::erase(const iterator& cit)
if (it.hashIndex_ >= 0) if (it.hashIndex_ >= 0)
{ {
// The last element in the local list // The last element in the local list
it.elementIndex_ = objects_[it.hashIndex_].size() - 1; it.elemIndex_ = objects_[it.hashIndex_].size() - 1;
} }
else else
{ {
@ -335,7 +335,7 @@ bool Foam::StaticHashTable<T, Key, Hash>::erase(const iterator& cit)
// - not end() // - not end()
// - handled by operator++ // - handled by operator++
it.hashIndex_ = -1; it.hashIndex_ = -1;
it.elementIndex_ = 0; it.elemIndex_ = 0;
} }
} }

View File

@ -32,7 +32,6 @@ Note
Uses straight lists as underlying type. Uses straight lists as underlying type.
Is slower to insert than the standard HashTable, but should be more Is slower to insert than the standard HashTable, but should be more
memory efficient and faster to access. memory efficient and faster to access.
Explicitly does not have default size.
SourceFiles SourceFiles
StaticHashTableI.H StaticHashTableI.H
@ -284,13 +283,13 @@ public:
// Private data // Private data
//- Reference to the StaticHashTable this is an iterator for //- Reference to the StaticHashTable this is an iterator for
TableRef curHashTable_; TableRef hashTable_;
//- Current hash index //- Current hash index
label hashIndex_; label hashIndex_;
//- Index of current element at hashIndex //- Index of current element at hashIndex
label elementIndex_; label elemIndex_;
public: public:
@ -299,9 +298,9 @@ public:
//- Construct from hash table, hash index and element index //- Construct from hash table, hash index and element index
inline Iterator inline Iterator
( (
TableRef curHashTable, TableRef,
label hashIndex_, label hashIndex_,
label elementIndex_ label elemIndex_
); );
//- Construct from the non-const iterator //- Construct from the non-const iterator
@ -310,13 +309,13 @@ public:
// Member operators // Member operators
inline void operator=(const iterator& iter); inline void operator=(const iterator&);
inline bool operator==(const iterator& iter) const; inline bool operator==(const iterator&) const;
inline bool operator==(const const_iterator& iter) const; inline bool operator==(const const_iterator&) const;
inline bool operator!=(const iterator& iter) const; inline bool operator!=(const iterator&) const;
inline bool operator!=(const const_iterator& iter) const; inline bool operator!=(const const_iterator&) const;
inline TRef operator*(); inline TRef operator*();
inline TRef operator()(); inline TRef operator()();
@ -324,7 +323,7 @@ public:
inline Iterator& operator++(); inline Iterator& operator++();
inline Iterator operator++(int); inline Iterator operator++(int);
inline const Key& key(); inline const Key& key() const;
}; };

View File

@ -150,14 +150,14 @@ template<class T, class Key, class Hash>
template<class TRef, class TableRef> template<class TRef, class TableRef>
inline Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::Iterator inline Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::Iterator
( (
TableRef curHashTable, TableRef hashTbl,
label hashIndex, label hashIndex,
label elementIndex label elemIndex
) )
: :
curHashTable_(curHashTable), hashTable_(hashTbl),
hashIndex_(hashIndex), hashIndex_(hashIndex),
elementIndex_(elementIndex) elemIndex_(elemIndex)
{} {}
@ -168,9 +168,9 @@ inline Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::Iterator
const iterator& iter const iterator& iter
) )
: :
curHashTable_(iter.curHashTable_), hashTable_(iter.hashTable_),
hashIndex_(iter.hashIndex_), hashIndex_(iter.hashIndex_),
elementIndex_(iter.elementIndex_) elemIndex_(iter.elemIndex_)
{} {}
@ -183,7 +183,7 @@ Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator=
) )
{ {
this->hashIndex_ = iter.hashIndex_; this->hashIndex_ = iter.hashIndex_;
this->elementIndex_ = iter.elementIndex_; this->elemIndex_ = iter.elemIndex_;
} }
@ -195,7 +195,7 @@ Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator==
const iterator& iter const iterator& iter
) const ) const
{ {
return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_; return hashIndex_ == iter.hashIndex_ && elemIndex_ == iter.elemIndex_;
} }
@ -207,7 +207,7 @@ Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator==
const const_iterator& iter const const_iterator& iter
) const ) const
{ {
return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_; return hashIndex_ == iter.hashIndex_ && elemIndex_ == iter.elemIndex_;
} }
@ -240,7 +240,7 @@ template<class TRef, class TableRef>
inline TRef inline TRef
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator*() Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator*()
{ {
return curHashTable_.objects_[hashIndex_][elementIndex_]; return hashTable_.objects_[hashIndex_][elemIndex_];
} }
@ -271,29 +271,29 @@ Foam::StaticHashTable<T, Key, Hash>::Iterator
if (hashIndex_ >= 0) if (hashIndex_ >= 0)
{ {
// Try the next element on the local list // Try the next element on the local list
elementIndex_++; elemIndex_++;
if (elementIndex_ < curHashTable_.objects_[hashIndex_].size()) if (elemIndex_ < hashTable_.objects_[hashIndex_].size())
{ {
return *this; return *this;
} }
} }
// Step to the next table entry // Step to the next table entry
elementIndex_ = 0; elemIndex_ = 0;
while while
( (
++hashIndex_ < curHashTable_.objects_.size() ++hashIndex_ < hashTable_.objects_.size()
&& !curHashTable_.objects_[hashIndex_].size() && !hashTable_.objects_[hashIndex_].size()
) )
{} {}
if (hashIndex_ >= curHashTable_.objects_.size()) if (hashIndex_ >= hashTable_.objects_.size())
{ {
// make end iterator // make end iterator
hashIndex_ = curHashTable_.keys_.size(); hashIndex_ = hashTable_.keys_.size();
} }
return *this; return *this;
@ -326,9 +326,9 @@ Foam::StaticHashTable<T, Key, Hash>::Iterator
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
template<class TRef, class TableRef> template<class TRef, class TableRef>
inline const Key& inline const Key&
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::key() Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::key() const
{ {
return curHashTable_.keys_[hashIndex_][elementIndex_]; return hashTable_.keys_[hashIndex_][elemIndex_];
} }