lpn 0.2.0

Software to study attacks on the Learning Parity with Noise problem
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
use std::boxed::Box;
use std::default::Default;
use std::sync::Once;

use fnv::FnvHashMap;

use m4ri_rust::friendly::BinMatrix;
use m4ri_rust::friendly::BinVector;

use crate::codes::BinaryCode;

/// ``[21, 11]`` Guava code
///
/// Best code found from the GUAVA database version 3.15
///
/// Decodes using Syndrome decoding
#[derive(Clone, Serialize)]
pub struct GuavaCode21_11;

static INIT: Once = Once::new();
static mut GENERATOR_MATRIX: *const BinMatrix = 0 as *const BinMatrix;
static mut PARITY_MATRIX: *const BinMatrix = 0 as *const BinMatrix;
static mut PARITY_MATRIX_T: *const BinMatrix = 0 as *const BinMatrix;
static mut SYNDROME_MAP: *const FnvHashMap<u64, &'static [usize; 1]> = 0 as *const FnvHashMap<u64, &'static [usize; 1]>;

fn init() {
    INIT.call_once(|| {
        unsafe {
            let matrix = Box::new(BinMatrix::from_slices(&[
                &[ 976897 ],
                &[ 929794 ],
                &[ 1353732 ],
                &[ 1490952 ],
                &[ 776208 ],
                &[ 1140768 ],
                &[ 1964096 ],
                &[ 1734784 ],
                &[ 1771776 ],
                &[ 1827328 ],
                &[ 1917952 ],
                
            ], 21));
            GENERATOR_MATRIX = Box::into_raw(matrix);

            let matrix = Box::new(BinMatrix::from_slices(&[
                &[ 1232897 ],
                &[ 1482882 ],
                &[ 684164 ],
                &[ 1112200 ],
                &[ 755856 ],
                &[ 880672 ],
                &[ 1915072 ],
                &[ 223488 ],
                &[ 1993216 ],
                &[ 508928 ],
                
            ], 21));
            let matrix_t = Box::new(matrix.transposed());
            PARITY_MATRIX = Box::into_raw(matrix);
            PARITY_MATRIX_T = Box::into_raw(matrix_t);

            let mut map = Box::new(FnvHashMap::with_capacity_and_hasher(1024, Default::default()));
            map.insert(0, &[0]);     // 0 => [0]
            map.insert(1, &[1]);     // 1 => [1]
            map.insert(2, &[2]);     // 2 => [2]
            map.insert(4, &[4]);     // 4 => [4]
            map.insert(8, &[8]);     // 8 => [8]
            map.insert(16, &[16]);     // 16 => [16]
            map.insert(32, &[32]);     // 32 => [32]
            map.insert(64, &[64]);     // 64 => [64]
            map.insert(94, &[128]);     // 94 => [128]
            map.insert(128, &[256]);     // 128 => [256]
            map.insert(256, &[512]);     // 256 => [512]
            map.insert(512, &[1024]);     // 512 => [1024]
            map.insert(472, &[2048]);     // 472 => [2048]
            map.insert(109, &[4096]);     // 109 => [4096]
            map.insert(494, &[8192]);     // 494 => [8192]
            map.insert(941, &[16384]);     // 941 => [16384]
            map.insert(539, &[32768]);     // 539 => [32768]
            map.insert(752, &[65536]);     // 752 => [65536]
            map.insert(919, &[131072]);     // 919 => [131072]
            map.insert(866, &[262144]);     // 866 => [262144]
            map.insert(372, &[524288]);     // 372 => [524288]
            map.insert(331, &[1048576]);     // 331 => [1048576]
            map.insert(3, &[3]);     // 3 => [3]
            map.insert(5, &[5]);     // 5 => [5]
            map.insert(9, &[9]);     // 9 => [9]
            map.insert(17, &[17]);     // 17 => [17]
            map.insert(33, &[33]);     // 33 => [33]
            map.insert(65, &[65]);     // 65 => [65]
            map.insert(95, &[129]);     // 95 => [129]
            map.insert(129, &[257]);     // 129 => [257]
            map.insert(257, &[513]);     // 257 => [513]
            map.insert(513, &[1025]);     // 513 => [1025]
            map.insert(473, &[2049]);     // 473 => [2049]
            map.insert(108, &[4097]);     // 108 => [4097]
            map.insert(495, &[8193]);     // 495 => [8193]
            map.insert(940, &[16385]);     // 940 => [16385]
            map.insert(538, &[32769]);     // 538 => [32769]
            map.insert(753, &[65537]);     // 753 => [65537]
            map.insert(918, &[131073]);     // 918 => [131073]
            map.insert(867, &[262145]);     // 867 => [262145]
            map.insert(373, &[524289]);     // 373 => [524289]
            map.insert(330, &[1048577]);     // 330 => [1048577]
            map.insert(6, &[6]);     // 6 => [6]
            map.insert(10, &[10]);     // 10 => [10]
            map.insert(18, &[18]);     // 18 => [18]
            map.insert(34, &[34]);     // 34 => [34]
            map.insert(66, &[66]);     // 66 => [66]
            map.insert(92, &[130]);     // 92 => [130]
            map.insert(130, &[258]);     // 130 => [258]
            map.insert(258, &[514]);     // 258 => [514]
            map.insert(514, &[1026]);     // 514 => [1026]
            map.insert(474, &[2050]);     // 474 => [2050]
            map.insert(111, &[4098]);     // 111 => [4098]
            map.insert(492, &[8194]);     // 492 => [8194]
            map.insert(943, &[16386]);     // 943 => [16386]
            map.insert(537, &[32770]);     // 537 => [32770]
            map.insert(754, &[65538]);     // 754 => [65538]
            map.insert(917, &[131074]);     // 917 => [131074]
            map.insert(864, &[262146]);     // 864 => [262146]
            map.insert(374, &[524290]);     // 374 => [524290]
            map.insert(329, &[1048578]);     // 329 => [1048578]
            map.insert(12, &[12]);     // 12 => [12]
            map.insert(20, &[20]);     // 20 => [20]
            map.insert(36, &[36]);     // 36 => [36]
            map.insert(68, &[68]);     // 68 => [68]
            map.insert(90, &[132]);     // 90 => [132]
            map.insert(132, &[260]);     // 132 => [260]
            map.insert(260, &[516]);     // 260 => [516]
            map.insert(516, &[1028]);     // 516 => [1028]
            map.insert(476, &[2052]);     // 476 => [2052]
            map.insert(105, &[4100]);     // 105 => [4100]
            map.insert(490, &[8196]);     // 490 => [8196]
            map.insert(937, &[16388]);     // 937 => [16388]
            map.insert(543, &[32772]);     // 543 => [32772]
            map.insert(756, &[65540]);     // 756 => [65540]
            map.insert(915, &[131076]);     // 915 => [131076]
            map.insert(870, &[262148]);     // 870 => [262148]
            map.insert(368, &[524292]);     // 368 => [524292]
            map.insert(335, &[1048580]);     // 335 => [1048580]
            map.insert(24, &[24]);     // 24 => [24]
            map.insert(40, &[40]);     // 40 => [40]
            map.insert(72, &[72]);     // 72 => [72]
            map.insert(86, &[136]);     // 86 => [136]
            map.insert(136, &[264]);     // 136 => [264]
            map.insert(264, &[520]);     // 264 => [520]
            map.insert(520, &[1032]);     // 520 => [1032]
            map.insert(464, &[2056]);     // 464 => [2056]
            map.insert(101, &[4104]);     // 101 => [4104]
            map.insert(486, &[8200]);     // 486 => [8200]
            map.insert(933, &[16392]);     // 933 => [16392]
            map.insert(531, &[32776]);     // 531 => [32776]
            map.insert(760, &[65544]);     // 760 => [65544]
            map.insert(927, &[131080]);     // 927 => [131080]
            map.insert(874, &[262152]);     // 874 => [262152]
            map.insert(380, &[524296]);     // 380 => [524296]
            map.insert(323, &[1048584]);     // 323 => [1048584]
            map.insert(48, &[48]);     // 48 => [48]
            map.insert(80, &[80]);     // 80 => [80]
            map.insert(78, &[144]);     // 78 => [144]
            map.insert(144, &[272]);     // 144 => [272]
            map.insert(272, &[528]);     // 272 => [528]
            map.insert(528, &[1040]);     // 528 => [1040]
            map.insert(456, &[2064]);     // 456 => [2064]
            map.insert(125, &[4112]);     // 125 => [4112]
            map.insert(510, &[8208]);     // 510 => [8208]
            map.insert(957, &[16400]);     // 957 => [16400]
            map.insert(523, &[32784]);     // 523 => [32784]
            map.insert(736, &[65552]);     // 736 => [65552]
            map.insert(903, &[131088]);     // 903 => [131088]
            map.insert(882, &[262160]);     // 882 => [262160]
            map.insert(356, &[524304]);     // 356 => [524304]
            map.insert(347, &[1048592]);     // 347 => [1048592]
            map.insert(96, &[96]);     // 96 => [96]
            map.insert(126, &[160]);     // 126 => [160]
            map.insert(160, &[288]);     // 160 => [288]
            map.insert(288, &[544]);     // 288 => [544]
            map.insert(544, &[1056]);     // 544 => [1056]
            map.insert(504, &[2080]);     // 504 => [2080]
            map.insert(77, &[4128]);     // 77 => [4128]
            map.insert(462, &[8224]);     // 462 => [8224]
            map.insert(909, &[16416]);     // 909 => [16416]
            map.insert(571, &[32800]);     // 571 => [32800]
            map.insert(720, &[65568]);     // 720 => [65568]
            map.insert(951, &[131104]);     // 951 => [131104]
            map.insert(834, &[262176]);     // 834 => [262176]
            map.insert(340, &[524320]);     // 340 => [524320]
            map.insert(363, &[1048608]);     // 363 => [1048608]
            map.insert(30, &[192]);     // 30 => [192]
            map.insert(192, &[320]);     // 192 => [320]
            map.insert(320, &[576]);     // 320 => [576]
            map.insert(576, &[1088]);     // 576 => [1088]
            map.insert(408, &[2112]);     // 408 => [2112]
            map.insert(45, &[4160]);     // 45 => [4160]
            map.insert(430, &[8256]);     // 430 => [8256]
            map.insert(1005, &[16448]);     // 1005 => [16448]
            map.insert(603, &[32832]);     // 603 => [32832]
            map.insert(688, &[65600]);     // 688 => [65600]
            map.insert(983, &[131136]);     // 983 => [131136]
            map.insert(802, &[262208]);     // 802 => [262208]
            map.insert(308, &[524352]);     // 308 => [524352]
            map.insert(267, &[1048640]);     // 267 => [1048640]
            map.insert(222, &[384]);     // 222 => [384]
            map.insert(350, &[640]);     // 350 => [640]
            map.insert(606, &[1152]);     // 606 => [1152]
            map.insert(390, &[2176]);     // 390 => [2176]
            map.insert(51, &[4224]);     // 51 => [4224]
            map.insert(432, &[8320]);     // 432 => [8320]
            map.insert(1011, &[16512]);     // 1011 => [16512]
            map.insert(581, &[32896]);     // 581 => [32896]
            map.insert(686, &[65664]);     // 686 => [65664]
            map.insert(969, &[131200]);     // 969 => [131200]
            map.insert(828, &[262272]);     // 828 => [262272]
            map.insert(298, &[524416]);     // 298 => [524416]
            map.insert(277, &[1048704]);     // 277 => [1048704]
            map.insert(384, &[768]);     // 384 => [768]
            map.insert(640, &[1280]);     // 640 => [1280]
            map.insert(344, &[2304]);     // 344 => [2304]
            map.insert(237, &[4352]);     // 237 => [4352]
            map.insert(366, &[8448]);     // 366 => [8448]
            map.insert(813, &[16640]);     // 813 => [16640]
            map.insert(667, &[33024]);     // 667 => [33024]
            map.insert(624, &[65792]);     // 624 => [65792]
            map.insert(791, &[131328]);     // 791 => [131328]
            map.insert(994, &[262400]);     // 994 => [262400]
            map.insert(500, &[524544]);     // 500 => [524544]
            map.insert(459, &[1048832]);     // 459 => [1048832]
            map.insert(768, &[1536]);     // 768 => [1536]
            map.insert(216, &[2560]);     // 216 => [2560]
            map.insert(365, &[4608]);     // 365 => [4608]
            map.insert(238, &[8704]);     // 238 => [8704]
            map.insert(685, &[16896]);     // 685 => [16896]
            map.insert(795, &[33280]);     // 795 => [33280]
            map.insert(1008, &[66048]);     // 1008 => [66048]
            map.insert(663, &[131584]);     // 663 => [131584]
            map.insert(610, &[262656]);     // 610 => [262656]
            map.insert(116, &[524800]);     // 116 => [524800]
            map.insert(75, &[1049088]);     // 75 => [1049088]
            map.insert(984, &[3072]);     // 984 => [3072]
            map.insert(621, &[5120]);     // 621 => [5120]
            map.insert(1006, &[9216]);     // 1006 => [9216]
            map.insert(429, &[17408]);     // 429 => [17408]
            map.insert(27, &[33792]);     // 27 => [33792]
            map.insert(240, &[66560]);     // 240 => [66560]
            map.insert(407, &[132096]);     // 407 => [132096]
            map.insert(354, &[263168]);     // 354 => [263168]
            map.insert(884, &[525312]);     // 884 => [525312]
            map.insert(843, &[1049600]);     // 843 => [1049600]
            map.insert(437, &[6144]);     // 437 => [6144]
            map.insert(54, &[10240]);     // 54 => [10240]
            map.insert(629, &[18432]);     // 629 => [18432]
            map.insert(963, &[34816]);     // 963 => [34816]
            map.insert(808, &[67584]);     // 808 => [67584]
            map.insert(591, &[133120]);     // 591 => [133120]
            map.insert(698, &[264192]);     // 698 => [264192]
            map.insert(172, &[526336]);     // 172 => [526336]
            map.insert(147, &[1050624]);     // 147 => [1050624]
            map.insert(387, &[12288]);     // 387 => [12288]
            map.insert(960, &[20480]);     // 960 => [20480]
            map.insert(630, &[36864]);     // 630 => [36864]
            map.insert(669, &[69632]);     // 669 => [69632]
            map.insert(1018, &[135168]);     // 1018 => [135168]
            map.insert(783, &[266240]);     // 783 => [266240]
            map.insert(281, &[528384]);     // 281 => [528384]
            map.insert(294, &[1052672]);     // 294 => [1052672]
            map.insert(579, &[24576]);     // 579 => [24576]
            map.insert(1013, &[40960]);     // 1013 => [40960]
            map.insert(798, &[73728]);     // 798 => [73728]
            map.insert(633, &[139264]);     // 633 => [139264]
            map.insert(652, &[270336]);     // 652 => [270336]
            map.insert(154, &[532480]);     // 154 => [532480]
            map.insert(165, &[1056768]);     // 165 => [1056768]
            map.insert(438, &[49152]);     // 438 => [49152]
            map.insert(349, &[81920]);     // 349 => [81920]
            map.insert(58, &[147456]);     // 58 => [147456]
            map.insert(207, &[278528]);     // 207 => [278528]
            map.insert(729, &[540672]);     // 729 => [540672]
            map.insert(742, &[1064960]);     // 742 => [1064960]
            map.insert(235, &[98304]);     // 235 => [98304]
            map.insert(396, &[163840]);     // 396 => [163840]
            map.insert(377, &[294912]);     // 377 => [294912]
            map.insert(879, &[557056]);     // 879 => [557056]
            map.insert(848, &[1081344]);     // 848 => [1081344]
            map.insert(359, &[196608]);     // 359 => [196608]
            map.insert(402, &[327680]);     // 402 => [327680]
            map.insert(900, &[589824]);     // 900 => [589824]
            map.insert(955, &[1114112]);     // 955 => [1114112]
            map.insert(245, &[393216]);     // 245 => [393216]
            map.insert(739, &[655360]);     // 739 => [655360]
            map.insert(732, &[1179648]);     // 732 => [1179648]
            map.insert(534, &[786432]);     // 534 => [786432]
            map.insert(553, &[1310720]);     // 553 => [1310720]
            map.insert(63, &[1572864]);     // 63 => [1572864]
            map.insert(7, &[7]);     // 7 => [7]
            map.insert(11, &[11]);     // 11 => [11]
            map.insert(19, &[19]);     // 19 => [19]
            map.insert(35, &[35]);     // 35 => [35]
            map.insert(67, &[67]);     // 67 => [67]
            map.insert(93, &[131]);     // 93 => [131]
            map.insert(131, &[259]);     // 131 => [259]
            map.insert(259, &[515]);     // 259 => [515]
            map.insert(515, &[1027]);     // 515 => [1027]
            map.insert(475, &[2051]);     // 475 => [2051]
            map.insert(110, &[4099]);     // 110 => [4099]
            map.insert(493, &[8195]);     // 493 => [8195]
            map.insert(942, &[16387]);     // 942 => [16387]
            map.insert(536, &[32771]);     // 536 => [32771]
            map.insert(755, &[65539]);     // 755 => [65539]
            map.insert(916, &[131075]);     // 916 => [131075]
            map.insert(865, &[262147]);     // 865 => [262147]
            map.insert(375, &[524291]);     // 375 => [524291]
            map.insert(328, &[1048579]);     // 328 => [1048579]
            map.insert(13, &[13]);     // 13 => [13]
            map.insert(21, &[21]);     // 21 => [21]
            map.insert(37, &[37]);     // 37 => [37]
            map.insert(69, &[69]);     // 69 => [69]
            map.insert(91, &[133]);     // 91 => [133]
            map.insert(133, &[261]);     // 133 => [261]
            map.insert(261, &[517]);     // 261 => [517]
            map.insert(517, &[1029]);     // 517 => [1029]
            map.insert(477, &[2053]);     // 477 => [2053]
            map.insert(104, &[4101]);     // 104 => [4101]
            map.insert(491, &[8197]);     // 491 => [8197]
            map.insert(936, &[16389]);     // 936 => [16389]
            map.insert(542, &[32773]);     // 542 => [32773]
            map.insert(757, &[65541]);     // 757 => [65541]
            map.insert(914, &[131077]);     // 914 => [131077]
            map.insert(871, &[262149]);     // 871 => [262149]
            map.insert(369, &[524293]);     // 369 => [524293]
            map.insert(334, &[1048581]);     // 334 => [1048581]
            map.insert(25, &[25]);     // 25 => [25]
            map.insert(41, &[41]);     // 41 => [41]
            map.insert(73, &[73]);     // 73 => [73]
            map.insert(87, &[137]);     // 87 => [137]
            map.insert(137, &[265]);     // 137 => [265]
            map.insert(265, &[521]);     // 265 => [521]
            map.insert(521, &[1033]);     // 521 => [1033]
            map.insert(465, &[2057]);     // 465 => [2057]
            map.insert(100, &[4105]);     // 100 => [4105]
            map.insert(487, &[8201]);     // 487 => [8201]
            map.insert(932, &[16393]);     // 932 => [16393]
            map.insert(530, &[32777]);     // 530 => [32777]
            map.insert(761, &[65545]);     // 761 => [65545]
            map.insert(926, &[131081]);     // 926 => [131081]
            map.insert(875, &[262153]);     // 875 => [262153]
            map.insert(381, &[524297]);     // 381 => [524297]
            map.insert(322, &[1048585]);     // 322 => [1048585]
            map.insert(49, &[49]);     // 49 => [49]
            map.insert(81, &[81]);     // 81 => [81]
            map.insert(79, &[145]);     // 79 => [145]
            map.insert(145, &[273]);     // 145 => [273]
            map.insert(273, &[529]);     // 273 => [529]
            map.insert(529, &[1041]);     // 529 => [1041]
            map.insert(457, &[2065]);     // 457 => [2065]
            map.insert(124, &[4113]);     // 124 => [4113]
            map.insert(511, &[8209]);     // 511 => [8209]
            map.insert(956, &[16401]);     // 956 => [16401]
            map.insert(522, &[32785]);     // 522 => [32785]
            map.insert(737, &[65553]);     // 737 => [65553]
            map.insert(902, &[131089]);     // 902 => [131089]
            map.insert(883, &[262161]);     // 883 => [262161]
            map.insert(357, &[524305]);     // 357 => [524305]
            map.insert(346, &[1048593]);     // 346 => [1048593]
            map.insert(97, &[97]);     // 97 => [97]
            map.insert(127, &[161]);     // 127 => [161]
            map.insert(161, &[289]);     // 161 => [289]
            map.insert(289, &[545]);     // 289 => [545]
            map.insert(545, &[1057]);     // 545 => [1057]
            map.insert(505, &[2081]);     // 505 => [2081]
            map.insert(76, &[4129]);     // 76 => [4129]
            map.insert(463, &[8225]);     // 463 => [8225]
            map.insert(908, &[16417]);     // 908 => [16417]
            map.insert(570, &[32801]);     // 570 => [32801]
            map.insert(721, &[65569]);     // 721 => [65569]
            map.insert(950, &[131105]);     // 950 => [131105]
            map.insert(835, &[262177]);     // 835 => [262177]
            map.insert(341, &[524321]);     // 341 => [524321]
            map.insert(362, &[1048609]);     // 362 => [1048609]
            map.insert(31, &[193]);     // 31 => [193]
            map.insert(193, &[321]);     // 193 => [321]
            map.insert(321, &[577]);     // 321 => [577]
            map.insert(577, &[1089]);     // 577 => [1089]
            map.insert(409, &[2113]);     // 409 => [2113]
            map.insert(44, &[4161]);     // 44 => [4161]
            map.insert(431, &[8257]);     // 431 => [8257]
            map.insert(1004, &[16449]);     // 1004 => [16449]
            map.insert(602, &[32833]);     // 602 => [32833]
            map.insert(689, &[65601]);     // 689 => [65601]
            map.insert(982, &[131137]);     // 982 => [131137]
            map.insert(803, &[262209]);     // 803 => [262209]
            map.insert(309, &[524353]);     // 309 => [524353]
            map.insert(266, &[1048641]);     // 266 => [1048641]
            map.insert(223, &[385]);     // 223 => [385]
            map.insert(351, &[641]);     // 351 => [641]
            map.insert(607, &[1153]);     // 607 => [1153]
            map.insert(391, &[2177]);     // 391 => [2177]
            map.insert(50, &[4225]);     // 50 => [4225]
            map.insert(433, &[8321]);     // 433 => [8321]
            map.insert(1010, &[16513]);     // 1010 => [16513]
            map.insert(580, &[32897]);     // 580 => [32897]
            map.insert(687, &[65665]);     // 687 => [65665]
            map.insert(968, &[131201]);     // 968 => [131201]
            map.insert(829, &[262273]);     // 829 => [262273]
            map.insert(299, &[524417]);     // 299 => [524417]
            map.insert(276, &[1048705]);     // 276 => [1048705]
            map.insert(385, &[769]);     // 385 => [769]
            map.insert(641, &[1281]);     // 641 => [1281]
            map.insert(345, &[2305]);     // 345 => [2305]
            map.insert(236, &[4353]);     // 236 => [4353]
            map.insert(367, &[8449]);     // 367 => [8449]
            map.insert(812, &[16641]);     // 812 => [16641]
            map.insert(666, &[33025]);     // 666 => [33025]
            map.insert(625, &[65793]);     // 625 => [65793]
            map.insert(790, &[131329]);     // 790 => [131329]
            map.insert(995, &[262401]);     // 995 => [262401]
            map.insert(501, &[524545]);     // 501 => [524545]
            map.insert(458, &[1048833]);     // 458 => [1048833]
            map.insert(769, &[1537]);     // 769 => [1537]
            map.insert(217, &[2561]);     // 217 => [2561]
            map.insert(364, &[4609]);     // 364 => [4609]
            map.insert(239, &[8705]);     // 239 => [8705]
            map.insert(684, &[16897]);     // 684 => [16897]
            map.insert(794, &[33281]);     // 794 => [33281]
            map.insert(1009, &[66049]);     // 1009 => [66049]
            map.insert(662, &[131585]);     // 662 => [131585]
            map.insert(611, &[262657]);     // 611 => [262657]
            map.insert(117, &[524801]);     // 117 => [524801]
            map.insert(74, &[1049089]);     // 74 => [1049089]
            map.insert(985, &[3073]);     // 985 => [3073]
            map.insert(620, &[5121]);     // 620 => [5121]
            map.insert(1007, &[9217]);     // 1007 => [9217]
            map.insert(428, &[17409]);     // 428 => [17409]
            map.insert(26, &[33793]);     // 26 => [33793]
            map.insert(241, &[66561]);     // 241 => [66561]
            map.insert(406, &[132097]);     // 406 => [132097]
            map.insert(355, &[263169]);     // 355 => [263169]
            map.insert(885, &[525313]);     // 885 => [525313]
            map.insert(842, &[1049601]);     // 842 => [1049601]
            map.insert(436, &[6145]);     // 436 => [6145]
            map.insert(55, &[10241]);     // 55 => [10241]
            map.insert(628, &[18433]);     // 628 => [18433]
            map.insert(962, &[34817]);     // 962 => [34817]
            map.insert(809, &[67585]);     // 809 => [67585]
            map.insert(590, &[133121]);     // 590 => [133121]
            map.insert(699, &[264193]);     // 699 => [264193]
            map.insert(173, &[526337]);     // 173 => [526337]
            map.insert(146, &[1050625]);     // 146 => [1050625]
            map.insert(386, &[12289]);     // 386 => [12289]
            map.insert(961, &[20481]);     // 961 => [20481]
            map.insert(631, &[36865]);     // 631 => [36865]
            map.insert(668, &[69633]);     // 668 => [69633]
            map.insert(1019, &[135169]);     // 1019 => [135169]
            map.insert(782, &[266241]);     // 782 => [266241]
            map.insert(280, &[528385]);     // 280 => [528385]
            map.insert(295, &[1052673]);     // 295 => [1052673]
            map.insert(578, &[24577]);     // 578 => [24577]
            map.insert(1012, &[40961]);     // 1012 => [40961]
            map.insert(799, &[73729]);     // 799 => [73729]
            map.insert(632, &[139265]);     // 632 => [139265]
            map.insert(653, &[270337]);     // 653 => [270337]
            map.insert(155, &[532481]);     // 155 => [532481]
            map.insert(164, &[1056769]);     // 164 => [1056769]
            map.insert(439, &[49153]);     // 439 => [49153]
            map.insert(348, &[81921]);     // 348 => [81921]
            map.insert(59, &[147457]);     // 59 => [147457]
            map.insert(206, &[278529]);     // 206 => [278529]
            map.insert(728, &[540673]);     // 728 => [540673]
            map.insert(743, &[1064961]);     // 743 => [1064961]
            map.insert(234, &[98305]);     // 234 => [98305]
            map.insert(397, &[163841]);     // 397 => [163841]
            map.insert(376, &[294913]);     // 376 => [294913]
            map.insert(878, &[557057]);     // 878 => [557057]
            map.insert(849, &[1081345]);     // 849 => [1081345]
            map.insert(358, &[196609]);     // 358 => [196609]
            map.insert(403, &[327681]);     // 403 => [327681]
            map.insert(901, &[589825]);     // 901 => [589825]
            map.insert(954, &[1114113]);     // 954 => [1114113]
            map.insert(244, &[393217]);     // 244 => [393217]
            map.insert(738, &[655361]);     // 738 => [655361]
            map.insert(733, &[1179649]);     // 733 => [1179649]
            map.insert(535, &[786433]);     // 535 => [786433]
            map.insert(552, &[1310721]);     // 552 => [1310721]
            map.insert(62, &[1572865]);     // 62 => [1572865]
            map.insert(14, &[14]);     // 14 => [14]
            map.insert(22, &[22]);     // 22 => [22]
            map.insert(38, &[38]);     // 38 => [38]
            map.insert(70, &[70]);     // 70 => [70]
            map.insert(88, &[134]);     // 88 => [134]
            map.insert(134, &[262]);     // 134 => [262]
            map.insert(262, &[518]);     // 262 => [518]
            map.insert(518, &[1030]);     // 518 => [1030]
            map.insert(478, &[2054]);     // 478 => [2054]
            map.insert(107, &[4102]);     // 107 => [4102]
            map.insert(488, &[8198]);     // 488 => [8198]
            map.insert(939, &[16390]);     // 939 => [16390]
            map.insert(541, &[32774]);     // 541 => [32774]
            map.insert(758, &[65542]);     // 758 => [65542]
            map.insert(913, &[131078]);     // 913 => [131078]
            map.insert(868, &[262150]);     // 868 => [262150]
            map.insert(370, &[524294]);     // 370 => [524294]
            map.insert(333, &[1048582]);     // 333 => [1048582]
            map.insert(42, &[42]);     // 42 => [42]
            map.insert(84, &[138]);     // 84 => [138]
            map.insert(138, &[266]);     // 138 => [266]
            map.insert(466, &[2058]);     // 466 => [2058]
            map.insert(103, &[4106]);     // 103 => [4106]
            map.insert(484, &[8202]);     // 484 => [8202]
            map.insert(935, &[16394]);     // 935 => [16394]
            map.insert(762, &[65546]);     // 762 => [65546]
            map.insert(925, &[131082]);     // 925 => [131082]
            map.insert(872, &[262154]);     // 872 => [262154]
            map.insert(382, &[524298]);     // 382 => [524298]
            map.insert(82, &[82]);     // 82 => [82]
            map.insert(274, &[530]);     // 274 => [530]
            map.insert(508, &[8210]);     // 508 => [8210]
            map.insert(959, &[16402]);     // 959 => [16402]
            map.insert(880, &[262162]);     // 880 => [262162]
            map.insert(98, &[98]);     // 98 => [98]
            map.insert(162, &[290]);     // 162 => [290]
            map.insert(290, &[546]);     // 290 => [546]
            map.insert(546, &[1058]);     // 546 => [1058]
            map.insert(506, &[2082]);     // 506 => [2082]
            map.insert(460, &[8226]);     // 460 => [8226]
            map.insert(911, &[16418]);     // 911 => [16418]
            map.insert(569, &[32802]);     // 569 => [32802]
            map.insert(722, &[65570]);     // 722 => [65570]
            map.insert(949, &[131106]);     // 949 => [131106]
            map.insert(832, &[262178]);     // 832 => [262178]
            map.insert(342, &[524322]);     // 342 => [524322]
            map.insert(361, &[1048610]);     // 361 => [1048610]
            map.insert(28, &[194]);     // 28 => [194]
            map.insert(194, &[322]);     // 194 => [322]
            map.insert(410, &[2114]);     // 410 => [2114]
            map.insert(47, &[4162]);     // 47 => [4162]
            map.insert(601, &[32834]);     // 601 => [32834]
            map.insert(690, &[65602]);     // 690 => [65602]
            map.insert(981, &[131138]);     // 981 => [131138]
            map.insert(800, &[262210]);     // 800 => [262210]
            map.insert(310, &[524354]);     // 310 => [524354]
            map.insert(220, &[386]);     // 220 => [386]
            map.insert(604, &[1154]);     // 604 => [1154]
            map.insert(388, &[2178]);     // 388 => [2178]
            map.insert(434, &[8322]);     // 434 => [8322]
            map.insert(583, &[32898]);     // 583 => [32898]
            map.insert(971, &[131202]);     // 971 => [131202]
            map.insert(830, &[262274]);     // 830 => [262274]
            map.insert(296, &[524418]);     // 296 => [524418]
            map.insert(279, &[1048706]);     // 279 => [1048706]
            map.insert(642, &[1282]);     // 642 => [1282]
            map.insert(815, &[16642]);     // 815 => [16642]
            map.insert(665, &[33026]);     // 665 => [33026]
            map.insert(626, &[65794]);     // 626 => [65794]
            map.insert(789, &[131330]);     // 789 => [131330]
            map.insert(992, &[262402]);     // 992 => [262402]
            map.insert(502, &[524546]);     // 502 => [524546]
            map.insert(770, &[1538]);     // 770 => [1538]
            map.insert(218, &[2562]);     // 218 => [2562]
            map.insert(793, &[33282]);     // 793 => [33282]
            map.insert(661, &[131586]);     // 661 => [131586]
            map.insert(608, &[262658]);     // 608 => [262658]
            map.insert(118, &[524802]);     // 118 => [524802]
            map.insert(986, &[3074]);     // 986 => [3074]
            map.insert(623, &[5122]);     // 623 => [5122]
            map.insert(242, &[66562]);     // 242 => [66562]
            map.insert(405, &[132098]);     // 405 => [132098]
            map.insert(352, &[263170]);     // 352 => [263170]
            map.insert(886, &[525314]);     // 886 => [525314]
            map.insert(841, &[1049602]);     // 841 => [1049602]
            map.insert(52, &[10242]);     // 52 => [10242]
            map.insert(810, &[67586]);     // 810 => [67586]
            map.insert(589, &[133122]);     // 589 => [133122]
            map.insert(696, &[264194]);     // 696 => [264194]
            map.insert(174, &[526338]);     // 174 => [526338]
            map.insert(671, &[69634]);     // 671 => [69634]
            map.insert(1016, &[135170]);     // 1016 => [135170]
            map.insert(781, &[266242]);     // 781 => [266242]
            map.insert(283, &[528386]);     // 283 => [528386]
            map.insert(292, &[1052674]);     // 292 => [1052674]
            map.insert(1015, &[40962]);     // 1015 => [40962]
            map.insert(796, &[73730]);     // 796 => [73730]
            map.insert(635, &[139266]);     // 635 => [139266]
            map.insert(654, &[270338]);     // 654 => [270338]
            map.insert(152, &[532482]);     // 152 => [532482]
            map.insert(167, &[1056770]);     // 167 => [1056770]
            map.insert(56, &[147458]);     // 56 => [147458]
            map.insert(205, &[278530]);     // 205 => [278530]
            map.insert(731, &[540674]);     // 731 => [540674]
            map.insert(740, &[1064962]);     // 740 => [1064962]
            map.insert(233, &[98306]);     // 233 => [98306]
            map.insert(398, &[163842]);     // 398 => [163842]
            map.insert(379, &[294914]);     // 379 => [294914]
            map.insert(877, &[557058]);     // 877 => [557058]
            map.insert(850, &[1081346]);     // 850 => [1081346]
            map.insert(400, &[327682]);     // 400 => [327682]
            map.insert(953, &[1114114]);     // 953 => [1114114]
            map.insert(247, &[393218]);     // 247 => [393218]
            map.insert(734, &[1179650]);     // 734 => [1179650]
            map.insert(532, &[786434]);     // 532 => [786434]
            map.insert(555, &[1310722]);     // 555 => [1310722]
            map.insert(61, &[1572866]);     // 61 => [1572866]
            map.insert(140, &[268]);     // 140 => [268]
            map.insert(268, &[524]);     // 268 => [524]
            map.insert(524, &[1036]);     // 524 => [1036]
            map.insert(468, &[2060]);     // 468 => [2060]
            map.insert(482, &[8204]);     // 482 => [8204]
            map.insert(929, &[16396]);     // 929 => [16396]
            map.insert(764, &[65548]);     // 764 => [65548]
            map.insert(923, &[131084]);     // 923 => [131084]
            map.insert(327, &[1048588]);     // 327 => [1048588]
            map.insert(148, &[276]);     // 148 => [276]
            map.insert(121, &[4116]);     // 121 => [4116]
            map.insert(527, &[32788]);     // 527 => [32788]
            map.insert(899, &[131092]);     // 899 => [131092]
            map.insert(122, &[164]);     // 122 => [164]
            map.insert(548, &[1060]);     // 548 => [1060]
            map.insert(905, &[16420]);     // 905 => [16420]
            map.insert(575, &[32804]);     // 575 => [32804]
            map.insert(724, &[65572]);     // 724 => [65572]
            map.insert(947, &[131108]);     // 947 => [131108]
            map.insert(838, &[262180]);     // 838 => [262180]
            map.insert(336, &[524324]);     // 336 => [524324]
            map.insert(196, &[324]);     // 196 => [324]
            map.insert(324, &[580]);     // 324 => [580]
            map.insert(412, &[2116]);     // 412 => [2116]
            map.insert(426, &[8260]);     // 426 => [8260]
            map.insert(1001, &[16452]);     // 1001 => [16452]
            map.insert(692, &[65604]);     // 692 => [65604]
            map.insert(979, &[131140]);     // 979 => [131140]
            map.insert(806, &[262212]);     // 806 => [262212]
            map.insert(304, &[524356]);     // 304 => [524356]
            map.insert(271, &[1048644]);     // 271 => [1048644]
            map.insert(682, &[65668]);     // 682 => [65668]
            map.insert(973, &[131204]);     // 973 => [131204]
            map.insert(824, &[262276]);     // 824 => [262276]
            map.insert(302, &[524420]);     // 302 => [524420]
            map.insert(644, &[1284]);     // 644 => [1284]
            map.insert(787, &[131332]);     // 787 => [131332]
            map.insert(998, &[262404]);     // 998 => [262404]
            map.insert(496, &[524548]);     // 496 => [524548]
            map.insert(772, &[1540]);     // 772 => [1540]
            map.insert(681, &[16900]);     // 681 => [16900]
            map.insert(659, &[131588]);     // 659 => [131588]
            map.insert(614, &[262660]);     // 614 => [262660]
            map.insert(112, &[524804]);     // 112 => [524804]
            map.insert(988, &[3076]);     // 988 => [3076]
            map.insert(617, &[5124]);     // 617 => [5124]
            map.insert(1002, &[9220]);     // 1002 => [9220]
            map.insert(425, &[17412]);     // 425 => [17412]
            map.insert(847, &[1049604]);     // 847 => [1049604]
            map.insert(967, &[34820]);     // 967 => [34820]
            map.insert(587, &[133124]);     // 587 => [133124]
            map.insert(702, &[264196]);     // 702 => [264196]
            map.insert(168, &[526340]);     // 168 => [526340]
            map.insert(151, &[1050628]);     // 151 => [1050628]
            map.insert(964, &[20484]);     // 964 => [20484]
            map.insert(1022, &[135172]);     // 1022 => [135172]
            map.insert(779, &[266244]);     // 779 => [266244]
            map.insert(285, &[528388]);     // 285 => [528388]
            map.insert(637, &[139268]);     // 637 => [139268]
            map.insert(648, &[270340]);     // 648 => [270340]
            map.insert(158, &[532484]);     // 158 => [532484]
            map.insert(203, &[278532]);     // 203 => [278532]
            map.insert(392, &[163844]);     // 392 => [163844]
            map.insert(852, &[1081348]);     // 852 => [1081348]
            map.insert(896, &[589828]);     // 896 => [589828]
            map.insert(557, &[1310724]);     // 557 => [1310724]
            map.insert(448, &[2072]);     // 448 => [2072]
            map.insert(744, &[65560]);     // 744 => [65560]
            map.insert(890, &[262168]);     // 890 => [262168]
            map.insert(339, &[1048600]);     // 339 => [1048600]
            map.insert(454, &[8232]);     // 454 => [8232]
            map.insert(563, &[32808]);     // 563 => [32808]
            map.insert(200, &[328]);     // 200 => [328]
            map.insert(584, &[1096]);     // 584 => [1096]
            map.insert(422, &[8264]);     // 422 => [8264]
            map.insert(997, &[16456]);     // 997 => [16456]
            map.insert(595, &[32840]);     // 595 => [32840]
            map.insert(991, &[131144]);     // 991 => [131144]
            map.insert(316, &[524360]);     // 316 => [524360]
            map.insert(214, &[392]);     // 214 => [392]
            map.insert(598, &[1160]);     // 598 => [1160]
            map.insert(440, &[8328]);     // 440 => [8328]
            map.insert(678, &[65672]);     // 678 => [65672]
            map.insert(820, &[262280]);     // 820 => [262280]
            map.insert(229, &[4360]);     // 229 => [4360]
            map.insert(805, &[16648]);     // 805 => [16648]
            map.insert(451, &[1048840]);     // 451 => [1048840]
            map.insert(776, &[1544]);     // 776 => [1544]
            map.insert(208, &[2568]);     // 208 => [2568]
            map.insert(230, &[8712]);     // 230 => [8712]
            map.insert(677, &[16904]);     // 677 => [16904]
            map.insert(618, &[262664]);     // 618 => [262664]
            map.insert(976, &[3080]);     // 976 => [3080]
            map.insert(613, &[5128]);     // 613 => [5128]
            map.insert(421, &[17416]);     // 421 => [17416]
            map.insert(248, &[66568]);     // 248 => [66568]
            map.insert(415, &[132104]);     // 415 => [132104]
            map.insert(892, &[525320]);     // 892 => [525320]
            map.insert(445, &[6152]);     // 445 => [6152]
            map.insert(395, &[12296]);     // 395 => [12296]
            map.insert(638, &[36872]);     // 638 => [36872]
            map.insert(775, &[266248]);     // 775 => [266248]
            map.insert(1021, &[40968]);     // 1021 => [40968]
            map.insert(446, &[49160]);     // 446 => [49160]
            map.insert(199, &[278536]);     // 199 => [278536]
            map.insert(750, &[1064968]);     // 750 => [1064968]
            map.insert(227, &[98312]);     // 227 => [98312]
            map.insert(856, &[1081352]);     // 856 => [1081352]
            map.insert(253, &[393224]);     // 253 => [393224]
            map.insert(747, &[655368]);     // 747 => [655368]
            map.insert(176, &[304]);     // 176 => [304]
            map.insert(560, &[1072]);     // 560 => [1072]
            map.insert(704, &[65584]);     // 704 => [65584]
            map.insert(592, &[1104]);     // 592 => [1104]
            map.insert(672, &[65616]);     // 672 => [65616]
            map.insert(818, &[262224]);     // 818 => [262224]
            map.insert(416, &[8336]);     // 416 => [8336]
            map.insert(597, &[32912]);     // 597 => [32912]
            map.insert(314, &[524432]);     // 314 => [524432]
            map.insert(656, &[1296]);     // 656 => [1296]
            map.insert(651, &[33040]);     // 651 => [33040]
            map.insert(784, &[1552]);     // 784 => [1552]
            map.insert(254, &[8720]);     // 254 => [8720]
            map.insert(701, &[16912]);     // 701 => [16912]
            map.insert(647, &[131600]);     // 647 => [131600]
            map.insert(224, &[66576]);     // 224 => [66576]
            map.insert(859, &[1049616]);     // 859 => [1049616]
            map.insert(188, &[526352]);     // 188 => [526352]
            map.insert(181, &[1056784]);     // 181 => [1056784]
            map.insert(713, &[540688]);     // 713 => [540688]
            map.insert(251, &[98320]);     // 251 => [98320]
            map.insert(895, &[557072]);     // 895 => [557072]
            map.insert(716, &[1179664]);     // 716 => [1179664]
            map.insert(823, &[131360]);     // 823 => [131360]
            map.insert(827, &[33312]);     // 827 => [33312]
            map.insert(695, &[131616]);     // 695 => [131616]
            map.insert(974, &[9248]);     // 974 => [9248]
            map.insert(179, &[1050656]);     // 179 => [1050656]
            map.insert(419, &[12320]);     // 419 => [12320]
            map.insert(313, &[528416]);     // 313 => [528416]
            map.insert(186, &[532512]);     // 186 => [532512]
            map.insert(710, &[1064992]);     // 710 => [1064992]
            map.insert(213, &[393248]);     // 213 => [393248]
            map.insert(707, &[655392]);     // 707 => [655392]
            map.insert(566, &[786464]);     // 566 => [786464]
            map.insert(286, &[704]);     // 286 => [704]
            map.insert(115, &[4288]);     // 115 => [4288]
            map.insert(855, &[131392]);     // 855 => [131392]
            map.insert(930, &[262464]);     // 930 => [262464]
            map.insert(301, &[4672]);     // 301 => [4672]
            map.insert(749, &[16960]);     // 749 => [16960]
            map.insert(944, &[66112]);     // 944 => [66112]
            map.insert(727, &[131648]);     // 727 => [131648]
            map.insert(920, &[3136]);     // 920 => [3136]
            map.insert(471, &[132160]);     // 471 => [132160]
            map.insert(565, &[18496]);     // 565 => [18496]
            map.insert(211, &[1050688]);     // 211 => [1050688]
            map.insert(862, &[73792]);     // 862 => [73792]
            map.insert(143, &[278592]);     // 143 => [278592]
            map.insert(171, &[98368]);     // 171 => [98368]
            map.insert(675, &[655424]);     // 675 => [655424]
            map.insert(709, &[33152]);     // 709 => [33152]
            map.insert(558, &[65920]);     // 558 => [65920]
            map.insert(307, &[4736]);     // 307 => [4736]
            map.insert(837, &[33408]);     // 837 => [33408]
            map.insert(572, &[262784]);     // 572 => [262784]
            map.insert(499, &[17536]);     // 499 => [17536]
            map.insert(551, &[139392]);     // 551 => [139392]
            map.insert(817, &[557184]);     // 817 => [557184]
            map.insert(182, &[10496]);     // 182 => [10496]
            map.insert(719, &[133376]);     // 719 => [133376]
            map.insert(191, &[1573120]);     // 191 => [1573120]
            map.insert(889, &[139776]);     // 889 => [139776]
            map.insert(319, &[1573376]);     // 319 => [1573376]
            map.insert(157, &[70656]);     // 157 => [70656]
            map.insert(861, &[82944]);     // 861 => [82944]
            map.insert(443, &[1115136]);     // 443 => [1115136]
            map.insert(481, &[167936]);     // 481 => [167936]
            map.insert(714, &[212992]);     // 714 => [212992]
            map.insert(15, &[15]);     // 15 => [15]
            map.insert(23, &[23]);     // 23 => [23]
            map.insert(39, &[39]);     // 39 => [39]
            map.insert(71, &[71]);     // 71 => [71]
            map.insert(89, &[135]);     // 89 => [135]
            map.insert(135, &[263]);     // 135 => [263]
            map.insert(263, &[519]);     // 263 => [519]
            map.insert(519, &[1031]);     // 519 => [1031]
            map.insert(479, &[2055]);     // 479 => [2055]
            map.insert(106, &[4103]);     // 106 => [4103]
            map.insert(489, &[8199]);     // 489 => [8199]
            map.insert(938, &[16391]);     // 938 => [16391]
            map.insert(540, &[32775]);     // 540 => [32775]
            map.insert(759, &[65543]);     // 759 => [65543]
            map.insert(912, &[131079]);     // 912 => [131079]
            map.insert(869, &[262151]);     // 869 => [262151]
            map.insert(371, &[524295]);     // 371 => [524295]
            map.insert(332, &[1048583]);     // 332 => [1048583]
            map.insert(43, &[43]);     // 43 => [43]
            map.insert(85, &[139]);     // 85 => [139]
            map.insert(139, &[267]);     // 139 => [267]
            map.insert(467, &[2059]);     // 467 => [2059]
            map.insert(102, &[4107]);     // 102 => [4107]
            map.insert(485, &[8203]);     // 485 => [8203]
            map.insert(934, &[16395]);     // 934 => [16395]
            map.insert(763, &[65547]);     // 763 => [65547]
            map.insert(924, &[131083]);     // 924 => [131083]
            map.insert(873, &[262155]);     // 873 => [262155]
            map.insert(383, &[524299]);     // 383 => [524299]
            map.insert(83, &[83]);     // 83 => [83]
            map.insert(275, &[531]);     // 275 => [531]
            map.insert(509, &[8211]);     // 509 => [8211]
            map.insert(958, &[16403]);     // 958 => [16403]
            map.insert(881, &[262163]);     // 881 => [262163]
            map.insert(99, &[99]);     // 99 => [99]
            map.insert(163, &[291]);     // 163 => [291]
            map.insert(291, &[547]);     // 291 => [547]
            map.insert(547, &[1059]);     // 547 => [1059]
            map.insert(507, &[2083]);     // 507 => [2083]
            map.insert(461, &[8227]);     // 461 => [8227]
            map.insert(910, &[16419]);     // 910 => [16419]
            map.insert(568, &[32803]);     // 568 => [32803]
            map.insert(723, &[65571]);     // 723 => [65571]
            map.insert(948, &[131107]);     // 948 => [131107]
            map.insert(833, &[262179]);     // 833 => [262179]
            map.insert(343, &[524323]);     // 343 => [524323]
            map.insert(360, &[1048611]);     // 360 => [1048611]
            map.insert(29, &[195]);     // 29 => [195]
            map.insert(195, &[323]);     // 195 => [323]
            map.insert(411, &[2115]);     // 411 => [2115]
            map.insert(46, &[4163]);     // 46 => [4163]
            map.insert(600, &[32835]);     // 600 => [32835]
            map.insert(691, &[65603]);     // 691 => [65603]
            map.insert(980, &[131139]);     // 980 => [131139]
            map.insert(801, &[262211]);     // 801 => [262211]
            map.insert(311, &[524355]);     // 311 => [524355]
            map.insert(221, &[387]);     // 221 => [387]
            map.insert(605, &[1155]);     // 605 => [1155]
            map.insert(389, &[2179]);     // 389 => [2179]
            map.insert(435, &[8323]);     // 435 => [8323]
            map.insert(582, &[32899]);     // 582 => [32899]
            map.insert(970, &[131203]);     // 970 => [131203]
            map.insert(831, &[262275]);     // 831 => [262275]
            map.insert(297, &[524419]);     // 297 => [524419]
            map.insert(278, &[1048707]);     // 278 => [1048707]
            map.insert(643, &[1283]);     // 643 => [1283]
            map.insert(814, &[16643]);     // 814 => [16643]
            map.insert(664, &[33027]);     // 664 => [33027]
            map.insert(627, &[65795]);     // 627 => [65795]
            map.insert(788, &[131331]);     // 788 => [131331]
            map.insert(993, &[262403]);     // 993 => [262403]
            map.insert(503, &[524547]);     // 503 => [524547]
            map.insert(771, &[1539]);     // 771 => [1539]
            map.insert(219, &[2563]);     // 219 => [2563]
            map.insert(792, &[33283]);     // 792 => [33283]
            map.insert(660, &[131587]);     // 660 => [131587]
            map.insert(609, &[262659]);     // 609 => [262659]
            map.insert(119, &[524803]);     // 119 => [524803]
            map.insert(987, &[3075]);     // 987 => [3075]
            map.insert(622, &[5123]);     // 622 => [5123]
            map.insert(243, &[66563]);     // 243 => [66563]
            map.insert(404, &[132099]);     // 404 => [132099]
            map.insert(353, &[263171]);     // 353 => [263171]
            map.insert(887, &[525315]);     // 887 => [525315]
            map.insert(840, &[1049603]);     // 840 => [1049603]
            map.insert(53, &[10243]);     // 53 => [10243]
            map.insert(811, &[67587]);     // 811 => [67587]
            map.insert(588, &[133123]);     // 588 => [133123]
            map.insert(697, &[264195]);     // 697 => [264195]
            map.insert(175, &[526339]);     // 175 => [526339]
            map.insert(670, &[69635]);     // 670 => [69635]
            map.insert(1017, &[135171]);     // 1017 => [135171]
            map.insert(780, &[266243]);     // 780 => [266243]
            map.insert(282, &[528387]);     // 282 => [528387]
            map.insert(293, &[1052675]);     // 293 => [1052675]
            map.insert(1014, &[40963]);     // 1014 => [40963]
            map.insert(797, &[73731]);     // 797 => [73731]
            map.insert(634, &[139267]);     // 634 => [139267]
            map.insert(655, &[270339]);     // 655 => [270339]
            map.insert(153, &[532483]);     // 153 => [532483]
            map.insert(166, &[1056771]);     // 166 => [1056771]
            map.insert(57, &[147459]);     // 57 => [147459]
            map.insert(204, &[278531]);     // 204 => [278531]
            map.insert(730, &[540675]);     // 730 => [540675]
            map.insert(741, &[1064963]);     // 741 => [1064963]
            map.insert(232, &[98307]);     // 232 => [98307]
            map.insert(399, &[163843]);     // 399 => [163843]
            map.insert(378, &[294915]);     // 378 => [294915]
            map.insert(876, &[557059]);     // 876 => [557059]
            map.insert(851, &[1081347]);     // 851 => [1081347]
            map.insert(401, &[327683]);     // 401 => [327683]
            map.insert(952, &[1114115]);     // 952 => [1114115]
            map.insert(246, &[393219]);     // 246 => [393219]
            map.insert(735, &[1179651]);     // 735 => [1179651]
            map.insert(533, &[786435]);     // 533 => [786435]
            map.insert(554, &[1310723]);     // 554 => [1310723]
            map.insert(60, &[1572867]);     // 60 => [1572867]
            map.insert(141, &[269]);     // 141 => [269]
            map.insert(269, &[525]);     // 269 => [525]
            map.insert(525, &[1037]);     // 525 => [1037]
            map.insert(469, &[2061]);     // 469 => [2061]
            map.insert(483, &[8205]);     // 483 => [8205]
            map.insert(928, &[16397]);     // 928 => [16397]
            map.insert(765, &[65549]);     // 765 => [65549]
            map.insert(922, &[131085]);     // 922 => [131085]
            map.insert(326, &[1048589]);     // 326 => [1048589]
            map.insert(149, &[277]);     // 149 => [277]
            map.insert(120, &[4117]);     // 120 => [4117]
            map.insert(526, &[32789]);     // 526 => [32789]
            map.insert(898, &[131093]);     // 898 => [131093]
            map.insert(123, &[165]);     // 123 => [165]
            map.insert(549, &[1061]);     // 549 => [1061]
            map.insert(904, &[16421]);     // 904 => [16421]
            map.insert(574, &[32805]);     // 574 => [32805]
            map.insert(725, &[65573]);     // 725 => [65573]
            map.insert(946, &[131109]);     // 946 => [131109]
            map.insert(839, &[262181]);     // 839 => [262181]
            map.insert(337, &[524325]);     // 337 => [524325]
            map.insert(197, &[325]);     // 197 => [325]
            map.insert(325, &[581]);     // 325 => [581]
            map.insert(413, &[2117]);     // 413 => [2117]
            map.insert(427, &[8261]);     // 427 => [8261]
            map.insert(1000, &[16453]);     // 1000 => [16453]
            map.insert(693, &[65605]);     // 693 => [65605]
            map.insert(978, &[131141]);     // 978 => [131141]
            map.insert(807, &[262213]);     // 807 => [262213]
            map.insert(305, &[524357]);     // 305 => [524357]
            map.insert(270, &[1048645]);     // 270 => [1048645]
            map.insert(683, &[65669]);     // 683 => [65669]
            map.insert(972, &[131205]);     // 972 => [131205]
            map.insert(825, &[262277]);     // 825 => [262277]
            map.insert(303, &[524421]);     // 303 => [524421]
            map.insert(645, &[1285]);     // 645 => [1285]
            map.insert(786, &[131333]);     // 786 => [131333]
            map.insert(999, &[262405]);     // 999 => [262405]
            map.insert(497, &[524549]);     // 497 => [524549]
            map.insert(773, &[1541]);     // 773 => [1541]
            map.insert(680, &[16901]);     // 680 => [16901]
            map.insert(658, &[131589]);     // 658 => [131589]
            map.insert(615, &[262661]);     // 615 => [262661]
            map.insert(113, &[524805]);     // 113 => [524805]
            map.insert(989, &[3077]);     // 989 => [3077]
            map.insert(616, &[5125]);     // 616 => [5125]
            map.insert(1003, &[9221]);     // 1003 => [9221]
            map.insert(424, &[17413]);     // 424 => [17413]
            map.insert(846, &[1049605]);     // 846 => [1049605]
            map.insert(966, &[34821]);     // 966 => [34821]
            map.insert(586, &[133125]);     // 586 => [133125]
            map.insert(703, &[264197]);     // 703 => [264197]
            map.insert(169, &[526341]);     // 169 => [526341]
            map.insert(150, &[1050629]);     // 150 => [1050629]
            map.insert(965, &[20485]);     // 965 => [20485]
            map.insert(1023, &[135173]);     // 1023 => [135173]
            map.insert(778, &[266245]);     // 778 => [266245]
            map.insert(284, &[528389]);     // 284 => [528389]
            map.insert(636, &[139269]);     // 636 => [139269]
            map.insert(649, &[270341]);     // 649 => [270341]
            map.insert(159, &[532485]);     // 159 => [532485]
            map.insert(202, &[278533]);     // 202 => [278533]
            map.insert(393, &[163845]);     // 393 => [163845]
            map.insert(853, &[1081349]);     // 853 => [1081349]
            map.insert(897, &[589829]);     // 897 => [589829]
            map.insert(556, &[1310725]);     // 556 => [1310725]
            map.insert(449, &[2073]);     // 449 => [2073]
            map.insert(745, &[65561]);     // 745 => [65561]
            map.insert(891, &[262169]);     // 891 => [262169]
            map.insert(338, &[1048601]);     // 338 => [1048601]
            map.insert(455, &[8233]);     // 455 => [8233]
            map.insert(562, &[32809]);     // 562 => [32809]
            map.insert(201, &[329]);     // 201 => [329]
            map.insert(585, &[1097]);     // 585 => [1097]
            map.insert(423, &[8265]);     // 423 => [8265]
            map.insert(996, &[16457]);     // 996 => [16457]
            map.insert(594, &[32841]);     // 594 => [32841]
            map.insert(990, &[131145]);     // 990 => [131145]
            map.insert(317, &[524361]);     // 317 => [524361]
            map.insert(215, &[393]);     // 215 => [393]
            map.insert(599, &[1161]);     // 599 => [1161]
            map.insert(441, &[8329]);     // 441 => [8329]
            map.insert(679, &[65673]);     // 679 => [65673]
            map.insert(821, &[262281]);     // 821 => [262281]
            map.insert(228, &[4361]);     // 228 => [4361]
            map.insert(804, &[16649]);     // 804 => [16649]
            map.insert(450, &[1048841]);     // 450 => [1048841]
            map.insert(777, &[1545]);     // 777 => [1545]
            map.insert(209, &[2569]);     // 209 => [2569]
            map.insert(231, &[8713]);     // 231 => [8713]
            map.insert(676, &[16905]);     // 676 => [16905]
            map.insert(619, &[262665]);     // 619 => [262665]
            map.insert(977, &[3081]);     // 977 => [3081]
            map.insert(612, &[5129]);     // 612 => [5129]
            map.insert(420, &[17417]);     // 420 => [17417]
            map.insert(249, &[66569]);     // 249 => [66569]
            map.insert(414, &[132105]);     // 414 => [132105]
            map.insert(893, &[525321]);     // 893 => [525321]
            map.insert(444, &[6153]);     // 444 => [6153]
            map.insert(394, &[12297]);     // 394 => [12297]
            map.insert(639, &[36873]);     // 639 => [36873]
            map.insert(774, &[266249]);     // 774 => [266249]
            map.insert(1020, &[40969]);     // 1020 => [40969]
            map.insert(447, &[49161]);     // 447 => [49161]
            map.insert(198, &[278537]);     // 198 => [278537]
            map.insert(751, &[1064969]);     // 751 => [1064969]
            map.insert(226, &[98313]);     // 226 => [98313]
            map.insert(857, &[1081353]);     // 857 => [1081353]
            map.insert(252, &[393225]);     // 252 => [393225]
            map.insert(746, &[655369]);     // 746 => [655369]
            map.insert(177, &[305]);     // 177 => [305]
            map.insert(561, &[1073]);     // 561 => [1073]
            map.insert(705, &[65585]);     // 705 => [65585]
            map.insert(593, &[1105]);     // 593 => [1105]
            map.insert(673, &[65617]);     // 673 => [65617]
            map.insert(819, &[262225]);     // 819 => [262225]
            map.insert(417, &[8337]);     // 417 => [8337]
            map.insert(596, &[32913]);     // 596 => [32913]
            map.insert(315, &[524433]);     // 315 => [524433]
            map.insert(657, &[1297]);     // 657 => [1297]
            map.insert(650, &[33041]);     // 650 => [33041]
            map.insert(785, &[1553]);     // 785 => [1553]
            map.insert(255, &[8721]);     // 255 => [8721]
            map.insert(700, &[16913]);     // 700 => [16913]
            map.insert(646, &[131601]);     // 646 => [131601]
            map.insert(225, &[66577]);     // 225 => [66577]
            map.insert(858, &[1049617]);     // 858 => [1049617]
            map.insert(189, &[526353]);     // 189 => [526353]
            map.insert(180, &[1056785]);     // 180 => [1056785]
            map.insert(712, &[540689]);     // 712 => [540689]
            map.insert(250, &[98321]);     // 250 => [98321]
            map.insert(894, &[557073]);     // 894 => [557073]
            map.insert(717, &[1179665]);     // 717 => [1179665]
            map.insert(822, &[131361]);     // 822 => [131361]
            map.insert(826, &[33313]);     // 826 => [33313]
            map.insert(694, &[131617]);     // 694 => [131617]
            map.insert(975, &[9249]);     // 975 => [9249]
            map.insert(178, &[1050657]);     // 178 => [1050657]
            map.insert(418, &[12321]);     // 418 => [12321]
            map.insert(312, &[528417]);     // 312 => [528417]
            map.insert(187, &[532513]);     // 187 => [532513]
            map.insert(711, &[1064993]);     // 711 => [1064993]
            map.insert(212, &[393249]);     // 212 => [393249]
            map.insert(706, &[655393]);     // 706 => [655393]
            map.insert(567, &[786465]);     // 567 => [786465]
            map.insert(287, &[705]);     // 287 => [705]
            map.insert(114, &[4289]);     // 114 => [4289]
            map.insert(854, &[131393]);     // 854 => [131393]
            map.insert(931, &[262465]);     // 931 => [262465]
            map.insert(300, &[4673]);     // 300 => [4673]
            map.insert(748, &[16961]);     // 748 => [16961]
            map.insert(945, &[66113]);     // 945 => [66113]
            map.insert(726, &[131649]);     // 726 => [131649]
            map.insert(921, &[3137]);     // 921 => [3137]
            map.insert(470, &[132161]);     // 470 => [132161]
            map.insert(564, &[18497]);     // 564 => [18497]
            map.insert(210, &[1050689]);     // 210 => [1050689]
            map.insert(863, &[73793]);     // 863 => [73793]
            map.insert(142, &[278593]);     // 142 => [278593]
            map.insert(170, &[98369]);     // 170 => [98369]
            map.insert(674, &[655425]);     // 674 => [655425]
            map.insert(708, &[33153]);     // 708 => [33153]
            map.insert(559, &[65921]);     // 559 => [65921]
            map.insert(306, &[4737]);     // 306 => [4737]
            map.insert(836, &[33409]);     // 836 => [33409]
            map.insert(573, &[262785]);     // 573 => [262785]
            map.insert(498, &[17537]);     // 498 => [17537]
            map.insert(550, &[139393]);     // 550 => [139393]
            map.insert(816, &[557185]);     // 816 => [557185]
            map.insert(183, &[10497]);     // 183 => [10497]
            map.insert(718, &[133377]);     // 718 => [133377]
            map.insert(190, &[1573121]);     // 190 => [1573121]
            map.insert(888, &[139777]);     // 888 => [139777]
            map.insert(318, &[1573377]);     // 318 => [1573377]
            map.insert(156, &[70657]);     // 156 => [70657]
            map.insert(860, &[82945]);     // 860 => [82945]
            map.insert(442, &[1115137]);     // 442 => [1115137]
            map.insert(480, &[167937]);     // 480 => [167937]
            map.insert(715, &[212993]);     // 715 => [212993]
            map.insert(766, &[65550]);     // 766 => [65550]
            map.insert(907, &[16422]);     // 907 => [16422]
            map.insert(845, &[1049606]);     // 845 => [1049606]
            map.insert(452, &[8234]);     // 452 => [8234]
            map.insert(184, &[532514]);     // 184 => [532514]
            map.insert(767, &[65551]);     // 767 => [65551]
            map.insert(906, &[16423]);     // 906 => [16423]
            map.insert(844, &[1049607]);     // 844 => [1049607]
            map.insert(453, &[8235]);     // 453 => [8235]
            map.insert(185, &[532515]);     // 185 => [532515]
            
            SYNDROME_MAP = Box::into_raw(map);
        }
    });
}

