Skip to content

Commit 3a65aa6

Browse files
committed
More fixes.
1 parent bf59a7a commit 3a65aa6

4 files changed

Lines changed: 39 additions & 23 deletions

File tree

Arch.LowLevel/Arch.LowLevel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<PackageId>Arch.LowLevel</PackageId>
1515
<Title>Arch.LowLevel</Title>
16-
<Version>1.1.4</Version>
16+
<Version>1.1.5</Version>
1717
<Authors>genaray</Authors>
1818
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1919
<Description>LowLevel tools for arch.</Description>

Arch.LowLevel/Jagged/SparseJaggedArray.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,26 @@ namespace Arch.LowLevel.Jagged;
1313
/// <typeparam name="T"></typeparam>
1414
public record struct SparseBucket<T>
1515
{
16-
1716
/// <summary>
1817
/// The items array.
1918
/// </summary>
2019
internal T[] Array = System.Array.Empty<T>();
20+
21+
/// <summary>
22+
/// The filler, the default value.
23+
/// </summary>
24+
private readonly T _filler;
2125

2226
/// <summary>
2327
/// Creates an instance of the <see cref="Bucket{T}"/>.
2428
/// </summary>
2529
/// <param name="capacity">The total capacity.</param>
30+
/// <param name="filler">The filler.</param>
2631
/// <param name="allocate">If it should allocate straight forward.</param>
27-
public SparseBucket(int capacity, bool allocate = false)
32+
public SparseBucket(int capacity, T filler, bool allocate = false)
2833
{
2934
Capacity = capacity;
35+
_filler = filler;
3036
if (allocate)
3137
{
3238
EnsureCapacity();
@@ -79,6 +85,7 @@ internal void EnsureCapacity()
7985
}
8086

8187
Array = new T[Capacity];
88+
Clear();
8289
}
8390

8491
/// <summary>
@@ -106,12 +113,12 @@ public ref T this[int i]
106113
}
107114

108115
/// <summary>
109-
/// Clears this <see cref="SparseBucket{T}"/> and sets all values to the <see cref="filler"/>.
116+
/// Clears this <see cref="SparseBucket{T}"/> and sets all values to the <see cref="_filler"/>.
110117
/// </summary>
111118
[MethodImpl(MethodImplOptions.AggressiveInlining)]
112-
public void Clear(T filler = default)
119+
public void Clear()
113120
{
114-
System.Array.Fill(Array, filler);
121+
System.Array.Fill(Array, _filler);
115122
}
116123
}
117124

@@ -165,9 +172,9 @@ public SparseJaggedArray(int bucketSize, int capacity = 64)
165172
// Fill buckets
166173
for (var i = 0; i < _buckets.Length; i++)
167174
{
168-
var bucket = new SparseBucket<T>(_bucketSize);
175+
var bucket = new SparseBucket<T>(_bucketSize, _filler);
169176
SetBucket(i, in bucket);
170-
bucket.Clear(_filler);
177+
bucket.Clear();
171178
}
172179
}
173180

@@ -189,9 +196,9 @@ public SparseJaggedArray(int bucketSize, T filler, int capacity = 64) : this(buc
189196
// Fill buckets
190197
for (var i = 0; i < _buckets.Length; i++)
191198
{
192-
var bucket = new SparseBucket<T>(_bucketSize);
199+
var bucket = new SparseBucket<T>(_bucketSize, filler);
193200
SetBucket(i, in bucket);
194-
bucket.Clear(_filler);
201+
bucket.Clear();
195202
}
196203
}
197204

@@ -363,9 +370,9 @@ public void EnsureCapacity(int newCapacity)
363370

364371
for (var i = length; i < _buckets.Length; i++)
365372
{
366-
var bucket = new SparseBucket<T>(_bucketSize);
373+
var bucket = new SparseBucket<T>(_bucketSize, _filler);
367374
SetBucket(i, bucket);
368-
bucket.Clear(_filler);
375+
bucket.Clear();
369376
}
370377
}
371378

@@ -457,7 +464,7 @@ public void Clear()
457464
continue;
458465
}
459466

