예제 #1
0
        private void DoubleTheCapacity()
        {
            int keyCapacity        = arrayOfHashChainItems.Length;
            int doubledKeyCapacity = keyCapacity * 2;

            HashChainItem[] doubledArrayOfHashChainItems = new HashChainItem[doubledKeyCapacity];

            for (int hashChainItemIndex = 0; hashChainItemIndex < keyCapacity; ++hashChainItemIndex)
            {
                doubledArrayOfHashChainItems[hashChainItemIndex] = arrayOfHashChainItems[hashChainItemIndex];
            }

            for (int hashChainItemIndex = keyCapacity; hashChainItemIndex < doubledKeyCapacity; ++hashChainItemIndex)
            {
                doubledArrayOfHashChainItems[hashChainItemIndex].nextIndex = hashChainItemIndex + 1;
            }

            doubledArrayOfHashChainItems[doubledKeyCapacity - 1].nextIndex = HashChainIndexTerminal;

            if (availableHashChainIndex == HashChainIndexTerminal)
            {
                availableHashChainIndex = keyCapacity;
            }

            arrayOfHashChainItems = doubledArrayOfHashChainItems;
        }
예제 #2
0
        private int FindHashChainItemIndexForKey(int tableIndex, KeyType key)
        {
            int hashChainHeadIndex = tableOfHashChainHeadIndices[tableIndex];
            int hashChainItemIndex = hashChainHeadIndex;

            while (hashChainItemIndex != HashChainIndexTerminal)
            {
                HashChainItem hashChainItem = arrayOfHashChainItems[hashChainItemIndex];

                if (hashChainItem.key.CompareTo(key) == 0)
                {
                    return(hashChainItemIndex);
                }

                hashChainItemIndex = hashChainItem.nextIndex;
            }

            return(HashChainIndexTerminal);
        }