Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare > Class Template Reference

Range used in quicksort to split elements into subranges based on a value. More...

#include <parallel_sort.h>

Inheritance diagram for tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >:
Collaboration diagram for tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >:

Public Member Functions

 quick_sort_range (RandomAccessIterator begin_, size_t size_, const Compare &comp_)
 
bool empty () const
 
bool is_divisible () const
 
 quick_sort_range (quick_sort_range &range, split)
 

Public Attributes

const Compare & comp
 
size_t size
 
RandomAccessIterator begin
 

Static Public Attributes

static const size_t grainsize = 500
 

Private Member Functions

size_t median_of_three (const RandomAccessIterator &array, size_t l, size_t m, size_t r) const
 
size_t pseudo_median_of_nine (const RandomAccessIterator &array, const quick_sort_range &range) const
 
size_t split_range (quick_sort_range &range)
 
- Private Member Functions inherited from tbb::internal::no_assign
void operator= (const no_assign &)=delete
 
 no_assign (const no_assign &)=default
 
 no_assign ()=default
 

Detailed Description

template<typename RandomAccessIterator, typename Compare>
class tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >

Range used in quicksort to split elements into subranges based on a value.

The split operation selects a splitter and places all elements less than or equal to the value in the first range and the remaining elements in the second range.

Definition at line 46 of file parallel_sort.h.

Constructor & Destructor Documentation

◆ quick_sort_range() [1/2]

template<typename RandomAccessIterator, typename Compare>
tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::quick_sort_range ( RandomAccessIterator  begin_,
size_t  size_,
const Compare &  comp_ 
)
inline

Definition at line 106 of file parallel_sort.h.

◆ quick_sort_range() [2/2]

template<typename RandomAccessIterator, typename Compare>
tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::quick_sort_range ( quick_sort_range< RandomAccessIterator, Compare > &  range,
split   
)
inline

Definition at line 112 of file parallel_sort.h.

113  : comp(range.comp)
114  , size(split_range(range))
115  // +1 accounts for the pivot element, which is at its correct place
116  // already and, therefore, is not included into subranges.
117  , begin(range.begin+range.size+1) {}
size_t split_range(quick_sort_range &range)
Definition: parallel_sort.h:62

Member Function Documentation

◆ empty()

template<typename RandomAccessIterator, typename Compare>
bool tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::empty ( ) const
inline

◆ is_divisible()

template<typename RandomAccessIterator, typename Compare>
bool tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::is_divisible ( ) const
inline

◆ median_of_three()

template<typename RandomAccessIterator, typename Compare>
size_t tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::median_of_three ( const RandomAccessIterator &  array,
size_t  l,
size_t  m,
size_t  r 
) const
inlineprivate

Definition at line 48 of file parallel_sort.h.

48  {
49  return comp(array[l], array[m]) ? ( comp(array[m], array[r]) ? m : ( comp( array[l], array[r]) ? r : l ) )
50  : ( comp(array[r], array[m]) ? m : ( comp( array[r], array[l] ) ? r : l ) );
51  }

References tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::comp.

Referenced by tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::pseudo_median_of_nine().

Here is the caller graph for this function:

◆ pseudo_median_of_nine()

template<typename RandomAccessIterator, typename Compare>
size_t tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::pseudo_median_of_nine ( const RandomAccessIterator &  array,
const quick_sort_range< RandomAccessIterator, Compare > &  range 
) const
inlineprivate

Definition at line 53 of file parallel_sort.h.

53  {
54  size_t offset = range.size/8u;
55  return median_of_three(array,
56  median_of_three(array, 0, offset, offset*2),
57  median_of_three(array, offset*3, offset*4, offset*5),
58  median_of_three(array, offset*6, offset*7, range.size - 1) );
59 
60  }
size_t median_of_three(const RandomAccessIterator &array, size_t l, size_t m, size_t r) const
Definition: parallel_sort.h:48

References tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::median_of_three(), and tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::size.

Referenced by tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::split_range().

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

◆ split_range()

template<typename RandomAccessIterator, typename Compare>
size_t tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::split_range ( quick_sort_range< RandomAccessIterator, Compare > &  range)
inlineprivate

Definition at line 62 of file parallel_sort.h.

62  {
63  using std::iter_swap;
64  RandomAccessIterator array = range.begin;
65  RandomAccessIterator key0 = range.begin;
66  size_t m = pseudo_median_of_nine(array, range);
67  if (m) iter_swap ( array, array+m );
68 
69  size_t i=0;
70  size_t j=range.size;
71  // Partition interval [i+1,j-1] with key *key0.
72  for(;;) {
73  __TBB_ASSERT( i<j, NULL );
74  // Loop must terminate since array[l]==*key0.
75  do {
76  --j;
77  __TBB_ASSERT( i<=j, "bad ordering relation?" );
78  } while( comp( *key0, array[j] ));
79  do {
80  __TBB_ASSERT( i<=j, NULL );
81  if( i==j ) goto partition;
82  ++i;
83  } while( comp( array[i],*key0 ));
84  if( i==j ) goto partition;
85  iter_swap( array+i, array+j );
86  }
87 partition:
88  // Put the partition key were it belongs
89  iter_swap( array+j, key0 );
90  // array[l..j) is less or equal to key.
91  // array(j..r) is greater or equal to key.
92  // array[j] is equal to key
93  i=j+1;
94  size_t new_range_size = range.size-i;
95  range.size = j;
96  return new_range_size;
97  }
size_t pseudo_median_of_nine(const RandomAccessIterator &array, const quick_sort_range &range) const
Definition: parallel_sort.h:53
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

References __TBB_ASSERT, tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::begin, tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::comp, tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::pseudo_median_of_nine(), and tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::size.

Here is the call graph for this function:

Member Data Documentation

◆ begin

template<typename RandomAccessIterator, typename Compare>
RandomAccessIterator tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::begin

◆ comp

◆ grainsize

template<typename RandomAccessIterator, typename Compare>
const size_t tbb::interface9::internal::quick_sort_range< RandomAccessIterator, Compare >::grainsize = 500
static

◆ size


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

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.