File: SeedPattern.cpp

package info (click to toggle)
perm 0.4.0-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 976 kB
  • sloc: cpp: 13,499; makefile: 98; sh: 12
file content (1345 lines) | stat: -rw-r--r-- 44,809 bytes parent folder | download | duplicates (5)
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
#include "stdafx.h"
#include "SeedPattern.h"

// This function return the hash value of first 13 bits
inline unsigned int getF0SeedHashValue(WORD_SIZE encodedRead)
{
    const WORD_SIZE HASH_MASK = 0x1fff;
    return ((unsigned int)(encodedRead & HASH_MASK)); // Get the first 13 digit
}

unsigned int getF0SeedHashValue(CReadInBits r)
{
    WORD_SIZE hashValue = getF0SeedHashValue(r.UpperBits);
    hashValue <<= BITS_FOR_HASHING;
    hashValue += getF0SeedHashValue(r.LowerBits);
    return ((unsigned int)hashValue);
}

ptHashFunc selectF0(int readlength)
{
    if (BITS_FOR_HASHING <= (unsigned int) readlength ) {
        if (readlength <= 32) {
            return &getF0SeedHashValue;
        } else if (readlength <= 48) {
            LOG_INFO("\nInfo %d: Use S1 seed instead %d\n", WARNING_LOG, readlength);
            return &getF1SeedHashValue;
        } else if (readlength <= 64) {
            LOG_INFO("\nInfo %d: Use S2 seed instead %d\n", WARNING_LOG, readlength);
            return &getF2SeedHashValue;
        }
    } else {
        // TODO deal with reads shorter than 13.
        ;
    }
    LOG_INFO("\nInfo %d: No hash function defined for read with length %d\n", WARNING_LOG, readlength);
    return (NULL);
}

// private function called by its overloaded getF1SeedHashKey(WORD_SIZE encoedRead, WORD_SIZE encoedRead);
inline unsigned int getF0SeedKey(WORD_SIZE encoedRead, int keyWeight)
{
    // Use the suffixLength bits based on the seed pattern 11*1**(111*1**)(111*1**)1 to create a value
    if (keyWeight > 0 ) {
        WORD_SIZE HASH_MASK = ((0x01 << keyWeight) - 1);
        WORD_SIZE uiKey =  encoedRead & HASH_MASK;
        return ((unsigned int)uiKey);
    } else {
        return(0);
    }
}

unsigned int getF0SeedKey(CReadInBits r, int keyWeight)
{
    r.UpperBits >>= BITS_FOR_HASHING;
    r.LowerBits >>= BITS_FOR_HASHING;
    unsigned int uiKey1 = getF0SeedKey(r.UpperBits, keyWeight);
    unsigned int uiKey2 = getF0SeedKey(r.LowerBits, keyWeight);
#ifdef EXTEND_SEED
    unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);
#else
    unsigned int uiKey = (uiKey1 << keyWeight) + uiKey2;
#endif
    return (uiKey);
}

////////////////////////////////////////////////////////////////////////////////
inline unsigned int getF1SeedHashValue15(WORD_SIZE encodedRead)
{
    WORD_SIZE hashValue = 0;

    hashValue += (encodedRead & 0x07); // Get the first 3 digit
    hashValue <<= 3;
    encodedRead >>= 4;

    hashValue += (encodedRead & 0x07); // Get the first 4-6 digit
    hashValue <<= 3;
    encodedRead >>= 4;

    hashValue += (encodedRead & 0x07); // Get the first 7-9 digit
    hashValue <<= 3;
    encodedRead >>= 4;
    return (unsigned int) hashValue;
}

// This function is based on the seed pattern (111*).
inline unsigned int getF1SeedHashValue(WORD_SIZE encodedRead)
{
    // To save the number of CPU instructions, the value encoded bits that doesn't follow the order of reads
    // It still gets the first  digit and the fifth digit.. and so on to get total 13 digits
    WORD_SIZE hashValue = 0;

    hashValue += (encodedRead & 0x07); // Get the first 3 digit
    hashValue <<= 3;
    encodedRead >>= 4;

    hashValue += (encodedRead & 0x07); // Get the first 4-6 digit
    hashValue <<= 3;
    encodedRead >>= 4;

    hashValue += (encodedRead & 0x07); // Get the first 7-9 digit
    hashValue <<= 3;
    encodedRead >>= 4;

    hashValue += (encodedRead & 0x07); // Get the first 11-12 digit
    hashValue <<= 1;
    encodedRead >>= 4;

    hashValue += (encodedRead & 0x01); // Get the 13th position
    return (unsigned int) hashValue;
}

unsigned int getF1SeedHashValue15(CReadInBits r)
{
    WORD_SIZE hashValue = getF1SeedHashValue15(r.UpperBits);
    hashValue <<= BITS_FOR_HASHING;
    hashValue += getF1SeedHashValue15(r.LowerBits);
    return ((unsigned int)hashValue);
}

unsigned int getF1SeedHashValue(CReadInBits r)
{
    WORD_SIZE hashValue = getF1SeedHashValue(r.UpperBits);
    hashValue <<= BITS_FOR_HASHING;
    hashValue += getF1SeedHashValue(r.LowerBits);
    return ((unsigned int)hashValue);
}

ptHashFunc selectF1(int readlength)
{
    if (15 <= readlength && readlength < 20) {
        return &getF1SeedHashValue15;
    } else if (20 <= readlength && readlength <= 60) {
        return &getF1SeedHashValue;
    } else {
        LOG_INFO("\nInfo %d: No hash function defined for read with length %d\n", WARNING_LOG, readlength);
        return (NULL);
    }
}

