-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElf_final64_nodelevel_enqueue.h
775 lines (605 loc) · 27.9 KB
/
Elf_final64_nodelevel_enqueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
#ifndef ELF_FINAL64_NODELEVEL_ENQUEUE_H
#define ELF_FINAL64_NODELEVEL_ENQUEUE_H
#include "Util.h"
#include "Utils/structures.h"
#include "SortingEngine/sortingEngine.h"
#include "ThreadPool.h"
#include <queue>
#include <functional>
#include <map>
#include <stdlib.h>
vector<std::future<void>> results_get;
std::mutex values_mutex;
//std::mutex values_mutex3;
class Elf_final64_nodelevel_enqueue : public Index {
protected:
uint32_t* ELF;
uint32_t* max_dims;
const uint32_t NUM_DIM=0;
uint32_t MAX_FIRST_DIM;
uint32_t NUM_PREDICATES;
const uint32_t INITIAL_BUCKET_SIZE = 16;
int num_threads;
ThreadPool *pool;
// ThreadPool *pool = new ThreadPool(Elf_final64_nodelevel_enqueue::num_threads);
public:
struct FrequencyItem {
uint32_t count;
uint32_t* tids;
};
typedef FrequencyItem FrequencyItem;
typedef map<uint32_t, FrequencyItem*> FrequencyMap;
uint32_t* getElf(){
return this->ELF;
}
Elf_final64_nodelevel_enqueue(Store* s, uint32_t* max, uint32_t* ELF) : Index(s), max_dims(max), NUM_DIM(s->NUM_DIM) {
//nothing todo
this->ELF = ELF;
}
Elf_final64_nodelevel_enqueue(Store* s, uint32_t* max) : Index(s), max_dims(max), NUM_DIM(s->NUM_DIM) {
//nothing todo
}
Elf_final64_nodelevel_enqueue(Store* s, Elf_final64_nodelevel_enqueue* elf) : Index(s), ELF(elf->ELF), NUM_DIM(elf->NUM_DIM), MAX_FIRST_DIM(elf->MAX_FIRST_DIM) {
//nothing todo
}
~Elf_final64_nodelevel_enqueue() {
delete[] ELF;
};
void setNumThreads(int thread_num){
this->num_threads = thread_num;
this->pool = new ThreadPool(this->num_threads);
}
void join_threads(){
// this->pool->shutdown();
delete this->pool;
}
void setNumPredicates(uint32_t numColumns) {
NUM_PREDICATES = numColumns;
}
inline uint64_t get64(uint32_t* ptr) {
return *((uint64_t*) ptr);
}
inline void set64(uint32_t* ptr, uint64_t val) {
/* if(val != INVALID_POINTER && val > writePointer) {
counter++;
}*/
*((uint64_t*) ptr) = val;
}
uint32_t exactMatch(uint32_t* query) {
uint32_t compareValue;
uint32_t dim;
uint64_t pointer = get64(&(ELF[query[0]*2])); //exploit density property in first dim
dim = 1; //start @dim 1
while (pointer < LAST_ENTRY_MASK64) {//not found monolist begin assuming there are mono lists, XXX dirty hack NOT_FOUND is -1 (hopefully) interpreted as MAX_INT
compareValue = query[dim++];
pointer = listContains(compareValue, pointer);
}
if (pointer == NOT_FOUND)
return NOT_FOUND;
pointer &= RECOVER_MASK64;
uint32_t value;
for (; dim < NUM_DIM; dim++) {
compareValue = query[dim];
value = ELF[pointer++];
if (compareValue != value)
return NOT_FOUND;
}
return ELF[pointer] & RECOVER_MASK;
}
inline uint64_t listContains(uint32_t VALUE, uint64_t START) {
uint32_t toCompare;
uint64_t position = START;
while ((toCompare = ELF[position]) < LAST_ENTRY_MASK) {//not found end of list, is skipped totally for 1-element lists
if (VALUE == toCompare)
return get64(&(ELF[position + 1]));
else if (VALUE < toCompare)
return NOT_FOUND;
//else continue search
position += 3;
}
toCompare &= RECOVER_MASK; //unset bit indicating we found end of list
return (VALUE == toCompare) ? get64(&(ELF[position + 1])) : NOT_FOUND;
}
void buildIndex() {
//uint32_t requiredInts = d->requiredInts();
uint64_t requiredInts = ((uint64_t) STORE->NUM_POINTS)*(NUM_DIM + 3);
#ifndef NO_SIMD_OPERATIONS
//cout << "Zahl "<< requiredInts<<endl;
void* temp;
if (posix_memalign(&temp, 16, 2 * requiredInts * sizeof (uint32_t)) != 0) {
cout << "memalign failed!" << endl;
}
ELF = (uint32_t*) temp;
#else
ELF = new uint32_t[2 * requiredInts];
#endif
uint64_t memory = buildFromDataSorting(STORE->STORE, STORE->NUM_POINTS, STORE->NUM_DIM);
cout << "Size: " << memory << " : " << ((uint64_t) NUM_DIM)*(STORE->NUM_POINTS) << endl;
}
struct DimList {
uint64_t* begin;
uint32_t* length;
};
uint64_t createDimListSorting(Array<uint32_t>* data_array, uint32_t numDim, uint32_t dim, uint64_t writePointer) {
uint32_t freqListSize = 0;
DimList dimlist;
sort(data_array, dim, max_dims, numDim);
uint64_t* nextListPositions = (uint64_t*) malloc(sizeof (uint64_t) * data_array->size);
dimlist.begin = (uint64_t*) malloc(sizeof (uint64_t) * data_array->size);
dimlist.length = (uint32_t*) malloc(sizeof (uint64_t) * data_array->size);
uint32_t begin = 0;
uint32_t cur = data_array->ary[0].value[dim];
uint32_t i;
for (i = 1; i < data_array->size; i++) {
if (cur != data_array->ary[i].value[dim]) {
ELF[writePointer] = cur;
writePointer++;
nextListPositions[freqListSize] = writePointer;
writePointer += 2;
dimlist.begin[freqListSize] = begin;
dimlist.length[freqListSize] = i - begin;
begin = i;
cur = data_array->ary[i].value[dim];
freqListSize++;
}
}
ELF[writePointer] = cur;
writePointer++;
nextListPositions[freqListSize] = writePointer;
writePointer += 2;
ELF[writePointer - 3] |= LAST_ENTRY_MASK;
dimlist.begin[freqListSize] = begin;
dimlist.length[freqListSize] = i - begin;
freqListSize++;
nextListPositions = (uint64_t*) realloc(nextListPositions, sizeof (uint64_t) * freqListSize);
dimlist.begin = (uint64_t*) realloc(dimlist.begin, sizeof (uint64_t) * freqListSize);
dimlist.length = (uint32_t*) realloc(dimlist.length, sizeof (uint32_t) * freqListSize);
Array<uint32_t> temp;
if (dim + 1 < numDim) {
for (int j = 0; j < freqListSize; j++) {
temp.ary = &(data_array->ary[dimlist.begin[j]]);
temp.size = dimlist.length[j];
if (dimlist.length[j] > 1) {
set64(&(ELF[nextListPositions[j]]), writePointer);
writePointer = createDimListSorting(&temp, numDim, dim + 1, writePointer);
} else {
set64(&(ELF[nextListPositions[j]]), writePointer | LAST_ENTRY_MASK64);
writePointer = linearize_elf_mono(writePointer, temp.ary[0].tid, dim + 1);
ELF[writePointer - 1] |= LAST_ENTRY_MASK;
}
}
} else {
for (int j = 0; j < freqListSize; j++) {
for (int point = 0; point < dimlist.length[j]; point++) {
set64(&(ELF[nextListPositions[j]]), writePointer | LAST_ENTRY_MASK64);
writePointer = linearize_elf_mono(writePointer, data_array->ary[dimlist.begin[j] + point].tid, dim + 1);
}
ELF[writePointer - 1] |= LAST_ENTRY_MASK;
}
}
//cout << ELF[5051] << endl;
free(nextListPositions);
free(dimlist.begin);
free(dimlist.length);
return writePointer;
}
uint64_t buildFromDataSorting(uint32_t** store, uint32_t numRows, uint32_t numDim) {
//We don't know anything about the first deimension
// -> worst case, we have to store as many lists as points
Array<uint32_t> data_array;
data_array.ary = (TID<uint32_t>*) malloc(sizeof (TID<uint32_t>) * numRows);
data_array.size = numRows;
uint32_t* tempArray = new uint32_t[((size_t) numRows) * numDim];
for (uint64_t i = 0; i < numRows; i++) {
data_array.ary[i].tid = i;
data_array.ary[i].value = &(tempArray[i * numDim]);
memcpy(data_array.ary[i].value, store[i], sizeof (uint32_t) * numDim);
}
sort(&data_array, 0, &(max_dims[0]), numDim);
uint64_t writepointer = 0;
this->MAX_FIRST_DIM = data_array.ary[numRows - 1].value[0];
writepointer += (MAX_FIRST_DIM + 1) * 2;
uint32_t begin = 0;
uint32_t cur = data_array.ary[0].value[0];
uint32_t size;
uint32_t pos = 0;
uint32_t i;
Array<uint32_t> temp;
for (i = 1; i < numRows; i++) {
if (cur != data_array.ary[i].value[0]) {
size = i - begin;
temp.ary = &(data_array.ary[begin]);
temp.size = size;
if (size > 1) {
set64(&(ELF[pos * 2]), writepointer);
writepointer = createDimListSorting(&temp, numDim, 1, writepointer);
} else {
set64(&(ELF[pos * 2]), writepointer | LAST_ENTRY_MASK64);
writepointer = linearize_elf_mono(writepointer, temp.ary[0].tid, 1);
}
begin = i;
cur = data_array.ary[i].value[0];
pos++;
}
}
size = i - begin;
temp.ary = &(data_array.ary[begin]);
temp.size = size;
if (size > 1) {
set64(&(ELF[pos * 2]), writepointer);
writepointer = createDimListSorting(&temp, numDim, 1, writepointer);
} else {
set64(&(ELF[pos * 2]), writepointer | LAST_ENTRY_MASK64);
writepointer = linearize_elf_mono(writepointer, temp.ary[begin].tid, 1);
}
delete[] tempArray;
return writepointer;
}
uint64_t buildFromData() {
//We don't know anything about the first deimension
// -> worst case, we have to store as many lists as points
uint64_t writepointer = 0;
FrequencyItem* freqList;
uint32_t num_FreqLists = createFirstFrequencyList(&freqList, STORE->NUM_POINTS, 0);
this->MAX_FIRST_DIM = num_FreqLists - 1;
writepointer += num_FreqLists * 2;
for (uint32_t i = 0; i < num_FreqLists; i++) {
if (freqList[i].count > 1) {
set64(&(ELF[i * 2]), writepointer);
writepointer = linearize_dim_list(writepointer, freqList[i].tids, freqList[i].count, 1);
} else {
set64(&(ELF[i * 2]), writepointer | LAST_ENTRY_MASK64);
writepointer = linearize_elf_mono(writepointer, freqList[i].tids[0], 1);
}
free(freqList[i].tids);
}
free(freqList);
return writepointer;
}
//can exploit density criteria
uint32_t createFirstFrequencyList(FrequencyItem** freqList, uint32_t num_points, uint32_t dim) {
*freqList = (FrequencyItem*) malloc(num_points * sizeof (FrequencyItem));
if (!freqList) {
cout << "malloc freqList failed!" << endl;
}
uint32_t freqListSize = 0;
FrequencyItem* freqItem;
for (uint32_t i = 0; i < num_points; i++) {
freqItem = &((*freqList)[STORE->getPoint(i)[dim]]);
if (!freqItem->tids) {
freqItem->count = 0;
freqItem->tids = (uint32_t*) malloc(INITIAL_BUCKET_SIZE * sizeof (uint32_t));
if (!freqItem->tids) {
cout << "malloc failed!" << endl;
}
freqListSize++;
}
freqItem->tids[freqItem->count] = i;
freqItem->count += 1;
if (freqItem->count % 2 == 0) {
freqItem->tids = (uint32_t*) realloc(freqItem->tids, freqItem->count * 2 * sizeof (uint32_t));
if (!freqItem->tids) {
cout << "realloc failed!" << endl;
}
}
}
return freqListSize;
}
uint64_t linearize_dim_list(uint64_t writePointer, uint32_t* tids, uint32_t num_points, uint32_t dim) {
//We don't know anything about the first deimension
// -> worst case, we have to store as many lists as points
FrequencyMap* freqList = new FrequencyMap();
uint32_t num_FreqLists = createFrequencyList(freqList, tids, num_points, dim);
FrequencyMap::iterator iter;
uint64_t* nextListPositions = new uint64_t[num_FreqLists];
uint32_t i;
for (iter = freqList->begin(), i = 0; iter != freqList->end(); iter++, i++) {
ELF[writePointer] = iter->first;
writePointer++;
nextListPositions[i] = writePointer;
writePointer += 2;
}
ELF[writePointer - 3] |= LAST_ENTRY_MASK;
for (iter = freqList->begin(), i = 0; iter != freqList->end(); iter++, i++) {
if (iter->second->count > 1) {
set64(&(ELF[nextListPositions[i]]), writePointer);
writePointer = linearize_dim_list(writePointer, iter->second->tids, iter->second->count, dim + 1);
} else {
set64(&(ELF[nextListPositions[i]]), writePointer | LAST_ENTRY_MASK64);
writePointer = linearize_elf_mono(writePointer, iter->second->tids[0], dim + 1);
}
free(iter->second->tids);
free(iter->second);
}
delete freqList;
delete[] nextListPositions;
return writePointer;
}
uint32_t createFrequencyList(FrequencyMap* freqList, uint32_t* tids, uint32_t num_points, uint32_t dim) {
uint32_t* point;
uint32_t freqListSize = 0;
FrequencyItem* freqItem;
FrequencyMap::iterator iter;
for (uint32_t i = 0; i < num_points; i++) {
point = STORE->getPoint(tids[i]);
if ((iter = freqList->find(point[dim])) == freqList->end()) {
freqItem = (FrequencyItem*) malloc(sizeof (FrequencyItem));
if (!freqItem) {
cout << "FreqItem malloc failed!" << endl;
}
freqItem->count = 0;
freqItem->tids = (uint32_t*) malloc(INITIAL_BUCKET_SIZE * sizeof (uint32_t));
if (!freqItem->tids) {
cout << "malloc failed!" << endl;
}
iter = freqList->insert(pair<uint32_t, FrequencyItem*>(point[dim], freqItem)).first;
freqListSize++;
}
iter->second->tids[ iter->second->count] = tids[i];
iter->second->count += 1;
if (iter->second->count % 2 == 0) {
iter->second->tids = (uint32_t*) realloc(iter->second->tids, iter->second->count * 2 * sizeof (uint32_t));
if (!iter->second->tids) {
cout << "realloc failed!" << endl;
}
}
}
return freqListSize;
}
uint64_t linearize_elf_mono(uint64_t writePointer, uint32_t tid, uint32_t DIMENSION) {
uint32_t* point = STORE->getPoint(tid);
memcpy(&(ELF[writePointer]), &(point[DIMENSION]), sizeof (uint32_t)*(NUM_DIM - DIMENSION));
writePointer += (NUM_DIM - DIMENSION);
ELF[writePointer++] = tid;
return writePointer;
}
vector<uint32_t>* windowQuery(uint32_t* lowerBoundQuery, uint32_t* upperBoundQuery) {
vector<uint32_t>* resultTIDs = new vector<uint32_t>();
uint32_t LOWER = lowerBoundQuery[FIRST_DIM]*2;
uint32_t UPPER = upperBoundQuery[FIRST_DIM]*2;
uint64_t pointerNextDim;
for (uint32_t offset = LOWER; offset <= UPPER; offset += 2) {
pointerNextDim = get64(&(ELF[offset]));
if (pointerNextDim < LAST_ENTRY_MASK64) {
evluateWindowOnList(1, pointerNextDim, resultTIDs, lowerBoundQuery, upperBoundQuery);
} else {
pointerNextDim &= RECOVER_MASK64; //Unique value in First dim -> MonList found
evluateWindowOnMonoList(1, pointerNextDim, resultTIDs, lowerBoundQuery, upperBoundQuery);
}
}
// sort(resultTIDs->begin(), resultTIDs->end());
return resultTIDs;
}
void evluateWindowOnList(uint32_t DIMENSION, uint64_t START_LIST, vector<uint32_t>* RESULTS, uint32_t* lowerBoundQuery, uint32_t* upperBoundQuery) {
uint32_t toCompare;
uint64_t position = START_LIST;
uint64_t pointer;
while ((toCompare = ELF[position]) < LAST_ENTRY_MASK) {//not found end of list, is skipped totally for 1-element list
if (isIn(lowerBoundQuery[DIMENSION], upperBoundQuery[DIMENSION], toCompare)) {
pointer = get64(&(ELF[position + 1]));
if (pointer < LAST_ENTRY_MASK64)//no monlist found
evluateWindowOnList(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery);
else {
pointer &= RECOVER_MASK64;
evluateWindowOnMonoList(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery);
}
} else if (upperBoundQuery[DIMENSION] < toCompare) {//XXX @David scheint sinn zu machen
return;
}//else continue
position += 3;
}
//process last value
toCompare &= RECOVER_MASK;
if (isIn(lowerBoundQuery[DIMENSION], upperBoundQuery[DIMENSION], toCompare)) {
pointer = get64(&(ELF[position + 1]));
if (pointer < LAST_ENTRY_MASK64)//no monlist found
evluateWindowOnList(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery);
else {
pointer &= RECOVER_MASK64;
evluateWindowOnMonoList(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery);
}
}
}
inline void evluateWindowOnMonoList(uint32_t DIMENSION, uint64_t START_MONO_LIST, vector<uint32_t>* RESULTS, uint32_t* lowerBoundQuery, uint32_t* upperBoundQuery) {
uint32_t value;
uint32_t dim;
uint32_t i;
for (i = 0, dim = DIMENSION; dim < NUM_DIM; dim++, i++) {
value = ELF[START_MONO_LIST + i];
if (!isIn(lowerBoundQuery[dim], upperBoundQuery[dim], value))
return;
}
RESULTS->push_back(ELF[START_MONO_LIST + i] & RECOVER_MASK);
}
vector<uint32_t>* partialMatch(uint32_t* lowerBoundQuery, uint32_t* upperBoundQuery, bool* columnsForSelect) {
// cout << "nodelevel_enque";
vector<uint32_t> *resultTIDs = new vector<uint32_t>();
uint32_t LOWER;
uint32_t UPPER;
std::vector<uint64_t> pointerNextDim;
if (columnsForSelect[FIRST_DIM]) {
LOWER = lowerBoundQuery[FIRST_DIM] * 2;
UPPER = upperBoundQuery[FIRST_DIM] * 2;
} else {
LOWER = 0;
UPPER = MAX_FIRST_DIM * 2;
}
// Implementation of separating first and other pointers
for (uint32_t offset = LOWER; offset <= UPPER; offset += 2) {
pointerNextDim.push_back(get64(&(ELF[offset])));
}
// int i = 0;
for (auto it = std::next(pointerNextDim.begin()); it != pointerNextDim.end(); ++it) {
if (*it < LAST_ENTRY_MASK64) {
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back(pool->submit([=]{
this->partialMatch1(1, *it, resultTIDs, lowerBoundQuery, upperBoundQuery, columnsForSelect);
}));
} else {
*it &= RECOVER_MASK64; //Unique value in First dim -> MonList found
// std::unique_lock<std::mutex> lock(m_mutex);
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back((pool->submit([=] {this->partialMatchMonoList(1, *it, resultTIDs, lowerBoundQuery, upperBoundQuery, columnsForSelect);})));
}
}
if (pointerNextDim.front() < LAST_ENTRY_MASK64) {
partialMatch1(1, pointerNextDim.front(), resultTIDs, lowerBoundQuery, upperBoundQuery, columnsForSelect);
} else {
uint64_t pointer = pointerNextDim.front();
pointer &= RECOVER_MASK64;
partialMatchMonoList(1, pointer, resultTIDs, lowerBoundQuery, upperBoundQuery, columnsForSelect);
}
pool->queue_empty();
/* while(true) {
//
{
std::unique_lock<std::mutex> values_mutex2;
if(i+1 < results_get.size())
i++;
else{
values_mutex2.unlock();
break;
}
}
std::unique_lock<std::mutex> values_mutex2;
while (results_get[i].wait_for(std::chrono::seconds(10)) != future_status::ready && results_get[i].wait_for(std::chrono::seconds(10)) != future_status::deferred);
results_get[i].get();
values_mutex2.unlock();
}*/
for (int i=0; i < results_get.size();i++ ) {
while (results_get[i].wait_for(std::chrono::seconds(1)) != future_status::ready && results_get[i].wait_for(std::chrono::seconds(1)) != future_status::deferred);
try {
if (results_get[i].valid())
results_get[i].get();
else
{
results_get[i].wait_for(std::chrono::seconds(1));
results_get[i].get();
}
} catch (const std::future_error& e) {
std::cout << "Caught a future_error with code \"" << e.code()
<< "\"\nMessage: \"" << e.what() << "\"\n";
}
}
results_get.clear();
return resultTIDs;
}
void partialMatch1(uint32_t DIMENSION, uint64_t START_LIST, vector<uint32_t>* RESULTS, uint32_t* lowerBoundQuery, uint32_t* upperBoundQuery, bool* columnsForSelect) {
uint32_t toCompare;
uint64_t position = START_LIST;
uint64_t pointer;
uint64_t buffer = 0;
if (columnsForSelect[DIMENSION]) {
while ((toCompare = ELF[position]) < LAST_ENTRY_MASK) {//not found end of list, is skipped totally for 1-element list
if (isIn(lowerBoundQuery[DIMENSION], upperBoundQuery[DIMENSION], toCompare)) {
pointer = get64(&(ELF[position + 1]));
if (buffer == 0){
buffer = pointer;
position = position + 3;
continue;
}
if (pointer < LAST_ENTRY_MASK64) {//no monlist found
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back(pool->submit([=] {
this->partialMatch1(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery,
columnsForSelect);}));
}
else {
pointer &= RECOVER_MASK64;
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back(pool->submit([=] {
this->partialMatchMonoList(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery,
upperBoundQuery, columnsForSelect);
}));
}
} else if (upperBoundQuery[DIMENSION] < toCompare) {//XXX @David scheint sinn zu machen
break;
}//else continue
position += 3;
}
//process last value
toCompare &= RECOVER_MASK;
if (isIn(lowerBoundQuery[DIMENSION], upperBoundQuery[DIMENSION], toCompare)) {
pointer = get64(&(ELF[position + 1]));
if (pointer < LAST_ENTRY_MASK64) {//no monlist found
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back(pool->submit([=] {
this->partialMatch1(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery,
columnsForSelect);
}));
}
else {
pointer &= RECOVER_MASK64;
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back(pool->submit([=]{this->partialMatchMonoList(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery, columnsForSelect);}));
}
}
if (buffer != 0) {
if (buffer < LAST_ENTRY_MASK64)
partialMatch1(DIMENSION + 1, buffer, RESULTS, lowerBoundQuery, upperBoundQuery, columnsForSelect);
else
partialMatchMonoList(DIMENSION + 1, buffer & RECOVER_MASK64, RESULTS, lowerBoundQuery,
upperBoundQuery, columnsForSelect);
}
} else {
while ((toCompare = ELF[position]) < LAST_ENTRY_MASK) {//not found end of list, is skipped totally for 1-element list
pointer = get64(&(ELF[position + 1]));
if (buffer == 0){
buffer = pointer;
position = position + 3;
continue;
}
if (pointer < LAST_ENTRY_MASK64) {//no monlist found
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back(pool->submit([=] {
this->partialMatch1(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery,
columnsForSelect);
}));
}
else {
pointer &= RECOVER_MASK64;
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back(pool->submit([=]{this->partialMatchMonoList(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery, columnsForSelect);}));
}
position += 3;
}
//process last value
toCompare &= RECOVER_MASK;
pointer = get64(&(ELF[position + 1]));
if (pointer < LAST_ENTRY_MASK64){//no monlist found
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back(pool->submit([=] {this->partialMatch1(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery,columnsForSelect);}));
}
else {
pointer &= RECOVER_MASK64;
std::lock_guard<std::mutex> lk(values_mutex);
results_get.push_back(pool->submit([=]{this->partialMatchMonoList(DIMENSION + 1, pointer, RESULTS, lowerBoundQuery, upperBoundQuery, columnsForSelect);}));
}
if (buffer != 0) {
if (buffer < LAST_ENTRY_MASK64)
partialMatch1(DIMENSION + 1, buffer, RESULTS, lowerBoundQuery, upperBoundQuery, columnsForSelect);
else
partialMatchMonoList(DIMENSION + 1, buffer & RECOVER_MASK64, RESULTS, lowerBoundQuery,
upperBoundQuery, columnsForSelect);
}
}
}
void partialMatchMonoList(uint32_t DIMENSION, uint64_t START_MONO_LIST, vector<uint32_t>* RESULTS, uint32_t* lowerBoundQuery, uint32_t* upperBoundQuery, bool* columnsForSelect) {
uint32_t value;
uint32_t i = 0;
std::vector<uint32_t > result_test;
std::mutex mutex;
for (; DIMENSION + i < NUM_DIM; i++) {
if (columnsForSelect[DIMENSION + i]) {
value = ELF[START_MONO_LIST + i];
if (!isIn(lowerBoundQuery[DIMENSION + i], upperBoundQuery[DIMENSION + i], value))
return;
}
}
result_test.push_back(ELF[START_MONO_LIST + (NUM_DIM - DIMENSION)] & RECOVER_MASK);
std::lock_guard<std::mutex> lk(values_mutex);
RESULTS->insert(RESULTS->end(), result_test.begin(), result_test.end());
result_test.clear();
}
};
#endif // ELF_FINAL_H