Пример #1
0
        /// <summary>
        /// adds each word to hashmap if not already present; returns first duplicate
        /// </summary>
        /// <param name="line"> string to search for duplicate </param>
        /// <returns> first duplicate found, or 'no repeats found' if none </returns>
        public static string RepeatedWord(string line)
        {
            string[] words = line.Split(new char[] { ' ', ',', '.', ':', ';', '?', '!', '*', '<', '>', '(', ')', '{', '}', '[', ']' });
            int      idx   = 0;
            Hashmap  map   = new Hashmap(1024);

            foreach (var word in words)
            {
                if (word != "")
                {
                    string wordLower = word.ToLower();
                    idx = map.Hash(wordLower);
                    if (map.Contains(wordLower, 0))
                    {
                        return(wordLower);
                    }
                    else
                    {
                        map.Add(wordLower, 0);
                    }
                }
            }
            return("no repeats found");
        }
Пример #2
0
        public void Hash_CanReturnIndex(Object key, int idx)
        {
            Hashmap map = new Hashmap(1024);

            Assert.Equal(idx, map.Hash(key));
        }