Windows NT 4.0 source code leak
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.

139 lines
3.2 KiB

4 years ago
  1. /* --------------------------------------------------------------------
  2. Microsoft OS/2 LAN Manager
  3. Copyright(c) Microsoft Corp., 1990
  4. RPC Runtime - Written by Steven Zeck
  5. This file contains the class implementation of linked list.
  6. -------------------------------------------------------------------- */
  7. #include <precomp.hxx>
  8. // ** LinkItem class implementations ** //
  9. void LinkItem::Remove ( // delete an LinkList from a list *^
  10. LinkList& pLLHead // pointer to Head to Remove
  11. // Removal of a Linked List item is easy with doubly linked lists.
  12. )/*-----------------------------------------------------------------------*/
  13. {
  14. ASSERT(this && (void *)&pLLHead);
  15. if (!pLIPrev)
  16. pLLHead.pLIHead = pLINext; // LI at head of list
  17. else
  18. pLIPrev->pLINext = pLINext;
  19. if (!pLINext)
  20. pLLHead.pLITail = pLIPrev; // LI at tail of list
  21. else
  22. pLINext->pLIPrev = pLIPrev;
  23. pLLHead.Assert();
  24. }
  25. // ** LinkList class implementations ** //
  26. void LinkList::Add ( // Add a new node at the head of a list
  27. LinkItem *pLInew // allocated Item to Add
  28. // Add the newly allocated item to the front of the linked list.
  29. )/*-----------------------------------------------------------------------*/
  30. {
  31. if ( this == 0 )
  32. {
  33. return;
  34. }
  35. this->Assert();
  36. pLInew->pLINext = pLIHead; // old head is now Next
  37. pLInew->pLIPrev = Nil;
  38. pLIHead = pLInew; // new is now Head
  39. if (!pLITail) // handle empty list
  40. pLITail = pLInew;
  41. else {
  42. ASSERT(pLInew->pLINext);
  43. pLInew->pLINext->pLIPrev = pLInew; // old head points back to new
  44. }
  45. }
  46. void LinkList::Append ( // Append a new node at the end of a list
  47. LinkItem *pLInew // allocated Item to Add
  48. )/*-----------------------------------------------------------------------*/
  49. {
  50. if ( this == 0 )
  51. {
  52. return;
  53. }
  54. this->Assert();
  55. // empty lists are just like Add
  56. if (!pLITail) {
  57. this->Add(pLInew);
  58. return;
  59. }
  60. pLInew->pLINext = Nil; // new points back to old tail
  61. pLInew->pLIPrev = pLITail;
  62. pLITail->pLINext = pLInew; // old tail points forward to new
  63. pLITail = pLInew; // tail is now new
  64. }
  65. #ifdef LDEBUG
  66. void LinkList::Assert( // check consistency of the class
  67. // First check the boundary conditions for the linked list root,
  68. // then walk the list checking the backward/forward pointers. Finial
  69. // invoke the virtural function to check the contents of each item.
  70. )/*-----------------------------------------------------------------------*/
  71. {
  72. if (!pLIHead) // empty list
  73. ASSERT(!pLITail);
  74. if (!pLITail)
  75. ASSERT(!pLIHead);
  76. for (LinkItem *pLI = pLIHead; pLI; pLI = pLI->pLINext) {
  77. // tail should point to end of list
  78. if (pLI->pLINext == Nil)
  79. ASSERT(pLITail == pLI);
  80. // first in chain, should have NIL back pointer
  81. if (pLI->pLIPrev == Nil)
  82. ASSERT(pLIHead == pLI);
  83. // check back pointer of next Item points here
  84. if (pLI->pLINext)
  85. ASSERT(pLI->pLINext->pLIPrev == pLI);
  86. pLI->Assert(); // check any derived data
  87. }
  88. }
  89. void LinkItem::Assert(
  90. )/*-----------------------------------------------------------------------*/
  91. {
  92. return; // base class has no additional members, so return
  93. }
  94. #endif