public static void main(String[] args) { System.out.println(HashUtilities.shortHash(9)); String str = new String("Bananas!"); int hash = str.hashCode(); System.out.println(hash); int smallHash = HashUtilities.shortHash(hash); System.out.println("0 < " + smallHash + " < 1000"); }
/** * Returns the name associated with that key, or null if there is none. * * @param key The position in the map where the desired String is * @return The Desired String */ public String get(int key) { int hashKey = HashUtilities.shortHash(key); if (mapArray[hashKey] == null) { return null; } else { return mapArray[hashKey]; } }
public static void main(String[] args) { // HashUtilities hu = new HashUtilities(); System.out.println("Give me a string and I will calculate its hash code"); String str = System.console().readLine(); int hash = str.hashCode(); int smallHash = HashUtilities.shortHash(hash); System.out.println("0 < " + smallHash + " < 1000"); }
/** * Removes a name from the map. Future calls to get(key) will return null for this key unless * another name is added with the same key. * * @param key The position in the map of the String to be deleted. */ public void remove(int key) { int hashKey = HashUtilities.shortHash(key); if (mapArray[hashKey] != null) { mapArray[hashKey] = null; } }
/** * Puts a new String in the map. * * <p>If the key is already in the map, nothing is done. * * @param key The number to be associated with a given string * @param name The String to be associated with the key */ public void put(int key, String name) { int hashKey = HashUtilities.shortHash(key); if (mapArray[hashKey] == null) { mapArray[hashKey] = name; } }