Debian Codegraph @

vendor/nthash/lib/seedgen.cpp

raw
1 #include <stdio.h>
2 #include <iostream>
3 #include <stdlib.h>
4
5 #define __STDC_FORMAT_MACROS
6 #include <inttypes.h>
7
8 void printBin(uint64_t n) {
9 int count=0,count1=0;
10 while (++count<=64) {
11 if (n & ((uint64_t)1<<63)) {
12 printf("1 ");
13 ++count1;
14 }
15 else
16 printf("0 ");
17
18 n <<= 1;
19 }
20 printf(" count1=%d\n",count1);
21 }
22
23 void balanceSeed() {
24
25 srand(time(NULL));
26 int r1[4]= {32,32,32,32};
27 const int seedNum=4;
28 int hashSeed[seedNum][64];
29 for (int i=0; i<seedNum; i++)
30 for (int j=0; j<64; j++)
31 hashSeed[i][j]=0;
32 for (int j=0; j<64; j++) {
33 int ranVec[seedNum];
34 for (int i=0; i<seedNum; i++)
35 ranVec[i]=i;
36 for (int i=0; i<seedNum/2; i++) {
37 int ranInd = rand() % (seedNum-i);
38 int tmp = ranVec[seedNum-i-1];
39 ranVec[seedNum-i-1] = ranVec[ranInd];
40 ranVec[ranInd] = tmp;
41 }
42 if(r1[ranVec[0]]>0 && r1[ranVec[1]]>0) {
43 hashSeed[ranVec[0]][j] = 1;
44 r1[ranVec[0]]--;
45 hashSeed[ranVec[1]][j] = 1;
46 r1[ranVec[1]]--;
47 }
48 else if(r1[ranVec[0]]<0 && r1[ranVec[1]]>0) {
49 hashSeed[ranVec[1]][j] = 1;
50 r1[ranVec[1]]--;
51 if(r1[ranVec[2]]>0) {
52 hashSeed[ranVec[2]][j] = 1;
53 r1[ranVec[2]]--;
54 }
55 else
56 hashSeed[ranVec[3]][j] = 1;
57 r1[ranVec[3]]--;
58 }
59 else if(r1[ranVec[0]]>0 && r1[ranVec[1]]<0) {
60 hashSeed[ranVec[0]][j] = 1;
61 r1[ranVec[0]]--;
62 if(r1[ranVec[2]]>0) {
63 hashSeed[ranVec[2]][j] = 1;
64 r1[ranVec[2]]--;
65 }
66 else
67 hashSeed[ranVec[3]][j] = 1;
68 r1[ranVec[3]]--;
69 }
70 else {
71 hashSeed[ranVec[2]][j] = 1;
72 r1[ranVec[2]]--;
73 hashSeed[ranVec[3]][j] = 1;
74 r1[ranVec[3]]--;
75 }
76
77 }
78
79 for (int i=0; i<seedNum; i++) {
80 for (int j=0; j<64; j++)
81 std::cout << hashSeed[i][j] << " ";
82 std::cout << "\n";
83 }
84
85 long long unsigned int allSeed[seedNum];
86 for (int i=0; i<seedNum; i++) {
87 uint64_t hSeed=0;
88 for (int j=0; j<64; j++) {
89 if(hashSeed[i][j]==1)
90 hSeed = (uint64_t) (hSeed << 1 | 1);
91 else
92 hSeed = (uint64_t) (hSeed << 1 | 0);
93 }
94 allSeed[i]=hSeed;
95 printf("%" PRIu64 "\n", hSeed);
96 //printf("0x%llx\n", hSeed);
97 printBin(hSeed);
98
99 }
100 //for (int i=0; i<seedNum; i++)
101 printf("static const uint64_t seedA = 0x%llx;\n", allSeed[0]);
102 printf("static const uint64_t seedC = 0x%llx;\n", allSeed[1]);
103 printf("static const uint64_t seedG = 0x%llx;\n", allSeed[2]);
104 printf("static const uint64_t seedT = 0x%llx;\n", allSeed[3]);
105 exit(0);
106 }
107
108 void getSeeds() {
109 //balanceSeed();
110 srand(time(NULL));
111 const int seedNum=4;
112 int hashSeed[seedNum][64];
113 for (int i=0; i<seedNum; i++)
114 for (int j=0; j<64; j++)
115 hashSeed[i][j]=0;
116
117
118 for (int j=0; j<64; j++) {
119 int ranVec[seedNum];
120 for (int i=0; i<seedNum; i++)
121 ranVec[i]=i;
122 for (int i=0; i<seedNum/2; i++) {
123 int ranInd = rand() % (seedNum-i);
124 int tmp = ranVec[seedNum-i-1];
125 ranVec[seedNum-i-1] = ranVec[ranInd];
126 ranVec[ranInd] = tmp;
127 }
128 for (int i=0; i<seedNum/2; i++)
129 hashSeed[ranVec[i]][j] = 1;
130 }
131
132 for (int i=0; i<seedNum; i++) {
133 for (int j=0; j<64; j++)
134 std::cout << hashSeed[i][j] << " ";
135 std::cout << "\n";
136 }
137
138 long long unsigned int allSeed[seedNum];
139
140 for (int i=0; i<seedNum; i++) {
141 uint64_t hSeed=0;
142 for (int j=0; j<64; j++) {
143 if(hashSeed[i][j]==1)
144 hSeed = (uint64_t) (hSeed << 1 | 1);
145 else
146 hSeed = (uint64_t) (hSeed << 1 | 0);
147 }
148 allSeed[i]=hSeed;
149 printf("%" PRIu64 "\n", hSeed);
150 printBin(hSeed);
151
152 }
153
154 printf("static const uint64_t seedA = 0x%llx;\n", allSeed[0]);
155 printf("static const uint64_t seedC = 0x%llx;\n", allSeed[1]);
156 printf("static const uint64_t seedG = 0x%llx;\n", allSeed[2]);
157 printf("static const uint64_t seedT = 0x%llx;\n", allSeed[3]);
158 //return 0;
159 }