-
Notifications
You must be signed in to change notification settings - Fork 3
/
LinksConstants.cs
295 lines (265 loc) · 12 KB
/
LinksConstants.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
using System.Runtime.CompilerServices;
using Platform.Ranges;
using Platform.Reflection;
using Platform.Converters;
using Platform.Numbers;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
namespace Platform.Data
{
/// <summary>
/// <para>
/// Represents the links constants.
/// </para>
/// <para></para>
/// </summary>
/// <seealso cref="LinksConstantsBase"/>
public class LinksConstants<TLinkAddress> : LinksConstantsBase
{
private static readonly TLinkAddress _one = Arithmetic<TLinkAddress>.Increment(default);
private static readonly UncheckedConverter<ulong, TLinkAddress> _uInt64ToAddressConverter = UncheckedConverter<ulong, TLinkAddress>.Default;
#region Link parts
/// <summary>Возвращает индекс части, которая отвечает за индекс (адрес, идентификатор) самой связи.</summary>
public int IndexPart
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
/// <summary>Возвращает индекс части, которая отвечает за ссылку на связь-начало (первая часть-значение).</summary>
public int SourcePart
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
/// <summary>Возвращает индекс части, которая отвечает за ссылку на связь-конец (последняя часть-значение).</summary>
public int TargetPart
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
#endregion
#region Flow control
/// <summary>Возвращает значение, обозначающее продолжение прохода по связям.</summary>
/// <remarks>Используется в функции обработчике, который передаётся в функцию Each.</remarks>
public TLinkAddress Continue
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
/// <summary>Возвращает значение, обозначающее пропуск в проходе по связям.</summary>
public TLinkAddress Skip
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
/// <summary>Возвращает значение, обозначающее остановку прохода по связям.</summary>
/// <remarks>Используется в функции обработчике, который передаётся в функцию Each.</remarks>
public TLinkAddress Break
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
#endregion
#region Special symbols
/// <summary>Возвращает значение, обозначающее отсутствие связи.</summary>
public TLinkAddress Null
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
/// <summary>Возвращает значение, обозначающее любую связь.</summary>
/// <remarks>Возможно нужно зарезервировать отдельное значение, тогда можно будет создавать все варианты последовательностей в функции Create.</remarks>
public TLinkAddress Any
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
/// <summary>Возвращает значение, обозначающее связь-ссылку на саму связь.</summary>
public TLinkAddress Itself
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
#endregion
#region References
/// <summary>Возвращает диапазон возможных индексов для внутренних связей (внутренних ссылок).</summary>
public Range<TLinkAddress> InternalReferencesRange
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
/// <summary>Возвращает диапазон возможных индексов для внешних связей (внешних ссылок).</summary>
public Range<TLinkAddress>? ExternalReferencesRange
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
#endregion
/// <summary>
/// <para>
/// Initializes a new <see cref="LinksConstants"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="targetPart">
/// <para>A target part.</para>
/// <para></para>
/// </param>
/// <param name="possibleInternalReferencesRange">
/// <para>A possible internal references range.</para>
/// <para></para>
/// </param>
/// <param name="possibleExternalReferencesRange">
/// <para>A possible external references range.</para>
/// <para></para>
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LinksConstants(int targetPart, Range<TLinkAddress> possibleInternalReferencesRange, Range<TLinkAddress>? possibleExternalReferencesRange)
{
IndexPart = 0;
SourcePart = 1;
TargetPart = targetPart;
Null = default;
Break = default;
var currentInternalReferenceIndex = possibleInternalReferencesRange.Maximum;
Continue = currentInternalReferenceIndex;
Skip = Arithmetic.Decrement(ref currentInternalReferenceIndex);
Any = Arithmetic.Decrement(ref currentInternalReferenceIndex);
Itself = Arithmetic.Decrement(ref currentInternalReferenceIndex);
Arithmetic.Decrement(ref currentInternalReferenceIndex);
InternalReferencesRange = (possibleInternalReferencesRange.Minimum, currentInternalReferenceIndex);
ExternalReferencesRange = possibleExternalReferencesRange;
}
/// <summary>
/// <para>
/// Initializes a new <see cref="LinksConstants"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="targetPart">
/// <para>A target part.</para>
/// <para></para>
/// </param>
/// <param name="enableExternalReferencesSupport">
/// <para>A enable external references support.</para>
/// <para></para>
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LinksConstants(int targetPart, bool enableExternalReferencesSupport) : this(targetPart, GetDefaultInternalReferencesRange(enableExternalReferencesSupport), GetDefaultExternalReferencesRange(enableExternalReferencesSupport)) { }
/// <summary>
/// <para>
/// Initializes a new <see cref="LinksConstants"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="possibleInternalReferencesRange">
/// <para>A possible internal references range.</para>
/// <para></para>
/// </param>
/// <param name="possibleExternalReferencesRange">
/// <para>A possible external references range.</para>
/// <para></para>
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LinksConstants(Range<TLinkAddress> possibleInternalReferencesRange, Range<TLinkAddress>? possibleExternalReferencesRange) : this(DefaultTargetPart, possibleInternalReferencesRange, possibleExternalReferencesRange) { }
/// <summary>
/// <para>
/// Initializes a new <see cref="LinksConstants"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="enableExternalReferencesSupport">
/// <para>A enable external references support.</para>
/// <para></para>
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LinksConstants(bool enableExternalReferencesSupport) : this(GetDefaultInternalReferencesRange(enableExternalReferencesSupport), GetDefaultExternalReferencesRange(enableExternalReferencesSupport)) { }
/// <summary>
/// <para>
/// Initializes a new <see cref="LinksConstants"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="targetPart">
/// <para>A target part.</para>
/// <para></para>
/// </param>
/// <param name="possibleInternalReferencesRange">
/// <para>A possible internal references range.</para>
/// <para></para>
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LinksConstants(int targetPart, Range<TLinkAddress> possibleInternalReferencesRange) : this(targetPart, possibleInternalReferencesRange, null) { }
/// <summary>
/// <para>
/// Initializes a new <see cref="LinksConstants"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="possibleInternalReferencesRange">
/// <para>A possible internal references range.</para>
/// <para></para>
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LinksConstants(Range<TLinkAddress> possibleInternalReferencesRange) : this(DefaultTargetPart, possibleInternalReferencesRange, null) { }
/// <summary>
/// <para>
/// Initializes a new <see cref="LinksConstants"/> instance.
/// </para>
/// <para></para>
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LinksConstants() : this(DefaultTargetPart, enableExternalReferencesSupport: false) { }
/// <summary>
/// <para>
/// Gets the default internal references range using the specified enable external references support.
/// </para>
/// <para></para>
/// </summary>
/// <param name="enableExternalReferencesSupport">
/// <para>The enable external references support.</para>
/// <para></para>
/// </param>
/// <returns>
/// <para>A range of t link address</para>
/// <para></para>
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range<TLinkAddress> GetDefaultInternalReferencesRange(bool enableExternalReferencesSupport)
{
if (enableExternalReferencesSupport)
{
return (_one, _uInt64ToAddressConverter.Convert(Hybrid<TLinkAddress>.HalfOfNumberValuesRange));
}
else
{
return (_one, NumericType<TLinkAddress>.MaxValue);
}
}
/// <summary>
/// <para>
/// Gets the default external references range using the specified enable external references support.
/// </para>
/// <para></para>
/// </summary>
/// <param name="enableExternalReferencesSupport">
/// <para>The enable external references support.</para>
/// <para></para>
/// </param>
/// <returns>
/// <para>A range of t link address</para>
/// <para></para>
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Range<TLinkAddress>? GetDefaultExternalReferencesRange(bool enableExternalReferencesSupport)
{
if (enableExternalReferencesSupport)
{
return (Hybrid<TLinkAddress>.ExternalZero, NumericType<TLinkAddress>.MaxValue);
}
else
{
return null;
}
}
}
}