ENH: construct DynamicField, DynamicList from subset of elements

STYLE: inline some size(), empty() members
This commit is contained in:
Mark Olesen
2023-01-11 08:58:38 +01:00
parent f08392010f
commit 33c9df7741
25 changed files with 124 additions and 162 deletions

View File

@ -283,13 +283,13 @@ public:
//- Check index is within valid range [0,size)
inline void checkIndex(const label i) const;
//- Number of entries.
inline label size() const noexcept;
//- True if the list is empty (ie, size() is zero).
inline bool empty() const noexcept;
bool empty() const noexcept { return !size_; }
//- The number of elements that can be stored with reallocating
//- Number of entries.
label size() const noexcept { return size_; }
//- Number of elements that can be stored without reallocating
inline label capacity() const noexcept;
//- True if all entries have identical values, and list is non-empty

View File

@ -373,20 +373,6 @@ inline void Foam::PackedList<Width>::checkIndex(const label i) const
}
template<unsigned Width>
inline Foam::label Foam::PackedList<Width>::size() const noexcept
{
return size_;
}
template<unsigned Width>
inline bool Foam::PackedList<Width>::empty() const noexcept
{
return !size_;
}
template<unsigned Width>
inline Foam::label Foam::PackedList<Width>::capacity() const noexcept
{

View File

@ -257,14 +257,14 @@ public:
// Access
//- The size of the underlying table
inline label capacity() const noexcept;
//- True if the hash table is empty
bool empty() const noexcept { return !size_; }
//- The number of elements in table
inline label size() const noexcept;
label size() const noexcept { return size_; }
//- True if the hash table is empty
inline bool empty() const noexcept;
//- The size of the underlying table
label capacity() const noexcept { return capacity_; }
//- Find and return a hashed entry. FatalError if it does not exist.
inline T& at(const Key& key);

View File

@ -90,8 +90,8 @@ struct HashTableCore
//- Construct begin/end pair for table
inline const_iterator_pair(const TableType& tbl);
label size() const noexcept { return size_; }
bool empty() const noexcept { return !size_; }
label size() const noexcept { return size_; }
inline IteratorType begin() const;
inline IteratorType cbegin() const;

View File

@ -41,27 +41,6 @@ Foam::HashTable<T, Key, Hash>::hashKeyIndex(const Key& key) const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::label Foam::HashTable<T, Key, Hash>::capacity() const noexcept
{
return capacity_;
}
template<class T, class Key, class Hash>
inline Foam::label Foam::HashTable<T, Key, Hash>::size() const noexcept
{
return size_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::empty() const noexcept
{
return !size_;
}
template<class T, class Key, class Hash>
inline T& Foam::HashTable<T, Key, Hash>::at(const Key& key)
{

View File

@ -84,12 +84,12 @@ public:
// Access
//- The number of elements in the list
label size() const noexcept { return addr_.size(); }
//- True if the list is empty (ie, size() is zero).
bool empty() const noexcept { return addr_.empty(); }
//- The number of elements in the list
label size() const noexcept { return addr_.size(); }
//- The list of positive values (without addressing)
const UList<T>& posList() const noexcept { return posList_; }

View File

@ -53,8 +53,8 @@ SourceFiles
#define Foam_IndirectList_H
#include "List.H"
#include "IndirectListBase.H"
#include "IndirectListAddressing.H"
#include "IndirectListBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -122,12 +122,12 @@ public:
// Access
//- The number of elements in the list
label size() const noexcept { return addr_.size(); }
//- True if the list is empty (ie, size() is zero).
bool empty() const noexcept { return addr_.empty(); }
//- The number of elements in the list
label size() const noexcept { return addr_.size(); }
//- The list of values (without addressing)
const UList<T>& values() const noexcept { return values_; }

View File

@ -31,8 +31,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef IndirectListsFwd_H
#define IndirectListsFwd_H
#ifndef Foam_IndirectListsFwd_H
#define Foam_IndirectListsFwd_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -150,11 +150,11 @@ public:
// Member Functions
//- The number of elements in list
inline label size() const noexcept;
//- True if the list is empty
inline bool empty() const noexcept;
bool empty() const noexcept { return !size_; }
//- The number of elements in list
label size() const noexcept { return size_; }
//- Return first entry
inline link* front();

View File

@ -99,18 +99,6 @@ Foam::DLListBase::crend() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::DLListBase::size() const noexcept
{
return size_;
}
inline bool Foam::DLListBase::empty() const noexcept
{
return !size_;
}
inline Foam::DLListBase::link*
Foam::DLListBase::front()
{

View File

@ -141,11 +141,11 @@ public:
// Member Functions
//- The number of elements in list
inline label size() const noexcept;
//- True if the list is empty
inline bool empty() const noexcept;
bool empty() const noexcept { return !size_; }
//- The number of elements in list
label size() const noexcept { return size_; }
//- Return first entry
inline link* front();

View File

@ -70,18 +70,6 @@ inline IteratorType Foam::SLListBase::iterator_last() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::SLListBase::size() const noexcept
{
return size_;
}
inline bool Foam::SLListBase::empty() const noexcept
{
return !size_;
}
inline Foam::SLListBase::link*
Foam::SLListBase::front()
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -89,7 +89,7 @@ class DynamicList
//- Copy assignment from another list
template<class ListType>
inline void assignDynList(const ListType& list);
inline void doAssignDynList(const ListType& list);
//- Alter the size of the underlying storage
// The 'nocopy' option will not attempt to recover old content
@ -133,6 +133,9 @@ public:
// Also constructs from DynamicList with different sizing parameters.
inline explicit DynamicList(const UList<T>& lst);
//- Copy construct subset of list
inline DynamicList(const UList<T>& list, const labelUList& indices);
//- Construct from a FixedList
template<unsigned N>
inline explicit DynamicList(const FixedList<T, N>& lst);
@ -166,7 +169,7 @@ public:
static constexpr label min_size() noexcept { return SizeMin; }
//- Size of the underlying storage.
inline label capacity() const noexcept;
label capacity() const noexcept { return capacity_; }
//- Number of contiguous bytes of the underlying storage.
// \note Only meaningful for contiguous data

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,7 +32,7 @@ License
template<class T, int SizeMin>
template<class ListType>
inline void Foam::DynamicList<T, SizeMin>::assignDynList
inline void Foam::DynamicList<T, SizeMin>::doAssignDynList
(
const ListType& list
)
@ -210,6 +210,18 @@ inline Foam::DynamicList<T, SizeMin>::DynamicList
{}
template<class T, int SizeMin>
inline Foam::DynamicList<T, SizeMin>::DynamicList
(
const UList<T>& list,
const labelUList& indices
)
:
List<T>(list, indices),
capacity_(List<T>::size())
{}
template<class T, int SizeMin>
template<unsigned N>
inline Foam::DynamicList<T, SizeMin>::DynamicList
@ -283,13 +295,6 @@ inline Foam::DynamicList<T, SizeMin>::DynamicList
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, int SizeMin>
inline Foam::label Foam::DynamicList<T, SizeMin>::capacity() const noexcept
{
return capacity_;
}
template<class T, int SizeMin>
inline std::streamsize
Foam::DynamicList<T, SizeMin>::capacity_bytes() const noexcept
@ -791,7 +796,7 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
const UList<T>& lst
)
{
assignDynList(lst);
doAssignDynList(lst);
}
@ -802,7 +807,7 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
const FixedList<T, N>& lst
)
{
assignDynList(lst);
doAssignDynList(lst);
}
@ -817,7 +822,7 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
return; // Self-assignment is a no-op
}
assignDynList(lst);
doAssignDynList(lst);
}
@ -837,7 +842,7 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
return; // Self-assignment is a no-op
}
assignDynList(list);
doAssignDynList(list);
}
@ -847,7 +852,7 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
std::initializer_list<T> lst
)
{
assignDynList(lst);
doAssignDynList(lst);
}
@ -858,7 +863,14 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
const IndirectListBase<T, Addr>& lst
)
{
assignDynList(lst);
// NOTE: Self-assignment needs special handling
/// if
/// (
/// static_cast<const UList<T>*>(this)
/// == static_cast<const UList<T>*>(&list.values())
/// )
doAssignDynList(lst);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.

View File

@ -159,7 +159,7 @@ public:
#include "SubListI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Implementations * * * * * * * * * * * * * * //
template<class Type>
Foam::SubList<Type>

View File

@ -74,6 +74,7 @@ template<class T> class List;
template<class T> class SubList;
template<class T> class UList;
template<class T> class IndirectList;
template<class T> class UIndirectList;
template<class T, class Addr> class IndirectListBase;
template<class T> Istream& operator>>(Istream&, UList<T>&);
@ -448,11 +449,11 @@ public:
// STL member functions
//- The number of elements in the UList
inline label size() const noexcept;
//- True if List is empty (ie, size() is zero)
bool empty() const noexcept { return !size_; }
//- True if the UList is empty (ie, size() is zero)
inline bool empty() const noexcept;
//- The number of elements in the List
label size() const noexcept { return size_; }
//- The size of the largest possible UList
static constexpr label max_size() noexcept { return labelMax; }

View File

@ -416,20 +416,6 @@ inline void Foam::UList<T>::setAddressableSize(const label n) noexcept
}
template<class T>
inline Foam::label Foam::UList<T>::size() const noexcept
{
return size_;
}
template<class T>
inline bool Foam::UList<T>::empty() const noexcept
{
return !size_;
}
template<class T>
inline void Foam::UList<T>::swap(UList<T>& list)
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2022 OpenCFD Ltd.
Copyright (C) 2018-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -42,10 +42,10 @@ inline constexpr Foam::PtrDynList<T, SizeMin>::PtrDynList() noexcept
template<class T, int SizeMin>
inline Foam::PtrDynList<T, SizeMin>::PtrDynList(const label len)
:
PtrList<T>(len),
capacity_(len)
PtrList<T>(),
capacity_(0)
{
PtrList<T>::setAddressableSize(0);
reserve(len);
}

