mirror of https://github.com/deavmi/niknaks
Compare commits
6 Commits
cdae50845a
...
72cdc52695
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 72cdc52695 | |
Tristan B. Velloza Kildaire | de77bb7d06 | |
Tristan B. Velloza Kildaire | e84128384a | |
Tristan B. Velloza Kildaire | 1da8936ce7 | |
Tristan B. Velloza Kildaire | 620175d605 | |
Tristan B. Velloza Kildaire | d0ea22673f |
|
@ -610,6 +610,11 @@ private struct Sector(T)
|
|||
this.data = data;
|
||||
}
|
||||
|
||||
public static Sector!(T) make(T[] data)
|
||||
{
|
||||
return Sector!(T)(data);
|
||||
}
|
||||
|
||||
public T opIndex(size_t idx)
|
||||
{
|
||||
return this.data[idx];
|
||||
|
@ -715,17 +720,36 @@ private bool isSector(S)()
|
|||
__traits(isSame, Parameters!(S.opIndexAssign), AliasSeq!(T, size_t)) &&
|
||||
__traits(isSame, ReturnType!(S.opIndexAssign), void);
|
||||
|
||||
|
||||
// Has make(T[] data) returning S (implied S!(T) due to template arg check earlier)
|
||||
s &= hasStaticMember!(S, "make") &&
|
||||
__traits(isSame, Parameters!(S.make), AliasSeq!(T[])) &&
|
||||
__traits(isSame, ReturnType!(S.make), S);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A view represents a collection of
|
||||
* arrays which can be accessed
|
||||
* in an array like manner and have their
|
||||
* elements changed too. Therefore this
|
||||
* provides access to these originally
|
||||
* non-contiguous data sets as if they
|
||||
* were one contiguous array.
|
||||
*
|
||||
* Updating of elements is allowed,
|
||||
* fetching of elements (and slices)
|
||||
* and lastly sizing down but NOT
|
||||
* updwards. This last constraint
|
||||
* is why this is considered a "view".
|
||||
*/
|
||||
public struct View(T, SectorType = Sector!(T))
|
||||
if(isSector!(SectorType)())
|
||||
{
|
||||
private SectorType[] sectors;
|
||||
// private
|
||||
|
||||
// Maybe current size should be here as we
|
||||
// are a view, we should allow modofication
|
||||
|
@ -894,13 +918,13 @@ if(isSector!(SectorType)())
|
|||
private void add(T[] data)
|
||||
{
|
||||
// Create a new sector
|
||||
SectorType sec = SectorType(data);
|
||||
SectorType sec = SectorType.make(data);
|
||||
|
||||
// Update the tracking size
|
||||
this.curSize += sec.length;
|
||||
|
||||
// Concatenate it to the view
|
||||
this.sectors ~= SectorType(data);
|
||||
this.sectors ~= sec;
|
||||
}
|
||||
|
||||
@property
|
||||
|
@ -915,6 +939,8 @@ if(isSector!(SectorType)())
|
|||
// TODO: Need we continuously compute this?
|
||||
// ... we should have a tracking field for
|
||||
// ... this
|
||||
// Would only need to be called in length(size_t)
|
||||
// and add(T[])
|
||||
size_t actualSize = computeTotalLen();
|
||||
|
||||
// On successful exit, update the "fake" size
|
||||
|
|
Loading…
Reference in New Issue