| Line 4... |
Line 4... |
| 4 |
/////////////////////////////////////////////////////////////////////////////
|
4 |
/////////////////////////////////////////////////////////////////////////////
|
| 5 |
class TestHashTable {
|
5 |
class TestHashTable {
|
| 6 |
//---------------------------------------------------------------------------
|
6 |
//---------------------------------------------------------------------------
|
| 7 |
public static void main ( String [] args ) throws Exception {
|
7 |
public static void main ( String [] args ) throws Exception {
|
| 8 |
|
8 |
|
| - |
|
9 |
//set up an array holding the names of each probing method, for
|
| - |
|
10 |
//easy retrieval in the main loop
|
| 9 |
String[] names = {"Linear Probing","Prime Probing p=3",
|
11 |
String[] names = {"Linear Probing","Prime Probing p=3",
|
| 10 |
"Prime Probing p=5","Prime Probing p=7",
|
12 |
"Prime Probing p=5","Prime Probing p=7",
|
| 11 |
"Prime Probing p=11","Quadratic Probing",
|
13 |
"Prime Probing p=11","Quadratic Probing",
|
| 12 |
"Double Hashing" };
|
14 |
"Double Hashing" };
|
| 13 |
|
15 |
|
| 14 |
for( int i=0; i < 7; i++ ) {
|
16 |
HashTable testTable; //create the HashTable that we are going to use
|
| 15 |
|
17 |
|
| - |
|
18 |
//run once for each probing method
|
| - |
|
19 |
for( int i=0; i < 7; i++ ) {
|
| - |
|
20 |
|
| - |
|
21 |
//print out the probe method we are using
|
| 16 |
System.out.println("Using Method: " + names[i]);
|
22 |
System.out.println("Using Method: " + names[i]);
|
| 17 |
System.out.println();
|
23 |
System.out.println();
|
| 18 |
|
24 |
|
| - |
|
25 |
//clear the HashTable and set the next probe type
|
| 19 |
HashTable testTable = new HashTable( 17 ); //set max size to 17
|
26 |
testTable = new HashTable( 17 ); //set max size to 17
|
| 20 |
testTable.setProbeType(i); //set the probe type
|
27 |
testTable.setProbeType(i); //set the probe type
|
| 21 |
|
28 |
|
| - |
|
29 |
//enter all the data
|
| 22 |
testTable.put("AT",new Country("Austria","German",32378,8139299));
|
30 |
testTable.put("AT",new Country("Austria","German",32378,8139299));
|
| 23 |
testTable.put("BE",new Country("Belgium","Dutch",11800,10182034));
|
31 |
testTable.put("BE",new Country("Belgium","Dutch",11800,10182034));
|
| 24 |
testTable.put("DE",new Country("Germany","German",137800,82087361));
|
32 |
testTable.put("DE",new Country("Germany","German",137800,82087361));
|
| 25 |
testTable.put("DK",new Country("Denmark","Danish",16639,5356845));
|
33 |
testTable.put("DK",new Country("Denmark","Danish",16639,5356845));
|
| 26 |
testTable.put("ES",new Country("Spain","Spanish",194880,39167744));
|
34 |
testTable.put("ES",new Country("Spain","Spanish",194880,39167744));
|
| Line 30... |
Line 38... |
| 30 |
testTable.put("IE",new Country("Ireland","English",27100,3632944));
|
38 |
testTable.put("IE",new Country("Ireland","English",27100,3632944));
|
| 31 |
testTable.put("IT",new Country("Italy","Italian",116300,56735130));
|
39 |
testTable.put("IT",new Country("Italy","Italian",116300,56735130));
|
| 32 |
testTable.put("LU",new Country("Luxembourg","French",998,429080));
|
40 |
testTable.put("LU",new Country("Luxembourg","French",998,429080));
|
| 33 |
testTable.put("NL",new Country("Netherlands","Dutch",16033,15807641));
|
41 |
testTable.put("NL",new Country("Netherlands","Dutch",16033,15807641));
|
| 34 |
testTable.put("SE",new Country("Sweden","Swedish",173732,8911296));
|
42 |
testTable.put("SE",new Country("Sweden","Swedish",173732,8911296));
|
| 35 |
|
43 |
|
| - |
|
44 |
//print out the number of collisions
|
| 36 |
System.out.println();
|
45 |
System.out.println();
|
| 37 |
System.out.println("Number of collisions: " + testTable.collisions());
|
46 |
System.out.println("Number of collisions: " + testTable.collisions());
|
| 38 |
|
47 |
|
| - |
|
48 |
//print a seperator
|
| 39 |
System.out.println();
|
49 |
System.out.println();
|
| 40 |
System.out.println("----------------------------------------");
|
50 |
System.out.println("----------------------------------------");
|
| 41 |
System.out.println();
|
51 |
System.out.println();
|
| 42 |
}
|
52 |
}
|
| 43 |
|
53 |
|