Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BitStack.cs
Go to the documentation of this file.
1
using
System.Runtime.CompilerServices
;
2
3
namespace
System.Text.Json
;
4
5
internal
struct
BitStack
6
{
7
private
int
[]
_array
;
8
9
private
ulong
_allocationFreeContainer
;
10
11
private
int
_currentDepth
;
12
13
public
int
CurrentDepth
=>
_currentDepth
;
14
15
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
16
public
void
PushTrue
()
17
{
18
if
(
_currentDepth
< 64)
19
{
20
_allocationFreeContainer
= (
_allocationFreeContainer
<< 1) | 1;
21
}
22
else
23
{
24
PushToArray
(
value
:
true
);
25
}
26
_currentDepth
++;
27
}
28
29
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
30
public
void
PushFalse
()
31
{
32
if
(
_currentDepth
< 64)
33
{
34
_allocationFreeContainer
<<= 1;
35
}
36
else
37
{
38
PushToArray
(
value
:
false
);
39
}
40
_currentDepth
++;
41
}
42
43
[MethodImpl(
MethodImplOptions
.NoInlining)]
44
private
void
PushToArray
(
bool
value
)
45
{
46
if
(
_array
==
null
)
47
{
48
_array
=
new
int
[2];
49
}
50
int
number
=
_currentDepth
- 64;
51
int
remainder
;
52
int
num =
Div32Rem
(
number
,
out
remainder
);
53
if
(num >=
_array
.Length)
54
{
55
DoubleArray
(num);
56
}
57
int
num2
=
_array
[num];
58
num2
= ((!
value
) ? (
num2
& ~(1 <<
remainder
)) : (
num2
| (1 <<
remainder
)));
59
_array
[num] =
num2
;
60
}
61
62
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
63
public
bool
Pop
()
64
{
65
_currentDepth
--;
66
bool
flag =
false
;
67
if
(
_currentDepth
< 64)
68
{
69
_allocationFreeContainer
>>= 1;
70
return
(
_allocationFreeContainer
& 1) != 0;
71
}
72
if
(
_currentDepth
== 64)
73
{
74
return
(
_allocationFreeContainer
& 1) != 0;
75
}
76
return
PopFromArray
();
77
}
78
79
[MethodImpl(
MethodImplOptions
.NoInlining)]
80
private
bool
PopFromArray
()
81
{
82
int
number
=
_currentDepth
- 64 - 1;
83
int
remainder
;
84
int
num =
Div32Rem
(
number
,
out
remainder
);
85
return
(
_array
[num] & (1 <<
remainder
)) != 0;
86
}
87
88
private
void
DoubleArray
(
int
minSize
)
89
{
90
int
newSize
=
Math
.
Max
(
minSize
+ 1,
_array
.Length * 2);
91
Array
.Resize(
ref
_array
,
newSize
);
92
}
93
94
public
void
SetFirstBit
()
95
{
96
_currentDepth
++;
97
_allocationFreeContainer
= 1
uL
;
98
}
99
100
public
void
ResetFirstBit
()
101
{
102
_currentDepth
++;
103
_allocationFreeContainer
= 0
uL
;
104
}
105
106
[MethodImpl(
MethodImplOptions
.AggressiveInlining)]
107
private
static
int
Div32Rem
(
int
number
,
out
int
remainder
)
108
{
109
uint result = (uint)
number
/ 32
u
;
110
remainder
=
number
& 0x1F;
111
return
(
int
)result;
112
}
113
}
System.Array
Definition
Array.cs:16
System.Math.Max
static byte Max(byte val1, byte val2)
Definition
Math.cs:738
System.Math
Definition
Math.cs:13
System.Runtime.CompilerServices.MethodImplOptions
MethodImplOptions
Definition
MethodImplOptions.cs:5
System.Runtime.CompilerServices
Definition
NullablePublicOnlyAttribute.cs:3
System.Text.Json.ConverterStrategy.Dictionary
@ Dictionary
System.Text.Json
Definition
JsonArray.cs:7
System.ExceptionArgument.value
@ value
System.ExceptionArgument.newSize
@ newSize
System.Text.Json.BitStack.CurrentDepth
int CurrentDepth
Definition
BitStack.cs:13
System.Text.Json.BitStack.PushToArray
void PushToArray(bool value)
Definition
BitStack.cs:44
System.Text.Json.BitStack.ResetFirstBit
void ResetFirstBit()
Definition
BitStack.cs:100
System.Text.Json.BitStack._allocationFreeContainer
ulong _allocationFreeContainer
Definition
BitStack.cs:9
System.Text.Json.BitStack._array
int[] _array
Definition
BitStack.cs:7
System.Text.Json.BitStack.DoubleArray
void DoubleArray(int minSize)
Definition
BitStack.cs:88
System.Text.Json.BitStack.Div32Rem
static int Div32Rem(int number, out int remainder)
Definition
BitStack.cs:107
System.Text.Json.BitStack.SetFirstBit
void SetFirstBit()
Definition
BitStack.cs:94
System.Text.Json.BitStack.PushFalse
void PushFalse()
Definition
BitStack.cs:30
System.Text.Json.BitStack.PushTrue
void PushTrue()
Definition
BitStack.cs:16
System.Text.Json.BitStack.Pop
bool Pop()
Definition
BitStack.cs:63
System.Text.Json.BitStack.PopFromArray
bool PopFromArray()
Definition
BitStack.cs:80
System.Text.Json.BitStack._currentDepth
int _currentDepth
Definition
BitStack.cs:11
System.Text.Json.BitStack
Definition
BitStack.cs:6
source
System.Text.Json
System.Text.Json
BitStack.cs
Generated by
1.10.0