aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/containers/intrusive_linked_list.h
blob: 0c19a9ca39d3757dab9f4c172719d820d51e117d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

template <class TItem>
struct TIntrusiveLinkedListNode
{
    TItem* Next = nullptr;
    TItem* Prev = nullptr;
};

template <class TItem, class TItemToNode>
class TIntrusiveLinkedList
{
public:
    explicit TIntrusiveLinkedList(TItemToNode itemToNode = TItemToNode());

    TItem* GetFront() const;
    TItem* GetBack() const;

    int GetSize() const;

    void PushFront(TItem* item);
    void PopFront();

    void PushBack(TItem* item);
    void PopBack();

    void Remove(TItem* item);

    void Clear();

private:
    const TItemToNode ItemToNode_;

    TItem* Front_ = nullptr;
    TItem* Back_ = nullptr;
    int Size_ = 0;

};

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT

#define INTRUSIVE_LINKED_LIST_INL_H_
#include "intrusive_linked_list-inl.h"
#undef INTRUSIVE_LINKED_LIST_INL_H_