本文整理汇总了C++中unordered_map::at方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::at方法的具体用法?C++ unordered_map::at怎么用?C++ unordered_map::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_map
的用法示例。
在下文中一共展示了unordered_map::at方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: beFriend
void beFriend(string s1, string s2){
if(graph.find(s1) == graph.end())//Finish statment
graph.emplace(s1,node(s1));
if(graph.find(s2) == graph.end())
graph.emplace(s2, node(s2));
graph.at(s1).attach(&graph.at(s2));
}
示例2: read
shared_ptr<Event> read()
{
uint8_t buffer_in[3];
snd_rawmidi_read(handle_in, &buffer_in, 3);
shared_ptr<NoteOnEvent> note_on, note_off;
switch ( buffer_in[0] & 0xF0 )
{
case MIDI_NOTE_ON:
if ( buffer_in[2] )
{
note_on = shared_ptr<NoteOnEvent>(new NoteOnEvent { buffer_in[1], buffer_in[2] });
open_notes.emplace(buffer_in[1], note_on);
return note_on;
}
else
{
note_on = open_notes.at(buffer_in[1]);
open_notes.erase(buffer_in[1]);
return shared_ptr<Event>(new NoteOffEvent { note_on });
}
case MIDI_NOTE_OFF:
note_on = open_notes.at(buffer_in[1]);
open_notes.erase(buffer_in[1]);
return shared_ptr<Event>(new NoteOffEvent { note_on });
case MIDI_CONTROL:
return shared_ptr<Event>(new ControlEvent { static_cast<ControlEvent::Controller>(buffer_in[1]), buffer_in[2] });
default:
return shared_ptr<Event>(new Event {});
}
}
示例3: populateVec7Messages
bool populateVec7Messages(unordered_map<string,string>& htabVecMessages){
ifstream infile(vec7messagesFileName);
if(infile.is_open()){
string line;
while(getline(infile,line)){
if(line.find(",") != string::npos){
vector<string> messageLine = splitStringByDelimiter(line,',');
if(messageLine.size() == 2){
string key = trimWhiteSpaces(messageLine[0]);
string value = messageLine[1];
if(htabVecMessages.find(key) != htabVecMessages.end()){
string temp = htabVecMessages.at(key);
temp = temp + ";" + value;
htabVecMessages.at(key) = temp;
}
else
htabVecMessages.insert(make_pair<string,string>(key,value));
}
}
}
infile.close();
}
else
return false;
return true;
}
示例4: UpdateArrow
void UpdateArrow(const Arrow &a) {
if (status_by_arrow.count(a) > 0)
return;
int node2 = ArrowEnd(a);
Status status = statii.at(a.first);
bool found_reverse = false;
for (const auto &ia : incoming_arrows.at(a.first)) {
assert(ArrowEnd(ia) == a.first);
//cout << " ia " << ia << " " << ArrowEnd(ia) << endl;
if (ia.first == node2) {
found_reverse = true;
continue;
}
UpdateArrow(ia);
status.Merge(status_by_arrow.at(ia));
}
// cout << "UA " << a << " " << node2 << endl;
assert(!incoming_arrows.at(a.first).empty()); // todo: remove in non-tree case
if (!incoming_arrows.at(a.first).empty())
assert(found_reverse);
status_by_arrow[a] = status.Translate(a.second, dfa);
}
示例5: make_pair
/* get_code_indexes */
pair<unsigned long, unsigned long> get_code_indexes(string& origin,
string& destin, unordered_map<string, unsigned long> code_index_map) {
bool bad_origin = false;
bool bad_destin = false;
unsigned long origin_index;
unsigned long destin_index;
try {
origin_index = code_index_map.at(origin);
} catch(out_of_range& e) {
bad_origin = true;
}
try {
destin_index = code_index_map.at(destin);
} catch(out_of_range& e) {
bad_destin = true;
}
if(bad_origin && bad_destin) {
cerr << "\nTerminating: The origin & destin airport codes provided were not found" << endl;
exit(1);
} else if(bad_origin) {
cerr << "\nTerminating: The origin airport code provided was not found" << endl;
exit(1);
} else if(bad_destin) {
cerr << "\nTerminating: The destin airport code provided was not found" << endl;
exit(1);
}
return make_pair(origin_index, destin_index);
}
示例6: get_value_ides
void get_value_ides(string id, unsigned long threshold){
timeb first_uniq;
ftime(&first_uniq);
string snps = "[\"OK\",[";
unsigned long index = ides_name_index.at(id);
unsigned long related_samples = 0;
for(unsigned long i=0; i<num_samples; i++){
if(matrix[index][i] <= threshold && i!=index){
snps.append("\""+ides_index_name.at(i)+"\"").append(",");
related_samples++;
}
}
//f(snps.length() > 0) snps.pop_back();
if(snps.length() > 0 && related_samples>0) snps.pop_back();
snps.append("]]");
cout << snps << endl;
timeb end_first_uniq;
ftime(&end_first_uniq);
int dif = (int)((end_first_uniq.time*1000+end_first_uniq.millitm)-(first_uniq.time*1000+first_uniq.millitm));
write_log("{action:get_value, time:"+std::to_string(dif)+", date:"+current_date_time()+"}");
}
示例7: user_predictions
void user_predictions(unordered_map<string, size_t> &items, unordered_map<string, size_t> &users,
vector<vector<float>> &items_stats, vector<vector<float>> &users_stats,
vector<vector<pair<size_t, float>>> &ranking_user, vector<vector<string>> &targets,
vector<size_t> target_users,
vector<float> &predictions, vector<float> &missing_predictions, float **users_fvs) {
for (size_t index = 0; index < targets.size(); index++) {
float item_avg = 5;
// getting the item bias
size_t item_pos;
if (items.find(targets[index][1]) != items.end()) {
item_pos = items.at(targets[index][1]);
item_avg = items_stats[item_pos][1];
if (item_avg == 0)
item_avg = 5;
}
// Look for the user within the ranking
if (users.find(targets[index][0]) != users.end()) {
float user_avg = 0;
size_t query_pos =users.at(targets[index][0]);
// Capturing the average rating from the nearest neighbors of the user
float base = 0;
size_t target_user_index = find_by_value<size_t>(target_users, query_pos);
for (size_t vect_index = 0; vect_index < NN; vect_index++) {
size_t user_pos = ranking_user[target_user_index][vect_index].first;
float value = users_fvs[user_pos][item_pos];
if ((value == 0) || isnan(value))
value = users_stats[user_pos][1];
#ifdef DEBUG
cout << ranking_user[target_user_index][vect_index].second << "*" << value << endl;
#endif
user_avg += ranking_user[target_user_index][vect_index].second * value;
base += ranking_user[target_user_index][vect_index].second;
}
// Average them
user_avg /= base;
if (base == 0) {
predictions.push_back(item_avg);
missing_predictions.push_back(index);
}
else
predictions.push_back(user_avg);
}
else {
predictions.push_back(item_avg);
if (items.find(targets[index][1]) == items.end())
missing_predictions.push_back(index);
}
// if (index == targets.size() - 1)
// cout << "Last" << endl;
}
}
示例8: printGraph
void printGraph(){
queue<node*> list;
list.push(&graph.at("Quinn"));
while(!list.empty()){
node*n = list.front();
list.pop();
for(node* n2 : n->neighbours){
if(n2->visited == false){
list.push(n2);
n2->depth=(n->depth+1);
n2->visited = true;
}
}
}
vector<string> vec;
for(auto ele = graph.begin(); ele != graph.end(); ++ele){
string s = "";
if(ele->second.depth < 0)
s = ele->first + " uncool";
else
s= ele->first + " " + to_string(ele->second.depth);
vec.push_back(s);
}
sort(vec.begin(),vec.end());
for(string ele : vec)
cout << ele <<endl;
}
示例9:
string Student::GetMajor2Description() const {
if (!major2_) { return "NA"; }
double major_code{major2_.get()};
assert(major_code_map.count(major_code) == 1);
return major_code_map.at(major_code);
}
示例10: embed_in_soource_code
void embed_in_soource_code(set<string>& sourceFiles,unordered_map<string,set<string>>& htabLines,int returnValue){
for(set<string>::iterator it=sourceFiles.begin();it!=sourceFiles.end();it++){
ifstream infile(*it);
int intIndexOfDelimiter = (*it).find_first_of(".");
string rawFileName = (*it).substr(0,intIndexOfDelimiter);
string fileExtension = (*it).substr(intIndexOfDelimiter+1,(*it).size()-intIndexOfDelimiter-1);
string tempOutputFileName = rawFileName + "_temp." + fileExtension;
ofstream outfile(tempOutputFileName);
int ct = 0;
string line;
if(infile.is_open()){
while(getline(infile,line)){
ct++;
string strCount = std::to_string(static_cast<long long>(ct));
string strKey = (*it) + ";" + strCount;
if(htabLines.find(strKey) != htabLines.end()){
set<string> reasons = htabLines.at(strKey);
string sourceLine = line + "/* " + addCategory(reasons) + " */";
outfile<<sourceLine<<endl;
}
else{
outfile<<line<<endl;
}
}
infile.close();
outfile.close();
}
string finalOutputFileName = rawFileName + "_out." + fileExtension;
string cmdRemoveLineFeedCharacters = "sed -e 's/\r//g' " + tempOutputFileName + " > " + finalOutputFileName;
returnValue = executeCommand(cmdRemoveLineFeedCharacters);
returnValue = executeCommand("rm " + tempOutputFileName);
}
}
示例11: graph_tests
/** Runs a sequence of graph algorithm tests on the input graph.
Will emit an exception if either (a) any algorithm throws an
an exception and that algorithm is not named in except_on,
(b) an algorithm named in except_on does not throw, or
(c) any algorithm's output is different than specified in the
'expect' map
@param[in] g The input graph
@param[in] source The source vertex for algorithms that need one
@param[in] destination The destination vertex for algorithms that need one
@param[in] except_on The algorithms that should throw an exception
@param[in] expect A map indicating the expected output of each algorithm
@return void */
void graph_tests(const digraph &g, digraph::nodename source,
digraph::nodename destination,
const set<string> & except_on,
unordered_map<string,string> expect )
{
auto exc_return = [] ()
{ cout << "Caught Expected Exception" << endl;
return string("Exception"); };
auto tst = [exc_return, except_on, expect] (string fcn, auto a)
{
auto exc_test = [except_on, fcn] ()
{ return except_on.end()!=except_on.find(fcn); };
auto normal_return = [fcn] (auto retval)
{ stringstream ss;
ss << fcn << " visiting " << retval;
cout << ss.str() << endl;
return ss.str();
};
expect_exception_l(a, exc_test, exc_return,
normal_return, expect.at(fcn) );
};
cout << endl << "=====> Beginning a test set" << endl;
tst("BFS", [g, source] () { return g.bfs(source); } );
tst("DFS", [g, source] () { return g.dfs(source); } );
tst("Topsort", [g] () { return g.topsort(); } );
tst("Dijkstra", [g, source, destination] ()
{ return g.dijkstra(source, destination); } );
tst("Bellman", [g, source] ()
{ return get<0>(g.bellman_ford(source).get()); } );
};
示例12: computeVector
/*
* This function takes a MAP and compares it with the MASTER_MAP to create the vector of frequency for a
* given document: Output is an unordered_map<string, int> in relation with the master_map
*/
unordered_map <string, int> computeVector(const unordered_map <string, int> & FILE_MAP, const unordered_map<string, int> & MASTER_MAP){
unordered_map<string, int> FILE_VECTOR;
FILE_VECTOR.insert(MASTER_MAP.begin(), MASTER_MAP.end()); // Make a copy of the master map
// cout << "(" ;
for(MAP_ITER IT = FILE_VECTOR.begin(); IT != FILE_VECTOR.end(); ++IT){
unordered_map<string, int>::const_iterator FILE_IT = FILE_MAP.find(IT->first);
string KEY = IT->first; // Get the first key pointed by the iterator
if(FILE_IT == FILE_MAP.end()){ // If the word is not there then set it to zero
FILE_VECTOR.at(KEY) = 0;
}else{ // Else set it to the file frequency
FILE_VECTOR.at(KEY) = FILE_MAP.at(KEY);
}
// cout << FILE_VECTOR[KEY] << ", ";
}
// cout << ")" << endl;;
return FILE_VECTOR;
}
示例13: bfs
unordered_map<char, int> bfs(const vector<string>&grid,
char source,
const unordered_map<char, pair<int, int>>& locations) {
static const vector<pair<int, int>> directions{{0, -1}, {0, 1},
{-1, 0}, {1, 0}};
int r, c;
tie(r, c) = locations.at(source);
vector<vector<bool>> lookup(grid.size(), vector<bool>(grid[0].size()));
lookup[r][c] = true;
queue<tuple<int, int, int>> q;
q.emplace(r, c, 0);
unordered_map<char, int> dist;
while (!q.empty()) {
int r, c, d;
tie(r, c, d) = q.front(); q.pop();
if (source != grid[r][c] && grid[r][c] != '.') {
dist[grid[r][c]] = d;
continue;
}
for (const auto& dir : directions) {
int cr = r + dir.first, cc = c + dir.second;
if (!((0 <= cr && cr < grid.size()) &&
(0 <= cc && cc < grid[0].size()))) {
continue;
}
if (grid[cr][cc] != '#' && !lookup[cr][cc]) {
lookup[cr][cc] = true;
q.emplace(cr, cc, d + 1);
}
}
}
return dist ;
}
示例14: RenderException
shared_ptr<Material> FileParser::fetchMaterial(const Json::Value& materialNode, const unordered_map<string, shared_ptr<Material>>& materials) const {
string name = parseString(materialNode, "material name");
try {
return materials.at(name);
} catch (const out_of_range& e) {
throw RenderException("Unable to find material: \"" + name + "\"");
}
}
示例15: reorderBits
word TruthTableUtils::reorderBits(word x, uint bitCount, const unordered_map<uint, uint>& reorderMap)
{
word y = 0;
for (uint index = 0; index < bitCount; ++index)
y |= ((x >> index) & 1) << reorderMap.at(index);
return y;
}