本文整理汇总了C++中std::tr1::unordered_map::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::insert方法的具体用法?C++ unordered_map::insert怎么用?C++ unordered_map::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::tr1::unordered_map
的用法示例。
在下文中一共展示了unordered_map::insert方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hookDCCMessage
bool m_dccchat::hookDCCMessage(std::string modName, std::string hookMsg) {
if (moduleTriggers.find(hookMsg) == moduleTriggers.end()) {
moduleTriggers.insert(std::pair<std::string, std::string> (hookMsg, modName));
return true;
}
return false;
}
示例2: max_distance
uint max_distance(TreeNode* root)
{
if (root == NULL) {
return 0;
}
static std::tr1::unordered_map<void*, uint> cache;
typeof(cache.begin()) it = cache.find(root);
if (it != cache.end()) {
return it->second;
}
uint leftCost = max_distance(root->left);
uint rightCost = max_distance(root->right);
uint leftHeight = height(root->left);
uint rightHeight = height(root->right);
uint childCost = leftCost > rightCost ? leftCost : rightCost;
uint throughRoot = leftHeight + rightHeight + root->cost;
uint ret = childCost > throughRoot ? childCost : throughRoot;
cache.insert(std::make_pair(root, ret));
return ret;
}
示例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: dccConnect
void m_dccchat::dccConnect(std::string server, std::string nick, std::string ip, std::string port) {
Socket* dccSocket = new Socket();
std::istringstream portNumber (port);
unsigned short dccPort;
portNumber >> dccPort;
dccSocket->connectServer(ip, dccPort);
activeConnections.insert(std::pair<std::string, Socket*> (server + "/" + nick, dccSocket));
reportingModules.insert(std::pair<std::string, std::vector<std::string> > (server + "/" + nick, std::vector<std::string> ()));
dccListenArg listenData;
listenData.modPtr = this;
listenData.id = server + "/" + nick;
listenData.sockPtr = dccSocket;
pthread_t newThread;
threads.push_back(&newThread);
void* listenArgs = (void*) &listenData;
pthread_create(&newThread, NULL, &dccListen_thread, listenArgs);
sleep(1); // make the arguments passed to the thread not die before the thread function can read them.
}
示例5: height
uint height(TreeNode* root)
{
if (root == NULL) {
return 0;
}
static std::tr1::unordered_map<void*, uint> cache;
typeof(cache.begin()) it = cache.find(root);
if (it != cache.end()) {
return it->second;
}
uint left = height(root->left);
uint right = height(root->right);
uint child = left > right ? left : right;
uint ret = root->cost + child;
cache.insert(std::make_pair(root, ret));
return ret;
}