mirror of https://github.com/deavmi/niknaks
Compare commits
9 Commits
c886ba184b
...
f71286e85c
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | f71286e85c | |
Tristan B. Velloza Kildaire | 818a7cad32 | |
Tristan B. Velloza Kildaire | 98f2f10aca | |
Tristan B. Velloza Kildaire | a421b40bdb | |
Tristan B. Velloza Kildaire | 365d15d81f | |
Tristan B. Velloza Kildaire | 9472cb96d4 | |
Tristan B. Velloza Kildaire | 85580d2a71 | |
Tristan B. Velloza Kildaire | e9cb3a1960 | |
Tristan B. Velloza Kildaire | 19a7ce6f7e |
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue