diff --git a/build_linux64/libamscppnarray.linux64.a b/build_linux64/libamscppnarray.linux64.a index a322a05..04e2098 100644 Binary files a/build_linux64/libamscppnarray.linux64.a and b/build_linux64/libamscppnarray.linux64.a differ diff --git a/build_linux64/objstore/amscppnarray.o b/build_linux64/objstore/amscppnarray.o index 8a1f7f6..20758ff 100644 Binary files a/build_linux64/objstore/amscppnarray.o and b/build_linux64/objstore/amscppnarray.o differ diff --git a/build_linux64/tests b/build_linux64/tests index 43b6f9f..1beebae 100644 Binary files a/build_linux64/tests and b/build_linux64/tests differ diff --git a/include/amscppnarray/amscppnarray.hpp b/include/amscppnarray/amscppnarray.hpp index f921633..70ec991 100644 --- a/include/amscppnarray/amscppnarray.hpp +++ b/include/amscppnarray/amscppnarray.hpp @@ -4,17 +4,53 @@ #include #include #include +#include #include #include +#include namespace ams { namespace narray { +typedef int64_t narray_size_t; + +static const int narray_success = 1; +static const int narray_failure = -1; + +//problem size at which to begin using threaded operations +static const narray_size_t narray_thread_sz = 5000; + +//maximum number of threads to use +static const int narray_max_threads = 50; + template class narray { public: + narray_size_t length; + T *data; + + narray(); + narray(const narray& other); + narray& operator=(const narray& other); + narray& operator=(const std::vector& other); + narray(const std::initializer_list initlist); + ~narray(); + + int resize(const narray_size_t newlength); + + T& operator[](const narray_size_t ind); + const T& operator[](const narray_size_t ind) const; + T& at(const narray_size_t ind); + const T& at(const narray_size_t ind) const; + + void clear(); //erases all elements, sets size to 0 + void setall(const T& val); //sets all elements to val + + //Comparators + + //Operations }; diff --git a/include/amscppnarray/amscppnarray_impl.hpp b/include/amscppnarray/amscppnarray_impl.hpp index d17c725..b766755 100644 --- a/include/amscppnarray/amscppnarray_impl.hpp +++ b/include/amscppnarray/amscppnarray_impl.hpp @@ -6,7 +6,196 @@ namespace ams namespace narray { +template narray::narray() +{ + length = 0; + data = NULL; + + return; +} + +template int narray::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 narray::narray(const narray& 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 narray& narray::operator=(const narray& 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 narray& narray::operator=(const std::vector& 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 narray::narray(const std::initializer_list 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 narray::~narray() +{ + length = 0; + if(data!=NULL) {delete[] data; data=NULL;} + return; +} + +template T& narray::operator[](const narray_size_t ind) +{ + return data[ind]; +} + +template const T& narray::operator[](const narray_size_t ind) const +{ + return data[ind]; +} + +template T& narray::at(const narray_size_t ind) +{ + return data[ind]; +} + +template const T& narray::at(const narray_size_t ind) const +{ + return data[ind]; +} + +template void narray::clear() +{ + this->resize(0); + return; +} + +template void narray::setall(const T& val) +{ + narray_size_t I; + int nthreads; + if(length