2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

5 years ago
  1. //========= Copyright 2016-2020, HTC Corporation. All rights reserved. ===========
  2. namespace HTC.UnityPlugin.Utility
  3. {
  4. public class OrderedIndexedSet<T> : IndexedSet<T>
  5. {
  6. public OrderedIndexedSet() : base() { }
  7. public OrderedIndexedSet(int capacity) : base(capacity) { }
  8. public override void Insert(int index, T item)
  9. {
  10. m_Dictionary.Add(item, index);
  11. m_List.Insert(index, item);
  12. for (int i = index + 1, imax = m_List.Count; i < imax; ++i)
  13. {
  14. m_Dictionary[m_List[i]] = i;
  15. }
  16. }
  17. public override void RemoveAt(int index)
  18. {
  19. m_Dictionary.Remove(m_List[index]);
  20. m_List.RemoveAt(index);
  21. for (int i = index, imax = m_List.Count; i < imax; ++i)
  22. {
  23. m_Dictionary[m_List[i]] = i;
  24. }
  25. }
  26. public T GetFirst()
  27. {
  28. return m_List[0];
  29. }
  30. public bool TryGetFirst(out T item)
  31. {
  32. if (m_List.Count == 0)
  33. {
  34. item = default(T);
  35. return false;
  36. }
  37. else
  38. {
  39. item = GetFirst();
  40. return true;
  41. }
  42. }
  43. public T GetLast()
  44. {
  45. return m_List[m_List.Count - 1];
  46. }
  47. public bool TryGetLast(out T item)
  48. {
  49. if (m_List.Count == 0)
  50. {
  51. item = default(T);
  52. return false;
  53. }
  54. else
  55. {
  56. item = GetLast();
  57. return true;
  58. }
  59. }
  60. }
  61. }