Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MetadataAggregator.cs
Go to the documentation of this file.
3
5
6public sealed class MetadataAggregator
7{
8 internal struct RowCounts : IComparable<RowCounts>
9 {
10 public int AggregateInserts;
11
12 public int Updates;
13
15 {
16 return AggregateInserts - other.AggregateInserts;
17 }
18
19 public override string ToString()
20 {
21 return $"+0x{AggregateInserts:x} ~0x{Updates:x}";
22 }
23 }
24
26
28
33
38
40 {
41 if (baseTableRowCounts == null)
42 {
43 if (baseReader == null)
44 {
45 throw new ArgumentNullException("baseReader");
46 }
47 if (baseReader.GetTableRowCount(TableIndex.EncMap) != 0)
48 {
50 }
52 }
53 else
54 {
56 {
58 }
59 if (baseHeapSizes == null)
60 {
61 throw new ArgumentNullException("baseHeapSizes");
62 }
64 {
66 }
67 }
68 if (deltaReaders == null || deltaReaders.Count == 0)
69 {
70 throw new ArgumentException(System.SR.ExpectedNonEmptyList, "deltaReaders");
71 }
72 for (int i = 0; i < deltaReaders.Count; i++)
73 {
74 if (deltaReaders[i].GetTableRowCount(TableIndex.EncMap) == 0 || !deltaReaders[i].IsMinimalDelta)
75 {
76 throw new ArgumentException(System.SR.ReadersMustBeDeltaReaders, "deltaReaders");
77 }
78 }
81 }
82
84 {
85 _rowCounts = ToImmutable(rowCounts);
86 _heapSizes = ToImmutable(heapSizes);
87 }
88
90 {
91 int[] array = new int[MetadataTokens.TableCount];
92 int[] array2 = new int[MetadataTokens.HeapCount];
93 for (int i = 0; i < array.Length; i++)
94 {
95 array[i] = baseReader.GetTableRowCount((TableIndex)i);
96 }
97 for (int j = 0; j < array2.Length; j++)
98 {
99 array2[j] = baseReader.GetHeapSize((HeapIndex)j);
100 }
103 }
104
106 {
107 int num = 1 + deltaReaders.Count;
108 int[] array = new int[num];
109 int[] array2 = new int[num];
110 int[] array3 = new int[num];
111 int[] array4 = new int[num];
112 array[0] = baseSizes[0];
113 array2[0] = baseSizes[1];
114 array3[0] = baseSizes[2];
115 array4[0] = baseSizes[3] / 16;
116 for (int i = 0; i < deltaReaders.Count; i++)
117 {
118 array[i + 1] = array[i] + deltaReaders[i].GetHeapSize(HeapIndex.UserString);
119 array2[i + 1] = array2[i] + deltaReaders[i].GetHeapSize(HeapIndex.String);
120 array3[i + 1] = array3[i] + deltaReaders[i].GetHeapSize(HeapIndex.Blob);
121 array4[i + 1] = array4[i] + deltaReaders[i].GetHeapSize(HeapIndex.Guid) / 16;
122 }
123 return ImmutableArray.Create(array.ToImmutableArray(), array2.ToImmutableArray(), array3.ToImmutableArray(), array4.ToImmutableArray());
124 }
125
135
137 {
139 for (int i = 0; i < array.Length; i++)
140 {
141 array2[i] = array[i].ToImmutableArray();
142 }
143 return array2.ToImmutableArray();
144 }
145
147 {
149 for (int i = 0; i < array.Length; i++)
150 {
151 array[i] = new RowCounts[generations];
153 }
154 return array;
155 }
156
158 {
159 foreach (RowCounts[] array in rowCounts)
160 {
161 array[generation].AggregateInserts = array[generation - 1].AggregateInserts;
162 }
163 int numberOfRows = encMapTable.NumberOfRows;
164 for (int j = 1; j <= numberOfRows; j++)
165 {
166 uint token = encMapTable.GetToken(j);
167 int num = (int)(token & 0xFFFFFF);
168 RowCounts[] array2 = rowCounts[token >> 24];
169 if (num > array2[generation].AggregateInserts)
170 {
171 if (num != array2[generation].AggregateInserts + 1)
172 {
174 }
175 array2[generation].AggregateInserts = num;
176 }
177 else
178 {
179 array2[generation].Updates++;
180 }
181 }
182 }
183
185 {
186 if (handle.IsVirtual)
187 {
188 throw new NotSupportedException();
189 }
190 if (handle.IsHeapHandle)
191 {
192 int offset = handle.Offset;
195 int num = ((handle.Type == 114) ? (offset - 1) : offset);
196 generation = array.BinarySearch(num);
197 if (generation >= 0)
198 {
199 do
200 {
201 generation++;
202 }
203 while (generation < array.Length && array[generation] == num);
204 }
205 else
206 {
208 }
209 if (generation >= array.Length)
210 {
212 }
213 int value = ((handle.Type == 114 || generation == 0) ? offset : (offset - array[generation - 1]));
214 return new Handle((byte)handle.Type, value);
215 }
216 int rowId = handle.RowId;
218 generation = array2.BinarySearch(new RowCounts
219 {
220 AggregateInserts = rowId
221 });
222 if (generation >= 0)
223 {
224 while (generation > 0 && array2[generation - 1].AggregateInserts == rowId)
225 {
226 generation--;
227 }
228 }
229 else
230 {
232 if (generation >= array2.Length)
233 {
235 }
236 }
237 int value2 = ((generation == 0) ? rowId : (rowId - array2[generation - 1].AggregateInserts + array2[generation].Updates));
238 return new Handle((byte)handle.Type, value2);
239 }
240}
MetadataAggregator(RowCounts[][] rowCounts, int[][] heapSizes)
Handle GetGenerationHandle(Handle handle, out int generation)
MetadataAggregator(IReadOnlyList< int >? baseTableRowCounts, IReadOnlyList< int >? baseHeapSizes, IReadOnlyList< MetadataReader >? deltaReaders)
MetadataAggregator(MetadataReader baseReader, IReadOnlyList< MetadataReader > deltaReaders)
static void CalculateBaseCounts(MetadataReader baseReader, out IReadOnlyList< int > baseTableRowCounts, out IReadOnlyList< int > baseHeapSizes)
static ImmutableArray< ImmutableArray< T > > ToImmutable< T >(T[][] array)
static RowCounts[][] GetBaseRowCounts(IReadOnlyList< int > baseRowCounts, int generations)
static ImmutableArray< ImmutableArray< RowCounts > > CalculateRowCounts(IReadOnlyList< int > baseRowCounts, IReadOnlyList< MetadataReader > deltaReaders)
static void CalculateDeltaRowCountsForGeneration(RowCounts[][] rowCounts, int generation, ref EnCMapTableReader encMapTable)
readonly ImmutableArray< ImmutableArray< RowCounts > > _rowCounts
readonly ImmutableArray< ImmutableArray< int > > _heapSizes
static ImmutableArray< ImmutableArray< int > > CalculateHeapSizes(IReadOnlyList< int > baseSizes, IReadOnlyList< MetadataReader > deltaReaders)
MetadataAggregator(MetadataReader baseReader, IReadOnlyList< int > baseTableRowCounts, IReadOnlyList< int > baseHeapSizes, IReadOnlyList< MetadataReader > deltaReaders)
static bool TryGetHeapIndex(HandleKind type, out HeapIndex index)
static string ReadersMustBeDeltaReaders
Definition SR.cs:208
static string ExpectedListOfSize
Definition SR.cs:198
static string BaseReaderMustBeFullMetadataReader
Definition SR.cs:192
static string EnCMapNotSorted
Definition SR.cs:118
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string ExpectedNonEmptyList
Definition SR.cs:202
static string HandleBelongsToFutureGeneration
Definition SR.cs:140
Definition SR.cs:7