DoublyLinkedList.inl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace JsUtil
  7. {
  8. template<class T, class TAllocator>
  9. DoublyLinkedList<T, TAllocator>::DoublyLinkedList() : head(nullptr), tail(nullptr)
  10. {
  11. }
  12. template<class T, class TAllocator>
  13. T *DoublyLinkedList<T, TAllocator>::Head() const
  14. {
  15. return head;
  16. }
  17. template<class T, class TAllocator>
  18. T *DoublyLinkedList<T, TAllocator>::Tail() const
  19. {
  20. return tail;
  21. }
  22. template<class T, class TAllocator>
  23. bool DoublyLinkedList<T, TAllocator>::Contains(T *const element) const
  24. {
  25. return T::Contains(element, head);
  26. }
  27. template<class T, class TAllocator>
  28. bool DoublyLinkedList<T, TAllocator>::ContainsSubsequence(T *const first, T *const last) const
  29. {
  30. return T::ContainsSubsequence(first, last, head);
  31. }
  32. template<class T, class TAllocator>
  33. bool DoublyLinkedList<T, TAllocator>::IsEmpty()
  34. {
  35. return head == nullptr;
  36. }
  37. template<class T, class TAllocator>
  38. void DoublyLinkedList<T, TAllocator>::Clear()
  39. {
  40. tail = head = nullptr;
  41. }
  42. template<class T, class TAllocator>
  43. void DoublyLinkedList<T, TAllocator>::LinkToBeginning(T *const element)
  44. {
  45. T::LinkToBeginning(element, &head, &tail);
  46. }
  47. template<class T, class TAllocator>
  48. void DoublyLinkedList<T, TAllocator>::LinkToEnd(T *const element)
  49. {
  50. T::LinkToEnd(element, &head, &tail);
  51. }
  52. template<class T, class TAllocator>
  53. void DoublyLinkedList<T, TAllocator>::LinkBefore(T *const element, T *const nextElement)
  54. {
  55. T::LinkBefore(element, nextElement, &head, &tail);
  56. }
  57. template<class T, class TAllocator>
  58. void DoublyLinkedList<T, TAllocator>::LinkAfter(T *const element, T *const previousElement)
  59. {
  60. T::LinkAfter(element, previousElement, &head, &tail);
  61. }
  62. template<class T, class TAllocator>
  63. T *DoublyLinkedList<T, TAllocator>::UnlinkFromBeginning()
  64. {
  65. T *const element = head;
  66. if(element)
  67. T::UnlinkFromBeginning(element, &head, &tail);
  68. return element;
  69. }
  70. template<class T, class TAllocator>
  71. T *DoublyLinkedList<T, TAllocator>::UnlinkFromEnd()
  72. {
  73. T *const element = tail;
  74. if(element)
  75. T::UnlinkFromEnd(element, &head, &tail);
  76. return element;
  77. }
  78. template<class T, class TAllocator>
  79. void DoublyLinkedList<T, TAllocator>::UnlinkPartial(T *const element)
  80. {
  81. T::UnlinkPartial(element, &head, &tail);
  82. }
  83. template<class T, class TAllocator>
  84. void DoublyLinkedList<T, TAllocator>::Unlink(T *const element)
  85. {
  86. T::Unlink(element, &head, &tail);
  87. }
  88. template<class T, class TAllocator>
  89. void DoublyLinkedList<T, TAllocator>::MoveToBeginning(T *const element)
  90. {
  91. T::MoveToBeginning(element, &head, &tail);
  92. }
  93. template<class T, class TAllocator>
  94. void DoublyLinkedList<T, TAllocator>::UnlinkSubsequenceFromEnd(T *const first)
  95. {
  96. T::UnlinkSubsequenceFromEnd(first, &head, &tail);
  97. }
  98. template<class T, class TAllocator>
  99. void DoublyLinkedList<T, TAllocator>::UnlinkSubsequence(T *const first, T *const last)
  100. {
  101. T::UnlinkSubsequence(first, last, &head, &tail);
  102. }
  103. template<class T, class TAllocator>
  104. void DoublyLinkedList<T, TAllocator>::MoveSubsequenceToBeginning(T *const first, T *const last)
  105. {
  106. T::MoveSubsequenceToBeginning(first, last, &head, &tail);
  107. }
  108. }