QueueDictionary.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.Collections.Generic;
  2. namespace Model
  3. {
  4. public class QueueDictionary<T, K>
  5. {
  6. private readonly List<T> list = new List<T>();
  7. private readonly Dictionary<T, K> dictionary = new Dictionary<T, K>();
  8. public void Enqueue(T t, K k)
  9. {
  10. this.list.Add(t);
  11. this.dictionary.Add(t, k);
  12. }
  13. public void Dequeue()
  14. {
  15. if (this.list.Count == 0)
  16. {
  17. return;
  18. }
  19. T t = this.list[0];
  20. this.list.RemoveAt(0);
  21. this.dictionary.Remove(t);
  22. }
  23. public void Remove(T t)
  24. {
  25. this.list.Remove(t);
  26. this.dictionary.Remove(t);
  27. }
  28. public bool ContainsKey(T t)
  29. {
  30. return this.dictionary.ContainsKey(t);
  31. }
  32. public int Count
  33. {
  34. get
  35. {
  36. return this.list.Count;
  37. }
  38. }
  39. public T FirstKey
  40. {
  41. get
  42. {
  43. return this.list[0];
  44. }
  45. }
  46. public K FirstValue
  47. {
  48. get
  49. {
  50. T t = this.list[0];
  51. return this[t];
  52. }
  53. }
  54. public K this[T t]
  55. {
  56. get
  57. {
  58. return this.dictionary[t];
  59. }
  60. }
  61. public void Clear()
  62. {
  63. this.list.Clear();
  64. this.dictionary.Clear();
  65. }
  66. }
  67. }