Library: draft skeleton of builder operations

- create by forwarding allocator arguments to policy
- builder-Op to append from iterator
- decide to collapse the ArrayBucket class, since
  access is going through unsafe pointer arithmetic anyway
This commit is contained in:
Fischlurch 2024-05-28 18:52:01 +02:00
parent 27b36f0679
commit feeee4096d
3 changed files with 96 additions and 39 deletions

View file

@ -44,17 +44,19 @@
#include "lib/several.hpp"
#include "include/logging.h"
#include "lib/iter-explorer.hpp"
#include "lib/util.hpp"
#include <utility>
#include <vector>
using std::vector;
using std::move;
namespace lib {
using std::vector;
using std::forward;
using std::move;
namespace {// Allocation managment policies
@ -73,20 +75,77 @@ namespace lib {
: Several<I>
, POL
{
using Col = Several<I>;
size_t storageSiz_{0};
public:
SeveralBuilder() = default;
/** start Several build using a custom allocator */
template<typename...ARGS, typename = meta::enable_if<std::is_constructible<POL,ARGS...>>>
SeveralBuilder (ARGS&& ...alloInit)
: Several<I>{}
, POL{forward<ARGS> (alloInit)...}
{ }
SeveralBuilder&&
reserve (size_t cntElm)
{
adjustStorage (cntElm, sizeof(I));
return move(*this);
}
template<class IT>
SeveralBuilder&&
appendAll (IT&& data)
{
explore(data).foreach ([this](auto it){ emplaceElm(it); });
return move(*this);
}
Several<I>
build()
{
return move (*this);
}
private:
void
adjustStorage (size_t cnt, size_t spread)
{
UNIMPLEMENTED ("allocation");
}
template<class IT>
void
emplaceElm (IT& dataSrc)
{
using Val = typename IT::value_type;
size_t elmSiz = sizeof(Val);
adjustStorage (Col::size_+1, requiredSpread(elmSiz));
UNIMPLEMENTED ("emplace data");
}
size_t
requiredSpread (size_t elmSiz)
{
size_t currSpread = Col::empty()? 0 : Col::data_->spread;
return util::max (currSpread, elmSiz);
}
};
template<typename X>
SeveralBuilder<X>
makeSeveral (std::initializer_list<X> ili)
{
UNIMPLEMENTED ("start building a Several-Container");
return SeveralBuilder<X>{}
.reserve (ili.size())
.appendAll (ili);
}

View file

@ -45,7 +45,8 @@ namespace lib {
namespace {// Storage implementation details
struct Bucket
template<class I>
struct ArrayBucket
{
union Manager
{
@ -58,17 +59,13 @@ namespace lib {
Manager manager;
size_t spread;
template<class I>
auto access();
};
template<class I, size_t bytes>
struct ArrayBucket
: Bucket
{
/** mark start of the storage area */
alignas(I)
std::byte storage[bytes];
std::byte storage[sizeof(I)];
/** perform unchecked access into the storage area
* @note typically reaching behind the nominal end of this object
*/
I&
subscript (size_t idx)
{
@ -79,16 +76,6 @@ namespace lib {
}
};
/** @internal perform an unsafe down-cast to access the storage area */
template<class I>
auto
Bucket::access()
{
using Storage = ArrayBucket<I, sizeof(I)>;
return static_cast<Storage&> (*this);
}
}//(End)implementation details
@ -105,8 +92,10 @@ namespace lib {
: util::MoveAssign
{
protected:
size_t size_{0};
Bucket* data_{nullptr};
using Bucket = ArrayBucket<I>*;
size_t size_{0};
Bucket data_{nullptr};
public:
@ -126,7 +115,7 @@ namespace lib {
operator[] (size_t idx)
{
REQUIRE (data_);
return data_->access<I>().subscript (idx);
return data_->subscript (idx);
}
I& front() { return operator[] (size_-1); }

View file

@ -81843,19 +81843,13 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716907249314" ID="ID_1711986050" MODIFIED="1716907418033" TEXT="Bucket">
<node CREATED="1716907252393" ID="ID_198747165" MODIFIED="1716907259884" TEXT="der Descriptor"/>
<node CREATED="1716907260424" ID="ID_1362772717" MODIFIED="1716907268555" TEXT="liegt am Anfang der Element-Storage"/>
<node CREATED="1716912140198" ID="ID_9984568" MODIFIED="1716912197368" TEXT="erm&#xf6;glicht beliebigen Down-cast auf gegebene Storage-Gr&#xf6;&#xdf;e">
<linktarget COLOR="#a9b4c1" DESTINATION="ID_9984568" ENDARROW="Default" ENDINCLINATION="97;4;" ID="Arrow_ID_396222637" SOURCE="ID_581123494" STARTARROW="None" STARTINCLINATION="0;-15;"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716906944780" ID="ID_1643896091" MODIFIED="1716907418033" TEXT="ArrayBucket&lt;I,bytes&gt;">
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716906944780" ID="ID_1643896091" MODIFIED="1716912449577" TEXT="ArrayBucket&lt;I&gt;">
<node CREATED="1716907277198" ID="ID_104268426" MODIFIED="1716907281769" TEXT="Subklasse von Bucket"/>
<node CREATED="1716907312241" ID="ID_835337350" MODIFIED="1716907333394" TEXT="umspannt das Storage-Array"/>
<node CREATED="1716907260424" ID="ID_214476532" MODIFIED="1716912475418" TEXT="liegt am Anfang der Element-Storage"/>
<node CREATED="1716907312241" ID="ID_835337350" MODIFIED="1716912483271" TEXT="umspannt den Anfang vom Storage-Array"/>
<node COLOR="#338800" CREATED="1716907356091" ID="ID_1876919425" MODIFIED="1716912200686" TEXT="enth&#xe4;lt den subscript-Code">
<icon BUILTIN="button_ok"/>
<node BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1716912163674" ID="ID_581123494" MODIFIED="1716912308218" TEXT="mu&#xdf; hier einen offenen Downcast machen">
<node BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1716912163674" ID="ID_581123494" MODIFIED="1716912528793" TEXT="mu&#xdf; hier einen offenen Zugriff hinter das Objektende machen">
<richcontent TYPE="NOTE"><html>
<head>
@ -81867,15 +81861,30 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</body>
</html>
</richcontent>
<arrowlink DESTINATION="ID_9984568" ENDARROW="Default" ENDINCLINATION="97;4;" ID="Arrow_ID_396222637" STARTARROW="None" STARTINCLINATION="0;-15;"/>
<icon BUILTIN="messagebox_warning"/>
</node>
</node>
<node CREATED="1716907252393" ID="ID_1635839120" MODIFIED="1716907259884" TEXT="der Descriptor"/>
</node>
</node>
<node CREATED="1716909012702" ID="ID_1876994172" MODIFIED="1716909016713" TEXT="const-correctness">
<node CREATED="1716909019405" ID="ID_1406909807" MODIFIED="1716909042294" TEXT="ein const Several&lt;X&gt; ist ein Several&lt;const X&gt;"/>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1716914864769" ID="ID_966642586" MODIFIED="1716914906125" TEXT="Builder-Operationen">
<icon BUILTIN="pencil"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716914869721" ID="ID_756769385" MODIFIED="1716914902541" TEXT="basis-Allokation">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716914877848" ID="ID_1535626389" MODIFIED="1716914902541" TEXT="Gr&#xf6;&#xdf;en&#xe4;nderung Allokation">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716914886169" ID="ID_505410227" MODIFIED="1716914902542" TEXT="&#xc4;nderung Spread">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716914892972" ID="ID_1080699305" MODIFIED="1716914902543" TEXT="Platzieren neuer Daten">
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1715625082614" ID="ID_1575150785" MODIFIED="1715625089779" TEXT="SeveralBuilder_test">