-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcbg.hpp
2063 lines (1871 loc) · 68.5 KB
/
cbg.hpp
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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////////////////
// Production code of Cuckoo Breeding Ground (CBG) hash table.
// See "research_cuckoo_cbg.md" for scientific paper explaining the options.
///////////////////////////////////////////////////////////////////////////////
//
// Written by Alain Espinosa <alainesp at gmail.com> 2018-2019 and placed
// under the MIT license (see LICENSE file for a full definition).
//
///////////////////////////////////////////////////////////////////////////////
//
// CBG version 0.2.0 (consider alpha version).
// Common operations are implemented but many, particularly special ones, are
// not. Many optimizations opportunities remains unexploited. This is intended as
// an early prototype for early adopters.
//
// Tested on Windows 64 bits with VC++ 2017. Requires C++ 14.
// Easy to support 32 bits, Linux and other compilers, but currently not done.
// Comments and PR are welcomed.
//
///////////////////////////////////////////////////////////////////////////////
// Code Architecture
//-----------------------------------------------------------------------------
//
// Class 'cbg::cbg_internal::CBG_IMPL' contains the main algorithm with common
// operations. It doesn't depends in any particular data layout. Class
// 'cbg::cbg_internal::CBG_MAP_IMPL' only add mapping operations.
//
// Data management is provided by the DATA and METADATA template parameters.
// Currently we provide 3 different layouts:
//
// - "Struct of Arrays" (SoA): Metadata overhead of 2 bytes. Each metadata,
// keys and values are on a different array. The fastest for negative
// queries.
//
// - "Array of Structs" (AoS): Metadata overhead of one byte. Each metadata,
// keys and values are in the same array each one after the other. Heavy use
// of unaligned memory access. The fastest for positive queries.
//
// - "Array of Blocks" (AoB): Metadata overhead of one byte. Each metadata,
// keys and values are in the same array on blocks. Don't use unaligned
// memory access but performance suffers. Intended for positive queries.
//
// Namespace 'cbg::hashing' contains non-cryptographic hashing based on 'wyhash'
// [https://github.com/wangyi-fudan/wyhash]. This is for 64 bits only. For 32 bits
// we need a different hash function for performance reason.
//
///////////////////////////////////////////////////////////////////////////////
// NUM_ELEMS_BUCKET parameter selection:
//
// - Fastest possible : NUM_ELEMS_BUCKET=2 with load_factor < 80%
// - No memory waste : NUM_ELEMS_BUCKET=4 with load_factor > 95%
// - Balanced approach: NUM_ELEMS_BUCKET=3 with 80% < load_factor < 95%
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <cstdint>
#include <cassert>
#include <random>
///////////////////////////////////////////////////////////////////////////////
// Architecture specific code
///////////////////////////////////////////////////////////////////////////////
#if INTPTR_MAX != INT64_MAX
#error 64 bits architecture required
#endif // !_WIN64
#ifdef _MSC_VER
# include <intrin.h>// should be part of all recent Visual Studio
# pragma intrinsic(_umul128)
# pragma intrinsic(__umulh)
# define rot64(v, s) _rotr64(v, s)
#elif defined(__SIZEOF_INT128__)
# define __forceinline inline
static __forceinline uint64_t _umul128(uint64_t a, uint64_t b, uint64_t* ph)
{
__uint128_t r = a;
r *= b;
*ph = r >> 64;
return r;
}
static __forceinline uint64_t __umulh(uint64_t a, uint64_t b)
{
__uint128_t r = a;
r *= b;
return r >> 64;
}
static __forceinline uint64 rot64(uint64 x, int k)
{
return (x << k) | (x >> (64 - k));
}
#else
#error Unsupported architecture
#endif
namespace cbg
{
///////////////////////////////////////////////////////////////////////////////
// wyrand Pseudo-random number generation
///////////////////////////////////////////////////////////////////////////////
template<uint64_t _wyp0, uint64_t _wyp1> struct __WYRAND
{
uint64_t seed;
__WYRAND() noexcept
{
// Seed with a real random value, if available
std::random_device good_random;
seed = static_cast<uint64_t>(good_random()) | static_cast<uint64_t>(good_random()) << 32;
}
__WYRAND(uint64_t seed) noexcept : seed(seed)
{}
static __forceinline uint64_t _wymum(uint64_t A, uint64_t B) noexcept
{
A = _umul128(A, B, &B);
return A ^ B;
}
uint64_t operator()() noexcept
{
seed += _wyp0;
return _wymum(seed ^ _wyp1, seed);
}
};
using wyrand = __WYRAND<UINT64_C(0xa0761d6478bd642f), UINT64_C(0xe7037ed1a0b428db)>;
///////////////////////////////////////////////////////////////////////////////
// Non-cryptographic hashing for hashtables. A clearer C++ version of wyhash
///////////////////////////////////////////////////////////////////////////////
namespace hashing
{
namespace wyhash_internal
{
///////////////////////////////////////////////////////////////////////////////
// wyhash base
///////////////////////////////////////////////////////////////////////////////
template<uint64_t _wyp0, uint64_t _wyp1, uint64_t _wyp2, uint64_t _wyp3, uint64_t _wyp4> struct __WYHASH_IMPL
{
uint64_t seed1;
__WYHASH_IMPL() noexcept
{
// Seed with a real random value, if available
std::random_device good_random;
seed1 = static_cast<uint64_t>(good_random()) | static_cast<uint64_t>(good_random()) << 32;
}
__WYHASH_IMPL(uint64_t seed1) noexcept : seed1(seed1)
{}
static __forceinline uint64_t _wymum(uint64_t A, uint64_t B) noexcept
{
A = _umul128(A, B, &B);
return A ^ B;
}
static __forceinline uint64_t _wymix0(uint64_t A, uint64_t B, uint64_t seed) noexcept { return _wymum(A ^ seed ^ _wyp0, B ^ seed ^ _wyp1); }
static __forceinline uint64_t _wymix1(uint64_t A, uint64_t B, uint64_t seed) noexcept { return _wymum(A ^ seed ^ _wyp2, B ^ seed ^ _wyp3); }
static __forceinline uint64_t _wyr08(const uint8_t* p) noexcept { uint8_t v; memcpy(&v, p, 1); return v; }
static __forceinline uint64_t _wyr16(const uint8_t* p) noexcept { uint16_t v; memcpy(&v, p, 2); return v; }
static __forceinline uint64_t _wyr32(const uint8_t* p) noexcept { uint32_t v; memcpy(&v, p, 4); return v; }
static __forceinline uint64_t _wyr64(const uint8_t* p) noexcept { uint64_t v; memcpy(&v, p, 8); return v; }
static __forceinline uint64_t __wyr64(const uint8_t* p) noexcept { return (_wyr32(p) << 32) | _wyr32(p + 4); }
uint64_t hash(const void* key, size_t len) const noexcept
{
const uint8_t* p = (const uint8_t*)key;
uint64_t i, len1 = len;
uint64_t seed = seed1;
for (i = 0; i + 32 <= len; i += 32, p += 32)
seed = _wymix0(_wyr64(p), _wyr64(p + 8), seed) ^ _wymix1(_wyr64(p + 16), _wyr64(p + 24), seed);
switch (len & 31) {
case 0: len1 = _wymix0(len1, 0, seed); break;
case 1: seed = _wymix0(_wyr08(p), 0, seed); break;
case 2: seed = _wymix0(_wyr16(p), 0, seed); break;
case 3: seed = _wymix0((_wyr16(p) << 8) | _wyr08(p + 2), 0, seed); break;
case 4: seed = _wymix0(_wyr32(p), 0, seed); break;
case 5: seed = _wymix0((_wyr32(p) << 8) | _wyr08(p + 4), 0, seed); break;
case 6: seed = _wymix0((_wyr32(p) << 16) | _wyr16(p + 4), 0, seed); break;
case 7: seed = _wymix0((_wyr32(p) << 24) | (_wyr16(p + 4) << 8) | _wyr08(p + 6), 0, seed); break;
case 8: seed = _wymix0(__wyr64(p), 0, seed); break;
case 9: seed = _wymix0(__wyr64(p), _wyr08(p + 8), seed); break;
case 10: seed = _wymix0(__wyr64(p), _wyr16(p + 8), seed); break;
case 11: seed = _wymix0(__wyr64(p), (_wyr16(p + 8) << 8) | _wyr08(p + 8 + 2), seed); break;
case 12: seed = _wymix0(__wyr64(p), _wyr32(p + 8), seed); break;
case 13: seed = _wymix0(__wyr64(p), (_wyr32(p + 8) << 8) | _wyr08(p + 8 + 4), seed); break;
case 14: seed = _wymix0(__wyr64(p), (_wyr32(p + 8) << 16) | _wyr16(p + 8 + 4), seed); break;
case 15: seed = _wymix0(__wyr64(p), (_wyr32(p + 8) << 24) | (_wyr16(p + 8 + 4) << 8) | _wyr08(p + 8 + 6), seed); break;
case 16: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed); break;
case 17: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(_wyr08(p + 16), 0, seed); break;
case 18: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(_wyr16(p + 16), 0, seed); break;
case 19: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1((_wyr16(p + 16) << 8) | _wyr08(p + 16 + 2), 0, seed); break;
case 20: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(_wyr32(p + 16), 0, seed); break;
case 21: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1((_wyr32(p + 16) << 8) | _wyr08(p + 16 + 4), 0, seed); break;
case 22: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1((_wyr32(p + 16) << 16) | _wyr16(p + 16 + 4), 0, seed); break;
case 23: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1((_wyr32(p + 16) << 24) | (_wyr16(p + 16 + 4) << 8) | _wyr08(p + 16 + 6), 0, seed); break;
case 24: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), 0, seed); break;
case 25: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), _wyr08(p + 24), seed); break;
case 26: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), _wyr16(p + 24), seed); break;
case 27: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), (_wyr16(p + 24) << 8) | _wyr08(p + 24 + 2), seed); break;
case 28: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), _wyr32(p + 24), seed); break;
case 29: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), (_wyr32(p + 24) << 8) | _wyr08(p + 24 + 4), seed); break;
case 30: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), (_wyr32(p + 24) << 16) | _wyr16(p + 24 + 4), seed); break;
case 31: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), (_wyr32(p + 24) << 24) | (_wyr16(p + 24 + 4) << 8) | _wyr08(p + 24 + 6), seed); break;
}
return _wymum(seed ^ len1, _wyp4);
}
};
// 'Magic' primes
using wyhash_IMPL = __WYHASH_IMPL<UINT64_C(0xa0761d6478bd642f), UINT64_C(0xe7037ed1a0b428db), UINT64_C(0x8ebc6af09c88c6e3), UINT64_C(0x589965cc75374cc3), UINT64_C(0x1d8e4e27c47d124f)>;
}// end namespace wyhash_internal
///////////////////////////////////////////////////////////////////////////////
// Common wyhash for general use
///////////////////////////////////////////////////////////////////////////////
template<class T> struct wyhash : private wyhash_internal::wyhash_IMPL
{
static constexpr uint64_t _wyp4 = UINT64_C(0x1d8e4e27c47d124f);
wyhash() noexcept : wyhash_internal::wyhash_IMPL(){}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed){}
template<size_t len = sizeof(T)> uint64_t operator()(const T& elem) const noexcept
{
const uint8_t* p = (const uint8_t*)(&elem);
uint64_t i, len1 = len;
uint64_t seed = seed1;
for (i = 0; i + 32 <= len; i += 32, p += 32)
seed = _wymix0(_wyr64(p), _wyr64(p + 8), seed) ^ _wymix1(_wyr64(p + 16), _wyr64(p + 24), seed);
switch (len & 31) {
case 0: len1 = _wymix0(len1, 0, seed); break;
case 1: seed = _wymix0(_wyr08(p), 0, seed); break;
case 2: seed = _wymix0(_wyr16(p), 0, seed); break;
case 3: seed = _wymix0((_wyr16(p) << 8) | _wyr08(p + 2), 0, seed); break;
case 4: seed = _wymix0(_wyr32(p), 0, seed); break;
case 5: seed = _wymix0((_wyr32(p) << 8) | _wyr08(p + 4), 0, seed); break;
case 6: seed = _wymix0((_wyr32(p) << 16) | _wyr16(p + 4), 0, seed); break;
case 7: seed = _wymix0((_wyr32(p) << 24) | (_wyr16(p + 4) << 8) | _wyr08(p + 6), 0, seed); break;
case 8: seed = _wymix0(__wyr64(p), 0, seed); break;
case 9: seed = _wymix0(__wyr64(p), _wyr08(p + 8), seed); break;
case 10: seed = _wymix0(__wyr64(p), _wyr16(p + 8), seed); break;
case 11: seed = _wymix0(__wyr64(p), (_wyr16(p + 8) << 8) | _wyr08(p + 8 + 2), seed); break;
case 12: seed = _wymix0(__wyr64(p), _wyr32(p + 8), seed); break;
case 13: seed = _wymix0(__wyr64(p), (_wyr32(p + 8) << 8) | _wyr08(p + 8 + 4), seed); break;
case 14: seed = _wymix0(__wyr64(p), (_wyr32(p + 8) << 16) | _wyr16(p + 8 + 4), seed); break;
case 15: seed = _wymix0(__wyr64(p), (_wyr32(p + 8) << 24) | (_wyr16(p + 8 + 4) << 8) | _wyr08(p + 8 + 6), seed); break;
case 16: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed); break;
case 17: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(_wyr08(p + 16), 0, seed); break;
case 18: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(_wyr16(p + 16), 0, seed); break;
case 19: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1((_wyr16(p + 16) << 8) | _wyr08(p + 16 + 2), 0, seed); break;
case 20: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(_wyr32(p + 16), 0, seed); break;
case 21: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1((_wyr32(p + 16) << 8) | _wyr08(p + 16 + 4), 0, seed); break;
case 22: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1((_wyr32(p + 16) << 16) | _wyr16(p + 16 + 4), 0, seed); break;
case 23: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1((_wyr32(p + 16) << 24) | (_wyr16(p + 16 + 4) << 8) | _wyr08(p + 16 + 6), 0, seed); break;
case 24: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), 0, seed); break;
case 25: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), _wyr08(p + 24), seed); break;
case 26: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), _wyr16(p + 24), seed); break;
case 27: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), (_wyr16(p + 24) << 8) | _wyr08(p + 24 + 2), seed); break;
case 28: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), _wyr32(p + 24), seed); break;
case 29: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), (_wyr32(p + 24) << 8) | _wyr08(p + 24 + 4), seed); break;
case 30: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), (_wyr32(p + 24) << 16) | _wyr16(p + 24 + 4), seed); break;
case 31: seed = _wymix0(__wyr64(p), __wyr64(p + 8), seed) ^ _wymix1(__wyr64(p + 16), (_wyr32(p + 24) << 24) | (_wyr16(p + 24 + 4) << 8) | _wyr08(p + 24 + 6), seed); break;
}
return _wymum(seed ^ len1, _wyp4);
}
};
// Partial specialization
template<> struct wyhash<std::string> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL(){}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed){}
uint64_t operator()(const std::string& data) const noexcept
{
return hash(data.data(), data.length());
}
};
template<> struct wyhash<std::wstring> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL() {}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed) {}
uint64_t operator()(const std::wstring& data) const noexcept
{
return hash(data.data(), sizeof(wchar_t) * data.length());
}
};
template<> struct wyhash<std::u16string> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL() {}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed) {}
uint64_t operator()(const std::u16string& data) const noexcept
{
return hash(data.data(), sizeof(char16_t) * data.length());
}
};
template<> struct wyhash<std::u32string> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL() {}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed) {}
uint64_t operator()(const std::u32string& data) const noexcept
{
return hash(data.data(), sizeof(char32_t) * data.length());
}
};
template<> struct wyhash<char*> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL(){}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed){}
uint64_t operator()(const char* data) const noexcept
{
return hash(data, strlen(data));
}
};
#if __cplusplus >= 201703L// C++ 2017
template<> struct wyhash<std::string_view> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL(){}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed){}
uint64_t operator()(const std::string_view& data) const noexcept
{
return hash(data.data(), data.length());
}
};
template<> struct wyhash<std::pmr::string> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL() {}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed) {}
uint64_t operator()(const std::pmr::string& data) const noexcept
{
return hash(data.data(), data.length());
}
};
template<> struct wyhash<std::pmr::wstring> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL() {}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed) {}
uint64_t operator()(const std::pmr::wstring& data) const noexcept
{
return hash(data.data(), sizeof(wchar_t) * data.length());
}
};
template<> struct wyhash<std::pmr::u16string> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL() {}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed) {}
uint64_t operator()(const std::pmr::u16string& data) const noexcept
{
return hash(data.data(), sizeof(char16_t) * data.length());
}
};
template<> struct wyhash<std::pmr::u32string> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL() {}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed) {}
uint64_t operator()(const std::pmr::u32string& data) const noexcept
{
return hash(data.data(), sizeof(char32_t) * data.length());
}
};
#endif
// TODO: Consider using __cpp_char8_t?
#if __cplusplus >= 202001L// C++ 2020
template<> struct wyhash<std::u8string> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL() {}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed) {}
uint64_t operator()(const std::u8string& data) const noexcept
{
return hash(data.data(), sizeof(char8_t) * data.length());
}
};
template<> struct wyhash<std::pmr::u8string> : private wyhash_internal::wyhash_IMPL
{
wyhash() noexcept : wyhash_internal::wyhash_IMPL() {}
wyhash(uint64_t seed) noexcept : wyhash_internal::wyhash_IMPL(seed) {}
uint64_t operator()(const std::pmr::u8string& data) const noexcept
{
return hash(data.data(), sizeof(char8_t) * data.length());
}
};
#endif
}// end namespace hashing
// Search Hint
enum class Search_Hint
{
Unknow,
Expect_Positive,
Expect_Negative
};
// Internal implementations
namespace cbg_internal
{
///////////////////////////////////////////////////////////////////////////////
// Data layout is "Struct of Arrays"
///////////////////////////////////////////////////////////////////////////////
// Metadata layout
struct MetadataLayout_SoA
{
uint16_t* metadata;
MetadataLayout_SoA() noexcept : metadata(nullptr)
{}
MetadataLayout_SoA(size_t num_bins) noexcept
{
metadata = (uint16_t*)malloc(num_bins * sizeof(uint16_t));
memset(metadata, 0, num_bins * sizeof(uint16_t));
}
~MetadataLayout_SoA() noexcept
{
free(metadata);
metadata = nullptr;
}
__forceinline void Clear(size_t initial_pos, size_t size_in_bins) noexcept
{
memset(metadata + initial_pos, 0, size_in_bins * sizeof(uint16_t));
}
__forceinline void ReallocMetadata(size_t new_num_bins) noexcept
{
metadata = (uint16_t*)realloc(metadata, new_num_bins * sizeof(uint16_t));
}
/////////////////////////////////////////////////////////////////////
// Metadata coded utilities
/////////////////////////////////////////////////////////////////////
//
// Unlucky Bucket is Element
// bucket Reversed Distance Labels
// ------- ---------- -------- --------
// | | | | | |
// b7 b6 b5 b4 b3 b2 b1 b0
// 0b00'000'000
__forceinline uint16_t at(size_t pos) const noexcept
{
return metadata[pos];
}
__forceinline uint16_t Get_Label(size_t pos) const noexcept
{
return metadata[pos] & 0b00'000'111u;
}
__forceinline bool Is_Empty(size_t pos) const noexcept
{
return Get_Label(pos) == 0;
}
__forceinline void Set_Empty(size_t pos) noexcept
{
metadata[pos] &= 0b11'000'000;
}
__forceinline uint16_t Get_Hash(size_t pos) const noexcept
{
return metadata[pos] & 0xFF00u;
}
__forceinline void Update_Bin_At(size_t pos, size_t distance_to_base, bool is_reverse_item, uint_fast16_t label, size_t hash) noexcept
{
metadata[pos] = uint16_t((hash & 0xFF00) | (metadata[pos] & 0b11'000'000) | (is_reverse_item ? 0b00'100'000 : 0) | (distance_to_base << 3) | label);
}
__forceinline bool Is_Item_In_Reverse_Bucket(size_t pos) const noexcept
{
return metadata[pos] & 0b00'100'000;
}
__forceinline uint16_t Distance_to_Entry_Bin(size_t pos) const noexcept
{
return (metadata[pos] >> 3u) & 0b11u;
}
/*__forceinline bool Is_Unlucky_Bucket(size_t pos) const noexcept
{
return metadata[pos] & 0b10'000'000;
}*/
__forceinline void Set_Unlucky_Bucket(size_t pos) noexcept
{
metadata[pos] |= 0b10'000'000;
}
__forceinline bool Is_Bucket_Reversed(size_t pos) const noexcept
{
return metadata[pos] & 0b01'000'000;
}
__forceinline void Set_Bucket_Reversed(size_t pos) noexcept
{
metadata[pos] |= 0b01'000'000;
}
//// Cache line aware
//__forceinline bool Benefit_With_Reversal(size_t pos, size_t size_bucket) const noexcept
//{
// uintptr_t begin_cache_line = reinterpret_cast<uintptr_t>(metadata + pos) & (~static_cast<uintptr_t>(63));
// uintptr_t end_cache_line = reinterpret_cast<uintptr_t>(metadata + pos + size_bucket - 1) & (~static_cast<uintptr_t>(63));
// return begin_cache_line < end_cache_line;
//}
};
// Data layouts
template<class KEY> struct KeyLayout_SoA : public MetadataLayout_SoA
{
KEY* keys;
// Constructors
KeyLayout_SoA() noexcept : keys(nullptr), MetadataLayout_SoA()
{}
KeyLayout_SoA(size_t num_buckets) noexcept : MetadataLayout_SoA(num_buckets)
{
keys = (KEY*)malloc(num_buckets * sizeof(KEY));
}
~KeyLayout_SoA() noexcept
{
free(keys);
keys = nullptr;
}
__forceinline void MoveElem(size_t dest, size_t orig) noexcept
{
keys[dest] = keys[orig];
}
__forceinline void SaveElem(size_t pos, const KEY& elem) noexcept
{
keys[pos] = elem;
}
__forceinline const KEY& GetKey(size_t pos) const noexcept
{
return keys[pos];
}
__forceinline const KEY& GetKeyFromValue(const KEY& elem) const noexcept
{
return elem;
}
__forceinline KEY GetElem(size_t pos) const noexcept
{
return keys[pos];
}
__forceinline KEY* GetValue(size_t pos) const noexcept
{
return keys + pos;
}
__forceinline void ReallocElems(size_t new_num_buckets) noexcept
{
keys = (KEY*)realloc(keys, new_num_buckets * sizeof(KEY));
}
};
template<class KEY, class T> struct MapLayout_SoA : public MetadataLayout_SoA
{
using INSERT_TYPE = std::pair<KEY, T>;
KEY* keys;
T* data;
// Constructors
MapLayout_SoA() noexcept : keys(nullptr), data(nullptr), MetadataLayout_SoA()
{}
MapLayout_SoA(size_t num_buckets) noexcept : MetadataLayout_SoA(num_buckets)
{
keys = (KEY*)malloc(num_buckets * sizeof(KEY));
data = (T*)malloc(num_buckets * sizeof(T));
}
~MapLayout_SoA() noexcept
{
free(keys);
free(data);
keys = nullptr;
data = nullptr;
}
__forceinline void MoveElem(size_t dest, size_t orig) noexcept
{
keys[dest] = keys[orig];
data[dest] = data[orig];
}
__forceinline void SaveElem(size_t pos, const INSERT_TYPE& elem) noexcept
{
keys[pos] = elem.first;
data[pos] = elem.second;
}
__forceinline const KEY& GetKey(size_t pos) const noexcept
{
return keys[pos];
}
__forceinline const KEY& GetKeyFromValue(const INSERT_TYPE& elem) const noexcept
{
return elem.first;
}
__forceinline INSERT_TYPE GetElem(size_t pos) const noexcept
{
return std::make_pair(keys[pos], data[pos]);
}
__forceinline T* GetValue(size_t pos) const noexcept
{
return data + pos;
}
__forceinline void ReallocElems(size_t new_num_buckets) noexcept
{
keys = (KEY*)realloc(keys, new_num_buckets * sizeof(KEY));
data = (T*)realloc(data, new_num_buckets * sizeof(T));
}
};
///////////////////////////////////////////////////////////////////////////////
// Data layout is "Array of Structs"
///////////////////////////////////////////////////////////////////////////////
// Auxiliary class
template<size_t ELEM_SIZE> struct ElemLayout
{
uint8_t metadata;
uint8_t elem[ELEM_SIZE];
};
// Metadata layout
template<size_t ELEM_SIZE> struct MetadataLayout_AoS
{
ElemLayout<ELEM_SIZE>* all_data;
MetadataLayout_AoS() noexcept : all_data(nullptr)
{
}
MetadataLayout_AoS(size_t num_bins) noexcept
{
all_data = (ElemLayout<ELEM_SIZE>*)malloc(num_bins * sizeof(ElemLayout<ELEM_SIZE>));
for (size_t i = 0; i < num_bins; i++)
all_data[i].metadata = 0;
}
~MetadataLayout_AoS() noexcept
{
free(all_data);
all_data = nullptr;
}
__forceinline void Clear(size_t initial_pos, size_t size_in_bins) noexcept
{
for (size_t i = initial_pos; i < (initial_pos + size_in_bins); i++)
all_data[i].metadata = 0;
}
__forceinline void ReallocMetadata(size_t new_num_bins) noexcept
{
all_data = (ElemLayout<ELEM_SIZE>*)realloc(all_data, new_num_bins * sizeof(ElemLayout<ELEM_SIZE>));
}
/////////////////////////////////////////////////////////////////////
// Metadata coded utilities
/////////////////////////////////////////////////////////////////////
//
// Unlucky Bucket is Element
// bucket Reversed Distance Labels
// ------- ---------- -------- --------
// | | | | | |
// b7 b6 b5 b4 b3 b2 b1 b0
// 0b00'000'000
__forceinline uint8_t at(size_t pos) const noexcept
{
return all_data[pos].metadata;
}
__forceinline uint8_t Get_Label(size_t pos) const noexcept
{
return all_data[pos].metadata & 0b00'000'111;
}
__forceinline bool Is_Empty(size_t pos) const noexcept
{
return Get_Label(pos) == 0;
}
__forceinline void Set_Empty(size_t pos) noexcept
{
all_data[pos].metadata &= 0b11'000'000;
}
__forceinline uint16_t Get_Hash(size_t pos) const noexcept
{
return 0;
}
__forceinline void Update_Bin_At(size_t pos, size_t distance_to_base, bool is_reverse_item, uint_fast16_t label, size_t hash) noexcept
{
all_data[pos].metadata = (all_data[pos].metadata & 0b11'000'000) | (is_reverse_item ? 0b00'100'000 : 0) | (uint8_t(distance_to_base) << 3) | label;
}
__forceinline bool Is_Item_In_Reverse_Bucket(size_t pos) const noexcept
{
return all_data[pos].metadata & 0b00'100'000;
}
__forceinline uint16_t Distance_to_Entry_Bin(size_t pos) const noexcept
{
return (all_data[pos].metadata >> 3) & 0b11;
}
/*__forceinline bool Is_Unlucky_Bucket(size_t pos) const noexcept
{
return all_data[pos].metadata & 0b10'000'000;
}*/
__forceinline void Set_Unlucky_Bucket(size_t pos) noexcept
{
all_data[pos].metadata |= 0b10'000'000;
}
__forceinline bool Is_Bucket_Reversed(size_t pos) const noexcept
{
return all_data[pos].metadata & 0b01'000'000;
}
__forceinline void Set_Bucket_Reversed(size_t pos) noexcept
{
all_data[pos].metadata |= 0b01'000'000;
}
//// Cache line aware
//__forceinline bool Benefit_With_Reversal(size_t pos, size_t size_bucket) const noexcept
//{
// uintptr_t begin_cache_line = reinterpret_cast<uintptr_t>(all_data + pos) & (~static_cast<uintptr_t>(63));
// uintptr_t end_cache_line = reinterpret_cast<uintptr_t>(all_data + pos + size_bucket - 1) & (~static_cast<uintptr_t>(63));
// uintptr_t reverse_cache_line = reinterpret_cast<uintptr_t>(all_data + pos - (size_bucket - 1)) & (~static_cast<uintptr_t>(63));
// // TODO: Do more checks, this is too simple
// return begin_cache_line < end_cache_line && reverse_cache_line == begin_cache_line;
//}
};
// Data layouts
template<class KEY> struct KeyLayout_AoS : public MetadataLayout_AoS<sizeof(KEY)>
{
// Constructors
KeyLayout_AoS() noexcept : MetadataLayout_AoS<sizeof(KEY)>()
{}
KeyLayout_AoS(size_t num_bins) noexcept : MetadataLayout_AoS<sizeof(KEY)>(num_bins)
{}
__forceinline void MoveElem(size_t dest, size_t orig) noexcept
{
memcpy(all_data[dest].elem, all_data[orig].elem, sizeof(KEY));
}
__forceinline void SaveElem(size_t pos, const KEY& elem) noexcept
{
memcpy(all_data[pos].elem, &elem, sizeof(KEY));
}
__forceinline const KEY& GetKey(size_t pos) const noexcept
{
return *((KEY*)(all_data[pos].elem));
}
__forceinline const KEY& GetKeyFromValue(const KEY& elem) const noexcept
{
return elem;
}
__forceinline KEY GetElem(size_t pos) const noexcept
{
return *((KEY*)(all_data[pos].elem));
}
__forceinline KEY* GetValue(size_t pos) const noexcept
{
return (KEY*)(all_data[pos].elem);
}
__forceinline void ReallocElems(size_t new_num_buckets) noexcept
{
// Nothing
}
};
template<class KEY, class T> struct MapLayout_AoS : public MetadataLayout_AoS<sizeof(KEY) + sizeof(T)>
{
using INSERT_TYPE = std::pair<KEY, T>;
// Constructors
MapLayout_AoS() noexcept : MetadataLayout_AoS<sizeof(KEY) + sizeof(T)>()
{}
MapLayout_AoS(size_t num_buckets) noexcept : MetadataLayout_AoS<sizeof(KEY) + sizeof(T)>(num_buckets)
{}
__forceinline void MoveElem(size_t dest, size_t orig) noexcept
{
memcpy(all_data[dest].elem, all_data[orig].elem, sizeof(KEY) + sizeof(T));
}
__forceinline void SaveElem(size_t pos, const INSERT_TYPE& elem) noexcept
{
memcpy(all_data[pos].elem, &elem.first, sizeof(KEY));
memcpy(all_data[pos].elem + sizeof(KEY), &elem.second, sizeof(T));
}
__forceinline const KEY& GetKey(size_t pos) const noexcept
{
return *((KEY*)(all_data[pos].elem));
}
__forceinline const KEY& GetKeyFromValue(const INSERT_TYPE& elem) const noexcept
{
return elem.first;
}
__forceinline INSERT_TYPE GetElem(size_t pos) const noexcept
{
return std::make_pair(*((KEY*)(all_data[pos].elem)), *((T*)(all_data[pos].elem + sizeof(KEY))));
}
__forceinline T* GetValue(size_t pos) const noexcept
{
return (T*)(all_data[pos].elem + sizeof(KEY));
}
__forceinline void ReallocElems(size_t new_num_buckets) noexcept
{
// Nothing
}
};
///////////////////////////////////////////////////////////////////////////////
// Data layout is "Array of Blocks"
///////////////////////////////////////////////////////////////////////////////
// Auxiliary classes
template<class T> struct BlockKey
{
static constexpr size_t BLOCK_SIZE = alignof(T);
uint8_t metadata[BLOCK_SIZE];
T data[BLOCK_SIZE];
};
template<class KEY, class T> struct MaxAlignOf
{
static constexpr size_t BLOCK_SIZE = std::max(alignof(KEY), alignof(T));
};
template<class KEY, class T> struct BlockMap
{
uint8_t metadata[MaxAlignOf<KEY, T>::BLOCK_SIZE];
KEY keys[MaxAlignOf<KEY, T>::BLOCK_SIZE];
T data[MaxAlignOf<KEY, T>::BLOCK_SIZE];
};
// Metadata layout
template<size_t BLOCK_SIZE, class BLOCK> struct MetadataLayout_AoB
{
BLOCK* all_data;
MetadataLayout_AoB() noexcept : all_data(nullptr)
{}
MetadataLayout_AoB(size_t num_bins) noexcept
{
num_bins = (num_bins + BLOCK_SIZE - 1) / BLOCK_SIZE;
all_data = (BLOCK*)malloc(num_bins * sizeof(BLOCK));
for (size_t i = 0; i < num_bins; i++)
for (size_t j = 0; j < BLOCK_SIZE; j++)
all_data[i].metadata[j] = 0;
}
~MetadataLayout_AoB() noexcept
{
free(all_data);
all_data = nullptr;
}
__forceinline void Clear(size_t initial_pos, size_t size_in_bins) noexcept
{
for (size_t i = initial_pos; i < (initial_pos + size_in_bins); i++)
all_data[i / BLOCK_SIZE].metadata[i % BLOCK_SIZE] = 0;
}
__forceinline void ReallocMetadata(size_t new_num_bins) noexcept
{
new_num_bins = (new_num_bins + BLOCK_SIZE - 1) / BLOCK_SIZE;
all_data = (BLOCK*)realloc(all_data, new_num_bins * sizeof(BLOCK));
}
/////////////////////////////////////////////////////////////////////
// Metadata coded utilities
/////////////////////////////////////////////////////////////////////
//
// Unlucky Bucket is Element
// bucket Reversed Distance Labels
// ------- ---------- -------- --------
// | | | | | |
// b7 b6 b5 b4 b3 b2 b1 b0
// 0b00'000'000
__forceinline uint8_t at(size_t pos) const noexcept
{
return all_data[pos / BLOCK_SIZE].metadata[pos%BLOCK_SIZE];
}
__forceinline uint8_t Get_Label(size_t pos) const noexcept
{
return at(pos) & 0b00'000'111u;
}
__forceinline bool Is_Empty(size_t pos) const noexcept
{
return Get_Label(pos) == 0;
}
__forceinline void Set_Empty(size_t pos) noexcept
{
all_data[pos / BLOCK_SIZE].metadata[pos%BLOCK_SIZE] &= 0b11'000'000;
}
__forceinline uint16_t Get_Hash(size_t /*pos*/) const noexcept
{
return 0;
}
__forceinline void Update_Bin_At(size_t pos, size_t distance_to_base, bool is_reverse_item, uint_fast16_t label, size_t /*hash*/) noexcept
{
all_data[pos / BLOCK_SIZE].metadata[pos%BLOCK_SIZE] = uint8_t((at(pos) & 0b11'000'000) | (is_reverse_item ? 0b00'100'000 : 0) | (distance_to_base << 3) | label);
}
__forceinline bool Is_Item_In_Reverse_Bucket(size_t pos) const noexcept
{
return at(pos) & 0b00'100'000;
}
__forceinline uint16_t Distance_to_Entry_Bin(size_t pos) const noexcept
{
return (at(pos) >> 3u) & 0b11u;
}
/*__forceinline bool Is_Unlucky_Bucket(size_t pos) const noexcept
{
return at(pos) & 0b10'000'000;
}*/
__forceinline void Set_Unlucky_Bucket(size_t pos) noexcept
{
all_data[pos / BLOCK_SIZE].metadata[pos%BLOCK_SIZE] |= 0b10'000'000;
}
__forceinline bool Is_Bucket_Reversed(size_t pos) const noexcept
{
return at(pos) & 0b01'000'000;
}
__forceinline void Set_Bucket_Reversed(size_t pos) noexcept
{
all_data[pos / BLOCK_SIZE].metadata[pos%BLOCK_SIZE] |= 0b01'000'000;
}
//// Cache line aware
//__forceinline bool Benefit_With_Reversal(size_t pos, size_t size_bucket) const noexcept
//{
// // TODO: Make calculations here
// return false;
//}
};
// Data layouts
template<class KEY> struct KeyLayout_AoB : public MetadataLayout_AoB<alignof(KEY), BlockKey<KEY>>
{
static constexpr size_t BLOCK_SIZE = alignof(KEY);
// Constructors
KeyLayout_AoB() noexcept : MetadataLayout_AoB()
{}
KeyLayout_AoB(size_t num_bins) noexcept : MetadataLayout_AoB(num_bins)
{}
__forceinline void MoveElem(size_t dest, size_t orig) noexcept
{
all_data[dest / BLOCK_SIZE].data[dest%BLOCK_SIZE] = all_data[orig / BLOCK_SIZE].data[orig%BLOCK_SIZE];
}
__forceinline void SaveElem(size_t pos, const KEY& elem) noexcept
{
all_data[pos / BLOCK_SIZE].data[pos%BLOCK_SIZE] = elem;
}
__forceinline const KEY& GetKey(size_t pos) const noexcept
{
return all_data[pos / BLOCK_SIZE].data[pos%BLOCK_SIZE];
}
__forceinline const KEY& GetKeyFromValue(const KEY& elem) const noexcept
{
return elem;
}
__forceinline KEY GetElem(size_t pos) const noexcept
{
return all_data[pos / BLOCK_SIZE].data[pos%BLOCK_SIZE];
}
__forceinline KEY* GetValue(size_t pos) const noexcept
{
return all_data[pos / BLOCK_SIZE].data + pos%BLOCK_SIZE;
}
__forceinline void ReallocElems(size_t new_num_buckets) noexcept
{
// Nothing
}
};
template<class KEY, class T> struct MapLayout_AoB : public MetadataLayout_AoB<MaxAlignOf<KEY, T>::BLOCK_SIZE, BlockMap<KEY, T>>
{
using INSERT_TYPE = std::pair<KEY, T>;
static constexpr size_t BLOCK_SIZE = std::max(alignof(KEY), alignof(T));
// Constructors
MapLayout_AoB() noexcept : MetadataLayout_AoB()
{}
MapLayout_AoB(size_t num_buckets) noexcept : MetadataLayout_AoB(num_buckets)
{}
__forceinline void MoveElem(size_t dest, size_t orig) noexcept
{
all_data[dest / BLOCK_SIZE].keys[dest%BLOCK_SIZE] = all_data[orig / BLOCK_SIZE].keys[orig%BLOCK_SIZE];
all_data[dest / BLOCK_SIZE].data[dest%BLOCK_SIZE] = all_data[orig / BLOCK_SIZE].data[orig%BLOCK_SIZE];
}
__forceinline void SaveElem(size_t pos, const INSERT_TYPE& elem) noexcept
{
all_data[pos / BLOCK_SIZE].keys[pos%BLOCK_SIZE] = elem.first;
all_data[pos / BLOCK_SIZE].data[pos%BLOCK_SIZE] = elem.second;
}
__forceinline const KEY& GetKey(size_t pos) const noexcept
{
return all_data[pos / BLOCK_SIZE].keys[pos%BLOCK_SIZE];
}
__forceinline const KEY& GetKeyFromValue(const INSERT_TYPE& elem) const noexcept
{
return elem.first;
}
__forceinline INSERT_TYPE GetElem(size_t pos) const noexcept
{
return std::make_pair(all_data[pos / BLOCK_SIZE].keys[pos%BLOCK_SIZE], all_data[pos / BLOCK_SIZE].data[pos%BLOCK_SIZE]);
}
__forceinline T* GetValue(size_t pos) const noexcept
{