// private function callse by its overloaded getF1SeedHashKey(WORD_SIZE encoedRead, WORD_SIZE encoedRead);
inline unsigned int getF1SeedKey(WORD_SIZE encoedRead, int keyWeight)
{
    //index 234567 8901234  5678901 2
    // Use the suffixLength bits based on the seed pattern 11*1**(111*1**)(111*1**)1 to create a value
    if (keyWeight > 0 ) {
        WORD_SIZE uiKey =  encoedRead & 0x03; // Get the 14 and 15 digit
        encoedRead >>= 3;
        for (keyWeight -= 2; keyWeight > 0; keyWeight -= 3) {
            uiKey += encoedRead & 0x07;
            uiKey <<= 3;
            encoedRead >>= 4;
        }
        uiKey >>= (-1 * keyWeight);
        return ((unsigned int)uiKey);
    } else {
        return(0);
    }
}

unsigned int getF1SeedKey(CReadInBits r, int keyWeight)
{
    r.UpperBits >>= 20; // The first 20 base are used as hash key (111*)(111*)(111*)(111*)1
    r.LowerBits >>= 20;
    unsigned int uiKey1 = getF1SeedKey(r.UpperBits, keyWeight);
    unsigned int uiKey2 = getF1SeedKey(r.LowerBits, keyWeight);
#ifdef EXTEND_SEED
    unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);
#else
    unsigned int uiKey = (uiKey1 << keyWeight) + uiKey2;
#endif
    return (uiKey);
}

////////////////////////////////////////////////////////////////////////////////
// This function is based on the seed pattern (111*1**)(111*1**)(111*1**)1.
inline unsigned int getF2SeedHashValue(WORD_SIZE encodedRead)
{
    // To save the number of CPU instructions, the value encoded bits that doesn't follow the order of reads
    // It still gets the first 3 digit and the fifth digit.. and so on to get total 13 digits
    WORD_SIZE hashValue = (encodedRead & 0x07) << 1; // Get the first 3 digit
    encodedRead >>= 4;

    hashValue += (encodedRead & 0x01); // Get the first 4th digit in the 5th position
    hashValue <<= 3;
    encodedRead >>= 3;

    hashValue += (encodedRead & 0x07); // Get the 5-7th digit
    hashValue <<= 1;
    encodedRead >>= 4;

    hashValue += (encodedRead & 0x01); // Get 8th digit
    hashValue <<= 3;
    encodedRead >>= 3;

    hashValue += (encodedRead & 0x07); // Get 9-11th digit
    hashValue <<= 1;
    encodedRead >>= 4;

    hashValue += (encodedRead & 0x01); // Get 12th digit
    hashValue <<= 1;
    encodedRead >>= 3;

    hashValue += (encodedRead & 0x01); // Get the 13th position
    return (unsigned int) hashValue;
}

unsigned int getF2SeedHashValue(CReadInBits r)
{
    WORD_SIZE hashValue = getF2SeedHashValue(r.UpperBits);
    hashValue <<= BITS_FOR_HASHING;
    hashValue += getF2SeedHashValue(r.LowerBits);
    return ((unsigned int)hashValue);
}

unsigned int getF2SeedHashValue4ReadLength25_27(CReadInBits r)
{
    const int weight = 12;
    const int eliminatedCarePossitionsNo = 1;
    unsigned int hashValue = getF2SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF2SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}
unsigned int getF2SeedHashValue4ReadLength23_24(CReadInBits r)
{
    const int weight = 11;
    const int eliminatedCarePossitionsNo = 2;
    unsigned int hashValue = getF2SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF2SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}
unsigned int getF2SeedHashValue4ReadLength22(CReadInBits r)
{
    const int weight = 10;
    const int eliminatedCarePossitionsNo = 3;
    unsigned int hashValue = getF2SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF2SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}
unsigned int getF2SeedHashValue4ReadLength21(CReadInBits r)
{
    const int weight = 9;
    const int eliminatedCarePossitionsNo = 4;
    unsigned int hashValue = getF2SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF2SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}
unsigned int getF2SeedHashValue4ReadLength20(CReadInBits r)
{
    const int weight = 8;
    const int eliminatedCarePossitionsNo = 5;
    unsigned int hashValue = getF2SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF2SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

ptHashFunc selectF2(int readlength)
{
    if (readlength > 27) {
        return &getF2SeedHashValue;
    } else if (25 <= readlength && readlength <= 27) {
        return &getF2SeedHashValue4ReadLength25_27;
    } else if (23 <= readlength && readlength <= 24) {
        return &getF2SeedHashValue4ReadLength23_24;
    } else if (readlength == 22) {
        return &getF2SeedHashValue4ReadLength22;
    } else if (readlength == 21) {
        return &getF2SeedHashValue4ReadLength21;
    } else if (readlength == 20) {
        return &getF2SeedHashValue4ReadLength20;
    } else {
        LOG_INFO("\nInfo %d: No hash function defined for read with length %d\n", WARNING_LOG, readlength);
        return (NULL);
    }
}

// private function callse by its overloaded getF2SeedHashKey(WORD_SIZE encoedRead, WORD_SIZE encoedRead);
inline unsigned int getF2SeedKey(WORD_SIZE encoedRead, int keyWeight)
{
    //index 234567 8901234  5678901 2
    // Use the suffixLength bits based on the seed pattern 11*1**(111*1**)(111*1**)1 to create a value
    WORD_SIZE uiKey =  encoedRead & 0x03; // Get the 14 and 15 digit
    encoedRead >>= 3;
    uiKey <<= 1; // Get the 16 digit
    uiKey += (encoedRead & 0x01);
    for (keyWeight -= 3; keyWeight > 0; keyWeight -= 4) {
        encoedRead >>= 3;

        uiKey <<= 1; // Get 17th + 4i digit
        uiKey += (encoedRead & 0x01);
        encoedRead >>= 1;

        uiKey <<= 1; // Get 18th + 4i digit
        uiKey += (encoedRead & 0x01);
        encoedRead >>= 1;

        uiKey <<= 1; // Get 19th + 4i digit
        uiKey += (encoedRead & 0x01);
        encoedRead >>= 2; // don't care

        uiKey <<= 1; // Get 20th + 4i digit
        uiKey += (encoedRead & 0x01);
    }
    uiKey >>= (-1 * keyWeight);
    return ((unsigned int)uiKey);
}

unsigned int getF2SeedKey(CReadInBits r, int keyWeight)
{
    r.UpperBits >>= 22; // The first 22 base are used as hash key (111*1**)(111*1**)(111*1**)1
    r.LowerBits >>= 22;
    unsigned int uiKey1 = getF2SeedKey(r.UpperBits, keyWeight);
    unsigned int uiKey2 = getF2SeedKey(r.LowerBits, keyWeight);
#ifdef EXTEND_SEED
    unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);
#else
    unsigned int uiKey = (uiKey1 << keyWeight) + uiKey2;
#endif
    return (uiKey);
}

