From 5fc0c90b11a4b34b87769745589638b40750b822 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 4 Aug 2020 19:15:54 +0200 Subject: [PATCH] Fixed corner case --- ExaArray/ExaArray2D.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ExaArray/ExaArray2D.cs b/ExaArray/ExaArray2D.cs index 248dda0..49529b8 100644 --- a/ExaArray/ExaArray2D.cs +++ b/ExaArray/ExaArray2D.cs @@ -47,7 +47,7 @@ namespace Exa { get { - if (indexAbscissa >= this.chunks.Length - 1 || indexOrdinate >= this.chunks[indexAbscissa]?.Length) + if (this.chunks.Length == 0 || indexAbscissa >= this.chunks.Length || indexOrdinate >= this.chunks[indexAbscissa]?.Length) return default(T); return this.chunks[indexAbscissa][indexOrdinate]; @@ -55,13 +55,13 @@ namespace Exa set { - if(indexAbscissa >= this.chunks.Length - 1) + if(this.chunks.Length == 0 || indexAbscissa >= this.chunks.Length) this.chunks.Extend(indexAbscissa - this.chunks.Length + 1); this.chunks[indexAbscissa] ??= new ExaArray1D(Strategy.MAX_PERFORMANCE); - if(indexOrdinate >= this.chunks[indexAbscissa].Length - 1) + if(this.chunks[indexAbscissa].Length == 0 || indexOrdinate >= this.chunks[indexAbscissa].Length - 1) { - var extendBy = indexOrdinate - this.chunks[indexAbscissa].Length + 1; + var extendBy = (indexOrdinate - this.chunks[indexAbscissa].Length) + 1; if(extendBy > MAX_NUMBER_ELEMENTS - this.sumLengthOrdinates) throw new ArgumentOutOfRangeException($"It is not possible to extend more than {MAX_NUMBER_ELEMENTS} total elements across all dimensions.");