void EnsureCapacity(TContainer& container, typename TContainer::size_type index) { // if we need to resize if(container.size() <= index) { // then we shall resize! container.resize(index + 1); } }
friend typename TContainer::template rebind<result_of<TRecord>>::type select(const TContainer& recs, const select_query& q) { using TReturnContainer = typename TContainer::template rebind<result_of<TRecord> >::type; TReturnContainer ret; ret.reserve(recs.size()); for(const TRecord& cur : recs) { ret.push_back(select(cur, q)); } return ret; }
static QStringList toQStringList(TContainer inContainer) { QStringList outContainer; for (size_t index=0; index < inContainer.size(); ++index) { outContainer.append(QString::number(inContainer.at(index))); } return outContainer; };
inline std::vector<std::shared_ptr<TContainer> > split(TContainer & container, std::size_t const PARTS) { std::vector<std::shared_ptr<TContainer> > split_container; split_container.resize(PARTS); std::size_t const container_original_size = container.size(); for (long i = static_cast<long>(PARTS) - 1; i >= 0; --i) { std::size_t const part_size = container_original_size / PARTS + (container_original_size % PARTS > static_cast<std::size_t>(i)); split_container[i] = std::make_shared<TContainer>(std::make_move_iterator(std::next(container.end(), -part_size)), std::make_move_iterator(container.end()) ); // Make sure the container is smaller now if (container.size() > i * (container_original_size / PARTS + 1)) container.resize(i * (container_original_size / PARTS + 1)); } return split_container; }
hash_t Pearson_Compare(const TContainer& data) { hash_t hash; hash.fill(0); for (size_t j = 0; j < HASH_SIZE; ++j) { uint8_t subhash = etl::PEARSON_LOOKUP[(data[0] + j) % 256]; for (size_t i = 1; i < data.size(); ++i) { subhash = etl::PEARSON_LOOKUP[subhash ^ data[i]]; } hash[j] = subhash; } return hash; }
jobjectArray ToJavaArray(JNIEnv * env, jclass clazz, TContainer const & src, TToJavaFn && toJavaFn) { return ToJavaArray(env, clazz, begin(src), end(src), src.size(), forward<TToJavaFn>(toJavaFn)); }