Subversion Repositories programming

Rev

Rev 100 | Details | Compare with Previous | Last modification | View Log | RSS feed

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