13 const char * VERSION = GITVERSION;
23 template <
typename keyType,
typename IOvalueType = u
int16_t>
25 typedef uint64_t valueType;
27 vector<Othello<keyType> *> vOths;
30 bool addOth(
unsigned int groupid, vector<keyType> &keys, vector<VT> &values) {
32 poth =
new Othello<keyType>(L, &keys[0], keys.size(),
true, &values[0],
sizeof(values[0]));
34 printf(
"Build Halt!\n");
37 vOths[groupid] = poth;
38 if ((poth -> removedKeys).size()>0) {
40 keyType fullk; helper->combgrp(fullk,groupid,k);
41 printf(
"Key in Grp %x : %llx is removed \n", groupid, fullk);
42 removedKeys.push_back(fullk);
56 vector<uint8_t> values;
57 for (
int i = 0 ; i < NN; i ++) {
58 keys.push_back((((uint64_t) i) << 32) + i + 1);
59 values.push_back(i & 0xFF);
63 addOth(0,keys,values);
74 helper = _reader->helper;
77 vOths.resize(1<<_split);
81 keyType k; IOvalueType v;
83 vector<IOvalueType> values;
85 if (!_reader->getNext(&k,&v))
break;
89 buildsucc = addOth(0,keys,values);
94 if (_reader->getFileIsSorted()) {
96 printf(
"Reading file for keys in group %2x/%2x\n", grpid,(1<<
split)-1);
98 vector<IOvalueType> values;
100 keyType k; IOvalueType v; keyType keyingroup; uint32_t groupid;
101 if (!_reader->getNext(&k,&v))
break;
102 _reader->helper->
splitgrp(k,groupid,keyingroup);
103 if (groupid != grpid) {
104 if (!addOth(grpid,keys,values))
105 {_reader->finish();
return;}
107 printf(
"Reading file for keys in group %2x/%0x\n", grpid,(1<<
split)-1);
111 keys.push_back(keyingroup);
114 if (!addOth(grpid,keys,values))
115 { _reader->finish();
return;}
118 for (uint32_t grpid = 0; grpid < (1<<_split); grpid++) {
119 printf(
"Reading file for keys in group %2x/%2x\n", grpid,(1<<
split)-1);
120 vector<keyType> keys;
121 vector<IOvalueType> values;
124 keyType k; IOvalueType v; keyType keyingroup; uint32_t groupid;
125 if (!_reader->getNext(&k,&v))
break;
126 _reader->helper->
splitgrp(k,groupid,keyingroup);
127 if (groupid != grpid)
continue;
128 keys.push_back(keyingroup);
131 printf(
"keycount %d ", keys.size());
133 if (!addOth(grpid,keys,values))
134 {_reader->finish();
return;}
149 inline IOvalueType
query(
const keyType &k) {
153 return vOths[0]->queryInt(k);
155 helper->splitgrp(k,grp,kgrp);
156 return (vOths[grp]!=NULL)?vOths[grp]->queryInt(kgrp):0;
160 printf(
"Printall ...\n");
180 pFile = fopen (fname,
"wb");
181 unsigned char buf0x20[0x20];
183 p = (
char *) &(buf0x20[0]);
184 memset(buf0x20,0,
sizeof(buf0x20));
185 strcpy(p+0x4,VERSION);
186 uint32_t split32 =
split;
187 memcpy(buf0x20, &split32,
sizeof(uint32_t));
188 fwrite(buf0x20,
sizeof(buf0x20),1,pFile);
189 for (
int i = 0; i <(1<<
split); i++)
192 vOths[i]->exportInfo(buf0x20);
194 memset(buf0x20,0,
sizeof(buf0x20));
195 fwrite(buf0x20,
sizeof(buf0x20),1,pFile);
197 for (
int i = 0; i <(1<<
split); i++) {
199 vOths[i]->writeDataToBinaryFile(pFile);
203 uint32_t nRemovedKeys = removedKeys.size();
204 fwrite(&nRemovedKeys,
sizeof(nRemovedKeys),1,pFile);
205 for (
int i = 0 ; i < nRemovedKeys; i++)
206 fwrite(&removedKeys[i],
sizeof(keyType),1,pFile);
214 printf(
"Read from binary Othello file %s\n", fname);
216 pFile = fopen (fname,
"rb");
217 uint32_t compversion;
218 unsigned char buf0x20[0x20];
219 fread(buf0x20,
sizeof(buf0x20),1,pFile);
221 p = (
char *) &(buf0x20[0]);
222 #ifndef NO_VERSION_CHECK
223 if (strcmp(p+4,VERSION)) {
224 printf(
"Wrong version number\n");
230 memcpy(&split32, buf0x20,
sizeof(uint32_t));
233 for (
int i = 0; i < (1<<
split); i++) {
234 fread(buf0x20,
sizeof(buf0x20),1,pFile);
236 uint64_t *ppoth; ppoth = (uint64_t*) &buf0x20;
239 vOths.push_back(poth);
241 for (
int i = 0; i < (1<<
split); i++) {
242 if (vOths[i] != NULL) {
248 uint32_t nRemovedKeys = removedKeys.size();
249 fread(&nRemovedKeys,
sizeof(nRemovedKeys),1,pFile);
250 removedKeys.resize(nRemovedKeys);
251 for (
int i = 0 ; i < nRemovedKeys; i++)
252 fread(&removedKeys[i],
sizeof(keyType),1,pFile);
void writeToFile(const char *fname)
write Grouped l-Othello to a file.
Definition: muloth.h:178
virtual void splitgrp(const keyType &key, uint32_t &grp, keyType &keyInGroup)=0
split a keyTypeype value into two parts: groupID/keyInGroup by the highest splitbit bits...
Describes the data structure Grouped l-Othello. It classifies keys of keyType into 2^L classes...
Definition: muloth.h:24
void loadDataFromBinaryFile(FILE *pF)
load the array from file.
Definition: othello.h:364
IOvalueType query(const keyType &k)
returns a L-bit integer query value for a key.
Definition: muloth.h:149
std::vector< std::string > split(const char *str, char deli)
split a c-style string with delimineter chara.
Definition: io_helper.h:136
vector< keyType > removedKeys
list of skipped keys for all underlying Othello.
Definition: muloth.h:48
Definition: io_helper.h:149
Describes the data structure l-Othello. It classifies keys of keyType into 2^L classes.
Definition: othello.h:25
MulOth(const char *fname, IOHelper< keyType, IOvalueType > *_helper)
construct a Grouped l-Othello from a file.
Definition: muloth.h:212
Definition: io_helper.h:43
vector< keyType > removedKeys
The list of removed keys.
Definition: othello.h:45
MulOth(uint32_t _L, unsigned char _split, class FileReader< keyType, IOvalueType > *_reader)
Construct a Grouped l-Othello from a file.
Definition: muloth.h:73
MulOth(uint32_t _L, uint32_t NN)
This generates toy data for test purpose.
Definition: muloth.h:52
bool build
true if Othello is successfully built.
Definition: othello.h:38