Example #1
0
        /// <summary>
        /// Word counter
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="writer"></param>
        public static void WordCounter(TextReader reader, TextWriter writer)
        {
            string str1;

            ChainedHashTable hashTable = new ChainedHashTable(1031);

            while ((str1 = reader.ReadLine()) != null)
            {
                string[] strs = str1.Split(null);
                Counter  counter;

                for (int i = 0; i < (int)strs.Length; i++)
                {
                    string      str2        = strs[i];
                    Association association = (Association)hashTable.Find(new Association(str2));
                    if (association == null)
                    {
                        hashTable.Insert(new Association(str2, new Counter(1)));
                    }
                    else
                    {
                        counter = (Counter)association.Value;
                        counter = ++counter;
                    }
                }
            }
            writer.WriteLine(hashTable);
        }
            /// <summary>
            /// Internal constructor
            /// </summary>
            /// <param name="hashtable"></param>
            internal Enumerator(ChainedHashTable hashtable)
            {
                element  = null;
                position = -1;

                this.hashtable = hashtable;
            }