Ejemplo n.º 1
0
void weight_manager::get_weight(sfv_t& fv) const {
  for (sfv_t::iterator it = fv.begin(); it != fv.end(); ++it) {
    double global_weight = get_global_weight(it->first);
    it->second *= global_weight;
  }
  fv.erase(remove_if(fv.begin(), fv.end(), is_zero()), fv.end());
}
Ejemplo n.º 2
0
void sort_and_merge(sfv_t& sfv) {
    if (sfv.size() <= 1) {
        return;
    }
    sort(sfv.begin(), sfv.end());

    typedef sfv_t::iterator iterator;
    iterator cur = sfv.begin();
    iterator end = sfv.end();
    for (iterator iter = cur+1; iter != end; ++iter) {
        if (iter->first == cur->first) {
            cur->second += iter->second;
        } else {
            ++cur;
            *cur = *iter;
        }
    }
    sfv.erase(cur+1, end);
}