forked from wolfgangmauerer/libtrevisan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweakdes_aot.cc
93 lines (75 loc) · 2.82 KB
/
weakdes_aot.cc
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
/* This file is part of libtrevisan, a modular implementation of
Trevisan's randomness extraction construction.
Copyright (C) 2011-2012, Wolfgang Mauerer <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libtrevisan. If not, see <http://www.gnu.org/licenses/>. */
#include "weakdes_aot.h"
#include "primitives.h"
#include <iostream>
#ifndef NO_DEBUG
#include "debug.h"
#endif
using namespace std;
extern int debug_level;
void weakdes_aot::set_file(const string &filename) {
wd_type wd;
dat.open (filename.c_str(), ios::in | ios::binary);
if(!dat.is_open()) {
cout << "Error: Cannot open weak design input file!"
<< endl;
exit(-1);
}
dat.seekg (0, ios::beg);
dat.read((char*)&offset, sizeof(unsigned short));
dat.read((char*)&wd, sizeof(wd_type));
dat.read((char*)&m, sizeof(uint64_t));
dat.read((char*)&t, sizeof(uint64_t));
dat.read((char*)&d, sizeof(uint64_t));
dat.read((char*)&r, sizeof(long double));
if (debug_level >= PROGRESS) {
cerr << "Reading precomputed weak design from " << filename
<< " with parameters t=" << t << ", m=" << m << ", d=" << d
<< ", r=" << r << ", data offset=" << offset << endl;
cerr << "Original weak design type: " << weakdes_to_string(wd) << endl;
}
}
uint64_t weakdes_aot::compute_d() {
return d;
}
long double weakdes_aot::get_r() {
if (!dat.is_open()) {
cerr << "(aot weak design) Internal error: Cannot determine r without "
<< "input file!" << endl;
exit(-1);
}
return r;
}
void weakdes_aot::compute_Si(uint64_t i, vector<uint64_t> &indices) {
// TODO: This is a hot-spot, use a lock-less construction in
// the read path.
if (file_lock != nullptr)
flock.acquire(*file_lock);
dat.seekg(offset + i*t*sizeof(uint64_t), ios::beg);
// Since the array is continuous, we can read all indices in one single go
dat.read((char*)indices[0], sizeof(uint64_t)*t);
if (file_lock != nullptr)
flock.release();
}
void weakdes_aot::compute_admissible_params() {
weakdes::compute_admissible_params();
// The provided value for t can be larger than the requested
// value, see the comment in weakdes_gf2x.cc. But not the other way.
if (t_requested > t) {
cerr << "Error (weakdes_aot): Requested t=" << t_requested << " is larger "
<< "than the stored value ot t (" << t << "), aborting." << endl;
exit(-1);
}
}