-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmulatableBlock.java
127 lines (111 loc) · 4.26 KB
/
EmulatableBlock.java
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package com.vincentderk.acircuitminer.miner.emulatable.neutralfinder;
import com.vincentderk.acircuitminer.miner.canonical.EdgeCanonical;
import java.util.Arrays;
/**
* Data structure that holds information regarding an emulation.
* <p>
* When a pattern P emulates another pattern, this can store:
* <ul>
* <li>The emulated code,</li>
* <li>The input required for that emulation,</li>
* <li>Which nodes in P were/are active during the emulation,</li>
* <li>...</li>
* </ul>
*
* <p>
* Note: only the emulation information is stored. P, which is used to emulate,
* is not.
*
* @author Vincent Derkinderen
* @version 1.0
*/
public class EmulatableBlock {
/**
* The code of the pattern that is emulated
*/
public long[] emulatedCode;
/**
* The inputs for pattern P to emulate {@link #emulatedCode}. Possible
* values: {0,1,2} where 2 is an actual input value.
*/
public byte[] input;
/**
* This provides the link between the inputs given to an emulated pattern
* and the order of those inputs in the actual input given to the pattern P.
* <p>
* For example: There might be an occurrence whose input nodes to the
* emulated pattern are in order: 5,10,8. To emulate this pattern, let us
* say the input is {@code 120202}. Which {@code 2} the 5, 10 and 8 are, is
* embedded in this array. So {@code emulatedIndexToActualInputIndex[0]}
* represents the index of the input in the pattern that corresponds to the
* first input of the emulated pattern. In our example this might be 1,3 or
* 5, the indices of the {@code 2}'s in the actual input {@code 120202}.
*/
public int[] emulatedIndexToActualInputIndex;
/**
* The options of the emulation. This is the result of converting the P
* pattern into a Graph, testing an input and checking the resulting options
* in each node. An option being {0,1,2,3} where 3 refers to a meaningless
* number and 2 to an actual number.
* <p>
* This can be used to check which nodes were active
* ({@code options[x] == 2}).
*/
public byte[] options;
/**
* Amount of active multiplication nodes
*/
public int activeMultCount;
/**
* Amount of active sum nodes
*/
public int activeSumCount;
/**
* Amount of inactive multiplication nodes
*/
public int inactiveMultCount;
/**
* Amount of inactive sum nodes
*/
public int inactiveSumCount;
/**
* Amount of active inputs. This may be different from the amount of 2's
* present in {@link #input} as some of the input might be irrelevant due to
* multiplication with zero.
*/
public int activeInputCount;
/**
* Creates and returns a copy of this object. This is not a deep-clone so
* {@link #emulatedCode}, {@link #input}, {@link #options} and
* {@link #emulatedIndexToActualInputIndex} in this object are referencing
* the same arrays in the returned clone.
*
* @return A shallow copy of this object instance.
*/
@Override
public EmulatableBlock clone() {
EmulatableBlock block = new EmulatableBlock();
block.emulatedCode = emulatedCode;
block.input = input;
block.options = options;
block.activeMultCount = activeMultCount;
block.activeSumCount = activeSumCount;
block.inactiveMultCount = inactiveMultCount;
block.inactiveSumCount = inactiveSumCount;
block.activeInputCount = activeInputCount;
return block;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Emulated: ").append(EdgeCanonical.printCode(emulatedCode)).append("\n");
sb.append("With input: ").append(Arrays.toString(input)).append("\n");
sb.append("Options: ").append(Arrays.toString(options)).append("\n");
sb.append("activeMultCount: ").append(activeMultCount).append("\n");
sb.append("activeSumCount: ").append(activeSumCount).append("\n");
sb.append("inactiveMultCount: ").append(inactiveMultCount).append("\n");
sb.append("inactiveSumCount: ").append(inactiveSumCount).append("\n");
sb.append("activeInputCount: ").append(activeInputCount).append("\n");
return sb.toString();
}
}