Пример #1
0
 /* Function to prlong hash table */
 public void PrintTable()
 {
     for (long i = 0; i < TABLE_SIZE; i++)
     {
         Console.Write($"\nBucket {i}: ");
         LinkedHash entry = table[i];
         while (entry != null)
         {
             Console.Write(entry.Value + " ");
             entry = entry.Next;
         }
     }
 }
Пример #2
0
        // silet version for speed tests
        public void PrintValueSilent(long key)
        {
            if (table[key] == null)             // not found
            {
                return;
            }

            // read while you can
            LinkedHash entry = table[key];

            while (entry != null)
            {
                entry = entry.Next;
            }
        }
Пример #3
0
        /* Function to get value of a key */
        public void PrintValue(long key)
        {
            if (table[key] == null)             // not found
            {
                Console.WriteLine("Empty");
                return;
            }

            // read while you can
            LinkedHash entry = table[key];

            while (entry != null)
            {
                Console.Write(entry.Value + " ");
                entry = entry.Next;
            }
        }
Пример #4
0
        // Add a value
        public void Add(long value)
        {
            long hash = Hash(value) % TABLE_SIZE;
            long key  = hash;

            if (table[hash] == null)
            {
                table[hash] = new LinkedHash(key, value);
            }
            else
            {
                LinkedHash entry = table[hash];
                while (entry.Next != null)
                {
                    entry = entry.Next;
                }
                entry.Next = new LinkedHash(key, value);
            }
        }