void insert(It b, It e) { size_t d = std::distance(b, e); if (d == 1) { insert(*b); return; } static container merged; merged.resize(0); merged.reserve(elements.size() + d); if (detail::is_sorted(b, e, comp)) { std::merge(elements.begin(), elements.end(), b, e, std::back_inserter(merged), comp); } else { static container sorted; sorted.assign(b, e); std::sort(sorted.begin(), sorted.end(), comp); std::merge(elements.begin(), elements.end(), sorted.begin(), sorted.end(), std::back_inserter(merged), comp); } merged.swap(elements); iterator it = std::unique(elements.begin(), elements.end()); elements.erase(it, elements.end()); }
inline string Join(const string& delim, const container& c) { ostringstream ret; typedef typename container::const_iterator iterator; for( iterator q = c.begin(); q != c.end(); ++q ) { if( q != c.begin() ) ret << delim; ret << *q; } return ret.str(); }
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); }
heuristic_trainer::heuristic_trainer(container & heuristic_word_files, super_container & file_names_by_subject, std::vector<std::string> & output_names) : bayesian_trainer(output_names) { //initialise the maps with the words container heuristic_words; probability_maps = std::list<word_map>(3); files_to_words(heuristic_word_files.begin(), heuristic_word_files.end(), std::back_inserter(heuristic_words)); for(word_map & map : probability_maps) { std::for_each(heuristic_words.begin(), heuristic_words.end(), words_to_map(map)); } // calculate n and vocab size and fill in the corpera containers corpera_by_subject = super_container(3); std::set<std::string> vocab_set; super_container::iterator corpera_it = corpera_by_subject.begin(); for (container & subject : file_names_by_subject) { files_to_words(subject.begin(), subject.end(), std::back_inserter<container>(*corpera_it)); vocab_set.insert<container::iterator>(corpera_it->begin(), corpera_it->end()); ++corpera_it; } }
void make_vector_zeroes( container & vec, const typename container::size_type & d1) { vec.resize(d1); for(auto it=vec.begin(); it!=vec.end(); ++it) { set_zero(*it); } }
void make_vector_default( container & vec, const typename container::size_type & d1, const typename container::size_type & d2, Args... remaining_dims) { vec.clear(); vec.resize(d1); for(auto it=vec.begin(); it!=vec.end(); ++it) { make_vector_default(*it, d2, remaining_dims...); } }
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()); } }
void make_vector_default( container & vec, const typename container::size_type & d1) { static_assert(std::is_default_constructible<typename container::value_type>::value, "make_default_vector requires that object type is default-constructible."); for(auto it=vec.begin(); it!=vec.end(); ++it) { *it = typename container::value_type(); } vec.resize(d1); }
vector_valuer(container & vec, const value_type & val, const other_container & other_vec) { vec.resize(other_vec.size()); auto o_it = other_vec.begin(); for(auto it=vec.begin(); it!=vec.end(); ++it) { vector_valuer<d-1,decltype(*it),value_type,decltype(*o_it)>(*it,val,*o_it); } }
vector_defaulter(container & vec, const other_container & other_vec) { vec.resize(other_vec.size()); auto o_it = other_vec.begin(); for(auto it=vec.begin(); it!=vec.end(); ++it) { vector_defaulter<d-1,decltype(*it),decltype(*o_it)>(*it,*o_it); } }
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); }
static std::set<core::identifier_string> find_variable_names(const container& equations) { std::set<pbes_system::propositional_variable_instantiation> occ; auto oit = std::inserter(occ, occ.end()); std::set<core::identifier_string> occ_ids; for(auto it = equations.begin(); it != equations.end(); ++it) { pbes_system::detail::make_find_propositional_variables_traverser<pbes_system::pbes_expression_traverser>(oit).apply(it->formula()); occ_ids.insert(it->variable().name()); } for(auto it = occ.begin(); it != occ.end(); ++it) { occ_ids.insert(it->name()); } return occ_ids; }
void make_vector_function( container & vec, const func_type & func, const typename container::size_type & d1, const typename container::size_type & d2, Args... remaining_dims) { vec.clear(); vec.resize(d1); typename container::size_type i(0); auto new_func = [&] (const typename container::size_type & i2, Args... remaining_is) { return func(i,i2,remaining_is...); }; for(auto it=vec.begin(); it!=vec.end(); ++it) { make_vector_function(*it, new_func, d2, remaining_dims...); ++i; } }
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; } }
memory(const container& source) : memory(source._size) { std::copy( source.begin(), source.end(), iterator {_data}); };
void to_upper(container & c) { hnc::algo::to_upper(c.begin(), c.end()); }
void print_vec(const container& vec) { for(typename container::const_iterator it = vec.begin(); it != vec.end(); ++it) std::cout << *it << ' '; std::cout << std::endl; }