////////////////////////////////////////////////////////////////////////////////
inline unsigned int getS1_1SeedHashValue(WORD_SIZE Bits)
{
    // For read length >= 32 (SOLiD Read length 33), it has corresponding seed with weight >= 13
    // 32 - (10-1) = 23
    // (1111**1***) (1111**1***) 111
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x0f); // Get the first 4 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 5 th digit
    Bits >>= 4;
    hashValue <<= 4;

    hashValue += (Bits & 0x0f); // Get the first 6-9 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 10 digit
    Bits >>= 4;

    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 11 digit
    Bits >>= 1;

    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 12 digit
    Bits >>= 1;

    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 13 digit
    return ((unsigned int)hashValue);
}

unsigned int getS1_1SeedHashValue(CReadInBits r)
{
    unsigned int hashValue = getS1_1SeedHashValue(r.UpperBits);
    hashValue <<= BITS_FOR_HASHING; // BITS_FOR_HASHING is a fixed bits for 13
    hashValue += getS1_1SeedHashValue(r.LowerBits);
    return hashValue;
}

// Get first 12 care bits and concatenate the key together.
unsigned int getS1_1SeedHashValue4ReadLength31(CReadInBits r)
{
    const int weight = 12;
    const int eliminatedCarePossitionsNo = 1;
    unsigned int hashValue = getS1_1SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getS1_1SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

// Get first 11 care bits and concatenate the key together.
unsigned int getS1_1SeedHashValue4ReadLength30(CReadInBits r)
{
    const int weight = 11;
    const int eliminatedCarePossitionsNo = 2;
    unsigned int hashValue = getS1_1SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getS1_1SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

// Get first 10 care bits and concatenate the key together.
unsigned int getS1_1SeedHashValue4ReadLength26_29(CReadInBits r)
{
    const int weight = 10;
    const int eliminatedCarePossitionsNo = 3;
    unsigned int hashValue = getS1_1SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getS1_1SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

// Get first 9 care bits and concatenate the key together.
unsigned int getS1_1SeedHashValue4ReadLength23_25(CReadInBits r)
{
    const int weight = 9;
    const int eliminatedCarePossitionsNo = 4;
    unsigned int hashValue = getS1_1SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getS1_1SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

ptHashFunc selectS1_1(int readlength)
{
    if (readlength > 31) {
        return &getS1_1SeedHashValue;
    } else if (readlength == 31) {
        return &getS1_1SeedHashValue4ReadLength31;
    } else if (readlength == 30) {
        return &getS1_1SeedHashValue4ReadLength30;
    } else if (26 <= readlength && readlength <= 29) {
        return &getS1_1SeedHashValue4ReadLength26_29;
    } else if (23 <= readlength && readlength <= 25) {
        return &getS1_1SeedHashValue4ReadLength23_25;
    } else {
        LOG_INFO("\nInfo %d: No hash function defined for read with length %d\n", WARNING_LOG, readlength);
        return (NULL);
    }
}

inline unsigned int getS1_1SeedKey(WORD_SIZE Bits, int keyWeight)
{
    // 1**1*** 1111**1*** 111
    WORD_SIZE uiKey = 0;
    // For read lenght = 33 to 35, keyWeight == 1
    uiKey += (Bits & 0x01); // Get the first 14 digit
    if (keyWeight > 1) {
        Bits >>= 3;
        uiKey <<= 1;
        uiKey += (Bits & 0x01); // Get the first 15 th digit, for read length 36 to 39

        for (keyWeight -= 2; keyWeight > 0; keyWeight -= 5) { // For read lenght == 40
            Bits >>= 4;
            uiKey <<= 1;
            uiKey += (Bits & 0x01); // Get 16 th + 5i;

            Bits >>= 1;
            uiKey <<= 1;
            uiKey += (Bits & 0x01); // Get 17 th + 5i;

            Bits >>= 1;
            uiKey <<= 1;
            uiKey += (Bits & 0x01); // Get 18 th + 5i;

            Bits >>= 1;
            uiKey <<= 1;
            uiKey += (Bits & 0x01); // Get 19 th + 5i;

            Bits >>= 3;
            uiKey <<= 1;
            uiKey += (Bits & 0x01); // Get 20 th + 5i;
        }
        uiKey >>= (-1 * keyWeight);
    }
    return ((unsigned int)uiKey);
}

unsigned int getS1_1SeedKey(CReadInBits r, int keyWeight)
{
    // The seed pattern is (1111**1***)(1111**1***)111
    // The first 13 care position, that is the first 23 positions are used for hash value.
    // keyWeight number of base used to generate key for binary search
    if (keyWeight > 0) {
        r.UpperBits >>= 23;
        r.LowerBits >>= 23;
        unsigned int uiKey1 = getS1_1SeedKey(r.UpperBits, keyWeight);
        unsigned int uiKey2 = getS1_1SeedKey(r.LowerBits, keyWeight);
#ifdef EXTEND_SEED
        unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);
#else
        unsigned int uiKey = (uiKey1 << keyWeight) + uiKey2;
#endif
        return uiKey;
    } else
        return (0);
}

////////////////////////////////////////////////////////////////////////////////
inline unsigned int getS2_0SeedHashValue(WORD_SIZE Bits)
{
    // For read length >= 35 or more, weight is 13. (Note SOliD read 35 actually has only color 34)
    // (1111**1****)(1111**1****)111
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x0f); // Get the first 4 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 5 digit
    Bits >>= 5;
    hashValue <<= 4;

    hashValue += (Bits & 0x0f); // Get the first 6-9 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 10 digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 11 digit
    Bits >>= 1;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 12 digit
    Bits >>= 1;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 13 digit

    return ((unsigned int)hashValue);
}

unsigned int getS2_0SeedHashValue(CReadInBits r)
{
    WORD_SIZE hashValue = getS2_0SeedHashValue(r.UpperBits);
    hashValue <<= BITS_FOR_HASHING; // BITS_FOR_HASHING is a fixed bits for 13
    hashValue += getS2_0SeedHashValue(r.LowerBits);
    return ((unsigned int)hashValue);

}

inline unsigned int getS2_0SeedHashValue4ReadLength34(WORD_SIZE Bits)
{
    // For read 34, the seed length is 24.
    // (1111**1****)(1111**1****)11
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x0f); // Get the first 4 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 5 digit
    Bits >>= 5;
    hashValue <<= 4;

    hashValue += (Bits & 0x0f); // Get the first 6-9 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 10 digit
    Bits >>= 5;
    hashValue <<= 2;
    hashValue += (Bits & 0x03); // Get the first 11 - 12th digit

    return ((unsigned int)hashValue);
}

// For Solid Read, the read length typical read length is 34.
// The seed weight for it is 12
unsigned int getS2_0SeedHashValue4ReadLength34(CReadInBits r)
{
    const int weight = 12;
    WORD_SIZE hashValue = getS2_0SeedHashValue4ReadLength34(r.UpperBits);
    hashValue <<= weight;
    hashValue += getS2_0SeedHashValue4ReadLength34(r.LowerBits);
    return ((unsigned int)hashValue);
}

inline unsigned int getS2_0SeedHashValue4ReadLength33(WORD_SIZE Bits)
{
    // For read 33, the seed length is 23.
    // (1111**1****)(1111**1****)1
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x0f); // Get the first 4 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 5 digit
    Bits >>= 5;
    hashValue <<= 4;

    hashValue += (Bits & 0x0f); // Get the first 6-9 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 10 digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 11th digit

    return ((unsigned int)hashValue);
}

