-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestHashTable.java
55 lines (47 loc) · 1.45 KB
/
TestHashTable.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
import java.util.*;
import java.nio.file.*;
class TestHashTable
{
void run ( int threshold )
{
HashTable h = new HashTable ();
int hit1=0, miss1=0, hit2=0, miss2=0;
List<String> lines = null;
List<String> linesmiss = null;
try {
lines = Files.readAllLines (Paths.get ("names36.txt"));
linesmiss = Files.readAllLines (Paths.get ("namesmiss.txt"));
} catch (Exception e) {
System.out.println (e.toString ());
}
for ( int i=0; i<lines.size (); i++ )
{
h.insert (lines.get (i));
}
for ( int i=0; i<lines.size (); i++ )
{
if (h.find (lines.get(i)))
hit1++;
else
miss1++;
}
for ( int i=0; i<linesmiss.size (); i++ )
{
if (h.find (linesmiss.get(i)))
hit2++;
else
miss2++;
}
System.out.println ("Collision Threshold: " + threshold);
if (h.getCollisions () <= threshold)
System.out.println ("Collisions Threshold Met!");
else
System.out.println ("Collisions Threshold Not Met! Collisions = " + h.getCollisions ());
System.out.println ("Seen data [Hit:Miss]: " + hit1 + ":" + miss1);
System.out.println ("Unseen data [Hit:Miss]: " + hit2 + ":" + miss2);
}
public static void main ( String [] args )
{
(new TestHashTable ()).run(Integer.valueOf (args[0]));
}
}