niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 1 | /* |
mflodman@webrtc.org | c80d9d9 | 2012-02-06 10:11:25 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // When the platform supports STL, the functions are implemented using a |
| 12 | // templated spreadsort algorithm (http://sourceforge.net/projects/spreadsort/), |
| 13 | // part of the Boost C++ library collection. Otherwise, the C standard library's |
| 14 | // qsort() will be used. |
| 15 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/interface/sort.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 17 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 | [diff] [blame] | 18 | #include <assert.h> |
| 19 | #include <string.h> // memcpy |
| 20 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 21 | #include <new> // nothrow new |
| 22 | |
| 23 | #ifdef NO_STL |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 | [diff] [blame] | 24 | #include <stdlib.h> // qsort |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 25 | #else |
| 26 | #include <algorithm> // std::sort |
| 27 | #include <vector> |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 28 | |
pbos@webrtc.org | acaf3a1 | 2013-05-27 15:07:45 | [diff] [blame] | 29 | // TODO(ajm) upgrade to spreadsort v2. |
| 30 | #include "webrtc/system_wrappers/source/spreadsortlib/spreadsort.hpp" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | #ifdef NO_STL |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 34 | #define COMPARE_DEREFERENCED(XT, YT) \ |
| 35 | do { \ |
| 36 | if ((XT) > (YT)) { \ |
| 37 | return 1; \ |
| 38 | } \ |
| 39 | else if ((XT) < (YT)) { \ |
| 40 | return -1; \ |
| 41 | } \ |
| 42 | return 0; \ |
| 43 | } while(0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 44 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 45 | #define COMPARE_FOR_QSORT(X, Y, TYPE) \ |
| 46 | do { \ |
| 47 | TYPE xT = static_cast<TYPE>(*static_cast<const TYPE*>(X)); \ |
| 48 | TYPE yT = static_cast<TYPE>(*static_cast<const TYPE*>(Y)); \ |
| 49 | COMPARE_DEREFERENCED(xT, yT); \ |
| 50 | } while(0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 51 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 52 | #define COMPARE_KEY_FOR_QSORT(SORT_KEY_X, SORT_KEY_Y, TYPE) \ |
| 53 | do { \ |
| 54 | TYPE xT = static_cast<TYPE>( \ |
| 55 | *static_cast<TYPE*>(static_cast<const SortKey*>(SORT_KEY_X)->key_)); \ |
| 56 | TYPE yT = static_cast<TYPE>( \ |
| 57 | *static_cast<TYPE*>(static_cast<const SortKey*>(SORT_KEY_Y)->key_)); \ |
| 58 | COMPARE_DEREFERENCED(xT, yT); \ |
| 59 | } while(0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 60 | |
| 61 | #define KEY_QSORT(SORT_KEY, KEY, NUM_OF_ELEMENTS, KEY_TYPE, COMPARE_FUNC) \ |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 62 | do { \ |
| 63 | KEY_TYPE* key_type = (KEY_TYPE*)(key); \ |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 64 | for (uint32_t i = 0; i < (NUM_OF_ELEMENTS); ++i) { \ |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 65 | ptr_sort_key[i].key_ = &key_type[i]; \ |
| 66 | ptr_sort_key[i].index_ = i; \ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 67 | } \ |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 68 | qsort((SORT_KEY), (NUM_OF_ELEMENTS), sizeof(SortKey), (COMPARE_FUNC)); \ |
| 69 | } while(0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 70 | #endif |
| 71 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 72 | namespace webrtc { |
| 73 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 74 | #ifdef NO_STL |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 75 | struct SortKey { |
| 76 | void* key_; |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 77 | uint32_t index_; |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 78 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 79 | #else |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 80 | template<typename KeyType> |
| 81 | struct SortKey { |
| 82 | KeyType key_; |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 83 | uint32_t index_; |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 84 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 85 | #endif |
| 86 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 87 | namespace { // Unnamed namespace provides internal linkage. |
| 88 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 89 | #ifdef NO_STL |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 90 | int CompareWord8(const void* x, const void* y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 91 | COMPARE_FOR_QSORT(x, y, int8_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 92 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 93 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 94 | int CompareUWord8(const void* x, const void* y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 95 | COMPARE_FOR_QSORT(x, y, uint8_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 96 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 97 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 98 | int CompareWord16(const void* x, const void* y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 99 | COMPARE_FOR_QSORT(x, y, int16_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 100 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 101 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 102 | int CompareUWord16(const void* x, const void* y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 103 | COMPARE_FOR_QSORT(x, y, uint16_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 104 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 105 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 106 | int CompareWord32(const void* x, const void* y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 107 | COMPARE_FOR_QSORT(x, y, int32_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 108 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 109 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 110 | int CompareUWord32(const void* x, const void* y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 111 | COMPARE_FOR_QSORT(x, y, uint32_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 112 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 113 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 114 | int CompareWord64(const void* x, const void* y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 115 | COMPARE_FOR_QSORT(x, y, int64_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 116 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 117 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 118 | int CompareUWord64(const void* x, const void* y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 119 | COMPARE_FOR_QSORT(x, y, uint64_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 120 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 121 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 122 | int CompareFloat32(const void* x, const void* y) { |
| 123 | COMPARE_FOR_QSORT(x, y, float); |
| 124 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 125 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 126 | int CompareFloat64(const void* x, const void* y) { |
| 127 | COMPARE_FOR_QSORT(x, y, double); |
| 128 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 129 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 130 | int CompareKeyWord8(const void* sort_key_x, const void* sort_key_y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 131 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, int8_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 132 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 133 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 134 | int CompareKeyUWord8(const void* sort_key_x, const void* sort_key_y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 135 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, uint8_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 136 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 137 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 138 | int CompareKeyWord16(const void* sort_key_x, const void* sort_key_y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 139 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, int16_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 140 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 141 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 142 | int CompareKeyUWord16(const void* sort_key_x, const void* sort_key_y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 143 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, uint16_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 144 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 145 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 146 | int CompareKeyWord32(const void* sort_key_x, const void* sort_key_y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 147 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, int32_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 148 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 149 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 150 | int CompareKeyUWord32(const void* sort_key_x, const void* sort_key_y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 151 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, uint32_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 152 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 153 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 154 | int CompareKeyWord64(const void* sort_key_x, const void* sort_key_y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 155 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, int64_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 156 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 157 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 158 | int CompareKeyUWord64(const void* sort_key_x, const void* sort_key_y) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 159 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, uint64_t); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 160 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 161 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 162 | int CompareKeyFloat32(const void* sort_key_x, const void* sort_key_y) { |
| 163 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, float); |
| 164 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 165 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 166 | int CompareKeyFloat64(const void* sort_key_x, const void* sort_key_y) { |
| 167 | COMPARE_KEY_FOR_QSORT(sort_key_x, sort_key_y, double); |
| 168 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 169 | #else |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 170 | template <typename KeyType> |
| 171 | struct KeyLessThan { |
| 172 | bool operator()(const SortKey<KeyType>& sort_key_x, |
| 173 | const SortKey<KeyType>& sort_key_y) const { |
| 174 | return sort_key_x.key_ < sort_key_y.key_; |
| 175 | } |
| 176 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 177 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 178 | template <typename KeyType> |
| 179 | struct KeyRightShift { |
| 180 | KeyType operator()(const SortKey<KeyType>& sort_key, |
| 181 | const unsigned offset) const { |
| 182 | return sort_key.key_ >> offset; |
| 183 | } |
| 184 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 185 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 186 | template <typename DataType> |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 187 | inline void IntegerSort(void* data, uint32_t num_of_elements) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 188 | DataType* data_type = static_cast<DataType*>(data); |
| 189 | boost::integer_sort(data_type, data_type + num_of_elements); |
| 190 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 191 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 192 | template <typename DataType, typename IntegerType> |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 193 | inline void FloatSort(void* data, uint32_t num_of_elements) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 194 | DataType* data_type = static_cast<DataType*>(data); |
| 195 | IntegerType c_val = 0; |
| 196 | boost::float_sort_cast(data_type, data_type + num_of_elements, c_val); |
| 197 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 198 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 199 | template <typename DataType> |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 200 | inline void StdSort(void* data, uint32_t num_of_elements) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 201 | DataType* data_type = static_cast<DataType*>(data); |
| 202 | std::sort(data_type, data_type + num_of_elements); |
| 203 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 204 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 205 | template<typename KeyType> |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 206 | inline int32_t SetupKeySort(void* key, |
| 207 | SortKey<KeyType>*& ptr_sort_key, |
| 208 | uint32_t num_of_elements) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 209 | ptr_sort_key = new(std::nothrow) SortKey<KeyType>[num_of_elements]; |
| 210 | if (ptr_sort_key == NULL) { |
| 211 | return -1; |
| 212 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 213 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 214 | KeyType* key_type = static_cast<KeyType*>(key); |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 215 | for (uint32_t i = 0; i < num_of_elements; i++) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 216 | ptr_sort_key[i].key_ = key_type[i]; |
| 217 | ptr_sort_key[i].index_ = i; |
| 218 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 219 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 220 | return 0; |
| 221 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 222 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 223 | template<typename KeyType> |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 224 | inline int32_t TeardownKeySort(void* data, |
| 225 | SortKey<KeyType>* ptr_sort_key, |
| 226 | uint32_t num_of_elements, |
| 227 | uint32_t size_of_element) { |
| 228 | uint8_t* ptr_data = static_cast<uint8_t*>(data); |
| 229 | uint8_t* ptr_data_sorted = |
| 230 | new(std::nothrow) uint8_t[num_of_elements * size_of_element]; |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 231 | if (ptr_data_sorted == NULL) { |
| 232 | return -1; |
| 233 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 234 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 235 | for (uint32_t i = 0; i < num_of_elements; i++) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 236 | memcpy(ptr_data_sorted + i * size_of_element, ptr_data + |
| 237 | ptr_sort_key[i].index_ * size_of_element, size_of_element); |
| 238 | } |
| 239 | memcpy(ptr_data, ptr_data_sorted, num_of_elements * size_of_element); |
| 240 | delete[] ptr_sort_key; |
| 241 | delete[] ptr_data_sorted; |
| 242 | return 0; |
| 243 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 244 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 245 | template<typename KeyType> |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 246 | inline int32_t IntegerKeySort(void* data, void* key, |
| 247 | uint32_t num_of_elements, |
| 248 | uint32_t size_of_element) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 249 | SortKey<KeyType>* ptr_sort_key; |
| 250 | if (SetupKeySort<KeyType>(key, ptr_sort_key, num_of_elements) != 0) { |
| 251 | return -1; |
| 252 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 253 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 254 | boost::integer_sort(ptr_sort_key, ptr_sort_key + num_of_elements, |
| 255 | KeyRightShift<KeyType>(), KeyLessThan<KeyType>()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 256 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 257 | if (TeardownKeySort<KeyType>(data, ptr_sort_key, num_of_elements, |
| 258 | size_of_element) != 0) { |
| 259 | return -1; |
| 260 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 261 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 262 | return 0; |
| 263 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 264 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 265 | template<typename KeyType> |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 266 | inline int32_t StdKeySort(void* data, void* key, |
| 267 | uint32_t num_of_elements, |
| 268 | uint32_t size_of_element) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 269 | SortKey<KeyType>* ptr_sort_key; |
| 270 | if (SetupKeySort<KeyType>(key, ptr_sort_key, num_of_elements) != 0) { |
| 271 | return -1; |
| 272 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 273 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 274 | std::sort(ptr_sort_key, ptr_sort_key + num_of_elements, |
| 275 | KeyLessThan<KeyType>()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 276 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 277 | if (TeardownKeySort<KeyType>(data, ptr_sort_key, num_of_elements, |
| 278 | size_of_element) != 0) { |
| 279 | return -1; |
| 280 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 281 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 282 | return 0; |
| 283 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 284 | #endif |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 285 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 286 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 287 | int32_t Sort(void* data, uint32_t num_of_elements, Type type) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 288 | if (data == NULL) { |
| 289 | return -1; |
| 290 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 291 | |
| 292 | #ifdef NO_STL |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 293 | switch (type) { |
| 294 | case TYPE_Word8: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 295 | qsort(data, num_of_elements, sizeof(int8_t), CompareWord8); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 296 | break; |
| 297 | case TYPE_UWord8: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 298 | qsort(data, num_of_elements, sizeof(uint8_t), CompareUWord8); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 299 | break; |
| 300 | case TYPE_Word16: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 301 | qsort(data, num_of_elements, sizeof(int16_t), CompareWord16); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 302 | break; |
| 303 | case TYPE_UWord16: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 304 | qsort(data, num_of_elements, sizeof(uint16_t), CompareUWord16); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 305 | break; |
| 306 | case TYPE_Word32: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 307 | qsort(data, num_of_elements, sizeof(int32_t), CompareWord32); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 308 | break; |
| 309 | case TYPE_UWord32: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 310 | qsort(data, num_of_elements, sizeof(uint32_t), CompareUWord32); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 311 | break; |
| 312 | case TYPE_Word64: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 313 | qsort(data, num_of_elements, sizeof(int64_t), CompareWord64); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 314 | break; |
| 315 | case TYPE_UWord64: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 316 | qsort(data, num_of_elements, sizeof(uint64_t), CompareUWord64); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 317 | break; |
| 318 | case TYPE_Float32: |
| 319 | qsort(data, num_of_elements, sizeof(float), CompareFloat32); |
| 320 | break; |
| 321 | case TYPE_Float64: |
| 322 | qsort(data, num_of_elements, sizeof(double), CompareFloat64); |
| 323 | break; |
| 324 | default: |
| 325 | return -1; |
| 326 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 327 | #else |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 328 | // Fall back to std::sort for 64-bit types and floats due to compiler |
| 329 | // warnings and VS 2003 build crashes respectively with spreadsort. |
| 330 | switch (type) { |
| 331 | case TYPE_Word8: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 332 | IntegerSort<int8_t>(data, num_of_elements); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 333 | break; |
| 334 | case TYPE_UWord8: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 335 | IntegerSort<uint8_t>(data, num_of_elements); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 336 | break; |
| 337 | case TYPE_Word16: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 338 | IntegerSort<int16_t>(data, num_of_elements); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 339 | break; |
| 340 | case TYPE_UWord16: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 341 | IntegerSort<uint16_t>(data, num_of_elements); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 342 | break; |
| 343 | case TYPE_Word32: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 344 | IntegerSort<int32_t>(data, num_of_elements); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 345 | break; |
| 346 | case TYPE_UWord32: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 347 | IntegerSort<uint32_t>(data, num_of_elements); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 348 | break; |
| 349 | case TYPE_Word64: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 350 | StdSort<int64_t>(data, num_of_elements); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 351 | break; |
| 352 | case TYPE_UWord64: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 353 | StdSort<uint64_t>(data, num_of_elements); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 354 | break; |
| 355 | case TYPE_Float32: |
| 356 | StdSort<float>(data, num_of_elements); |
| 357 | break; |
| 358 | case TYPE_Float64: |
| 359 | StdSort<double>(data, num_of_elements); |
| 360 | break; |
| 361 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 362 | #endif |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 363 | return 0; |
| 364 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 365 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 366 | int32_t KeySort(void* data, void* key, uint32_t num_of_elements, |
| 367 | uint32_t size_of_element, Type key_type) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 368 | if (data == NULL) { |
| 369 | return -1; |
| 370 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 371 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 372 | if (key == NULL) { |
| 373 | return -1; |
| 374 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 375 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 376 | if ((uint64_t)num_of_elements * size_of_element > 0xffffffff) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 377 | return -1; |
| 378 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 379 | |
| 380 | #ifdef NO_STL |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 381 | SortKey* ptr_sort_key = new(std::nothrow) SortKey[num_of_elements]; |
| 382 | if (ptr_sort_key == NULL) { |
| 383 | return -1; |
| 384 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 385 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 386 | switch (key_type) { |
| 387 | case TYPE_Word8: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 388 | KEY_QSORT(ptr_sort_key, key, num_of_elements, int8_t, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 389 | CompareKeyWord8); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 390 | break; |
| 391 | case TYPE_UWord8: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 392 | KEY_QSORT(ptr_sort_key, key, num_of_elements, uint8_t, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 393 | CompareKeyUWord8); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 394 | break; |
| 395 | case TYPE_Word16: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 396 | KEY_QSORT(ptr_sort_key, key, num_of_elements, int16_t, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 397 | CompareKeyWord16); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 398 | break; |
| 399 | case TYPE_UWord16: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 400 | KEY_QSORT(ptr_sort_key, key, num_of_elements, uint16_t, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 401 | CompareKeyUWord16); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 402 | break; |
| 403 | case TYPE_Word32: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 404 | KEY_QSORT(ptr_sort_key, key, num_of_elements, int32_t, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 405 | CompareKeyWord32); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 406 | break; |
| 407 | case TYPE_UWord32: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 408 | KEY_QSORT(ptr_sort_key, key, num_of_elements, uint32_t, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 409 | CompareKeyUWord32); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 410 | break; |
| 411 | case TYPE_Word64: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 412 | KEY_QSORT(ptr_sort_key, key, num_of_elements, int64_t, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 413 | CompareKeyWord64); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 414 | break; |
| 415 | case TYPE_UWord64: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 416 | KEY_QSORT(ptr_sort_key, key, num_of_elements, uint64_t, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 417 | CompareKeyUWord64); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 418 | break; |
| 419 | case TYPE_Float32: |
| 420 | KEY_QSORT(ptr_sort_key, key, num_of_elements, float, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 421 | CompareKeyFloat32); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 422 | break; |
| 423 | case TYPE_Float64: |
| 424 | KEY_QSORT(ptr_sort_key, key, num_of_elements, double, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 425 | CompareKeyFloat64); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 426 | break; |
| 427 | default: |
| 428 | return -1; |
| 429 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 430 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 431 | // Shuffle into sorted position based on index map. |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 432 | uint8_t* ptr_data = static_cast<uint8_t*>(data); |
| 433 | uint8_t* ptr_data_sorted = |
| 434 | new(std::nothrow) uint8_t[num_of_elements * size_of_element]; |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 435 | if (ptr_data_sorted == NULL) { |
| 436 | return -1; |
| 437 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 438 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 439 | for (uint32_t i = 0; i < num_of_elements; i++) { |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 440 | memcpy(ptr_data_sorted + i * size_of_element, ptr_data + |
| 441 | ptr_sort_key[i].index_ * size_of_element, size_of_element); |
| 442 | } |
| 443 | memcpy(ptr_data, ptr_data_sorted, num_of_elements * size_of_element); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 444 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 445 | delete[] ptr_sort_key; |
| 446 | delete[] ptr_data_sorted; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 447 | |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 448 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 449 | #else |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 450 | // Fall back to std::sort for 64-bit types and floats due to compiler |
| 451 | // warnings and errors respectively with spreadsort. |
| 452 | switch (key_type) { |
| 453 | case TYPE_Word8: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 454 | return IntegerKeySort<int8_t>(data, key, num_of_elements, |
| 455 | size_of_element); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 456 | case TYPE_UWord8: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 457 | return IntegerKeySort<uint8_t>(data, key, num_of_elements, |
| 458 | size_of_element); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 459 | case TYPE_Word16: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 460 | return IntegerKeySort<int16_t>(data, key, num_of_elements, |
| 461 | size_of_element); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 462 | case TYPE_UWord16: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 463 | return IntegerKeySort<uint16_t>(data, key, num_of_elements, |
| 464 | size_of_element); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 465 | case TYPE_Word32: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 466 | return IntegerKeySort<int32_t>(data, key, num_of_elements, |
| 467 | size_of_element); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 468 | case TYPE_UWord32: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 469 | return IntegerKeySort<uint32_t>(data, key, num_of_elements, |
| 470 | size_of_element); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 471 | case TYPE_Word64: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 472 | return StdKeySort<int64_t>(data, key, num_of_elements, |
| 473 | size_of_element); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 474 | case TYPE_UWord64: |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 | [diff] [blame] | 475 | return StdKeySort<uint64_t>(data, key, num_of_elements, |
| 476 | size_of_element); |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 477 | case TYPE_Float32: |
| 478 | return StdKeySort<float>(data, key, num_of_elements, size_of_element); |
| 479 | case TYPE_Float64: |
| 480 | return StdKeySort<double>(data, key, num_of_elements, size_of_element); |
| 481 | } |
| 482 | assert(false); |
| 483 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 484 | #endif |
phoglund@webrtc.org | 6bc5d4d | 2012-12-19 14:55:24 | [diff] [blame] | 485 | } |
| 486 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 | [diff] [blame] | 487 | } // namespace webrtc |