460-
bucket.Clear(_filler);
467+
bucket.Clear();
461468
}
462469
}
463470
}

Arch.LowLevel/Jagged/UnsafeSparseJaggedArray.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@ public record struct UnsafeSparseBucket<T> : IDisposable where T : unmanaged
1717
/// The items array.
1818
/// </summary>
1919
internal UnsafeArray<T> Array = UnsafeArray.Empty<T>();
20+
21+
/// <summary>
22+
/// The filler, the default value.
23+
/// </summary>
24+
private readonly T _filler;
25+
2026

2127
/// <summary>
2228
/// Creates an instance of the <see cref="Bucket{T}"/>.
2329
/// </summary>
2430
/// <param name="capacity">The total capacity.</param>
31+
/// <param name="filler">The filler.</param>
2532
/// <param name="allocate">If it should allocate straight forward.</param>
26-
public UnsafeSparseBucket(int capacity, bool allocate = false)
33+
public UnsafeSparseBucket(int capacity, T filler, bool allocate = false)
2734
{
2835
Capacity = capacity;
36+
_filler = filler;
2937
if (allocate)
3038
{
3139
EnsureCapacity();
@@ -78,6 +86,7 @@ internal void EnsureCapacity()
7886
}
7987

8088
Array = new UnsafeArray<T>(Capacity);
89+
Clear();
8190
}
8291

8392
/// <summary>
@@ -108,9 +117,9 @@ public ref T this[int i]
108117
/// Clears this <see cref="UnsafeSparseBucket{T}"/> and sets all values to the <see cref="filler"/>.
109118
/// </summary>
110119
[MethodImpl(MethodImplOptions.AggressiveInlining)]
111-
public void Clear(T filler = default)
120+
public void Clear()
112121
{
113-
UnsafeArray.Fill(ref Array, filler);
122+
UnsafeArray.Fill(ref Array, _filler);
114123
}
115124

116125

@@ -174,9 +183,9 @@ public UnsafeSparseJaggedArray(int bucketSize, int capacity = 64)
174183
// Fill buckets
175184
for (var i = 0; i < _bucketArray.Length; i++)
176185
{
177-
var bucket = new UnsafeSparseBucket<T>(_bucketSize);
186+
var bucket = new UnsafeSparseBucket<T>(_bucketSize, _filler);
178187
SetBucket(i, in bucket);
179-
bucket.Clear(_filler);
188+
bucket.Clear();
180189
}
181190
}
182191

@@ -198,9 +207,9 @@ public UnsafeSparseJaggedArray(int bucketSize, T filler, int capacity = 64) : th
198207
// Fill buckets
199208
for (var i = 0; i < _bucketArray.Length; i++)
200209
{
201-
var bucket = new UnsafeSparseBucket<T>(_bucketSize);
210+
var bucket = new UnsafeSparseBucket<T>(_bucketSize, _filler);
202211
SetBucket(i, in bucket);
203-
bucket.Clear(_filler);
212+
bucket.Clear();
204213
}
205214
}
206215

@@ -372,9 +381,9 @@ public void EnsureCapacity(int newCapacity)
372381

373382
for (var i = length; i < _bucketArray.Length; i++)
374383
{
375-
var bucket = new UnsafeSparseBucket<T>(_bucketSize);
384+
var bucket = new UnsafeSparseBucket<T>(_bucketSize, _filler);
376385
SetBucket(i, in bucket);
377-
bucket.Clear(_filler);
386+
bucket.Clear();
378387
}
379388
}
380389

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Download the packages and get started today!
1616
dotnet add package Arch.System --version 1.1.0
1717
dotnet add package Arch.System.SourceGenerator --version 2.0.0
1818
dotnet add package Arch.EventBus --version 1.0.2
19-
dotnet add package Arch.LowLevel --version 1.1.4
19+
dotnet add package Arch.LowLevel --version 1.1.5
2020
dotnet add package Arch.Relationships --version 1.0.0
2121
dotnet add package Arch.Persistence --version 2.0.0
2222
dotnet add package Arch.AOT.SourceGenerator --version 1.0.1

0 commit comments

Comments
 (0)