/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #ifndef HashSet_C #define HashSet_C #include "HashSet.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::HashSet::HashSet(const UList& lst) : HashTable(2*lst.size()) { forAll(lst, elemI) { insert(lst[elemI]); } } template template Foam::HashSet::HashSet ( const HashTable& h ) : HashTable(h.size()) { for ( typename HashTable::const_iterator cit = h.cbegin(); cit != h.cend(); ++cit ) { insert(cit.key()); } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template Foam::label Foam::HashSet::insert(const UList& lst) { label count = 0; forAll(lst, elemI) { if (insert(lst[elemI])) { ++count; } } return count; } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template inline bool Foam::HashSet::operator[](const Key& key) const { return found(key); } template bool Foam::HashSet::operator==(const HashSet& rhs) const { // Are all lhs elements in rhs? for (const_iterator iter = this->cbegin(); iter != this->cend(); ++iter) { if (!rhs.found(iter.key())) { return false; } } // Are all rhs elements in lhs? for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { if (!found(iter.key())) { return false; } } return true; } template bool Foam::HashSet::operator!=(const HashSet& rhs) const { return !(operator==(rhs)); } template void Foam::HashSet::operator|=(const HashSet& rhs) { // Add rhs elements into lhs for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { insert(iter.key()); } } template void Foam::HashSet::operator&=(const HashSet& rhs) { // Remove elements not also found in rhs for (iterator iter = this->begin(); iter != this->end(); ++iter) { if (!rhs.found(iter.key())) { erase(iter); } } } template void Foam::HashSet::operator^=(const HashSet& rhs) { // Add missed rhs elements, remove duplicate elements for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { if (found(iter.key())) { erase(iter.key()); } else { insert(iter.key()); } } } // same as HashTable::erase() template void Foam::HashSet::operator-=(const HashSet& rhs) { // Remove rhs elements from lhs for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { erase(iter.key()); } } /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ template Foam::HashSet Foam::operator| ( const HashSet& hash1, const HashSet& hash2 ) { HashSet out(hash1); out |= hash2; return out; } template Foam::HashSet Foam::operator& ( const HashSet& hash1, const HashSet& hash2 ) { HashSet out(hash1); out &= hash2; return out; } template Foam::HashSet Foam::operator^ ( const HashSet& hash1, const HashSet& hash2 ) { HashSet out(hash1); out ^= hash2; return out; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* //