Subversion Repositories programming

Rev

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