Skip to content

Commit f33b281

Browse files
Switch up naming
1 parent 40d2521 commit f33b281

6 files changed

Lines changed: 52 additions & 56 deletions

File tree

CommonExtendedObjectsTests/IntArrayTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class IntArrayTests
2828
[TestMethod]
2929
public void IndexingShouldGetAndSetValuesCorrectly()
3030
{
31-
var arr = new IntArray(5);
31+
var arr = new UnmanagedIntArray(5);
3232
for (var i = 0; i < arr.Length; i++)
3333
{
3434
arr[i] = i * 10;
@@ -48,7 +48,7 @@ public void IndexingShouldGetAndSetValuesCorrectly()
4848
[TestMethod]
4949
public void RemoveAtShouldRemoveElementAndShiftLeft()
5050
{
51-
var arr = new IntArray(5);
51+
var arr = new UnmanagedIntArray(5);
5252
for (var i = 0; i < arr.Length; i++)
5353
{
5454
arr[i] = i;
@@ -68,7 +68,7 @@ public void RemoveAtShouldRemoveElementAndShiftLeft()
6868
[TestMethod]
6969
public void ResizeShouldChangeLengthAndPreserveOldData()
7070
{
71-
var arr = new IntArray(3);
71+
var arr = new UnmanagedIntArray(3);
7272
arr[0] = 1;
7373
arr[1] = 2;
7474
arr[2] = 3;
@@ -89,7 +89,7 @@ public void ResizeShouldChangeLengthAndPreserveOldData()
8989
[TestMethod]
9090
public void ClearShouldZeroOutAllElements()
9191
{
92-
var arr = new IntArray(4);
92+
var arr = new UnmanagedIntArray(4);
9393
for (var i = 0; i < arr.Length; i++)
9494
{
9595
arr[i] = 42;
@@ -114,7 +114,7 @@ public void CompareIntArrayvsIntArrayDotNetPerformance()
114114
var stopwatch = new Stopwatch();
115115

116116
// === IntArray Test ===
117-
var intArray = new IntArray(Size);
117+
var intArray = new UnmanagedIntArray(Size);
118118
stopwatch.Restart();
119119

120120
for (var i = 0; i < Size; i++)
@@ -192,7 +192,7 @@ public void CompareIntArrayvsIntArrayDotNetPerformance()
192192
[TestMethod]
193193
public void IndexingShouldWorkForIntArray()
194194
{
195-
RunIndexingTest(new IntArray(5));
195+
RunIndexingTest(new UnmanagedIntArray(5));
196196
}
197197

198198
/// <summary>
@@ -229,7 +229,7 @@ private static void RunIndexingTest(IUnmanagedArray<int> arr)
229229
[TestMethod]
230230
public void RemoveMultipleShouldRemoveSequentialIndices()
231231
{
232-
var arr = new IntArray(10);
232+
var arr = new UnmanagedIntArray(10);
233233
for (var i = 0; i < arr.Length; i++)
234234
{
235235
arr[i] = i + 1; // [1..10]
@@ -263,7 +263,7 @@ public void RemoveMultipleShouldRemoveSequentialIndices()
263263
[TestMethod]
264264
public void RemoveMultipleShouldRemoveNonSequentialIndices()
265265
{
266-
var arr = new IntArray(10);
266+
var arr = new UnmanagedIntArray(10);
267267
for (var i = 0; i < arr.Length; i++)
268268
{
269269
arr[i] = i + 1; // [1..10]

CommonExtendedObjectsTests/IntListTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ public class IntListTests
2323
[TestMethod]
2424
public void AddPopPeekBehavior()
2525
{
26-
using var list = new IntList(4);
26+
using var list = new UnmanagedIntList(4) {10, 20, 30};
2727

28-
list.Add(10);
29-
list.Add(20);
30-
list.Add(30);
3128

3229
Assert.AreEqual(3, list.Length);
3330
Assert.AreEqual(30, list.Peek());
@@ -51,7 +48,7 @@ public void AddPopPeekBehavior()
5148
[ExpectedException(typeof(InvalidOperationException))]
5249
public void PopEmptyThrows()
5350
{
54-
using var list = new IntList();
51+
using var list = new UnmanagedIntList();
5552
list.Pop();
5653
}
5754

@@ -62,7 +59,7 @@ public void PopEmptyThrows()
6259
[ExpectedException(typeof(InvalidOperationException))]
6360
public void PeekEmptyThrows()
6461
{
65-
using var list = new IntList();
62+
using var list = new UnmanagedIntList();
6663
list.Peek();
6764
}
6865

@@ -72,7 +69,7 @@ public void PeekEmptyThrows()
7269
[TestMethod]
7370
public void CapacityResizesCorrectly()
7471
{
75-
using var list = new IntList(2);
72+
using var list = new UnmanagedIntList(2);
7673
for (var i = 0; i < 1000; i++)
7774
{
7875
list.Add(i);
@@ -91,7 +88,7 @@ public void PerformanceBenchmark()
9188
const int n = 1_000_000;
9289

9390
// IntList timing
94-
using var intList = new IntList(n);
91+
using var intList = new UnmanagedIntList(n);
9592
var sw = Stopwatch.StartNew();
9693
for (var i = 0; i < n; i++)
9794
{
@@ -103,6 +100,7 @@ public void PerformanceBenchmark()
103100

104101
// List<int> timing
105102
var list = new List<int>(n);
103+
106104
sw.Restart();
107105
for (var i = 0; i < n; i++)
108106
{
@@ -114,6 +112,7 @@ public void PerformanceBenchmark()
114112

115113
// Stack<int> timing
116114
var stack = new Stack<int>(n);
115+
117116
sw.Restart();
118117
for (var i = 0; i < n; i++)
119118
{

CoreLibrary.sln

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.14.36109.1
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.35931.194
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViewModel", "ViewModel\ViewModel.csproj", "{9B2741D2-443A-4136-B9A4-1191686DA4AD}"
77
EndProject
@@ -77,9 +77,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreConsole", "CoreConsole\
7777
EndProject
7878
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InterpreteTests", "InterpreteTests\InterpreteTests.csproj", "{18981E7D-2AB9-48B2-8181-9E9DF3263B23}"
7979
EndProject
80-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenderEngineTests", "RenderEngineTests\RenderEngineTests.csproj", "{8CE955D6-DEE7-519A-ACEA-1D3BA519932A}"
80+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenderEngineTests", "RenderEngineTests\RenderEngineTests.csproj", "{8CE955D6-DEE7-519A-ACEA-1D3BA519932A}"
8181
EndProject
82-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonExtendedObjectsTests", "CommonExtendedObjectsTests\CommonExtendedObjectsTests.csproj", "{477CFEA4-070A-499C-9465-699D98AEC3B7}"
82+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonExtendedObjectsTests", "CommonExtendedObjectsTests\CommonExtendedObjectsTests.csproj", "{477CFEA4-070A-499C-9465-699D98AEC3B7}"
8383
EndProject
8484
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Projektmappenelemente", "Projektmappenelemente", "{84D27F74-D2BA-6C25-2661-968F101900D9}"
8585
ProjectSection(SolutionItems) = preProject

ExtendedSystemObjects/SortedKvStore.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@ public sealed class SortedKvStore : IDisposable, IEnumerable<KeyValuePair<int, i
3030
/// <summary>
3131
/// The keys
3232
/// </summary>
33-
private readonly IntArray _keys;
33+
private readonly UnmanagedIntArray _keys;
3434

3535
/// <summary>
3636
/// The occupied Array, 0/1 flags
3737
/// </summary>
38-
private readonly IntArray _occupied;
38+
private readonly UnmanagedIntArray _occupied;
3939

4040
/// <summary>
4141
/// The values
4242
/// </summary>
43-
private readonly IntArray _values;
43+
private readonly UnmanagedIntArray _values;
4444

4545
/// <summary>
4646
/// Initializes a new instance of the <see cref="SortedKvStore" /> class with a specified initial capacity.
4747
/// </summary>
4848
/// <param name="initialCapacity">The initial capacity of the store.</param>
4949
public SortedKvStore(int initialCapacity = 16)
5050
{
51-
_keys = new IntArray(initialCapacity);
52-
_values = new IntArray(initialCapacity);
53-
_occupied = new IntArray(initialCapacity);
51+
_keys = new UnmanagedIntArray(initialCapacity);
52+
_values = new UnmanagedIntArray(initialCapacity);
53+
_occupied = new UnmanagedIntArray(initialCapacity);
5454
}
5555

5656
/// <summary>
@@ -349,7 +349,7 @@ public void Compact()
349349
/// <returns>All active elements as Key Value pair.</returns>
350350
public IEnumerator<KeyValuePair<int, int>> GetEnumerator()
351351
{
352-
for (int i = 0; i < Count; i++)
352+
for (var i = 0; i < Count; i++)
353353
{
354354
if (_occupied[i] != 0)
355355
{

ExtendedSystemObjects/IntArray.cs renamed to ExtendedSystemObjects/UnmanagedIntArray.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: ExtendedSystemObjects
4-
* FILE: ExtendedSystemObjects/IntArray.cs
4+
* FILE: ExtendedSystemObjects/UnmanagedIntArray.cs
55
* PURPOSE: A high-performance array implementation with reduced features. Limited to integer Values.
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
77
*/
@@ -25,7 +25,7 @@ namespace ExtendedSystemObjects
2525
/// backed by unmanaged memory. Designed for performance-critical
2626
/// scenarios where garbage collection overhead must be avoided.
2727
/// </summary>
28-
public sealed unsafe class IntArray : IUnmanagedArray<int>, IEnumerable<int>
28+
public sealed unsafe class UnmanagedIntArray : IUnmanagedArray<int>, IEnumerable<int>
2929
{
3030
/// <summary>
3131
/// The buffer
@@ -45,10 +45,10 @@ public sealed unsafe class IntArray : IUnmanagedArray<int>, IEnumerable<int>
4545
private static bool UseSimd => Vector.IsHardwareAccelerated;
4646

4747
/// <summary>
48-
/// Initializes a new instance of the <see cref="IntArray" /> class with the specified size.
48+
/// Initializes a new instance of the <see cref="UnmanagedIntArray" /> class with the specified size.
4949
/// </summary>
5050
/// <param name="size">The number of elements to allocate.</param>
51-
public IntArray(int size)
51+
public UnmanagedIntArray(int size)
5252
{
5353
if (size < 0)
5454
{
@@ -119,25 +119,24 @@ public int this[int i]
119119
public int IndexOf(int value)
120120
{
121121
var span = AsSpan();
122-
int vectorSize = Vector<int>.Count;
122+
var vectorSize = Vector<int>.Count;
123123

124124
if (UseSimd && span.Length >= vectorSize)
125125
{
126126
var vTarget = new Vector<int>(value);
127-
int i = 0;
127+
var i = 0;
128128

129129
for (; i <= span.Length - vectorSize; i += vectorSize)
130130
{
131131
var vData = new Vector<int>(span.Slice(i, vectorSize));
132132
var vCmp = Vector.Equals(vData, vTarget);
133133

134-
if (!Vector.EqualsAll(vCmp, Vector<int>.Zero))
134+
if (Vector.EqualsAll(vCmp, Vector<int>.Zero)) continue;
135+
136+
for (var j = 0; j < vectorSize; j++)
135137
{
136-
for (int j = 0; j < vectorSize; j++)
137-
{
138-
if (vCmp[j] != 0)
139-
return i + j;
140-
}
138+
if (vCmp[j] != 0)
139+
return i + j;
141140
}
142141
}
143142

@@ -150,16 +149,14 @@ public int IndexOf(int value)
150149

151150
return -1;
152151
}
153-
else
154-
{
155-
for (int i = 0; i < span.Length; i++)
156-
{
157-
if (span[i] == value)
158-
return i;
159-
}
160152

161-
return -1;
153+
for (var i = 0; i < span.Length; i++)
154+
{
155+
if (span[i] == value)
156+
return i;
162157
}
158+
159+
return -1;
163160
}
164161

165162
/// <inheritdoc />
@@ -375,9 +372,9 @@ public void EnsureCapacity(int minCapacity)
375372
}
376373

377374
/// <summary>
378-
/// Finalizes an instance of the <see cref="IntArray" /> class.
375+
/// Finalizes an instance of the <see cref="UnmanagedIntArray" /> class.
379376
/// </summary>
380-
~IntArray()
377+
~UnmanagedIntArray()
381378
{
382379
Dispose(false);
383380
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: ExtendedSystemObjects
4-
* FILE: ExtendedSystemObjects/IntList.cs
4+
* FILE: ExtendedSystemObjects/UnmanagedIntList.cs
55
* PURPOSE: A high-performance List implementation with reduced features. Limited to integer Values.
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
77
*/
@@ -27,7 +27,7 @@ namespace ExtendedSystemObjects
2727
/// Designed for scenarios where manual memory management is needed.
2828
/// </summary>
2929
/// <seealso cref="T:System.IDisposable" />
30-
public sealed unsafe class IntList : IUnmanagedArray<int>, IEnumerable<int>
30+
public sealed unsafe class UnmanagedIntList : IUnmanagedArray<int>, IEnumerable<int>
3131
{
3232
/// <summary>
3333
/// The buffer
@@ -50,10 +50,10 @@ public sealed unsafe class IntList : IUnmanagedArray<int>, IEnumerable<int>
5050
private int* _ptr;
5151

5252
/// <summary>
53-
/// Initializes a new instance of the <see cref="IntList" /> class with the specified initial capacity.
53+
/// Initializes a new instance of the <see cref="UnmanagedIntList" /> class with the specified initial capacity.
5454
/// </summary>
5555
/// <param name="initialCapacity">The initial number of elements the list can hold without resizing. Default is 16.</param>
56-
public IntList(int initialCapacity = 16)
56+
public UnmanagedIntList(int initialCapacity = 16)
5757
{
5858
_capacity = initialCapacity > 0 ? initialCapacity : 16;
5959
_buffer = Marshal.AllocHGlobal(_capacity * sizeof(int));
@@ -62,7 +62,7 @@ public IntList(int initialCapacity = 16)
6262

6363
/// <inheritdoc />
6464
/// <summary>
65-
/// Gets the number of elements contained in the <see cref="IntList" />.
65+
/// Gets the number of elements contained in the <see cref="UnmanagedIntList" />.
6666
/// </summary>
6767
public int Length { get; private set; }
6868

@@ -279,9 +279,9 @@ public Span<int> AsSpan()
279279
}
280280

281281
/// <summary>
282-
/// Finalizes an instance of the <see cref="IntList" /> class, releasing unmanaged resources.
282+
/// Finalizes an instance of the <see cref="UnmanagedIntList" /> class, releasing unmanaged resources.
283283
/// </summary>
284-
~IntList()
284+
~UnmanagedIntList()
285285
{
286286
Dispose(false);
287287
}

0 commit comments

Comments
 (0)