View File

@ -211,12 +211,12 @@ public:
// Access
//- The number of elements in the list
inline label size() const noexcept;
//- True if the list is empty (ie, size() is zero)
inline bool empty() const noexcept;
//- The number of elements in the list
inline label size() const noexcept;
//- Reference to the first element of the list
inline T& front();

View File

@ -103,16 +103,16 @@ inline Foam::UPtrList<T>::UPtrList(UList<T>& list)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline Foam::label Foam::UPtrList<T>::size() const noexcept
inline bool Foam::UPtrList<T>::empty() const noexcept
{
return ptrs_.size();
return ptrs_.empty();
}
template<class T>
inline bool Foam::UPtrList<T>::empty() const noexcept
inline Foam::label Foam::UPtrList<T>::size() const noexcept
{
return ptrs_.empty();
return ptrs_.size();
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -76,7 +76,7 @@ class DynamicField
//- Copy assignment from another list
template<class ListType>
inline void assignDynList(const ListType& list);
inline void doAssignDynList(const ListType& list);
//- Alter the size of the underlying storage
// The 'nocopy' option will not attempt to recover old content
@ -178,21 +178,18 @@ public:
// Member Functions
// Access
// Sizing
//- Normal lower capacity limit - the SizeMin template parameter
static constexpr label min_size() noexcept { return SizeMin; }
//- Size of the underlying storage.
inline label capacity() const noexcept;
label capacity() const noexcept { return capacity_; }
//- Number of contiguous bytes of the underlying storage.
// \note Only meaningful for contiguous data
inline std::streamsize capacity_bytes() const noexcept;
// Sizing
//- Alter the size of the underlying storage.
// The addressed size will be truncated if needed to fit, but will
// remain otherwise untouched.
@ -305,10 +302,7 @@ public:
inline Istream& readList(Istream& is);
// Member Operators
//- Return non-const access to an element, resizing list if needed
inline T& operator()(const label i);
// Assignment
//- Assign addressed entries to the given value
inline void operator=(const T& val);
@ -322,6 +316,10 @@ public:
//- Copy assignment
inline void operator=(const DynamicField<T, SizeMin>& list);
//- Copy assign from IndirectList
template<class Addr>
inline void operator=(const IndirectListBase<T, Addr>& rhs);
//- Move assignment
inline void operator=(List<T>&& list);
@ -337,6 +335,12 @@ public:
inline void operator=(DynamicField<T, AnySizeMin>&& list);
// Member Operators
//- Return non-const access to an element, resizing list if needed
inline T& operator()(const label i);
// IOstream Operators
//- Use the readList() method to read contents from Istream.

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -30,7 +30,7 @@ License
template<class T, int SizeMin>
template<class ListType>
inline void Foam::DynamicField<T, SizeMin>::assignDynList
inline void Foam::DynamicField<T, SizeMin>::doAssignDynList
(
const ListType& list
)
@ -323,13 +323,6 @@ Foam::DynamicField<T, SizeMin>::clone() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, int SizeMin>
inline Foam::label Foam::DynamicField<T, SizeMin>::capacity() const noexcept
{
return capacity_;
}
template<class T, int SizeMin>
inline std::streamsize
Foam::DynamicField<T, SizeMin>::capacity_bytes() const noexcept
@ -716,7 +709,7 @@ inline void Foam::DynamicField<T, SizeMin>::operator=
const UList<T>& list
)
{
assignDynList(list);
doAssignDynList(list);
}
@ -731,7 +724,25 @@ inline void Foam::DynamicField<T, SizeMin>::operator=
return; // Self-assignment is a no-op
}
assignDynList(list);
doAssignDynList(list);
}
template<class T, int SizeMin>
template<class Addr>
inline void Foam::DynamicField<T, SizeMin>::operator=
(
const IndirectListBase<T, Addr>& list
)
{
// NOTE: Self-assignment needs special handling
/// if
/// (
/// static_cast<const UList<T>*>(this)
/// == static_cast<const UList<T>*>(&list.values())
/// )
doAssignDynList(list);
}

View File

@ -440,7 +440,7 @@ public:
const SubField<Type> slice(const labelRange& range) const;
// Member Operators
// Assignment
//- Copy assignment
void operator=(const Field<Type>&);
@ -460,14 +460,18 @@ public:
template<int SizeMin>
inline void operator=(DynamicList<Type, SizeMin>&& rhs);
//- Value assignment
//- Assign entries to the given value
inline void operator=(const Type& val);
//- Assign entries to zero
inline void operator=(const Foam::zero);
template<class Form, class Cmpt, direction nCmpt>
void operator=(const VectorSpace<Form,Cmpt,nCmpt>&);
// Member Operators
void operator+=(const UList<Type>&);
void operator+=(const tmp<Field<Type>>&);
@ -487,7 +491,7 @@ public:
void operator/=(const scalar&);
// IOstream operators
// IOstream Operators
friend Ostream& operator<< <Type>
(Ostream&, const Field<Type>&);