impl GuavaCode21_11 {
    fn parity_check_matrix_transposed(&self) -> &BinMatrix {
        init();
        unsafe {
            PARITY_MATRIX_T.as_ref().unwrap()
        }
    }
}

impl BinaryCode for GuavaCode21_11 {
    fn name(&self) -> String {
        "[21, 11] Guava code".to_owned()
    }

    fn length(&self) -> usize {
        21
    }

    fn dimension(&self) -> usize {
        11
    }

    fn generator_matrix(&self) -> &BinMatrix {
        init();
        unsafe {
            GENERATOR_MATRIX.as_ref().unwrap()
        }
    }

    fn parity_check_matrix(&self) -> &BinMatrix {
        init();
        unsafe {
            PARITY_MATRIX.as_ref().unwrap()
        }
    }

    fn decode_to_code(&self, c: &BinVector) -> Result<BinVector, &str> {
        init();
        let map = unsafe {
            SYNDROME_MAP.as_ref().unwrap()
        };
        debug_assert_eq!(c.len(), self.length(), "the length doesn't match the expected length (length of the code)");
        let he = c * self.parity_check_matrix_transposed();
        let mut error = BinVector::with_capacity(21);
        let stor = unsafe { error.get_storage_mut() };
        let errbytes = map[&he.as_u64()];
        debug_assert_eq!(errbytes.len(), 21 / 64 + if 21 % 64 != 0 { 1 } else { 0 });
        stor.clear();
        stor.extend_from_slice(&errbytes[..]);
        unsafe { error.set_len(21) };
        debug_assert_eq!(error.len(), self.length(), "internal: the error vector is of the wrong length");
        let result = c + &error;
        debug_assert_eq!(result.len(), self.length(), "internal: the result vector is of the wrong length");
        debug_assert_eq!((&result * self.parity_check_matrix_transposed()).count_ones(), 0);
        Ok(result)
    }

