Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SparseArrayBuilder.cs
Go to the documentation of this file.
1using System.Linq;
2
4
5internal struct SparseArrayBuilder<T>
6{
8
10
11 private int _reservedCount;
12
13 public int Count => checked(_builder.Count + _reservedCount);
14
16
18 {
19 this = default(SparseArrayBuilder<T>);
21 }
22
23 public void AddRange(IEnumerable<T> items)
24 {
25 _builder.AddRange(items);
26 }
27
28 public void CopyTo(T[] array, int arrayIndex, int count)
29 {
30 int num = 0;
32 for (int i = 0; i < _markers.Count; i++)
33 {
35 int num2 = Math.Min(marker.Index - num, count);
36 if (num2 > 0)
37 {
38 position = _builder.CopyTo(position, array, arrayIndex, num2);
40 num += num2;
41 count -= num2;
42 }
43 if (count == 0)
44 {
45 return;
46 }
47 int num3 = Math.Min(marker.Count, count);
49 num += num3;
50 count -= num3;
51 }
52 if (count > 0)
53 {
54 _builder.CopyTo(position, array, arrayIndex, count);
55 }
56 }
57
58 public void Reserve(int count)
59 {
60 _markers.Add(new Marker(count, Count));
62 {
64 }
65 }
66
67 public bool ReserveOrAdd(IEnumerable<T> items)
68 {
69 if (items.TryGetNonEnumeratedCount(out var count))
70 {
71 if (count > 0)
72 {
74 return true;
75 }
76 }
77 else
78 {
79 AddRange(items);
80 }
81 return false;
82 }
83
84 public T[] ToArray()
85 {
86 if (_markers.Count == 0)
87 {
88 return _builder.ToArray();
89 }
90 T[] array = new T[Count];
91 CopyTo(array, 0, array.Length);
92 return array;
93 }
94}
static byte Min(byte val1, byte val2)
Definition Math.cs:912
System.Collections.Generic.ArrayBuilder< Marker > _markers
void CopyTo(T[] array, int arrayIndex, int count)
System.Collections.Generic.ArrayBuilder< Marker > Markers