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
 Default construct. 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...
 
 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 > &other)
 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 (constant 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 60 of file List.H.

Constructor & Destructor Documentation

◆ SortableList() [1/9]

constexpr SortableList ( )
inlineconstexprnoexcept

Default construct.

Definition at line 34 of file SortableList.C.

◆ SortableList() [2/9]

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/9]

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/9]

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/9]

SortableList ( const SortableList< T > &  lst)
inline

Copy construct.

Definition at line 63 of file SortableList.C.

◆ SortableList() [6/9]

SortableList ( SortableList< T > &&  lst)
inline

Move construct.

Definition at line 71 of file SortableList.C.

◆ SortableList() [7/9]

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/9]

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/9]

SortableList ( std::initializer_list< T values)
inline

Construct from an initializer list, sorting immediately.

Definition at line 97 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 108 of file SortableList.H.

Referenced by primitiveMesh::checkPointNearness(), commSchedule::commSchedule(), 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 114 of file SortableList.H.

◆ clear()

void clear ( )

Clear the list and the indices.

Definition at line 108 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 116 of file SortableList.C.

Referenced by DynamicList< Foam::FixedList< scalar, 3 > >::transfer(), and List< vectorField >::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 124 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 134 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 144 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 164 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 > &  other)
inline

Swap content with another SortableList in constant time.

Definition at line 184 of file SortableList.C.

◆ operator=() [1/6]

void operator= ( const T val)
inline

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

Definition at line 199 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 207 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 215 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 228 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 (constant time)

Definition at line 236 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 249 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: