SortableList< T > Class Template Reference

A list that is sorted upon construction or when explicitly requested with the sort() method. More...

Public Member Functions

constexpr SortableList () noexcept
 Null constructor, sort later (eg, after assignment or transfer) More...
 
 SortableList (const label size)
 Construct given size, sort later. More...
 
 SortableList (const label size, const Foam::zero)
 Construct zero-initialized with given size, sort later. More...
 
 SortableList (const label size, const T &val)
 Construct given size and initial value, sorting later. More...
 
 SortableList (const SortableList< T > &lst)
 Copy construct. More...
 
 SortableList (SortableList< T > &&lst)
 Move construct. More...
 
 SortableList (const UList< T > &values)
 Copy construct from UList, sorting immediately. More...
 
 SortableList (List< T > &&values)
 Move construct from List, sorting immediately. More...
 
template<class InputIterator >
 SortableList (InputIterator begIter, InputIterator endIter)
 Construct given begin/end iterators. More...
 
 SortableList (std::initializer_list< T > values)
 Construct from an initializer list, sorting immediately. More...
 
const labelListindices () const
 Return the list of sorted indices. Updated every sort. More...
 
labelListindices ()
 Return non-const access to the sorted indices. Updated every sort. More...
 
void clear ()
 Clear the list and the indices. More...
 
List< T > & shrink ()
 Clear the indices and return a reference to the underlying List. More...
 
void sort ()
 Forward (stable) sort the list (if changed after construction). More...
 
void reverseSort ()
 Reverse (stable) sort the list. More...
 
void partialSort (label n, label start=0)
 Forward partial sort the list until the middle point. More...
 
void partialReverseSort (label n, label start=0)
 Reverse partial sort the list until the middle point. More...
 
void swap (SortableList< T > &lst)
 Swap content with another SortableList in constant time. More...
 
void operator= (const T &val)
 Assignment of all entries to the given value, removing indices. More...
 
void operator= (const UList< T > &lst)
 Assignment to UList operator, removing indices. Takes linear time. More...
 
void operator= (const SortableList< T > &lst)
 Assignment operator. Takes linear time. More...
 
void operator= (List< T > &&lst)
 Move assignment, removing indices. Takes linear time. More...
 
void operator= (SortableList< T > &&lst)
 Move operator. Takes linear time. More...
 
void operator= (std::initializer_list< T > lst)
 Assignment to an initializer list. More...
 

Detailed Description

template<class T>
class Foam::SortableList< T >

A list that is sorted upon construction or when explicitly requested with the sort() method.

Uses the std::stable_sort() algorithm.

Note
In many cases you may wish to reuse list storage. The Foam::sortedOrder() function and the Foam::SortList container provide two other alternatives.
Source files

Definition at line 63 of file List.H.

Constructor & Destructor Documentation

◆ SortableList() [1/10]

constexpr SortableList ( )
inlineconstexprnoexcept

Null constructor, sort later (eg, after assignment or transfer)

Definition at line 34 of file SortableList.C.

◆ SortableList() [2/10]

SortableList ( const label  size)
inlineexplicit

Construct given size, sort later.

The indices remain empty until the list is sorted

Definition at line 42 of file SortableList.C.

◆ SortableList() [3/10]

SortableList ( const label  size,
const Foam::zero   
)
inline

Construct zero-initialized with given size, sort later.

The indices remain empty until the list is sorted

Definition at line 49 of file SortableList.C.

◆ SortableList() [4/10]

SortableList ( const label  size,
const T val 
)
inline

Construct given size and initial value, sorting later.

The indices remain empty until the list is sorted

Definition at line 56 of file SortableList.C.

◆ SortableList() [5/10]

SortableList ( const SortableList< T > &  lst)
inline

Copy construct.

Definition at line 63 of file SortableList.C.

◆ SortableList() [6/10]

SortableList ( SortableList< T > &&  lst)
inline

Move construct.

Definition at line 71 of file SortableList.C.

◆ SortableList() [7/10]

SortableList ( const UList< T > &  values)
inlineexplicit

Copy construct from UList, sorting immediately.

Definition at line 79 of file SortableList.C.

References SortableList< T >::sort().

Here is the call graph for this function:

◆ SortableList() [8/10]

SortableList ( List< T > &&  values)
inline

Move construct from List, sorting immediately.

Definition at line 88 of file SortableList.C.

References SortableList< T >::sort().

Here is the call graph for this function:

◆ SortableList() [9/10]

SortableList ( InputIterator  begIter,
InputIterator  endIter 
)
inline

Construct given begin/end iterators.

