Commit a7232f77 authored by incardon's avatar incardon
Browse files

Fixing Membal out of bound

parent 90fc33fd
......@@ -37,12 +37,16 @@
*/
class Mem_bal
{
//! vector that store the information
typedef openfpm::vector<size_t> base;
//! each cell has a pointer to a dynamic structure
// that store the elements in the cell
openfpm::vector<base> cl_base;
//! Invalid element
size_t invalid;
public:
inline void init_to_zero(size_t slot, size_t tot_n_cell)
......@@ -109,11 +113,17 @@ public:
inline const size_t & getStartId(size_t part_id) const
{
if (cl_base.get(part_id).size() == 0)
return invalid;
return cl_base.get(part_id).get(0);
}
inline const size_t & getStopId(size_t part_id) const
{
if (cl_base.get(part_id).size() == 0)
return invalid;
return *(&cl_base.get(part_id).last() + 1);
}
......
......@@ -32,28 +32,49 @@
*/
class Mem_mw
{
//! Base type storing information
typedef openfpm::vector<size_t> base;
// each cell has a dynamic structure
// that store the elements in the cell
//! each cell has a dynamic structure
//! that store the elements in the cell
std::unordered_map<size_t,base> cl_base;
//! In case of invalid element return this
typename std::remove_reference<decltype(std::declval<openfpm::vector<size_t>>().get(0))>::type invalid;
openfpm::vector<size_t> invalid_v;
public:
/*! \brief Initialize the data structure to zeros
*
* In this case it does nothing
*
* \param slots
* \param tot_n_cell total number of cells
*
*/
inline void init_to_zero(size_t slot, size_t tot_n_cell)
{
}
/*! \brief Copy two data-structure
*
* \param cell data-structure to copy
*
* \return itself
*
*/
inline Mem_mw & operator=(const Mem_mw & cell)
{
cl_base = cell.cl_base;
return *this;
}
/*! \brief Add an element to the cell
*
* \param cell_id cell-id
* \param ele element to add
*
*/
inline void addCell(size_t cell_id, typename base::value_type ele)
{
//add another neighbor element
......@@ -61,16 +82,35 @@ public:
cl_base[cell_id].add(ele);
}
/*! \brief Add an element to the cell
*
* \param cell_id cell-id
* \param ele element to add
*
*/
inline void add(size_t cell_id, typename base::value_type ele)
{
this->addCell(cell_id,ele);
}
/*! \brief Remove an element from the cell
*
* \param cell cell-id
* \param ele element to remove
*
*/
inline void remove(size_t cell, size_t ele)
{
cl_base[cell].remove(ele);
}
/*! \brief Get the number of elements in the cell
*
* \param cell_id
*
* \return the number of elements
*
*/
inline size_t getNelements(const size_t cell_id) const
{
auto it = cl_base.find(cell_id);
......@@ -89,14 +129,6 @@ public:
return it->second.get(ele);
}
inline auto get_v(size_t cell) -> decltype(cl_base[0]) &
{
auto it = cl_base.find(cell);
if (it == cl_base.end())
return invalid_v;
return it->second;
}
inline auto get(size_t cell, size_t ele) const -> decltype(cl_base.find(cell)->second.get(0)) &
{
......@@ -107,15 +139,6 @@ public:
return it->second.get(ele);
}
inline auto get_v(size_t cell) const -> const decltype(cl_base.find(cell)->second) &
{
auto it = cl_base.find(cell);
if (it == cl_base.end())
return invalid_v;
return it->second;
}
inline void swap(Mem_mw & cl)
{
cl_base.swap(cl.cl_base);
......@@ -135,7 +158,7 @@ public:
{
auto it = cl_base.find(part_id);
if (it == cl_base.end())
return *(&invalid_v.get(0));
return *(&invalid);
return it->second.get(0);
}
......@@ -144,7 +167,7 @@ public:
{
auto it = cl_base.find(part_id);
if (it == cl_base.end())
return *(&invalid_v.get(0));
return *(&invalid);
return *(&it->second.last() + 1);
}
......@@ -157,7 +180,8 @@ public:
public:
inline Mem_mw(size_t slot)
{}
{
}
inline void set_slot(size_t slot)
{}
......
......@@ -158,22 +158,49 @@ public:
// Setter method
//! set the x property
/*! \brief set the x property
*
* \param x_
*
*/
inline void setx(T x_) {boost::fusion::at_c<0>(data) = x_;};
//! set the y property
/*! \brief set the y property
*
* \param y_
*
*/
inline void sety(T y_) {boost::fusion::at_c<1>(data) = y_;};
//! set the z property
/*! \brief set the z property
*
* \param z_
*
*/
inline void setz(T z_) {boost::fusion::at_c<2>(data) = z_;};
//! set the s property
/*! \brief set the s property
*
* \param s_
*
*/
inline void sets(T s_) {boost::fusion::at_c<3>(data) = s_;};
//! set the v property
/*! \brief set the v property
*
* \param i component to set
* \param v_ value
*
*/
inline void setv(size_t i,T v_) {boost::fusion::at_c<4>(data)[i] = v_;}
//! set the t property
/*! \brief set the t property
*
* \param i component to set
* \param j component to set
* \param t_ value
*
*/
inline void sett(size_t i, size_t j,T t_) {boost::fusion::at_c<5>(data)[i][j] = t_;}
......@@ -184,7 +211,11 @@ public:
Point_test()
{}
//! check if two point match
/*! \brief check if two point match
*
* \param p point to compare
*
*/
bool operator==(const Point_test<float> & p) const
{
if (boost::fusion::at_c<0>(data) != boost::fusion::at_c<0>(p.data)) return false;
......@@ -206,7 +237,13 @@ public:
return true;
}
//! check if two point match
/*! \brief Sum the point
*
* \param p point to sum
*
* \return this
*
*/
Point_test<float> & operator+=(const Point_test<float> & p)
{
boost::fusion::at_c<0>(data) += boost::fusion::at_c<0>(p.data);
......@@ -226,7 +263,11 @@ public:
return *this;
}
//! constructor from encapg
/*! \brief Copy constructor from encapc (encapsulated point)
*
* \param p ecapsulated point
*
*/
template <unsigned int dim, typename Mem> inline Point_test(const encapc<dim,Point_test<T>,Mem> & p)
{
boost::fusion::at_c<0>(data) = p.template get<0>();
......@@ -246,7 +287,11 @@ public:
}
}
//! constructor from another point
/*! \brief constructor from another point
*
* \param p point to copy
*
*/
inline Point_test(const Point_test<T> & p)
{
boost::fusion::at_c<0>(data) = boost::fusion::at_c<0>(p.data);
......@@ -266,7 +311,13 @@ public:
}
}
//! constructor from another point
/*! \brief Copy the point
*
* \param p point
*
* \return this
*
*/
inline Point_test<T> operator= (const Point_test<T> & p)
{
boost::fusion::at_c<0>(data) = boost::fusion::at_c<0>(p.data);
......@@ -377,13 +428,32 @@ public:
// Setter method
//! set the property x
/*! \brief set the x property
*
* \param x_
*
*/
inline void setx(T x_) {boost::fusion::at_c<0>(data) = x_;};
//! set the property y
/*! \brief set the y property
*
* \param y_
*
*/
inline void sety(T y_) {boost::fusion::at_c<1>(data) = y_;};
//! set the property z
/*! \brief set the z property
*
* \param z_
*
*/
inline void setz(T z_) {boost::fusion::at_c<2>(data) = z_;};
//! set the property s
/*! \brief set the s property
*
* \param s_
*
*/
inline void sets(T s_) {boost::fusion::at_c<3>(data) = s_;};
//! Attributes name
......@@ -440,7 +510,14 @@ public:
}
}
//! constructor from another point
/*! \brief Copy the point
*
* \param p point
*
* \return this
*
*/
inline Point_test_prp<T> operator= (const Point_test<T> & p)
{
boost::fusion::at_c<0>(data) = boost::fusion::at_c<0>(p.data);
......
......@@ -70,9 +70,13 @@ struct aggregate
template<typename ... list>
struct aggregate
{
//! internal type containing the data
typedef boost::fusion::vector<list...> type;
//! real internal type containing the data
typedef boost::fusion::vector<list...> type_real;
//! the data
type data;
/*! \brief get the properties i
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment