本文整理汇总了C++中std::tr1::unordered_map::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::erase方法的具体用法?C++ unordered_map::erase怎么用?C++ unordered_map::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::tr1::unordered_map
的用法示例。
在下文中一共展示了unordered_map::erase方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Merge
void Merge(const int& first, const int& second) {
Tree<int>* first_tree;
Tree<int>* second_tree;
if (vertices_by_objects.count(first) == 0) {
first_tree = new Tree<int>(first);
trees_by_roots[first_tree->root] = first_tree;
vertices_by_objects[first] = first_tree->root;
} else {
first_tree = trees_by_roots[Tree<int>::FindRoot(vertices_by_objects[first])];
}
if (vertices_by_objects.count(second) == 0) {
second_tree = new Tree<int>(second);
trees_by_roots[second_tree->root] = second_tree;
vertices_by_objects[second] = second_tree->root;
} else {
second_tree = trees_by_roots[Tree<int>::FindRoot(vertices_by_objects[second])];
}
if (first_tree != second_tree) {
// std::cout << "MERGE(" << first << ", " << second << ")\n";
first_tree->Merge(second_tree);
trees_by_roots.erase(first_tree->root);
delete trees_by_roots[second_tree->root];
trees_by_roots.erase(second_tree->root);
trees_by_roots[first_tree->root] = first_tree;
// Vertex<int>* a = second_tree->root;
// first_tree->Merge(second_tree);
// std::cout << "END MERGE\n";
// trees_by_roots.erase(a);
}
}
开发者ID:luxe,项目名称:Cpp-mini-program-scraps,代码行数:34,代码来源:ideone-c++4.8.1-t550kg-20:02:44_2014-02-27_cET.cpp
示例2: replace
void replace(std::string user, std::string command, std::deque<std::string> args)
{
if (cuboidMap.find(user) != cuboidMap.end())
{
cuboidMap.erase(user);
}
if (args.size() == 2)
{
cuboidMap[user].active = 1;
cuboidMap[user].state = 0;
cuboidMap[user].action = REPLACE;
int blockID = atoi(args[0].c_str());
//If item was not a number, search the name from config
if (blockID == 0)
{
blockID = mineserver->config.iData(args[0].c_str());
}
if(blockID < 1 || blockID > 255)
{
cuboidMap.erase(user);
return;
}
cuboidMap[user].fromBlock = blockID;
blockID = atoi(args[1].c_str());
//If item was not a number, search the name from config
if (blockID == 0 && args[1] != "0")
{
blockID = mineserver->config.iData(args[1].c_str());
}
if(blockID < 0 || blockID > 255)
{
cuboidMap.erase(user);
return;
}
cuboidMap[user].toBlock = blockID;
mineserver->chat.sendmsgTo(user.c_str(),"Cuboid replace start, hit first block");
}
}
示例3: onNickChange
void m_dccchat::onNickChange(std::string server, std::string oldNick, std::string newNick) {
std::tr1::unordered_map<std::string, Socket*>::iterator dccIter = activeConnections.find(server + "/" + oldNick);
if (dccIter != activeConnections.end()) {
Socket* thisSocket = dccIter->second;
activeConnections.erase(dccIter);
activeConnections.insert(std::pair<std::string, Socket*> (server + "/" + newNick, thisSocket));
}
}
示例4: set
void set(int key, int value) {
if(key2node.find(key) != key2node.end())
{
// node to front
Node2front(key);
head->value = value;
}
else{
Node * n = new Node(key, value);
key2node[key] = n;
n->next = head;
n->pre = NULL;
if(head != NULL)
head->pre = n;
else
tail = n;
head = n;
// Node * p = head;
// cout << ":";
// while(p!= NULL){
// cout << p->key << " ";
// p = p->next;
// }cout<< " taiL:" << tail->key /*<< " tpre:" << tail->pre->key */<< endl;
// if(key2node.size() > 1)
// cout << "tpre:" << tail->pre->key << endl;
// delete last node
if(key2node.size() > capa)
{
int k = tail->key;
if(tail->pre != NULL){
// cout << "tail pre:" << tail->pre->key << endl;
tail->pre->next = NULL;
tail = tail->pre;
// cout << "tail:" << tail->key << endl;
}
else {
head = tail = NULL;
}
key2node.erase(k);
}
// cout << head->key << head->value << " " <<tail->key << tail->value << endl;
// p = head;
// cout << ":";
// while(p!= NULL){
// cout << p->key << " ";
// p = p->next;
// }cout << endl;
}
}
示例5:
void l1_regularize(const int iter) {
float lambda_hat = get_eta(iter) * lambda;
std::tr1::unordered_map<int, float> tmp = w;
std::tr1::unordered_map<int, float>::iterator it = tmp.begin();
for (; it != tmp.end(); it++) {
int key = it->first;
std::tr1::unordered_map<int, float>::iterator wit = w.find(key);
float aaa = wit->second;
wit->second = clip_by_zero(wit->second, lambda_hat);
if (fabsf(aaa) < lambda_hat) {
w.erase(wit);
}
}
};
示例6: dccListen
void m_dccchat::dccListen(std::string id, Socket* listenSocket) {
std::tr1::unordered_map<std::string, std::vector<std::string> >::iterator ourReportingModules = reportingModules.find(id);
while (true) {
if (!listenSocket->isConnected())
break;
std::string receivedMsg = listenSocket->receive();
std::cout << "DCC " << id << ":" << receivedMsg << std::endl;
std::tr1::unordered_map<std::string, Module*> modules = getModules(); // get a new one each time in case it is updated
for (std::tr1::unordered_map<std::string, std::string>::iterator hookIter = moduleTriggers.begin(); hookIter != moduleTriggers.end(); ++hookIter) {
if (hookIter->first == receivedMsg.substr(0, receivedMsg.find_first_of(' '))) {
bool alreadyReporting = false;
for (unsigned int i = 0; i < ourReportingModules->second.size(); i++) {
if (ourReportingModules->second[i] == hookIter->second) {
alreadyReporting = true;
break;
}
}
if (!alreadyReporting)
ourReportingModules->second.push_back(hookIter->second);
}
}
for (unsigned int i = 0; i < ourReportingModules->second.size(); i++) {
std::tr1::unordered_map<std::string, Module*>::iterator modIter = modules.find(ourReportingModules->second[i]);
if (modIter == modules.end())
ourReportingModules->second.erase(ourReportingModules->second.begin()+i);
else {
std::vector<std::string> modSupports = modIter->second->supports();
for (unsigned int i = 0; i < modSupports.size(); i++) {
if (modSupports[i] == "DCC_CHAT") {
dccChat* dccMod = (dccChat*)modIter->second;
dccMod->onDCCReceive(id, receivedMsg);
break;
}
}
}
}
}
std::tr1::unordered_map<std::string, Module*> modules = getModules();
for (unsigned int i = 0; i < reportingModules.size(); i++) {
std::tr1::unordered_map<std::string, Module*>::iterator modIter = modules.find(ourReportingModules->second[i]);
dccChat* dccMod = (dccChat*) modIter->second;
dccMod->onDCCEnd(id); // call the DCC end hook for each watching module as the DCC session ends
}
delete listenSocket;
activeConnections.erase(id);
}
示例7: displayMulti
//Implementation of displayMulti()
void Engine::displayMulti(std::tr1::unordered_map<string, unsigned int> table) {
// If the map is empty there is nothing to be done.
if(table.empty()) {
cout << "No movies matched your search. Sorry" << endl << endl ;
return ;
}
std::tr1::unordered_map<string, unsigned int>::iterator it2 ;
string big ;
// Iterate three times to get the three movies with highest frequencies
for(int i = 0 ; i < 3 ; i++) {
// If the intersection is empty the job is done
if(table.size() == 0) {
cout << "No more movies." << endl << endl ;
return ;
}
// Assume the movie with highest frequency is the first one
big = table.begin()->first ;
// Iterate through the rest of the movies and if one with higher frequency
// is found swap it with big
for(it2 = table.begin() ; it2 != table.end() ; it2++)
if(table[big] < it2->second)
big = it2->first;
// Print the movie with highest frequency
cout << "Movie " << i+1 << ": " << big << endl ;
// Erase that movie from the map
table.erase(big) ;
}
cout << endl ;
}
示例8: main
//.........这里部分代码省略.........
if (countflag) {
sscanf(&buffer[0],"packet %d",&ipacket);
count[ipacket % nsenders]++;
}
// scan past header line
strtok(&buffer[0],"\n");
// process perpacket datums in packet
for (int i = 0; i < perpacket; i++) {
uint64_t key = strtoul(strtok(NULL,",\n"),NULL,0);
char *value = strtok(NULL,",\n");
int count = atoi(strtok(NULL,",\n"));
// store outer key in okv hash table
// if new key, add to active set, deleting LRU key if necessary
// count = # of times key has been seen
// discard key if its count is not consistent with okv count
// build up inner key 16-bits at a time
if (!okv.count(key)) {
if (count > 1) continue;
nunique++;
if (ofree) {
okey = ofree;
ofree = ofree->next;
okv[key] = okey;
} else {
okey = olist.last;
olist.remove(okey);
okv.erase(okey->key);
okv[key] = okey;
}
okey->key = key;
okey->inner = atoi(value);
okey->count = 1;
olist.prepend(okey);
} else {
okey = okv[key];
if (okey->count != count-1) {
okv.erase(okey->key);
olist.remove(okey);
okey->next = ofree;
ofree = okey;
continue;
}
if (count <= 4) {
olist.move2front(okey);
uint64_t ivalue = atoi(value);
ivalue = ivalue << (16*okey->count);
okey->inner |= ivalue;
okey->count++;
continue;
}
// 5th occurrence of outer key, discard it
// value of inner key = low-order digit of value
// truth of inner key = hi-order digit of value
okv.erase(okey->key);
olist.remove(okey);
okey->next = ofree;