예제 #1
0
        public void Insert(int key, int value)
        {
            var pair      = new HashTableDataItem(key, value);
            var hashIndex = this.hashCode(key);

            while (this.Table[hashIndex] != null && this.Table[hashIndex].Key != -1)
            {
                hashIndex++;
                hashIndex %= this.Table.Length;
            }
            this.Table[hashIndex] = pair;
        }
예제 #2
0
        public bool Delete(HashTableDataItem item)
        {
            var hashIndex  = hashCode(item.Key);
            var wasDeleted = false;

            while (this.Table[hashIndex] != null)
            {
                if (this.Table[hashIndex].Key == item.Key)
                {
                    this.Table[hashIndex] = null;
                    wasDeleted            = true;
                    break;
                }
                hashIndex++;
                hashIndex %= this.Table.Length;
            }
            return(wasDeleted);
        }