// Copyright (c) 1996, 1997, 1998 Bruno R. Preiss, P.Eng. // $Author: brpreiss $ // $Date: 1998/12/14 02:52:01 $ // $RCSfile: Demo4.java,v $ // $Revision: 3.5 $ package Opus5; /** * Demonstration program that tests the following classes: * ChainedHashTable, * ChainedScatterTable, and * OpenScatterTable. * @see ChainedHashTable * @see ChainedScatterTable * @see OpenScatterTable * @author Bruno R. Preiss, P.Eng. * @version $Id: Demo4.java,v 3.5 1998/12/14 02:52:01 brpreiss Exp $ **/ public class Demo4 { //[ final String copyright = "@(#) Copyright (c) 1998 by Bruno R. Preiss, P.Eng."; //] /** * Prints the hashcodes for the strings * "ett", "två", "tre", "fyra", "fem", "sex", * "sju", "åtta", "nio", "tio", "elva", "tolv". **/ private static void testHash () { Terminal.out.println ("ett=" + Integer.toOctalString ( new Str ("ett").hashCode ())); Terminal.out.println ("tv\u00e5=" + Integer.toOctalString ( new Str ("tv\u00e5").hashCode ())); Terminal.out.println ("tre=" + Integer.toOctalString ( new Str ("tre").hashCode ())); Terminal.out.println ("fyra="+ Integer.toOctalString ( new Str ("fyra").hashCode ())); Terminal.out.println ("fem=" + Integer.toOctalString ( new Str ("fem").hashCode ())); Terminal.out.println ("sex=" + Integer.toOctalString ( new Str ("sex").hashCode ())); Terminal.out.println ("sju=" + Integer.toOctalString ( new Str ("sju").hashCode ())); Terminal.out.println ("\u00e5tta="+ Integer.toOctalString ( new Str ("\u00e5tta").hashCode ())); Terminal.out.println ("nio=" + Integer.toOctalString ( new Str ("nio").hashCode ())); Terminal.out.println ("tio=" + Integer.toOctalString ( new Str ("tio").hashCode ())); Terminal.out.println ("elva="+ Integer.toOctalString ( new Str ("elva").hashCode ())); Terminal.out.println ("tolv="+ Integer.toOctalString ( new Str ("tolv").hashCode ())); } /** * Performs various tests on the specified hash table. * @param hashTable The hash table to be tested. **/ private static void testHashTable (HashTable hashTable) { Terminal.out.println (hashTable); hashTable.insert (new Association (new Str ("foo"), new Dbl (1.2))); hashTable.insert (new Association (new Str ("bar"), new Dbl (3.4))); hashTable.insert (new Association (new Str ("foo"), new Dbl (5.6))); Terminal.out.println (hashTable); Comparable obj = hashTable.find (new Association (new Str ("foo"))); Terminal.out.println (obj); hashTable.withdraw (obj); Terminal.out.println (hashTable); Enumeration i = hashTable.getEnumeration (); while (i.hasMoreElements ()) Terminal.out.println (i.nextElement ()); } /** * The (static) main program. * Invokes various test routines. * @param args The command-line arguments. Ignored. **/ public static void main (String[] args) { testHash (); Terminal.out.println ("ChainedHashTable Test"); HashTable hashTable = new ChainedHashTable (57); testHashTable (hashTable); Terminal.out.println ("ChainedScatterTable Test"); hashTable = new ChainedScatterTable (57); testHashTable (hashTable); Terminal.out.println ("OpenScatterTable Test"); hashTable = new OpenScatterTableV2 (57); testHashTable (hashTable); } }