HashSet.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. public void Add(T item)
  21. {
  22. // We don't care for the value in dictionary, Keys matter.
  23. _dict.Add(item, 0);
  24. }
  25. public void Clear()
  26. {
  27. _dict.Clear();
  28. }
  29. public bool Contains(T item)
  30. {
  31. return _dict.ContainsKey(item);
  32. }
  33. public void CopyTo(T[] array, int arrayIndex)
  34. {
  35. throw new NotImplementedException();
  36. }
  37. public bool Remove(T item)
  38. {
  39. return _dict.Remove(item);
  40. }
  41. public IEnumerator<T> GetEnumerator()
  42. {
  43. return _dict.Keys.GetEnumerator();
  44. }
  45. IEnumerator IEnumerable.GetEnumerator()
  46. {
  47. return _dict.Keys.GetEnumerator();
  48. }
  49. // Properties
  50. public int Count
  51. {
  52. get { return _dict.Keys.Count; }
  53. }
  54. public bool IsReadOnly
  55. {
  56. get { return false; }
  57. }
  58. }
  59. }
  60. #endif