-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHash.java
More file actions
152 lines (129 loc) · 6.42 KB
/
Copy pathHash.java
File metadata and controls
152 lines (129 loc) · 6.42 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import java.io.IOException;
import java.io.RandomAccessFile;
public class Hash {
final static int SIZE = 128;
public static void main(String[] args) {
String inputPath = "input.txt";
String outputPath = "output.csv";
hash1(inputPath, outputPath); // burris hash linear
// hash2(inputPath, outputPath); // my hash linear
// hash3(inputPath, outputPath); // burris hash random
// hash4(inputPath, outputPath); // my hash random
}
public static void hash1(String inputPath, String outputPath) {
burrHash burrisHash = new burrHash();
try (RandomAccessFile inputFile = new RandomAccessFile(inputPath, "r");
RandomAccessFile outputFile = new RandomAccessFile(outputPath, "rw")) {
String line;
while ((line = inputFile.readLine()) != null) {
burrisHash.insert(line);
}
outputFile.writeBytes("Index, Item, Probes, Initial\n");
for (int i = 0; i < SIZE; i++) {
if (burrisHash.getHashVal(i) != null) {
String outputLine = String.format("%3d,%-16s,%d,%d\n", i, burrisHash.getHashVal(i), burrisHash.getProbes(i), burrisHash.getInit(i));
outputFile.writeBytes(outputLine);
System.out.printf("Index %3d: %-16s, Probes: %d, InitialProbe: %d\n", i, burrisHash.getHashVal(i), burrisHash.getProbes(i), burrisHash.getInit(i));
}
}
int sum = 0, max = burrisHash.getProbes(0);
for (int i = 0; i < SIZE; i++) {
sum += burrisHash.getProbes(i);
if (burrisHash.getProbes(i) > max) {
max = burrisHash.getProbes(i);
}
}
double average = sum / (double) 100;
System.out.println("Expected probes: " + average + " Max probes: " + max + " Min probes: 1");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void hash2(String inputPath, String outputPath) {
myHash myHash = new myHash();
try (RandomAccessFile inputFile = new RandomAccessFile(inputPath, "r");
RandomAccessFile outputFile = new RandomAccessFile(outputPath, "rw")) {
String line;
while ((line = inputFile.readLine()) != null) {
myHash.insert(line);
}
outputFile.writeBytes("Index, Item, Probes, Initial\n");
for (int i = 0; i < SIZE; i++) {
if (myHash.getHashVal(i) != null) {
String outputLine = String.format("%3d,%-16s,%d,%d\n", i, myHash.getHashVal(i), myHash.getProbes(i), myHash.getInit(i));
outputFile.writeBytes(outputLine);
System.out.printf("Index %3d: %-16s, Probes: %d, InitialProbe: %d\n", i, myHash.getHashVal(i), myHash.getProbes(i), myHash.getInit(i));
}
}
int sum = 0, max = myHash.getProbes(0);
for (int i = 0; i < SIZE; i++) {
sum += myHash.getProbes(i);
if (myHash.getProbes(i) > max) {
max = myHash.getProbes(i);
}
}
double average = sum / (double) 100;
System.out.println("Expected probes: " + average + " Max probes: " + max + " Min probes: 1");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void hash3(String inputPath, String outputPath) {
RandomBurrHash rburrisHash = new RandomBurrHash();
try (RandomAccessFile inputFile = new RandomAccessFile(inputPath, "r");
RandomAccessFile outputFile = new RandomAccessFile(outputPath, "rw")) {
String line;
while ((line = inputFile.readLine()) != null) {
rburrisHash.insert(line);
}
outputFile.writeBytes("Index, Item, Probes, Initial\n");
for (int i = 0; i < SIZE; i++) {
if (rburrisHash.getHashVal(i) != null) {
String outputLine = String.format("%3d,%-16s,%d,%d\n", i, rburrisHash.getHashVal(i), rburrisHash.getProbes(i), rburrisHash.getInit(i));
outputFile.writeBytes(outputLine);
System.out.printf("Index %3d: %-16s, Probes: %d, InitialProbe: %d\n", i, rburrisHash.getHashVal(i), rburrisHash.getProbes(i), rburrisHash.getInit(i));
}
}
int sum = 0, max = rburrisHash.getProbes(0);
for (int i = 0; i < SIZE; i++) {
sum += rburrisHash.getProbes(i);
if (rburrisHash.getProbes(i) > max) {
max = rburrisHash.getProbes(i);
}
}
double average = sum / (double)100;
System.out.println("Expected probes: " + average + " Max probes: " + max + " Min probes: 1");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void hash4(String inputPath, String outputPath) {
myRandHash myRandHash = new myRandHash();
try (RandomAccessFile inputFile = new RandomAccessFile(inputPath, "r");
RandomAccessFile outputFile = new RandomAccessFile(outputPath, "rw")) {
String line;
while ((line = inputFile.readLine()) != null) {
myRandHash.insert(line);
}
outputFile.writeBytes("Index, Item, Probes, Initial\n");
for (int i = 0; i < SIZE; i++) {
if (myRandHash.getHashVal(i) != null) {
String outputLine = String.format("%3d,%-16s,%d,%d\n", i, myRandHash.getHashVal(i), myRandHash.getProbes(i), myRandHash.getInit(i));
outputFile.writeBytes(outputLine);
System.out.printf("Index %3d: %-16s, Probes: %d, InitialProbe: %d\n", i, myRandHash.getHashVal(i), myRandHash.getProbes(i), myRandHash.getInit(i));
}
}
int sum = 0, max = myRandHash.getProbes(0);
for (int i = 0; i < SIZE; i++) {
sum += myRandHash.getProbes(i);
if (myRandHash.getProbes(i) > max) {
max = myRandHash.getProbes(i);
}
}
double average = sum / (double) 100;
System.out.println("Expected probes: " + average + " Max probes: " + max + " Min probes: 1");
} catch (IOException e) {
e.printStackTrace();
}
}
}