    fn decode_to_message(&self, c: &BinVector) -> Result<BinVector, &str> {
        
        let mut codeword = self.decode_to_code(c)?;
        codeword.truncate(11);
        Ok(codeword)
        
    }

    fn decode_slice(&self, c: &mut [u64]) {
        init();
        
        debug_assert_eq!(c[21 / 64] & !((1 << 21) - 1), 0, "this message has excess bits");

        let map = unsafe {
            SYNDROME_MAP.as_ref().unwrap()
        };
        let he = &BinMatrix::from_slices(&[&c[..]], self.length()) * self.parity_check_matrix_transposed();
        let error = map[unsafe { &he.get_word_unchecked(0, 0) }];
        c.iter_mut().zip(error.iter().copied()).for_each(|(sample, error)| *sample ^= error as u64);
    }

    
}

#[cfg(test)]
mod tests {
    use super::*;
    use m4ri_rust::friendly::BinVector;
    use crate::oracle::Sample;

    #[test]
    fn size() {
        let code = GuavaCode21_11.generator_matrix();
        assert_eq!(code.ncols(), 21);
        assert_eq!(code.nrows(), 11);
    }

    #[test]
    fn test_decode_sample() {
        let code = GuavaCode21_11;
        for _ in 0..1000 {
            // setup
            let vec = BinVector::random(code.length());
            let mut sample_a = Sample::from_binvector(&vec, false);
            let mut sample_b = Sample::from_binvector(&vec, true);
            
            let decoded_vec = code.decode_to_message(&vec).unwrap();
            println!("decoded_vec: {:?}", decoded_vec);

            // test vectors
            let decoded_vec_sample_a = Sample::from_binvector(&decoded_vec, false);
            let decoded_vec_sample_b = Sample::from_binvector(&decoded_vec, true);

            code.decode_sample(&mut sample_a);
            code.decode_sample(&mut sample_b);
            assert_eq!(sample_a.get_product(), false);
            assert_eq!(sample_b.get_product(), true);
            assert_eq!(sample_a, decoded_vec_sample_a);
            assert_eq!(sample_b, decoded_vec_sample_b);
        }
    }

