예제 #1
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((Key)keys[i], (Value)vals[i]);
                }
            }
            keys = temp.keys;
            vals = temp.vals;
            M    = temp.M;
        }
예제 #2
0
        public static void MainTest(string[] args)
        {
            LinearProbingHashST <string, int> st = new LinearProbingHashST <string, int>();
            TextInput StdIn = new TextInput();

            string[] keys = StdIn.ReadAllStrings();

            for (int i = 0; i < keys.Length; i++)
            {
                st[keys[i]] = i;
            }
            foreach (string s in st.Keys())
            {
                Console.WriteLine("{0} {1}", s, st[s]);
            }
            Console.WriteLine();
        }