-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParseAnonSetData.java
executable file
·123 lines (102 loc) · 3.55 KB
/
ParseAnonSetData.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
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
// java ParseAnonSetData TxInputsAll InputsReduced
public class ParseAnonSetData {
private static class Pair {
int tx;
int idx;
Pair(int tx, int idx) {
this.tx = tx;
this.idx = idx;
}
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (!(o instanceof Pair)) {
return false;
}
Pair p = (Pair) o;
return p.tx == this.tx && p.idx == this.idx;
}
@Override
public int hashCode() {
return 53 * Integer.hashCode(tx) + Integer.hashCode(idx);
}
}
// takes ~36 sec
private static Map<Pair,Integer> loadTxSizes(String file) throws Exception {
System.err.println("Loading all tx inputs from file " + file);
Map<Pair, Integer> szMap = new HashMap<>();
int count = 0;
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
for (String txInput; (txInput = br.readLine()) != null; ) {
String[] parts = txInput.split(" ");
int tx = Integer.parseInt(parts[0]);
int idx = Integer.parseInt(parts[1]);
szMap.put(new Pair(tx, idx), parts.length - 2);
count++;
if (count % 100000 == 0) {
System.err.println("Loaded " + count + " inputs.");
}
}
}
System.err.println("Loaded " + count + " inputs from file " + file);
return szMap;
}
public static void main(String[] args) throws Exception {
String oldFile = args[0];
String newFile = args[1];
long start = System.currentTimeMillis();
Map<Pair, Integer> origSzMap = loadTxSizes(oldFile);
long time1 = System.currentTimeMillis();
System.err.println("time to load old file: " + ((time1 - start) / 1000));
Map<Pair, Integer> newSzMap = loadTxSizes(newFile);
long time2 = System.currentTimeMillis();
System.err.println("time to load new file: " + ((time2 - time1) / 1000));
printReducedAnonSet(origSzMap, newSzMap);
long time3 = System.currentTimeMillis();
System.err.println("time to parse data: " + ((time3 - time2) / 1000));
}
private static void printReducedAnonSet(Map<Pair, Integer> origSzMap,
Map<Pair, Integer> newSzMap) {
// num mixins -> anonSz -> count
// [0, 10] [1, 11]
Map<Integer,Map<Integer,Integer>> anonSzMap = new TreeMap<>();
for (Map.Entry<Pair,Integer> entry : origSzMap.entrySet()) {
int sz = entry.getValue();
if (sz <= 11) {
int mixins = sz - 1;
if (!anonSzMap.containsKey(mixins)) {
anonSzMap.put(mixins, new TreeMap<>());
}
Map<Integer,Integer> countMap = anonSzMap.get(mixins);
int anonSz = newSzMap.get(entry.getKey());
if (!countMap.containsKey(anonSz)) {
countMap.put(anonSz, 0);
}
countMap.put(anonSz, countMap.get(anonSz) + 1);
}
}
// print out anon set sizes
for (Map.Entry<Integer,Map<Integer,Integer>> entry : anonSzMap.entrySet()) {
System.out.print(entry.getKey());
// now print out percentages
for (int count : entry.getValue().values()) {
System.out.print("," + count);
}
System.out.println();
}
}
}