ENH: HashTable/HashSet contains(key) method

- functionality provided as 'found(key)' in OpenFOAM naming, since
  there was no stl equivalent at the time. Now support contains(),
  which is the equivalent for C++20 maps/sets.

STYLE: general contains() method for containers

STYLE: treat Enum and Switch similarly as hash-like objects
This commit is contained in:
Mark Olesen
2023-02-06 11:21:15 +01:00
parent ed39ee6afe
commit 750381bd99
36 changed files with 212 additions and 156 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -260,15 +260,17 @@ public:
// \note Method name compatibility with boost::dynamic_bitset // \note Method name compatibility with boost::dynamic_bitset
bool intersects(const bitSet& other) const; bool intersects(const bitSet& other) const;
//- Test value at specified position, never auto-vivify entries. //- Test for \em True value at specified position,
//- never auto-vivify entries.
// //
// \note Method name compatibility with std::bitset // \note Method name compatibility with std::bitset
inline bool test(const label pos) const; bool test(const label pos) const { return this->get(pos); }
//- Test value at specified position, never auto-vivify entries. //- Test for \em True value at specified position,
//- never auto-vivify entries.
// //
// \note Method name compatibility with HashSet // \note Method name compatibility with HashSet
inline bool found(const label pos) const; bool contains(const label pos) const { return this->get(pos); }
//- Locate the first bit that is set. //- Locate the first bit that is set.
// \return the location or -1 if there are no bits set. // \return the location or -1 if there are no bits set.
@ -611,6 +613,9 @@ public:
// Housekeeping // Housekeeping
//- Same as contains()
bool found(const label pos) const { return this->contains(pos); }
//- Deprecated(2020-11) use fill() //- Deprecated(2020-11) use fill()
// \deprecated(2020-11) use fill() // \deprecated(2020-11) use fill()
void assign(const unsigned int val) { this->fill(val); } void assign(const unsigned int val) { this->fill(val); }

View File

