void grouped_vocabulary_tree<Point, K>::merge_maps(map<int, int>& map1, const map<int, int>& map2) { using iter = map<int, int>::iterator; using citer = map<int, int>::const_iterator; iter it1 = map1.begin(); citer it2 = map2.cbegin(); iter end1 = map1.end(); citer end2 = map2.cend(); while (it2 != end2) { bool done1 = it1 == end1; if (!done1 && it1->first == it2->first) { // element already in 1, just increase count it1->second += it2->second; ++it1; ++it2; } else { if (done1 || it1->first > it2->first) { // from c++11 docs: // The function optimizes its insertion time if position points to the element // that will follow the inserted element (or to the end, if it would be the last). map1.insert(it1, *it2); ++it2; } else { ++it1; // if map1 is large while map2 is small this will not give better than const time insertion } } } }
int Database::GetRecordByFields(const string tableName, map<string, string> fieldValues, vector< map<string, string> >* out, string sortField, bool bAsc) const { if (!Util::IsLetterNumberDash(tableName) || !Util::IsLetterNumberDash(sortField)) return 2; string order = " ORDER BY " + sortField + (bAsc ? " ASC;" : " DSC;"); string sql = "SELECT * FROM " + tableName + " WHERE "; auto it = fieldValues.cbegin(); while (it != fieldValues.cend()) { if (!Util::IsLetterNumberDash((*it).first)) return 2; sql.append(Util::ToUpper((*it).first + "='")); //*TODO: Check value sql.append((*it).second + "'"); ++it; if (it != fieldValues.cend()) sql.append(" AND "); } sql += order; return Exec(sql, out); }
void map_intersection(map<Key, Value>& lhs, map<Key, Value> const& rhs) { typedef typename map<Key, Value>::iterator input_iterator1; typedef typename map<Key, Value>::const_iterator input_iterator2; input_iterator1 it1 = lhs.begin(); input_iterator2 it2 = rhs.cbegin(); input_iterator1 end1 = lhs.end(); input_iterator2 end2 = rhs.cend(); while (it1 != end1 && it2 != end2) { if (it1->first == it2->first) { it1->second += it2->second; ++it1; ++it2; } else { if (it1->first < it2->first) { ++it1; } else { ++it2; } } } }
void EulerUtils::Display::printMap ( string itemName, const map<string, int>& data ) { cout << "in printMap" << endl; cout << "Printing " << itemName << "..." << endl; for ( auto i = data.cbegin(); i != data.cend(); i++ ) cout << i->first << ": " << i->second << endl; cout << endl; }
int Database::AddRecord(const string tableName, const map<string, string> newEntry) { if (!Util::IsLetterNumberDash(tableName)) return 2; string sql = "INSERT INTO " + tableName + " ("; auto it = newEntry.cbegin(); while(it != newEntry.cend()) { if (!Util::IsLetterNumberDash((*it).first)) return 2; if (Util::ToUpper((*it).first).compare("ID") == 0) { ++it; continue; } sql.append(Util::ToUpper((*it).first)); ++it; if (it != newEntry.cend()) sql.append(","); else sql.append(") "); } sql.append("VALUES("); it = newEntry.cbegin(); while (it != newEntry.cend()) { //*TODO: Check values sql.append("'" + (*it).second + "'"); ++it; if (it != newEntry.cend()) sql.append(","); else sql.append(");"); } return Exec(sql); }
void Model::AddFeasCat(map<string, int> feaofcat, string catname,int threshold) { auto itfc = feaofcat.cbegin(); int count = 1; while (itfc != feaofcat.cend()) { if (itfc->second <= threshold) { ++itfc; continue; } stringstream query; query<< "insert into fc (feature,cat,count) values ('" << itfc->first << "','" << catname << "'," << itfc->second << ")"; this->ExecuteSQL(query.str().c_str()); ++itfc; } }
std::string RelationManager::showMap(const map<const Class *, set<const Class *> > &map, std::string msg) const { std::string s; if (map.empty()) return ""; if (msg != "") s.append(msg + "\n"); for (auto i = map.cbegin(); i != map.cend(); i++) { s.append(i->first->getName() + ": "); for (auto j = i->second.cbegin(); j != i->second.cend(); j++) s.append((*j)->getName() + " "); s.append("\n"); } return s.append("\n"); }
bool Model::contained_in( map<unsigned int, shared_ptr<list< shared_ptr<pair_sc> > > > &m, const shared_ptr<pair_sc> & sc, bool opt, bool debug) { for( auto iitm = m.cbegin(); iitm != m.cend(); iitm ++) { if (sc->signature != (sc->signature | iitm->first)) continue; for ( auto il = iitm->second->begin(); il != iitm->second->end(); il++) { if( (*il)->contains(sc, fpfp_sim)) return true; } } if ( !opt) return false; for( auto iitm = m.begin(); iitm != m.end(); iitm ++) { if (iitm->first != (sc->signature | iitm->first)) continue; auto ed = iitm->second; //for ( unsigned i = 0; i < ed->size(); i++) { for ( auto il = ed->begin(); il != ed->end(); il++) { if ( ! (*il)->valid) { if (!debug) ed->erase(il++); continue; } if( sc->contains(*il, fpfp_sim)) { (*il)->clean_children(); if (debug) (*il)->valid = false; else ed->erase(il++); } } } return false; }
void Book::addTransactions(map<float, int>& _transactions) { if (_transactions.size() > 0) addTransactions(_transactions.cbegin(), _transactions.cend()); }
static int size(const map<unsigned int, shared_ptr<list<shared_ptr<pair_sc> > > > &m) { int s = 0; for( auto iitm = m.cbegin(); iitm != m.cend(); iitm ++) s += iitm->second->size(); return s; }