-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWitness.cpp
79 lines (67 loc) · 1.92 KB
/
Witness.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
75
76
77
78
79
#include <limits>
#include "utils.h"
#include "Witness.h"
WitnessPlan::WitnessPlan (Plan * const input, RowSize const size, bool final) :
_input (input), _size (size), _final (final)
{
TRACE (false);
} // WitnessPlan::WitnessPlan
WitnessPlan::~WitnessPlan ()
{
TRACE (false);
delete _input;
} // WitnessPlan::~WitnessPlan
Iterator * WitnessPlan::init () const
{
TRACE (false);
return new WitnessIterator (this);
} // WitnessPlan::init
WitnessIterator::WitnessIterator (WitnessPlan const * const plan) :
_plan (plan), _input (plan->_input->init ()), _consumed (0), _produced (0)
{
TRACE (false);
parity = new byte[_plan->_size];
for (RowSize i = 0; i < _plan->_size; ++i) {
parity[i] = 0xFF;
}
#if defined(VERBOSEL2) || defined(VERBOSEL1)
traceprintf ("Initialized parity with size %d: %s\n",
_plan->_size, rowToHexString(parity, _plan->_size).c_str());
#endif
} // WitnessIterator::WitnessIterator
WitnessIterator::~WitnessIterator ()
{
TRACE (false);
delete _input;
#ifdef PRODUCTION
string output = _plan->_final ? "Final" : "Initial";
output += " parity is ";
output += rowToHexString(parity, _plan->_size);
Trace::PrintTrace(OP_RESULT, WITNESS_RESULT, output);
#endif
#if defined(VERBOSEL2) || defined(VERBOSEL1)
traceprintf ("produced %lu of %lu rows\n",
(unsigned long) (_produced),
(unsigned long) (_consumed));
#endif
} // WitnessIterator::~WitnessIterator
byte * WitnessIterator::next ()
{
TRACE (false);
byte * received = _input->next ();
if (received == nullptr) {
return nullptr;
} else {
byte * row = received;
++ _consumed;
for (u_int32_t i = 0; i < _plan->_size; ++i) {
parity[i] ^= row[i];
}
++ _produced;
return row;
}
} // WitnessIterator::next
bool WitnessIterator::forceFlushBuffer()
{
return _input->forceFlushBuffer();
} // WitnessIterator::isFinal