Uses std::distance to determine the size.

Definition at line 99 of file SortableList.C.

References Foam::sort().

Here is the call graph for this function:

◆ SortableList() [10/10]

SortableList ( std::initializer_list< T values)
inline

Construct from an initializer list, sorting immediately.

Definition at line 111 of file SortableList.C.

References SortableList< T >::sort().

Here is the call graph for this function:

Member Function Documentation

◆ indices() [1/2]

const labelList& indices ( ) const
inline

Return the list of sorted indices. Updated every sort.

Definition at line 113 of file SortableList.H.

Referenced by primitiveMesh::checkPointNearness(), commSchedule::commSchedule(), faMesh::faMesh(), searchableBox::findNearestOnEdge(), triangleFuncs::intersect(), Foam::matchPoints(), SortableList< T >::operator=(), SprayCloud< Foam::DSMCCloud >::penetration(), faceCollapser::setRefinement(), ParSortableList< Type >::sort(), and PatchTools::sortedEdgeFaces().

Here is the caller graph for this function:

◆ indices() [2/2]

labelList& indices ( )
inline

Return non-const access to the sorted indices. Updated every sort.

Definition at line 119 of file SortableList.H.

◆ clear()

void clear ( )

Clear the list and the indices.

Definition at line 122 of file SortableList.C.

References List< T >::clear().

Here is the call graph for this function:

◆ shrink()

Foam::List< T > & shrink ( )

Clear the indices and return a reference to the underlying List.

Definition at line 130 of file SortableList.C.

Referenced by DynamicList< Foam::triPoints >::transfer(), and List< substance >::transfer().

Here is the caller graph for this function:

◆ sort()

void sort ( )

Forward (stable) sort the list (if changed after construction).

Resizes the indices as required

Definition at line 138 of file SortableList.C.

References Foam::sortedOrder(), and List< T >::transfer().

Referenced by searchableBox::findNearestOnEdge(), triangleFuncs::intersect(), SprayCloud< Foam::DSMCCloud >::penetration(), faceCollapser::setRefinement(), SortableList< T >::SortableList(), and PatchTools::sortedEdgeFaces().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reverseSort()

void reverseSort ( )

Reverse (stable) sort the list.

Resizes the indices as required

Definition at line 148 of file SortableList.C.

References Foam::sortedOrder(), and List< T >::transfer().

Here is the call graph for this function:

◆ partialSort()

void partialSort ( label  n,
label  start = 0 
)

Forward partial sort the list until the middle point.

Definition at line 158 of file SortableList.C.

References Foam::ListOps::identity(), Foam::less(), n, and List< T >::transfer().

Here is the call graph for this function:

◆ partialReverseSort()

void partialReverseSort ( label  n,
label  start = 0 
)

Reverse partial sort the list until the middle point.

Definition at line 178 of file SortableList.C.

References Foam::ListOps::identity(), n, and List< T >::transfer().

Here is the call graph for this function:

◆ swap()

void swap ( SortableList< T > &  lst)
inline

Swap content with another SortableList in constant time.

Definition at line 198 of file SortableList.C.

Referenced by Foam::Swap().

Here is the caller graph for this function:

◆ operator=() [1/6]

void operator= ( const T val)
inline

Assignment of all entries to the given value, removing indices.

Definition at line 213 of file SortableList.C.

References UList< T >::operator=().

Here is the call graph for this function:

◆ operator=() [2/6]

void operator= ( const UList< T > &  lst)
inline

Assignment to UList operator, removing indices. Takes linear time.

Definition at line 221 of file SortableList.C.

References List< T >::operator=().

Here is the call graph for this function:

◆ operator=() [3/6]

void operator= ( const SortableList< T > &  lst)
inline

Assignment operator. Takes linear time.

Definition at line 229 of file SortableList.C.

References SortableList< T >::indices(), and List< T >::operator=().

Here is the call graph for this function:

◆ operator=() [4/6]

void operator= ( List< T > &&  lst)
inline

Move assignment, removing indices. Takes linear time.

Definition at line 242 of file SortableList.C.

References List< T >::transfer().

Here is the call graph for this function:

◆ operator=() [5/6]

void operator= ( SortableList< T > &&  lst)
inline

Move operator. Takes linear time.

Definition at line 250 of file SortableList.C.

References clear().

Here is the call graph for this function:

◆ operator=() [6/6]

void operator= ( std::initializer_list< T lst)
inline

Assignment to an initializer list.

Definition at line 263 of file SortableList.C.

References List< T >::operator=(), and Foam::sort().

Here is the call graph for this function:

The documentation for this class was generated from the following files: