|
|
@ -6,7 +6,196 @@ namespace ams
|
|
|
|
namespace narray
|
|
|
|
namespace narray
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> narray<T>::narray()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
length = 0;
|
|
|
|
|
|
|
|
data = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> int narray<T>::resize(const narray_size_t newlength)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int ret = narray_failure;
|
|
|
|
|
|
|
|
narray_size_t I;
|
|
|
|
|
|
|
|
T *newdata = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(newlength<=0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(data!=NULL) {delete[] data; data=NULL;}
|
|
|
|
|
|
|
|
length = 0;
|
|
|
|
|
|
|
|
ret = narray_success;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newdata = new(std::nothrow) T[newlength];
|
|
|
|
|
|
|
|
if(newdata==NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ret = narray_failure;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(I=0;I<length&I<newlength;I++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
newdata[I] = data[I];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(I=length;I<newlength;I++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
newdata[I] = T();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(data!=NULL) {delete[] data; data=NULL;}
|
|
|
|
|
|
|
|
data = newdata;
|
|
|
|
|
|
|
|
length = newlength;
|
|
|
|
|
|
|
|
ret = narray_success;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> narray<T>::narray(const narray<T>& other)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
narray_size_t I;
|
|
|
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
length = 0;
|
|
|
|
|
|
|
|
data = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this!=&other)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
res = this->resize(other.length);
|
|
|
|
|
|
|
|
if(res!=narray_success)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(I=0;I<length && I<other.length;I++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
data[I] = other.data[I];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> narray<T>& narray<T>::operator=(const narray<T>& other)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
narray_size_t I;
|
|
|
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this!=&other)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
res = this->resize(other.length);
|
|
|
|
|
|
|
|
if(res!=narray_success)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(I=0;I<length && I<other.length;I++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
data[I] = other.data[I];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> narray<T>& narray<T>::operator=(const std::vector<T>& other)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
narray_size_t I;
|
|
|
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this!=&other)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
res = this->resize(other.size());
|
|
|
|
|
|
|
|
if(res!=narray_success)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(I=0;I<length && I<other.size();I++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
data[I] = other.data[I];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> narray<T>::narray(const std::initializer_list<T> initlist)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
narray_size_t I;
|
|
|
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
length = 0;
|
|
|
|
|
|
|
|
data = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = this->resize(initlist.size());
|
|
|
|
|
|
|
|
if(res!=narray_success)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
I = 0;
|
|
|
|
|
|
|
|
for(T elem : initlist)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
data[I] = elem;
|
|
|
|
|
|
|
|
if(I<length) I++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> narray<T>::~narray()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
length = 0;
|
|
|
|
|
|
|
|
if(data!=NULL) {delete[] data; data=NULL;}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> T& narray<T>::operator[](const narray_size_t ind)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return data[ind];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> const T& narray<T>::operator[](const narray_size_t ind) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return data[ind];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> T& narray<T>::at(const narray_size_t ind)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return data[ind];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> const T& narray<T>::at(const narray_size_t ind) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return data[ind];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> void narray<T>::clear()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this->resize(0);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> void narray<T>::setall(const T& val)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
narray_size_t I;
|
|
|
|
|
|
|
|
int nthreads;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(length<narray_thread_sz)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(I=0;I<length;I++) data[I] = val;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//threaded operation
|
|
|
|
|
|
|
|
nthreads = std::thread::hardware_concurrency;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; //end namespace narray
|
|
|
|
}; //end namespace narray
|
|
|
|