コード例 #1
0
        private void Resize()
        {
            var newSize  = GetNextPrime(_size * 3);
            var newTable = new QuickLinkedList <T> [newSize];

            int newHashFunc(T i) => GetHash(i, newSize);

            foreach (var bucket in _table.Where(b => b != null))
            {
                foreach (var item in bucket)
                {
                    AddToTable(newTable, item, newHashFunc);
                }
            }

            _size  = newSize;
            _table = newTable;
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <param name="item"></param>
        /// <param name="hashFunc"></param>
        /// <returns>True if the item already exists in the hashtable</returns>
        private static bool AddToTable(QuickLinkedList <T>[] table, T item, Func <T, int> hashFunc)
        {
            var hashCode = hashFunc(item);

            var bucket = table[hashCode];

            if (bucket == null)
            {
                table[hashCode] = new QuickLinkedList <T>();
                bucket          = table[hashCode];
            }

            foreach (var entry in bucket)
            {
                if (EqualityComparer <T> .Default.Equals(entry, item))
                {
                    return(true);
                }
            }

            bucket.Add(item);
            return(false);
        }
コード例 #3
0
 public LinkedListTester()
 {
     _list  = new QuickLinkedList <string>();
     Output = $"LIST TESTER: {InstructionText}";
 }