HashSet.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #if WINDOWS_PHONE || XBOX
  2. //TODO: FIX
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. namespace FarseerPhysics.Common
  7. {
  8. public class HashSet<T> : ICollection<T>
  9. {
  10. private Dictionary<T, short> _dict;
  11. public HashSet(int capacity)
  12. {
  13. _dict = new Dictionary<T, short>(capacity);
  14. }
  15. public HashSet()
  16. {
  17. _dict = new Dictionary<T, short>();
  18. }
  19. // Methods
  20. #region ICollection<T> Members
  21. public void Add(T item)
  22. {
  23. // We don't care for the value in dictionary, Keys matter.
  24. _dict.Add(item, 0);
  25. }
  26. public void Clear()
  27. {
  28. _dict.Clear();
  29. }
  30. public bool Contains(T item)
  31. {
  32. return _dict.ContainsKey(item);
  33. }
  34. public void CopyTo(T[] array, int arrayIndex)
  35. {
  36. throw new NotImplementedException();
  37. }
  38. public bool Remove(T item)
  39. {
  40. return _dict.Remove(item);
  41. }
  42. public IEnumerator<T> GetEnumerator()
  43. {
  44. return _dict.Keys.GetEnumerator();
  45. }
  46. IEnumerator IEnumerable.GetEnumerator()
  47. {
  48. return _dict.Keys.GetEnumerator();
  49. }
  50. // Properties
  51. public int Count
  52. {
  53. get { return _dict.Keys.Count; }
  54. }
  55. public bool IsReadOnly
  56. {
  57. get { return false; }
  58. }
  59. #endregion
  60. }
  61. }
  62. #endif