Skip to content

Commit

Permalink
Merge pull request #52 from RoyconSkylands/fixing-jagged-array-2
Browse files Browse the repository at this point in the history
Fixing jagged array
  • Loading branch information
genaray authored Nov 20, 2023
2 parents 24dfc7e + 21e2b1c commit 8210c6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Arch.LowLevel/Jagged/JaggedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ public bool TryGetValue(int index, out T value)
value = _filler;
return false;
}

if (index >= Capacity)
{
value = _filler;
return false;
}

IndexToSlot(index, out var bucketIndex, out var itemIndex);

Expand Down
5 changes: 5 additions & 0 deletions Arch.LowLevel/Jagged/SparseJaggedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ public void Add(int index, in T item)
{
IndexToSlot(index, out var bucketIndex, out var itemIndex);

if (bucketIndex >= _bucketArray.Length)
{
EnsureCapacity(index);
}

ref var bucket = ref _bucketArray[bucketIndex];
bucket.EnsureCapacity();
bucket[itemIndex] = item;
Expand Down

0 comments on commit 8210c6f

Please sign in to comment.