using System.Collections.Generic; using MongoDB.Bson.IO; namespace ET { public class HashLinkedList { private Dictionary> dict = new Dictionary>(); private LinkedList linkedList = new LinkedList(); public K this[T t] { get { if (this.dict.ContainsKey(t)) { return this.dict[t].Value; } return default; } } public int Count { get { return this.dict.Count; } } public K First { get { var first = this.linkedList.First; if (first == null) { return default; } return first.Value; } } public K Last { get { var last = this.linkedList.Last; if (last == null) { return default; } return last.Value; } } public bool AddLast(T t, K k) { if (this.dict.ContainsKey(t)) { return false; } LinkedListNode node = this.linkedList.AddLast(k); this.dict.Add(t, node); return true; } public bool AddFirst(T t, K k) { if (this.dict.ContainsKey(t)) { return false; } LinkedListNode node = this.linkedList.AddFirst(k); this.dict.Add(t, node); return true; } public K Remove(T t) { LinkedListNode node; if (this.dict.TryGetValue(t, out node)) { K value = node.Value; this.dict.Remove(t); this.linkedList.Remove(node); return value; } return default; } public bool ContainsKey(T t) { return this.dict.ContainsKey(t); } public LinkedList.Enumerator GetEnumerator() { return this.linkedList.GetEnumerator(); } public void Clear() { this.dict.Clear(); this.linkedList.Clear(); } } }