make multi ranges of specific sub range instances unique
This commit is contained in:
parent
41f2e60d6e
commit
c6914831af
5 changed files with 96 additions and 2 deletions
|
@ -6,12 +6,14 @@
|
|||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
//#include "base_def.h"
|
||||
#include "ranges/range_base.h"
|
||||
#include "ranges/index_base.h"
|
||||
|
||||
#include "rpack_num.h"
|
||||
#include "ranges/rpack_num.h"
|
||||
#include "ranges/multi_range_factory_product_map.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
@ -118,6 +120,7 @@ namespace MultiArrayTools
|
|||
* MultiRangeFactory *
|
||||
*************************/
|
||||
|
||||
// NOT THREAD SAVE
|
||||
template <class... Ranges>
|
||||
class MultiRangeFactory : public RangeFactoryBase
|
||||
{
|
||||
|
@ -132,6 +135,11 @@ namespace MultiArrayTools
|
|||
MultiRangeFactory(const std::shared_ptr<ContainerRange<T,Ranges...> >& cr);
|
||||
|
||||
virtual std::shared_ptr<RangeBase> create() override;
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<RangeBase> checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp);
|
||||
|
||||
};
|
||||
|
||||
/******************
|
||||
|
@ -449,10 +457,34 @@ namespace MultiArrayTools
|
|||
template <class... Ranges>
|
||||
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
||||
{
|
||||
mProd = checkIfCreated( std::dynamic_pointer_cast<oType>( mProd )->mSpace );
|
||||
setSelf();
|
||||
return mProd;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp)
|
||||
{
|
||||
std::shared_ptr<RangeBase> out;
|
||||
bool check = false;
|
||||
for(auto& x: MultiRangeFactoryProductMap::mAleadyCreated){
|
||||
if(x.second.size() == sizeof...(Ranges)){
|
||||
check = RPackNum<sizeof...(Ranges)-1>::checkIfCreated(ptp, x.second);
|
||||
if(check){
|
||||
out = x.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(not check){
|
||||
std::vector<std::intptr_t> pv(sizeof...(Ranges));
|
||||
RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv);
|
||||
MultiRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
|
||||
out = mProd;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/******************
|
||||
* MultiRange *
|
||||
******************/
|
||||
|
|
25
src/include/ranges/multi_range_factory_product_map.h
Normal file
25
src/include/ranges/multi_range_factory_product_map.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
#ifndef __multi_range_factory_product_map_h__
|
||||
#define __multi_range_factory_product_map_h__
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "ranges/rbase_def.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
class MultiRangeFactoryProductMap
|
||||
{
|
||||
public:
|
||||
|
||||
template <class... Ranges>
|
||||
friend class MultiRangeFactory;
|
||||
|
||||
private:
|
||||
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -227,7 +227,14 @@ namespace MultiArrayHelper
|
|||
std::vector<std::shared_ptr<RangeBase> >& v)
|
||||
{
|
||||
setRangeToVec(v, std::get<N>(rst));
|
||||
//v[N] = std::get<N>(rst);
|
||||
RPackNum<N-1>::RangesToVec(rst, v);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||
std::vector<std::intptr_t>& v)
|
||||
{
|
||||
v[N] = reinterpret_cast<std::intptr_t>( std::get<N>(rst).get() );
|
||||
RPackNum<N-1>::RangesToVec(rst, v);
|
||||
}
|
||||
|
||||
|
@ -285,6 +292,14 @@ namespace MultiArrayHelper
|
|||
resolveSetRange(std::get<tps-N-1>(rtp), orig, off, size);
|
||||
RPackNum<N-1>::resolveRangeType(orig, rtp, off+size, sizes...);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
||||
const std::vector<std::intptr_t>& a)
|
||||
{
|
||||
return reinterpret_cast<std::intptr_t>( std::get<N>(p).get() ) == a[N] and
|
||||
RPackNum<N-1>::checkIfCreated(p,a);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -416,6 +431,13 @@ namespace MultiArrayHelper
|
|||
return 1;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||
std::vector<std::intptr_t>& v)
|
||||
{
|
||||
v[0] = reinterpret_cast<std::intptr_t>( std::get<0>(rst).get() );;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||
std::vector<std::shared_ptr<RangeBase> >& v)
|
||||
|
@ -472,6 +494,13 @@ namespace MultiArrayHelper
|
|||
resolveSetRange(std::get<tps-1>(rtp), orig, off, size);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
||||
const std::vector<std::intptr_t>& a)
|
||||
{
|
||||
return reinterpret_cast<std::intptr_t>( std::get<0>(p).get() ) == a[0];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <IndexType IT>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
set(libmultiarray_a_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/lib/ranges/range_base.cc
|
||||
${CMAKE_SOURCE_DIR}/src/lib/ranges/anonymous_range.cc
|
||||
${CMAKE_SOURCE_DIR}/src/lib/ranges/multi_range_factory_product_map.cc
|
||||
)
|
||||
|
||||
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc")
|
||||
|
|
7
src/lib/ranges/multi_range_factory_product_map.cc
Normal file
7
src/lib/ranges/multi_range_factory_product_map.cc
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
#include "ranges/multi_range_factory_product_map.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > MultiRangeFactoryProductMap::mAleadyCreated;
|
||||
}
|
Loading…
Reference in a new issue