#pragma once #ifndef INTRUSIVE_LINKED_LIST_INL_H_ #error "Direct inclusion of this file is not allowed, include intrusive_linked_list.h" // For the sake of sane code completion. #include "intrusive_linked_list.h" #endif #include namespace NYT { //////////////////////////////////////////////////////////////////////////////// template TIntrusiveLinkedList::TIntrusiveLinkedList(TItemToNode itemToNode) : ItemToNode_(itemToNode) { } template TItem* TIntrusiveLinkedList::GetFront() const { return Front_; } template TItem* TIntrusiveLinkedList::GetBack() const { return Back_; } template int TIntrusiveLinkedList::GetSize() const { return Size_; } template void TIntrusiveLinkedList::PushBack(TItem* item) { auto* node = ItemToNode_(item); if (Back_) { ItemToNode_(Back_)->Next = item; } else { Front_ = item; } node->Next = nullptr; node->Prev = Back_; Back_ = item; ++Size_; } template void TIntrusiveLinkedList::PopBack() { Y_ASSERT(Back_); if (Front_ == Back_) { Front_ = Back_ = nullptr; } else { Back_ = ItemToNode_(Back_)->Prev; ItemToNode_(Back_)->Next = nullptr; } --Size_; } template void TIntrusiveLinkedList::PushFront(TItem* item) { auto* node = ItemToNode_(item); if (Front_) { ItemToNode_(Front_)->Prev = item; } else { Back_ = item; } node->Next = Front_; node->Prev = nullptr; Front_ = item; ++Size_; } template void TIntrusiveLinkedList::PopFront() { Y_ASSERT(Front_); if (Front_ == Back_) { Front_ = Back_ = nullptr; } else { Front_ = ItemToNode_(Front_)->Next; ItemToNode_(Front_)->Prev = nullptr; } --Size_; } template void TIntrusiveLinkedList::Remove(TItem* item) { YT_ASSERT(Front_); auto* node = ItemToNode_(item); if (node->Next) { ItemToNode_(node->Next)->Prev = node->Prev; } if (node->Prev) { ItemToNode_(node->Prev)->Next = node->Next; } if (Front_ == item) { Front_ = node->Next; } if (Back_ == item) { Back_ = node->Prev; } --Size_; } template void TIntrusiveLinkedList::Clear() { Front_ = Back_ = nullptr; Size_ = 0; } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT