public (HashNode <T> previous, HashNode <T> current) GetNodeByKey(string key) { int position = GetBucketByKey(key); HashNode <T> listNode = buckets[position]; HashNode <T> previous = null; while (null != listNode) { if (listNode.Key == key) { return(previous, listNode); } previous = listNode; listNode = listNode.Next; } return(null, null); }
public T GetNode(string key) { if (key != "-1") { ValidateKey(key); var(_, node) = GetNodeByKey(key); return(node.Value); } var valueNode = new HashNode <T> { Key = key, Next = null }; return(valueNode.Value); }
public void Add(string key, T item) { ValidateKey(key); var valueNode = new HashNode <T> { Key = key, Value = item, Next = null }; int position = GetBucketByKey(key); listNode = buckets[position]; if (null == listNode) { buckets[position] = valueNode; } else { while (null != listNode.Next) { listNode = listNode.Next; } listNode.Next = valueNode; } }