-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.cpp
74 lines (56 loc) · 1.44 KB
/
utils.cpp
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
/*
* File: utils.cpp
* Author: masoud
*
* Created on February 17, 2012, 9:45 AM
*/
#include "utils.h"
#ifdef USE_RANDOMLIB
//#include "PreRandom.h"
#endif
#ifdef USE_PRERAND
PreRandom ptrand;
#endif
using namespace std;
#ifdef HAVE_M4RI
mzd_t *AllBinaryVectors = NULL;
void precomputedTables() {
AllBinaryVectors=mzd_init(POW2(MAXIMUM_CODE_DIMENSION), MAXIMUM_CODE_DIMENSION);
for(word t=0;t<POW2(MAXIMUM_CODE_DIMENSION);t++)
*AllBinaryVectors->rows[t]=t;
//mzd_print(AllBinaryVectors);
}
mzd_t * AllBinVectors(unsigned int length){
assert(length<=MAXIMUM_CODE_DIMENSION);
return mzd_init_window(AllBinaryVectors,0,0,POW2(length),length);
}
#endif
bool readfile(vector< vector<int> >& vals,const char* fname){
ifstream infile(fname,ifstream::in);
if(!infile){
cerr<<"couldn't open file "<<fname<<endl;
return false;
}
string aline;
while(getline(infile,aline))
{
stringstream lineStream(aline );
//cout<<"->"<<aline<<endl;
string x;
vector<int> dims;
do
{
int z=-1;
lineStream>>z;
//cout<<z<<" ";
if(z!=-1)
dims.push_back(z);
}while(getline(lineStream,x,'\t') && infile.good() );
//cout<<endl;
vals.push_back(dims);
}
fprintf(stderr,"read %d lines from file %s, each having size %d\n",
(unsigned int)vals.size(),fname,(unsigned int)vals[0].size());
infile.close();
return true;
}