HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sort.h
Go to the documentation of this file.
1 //
2 // Copyright 2024 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_WORK_SORT_H
8 #define PXR_BASE_WORK_SORT_H
9 
10 /// \file work/sort.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/base/work/impl.h"
15 
16 #include <algorithm>
17 
19 
20 /// Sorts in-place a container that provides begin() and end() methods
21 ///
22 template <typename C>
23 void
24 WorkParallelSort(C* container)
25 {
26  // Don't bother with parallel_for, if concurrency is limited to 1.
27  if (WorkHasConcurrency()) {
29  WorkImpl_ParallelSort(container);
30  }else{
31  std::sort(container->begin(), container->end());
32  }
33 }
34 
35 
36 /// Sorts in-place a container that provides begin() and end() methods,
37 /// using a custom comparison functor.
38 ///
39 template <typename C, typename Compare>
40 void
41 WorkParallelSort(C* container, const Compare& comp)
42 {
43  // Don't bother with parallel_for, if concurrency is limited to 1.
44  if (WorkHasConcurrency()) {
46  WorkImpl_ParallelSort(container, comp);
47  }else{
48  std::sort(container->begin(), container->end(), comp);
49  }
50 }
51 
53 
54 #endif
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
PUGI__FN void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7550
WORK_API bool WorkHasConcurrency()
PXR_NAMESPACE_OPEN_SCOPE void WorkImpl_ParallelSort(C *container)
Definition: sort_impl.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
PXR_NAMESPACE_OPEN_SCOPE void WorkParallelSort(C *container)
Definition: sort.h:24
#define PXR_WORK_IMPL_NAMESPACE_USING_DIRECTIVE
Definition: impl.h:17