Esempio n. 1
0
    /**
     * Unit tests the {@code LinearProbingHashST} data type.
     *
     * @param args the command-line arguments
     */
    public static void main(String[] args) { 
        LinearProbingHashST<String, Integer> st = new LinearProbingHashST<String, Integer>();
        for (int i = 0; !StdIn.isEmpty(); i++) {
            String key = StdIn.readString();
            st.put(key, i);
        }

        // print keys
        for (String s : st.keys()) 
            StdOut.println(s + " " + st.get(s)); 
    }
Esempio n. 2
0
 // resizes the hash table to the given capacity by re-hashing all of the keys
 private void resize(int capacity) {
     LinearProbingHashST<Key, Value> temp = new LinearProbingHashST<Key, Value>(capacity);
     for (int i = 0; i < m; i++) {
         if (keys[i] != null) {
             temp.put(keys[i], vals[i]);
         }
     }
     keys = temp.keys;
     vals = temp.vals;
     m    = temp.m;
 }