2424
2525#include < core/vector.hpp>
2626#include < core/error.hpp>
27+ #include < core/library.hpp>
28+ #include < io/logger.hpp>
2729
2830namespace cubool {
2931
@@ -50,19 +52,47 @@ namespace cubool {
5052 }
5153
5254 void Vector::build (const index *rows, size_t nvals, bool isSorted, bool noDuplicates) {
53- RAISE_ERROR (NotImplemented, " This function is not implemented" );
55+ CHECK_RAISE_ERROR (rows != nullptr || nvals == 0 , InvalidArgument, " Null ptr rows array" );
56+
57+ this ->releaseCache ();
58+
59+ LogStream stream (*Library::getLogger ());
60+ stream << Logger::Level::Info
61+ << " Vector:build:" << this ->getDebugMarker () << " "
62+ << " isSorted=" << isSorted << " , "
63+ << " noDuplicates=" << noDuplicates << LogStream::cmt;
64+
65+ mHnd ->build (rows, nvals, isSorted, noDuplicates);
5466 }
5567
5668 void Vector::extract (index *rows, size_t &nvals) {
57- RAISE_ERROR (NotImplemented, " This function is not implemented" );
69+ CHECK_RAISE_ERROR (rows != nullptr || getNvals () == 0 , InvalidArgument, " Null ptr rows array" );
70+ CHECK_RAISE_ERROR (getNvals () <= nvals, InvalidArgument, " Passed arrays size must be more or equal to the nvals of the vector" );
71+
72+ this ->commitCache ();
73+ mHnd ->extract (rows, nvals);
5874 }
5975
6076 void Vector::extractSubVector (const VectorBase &otherBase, index i, index nrows, bool checkTime) {
6177 RAISE_ERROR (NotImplemented, " This function is not implemented" );
6278 }
6379
6480 void Vector::clone (const VectorBase &otherBase) {
65- RAISE_ERROR (NotImplemented, " This function is not implemented" );
81+ const auto * other = dynamic_cast <const Vector*>(&otherBase);
82+
83+ CHECK_RAISE_ERROR (other != nullptr , InvalidArgument, " Passed vector does not belong to core vector class" );
84+
85+ if (this == other)
86+ return ;
87+
88+ auto M = other->getNrows ();
89+
90+ CHECK_RAISE_ERROR (M == this ->getNrows (), InvalidArgument, " Cloned vector has incompatible size" );
91+
92+ other->commitCache ();
93+ this ->releaseCache (); // Values of this vector won't be used any more
94+
95+ mHnd ->clone (*other->mHnd );
6696 }
6797
6898 void Vector::reduce (index &result, bool checkTime) {
@@ -74,19 +104,20 @@ namespace cubool {
74104 }
75105
76106 index Vector::getNrows () const {
77- RAISE_ERROR (NotImplemented, " This function is not implemented " );
107+ return mHnd -> getNrows ( );
78108 }
79109
80110 index Vector::getNvals () const {
81- RAISE_ERROR (NotImplemented, " This function is not implemented" );
111+ this ->commitCache ();
112+ return mHnd ->getNvals ();
82113 }
83114
84115 void Vector::releaseCache () const {
85- RAISE_ERROR (NotImplemented, " This function is not implemented " );
116+ mCachedI . clear ( );
86117 }
87118
88119 void Vector::commitCache () const {
89- RAISE_ERROR (NotImplemented, " This function is not implemented " );
120+ // todo
90121 }
91122
92123}
0 commit comments