added HashSet::operator[]() const

- can use the same syntax for boolList, PackedBoolList and labelHashSet
    if (myHashedSet[x]) ...
    if (myBoolList[x]) ...
    if (myPackedList[x]) ...
This commit is contained in:
Mark Olesen
2009-01-27 21:55:03 +01:00
parent c048dd88c7
commit c6e9b323f5
3 changed files with 37 additions and 1 deletions

View File

@ -111,6 +111,33 @@ int main(int argc, char *argv[])
Info<< "setD : " << setD << endl; Info<< "setD : " << setD << endl;
Info<< "setB ^ setC ^ setD : " << (setB ^ setC ^ setD) << endl; Info<< "setB ^ setC ^ setD : " << (setB ^ setC ^ setD) << endl;
// test operator[]
Info<< "setD : " << setD << endl;
if (setD[0])
{
Info<< "setD has 0" << endl;
}
else
{
Info<< "setD has no 0" << endl;
}
if (setD[11])
{
Info<< "setD has 11" << endl;
}
else
{
Info<< "setD has no 0" << endl;
}
Info<< "setD : " << setD << endl;
// this doesn't work (yet?)
// setD[12] = true;
return 0; return 0;
} }

View File

@ -51,6 +51,13 @@ Foam::HashSet<Key, Hash>::HashSet(const HashTable<AnyType, Key, Hash>& ht)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Key, class Hash>
inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
{
return found(key);
}
template<class Key, class Hash> template<class Key, class Hash>
bool Foam::HashSet<Key, Hash>::operator==(const HashSet<Key, Hash>& rhs) const bool Foam::HashSet<Key, Hash>::operator==(const HashSet<Key, Hash>& rhs) const
{ {

View File

@ -133,9 +133,11 @@ public:
return HashTable<nil, Key, Hash>::insert(key, nil()); return HashTable<nil, Key, Hash>::insert(key, nil());
} }
// Member Operators // Member Operators
//- Return true if the entry exists, same as found()
inline bool operator[](const Key&) const;
//- Equality. Two hashtables are equal when their contents are equal. //- Equality. Two hashtables are equal when their contents are equal.
// Independent of table size or order. // Independent of table size or order.
bool operator==(const HashSet<Key, Hash>&) const; bool operator==(const HashSet<Key, Hash>&) const;