Compare commits

...

6 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 72cdc52695
Merge de77bb7d06 into b6106883da 2024-05-02 16:23:21 +02:00
Tristan B. Velloza Kildaire de77bb7d06 View
- `add(T[])` was constructing TWO `SectorType` instances, make it only one
2024-05-02 16:23:09 +02:00
Tristan B. Velloza Kildaire e84128384a View
- Cleaned up
2024-05-02 16:14:58 +02:00
Tristan B. Velloza Kildaire 1da8936ce7 View
- Added docs
2024-05-02 16:11:38 +02:00
Tristan B. Velloza Kildaire 620175d605 SectorType
- More compile-time checks added
2024-05-02 16:07:32 +02:00
Tristan B. Velloza Kildaire d0ea22673f SectorType
- More compile-time checks added
2024-05-02 16:07:12 +02:00
1 changed files with 30 additions and 4 deletions

View File

@ -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