#include "compact_queue.h" namespace NYT { //////////////////////////////////////////////////////////////////////////////// template void TCompactQueue::Push(T value) { if (Size_ == Queue_.size()) { auto oldSize = Queue_.size(); Queue_.resize(2 * oldSize); if (FrontIndex_ + Size_ > oldSize) { std::move( Queue_.begin(), Queue_.begin() + FrontIndex_, Queue_.begin() + Size_); } } auto index = FrontIndex_ + Size_; if (index >= Queue_.size()) { index -= Queue_.size(); } Queue_[index] = std::move(value); ++Size_; } template T TCompactQueue::Pop() { YT_VERIFY(!Empty()); auto value = std::move(Queue_[FrontIndex_]); ++FrontIndex_; if (FrontIndex_ >= Queue_.size()) { FrontIndex_ -= Queue_.size(); } --Size_; return value; } template const T& TCompactQueue::Front() const { return Queue_[FrontIndex_]; } template size_t TCompactQueue::Size() const { return Size_; } template size_t TCompactQueue::Capacity() const { return Queue_.capacity(); } template bool TCompactQueue::Empty() const { return Size_ == 0; } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT