/// <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); }
/// <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; } }
public MyHashtableNode(TKey key, TValue value, MyHashtableNode <TKey, TValue> next) { this.key = key; this.value = value; this.next = next; }