// For read length is 33, the seed weight for it is 11
unsigned int getS2_0SeedHashValue4ReadLength33(CReadInBits r)
{
    const int weight = 11;
    WORD_SIZE hashValue = getS2_0SeedHashValue4ReadLength33(r.UpperBits);
    hashValue <<= weight;
    hashValue += getS2_0SeedHashValue4ReadLength33(r.LowerBits);
    return ((unsigned int)hashValue);
}

inline unsigned int getS2_0SeedHashValue4ReadLength28_32(WORD_SIZE Bits)
{
    // For read 32, the seed length is 22. The weight is 10
    // (1111**1****)(1111**1****)
    // For read 28, the seed length is 18. The weight is 10
    // (1111**1****)(1111**1)
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x0f); // Get the first 4 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 5 digit
    Bits >>= 5;
    hashValue <<= 4;

    hashValue += (Bits & 0x0f); // Get the first 6-9 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 10 digit
    return ((unsigned int)hashValue);
}
// Hash Value for read length 28 to 32. Get the first 10 care bits and concatenate them together
unsigned int getS2_0SeedHashValue4ReadLength28_32(CReadInBits r)
{
    const int weight = 10;
    WORD_SIZE hashValue = getS2_0SeedHashValue4ReadLength28_32(r.UpperBits);
    hashValue <<= weight;
    hashValue += getS2_0SeedHashValue4ReadLength28_32(r.LowerBits);
    return ((unsigned int)hashValue);
}


inline unsigned int getS2_0SeedHashValue4ReadLength25_27(WORD_SIZE Bits)
{
    // For read 25, the seed length is 15. The weight is 9
    // (1111**1****)(1111)
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x0f); // Get the first 4 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 5 digit
    Bits >>= 5;
    hashValue <<= 4;

    hashValue += (Bits & 0x0f); // Get the first 6-9 digit
    return ((unsigned int)hashValue);
}

// Hash Value for read length 25. Get the first 9 care bits and concatenate them together
unsigned int getS2_0SeedHashValue4ReadLength25_27(CReadInBits r)
{
    const int weight = 9;
    WORD_SIZE hashValue = getS2_0SeedHashValue4ReadLength25_27(r.UpperBits);
    hashValue <<= weight;
    hashValue += getS2_0SeedHashValue4ReadLength25_27(r.LowerBits);
    return ((unsigned int)hashValue);
}

ptHashFunc selectS2_0(int readlength)
{
    if (readlength > 34) {
        return &getS2_0SeedHashValue;
    } else if (readlength == 34) {
        return &getS2_0SeedHashValue4ReadLength34;
    } else if (readlength == 33) {
        return &getS2_0SeedHashValue4ReadLength33;
    } else if (28 <= readlength && readlength <= 32) {
        return &getS2_0SeedHashValue4ReadLength28_32;
    } else if (25 <= readlength && readlength <= 27) {
        return &getS2_0SeedHashValue4ReadLength25_27;
    } else {
        LOG_INFO("\nInfo %d: No hash function defined for read with length %d\n", WARNING_LOG, readlength);
        return (NULL);
    }
}

