void reserve(size_type n) { if (size_ == 0) { elements.resize(n, std::make_pair(res_empty, V())); return; } static container vals; vals.resize(0); vals.reserve(size_); for (size_type i = 0, ie = capacity(); i < ie; ++i) { if (elements[i].first != res_empty && elements[i].first != res_del) { vals.push_back(elements[i]); } } clear(n); size_ = vals.size(); size_t max = capacity() - 1; for (size_type i = 0, ie = vals.size(); i < ie; ++i) { size_t spot = hash_value(vals[i].first) & max; while (elements[spot].first != res_empty && elements[spot].first != vals[i].first) { spot = (spot + 5) & max; } elements[spot] = vals[i]; } }
int global_gene_init() { //gene init int op_total=g_gene_cell_meta_pool.size(); vector< vector<gene_cell_meta_t> > gene_cell_meta_vv; vector< gene_cell_meta_t> dest; LOG_DEBUG<<"op_total:"<<op_total<<std::endl; for(int i=0;i<op_total;i++) { gene_cell_meta_t *pgene_cell_meta=g_gene_cell_meta_pool.get(i); if(pgene_cell_meta) { vector<gene_cell_meta_t> gene_cell_meta_v; gene_cell_meta_v.clear(); gene_cell_meta_t gene_cell_meta; gene_cell_data_t gene_cell_data; gene_cell_data_t *pgene_cell_data; pgene_cell_data=g_gene_cell_data_pool.get(pgene_cell_meta->did); for(int j=0;j<pgene_cell_meta->cn;j++) { memcpy(&gene_cell_meta, pgene_cell_meta, sizeof(gene_cell_meta_t)); memcpy(&gene_cell_data, pgene_cell_data, sizeof(gene_cell_data_t)); gene_cell_data.cn=j; int data_idx=g_gene_cell_data_pool.put(gene_cell_data); gene_cell_meta.did=data_idx; gene_cell_meta_v.push_back(gene_cell_meta); int meta_idx=g_gene_cell_meta_pool.put(gene_cell_meta); } LOG_DEBUG<<"gene_cell_meta_v.size: "<<gene_cell_meta_v.size()<<std::endl; gene_cell_meta_vv.push_back(gene_cell_meta_v); } LOG_DEBUG<<"gene_cell_meta_vv.size: "<<gene_cell_meta_vv.size()<<std::endl; } /*gene gene_pool * */ //gene all the genome if(gene_cell_meta_vv.size() < 6) { gene_generate(gene_cell_meta_vv.begin() , gene_cell_meta_vv.end(), dest, g_gene_meta_pool); LOG_DEBUG<<"g_gene_meta_pool.size:"<<g_gene_meta_pool.size()<<std::endl; }else if(gene_cell_meta_vv.size() > 10) { /* gene small gene half gene full */ }else { /* gene small gene full */ } return 0; }
long long int findSmallestScalarProduct(container x, container y) { long long int zero = 0; if(x.size() != y.size()) { std::cout << "Containers Are Not Same Length!\n"; throw -1; } ascend_sort(x.begin(),x.end()); descend_sort(y.begin(),y.end()); return std::inner_product(x.begin(),x.end(),y.begin(),zero); }
void container::copy(size_t i, container const &other, size_t l, size_t r) { if (r <= l) throw std::invalid_argument( "big_integer: container: in function copy(): left bound is larger than the right one" ); if (r - l == 1 && sz == 0) { sz = 1; data_short = *(other.data_long->begin() + l); return; } if (sz == 1) data_long = std::make_shared< std::vector<uint32_t> > (1, data_short); else real_copy(); if (other.size() == 1) data_long->insert(data_long->begin() + i, other.data_short); else std::copy(other.data_long->begin() + l, other.data_long->begin() + r, this->data_long->begin() + i ); sz = data_long->size(); }
inline void push_front(const container<T>& aOther) { if (&aOther == this) throw std::runtime_error("P12218319::deque::push_front : Cannot push self"); const uint32_t s = size(); reserve(s + aOther.size()); single_for<const container<T>&>(aOther, 0, s, [this](const T& aValue)->void { push_front(aValue); }); }
BigData getRightPart(){ char halfSize = data.size() / 2; container buffer; for (char i = 0; i < halfSize; i++) buffer.push_back(data[i]); return BigData(buffer); }
matrix(size_type N, size_type M, container<T> vector) : vec(N * M), rows(N), columns(M) { if (vector.size() == N * M) { std::copy(vector.begin(), vector.end(), vec.begin()); } }
template <template <class> class container, class T> void print(container<T>& vec) { printf("vector - size(%u) capacity(%u)\n", vec.size(), vec.capacity()); for (auto it = vec.begin(); it != vec.end(); ++it) print(*it); //test const version printf("test const version\n"); const container<T>& const_vec = vec; for (auto it : vec) print(it); }
int global_genome_init() { int size=g_gene_meta_pool.size(); int cell_num; int gene_num; genome_meta_t *pgenome_meta=g_genome_meta_pool.get(-1); cell_num=sizeof(g_gene_chaos)/sizeof(g_gene_chaos[0]); gene_num=g_gene_meta_pool.size(); pgenome_meta->cell_num=cell_num; pgenome_meta->gene_num=gene_num; for(int i=0;i<g_gene_meta_pool.total;i++) { gene_meta_t *pgene_meta=g_gene_meta_pool.get(i); if(pgene_meta) { pgene_meta->gene_cells[i]=i; pgene_meta->cell_cases[i]; /* typedef struct genome_meta{ uint8_t *gene_cell_feas; uint8_t gene_cells[10]; uint16_t cell_num; uint16_t gene_num; } genome_meta_t; typedef struct gene_meta{ uint8_t gene_cells[10]; uint8_t cell_cases[10]; uint8_t cnums; gene_action action; }gene_meta_t; */ } } return 0; }
BigData getLeftPart(){ char halfSize = data.size() / 2; container buffer; container test = data; while (test.size() > 1 && test[test.size() - 1] == 0) { test.pop_back(); } if (test.size() > 1) { for (char i = 0; i < halfSize; i++) buffer.push_back(data[i + halfSize]); } if (!buffer.size()) buffer.push_back(0); return BigData(buffer); }
double median(container l) { typedef container::size_type l_sz; l_sz size = l.size(); if (size == 0) throw std::domain_error("median of an empty list"); l.sort(); std::size_t mid = size / 2; const_iter it = l.begin(); for(std::size_t i = 0; i != mid; ++i) { ++it; } if (size % 2 == 0) { const_iter base = it--; return (*base + *it) / 2; } else { return *it; } }