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
11 
12 #include "pxr/pxr.h"
14 
15 #include <tbb/parallel_sort.h>
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()) {
28  tbb::parallel_sort(container->begin(), container->end());
29  }else{
30  std::sort(container->begin(), container->end());
31  }
32 }
33 
34 
35 /// Sorts in-place a container that provides begin() and end() methods,
36 /// using a custom comparison functor.
37 ///
38 template <typename C, typename Compare>
39 void
40 WorkParallelSort(C* container, const Compare& comp)
41 {
42  // Don't bother with parallel_for, if concurrency is limited to 1.
43  if (WorkHasConcurrency()) {
44  tbb::parallel_sort(container->begin(), container->end(), comp);
45  }else{
46  std::sort(container->begin(), container->end(), comp);
47  }
48 }
49 
51 
52 #endif
PUGI__FN void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7550
WORK_API bool WorkHasConcurrency()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
PXR_NAMESPACE_OPEN_SCOPE void WorkParallelSort(C *container)
Definition: sort.h:24