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; }
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; }
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)); } }
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. }
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; }