Exemplo n.º 1
0
        public static void AddHashData(string value, Node node)
        {
            int hashKey = HashCodeExtensionMethod.GetHashCode2(value);

            if (hashTable[hashKey] == null)
            {
                hashTable[hashKey] = node;
                return;
            }
            else
            {
                if (NodeCount(value, hashKey) >= 5)
                {
                    int hashKey2 = HashCodeExtensionMethod.GetHashCode3(value);
                    if (hashTable[hashKey2] == null)
                    {
                        hashTable[hashKey2] = node;
                        return;
                    }
                    else
                    {
                        if (NodeCount(value, hashKey2) >= 5)
                        {
                            Console.WriteLine("Node is Full(key 1: {0} key2 : {1})", hashKey, hashKey2);
                            return;
                        }
                        node.hashNext       = hashTable[hashKey2];
                        hashTable[hashKey2] = node;
                        return;
                    }
                }
                node.hashNext      = hashTable[hashKey];
                hashTable[hashKey] = node;
            }
        }
Exemplo n.º 2
0
        public static string DeleteHashData(string value)
        {
            int hashKey = HashCodeExtensionMethod.GetHashCode2(value);

            if (hashTable[hashKey] == null)
            {
                hashKey = HashCodeExtensionMethod.GetHashCode3(value);
                if (hashTable[hashKey] == null)
                {
                    Console.WriteLine("{0} 값 삭제 실패", value);
                    return(null);
                }
            }

            Node deleteNode = null;

            if (hashTable[hashKey].value == value)
            {
                deleteNode         = hashTable[hashKey];
                hashTable[hashKey] = hashTable[hashKey].hashNext;
                Console.WriteLine("{0} 값 삭제 성공", value);
                return(value);
            }
            else
            {
                Node node = hashTable[hashKey];
                Node next = node.hashNext;
                while (node != null)
                {
                    if (node.value == value)
                    {
                        if (node.hashNext != null)
                        {
                            node.hashNext = next.hashNext;
                            deleteNode    = next;
                        }
                        Console.WriteLine("{0} 값 삭제 성공", value);
                        return(value);
                    }
                    node = next;
                    if (node != null)
                    {
                        next = node.hashNext;
                    }
                }
            }
            Console.WriteLine("{0} 값 삭제 실패", value);

            return(null);
        }