@ -518,18 +518,6 @@ inline unsigned int Foam::bitSet::count(const bool on) const
} }
inline bool Foam::bitSet::test(const label pos) const
{
return get(pos);
}
inline bool Foam::bitSet::found(const label pos) const
{
return get(pos);
}
inline Foam::labelList Foam::bitSet::sortedToc() const inline Foam::labelList Foam::bitSet::sortedToc() const
{ {
return toc(); return toc();

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd. Copyright (C) 2022-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -288,11 +288,11 @@ public:
// \return position in list or -1 if not found. // \return position in list or -1 if not found.
label find(const T& val, label pos = 0) const; label find(const T& val, label pos = 0) const;
//- True if the value if found in the list. //- Is the value contained in the list?
// Linear search from start pos until the end of the list.
// Any occurrences before the start pos are ignored. // Any occurrences before the start pos are ignored.
// Linear search.
// \return true if found. // \return true if found.
inline bool found(const T& val, label pos = 0) const; inline bool contains(const T& val, label pos = 0) const;
// Stack-like Operations // Stack-like Operations
@ -480,6 +480,12 @@ public:
// Housekeeping // Housekeeping
//- Same as contains()
bool found(const T& val, label pos = 0) const
{
return contains(val, pos);
}
//- Access the first element (front). Requires !empty(). //- Access the first element (front). Requires !empty().
//FOAM_DEPRECATED_FOR(2022-10, "front()") //FOAM_DEPRECATED_FOR(2022-10, "front()")
T& first() { return front(); } T& first() { return front(); }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd. Copyright (C) 2022-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -256,7 +256,7 @@ inline void Foam::CircularBuffer<T>::reserve_nocopy(const label len)
template<class T> template<class T>
inline bool Foam::CircularBuffer<T>::found(const T& val, label pos) const inline bool Foam::CircularBuffer<T>::contains(const T& val, label pos) const
{ {
return (this->find(val, pos) >= 0); return (this->find(val, pos) >= 0);
} }
@ -395,7 +395,7 @@ inline void Foam::CircularBuffer<T>::pop_back(label n)
template<class T> template<class T>
inline Foam::label Foam::CircularBuffer<T>::push_uniq(const T& val) inline Foam::label Foam::CircularBuffer<T>::push_uniq(const T& val)
{ {
if (this->found(val)) if (this->contains(val))
{ {
return 0; return 0;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2022 OpenCFD Ltd. Copyright (C) 2019-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -87,9 +87,9 @@ Foam::DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class IDLListType, class T> template<class IDLListType, class T>
bool Foam::DictionaryBase<IDLListType, T>::found(const word& keyword) const bool Foam::DictionaryBase<IDLListType, T>::contains(const word& keyword) const
{ {
return hashedTs_.found(keyword); return hashedTs_.contains(keyword);
} }
@ -217,7 +217,7 @@ T* Foam::DictionaryBase<IDLListType, T>::remove(const word& keyword)
if (iter.found()) if (iter.found())
{ {
T* ptr = IDLListType::remove(iter()); T* ptr = IDLListType::remove(iter.val());
hashedTs_.erase(iter); hashedTs_.erase(iter);
return ptr; return ptr;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020-2022 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -114,7 +114,7 @@ public:
// Search and lookup // Search and lookup
//- Search for given keyword //- Search for given keyword
bool found(const word& keyword) const; bool contains(const word& keyword) const;
//- Find and return an entry, nullptr on failure. //- Find and return an entry, nullptr on failure.
const T* cfind(const word& keyword) const; const T* cfind(const word& keyword) const;
@ -188,6 +188,9 @@ public:
// Housekeeping // Housekeeping
//- Same as contains()
bool found(const word& key) const { return this->contains(key); }
//- Deprecated(2020-03) use cfind() //- Deprecated(2020-03) use cfind()
// \deprecated(2020-03) - use cfind() method // \deprecated(2020-03) - use cfind() method
FOAM_DEPRECATED_FOR(2020-03, "cfind() method") FOAM_DEPRECATED_FOR(2020-03, "cfind() method")

View File

@ -87,7 +87,7 @@ inline bool Foam::HashPtrTable<T, Key, Hash>::emplace
// Use insertion semantics // Use insertion semantics
return return
( (
!parent_type::found(key) !parent_type::contains(key)
&& this->parent_type::set(key, new T(std::forward<Args>(args)...)) && this->parent_type::set(key, new T(std::forward<Args>(args)...))
); );
} }

View File

@ -237,14 +237,14 @@ inline Foam::label Foam::HashSet<Key, Hash>::unset
template<class Key, class Hash> template<class Key, class Hash>
inline bool Foam::HashSet<Key, Hash>::operator()(const Key& key) const noexcept inline bool Foam::HashSet<Key, Hash>::operator()(const Key& key) const noexcept
{ {
return this->found(key); return this->contains(key);
} }
template<class Key, class Hash> template<class Key, class Hash>
inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const noexcept inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const noexcept
{ {
return this->found(key); return this->contains(key);
} }
@ -281,7 +281,7 @@ bool Foam::HashSet<Key, Hash>::operator==(const HashSet<Key, Hash>& rhs) const
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{ {
if (!this->found(iter.key())) if (!this->contains(iter.key()))
{ {
return false; return false;
} }
@ -328,7 +328,7 @@ Foam::HashSet<Key, Hash>::operator^=(const HashSet<Key, Hash>& rhs)
// Add missed rhs elements, remove duplicate elements // Add missed rhs elements, remove duplicate elements
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{ {
if (this->found(iter.key())) if (this->contains(iter.key()))
{ {
this->erase(iter.key()); this->erase(iter.key());
} }
@ -395,7 +395,7 @@ Foam::HashSet<Key, Hash> Foam::operator&
for (const Key& k : a) for (const Key& k : a)
{ {
if (b.found(k)) if (b.contains(k))
{ {
result.insert(k); result.insert(k);
} }
@ -429,7 +429,7 @@ Foam::HashSet<Key, Hash> Foam::operator-
for (const Key& k : a) for (const Key& k : a)
{ {
if (!b.found(k)) if (!b.contains(k))
{ {
result.insert(k); result.insert(k);
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -176,11 +176,11 @@ public:
// Member Functions // Member Functions
//- Same as found() - return true if key exists in the set. //- Same as contains() - return true if key exists in the set.
// Method name compatibility with bitSet and boolList. // Method name compatibility with bitSet and boolList.
bool test(const Key& key) const bool test(const Key& key) const
{ {
return this->found(key); return this->contains(key);
} }
@ -322,11 +322,11 @@ public:
// Member Operators // Member Operators
//- Return true if the entry exists, same as found() //- Return true if the entry exists, same as contains()
// \note this allows use of HashSet as a predicate test // \note this allows use of HashSet as a predicate test
inline bool operator()(const Key& key) const noexcept; inline bool operator()(const Key& key) const noexcept;
//- Return true if the entry exists, same as found(). //- Return true if the entry exists, same as contains().
inline bool operator[](const Key& key) const noexcept; inline bool operator[](const Key& key) const noexcept;
//- Copy assign //- Copy assign

View File

@ -553,7 +553,7 @@ Foam::label Foam::HashTable<T, Key, Hash>::erase
++iter ++iter
) )
{ {
if (other.found(iter.key()) && erase(iter)) if (other.contains(iter.key()) && erase(iter))
{ {
++changed; ++changed;
} }
@ -586,7 +586,7 @@ Foam::label Foam::HashTable<T, Key, Hash>::retain
for (iterator iter = begin(); iter != end(); ++iter) for (iterator iter = begin(); iter != end(); ++iter)
{ {
if (!other.found(iter.key()) && erase(iter)) if (!other.contains(iter.key()) && erase(iter))
{ {
++changed; ++changed;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -57,7 +57,7 @@ Note
forAllConstIters(table, iter) forAllConstIters(table, iter)
{ {
Info<< "val:" << *iter << nl Info<< "val:" << *iter << nl
<< "key:" << iter.key() << nl; << "key:" << iter.key() << nl
<< "val:" << iter.val() << nl; << "val:" << iter.val() << nl;
} }
\endcode \endcode
@ -213,18 +213,6 @@ private:
Ostream& writeTable(Ostream& os) const; Ostream& writeTable(Ostream& os) const;
protected:
//- Internally used base for iterator and const_iterator
template<bool Const> class Iterator;
//- An iterator with const access to HashTable internals.
friend class Iterator<true>;
//- An iterator with non-const access to HashTable internals.
friend class Iterator<false>;
public: public:
// Constructors // Constructors
@ -272,8 +260,8 @@ public:
//- Find and return a hashed entry. FatalError if it does not exist. //- Find and return a hashed entry. FatalError if it does not exist.
inline const T& at(const Key& key) const; inline const T& at(const Key& key) const;
//- True if hashed key is found in table //- True if hashed key is contained (found) in table
inline bool found(const Key& key) const; inline bool contains(const Key& key) const;
//- Find and return an iterator set at the hashed entry //- Find and return an iterator set at the hashed entry
// If not found iterator = end() // If not found iterator = end()
@ -548,9 +536,11 @@ public:
// Member Operators // Member Operators
//- Find and return a hashed entry. FatalError if it does not exist. //- Find and return a hashed entry. FatalError if it does not exist.
// Same as at().
inline T& operator[](const Key& key); inline T& operator[](const Key& key);
//- Find and return a hashed entry. FatalError if it does not exist. //- Find and return a hashed entry. FatalError if it does not exist.
// Same as at().
inline const T& operator[](const Key& key) const; inline const T& operator[](const Key& key) const;
//- Return existing entry or create a new entry. //- Return existing entry or create a new entry.
@ -586,6 +576,15 @@ protected:
// Iterators and helpers // Iterators and helpers
//- Internally used base for iterator and const_iterator
template<bool Const> class Iterator;
//- Allow iterator access to HashTable internals.
friend class Iterator<true>;
//- Allow iterator access to HashTable internals.
friend class Iterator<false>;
//- The iterator base for HashTable (internal use only). //- The iterator base for HashTable (internal use only).
// Note: data and functions are protected, to allow reuse by iterator // Note: data and functions are protected, to allow reuse by iterator
// and prevent most external usage. // and prevent most external usage.
@ -908,13 +907,13 @@ public:
reference operator*() const { return this->key(); } reference operator*() const { return this->key(); }
reference operator()() const { return this->key(); } reference operator()() const { return this->key(); }
inline key_iterator_base& operator++() key_iterator_base& operator++()
{ {
this->increment(); this->increment();
return *this; return *this;
} }
inline key_iterator_base operator++(int) key_iterator_base operator++(int)
{ {
key_iterator_base iter(*this); key_iterator_base iter(*this);
this->increment(); this->increment();
@ -981,6 +980,12 @@ public:
Ostream&, Ostream&,
const HashTable<T, Key, Hash>& tbl const HashTable<T, Key, Hash>& tbl
); );
// Housekeeping
//- Same as contains()
bool found(const Key& key) const { return this->contains(key); }
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -76,7 +76,7 @@ inline const T& Foam::HashTable<T, Key, Hash>::at(const Key& key) const
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::found(const Key& key) const inline bool Foam::HashTable<T, Key, Hash>::contains(const Key& key) const
{ {
if (size_) if (size_)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -191,10 +191,11 @@ public:
// \return -1 if not found. // \return -1 if not found.
label rfind(const T& val, label pos = -1) const; label rfind(const T& val, label pos = -1) const;
//- True if the value if found in the list. //- Is the value contained in the list?
// Linear search from start pos until the end of the list.
// Any occurrences before the start pos are ignored. // Any occurrences before the start pos are ignored.
// Linear search. // \return true if found.
inline bool found(const T& val, label pos=0) const; inline bool contains(const T& val, label pos = 0) const;
// Member Operators // Member Operators
@ -382,6 +383,12 @@ public:
//- Access last element of the list, position [size()-1] //- Access last element of the list, position [size()-1]
//FOAM_DEPRECATED_FOR(2022-10, "back()") //FOAM_DEPRECATED_FOR(2022-10, "back()")
const T& last() const { return back(); }; const T& last() const { return back(); };
//- Same as contains()
bool found(const T& val, label pos = 0) const
{
return this->contains(val, pos);
}
}; };

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -99,7 +99,7 @@ inline bool Foam::IndirectListBase<T, Addr>::uniform() const
template<class T, class Addr> template<class T, class Addr>
inline bool Foam::IndirectListBase<T, Addr>::found inline bool Foam::IndirectListBase<T, Addr>::contains
( (
const T& val, const T& val,
label pos label pos

View File

@ -661,7 +661,7 @@ inline void Foam::DynamicList<T, SizeMin>::push_back
template<class T, int SizeMin> template<class T, int SizeMin>
inline Foam::label Foam::DynamicList<T, SizeMin>::push_uniq(const T& val) inline Foam::label Foam::DynamicList<T, SizeMin>::push_uniq(const T& val)
{ {
if (this->found(val)) if (this->contains(val))
{ {
return 0; return 0;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -293,10 +293,11 @@ public:
// \return position in list or -1 if not found. // \return position in list or -1 if not found.
label rfind(const T& val, label pos = -1) const; label rfind(const T& val, label pos = -1) const;
//- True if the value if found in the list. //- Is the value contained in the list?
// Linear search from start pos until the end of the list.
// Any occurrences before the start pos are ignored. // Any occurrences before the start pos are ignored.
// Linear search. // \return true if found.
inline bool found(const T& val, label pos = 0) const; inline bool contains(const T& val, label pos = 0) const;
// Edit // Edit
@ -522,6 +523,12 @@ public:
//- Access last element of the list, position [N-1] - back() //- Access last element of the list, position [N-1] - back()
const T& last() const noexcept { return back(); } const T& last() const noexcept { return back(); }
//- Same as contains()
bool found(const T& val, label pos = 0) const
{
return this->contains(val, pos);
}
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -345,11 +345,7 @@ inline bool Foam::FixedList<T, N>::uniform() const
template<class T, unsigned N> template<class T, unsigned N>
inline bool Foam::FixedList<T, N>::found inline bool Foam::FixedList<T, N>::contains(const T& val, label pos) const
(
const T& val,
label pos
) const
{ {
return (this->find(val, pos) >= 0); return (this->find(val, pos) >= 0);
} }

View File

@ -248,7 +248,7 @@ inline void Foam::List<T>::push_back(const IndirectListBase<T, Addr>& list)
template<class T> template<class T>
inline Foam::label Foam::List<T>::push_uniq(const T& val) inline Foam::label Foam::List<T>::push_uniq(const T& val)
{ {
if (this->found(val)) if (this->contains(val))
{ {
return 0; return 0;
} }

View File

@ -325,11 +325,11 @@ public:
// \return position in list or -1 if not found. // \return position in list or -1 if not found.
label rfind(const T& val, label pos = -1) const; label rfind(const T& val, label pos = -1) const;
//- True if the value if found in the list. //- Is the value contained in the list?
// Linear search from start pos until the end of the list.
// Any occurrences before the start pos are ignored. // Any occurrences before the start pos are ignored.
// Linear search.
// \return true if found. // \return true if found.
inline bool found(const T& val, label pos = 0) const; inline bool contains(const T& val, label pos = 0) const;
// Edit // Edit
@ -611,6 +611,12 @@ public:
//- Access last element of the list, position [size()-1] //- Access last element of the list, position [size()-1]
//FOAM_DEPRECATED_FOR(2022-10, "back()") //FOAM_DEPRECATED_FOR(2022-10, "back()")
const T& last() const { return back(); }; const T& last() const { return back(); };
//- Same as contains()
bool found(const T& val, label pos = 0) const
{
return this->contains(val, pos);
}
}; };

View File

@ -262,7 +262,7 @@ inline std::streamsize Foam::UList<T>::size_bytes() const noexcept
template<class T> template<class T>
inline bool Foam::UList<T>::found(const T& val, label pos) const inline bool Foam::UList<T>::contains(const T& val, label pos) const
{ {
return (this->find(val, pos) >= 0); return (this->find(val, pos) >= 0);
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -1095,7 +1095,8 @@ void Foam::ListOps::uniqueEqOp<T>::operator()
{ {
for (const T& val : y) for (const T& val : y)
{ {
if (!x.found(val)) // --> x.push_uniq(val)
if (!x.contains(val))
{ {
x.push_back(val); x.push_back(val);
} }

View File

@ -450,7 +450,7 @@ const Foam::regIOobject* Foam::objectRegistry::cfindIOobject
} }
bool Foam::objectRegistry::found bool Foam::objectRegistry::contains
( (
const word& name, const word& name,
const bool recursive const bool recursive

View File

@ -413,11 +413,11 @@ public:
const bool recursive = false const bool recursive = false
) const; ) const;
//- Can the regIOobject object be found (by name). //- Does the registry contain the regIOobject object (by name).
// //
// \param name the object name
// \param recursive search parent registries // \param recursive search parent registries
bool found(const word& name, const bool recursive = false) const; bool contains(const word& name, const bool recursive = false) const;
//- Is the named Type found? //- Is the named Type found?
// //
@ -591,6 +591,12 @@ public:
// Housekeeping // Housekeeping
//- Same as contains()
bool found(const word& name, bool recursive = false) const
{
return this->contains(name, recursive);
}
//- Deprecated(2018-10) find object //- Deprecated(2018-10) find object
// \deprecated(2018-10) - use findObject() method // \deprecated(2018-10) - use findObject() method
template<class Type> template<class Type>

View File

@ -424,9 +424,9 @@ Foam::interpolationLookUpTable<Type>::operator[](const label i) const
template<class Type> template<class Type>
bool Foam::interpolationLookUpTable<Type>::found(const word& fieldName) const bool Foam::interpolationLookUpTable<Type>::contains(const word& fieldName) const
{ {
return fieldIndices_.found(fieldName); return fieldIndices_.contains(fieldName);
} }

View File

@ -39,8 +39,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef interpolationLookUpTable_H #ifndef Foam_interpolationLookUpTable_H
#define interpolationLookUpTable_H #define Foam_interpolationLookUpTable_H
#include "List.H" #include "List.H"
#include "ListOps.H" #include "ListOps.H"
@ -162,7 +162,7 @@ public:
// Member Functions // Member Functions
//- Return true if the field exists in the table //- Return true if the field exists in the table
bool found(const word& fieldName) const; bool contains(const word& fieldName) const;
//- Return the output list given a single input scalar //- Return the output list given a single input scalar
const List<scalar>& lookUp(const scalar); const List<scalar>& lookUp(const scalar);
@ -212,6 +212,14 @@ public:
//- Return an element of List<scalar, Type> //- Return an element of List<scalar, Type>
scalarField& operator[](const label); scalarField& operator[](const label);
// Housekeeping
//- Same as contains()
bool found(const word& fieldName) const
{
return this->contains(fieldName);
}
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -153,9 +153,9 @@ public:
//- True if the vertices are unique and non-negative. //- True if the vertices are unique and non-negative.
bool valid() const noexcept { return good(); } bool valid() const noexcept { return good(); }
//- Return true if point label is found in edge. //- Return true if the point label is contained in the edge.
// Always false for a negative label. // Always false for a negative label.
inline bool found(const label pointLabel) const; inline bool contains(const label pointLabel) const;
//- Return local index (0,1) of point label in edge -1 on failure //- Return local index (0,1) of point label in edge -1 on failure
// Always return -1 for a negative label. // Always return -1 for a negative label.
@ -321,6 +321,12 @@ public:
} }
}; };
// Housekeeping
//- Same as contains()
bool found(label vertex) const { return contains(vertex); }
//- Deprecated(2021-04) hashing functor. Use hasher() //- Deprecated(2021-04) hashing functor. Use hasher()
// \deprecated(2021-04) - use hasher() functor // \deprecated(2021-04) - use hasher() functor
template<class Unused=bool> template<class Unused=bool>

View File

@ -110,7 +110,7 @@ inline bool Foam::edge::good() const noexcept
} }
inline bool Foam::edge::found(const label pointLabel) const inline bool Foam::edge::contains(const label pointLabel) const
{ {
// -1: always false // -1: always false
return return
@ -142,17 +142,17 @@ inline Foam::label Foam::edge::which(const label pointLabel) const
inline bool Foam::edge::connected(const edge& other) const inline bool Foam::edge::connected(const edge& other) const
{ {
return (other.found(first()) || other.found(second())); return (other.contains(first()) || other.contains(second()));
} }
inline Foam::label Foam::edge::commonVertex(const edge& other) const inline Foam::label Foam::edge::commonVertex(const edge& other) const
{ {
if (other.found(first())) if (other.contains(first()))
{ {
return first(); return first();
} }
if (other.found(second())) if (other.contains(second()))
{ {
return second(); return second();
} }

View File

@ -209,7 +209,7 @@ inline bool Foam::face::connected(const labelUList& other) const
{ {
for (const label pointi : *this) for (const label pointi : *this)
{ {
if (other.found(pointi)) if (other.contains(pointi))
{ {
return true; return true;
} }
@ -223,7 +223,7 @@ inline bool Foam::face::connected(const FixedList<label, N>& other) const
{ {
for (const label pointi : *this) for (const label pointi : *this)
{ {
if (other.found(pointi)) if (other.contains(pointi))
{ {
return true; return true;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -154,7 +154,7 @@ Foam::Switch Foam::Switch::find(const std::string& str)
} }
bool Foam::Switch::found(const std::string& str) bool Foam::Switch::contains(const std::string& str)
{ {
return (switchType::INVALID != parse(str, false)); // failOnError=false return (switchType::INVALID != parse(str, false)); // failOnError=false
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -209,13 +209,13 @@ public:
//- A string representation of bool as "false" / "true" //- A string representation of bool as "false" / "true"
static const char* name(const bool b) noexcept; static const char* name(const bool b) noexcept;
//- True if there is a switch type corresponding to the given string.
static bool contains(const std::string& str);
//- Find switchType for the given string, returning as a Switch that //- Find switchType for the given string, returning as a Switch that
//- can be tested for good() or bad(). //- can be tested for good() or bad().
static Switch find(const std::string& str); static Switch find(const std::string& str);
//- Test if there is a switch type corresponding to the given string.
static bool found(const std::string& str);
// Member Functions // Member Functions
@ -271,6 +271,9 @@ public:
// Housekeeping // Housekeeping
//- Same as contains()
static bool found(const std::string& str) { return contains(str); }
//- Deprecated(2020-01) From string with/without bad input test //- Deprecated(2020-01) From string with/without bad input test
// \deprecated(2020-01) - confusing syntax, use static find() method // \deprecated(2020-01) - confusing syntax, use static find() method
FOAM_DEPRECATED_FOR(2019-02, "static find() method") FOAM_DEPRECATED_FOR(2019-02, "static find() method")
@ -281,13 +284,10 @@ public:
FOAM_DEPRECATED_FOR(2019-02, "static find() method") FOAM_DEPRECATED_FOR(2019-02, "static find() method")
Switch(const char* str, bool allowBad); Switch(const char* str, bool allowBad);
//- Deprecated(2020-01) Use good() method, or static found() method //- Deprecated(2020-01) Use good() method, or static contains() method
// \deprecated(2020-01) Use good() method, or static found() method // \deprecated(2020-01) Use good() method, or static contains() method
FOAM_DEPRECATED_FOR(2019-02, "good() or static found() method") FOAM_DEPRECATED_FOR(2019-02, "good() or static contains() method")
bool valid() const noexcept bool valid() const noexcept { return good(); }
{
return good();
}
//- Same as getOrAddToDict() //- Same as getOrAddToDict()
static Switch lookupOrAddToDict static Switch lookupOrAddToDict

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -139,6 +139,12 @@ public:
// Query // Query
//- True if there is an enumeration corresponding to the given name.
inline bool contains(const word& enumName) const;
//- True if there is a name corresponding to the given enumeration.
inline bool contains(const EnumType e) const;
//- Find the index of the given name. //- Find the index of the given name.
// \return position in list or -1 if not found. // \return position in list or -1 if not found.
inline label find(const word& enumName) const; inline label find(const word& enumName) const;
@ -147,12 +153,6 @@ public:
// \return position in list or -1 if not found. // \return position in list or -1 if not found.
inline label find(const EnumType e) const; inline label find(const EnumType e) const;
//- True if there is an enumeration corresponding to the given name.
inline bool found(const word& enumName) const;
//- True if there is a name corresponding to the given enumeration.
inline bool found(const EnumType e) const;
//- The enumeration corresponding to the given name. //- The enumeration corresponding to the given name.
// FatalError if not found. // FatalError if not found.
EnumType get(const word& enumName) const; EnumType get(const word& enumName) const;
@ -319,7 +319,6 @@ public:
return getOrDefault(key, dict, deflt, failsafe); return getOrDefault(key, dict, deflt, failsafe);
} }
//- Deprecated(2020-11) use get() method //- Deprecated(2020-11) use get() method
// \deprecated(2020-11) - use get() method // \deprecated(2020-11) - use get() method
FOAM_DEPRECATED_FOR(2020-11, "get() method") FOAM_DEPRECATED_FOR(2020-11, "get() method")
@ -361,6 +360,12 @@ public:
{ {
push_back(list); push_back(list);
} }
//- Same as contains()
bool found(const word& enumName) const { return contains(enumName); }
//- Same as contains()
bool found(const EnumType e) const { return contains(e); }
}; };

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -100,16 +100,16 @@ inline Foam::label Foam::Enum<EnumType>::find(const EnumType e) const
template<class EnumType> template<class EnumType>
inline bool Foam::Enum<EnumType>::found(const word& enumName) const inline bool Foam::Enum<EnumType>::contains(const word& enumName) const
{ {
return keys_.found(enumName); return keys_.contains(enumName);
} }
template<class EnumType> template<class EnumType>
inline bool Foam::Enum<EnumType>::found(const EnumType e) const inline bool Foam::Enum<EnumType>::contains(const EnumType e) const
{ {
return vals_.found(int(e)); return vals_.contains(int(e));
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -270,7 +270,7 @@ public:
// Search // Search
//- Index of the first match for the value. //- Index of the first matching test for the value.
// Any occurrences before the start pos are ignored. // Any occurrences before the start pos are ignored.
// Linear search. // Linear search.
// \return position in list or -1 if not found. // \return position in list or -1 if not found.
@ -282,23 +282,23 @@ public:
// \return position in list or -1 if not found. // \return position in list or -1 if not found.
label rfind(const scalar value, label pos = -1) const; label rfind(const scalar value, label pos = -1) const;
//- True if the value matches any in the list. //- True if the value matches in the list.
// Linear search from start pos until the end of the list.
// Any occurrences before the start pos are ignored. // Any occurrences before the start pos are ignored.
// Linear search.
// \return true if found. // \return true if found.
inline bool found(const scalar value, label pos=0) const; inline bool contains(const scalar value, label pos = 0) const;
//- Match any condition in the list. //- Match \em any condition in the list.
// //
// \return True if the value matches any condition in the list. // \return True if the value matches any condition in the list.
inline bool match(const scalar value) const; inline bool match(const scalar value) const;
//- Match any condition in the list. //- Match \em any condition in the list.
// //
// \return True if the value matches any condition in the list. // \return True if the value matches any condition in the list.
inline bool matchAny(const scalar value) const; inline bool matchAny(const scalar value) const;
//- Match all conditions in the list. //- Match \em all conditions in the list.
// //
// \return True if the value matches all conditions in the list. // \return True if the value matches all conditions in the list.
inline bool matchAll(const scalar value) const; inline bool matchAll(const scalar value) const;
@ -324,8 +324,17 @@ public:
// Member Operators // Member Operators
//- Identical to found(), match(), for use as a predicate. //- Identical to contains(), match(), for use as a predicate.
inline bool operator()(const scalar value) const; inline bool operator()(const scalar value) const;
// Housekeeping
//- Same as contains()
bool found(const scalar value, label pos = 0) const
{
return this->contains(value, pos);
}
}; };

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -60,7 +60,7 @@ inline Foam::predicates::scalars::unary Foam::predicates::scalars::operation
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::predicates::scalars::found inline bool Foam::predicates::scalars::contains
( (
const scalar value, const scalar value,
label pos label pos

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -142,8 +142,8 @@ public:
// \return position in list or -1 if not found. // \return position in list or -1 if not found.
inline label find(const word& val) const; inline label find(const word& val) const;
//- True if the value if found in the list (searches the hash). //- Is the value contained in the list (searches the hash).
inline bool found(const word& val) const; inline bool contains(const word& val) const;
// Member Operators // Member Operators
@ -156,7 +156,7 @@ public:
// \return position in list or -1 if not found. // \return position in list or -1 if not found.
inline label operator[](const word& val) const; inline label operator[](const word& val) const;
//- Check hashed values for the specified name - same as found(). //- Check hashed values for the specified name - same as contains().
// Can be used as a unary predicate. // Can be used as a unary predicate.
inline bool operator()(const word& val) const; inline bool operator()(const word& val) const;
@ -181,6 +181,9 @@ public:
// Housekeeping // Housekeeping
//- Same as contains(), searches the hash.
bool found(const word& val) const { return this->contains(val); }
//- Append an element if not already in the list. //- Append an element if not already in the list.
FOAM_DEPRECATED_FOR(2022-05, "push_uniq method") FOAM_DEPRECATED_FOR(2022-05, "push_uniq method")
void append(const word& val) { this->push_uniq(val); } void append(const word& val) { this->push_uniq(val); }
@ -192,11 +195,6 @@ public:
//- Append an element if not already in the list. //- Append an element if not already in the list.
//FOAM_DEPRECATED_FOR(2022-10, "push_uniq method") //FOAM_DEPRECATED_FOR(2022-10, "push_uniq method")
label appendUniq(const word& val) { return this->push_uniq(val); } label appendUniq(const word& val) { return this->push_uniq(val); }
//- Deprecated(2019-01) Is the specified name found in the list?
// \deprecated(2019-01) - use found() method
FOAM_DEPRECATED_FOR(2019-01, "found() method")
bool contains(const word& val) const { return this->found(val); }
}; };

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -130,9 +130,9 @@ inline Foam::label Foam::hashedWordList::find(const word& val) const
} }
inline bool Foam::hashedWordList::found(const word& val) const inline bool Foam::hashedWordList::contains(const word& val) const
{ {
return lookup().found(val); return lookup().contains(val);
} }
@ -201,7 +201,7 @@ inline Foam::label Foam::hashedWordList::operator[](const word& val) const
inline bool Foam::hashedWordList::operator()(const word& val) const inline bool Foam::hashedWordList::operator()(const word& val) const
{ {
return lookup_.found(val); return lookup_.contains(val);
} }