    #[test]
    fn random_decode_tests() {

        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[false, false, false, true, false, true, true, true, false, false, false, true, true, true, false, false, false, false, true, false, true]);
            let codeword = BinVector::from_bools(&[true, false, false, true, false, true, true, false, false, false, false, true, true, true, false, true, false, false, true, false, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[false, true, false, true, true, false, false, false, true, false, true, false, false, true, true, false, true, false, false, false, true]);
            let codeword = BinVector::from_bools(&[false, true, false, true, true, false, false, false, true, false, true, false, false, true, true, false, true, false, true, false, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[false, false, false, false, true, true, true, false, false, true, true, true, true, true, false, true, false, true, true, true, true]);
            let codeword = BinVector::from_bools(&[false, true, false, false, true, false, true, false, false, true, true, false, true, true, false, true, false, true, true, true, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[false, false, true, false, false, false, false, false, false, false, true, false, false, true, false, false, true, true, true, false, false]);
            let codeword = BinVector::from_bools(&[true, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, true, true, true, false, false]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[false, false, true, false, true, true, true, true, false, false, false, false, false, true, true, true, true, true, true, false, false]);
            let codeword = BinVector::from_bools(&[true, false, true, false, true, true, true, true, false, false, false, false, true, true, true, false, true, true, true, false, false]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[false, true, true, true, false, true, true, true, false, true, true, true, false, false, false, true, true, true, true, false, true]);
            let codeword = BinVector::from_bools(&[false, true, true, true, true, true, true, true, false, true, true, true, false, false, true, true, true, true, true, false, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, false, false, true, false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, false, true]);
            let codeword = BinVector::from_bools(&[true, false, false, true, true, false, false, true, false, false, true, true, false, false, true, true, false, false, true, false, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, false, true, true, false, false, true, true, true, true, false, true, true, false, false, true, false, false, true, false, true]);
            let codeword = BinVector::from_bools(&[true, false, false, true, true, false, true, true, true, true, false, true, true, false, false, true, false, false, true, false, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, false, false, false, true, true, true, false, false, true, true, true, false, false, false, false, false, true, true, false, true]);
            let codeword = BinVector::from_bools(&[true, false, false, false, true, true, true, false, true, true, true, true, false, false, false, false, false, false, true, false, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, false, false, false, true, true, true, false, true, false, true, false, false, true, true, false, false, false, false, true, false]);
            let codeword = BinVector::from_bools(&[true, false, false, true, true, false, true, false, true, false, true, false, false, false, true, false, false, false, false, true, false]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, false, true, true, false, false, true, true, true, false, true, false, true, true, true, true, false, false, true, false, true]);
            let codeword = BinVector::from_bools(&[true, false, true, true, false, false, false, true, true, false, true, false, true, true, false, true, false, false, false, false, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, false, true, true, true, true, true, false, false, false, false, false, false, false, false, false, true, false, true, false, true]);
            let codeword = BinVector::from_bools(&[false, false, true, true, true, true, true, false, false, false, false, false, false, true, false, false, true, false, true, false, false]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, true, true, false, true, true, true, false, false, false, false, false, true, true, false, true, false, false, true, false, false]);
            let codeword = BinVector::from_bools(&[false, true, false, true, true, true, true, false, true, false, false, false, true, true, false, true, false, false, true, false, false]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, true, true, true, false, true, false, true, true, true, false, false, true, true, true, true, true, true, false, true, true]);
            let codeword = BinVector::from_bools(&[false, true, true, true, false, true, false, true, true, true, true, false, false, true, true, true, false, true, false, true, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, false, true, true, false, true, true, true, false, false, true, false, false, true, true, true, true, true, false, true, true]);
            let codeword = BinVector::from_bools(&[false, false, true, true, true, true, false, true, false, false, true, false, false, true, true, true, true, true, true, true, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, true, false, false, false, false, true, true, false, false, true, true, true, true, true, true, true, false, false, true, false]);
            let codeword = BinVector::from_bools(&[true, true, false, false, false, false, true, true, false, true, true, true, true, true, true, true, true, false, false, false, false]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[true, false, false, false, false, false, true, true, false, false, true, false, true, false, true, true, false, true, false, true, true]);
            let codeword = BinVector::from_bools(&[false, false, false, false, false, false, true, true, false, false, true, false, false, false, true, true, false, true, false, true, true]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[false, true, false, true, false, true, false, false, false, false, false, false, true, true, true, false, false, true, true, false, false]);
            let codeword = BinVector::from_bools(&[true, true, false, true, false, true, false, false, false, false, false, false, true, true, true, false, true, true, true, false, false]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[false, true, false, true, false, true, false, false, false, true, false, true, true, false, true, false, true, true, false, false, false]);
            let codeword = BinVector::from_bools(&[false, true, false, true, true, true, false, true, false, true, false, true, true, false, true, true, true, true, false, false, false]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
        {
            let code = GuavaCode21_11;
            let randvec = BinVector::from_bools(&[false, false, false, false, false, true, false, true, false, true, true, true, true, false, true, true, true, true, true, true, true]);
            let codeword = BinVector::from_bools(&[false, false, true, true, false, true, false, true, false, true, true, true, true, false, true, true, true, true, true, true, false]);
            assert_eq!(code.decode_to_code(&randvec), Ok(codeword));
        }
        
    }

    #[test]
    fn test_generator_representation() {
        init();
        let generator_matrix = unsafe { GENERATOR_MATRIX.as_ref().unwrap() };
        let first_row = generator_matrix.get_window(0, 0, 1, generator_matrix.ncols());
        let vector = BinVector::from_bools(&[ true, false, false, false, false, false, false, false, false, false, false, true, false, true, true, true, false, true, true, true, false ]);
        assert_eq!(vector, first_row.as_vector());
    }

}