コード例 #1
0
ファイル: MyHashtable.cs プロジェクト: nearyc/Test
        /// <summary>
        /// 根据Value寻找是否存在等值node
        /// </summary>
        /// <param name="node"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private bool Search(MyHashtableNode <TKey, TValue> node, TValue value)
        {
            var nodePointer = node;

            while (nodePointer != null)
            {
                if (nodePointer.value.Equals(value))
                {
                    return(true);
                }
                else
                {
                    nodePointer = nodePointer.next;
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: MyHashtable.cs プロジェクト: nearyc/Test
        /// <summary>
        /// 添加键值对
        /// </summary>
        /// <param name="k"></param>
        /// <param name="v"></param>
        public void Add(TKey k, TValue v)
        {
            var newNode = new MyHashtableNode <TKey, TValue>(k, v);

            newNode.SethashCode(_hashFunction);
            if (_heads[newNode.hashCode.Value] == null)
            {
                _heads[newNode.hashCode.Value] = newNode;
            }
            else
            {
                var nodePointer = _heads[newNode.hashCode.Value];
                while (nodePointer.next != null)
                {
                    nodePointer = nodePointer.next;
                }
                nodePointer.next = newNode;
            }
        }
コード例 #3
0
 public MyHashtableNode(TKey key, TValue value, MyHashtableNode <TKey, TValue> next)
 {
     this.key   = key;
     this.value = value;
     this.next  = next;
 }