Go to the documentation of this file.
35 template<
class IntListType>
39 const IntListType&
input
42 const label len =
input.size();
47 for (label i=0; i < len; ++i)
59 template<
class IntListType>
66 const label len =
input.size();
68 for (label i=0; i < len; ++i)
78 template<
class ListType>
82 const ListType&
input,
86 const label len =
input.size();
92 for (label i=0; i < len; ++i)
94 const label newIdx = oldToNew[i];
122 template<
class ListType>
126 ListType& inputOutput,
136 const ListType&
input = inputOutput;
137 const label len =
input.size();
143 for (label i=0; i < len; ++i)
145 const label newIdx = oldToNew[i];
169 inputOutput.transfer(
output);
173 template<
unsigned W
idth>
177 const PackedList<Width>&
input,
181 const label len =
input.size();
183 PackedList<Width>
output(len);
186 for (label i=0; i < len; ++i)
188 const auto& val =
input.get(i);
190 const label newIdx = oldToNew[i];
223 template<
unsigned W
idth>
238 template<
class Container>
247 for (
auto iter =
input.begin(); iter !=
input.end(); ++iter)
249 const label oldIdx = iter.key();
255 output.insert(oldToNew[oldIdx], iter.val());
263 template<
class Container>
272 for (
auto iter =
input.begin(); iter !=
input.end(); ++iter)
274 const label oldIdx = iter.val();
280 const label newIdx = oldToNew[oldIdx];
282 if (oldIdx != newIdx)
294 template<
class Container>
297 const Map<label>& mapper,
308 for (
auto iter =
input.begin(); iter !=
input.end(); ++iter)
310 label& value = iter.val();
312 auto mapIter = mapper.find(value);
313 if (mapIter.found() && value != *mapIter)
327 const UList<T>&
input
347 template<
class T,
class ListComparePredicate>
352 const ListComparePredicate& comp
355 const label len =
input.size();
358 if (order.size() != len)
374 const UList<T>&
input
394 template<
class T,
class ListComparePredicate>
399 const ListComparePredicate& comp
402 if (
input.size() < 2)
410 const label last = (order.size()-1);
412 for (label i = 0; i < last; ++i)
416 order[
count] = order[i];
427 const UList<T>&
input
447 template<
class T,
class ListComparePredicate>
452 const ListComparePredicate& comp
457 if (order.size() > 1)
459 const label last = (order.size()-1);
461 for (label i = 0; i < last; ++i)
465 order[
count++] = order[i];
468 order[
count++] = order[last];
474 template<
class ListType>
485 template<
class ListType,
class ListComparePredicate>
489 const ListComparePredicate& comp
495 const label len = order.size();
500 for (label i=0; i < len; ++i)
509 template<
class BoolListType,
class T>
512 const BoolListType& select,
513 const UList<T>&
input,
519 const label len =
input.size();
525 for (label i=0; i < len; ++i)
543 const bitSet& select,
544 const UList<T>&
input,
548 const label len =
input.size();
556 output.resize(select.count());
558 for (
const label i : select)
568 const label outlen = (select.size() - select.count());
571 for (label i=0; i < len; ++i)
577 if (
count >= outlen)
break;
588 template<
class BoolListType,
class ListType>
591 const BoolListType& select,
598 const label len =
input.size();
602 for (label i=0; i < len; ++i)
618 template<
class ListType>
632 const label len =
input.size();
634 for (
const label i : select)
649 const label outlen = (select.
size() - select.
count());
653 for (label i=0; i < len; ++i)
662 if (
count >= outlen)
break;
671 template<
class T,
class UnaryPredicate>
674 const UList<T>&
input,
675 const UnaryPredicate& pred,
679 const label len =
input.size();
684 for (label i=0; i < len; ++i)
699 template<
class ListType,
class UnaryPredicate>
703 const UnaryPredicate& pred,
707 const label len =
input.size();
710 for (label i=0; i < len; ++i)
725 template<
class InputIntListType,
class OutputIntListType>
736 for (
const InputIntListType& sublist :
input)
740 sizes[sublist[idx]]++;
748 output[outi].resize(sizes[outi]);
755 const InputIntListType& sublist =
input[listi];
759 const label outi = sublist[idx];
761 output[outi][sizes[outi]++] = listi;
767 template<
class ListType>
770 const ListType&
input,
771 typename ListType::const_reference val,
775 const label len =
input.size();
782 for (label i = start; i < len; ++i)
786 if (!
count) start = i;
797 const label total =
count;
799 for (label i = start; i < len; ++i)
804 if (++
count == total)
816 template<
class ListType>
819 const ListType&
input,
823 const label len =
input.size();
825 if (start < 0 || start >= len)
830 for (label i = start+1; i < len; ++i)
842 template<
class ListType>
845 const ListType&
input,
849 const label len =
input.size();
851 if (start < 0 || start >= len)
856 for (label i = start+1; i < len; ++i)
868 template<
class ListType>
871 const ListType&
input,
875 const label len =
input.size();
877 if (start < 0 || start >= len)
882 label minIdx = start;
883 label maxIdx = start;
885 for (label i = start+1; i < len; ++i)
901 template<
class ListType>
904 const ListType&
input,
905 typename ListType::const_reference val,
910 label high =
input.size() - 1;
912 if (start < 0 || start >=
input.size())
919 const label mid = (low + high)/2;
921 if (val <
input[mid])
925 else if (
input[mid] < val)
939 template<
class ListType,
class T,
class ComparePredicate>
942 const ListType&
input,
945 const ComparePredicate& comp
949 label high =
input.size() - 1;
951 if (start < 0 || start >=
input.size())
956 while ((high - low) > 1)
958 const label mid = (low + high)/2;
960 if (comp(
input[mid], val))
970 if (comp(
input[high], val))
974 else if (comp(
input[low], val))
985 template<
class ListType,
class T>
988 const ListType&
input,
1003 template<
class ListType>
1006 const label len =
input.size();
1007 const label last = (len - 1);
1012 for (label i=0; i < len; ++i)
1021 template<
class ListType>
1024 const label len =
input.size();
1025 const label last = (len - 1);
1026 const label n2 = len >> 1;
1028 for (label i=0; i<n2; ++i)
1035 template<
class ListType>
1038 const label len =
input.size();
1043 for (label i=0; i<len; ++i)
1045 label index = (i -
n) % len;
1059 template<
template<
typename>
class ListType,
class DataType>
1062 const label len =
input.size();
1064 n = (len -
n) % len;
1092 label len =
x.size();
1095 x.resize(len +
y.size());
1096 for (
const T& val :
y)
1120 for (
const T& val :
y)
1136 template<
class ListType,
class UnaryPredicate>
1139 const ListType&
input,
1140 const UnaryPredicate& pred,
1144 const label len =
input.size();
1148 for (label i = start; i < len; ++i)
1161 template<
class ListType,
class UnaryPredicate>
1164 const ListType&
input,
1165 const UnaryPredicate& pred,
1173 template<
class ListType,
class UnaryPredicate>
1176 const ListType&
input,
1177 const UnaryPredicate& pred,
1181 const label len =
input.size();
1188 for (label i = start; i < len; ++i)
1192 if (!
count) start = i;
1203 const label total =
count;
1205 for (label i = start; i < len; ++i)
1210 if (++
count == total)
1230 const label len = list.
size();
1232 for (
const label index : locations)
1235 if (index >= 0 && index < len)
1251 const label len = list.
size();
1253 for (
const label index : locations)
1256 if (index >= 0 && index < len)
1272 const label len = list.
size();
1277 for (label index = 0; index <
end; ++index)
1279 if (locations[index])
1295 const label len = list.
size();
1309 template<
class T,
class T2,
class UnaryOperation>
1313 const UnaryOperation& op
1316 const label len =
input.size();
1325 for (label i = 0; i < len; ++i)
1335 template<
class T,
class InputIterator,
class UnaryOperation>
1338 InputIterator first,
1340 const UnaryOperation& op
1351 while (first != last)
1372 List<T> list(len, deflt);
1388 List<T> list(len, deflt);
1399 const UList<bool>& locations,
1404 List<T> list(len, deflt);
1415 const bitSet& locations,
1420 List<T> list(len, deflt);
1436 List<T> list(len, deflt);
1439 if (index >= 0 && index < len)
1457 List<T> list(len, deflt);
1460 if (index >= 0 && index < len)
1462 list[index] = std::move(val);
List< label > labelList
A List of labels.
label find_first() const
Locate the first bit that is set.
static Ostream & output(Ostream &os, const IntRange< T > &range)
void inplaceSubsetList(ListType &input, const UnaryPredicate &pred, const bool invert=false)
Inplace subset of the list when predicate is true.
void inplaceReverseList(ListType &input)
Inplace reversal of a list using Swap.
labelList uniqueOrder(const UList< T > &input)
Return (sorted) indices corresponding to unique list values.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
static constexpr const zero Zero
Global zero (0)
static bool less(const vector &x, const vector &y)
To compare normals.
A List obtained as a section of another List.
List< T > create(const UList< T2 > &input, const UnaryOperation &op)
Create a List from a List of a dissimilar type, using the entire list.
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
void inplaceRotateList(ListType< DataType > &list, label n)
Inplace reversal of a list using the Reversal Block Swapping algorithm.
void inplaceUniqueSort(ListType &input)
Inplace sorting and removal of duplicates.
List< T > createWithValue(const label len, const labelUList &locations, const T &val, const T &deflt=T())
void Swap(DynamicList< T, SizeMin1 > &a, DynamicList< T, SizeMin2 > &b)
unsigned int count(const bool on=true) const
Count number of bits set.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values (not the indices) of a list.
#define forAll(list, i)
Loop across all elements in list.
void stableSort(UList< T > &a)
void invertManyToMany(const label len, const UList< InputIntListType > &input, List< OutputIntListType > &output)
Invert many-to-many.
Pair< label > labelPair
A pair of labels.
labelPair findMinMax(const ListType &input, label start=0)
labelList findIndices(const ListType &input, const UnaryPredicate &pred, label start=0)
Linear search to find all occurences of given element.
void inplaceMapKey(const labelUList &oldToNew, Container &input)
Rewrite with mapped keys. Ignore elements with negative key.
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
ListType reorder(const labelUList &oldToNew, const ListType &input, const bool prune=false)
Reorder the elements of a list.
A list compare binary predicate for normal sort.
label findSortedIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
label inplaceMapValue(const labelUList &oldToNew, Container &input)
Map values. Ignore negative values.
void resize(const label newSize)
Adjust allocated size of list.
labelList duplicateOrder(const UList< T > &input)
Return (sorted) indices corresponding to duplicate list values.
label find_next(label pos) const
Locate the next bit set, starting one beyond the specified position.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
ListType rotateList(const ListType &list, const label n)
Rotate a list by n places.
List helper to append y unique elements onto the end of x.
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
scalar distance(const vector &p1, const vector &p2)
List helper to append y elements onto the end of x.
ListType reverseList(const ListType &input)
Reverse a list. First element becomes last element etc.
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values (not the indices) of a list.
#define List_CONST_ACCESS(type, f, fp)
An ordered pair of two objects of type <T> with first() and second() elements.
void setValue(UList< T > &list, const labelUList &locations, const T &val)
Set various locations of the list with a specified value.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
label findMax(const ListType &input, label start=0)
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
label size() const noexcept
Number of entries.
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
void clear()
Clear the list, i.e. set size to zero.
static Istream & input(Istream &is, IntRange< T > &range)
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.
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Inplace reorder the elements of a list.
Various functions to operate on Lists.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
UList< label > labelUList
A UList of labels.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys and label hasher.
#define List_ACCESS(type, f, fp)
label findMin(const ListType &input, label start=0)
Macros for accessing List elements.
dimensionedScalar pos(const dimensionedScalar &ds)
List< T > subsetList(const UList< T > &input, const UnaryPredicate &pred, const bool invert=false)
Copy a subset of the input list when predicate is true.