Subversion Repositories programming

Rev

Rev 14 | Rev 100 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

// Written by Ira Snyder
// 10-18-2004
import java.io.*;
/////////////////////////////////////////////////////////////////////////////
class TestHashTable {
//---------------------------------------------------------------------------
    public static void main ( String [] args ) throws Exception {
        
        //set up an array holding the names of each probing method, for
        //easy retrieval in the main loop
        String[] names = {"Linear Probing","Prime Probing p=3",
                          "Prime Probing p=5","Prime Probing p=7",
                          "Prime Probing p=11","Quadratic Probing",
                          "Double Hashing" };
        
        HashTable testTable; //create the HashTable that we are going to use
        
        //run once for each probing method
        for( int i=0; i < 7; i++ ) {
            
            //print out the probe method we are using
            System.out.println("Using Method: " + names[i]);
            System.out.println();
            
            //clear the HashTable and set the next probe type
            testTable = new HashTable( 17 ); //set max size to 17
            testTable.setProbeType(i); //set the probe type
            
            //enter all the data
            testTable.put("AT",new Country("Austria","German",32378,8139299));
            testTable.put("BE",new Country("Belgium","Dutch",11800,10182034));
            testTable.put("DE",new Country("Germany","German",137800,82087361));
            testTable.put("DK",new Country("Denmark","Danish",16639,5356845));
            testTable.put("ES",new Country("Spain","Spanish",194880,39167744));
            testTable.put("FR",new Country("France","French",211200,58978172));
            testTable.put("GB",new Country("United Kingdom","English",94500,59113439));
            testTable.put("GR",new Country("Greece","Greek",50900,10707135));
            testTable.put("IE",new Country("Ireland","English",27100,3632944));
            testTable.put("IT",new Country("Italy","Italian",116300,56735130));
            testTable.put("LU",new Country("Luxembourg","French",998,429080));
            testTable.put("NL",new Country("Netherlands","Dutch",16033,15807641));
            testTable.put("SE",new Country("Sweden","Swedish",173732,8911296));
            
            //print out the number of collisions
            System.out.println();
            System.out.println("Number of collisions: " + testTable.collisions());
            
            //print a seperator
            System.out.println();
            System.out.println("----------------------------------------");
            System.out.println();
        }
    
    }
//---------------------------------------------------------------------------
}
/////////////////////////////////////////////////////////////////////////////