Exemplo n.º 1
0
  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");
  }
Exemplo n.º 2
0
 /**
  * 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];
   }
 }
Exemplo n.º 3
0
  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");
  }
Exemplo n.º 4
0
 /**
  * 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;
   }
 }
Exemplo n.º 5
0
 /**
  * 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;
   }
 }