Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
QueuedMap.cs
Go to the documentation of this file.
4
6
7[DebuggerDisplay("Count = {Count}")]
9internal sealed class QueuedMap<TKey, TValue>
10{
11 private sealed class ArrayBasedLinkedQueue<T>
12 {
14
15 private int _headIndex = -1;
16
17 private int _tailIndex = -1;
18
19 private int _freeIndex = -1;
20
21 internal bool IsEmpty => _headIndex == -1;
22
24 {
26 }
27
32
33 internal int Enqueue(T item)
34 {
35 int num;
36 if (_freeIndex != -1)
37 {
38 num = _freeIndex;
40 _storage[num] = new KeyValuePair<int, T>(-1, item);
41 }
42 else
43 {
44 num = _storage.Count;
46 }
47 if (_headIndex == -1)
48 {
49 _headIndex = num;
50 }
51 else
52 {
54 }
55 _tailIndex = num;
56 return num;
57 }
58
59 internal bool TryDequeue([MaybeNullWhen(false)] out T item)
60 {
61 if (_headIndex == -1)
62 {
63 item = default(T);
64 return false;
65 }
66 item = _storage[_headIndex].Value;
67 int key = _storage[_headIndex].Key;
71 if (_headIndex == -1)
72 {
73 _tailIndex = -1;
74 }
75 return true;
76 }
77
78 internal void Replace(int index, T item)
79 {
81 }
82 }
83
85
87
88 internal int Count => _mapKeyToIndex.Count;
89
95
101
102 internal void Push(TKey key, TValue value)
103 {
105 {
107 return;
108 }
111 }
112
114 {
115 bool flag = _queue.TryDequeue(out item);
116 if (flag)
117 {
119 }
120 return flag;
121 }
122
123 internal int PopRange(KeyValuePair<TKey, TValue>[] items, int arrayOffset, int count)
124 {
125 int i = 0;
126 int num = arrayOffset;
127 for (; i < count; i++)
128 {
129 if (!TryPop(out var item))
130 {
131 break;
132 }
133 items[num] = item;
134 num++;
135 }
136 return i;
137 }
138}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
readonly Dictionary< TKey, int > _mapKeyToIndex
Definition QueuedMap.cs:86
readonly ArrayBasedLinkedQueue< KeyValuePair< TKey, TValue > > _queue
Definition QueuedMap.cs:84
bool TryPop(out KeyValuePair< TKey, TValue > item)
Definition QueuedMap.cs:113
int PopRange(KeyValuePair< TKey, TValue >[] items, int arrayOffset, int count)
Definition QueuedMap.cs:123