added HashTable::erase(const HashTable&) method

This commit is contained in:
Mark Olesen
2009-01-09 09:35:53 +01:00
parent 92c88521c4
commit 990a9e7f57
7 changed files with 102 additions and 14 deletions

View File

@ -126,6 +126,7 @@ void Foam::HashSet<Key, Hash>::operator^=(const HashSet<Key, Hash>& rhs)
}
// same as HashTable::erase()
template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs)
{

View File

@ -388,11 +388,11 @@ bool Foam::HashTable<T, Key, Hash>::erase(const iterator& cit)
template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
{
iterator it = find(key);
iterator fnd = find(key);
if (it != end())
if (fnd != end())
{
return erase(it);
return erase(fnd);
}
else
{
@ -401,6 +401,28 @@ bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
}
template<class T, class Key, class Hash>
Foam::label Foam::HashTable<T, Key, Hash>::erase
(
const HashTable<T, Key, Hash>& rhs
)
{
label count = 0;
// Remove rhs elements from this table
// NOTE: could optimize depending on which hash is smaller
for (iterator iter = this->begin(); iter != this->end(); ++iter)
{
if (rhs.found(iter.key()) && erase(iter))
{
count++;
}
}
return count;
}
template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::resize(const label newSize)
{

View File

@ -200,6 +200,10 @@ public:
//- Erase an hashedEntry specified by given key if in table
bool erase(const Key&);
//- Remove entries in the given HashTable from this HashTable
// Return the number of elements removed
label erase(const HashTable<T, Key, Hash>&);
//- Resize the hash table for efficiency
void resize(const label newSize);

View File

@ -346,6 +346,28 @@ bool Foam::StaticHashTable<T, Key, Hash>::erase(const Key& key)
}
template<class T, class Key, class Hash>
Foam::label Foam::StaticHashTable<T, Key, Hash>::erase
(
const StaticHashTable<T, Key, Hash>& rhs
)
{
label count = 0;
// Remove rhs elements from this table
// NOTE: could optimize depending on which hash is smaller
for (iterator iter = this->begin(); iter != this->end(); ++iter)
{
if (rhs.found(iter.key()) && erase(iter))
{
count++;
}
}
return count;
}
template<class T, class Key, class Hash>
void Foam::StaticHashTable<T, Key, Hash>::resize(const label newSize)
{

View File

@ -196,6 +196,10 @@ public:
//- Resize the hash table for efficiency
void resize(const label newSize);
//- Remove entries in the given hash table from this hash table
// Return the number of elements removed
label erase(const StaticHashTable<T, Key, Hash>&);
//- Clear all entries from table
void clear();