Various utility functions to work on Lists. More...
Classes | |
struct | appendEqOp |
List helper to append y elements onto the end of x. More... | |
struct | greater |
A list compare binary predicate for reverse sort. More... | |
struct | less |
A list compare binary predicate for normal sort. More... | |
struct | unionEqOp |
List helper to add y unique elements to x. More... | |
struct | uniqueEqOp |
List helper to append y unique elements onto the end of x. More... | |
Functions | |
void | identity (labelUList &map, label start=0) |
Set identity map with (map[i] == i) More... | |
template<class ListType , class UnaryPredicate > | |
label | find (const ListType &input, const UnaryPredicate &pred, const label start=0) |
Find index of the first occurrence that satisfies the predicate. More... | |
template<class ListType , class UnaryPredicate > | |
bool | found (const ListType &input, const UnaryPredicate &pred, const label start=0) |
True if there is a value in the list that satisfies the predicate. More... | |
template<class ListType , class UnaryPredicate > | |
labelList | findIndices (const ListType &input, const UnaryPredicate &pred, label start=0) |
Linear search to find all occurences of given element. More... | |
template<class T > | |
void | setValue (UList< T > &list, const labelUList &locations, const T &val) |
Set various locations of the list with a specified value. More... | |
template<class T > | |
void | setValue (UList< T > &list, const labelHashSet &locations, const T &val) |
Set various locations of the list with a specified value. More... | |
template<class T > | |
void | setValue (UList< T > &list, const UList< bool > &locations, const T &val) |
Set various locations of the list with a specified value. More... | |
template<class T > | |
void | setValue (UList< T > &list, const bitSet &locations, const T &val) |
Set various locations of the list with a specified value. More... | |
template<class T , class T2 , class UnaryOperation > | |
List< T > | create (const UList< T2 > &input, const UnaryOperation &op) |
Create a List from a List of a dissimilar type, using the entire list. More... | |
template<class T , class InputIterator , class UnaryOperation > | |
List< T > | create (InputIterator first, InputIterator last, const UnaryOperation &op) |
Create a List from an iterator range [first,last) of a dissimilar type. More... | |
template<class T > | |
List< T > | createWithValue (const label len, const labelUList &locations, const T &val, const T &deflt=T()) |
template<class T > | |
List< T > | createWithValue (const label len, const labelHashSet &locations, const T &val, const T &deflt=T()) |
template<class T > | |
List< T > | createWithValue (const label len, const UList< bool > &locations, const T &val, const T &deflt=T()) |
template<class T > | |
List< T > | createWithValue (const label len, const bitSet &locations, const T &val, const T &deflt=T()) |
template<class T > | |
List< T > | createWithValue (const label len, const label index, const T &val, const T &deflt=T()) |
template<class T > | |
List< T > | createWithValue (const label len, const label index, T &&val, const T &deflt=T()) |
void identity | ( | labelUList & | map, |
label | start = 0 |
||
) |
Set identity map with (map[i] == i)
Optionally with an alternative start index, so that (map[i] == i+start)
Definition at line 203 of file ListOps.C.
References UList< T >::begin(), and UList< T >::end().
Referenced by SortableList< T >::partialReverseSort(), SortableList< T >::partialSort(), SortList< T >::reset(), SortList< T >::reverseSort(), and SortList< T >::sort().
label Foam::ListOps::find | ( | const ListType & | input, |
const UnaryPredicate & | pred, | ||
const label | start = 0 |
||
) |
Find index of the first occurrence that satisfies the predicate.
When start is specified, any occurrences before start are ignored. Linear search.
Referenced by distribution::add(), HashTable< Foam::autoPtr< Foam::interfaceCompositionModel > >::at(), IOstreamOption::compressionEnum(), face::edgeDirection(), HashPtrTable< exprResult >::erase(), HashTable< Foam::autoPtr< Foam::interfaceCompositionModel > >::erase(), objectRegistry::erase(), IndirectListBase< T, Addr >::found(), scalars::found(), FixedList< Type, 3 >::found(), UList< Foam::wordRe >::found(), found(), Enum< faceAction >::get(), isoSurfaceParams::getFilterType(), Enum< faceAction >::getOrDefault(), string::hasPath(), Enum< faceAction >::lookup(), HashTable< Foam::autoPtr< Foam::interfaceCompositionModel > >::operator()(), Enum< faceAction >::read(), Enum< faceAction >::readEntry(), HashPtrTable< exprResult >::release(), HashPtrTable< exprResult >::remove(), string::removeRepeated(), string::replace(), string::replaceAll(), regExpPosix::search(), cellTable::setName(), simpleObjectRegistry::setNamedValue(), simpleObjectRegistry::setValues(), exprString::valid(), face::which(), and Enum< faceAction >::write().
bool found | ( | const ListType & | input, |
const UnaryPredicate & | pred, | ||
const label | start = 0 |
||
) |
True if there is a value in the list that satisfies the predicate.
When start is specified, any occurrences before start are ignored. Linear search.
Definition at line 1156 of file ListOpsTemplates.C.
References find(), and Foam::input().
Referenced by starcdWriter::write(), writeObjects::write(), and starcdWriter::writeTemplate().
labelList Foam::ListOps::findIndices | ( | const ListType & | input, |
const UnaryPredicate & | pred, | ||
label | start = 0 |
||
) |
Linear search to find all occurences of given element.
void setValue | ( | UList< T > & | list, |
const labelUList & | locations, | ||
const T & | val | ||
) |
Set various locations of the list with a specified value.
list | the list to modify |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
Definition at line 1217 of file ListOpsTemplates.C.
References UList< T >::size().
void setValue | ( | UList< T > & | list, |
const labelHashSet & | locations, | ||
const T & | val | ||
) |
Set various locations of the list with a specified value.
list | the list to modify |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
Definition at line 1238 of file ListOpsTemplates.C.
References UList< T >::size().
Set various locations of the list with a specified value.
list | the list to modify |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
Definition at line 1259 of file ListOpsTemplates.C.
References Foam::BitOps::count(), stdFoam::end(), Foam::min(), and UList< T >::size().
Set various locations of the list with a specified value.
list | the list to modify |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
Definition at line 1282 of file ListOpsTemplates.C.
References bitSet::find_first(), bitSet::find_next(), Foam::pos(), and UList< T >::size().
List<T> Foam::ListOps::create | ( | InputIterator | first, |
InputIterator | last, | ||
const UnaryOperation & | op | ||
) |
Create a List from an iterator range [first,last) of a dissimilar type.
Uses std::distance for the size.
first | the begin of the iterator range |
last | the end of the iterator range |
op | the unary conversion operator, which can be used to convert to other types. |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const labelUList & | locations, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and various locations with another specified value.
len | the length of the list |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const labelHashSet & | locations, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and various locations with another specified value.
len | the length of the list |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const UList< bool > & | locations, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and various locations with another specified value.
len | the length of the list |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const bitSet & | locations, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and various locations with another specified value.
len | the length of the list |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const label | index, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and one specified value, which is copy assigned at the specified index
len | the length of the list |
index | where to apply the specified value. An out-of-range index is silently ignored. |
val | the value to copy assign at the specified index |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const label | index, | ||
T && | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and one specified value, which is move assigned at the specified index
len | the length of the list |
index | where to apply the specified value. An out-of-range index is silently ignored. |
val | the value to move assign at the specified index |
deflt | the initialization default value |
For example,