Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/utility/external/FullyDistMultiVec.hpp
Go to the documentation of this file.
00001 #ifndef FULLY_DIST_MULTI_VEC_HPP
00002 #define FULLY_DIST_MULTI_VEC_HPP
00003 
00004 #include "CombBLAS.h"
00005 
00006 template <typename IndexType, typename ValueType>
00007 struct FullyDistMultiVec {
00008   typedef IndexType index_t; 
00009   typedef ValueType value_t;
00010   typedef FullyDistVec<IndexType, ValueType> mpi_vector_t;
00011   typedef std::vector<mpi_vector_t*> container_t;
00012 
00013   index_t dim;
00014   index_t size;
00015   container_t multi_vec_container;
00016 
00017   void clear () { 
00018     for (index_t i=0; i<size; ++i) 
00019       if (NULL!=multi_vec_container[i]) 
00020         delete multi_vec_container[i];
00021   }
00022 
00023   FullyDistMultiVec (const FullyDistMultiVec& other) :
00024     dim (other.dim), size(other.size), multi_vec_container (size) {
00025     for (index_t i=0; i<size; ++i) 
00026       multi_vec_container[i] = new mpi_vector_t(other[i]);
00027   }
00028 
00032   FullyDistMultiVec (index_t dim, 
00033                      index_t size, 
00034                      value_t init_val=0.0) : 
00035                      dim(dim), size(size), multi_vec_container(size) {
00036     for (index_t i=0; i<size; ++i) 
00037       multi_vec_container[i] = new mpi_vector_t(dim,init_val);
00038   }
00039 
00040   mpi_vector_t& operator[](index_t i) { return *(multi_vec_container[i]); }
00041 
00042   mpi_vector_t& operator[](index_t i) const {return *(multi_vec_container[i]);}
00043 
00044   void operator=(const FullyDistMultiVec& other) {
00045     clear();
00046     dim = other.dim;
00047     size = other.size;
00048     multi_vec_container.resize(other.size);
00049     for (index_t i=0; i<size; ++i) 
00050       multi_vec_container[i] = new mpi_vector_t(other[i]);
00051   }
00052 };
00053 
00054 #endif // FULLY_DIST_MULTI_VEC_HPP