5 #include "fastCommBuffer.h" 6 #include "indexedFddStorage.h" 8 template <
class K,
class T>
11 localData =
new T[allocSize];
12 localKeys =
new K[allocSize];
16 template <
class K,
class T>
23 localData =
new T[allocSize];
24 localKeys =
new K[allocSize];
27 template <
class K,
class T>
35 template <
class K,
class T>
40 template <
class K,
class T>
44 template <
class K,
class T>
46 return localData[ref];
49 template <
class K,
class T>
52 std::vector<size_t> p(size,0);
53 std::vector<size_t> rp(size);
54 std::vector<bool> sorted(size,
false);
58 iota(p.begin(), p.end(), 0);
59 std::sort(p.begin(), p.end(),
60 [&](
size_t i,
size_t j){
return localKeys[i] < localKeys[j]; });
65 for (i = 0; i < size; ++i){
76 savedKey = localKeys[p[pos]];
77 savedData = localData[p[pos]];
79 while ( ! sorted[pos] ){
81 K holdenKey = localKeys[pos];
82 T holdenData = localData[pos];
84 size_t holdenPos = rp[pos];
87 localKeys[pos] = savedKey;
88 localData[pos] = savedData;
92 savedData = holdenData;
107 template <
class K,
class T>
109 template <
class K,
class T>
112 template <
class K,
class T>
116 template <
class K,
class T>
118 lineSizes =
new size_t[s];
122 template <
class K,
class T>
124 setData(keys, data, s);
127 template <
class K,
class T>
129 setData(keys, data, lineSizes, s);
135 template <
class K,
class T>
137 if (lineSizes != NULL){
144 template <
class K,
class T>
149 std::copy(data, data + s, this->localData);
150 std::copy(keys, keys + s, this->localKeys);
155 template <
class K,
class T>
158 #pragma omp parallel for 159 for (
size_t i = 0; i < s; ++i){
160 lineSizes[i] = ls[i];
162 this->localData[i] =
new T [lineSizes[i]];
163 for (
size_t j = 0; j < lineSizes[i]; ++j){
164 this->localData[i][j] = ((T *) data[i])[j];
166 this->localKeys[i] = keys[i];
170 template <
class K,
class T>
172 fastCommBuffer buffer(0);
173 fastCommBuffer buffer2(0);
177 buffer.setBuffer(data, s);
178 buffer2.setBuffer(keys, s);
181 for (
size_t i = 0; i < s; ++i){
182 buffer >> this->localData[i];
183 buffer2 >> this->localKeys[i];
186 template <
class K,
class T>
188 fastCommBuffer buffer(0);
189 fastCommBuffer buffer2(0);
191 buffer.setBuffer(data, s);
192 buffer2.setBuffer(keys, s);
194 for (
size_t i = 0; i < s; ++i){
195 lineSizes[i] = ls[i];
197 this->localData[i] =
new T [lineSizes[i]];
199 buffer2 >> this->localKeys[i];
200 buffer.read(this->localData[i], ls[i]*
sizeof(T));
204 template <
class K,
class T>
209 template <
class K,
class T>
216 template <
class K,
class T>
218 if ( this->size == this->allocSize )
219 grow( std::max(this->size + 1,
size_t(this->allocSize*1.5) ) );
220 this->localKeys[this->size] = std::move(key);
221 this->localData[this->size++] = std::move(item);
224 template <
class K,
class T>
226 if ( this->size == this->allocSize )
227 grow( std::max(this->size + 1,
size_t(this->allocSize*1.5) ) );
228 lineSizes[this->size] = s;
229 this->localKeys[this->size] = key;
230 this->localData[this->size++] = item;
240 template <
class K,
class T>
248 template <
class K,
class T>
250 if (this->allocSize < toSize){
255 T * newStorage =
new T [toSize];
256 K * newKeys =
new K [toSize];
258 if (this->size > 0) {
262 std::move(this->localData, this->localData + this->size, newStorage);
266 std::move(this->localKeys, this->localKeys + this->size, newKeys);
277 delete [] this->localData;
278 delete [] this->localKeys;
280 this->localData = newStorage;
281 this->localKeys = newKeys;
282 this->allocSize = toSize;
285 template <
class K,
class T>
287 if (this->allocSize < toSize){
288 if ((this->allocSize * 2) > toSize){
289 toSize = this->allocSize * 2;
292 size_t * newLineSizes =
new size_t [toSize];
293 T ** newStorage =
new T* [toSize];
294 K * newKeys =
new K [toSize];
299 #pragma omp parallel for 300 for (
size_t i = 0; i < this->size; ++i){
301 newStorage[i] = this->localData[i];
302 newLineSizes[i] = lineSizes[i];
303 newKeys[i] = this->localKeys[i];
307 delete [] this->localData;
308 delete [] this->localKeys;
311 this->localData = newStorage;
312 this->localKeys = newKeys;
313 lineSizes = newLineSizes;
314 this->allocSize = toSize;
324 template <
class K,
class T>
326 if ( (this->size > 0) && (this->allocSize > this->size) ){
327 T * newStorage =
new T [this->size];
328 K * newKeys =
new K [this->size];
330 for (
size_t i = 0; i < this->size; ++i){
331 newStorage[i] = this->localData[i];
332 newKeys[i] = this->localKeys[i];
335 delete [] this->localData;
336 delete [] this->localKeys;
338 this->localData = newStorage;
339 this->localKeys = newKeys;
340 this->allocSize = this->size;
343 template <
class K,
class T>
345 if ( (this->size > 0) && (this->allocSize > this->size) ){
346 T ** newStorage =
new T* [this->size];
347 K * newKeys =
new K [this->size];
348 size_t * newLineSizes =
new size_t[this->size];
350 for (
size_t i = 0; i < this->size; ++i){
351 newStorage[i] = this->localData[i];
352 newLineSizes[i] = lineSizes[i];
353 newKeys[i] = this->localKeys[i];
357 delete [] this->localData;
358 delete [] this->localKeys;
361 this->localData = newStorage;
362 lineSizes = newLineSizes;
363 this->localKeys = newKeys;
364 this->allocSize = this->size;