inline unsigned int getS2_0SeedKey(WORD_SIZE Bits, int keyWeight)
{
    // 1(**1****)1111**1****)
    WORD_SIZE uiKey = (Bits & 0x01);; // 14th bit
    for (keyWeight -= 1; keyWeight > 0; keyWeight -= 5) {
        Bits >>= 3;
        uiKey <<= 1;
        uiKey += (Bits & 0x01); // 15th bit
        Bits >>= 5;

        uiKey <<= 1;
        uiKey += (Bits & 0x01); // 16th bit
        Bits >>= 1;

        uiKey <<= 1;
        uiKey += (Bits & 0x01); // 17th bit
        Bits >>= 1;

        uiKey <<= 1;
        uiKey += (Bits & 0x01); // 18th bit
        Bits >>= 1;

        uiKey <<= 1;
        uiKey += (Bits & 0x01); // 19th bit
    }
    uiKey >>= (-1 * keyWeight);
    return ((unsigned int)uiKey);
}

unsigned int getS2_0SeedKey(CReadInBits r, int keyWeight)
{
    // The seed pattern is (1111**1****)(11111**1****)
    // The first 13 care position, that is the first 25 position are used for hash value
    if (keyWeight > 0) {
        r.UpperBits >>= 25;
        r.LowerBits >>= 25;
        unsigned int uiKey1 = getS2_0SeedKey(r.UpperBits, keyWeight);
        unsigned int uiKey2 = getS2_0SeedKey(r.LowerBits, keyWeight);
#ifdef EXTEND_SEED
        unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);
#else
        unsigned int uiKey = (uiKey1 << keyWeight) + uiKey2;
#endif
        return uiKey;
    } else
        return (0);
}


inline unsigned int getS2_0SeedKey4ReadLength34(WORD_SIZE Bits, int keyWeight)
{
    keyWeight = 0;
    // 11(**1****)1
    WORD_SIZE uiKey = (Bits & 0x03);; // 13 14th bit

    Bits >>= 4;
    uiKey <<= 1;
    uiKey += (Bits & 0x01); // 15th bit
    Bits >>= 5;

    uiKey <<= 1;
    uiKey += (Bits & 0x01); // 16th bit

    return ((unsigned int)uiKey);
}

// EXTEND_SEED
unsigned int getS2_0SeedKey4ReadLength34(CReadInBits r, int keyWeight)
{
    // The seed pattern is (1111**1****)(1111**1****)11
    // The first 13 care position, that is the first 25 position are used for hash value
    if (keyWeight > 0) {
        r.UpperBits >>= 24;
        r.LowerBits >>= 24;
        unsigned int uiKey1 = getS2_0SeedKey4ReadLength34(r.UpperBits, keyWeight);
        unsigned int uiKey2 = getS2_0SeedKey4ReadLength34(r.LowerBits, keyWeight);
        unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);
        return uiKey;
    } else
        return (0);
}



////////////////////////////////////////////////////////////////////////////////
inline unsigned int getF3SeedHashValue(WORD_SIZE Bits)
{

    // To save the number of CPU instructions, the value enocoded bits that doesn't follow the order of reads
    // It still gets the first 3 digit and the fivth digit.. and so on to get total 13 digits
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x07); // Get the first 3 digit
    Bits >>= 4;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 4th digit
    Bits >>= 3;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 5th digit
    Bits >>= 4;
    hashValue <<= 3;

    hashValue += (Bits & 0x07); // Get the first 6-8 digit
    Bits >>= 4;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 9th digit
    Bits >>= 3;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 10th digit
    Bits >>= 4;
    hashValue <<= 3;
    hashValue += (Bits & 0x07); // Get the first 11-13th digit
    return ((unsigned int)hashValue);
}

unsigned int getF3SeedHashValue(CReadInBits r)
{
    WORD_SIZE hashValue = getF3SeedHashValue(r.UpperBits);
    hashValue <<= BITS_FOR_HASHING;
    hashValue += getF3SeedHashValue(r.LowerBits);
    return ((unsigned int)hashValue);
}

inline unsigned int getF3SeedHashValue4ReadLength34(WORD_SIZE Bits)
{

    // To save the number of CPU instructions, the value enocoded bits that doesn't follow the order of reads
    // It still gets the first 3 digit and the fivth digit.. and so on to get total 13 digits
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x07); // Get the first 3 digit
    Bits >>= 4;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 4th digit
    Bits >>= 3;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 5th digit
    Bits >>= 4;
    hashValue <<= 3;

    hashValue += (Bits & 0x07); // Get the first 6-8 digit
    Bits >>= 4;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 9th digit
    Bits >>= 3;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 10th digit
    Bits >>= 4;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 11th digit
    Bits >>= 1;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 12th digit
    return ((unsigned int)hashValue);
}

unsigned int getF3SeedHashValue4ReadLength34(CReadInBits r)
{
    // The seed length is (34 - 10) = 24.
    // // (11101001000 11101001000 11. Has weight only 12
    const int weight = 12;
    WORD_SIZE hashValue = getF3SeedHashValue4ReadLength34(r.UpperBits);
    hashValue <<= weight;
    hashValue += getF3SeedHashValue4ReadLength34(r.LowerBits);
    return ((unsigned int)hashValue);
}

