Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Deque.cs
Go to the documentation of this file.
1
using
System.Diagnostics
;
2
3
namespace
System.Collections.Generic
;
4
5
[DebuggerDisplay(
"Count = {_size}"
)]
6
internal
sealed
class
Deque
<T>
7
{
8
private
T[]
_array
=
Array
.Empty<T>();
9
10
private
int
_head
;
11
12
private
int
_tail
;
13
14
private
int
_size
;
15
16
public
int
Count
=>
_size
;
17
18
public
bool
IsEmpty
=>
_size
== 0;
19
20
public
void
EnqueueTail
(T
item
)
21
{
22
if
(
_size
==
_array
.Length)
23
{
24
Grow
();
25
}
26
_array
[
_tail
] =
item
;
27
if
(++
_tail
==
_array
.Length)
28
{
29
_tail
= 0;
30
}
31
_size
++;
32
}
33
34
public
T
DequeueHead
()
35
{
36
T result =
_array
[
_head
];
37
_array
[
_head
] =
default
(T);
38
if
(++
_head
==
_array
.Length)
39
{
40
_head
= 0;
41
}
42
_size
--;
43
return
result;
44
}
45
46
public
T
PeekHead
()
47
{
48
return
_array
[
_head
];
49
}
50
51
public
T
DequeueTail
()
52
{
53
if
(--
_tail
== -1)
54
{
55
_tail
= _array.Length - 1;
56
}
57
T result =
_array
[
_tail
];
58
_array
[
_tail
] =
default
(T);
59
_size
--;
60
return
result;
61
}
62
63
public
IEnumerator<T>
GetEnumerator
()
64
{
65
int
pos =
_head
;
66
int
count
=
_size
;
67
while
(
count
-- > 0)
68
{
69
yield
return
_array
[pos];
70
pos = (pos + 1) %
_array
.Length;
71
}
72
}
73
74
private
void
Grow
()
75
{
76
int
num = (int)((
long
)_array.Length * 2
L
);
77
if
(num <
_array
.Length + 4)
78
{
79
num = _array.Length + 4;
80
}
81
T[]
array
=
new
T[num];
82
if
(
_head
== 0)
83
{
84
Array
.
Copy
(
_array
,
array
,
_size
);
85
}
86
else
87
{
88
Array
.
Copy
(
_array
,
_head
,
array
, 0,
_array
.Length -
_head
);
89
Array
.
Copy
(
_array
, 0,
array
,
_array
.Length -
_head
,
_tail
);
90
}
91
_array
=
array
;
92
_head
= 0;
93
_tail
=
_size
;
94
}
95
}
System.Array.Copy
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition
Array.cs:624
System.Array
Definition
Array.cs:16
System.Collections.Generic.Deque.GetEnumerator
IEnumerator< T > GetEnumerator()
Definition
Deque.cs:63
System.Collections.Generic.Deque._size
int _size
Definition
Deque.cs:14
System.Collections.Generic.Deque.EnqueueTail
void EnqueueTail(T item)
Definition
Deque.cs:20
System.Collections.Generic.Deque.Count
int Count
Definition
Deque.cs:16
System.Collections.Generic.Deque._tail
int _tail
Definition
Deque.cs:12
System.Collections.Generic.Deque.IsEmpty
bool IsEmpty
Definition
Deque.cs:18
System.Collections.Generic.Deque._array
T[] _array
Definition
Deque.cs:8
System.Collections.Generic.Deque.PeekHead
T PeekHead()
Definition
Deque.cs:46
System.Collections.Generic.Deque._head
int _head
Definition
Deque.cs:10
System.Collections.Generic.Deque.DequeueTail
T DequeueTail()
Definition
Deque.cs:51
System.Collections.Generic.Deque.DequeueHead
T DequeueHead()
Definition
Deque.cs:34
System.Collections.Generic.Deque.Grow
void Grow()
Definition
Deque.cs:74
System.Collections.Generic.Deque
Definition
Deque.cs:7
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Diagnostics
Definition
AggregationManager.cs:6
System.ExceptionArgument.item
@ item
System.ExceptionArgument.count
@ count
System.ExceptionArgument.array
@ array
System.ConsoleKey.L
@ L
source
System.Threading.Channels
System.Collections.Generic
Deque.cs
Generated by
1.10.0