alternative Standard Libary  0.29.8
std::radix_sorter< T > Template-Klassenreferenz

#include <radix_sorter.hpp>

Öffentliche Typen

enum  data_type { data_unsigned = false, data_signed }
 

Öffentliche Methoden

template<data_type TDataType, typename TFunc >
void sort (T *src, int num, const TFunc &func, T *help_buffer)
 
template<data_type TDataType, typename TFunc >
void sort (T *src, int num, const TFunc &func)
 

Statische öffentliche Attribute

static const size_t kHistogramSize = 256
 

Ausführliche Beschreibung

template<typename T>
class std::radix_sorter< T >

Dokumentation der Aufzählungstypen

◆ data_type

template<typename T >
enum std::radix_sorter::data_type
Aufzählungswerte
data_unsigned 
data_signed 
45  {
46  data_unsigned = false,
48  };
Definition: radix_sorter.hpp:46
Definition: radix_sorter.hpp:47

Dokumentation der Elementfunktionen

◆ sort() [1/2]

template<typename T >
template<data_type TDataType, typename TFunc >
void std::radix_sorter< T >::sort ( T *  src,
int  num,
const TFunc &  func,
T *  help_buffer 
)
inline
52  {
53  if (num == 0) return;
54 
55  uint32_t histogram[kHistogramSize * 4];
56  Sys::MemSet(histogram, 0, sizeof(histogram));
57 
58  uint32_t* h1 = &histogram[0] + kHistogramSize;
59  uint32_t* h2 = h1 + kHistogramSize;
60  uint32_t* h3 = h2 + kHistogramSize;
61 
62  bool alreadySorted(true);
63  uint32_t prevValue = func(src[0]);
64 
65  int k(0);
66  for (int i = 0; i < num; ++i)
67  {
68  k = i;
69  const uint32_t x = func(src[i]);
70  if (alreadySorted && x < prevValue)
71  {
72  alreadySorted = false;
73  break;
74  }
75  const uint8_t* px = (const uint8_t*)&x;
76 
77  ++histogram[*px];
78  ++h1[px[1]];
79  ++h2[px[2]];
80  ++h3[px[3]];
81 
82  prevValue = x;
83  }
84  if (alreadySorted)
85  return;
86 
87  for (; k < num; ++k)
88  {
89  const uint32_t x = func(src[k]);
90  const uint8_t* px = (const uint8_t*)&x;
91 
92  ++histogram[*px];
93  ++h1[px[1]];
94  ++h2[px[2]];
95  ++h3[px[3]];
96  }
97 
98  const bool canBreakAfter16Bits = (h2[0] == (uint32_t)num && h3[0] == (uint32_t)num);
99  (void)canBreakAfter16Bits;
100 
101  if (TDataType == data_signed)
102  calculate_offsets_signed(histogram);
103  else
104  calculate_offsets(histogram);
105 
106  for (int i = 0; i < num; ++i)
107  {
108  const uint32_t pos = func(src[i]) & 0xFF;
109  help_buffer[histogram[pos]++] = src[i];
110  }
111 
112  for (int i = 0; i < num; ++i)
113  {
114  const uint32_t pos = (func(m_dst[i]) >> 8) & 0xFF;
115  src[h1[pos]++] = help_buffer[i];
116  }
117 
118  if (TDataType == data_unsigned && canBreakAfter16Bits)
119  return;
120 
121  for (int i = 0; i < num; ++i)
122  {
123  const uint32_t pos = (func(src[i]) >> 16) & 0xFF;
124  help_buffer[h2[pos]++] = src[i];
125  }
126 
127  for (int i = 0; i < num; ++i)
128  {
129  const uint32_t pos = (func(m_dst[i]) >> 24) & 0xFF;
130  src[h3[pos]++] = help_buffer[i];
131  }
132  }
Definition: radix_sorter.hpp:46
Definition: radix_sorter.hpp:47
static void MemSet(void *buf, unsigned char value, size_t bytes)
Definition: PLATFORM.cpp:47
static const size_t kHistogramSize
Definition: radix_sorter.hpp:42

◆ sort() [2/2]

template<typename T >
template<data_type TDataType, typename TFunc >
void std::radix_sorter< T >::sort ( T *  src,
int  num,
const TFunc &  func 
)
inline
136  {
137  if (num > m_dst.size())
138  resize(num);
139  sort<TDataType, TFunc>(src, num, func, m_dst.begin());
140  }
size_type size() const
Definition: vector.hpp:197
iterator begin()
Definition: vector.hpp:181

Dokumentation der Datenelemente

◆ kHistogramSize

template<typename T >
const size_t std::radix_sorter< T >::kHistogramSize = 256
static

Die Dokumentation für diese Klasse wurde erzeugt aufgrund der Datei: