template<int N,typename H,typename T>
struct red_blue_boll{
typedef std::map<H,typename red_blue_boll<N-1,H,T>::red_blue_type > red_blue_type;
public:
template<int COUNTS>
static void fill_rb_boll_data(red_blue_type& dst,const H (&vals)[COUNTS]){
const H& val_index = vals[COUNTS - N - 1];
typename red_blue_boll<N-1,H,T>::red_blue_type& top_dst = dst[val_index];
red_blue_boll<N-1,H,T>::fill_rb_boll_data(boost::ref(top_dst),vals);
}
public:
static int get_leaf_counts(const red_blue_type& dst, int leal){
if(N == leal){
return dst.size();
}
typename red_blue_type::const_iterator b = dst.begin();
typename red_blue_type::const_iterator e = dst.end();
int count = 0;
for(; b != e;++b){
count += red_blue_boll<N-1,H,T>::get_leaf_counts(b->second,leal);
}
return count;
}
static int calc_number_counts(const red_blue_type& dst,int leal,std::map<int,int>& rst){
typename red_blue_type::const_iterator b = dst.begin();
typename red_blue_type::const_iterator e = dst.end();
if(N == leal){
for(; b != e; ++b){
rst[b->first] += red_blue_boll<N-1,H,T>::get_leaf_counts(b->second,0);
}
return rst.size();
}else{
int count = 0;
for(; b !=e ; ++b){
count += red_blue_boll<N-1,H,T>::calc_number_counts(b->second,leal,boost::ref(rst));
}
return count;
}
}
public:
template<int COUNTS>
static void set_rb_boll_inst(const cp_data (&src)[COUNTS],red_blue_type& dst){
for(int i = 0; i < COUNTS; ++i){
fill_rb_boll_data(boost::ref(dst),src[i].vals);
}
}
};
template<typename H,typename T>
struct red_blue_boll<0,H,T>{
typedef T red_blue_type;
public:
template<int COUNTS>
static void fill_rb_boll_data(red_blue_type& dst,const H (&vals)[COUNTS]){
dst.push_back(vals[COUNTS - 1]);
}
static int get_leaf_counts(const red_blue_type& dst, int leal){
return dst.size();
}
static int calc_number_counts(const red_blue_type& dst,int leal,std::map<int,int>& rst){
red_blue_type::const_iterator b = dst.begin();
red_blue_type::const_iterator e = dst.end();
for(; b != e ; ++b){
rst[*b] += 1;
}
return rst.size();
}
};
一个有意思的类型实现,可惜是个半成品
最新推荐文章于 2021-08-26 00:47:37 发布