Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BitStack.cs
Go to the documentation of this file.
2
3namespace System.Text.Json;
4
5internal struct BitStack
6{
7 private int[] _array;
8
10
11 private int _currentDepth;
12
14
15 [MethodImpl(MethodImplOptions.AggressiveInlining)]
16 public void PushTrue()
17 {
18 if (_currentDepth < 64)
19 {
21 }
22 else
23 {
24 PushToArray(value: true);
25 }
27 }
28
29 [MethodImpl(MethodImplOptions.AggressiveInlining)]
30 public void PushFalse()
31 {
32 if (_currentDepth < 64)
33 {
35 }
36 else
37 {
38 PushToArray(value: false);
39 }
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 {
66 bool flag = false;
67 if (_currentDepth < 64)
68 {
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 {
98 }
99
100 public void ResetFirstBit()
101 {
104 }
105
106 [MethodImpl(MethodImplOptions.AggressiveInlining)]
107 private static int Div32Rem(int number, out int remainder)
108 {
109 uint result = (uint)number / 32u;
110 remainder = number & 0x1F;
111 return (int)result;
112 }
113}
static byte Max(byte val1, byte val2)
Definition Math.cs:738
void PushToArray(bool value)
Definition BitStack.cs:44
void DoubleArray(int minSize)
Definition BitStack.cs:88
static int Div32Rem(int number, out int remainder)
Definition BitStack.cs:107