Compare commits

...

10 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 9003c59473
Merge f71286e85c into b6106883da 2024-05-02 13:04:00 +00:00
Tristan B. Velloza Kildaire f71286e85c View
- Cleaned up
2024-05-02 15:03:49 +02:00
Tristan B. Velloza Kildaire 818a7cad32 View
- Cleaned up
2024-05-02 15:03:29 +02:00
Tristan B. Velloza Kildaire 98f2f10aca View
- Replaced unreachable code with a false assertion
2024-05-02 15:03:06 +02:00
Tristan B. Velloza Kildaire a421b40bdb View
- Removed unreachable code
2024-05-02 15:02:18 +02:00
Tristan B. Velloza Kildaire 365d15d81f View
- Removed unreachable code
2024-05-02 15:01:57 +02:00
Tristan B. Velloza Kildaire 9472cb96d4 View
- When calling `opSlice(size_t, size_t)` with arguments that are equal then you should return `[]`. This fixe a bug when we do `view[]` and length was `0` as `opSlice()` calls `opSlice(size_t, size_t)` with `opSlice(0, 0) then
2024-05-02 14:59:36 +02:00
Tristan B. Velloza Kildaire 85580d2a71 View
- Cleaned up
2024-05-02 14:51:06 +02:00
Tristan B. Velloza Kildaire e9cb3a1960 View
- Cleaned up
2024-05-02 14:50:46 +02:00
Tristan B. Velloza Kildaire 19a7ce6f7e View
- Only add debug in unittest mode
2024-05-02 14:50:11 +02:00
1 changed files with 19 additions and 24 deletions

View File

@ -11,6 +11,8 @@ import std.datetime.stopwatch : StopWatch, AutoStart;
import core.thread : Thread;
import core.sync.condition : Condition;
import std.functional : toDelegate;
import core.exception : ArrayIndexError;
import core.exception : RangeError;
version(unittest)
{
@ -657,8 +659,7 @@ private bool isSector(S)()
return __traits(hasMember, S, "opIndex");
}
import core.exception : ArrayIndexError;
import core.exception : RangeError;
public struct View(T, SectorType = Sector!(T))
if(isSector!(SectorType)())
@ -707,7 +708,9 @@ if(isSector!(SectorType)())
}
}
throw new ArrayIndexError(idx, this.length);
// NOTE: This should be unreachable but
// compiler moans and groans
assert(false);
}
public void opIndexAssign(T value, size_t idx)
@ -723,9 +726,13 @@ if(isSector!(SectorType)())
// could cheat if sector is never replaced, hence why it works
foreach(SectorType sector; this.sectors)
{
writeln(sector);
writeln("idx: ", idx);
writeln("thunk: ", thunk);
version(unittest)
{
writeln(sector);
writeln("idx: ", idx);
writeln("thunk: ", thunk);
}
if(idx-thunk < sector.opDollar())
{
sector[idx-thunk] = value;
@ -736,8 +743,6 @@ if(isSector!(SectorType)())
thunk += sector.opDollar();
}
}
throw new ArrayIndexError(idx, this.length);
}
public T[] opSlice()
@ -747,17 +752,20 @@ if(isSector!(SectorType)())
public T[] opSlice(size_t start, size_t end)
{
// Invariant of start < end
// Invariant of start <= end
if(!(start <= end))
{
// TODO: Check
throw new RangeError("Starting index must be smaller than or equal to ending index");
}
// If the indices are equal, then it is empty
else if(start == end)
{
return [];
}
// Within range of "fake" size
else if(!((start < this.length) && (end <= this.length)))
{
throw new RangeError("start index or end index not under range");
// throw new ArrayIndexError(idx, this.length);
}
T[] collected;
@ -794,15 +802,6 @@ if(isSector!(SectorType)())
thunk += sector.opDollar();
}
// FIXME: This is lazy, do a check for up to where
// and actually make THIS the real implementation
writeln(collected);
// TODO: Also if the range matches the bounds
// of a given range exactly then extract directly
return collected;
}
@ -853,9 +852,6 @@ if(isSector!(SectorType)())
@property
public void length(size_t size)
{
// TODO: Add support for sizing down
// TODO: Add support for sizing up
// TODO: Need we continuously compute this?
// ... we should have a tracking field for
// ... this
@ -907,7 +903,6 @@ if(isSector!(SectorType)())
this.sectors.length = sectorCnt;
}
}
}