unsigned int getF3SeedHashValue4ReadLength33(CReadInBits r)
{
    // The seed length is (33 - 10) = 23.
    // // (11101001000 11101001000 1. Has weight only 11
    const int eliminatedCarePossitionsNo = 1;
    const int weight = 11;
    unsigned int hashValue = getF3SeedHashValue4ReadLength34(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF3SeedHashValue4ReadLength34(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}


inline unsigned int getF3SeedHashValue4ReadLength29_32(WORD_SIZE Bits)
{
    // The seed length is (32 - 10) = 22.
    // (11101001000 11101001000. Has weight only 11
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x07); // Get the first 3 digit
    Bits >>= 4;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 4th digit
    Bits >>= 3;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 5th digit
    Bits >>= 4;
    hashValue <<= 3;

    hashValue += (Bits & 0x07); // Get the first 6-8 digit
    Bits >>= 4;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 9th digit
    Bits >>= 3;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the first 10th digit
    return ((unsigned int)hashValue);
}

// Get first 10 care bits and concatenate together.
unsigned int getF3SeedHashValue4ReadLength29_32(CReadInBits r)
{
    // The seed length is (29 - 10) = 19.
    // 11101001000 11101001 Has weight only 10
    const int weight = 10;
    WORD_SIZE hashValue = getF3SeedHashValue4ReadLength29_32(r.UpperBits);
    hashValue <<= weight;
    hashValue += getF3SeedHashValue4ReadLength29_32(r.LowerBits);
    return ((unsigned int)hashValue);
}

// Get first 9 care bits and concatenate together.
unsigned int getF3SeedHashValue4ReadLength26_28(CReadInBits r)
{
    // The seed length is (26 - 10) = 16.
    // 11101001000 11101 Has weight only 9
    const int eliminatedCarePossitionsNo = 1;
    const int weight = 9;
    unsigned int hashValue = getF3SeedHashValue4ReadLength29_32(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF3SeedHashValue4ReadLength29_32(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

// Get first 8 care bits and concatenate together.
unsigned int getF3SeedHashValue4ReadLength25(CReadInBits r)
{
    // The seed length is (25 - 10) = 15.
    // 11101001000 11101 Has weight only 8
    const int eliminatedCarePossitionsNo = 2;
    const int weight = 8;
    unsigned int hashValue = getF3SeedHashValue4ReadLength29_32(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF3SeedHashValue4ReadLength29_32(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

ptHashFunc selectF3(int readlength)
{
    if (readlength > 34) {
        return &getF3SeedHashValue;
    } else if (readlength == 34) {
        return &getF3SeedHashValue4ReadLength34;
    } else if (readlength == 33) {
        return &getF3SeedHashValue4ReadLength33;
    } else if (29 <= readlength && readlength <= 32) {
        return &getF3SeedHashValue4ReadLength29_32;
    } else if (26 <= readlength && readlength <= 28) {
        return &getF3SeedHashValue4ReadLength26_28;
    } else {
        LOG_INFO("\nInfo %d: No hash function defined for read with length %d\n", WARNING_LOG, readlength);
        return (NULL);
    }
}

unsigned int getF3SeedKey(WORD_SIZE Bits, int keyWeight)
{
    // Use the suffixLength bits based on the seed pattern (11101001000 11101001000 1110 ) (100 1000 1110) (100 1000 1110) to create a value
    WORD_SIZE uiKey =  0;
    for (; keyWeight > 0; keyWeight -= 5) {
        uiKey <<= 1;
        uiKey += (Bits & 0x01);
        Bits >>= 3;

        uiKey <<= 1;
        uiKey += (Bits & 0x01);
        Bits >>= 4;

        uiKey <<= 1;
        uiKey += (Bits & 0x01);
        Bits >>= 1;

        uiKey <<= 1;
        uiKey += (Bits & 0x01);
        Bits >>= 1;

        uiKey <<= 1;
        uiKey += (Bits & 0x01);  // for read length 47 (Possition 36)
        Bits >>= 2;
    }
    uiKey >>= (-1 * keyWeight);
    return ((unsigned int)uiKey);
}

unsigned int getF3SeedKey(CReadInBits r, int keyWeight)
{
    if (keyWeight > 0) {
        // The seed pattern is 11101001000 11101001000 111 01
        // The first 13 care position, that is the first 25 position are used for hash value
        r.UpperBits >>= 26;
        r.LowerBits >>= 26;

        unsigned int uiKey1 = getF3SeedKey(r.UpperBits, keyWeight);
        unsigned int uiKey2 = getF3SeedKey(r.LowerBits, keyWeight);
#ifdef EXTEND_SEED
        unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);
#else
        unsigned int uiKey = (uiKey1 << keyWeight) + uiKey2;
#endif
        return uiKey;
    } else {
        return(0);
    }
}

unsigned int getF3SeedKey4ReadLength34(WORD_SIZE Bits, int keyWeight)
{
    // Use the suffixLength bits based on the seed pattern (11101001000 11101001000 11)10 100 1000 1 to create a value
    // the keyWeight under extended seed is 12 + 4. (Because the maximium weight is 16 add 4)
    keyWeight = 0;
    WORD_SIZE uiKey =  0;

    uiKey += (Bits & 0x01);
    uiKey <<= 1;
    Bits >>= 2;

    uiKey += (Bits & 0x01);
    uiKey <<= 1;
    Bits >>= 3;

    uiKey += (Bits & 0x01);
    uiKey <<= 1;
    Bits >>= 4;

    uiKey += (Bits & 0x01);

    return ((unsigned int)uiKey);
}

unsigned int getF3SeedKey4ReadLength34(CReadInBits r, int keyWeight)
{
    if (keyWeight > 0) {
        // Use the suffixLength bits based on the seed pattern (11101001000 11101001000 11)10 100 1000 1 to create a value
        // the keyWeight under extended seed is 12 + 4. (Because the maximum weight is 16 add 4)
        r.UpperBits >>= 24;
        r.LowerBits >>= 24;

        unsigned int uiKey1 = getF3SeedKey4ReadLength34(r.UpperBits, keyWeight);
        unsigned int uiKey2 = getF3SeedKey4ReadLength34(r.LowerBits, keyWeight);

        unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);

        return uiKey;
    } else {
        return(0);
    }
}

unsigned int getF3SeedKey4ReadLength32(WORD_SIZE Bits, int keyWeight)
{
    // Use the suffixLength bits based on the seed pattern (11101001000 11101001000) 1110 100 1000
    // the keyWeight under extended seed is 10 + 5. (Because the maximum weight is 10 add 5)
    WORD_SIZE uiKey =  0;
    uiKey += (Bits & 0x07);
    uiKey <<= 1;
    Bits >>= 4;

    uiKey += (Bits & 0x01);
    uiKey <<= 1;
    Bits >>= 3;

    uiKey += (Bits & 0x01);
    return ((unsigned int)uiKey);
}

unsigned int getF3SeedKey4ReadLength32(CReadInBits r, int keyWeight)
{
    // Use the suffixLength bits based on the seed pattern (11101001000 11101001000) 1110 100 1000
    // the keyWeight under extended seed is 10 + 5. (Because the maximum weight is 10 add 5)
    if (keyWeight > 0) {
        r.UpperBits >>= 22;
        r.LowerBits >>= 22;

        unsigned int uiKey1 = getF3SeedKey4ReadLength32(r.UpperBits, keyWeight);
        unsigned int uiKey2 = getF3SeedKey4ReadLength32(r.LowerBits, keyWeight);
        unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);
        return uiKey;
    } else {
        return(0);
    }
}

////////////////////////////////////////////////////////////////////////////////
inline unsigned int getS1_2SeedHashValue(WORD_SIZE Bits)
{
    // To save the number of CPU instructions, the value encoded bits that doesn't follow the order of reads
    // It still gets the first 3 digit and the fifth digit.. and so on to get total 13 digits
    // (11110010000000)(11110010000000)(111)
    WORD_SIZE hashValue = 0;

    hashValue += (Bits & 0x0f); // Get the first 4 digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 5th digit
    Bits >>= 8;
    hashValue <<= 4;

    hashValue += (Bits & 0x0f); // Get the first 6-9th digit
    Bits >>= 6;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 10th digit
    Bits >>= 8;
    hashValue <<= 3;

    hashValue += (Bits & 0x07); // Get the first 11-13 digit
    return ((unsigned int)hashValue);
}

unsigned int getS1_2SeedHashValue(CReadInBits r)
{
    WORD_SIZE hashValue = getS1_2SeedHashValue(r.UpperBits);
    hashValue <<= BITS_FOR_HASHING;
    hashValue += getS1_2SeedHashValue(r.LowerBits);
    return ((unsigned int)hashValue);
}

unsigned int getS1_2SeedKey4ReadLength46_49(WORD_SIZE Bits, int keyWeight)
{
    // 1001
    WORD_SIZE uiKey =  0;
    uiKey = Bits & 0x01;
    if (keyWeight == 1)
        return ((unsigned int)uiKey);
    else {
        uiKey <<= 1;
        Bits >>= 3;
        uiKey += Bits & 0x01;
        return ((unsigned int)uiKey);
    }
}

// EXTEND_SEED
unsigned int getS1_2SeedKey4ReadLength46_49(CReadInBits r, int keyWeight)
{
    // The seed pattern is 11110010000000 11110010000000 111 100100
    // The first 13 care position, that is the first 31 position are used for hash value
    r.UpperBits >>= 31; // The first 21 base are used as hash key (111*1**)(111*1**)(111*1**)1
    r.LowerBits >>= 31;

    unsigned int uiKey1 = getS1_2SeedKey4ReadLength46_49(r.UpperBits, keyWeight);
    unsigned int uiKey2 = getS1_2SeedKey4ReadLength46_49(r.LowerBits, keyWeight);
#ifdef EXTEND_SEED
    unsigned int uiKey = InterleaveBits((unsigned short) uiKey2, (unsigned short)  uiKey1);
#else
    unsigned int uiKey = (uiKey1 << keyWeight) + uiKey2;
#endif
    return uiKey;
}


////////////////////////////////////////////////////////////////////////////////
inline unsigned int getF4SeedHashValue(WORD_SIZE Bits)
{
// To save the number of CPU instructions, the value encoded bits that doesn't follow the order of reads
    //50 - 9 = 41
    // (1100010000)(1100010000)(1100010000)(1100010000) 1 The weight is 13
    WORD_SIZE hashValue = 0;
    hashValue += (Bits & 0x03); // Get the first 2 digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 3th digit
    Bits >>= 5;
    hashValue <<= 2;
    hashValue += (Bits & 0x03); // Get the 4 and 5th digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 6th digit
    Bits >>= 5;
    hashValue <<= 2;
    hashValue += (Bits & 0x03); // Get the first 7 and 8th digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 9th digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 10th digit
    Bits >>= 1;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 11th digit
    Bits >>= 4;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 12th digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 13th digit
    return ((unsigned int)hashValue);
}

// Get first 13 care bits and concatenate together, with read length = 50
unsigned int getF4SeedHashValue(CReadInBits r)
{
    // The seed length is 50 - (10 - 1) = 41
    // (1100010000)(1100010000)(1100010000) 1100010000. The weight is 13
    const int weight = 13;
    unsigned int hashValue = getF4SeedHashValue(r.UpperBits);
    hashValue <<= weight;
    hashValue += getF4SeedHashValue(r.LowerBits);
    return hashValue;
}

// Get first 12 care bits and concatenate together.
unsigned int getF4SeedHashValue4ReadLength45_49(CReadInBits r)
{
    // The seed length is 45 - (10 - 1) = 36
    // (1100010000)(1100010000)(1100010000) 110001 The weight is 12
    const int eliminatedCarePossitionsNo = 1;
    const int weight = 12;
    unsigned int hashValue = getF4SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF4SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

// Get first 11 care bits and concatenate together.
unsigned int getF4SeedHashValue4ReadLength41_44(CReadInBits r)
{
    // The seed length is 41 - (10 - 1) = 32
    // (1100010000)(1100010000)(1100010000) 11 The weight is 11
    const int eliminatedCarePossitionsNo = 2;
    const int weight = 11;
    unsigned int hashValue = getF4SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF4SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

// Get first 10 care bits and concatenate together.
unsigned int getF4SeedHashValue4ReadLength40(CReadInBits r)
{
    // The seed length is 40 - (10 - 1) = 31
    // (1100010000)(1100010000)(1100010000) 1 The weight is 10
    const int eliminatedCarePossitionsNo = 3;
    const int weight = 10;
    unsigned int hashValue = getF4SeedHashValue(r.UpperBits);
    hashValue >>= eliminatedCarePossitionsNo;
    hashValue <<= weight;
    hashValue += (getF4SeedHashValue(r.LowerBits) >> eliminatedCarePossitionsNo);
    return hashValue;
}

inline unsigned int getF4SeedHashValue4ReadLength35_39(WORD_SIZE Bits)
{
    // The seed length is 35 - (10 - 1) = 26; 39 - (10 - 1) = 30
    // (1100010000)(1100010000)(1100010000) The weight is 9
    WORD_SIZE hashValue = 0;
    hashValue += (Bits & 0x03); // Get the first 2 digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 3th digit
    Bits >>= 5;
    hashValue <<= 2;
    hashValue += (Bits & 0x03); // Get the 4 and 5th digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 6th digit
    Bits >>= 5;
    hashValue <<= 2;
    hashValue += (Bits & 0x03); // Get the first 7 and 8th digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 9th digit
    return ((unsigned int)hashValue);
}

// Get first 9 care bits and concatenate together.
unsigned int getF4SeedHashValue4ReadLength35_39(CReadInBits r)
{
    // The seed length is 35 - (10 - 1) = 26; 39 - (10 - 1) = 30
    // (1100010000)(1100010000)(110001) The weight is 9

    const int SeedWeight = 9;
    WORD_SIZE hashValue = getF4SeedHashValue4ReadLength35_39(r.UpperBits);
    hashValue <<= SeedWeight;
    hashValue += getF4SeedHashValue4ReadLength35_39(r.LowerBits);
    return ((unsigned int)hashValue);
}

inline unsigned int getF4SeedHashValue4ReadLength31_34(WORD_SIZE Bits)
{
    // The seed length is 34 - (10 - 1) = 25; 31 - (10 - 1) = 22
    // (1100010000)(1100010000)(11000) The weight is 8
    WORD_SIZE hashValue = 0;
    hashValue += (Bits & 0x03); // Get the first 2 digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 3th digit
    Bits >>= 5;
    hashValue <<= 2;
    hashValue += (Bits & 0x03); // Get the 4 and 5th digit
    Bits >>= 5;
    hashValue <<= 1;
    hashValue += (Bits & 0x01); // Get the 6th digit
    Bits >>= 5;
    hashValue <<= 2;
    hashValue += (Bits & 0x03); // Get the first 7 and 8th digit
    return ((unsigned int)hashValue);
}

// Get first 8 care bits and concatenate together.
unsigned int getF4SeedHashValue4ReadLength31_34(CReadInBits r)
{
    // The seed length is 34 - (10 - 1) = 25; 31 - (10 - 1) = 22
    // (1100010000)(1100010000)(11000) The weight is 8
    const int SeedWeight = 8;
    WORD_SIZE hashValue = getF4SeedHashValue4ReadLength31_34(r.UpperBits);
    hashValue <<= SeedWeight;
    hashValue += getF4SeedHashValue4ReadLength31_34(r.LowerBits);
    return ((unsigned int)hashValue);
}

ptHashFunc selectF4(int readlength)
{
    if (readlength >= 50) {
        return &getF4SeedHashValue; // weight 13
    } else if (45 <= readlength && readlength <= 49) {
        return &getF4SeedHashValue4ReadLength45_49; // weight 12
    } else if (41 <= readlength && readlength <= 44) {
        return &getF4SeedHashValue4ReadLength41_44; // weight 10
    } else if (readlength == 40) {
        return &getF4SeedHashValue4ReadLength40; // weight 9
    } else if (35 <= readlength && readlength <= 39) {
        return &getF4SeedHashValue4ReadLength35_39; // weight 8
    } else if (31 <= readlength && readlength <= 34) {
        return &getF4SeedHashValue4ReadLength31_34; // weight 8
    } else {
        LOG_INFO("\nInfo %d: No hash function defined for read with length %d\n", WARNING_LOG, readlength);
        return (NULL);
    }
}

unsigned int getNoOfCaredPositions(const char* caSeedRepeat, unsigned int uiReadLength)
{
    unsigned int carePositions = 0;
    unsigned int seedRepeatLength = (unsigned int)strlen(caSeedRepeat);
    for (unsigned int i = 0; i < uiReadLength - seedRepeatLength + 1; i++) {
        if (caSeedRepeat[ i % seedRepeatLength ] == '1')
            carePositions++;
    }
    return(carePositions);
}

unsigned int getNoOfCaredPositions4FullRead(const char* caSeedRepeat, unsigned int uiReadLength)
{
    unsigned int carePositions = 0;
    unsigned int seedRepeatLength = (unsigned int)strlen(caSeedRepeat);
    for (unsigned int i = 0; i < uiReadLength; i++) {
        if (caSeedRepeat[ i % seedRepeatLength ] == '1')
            carePositions++;
    }
    return(carePositions);
}