本文整理汇总了C++中unordered_map::bucket方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::bucket方法的具体用法?C++ unordered_map::bucket怎么用?C++ unordered_map::bucket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_map
的用法示例。
在下文中一共展示了unordered_map::bucket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processPacket
int processPacket(const Packet &packet) {
// DNS query.
if (packet.sourcePort() != ntohs(53)) {
qr = DNS_QUERY;
makeFlowID(flowID, packet.sourceIP(), packet.destinationIP(),
packet.sourcePort(), packet.destinationPort());
}
// DNS response.
else {
qr = DNS_RESPONSE;
makeFlowID(flowID, packet.destinationIP(), packet.sourceIP(),
packet.destinationPort(), packet.sourcePort());
}
bucket = flowTable.bucket(flowID);
// Prevents interference with flush().
pthread_mutex_lock(&(flowTableLocks[bucket]));
flowItr = flowTable.find(flowID);
if (flowItr == flowTable.end()) {
if (flowTable.size() == maxFlows) {
if (maxFlowsWarning) {
cout << "dns: flow table is full" << endl;
maxFlowsWarning = false;
}
pthread_mutex_unlock(&(flowTableLocks[bucket]));
return 0;
}
flowItr = flowTable.insert(make_pair(flowID, new DNS)).first;
flowItr -> second -> rawClientIP(*(uint32_t*)(flowID));
flowItr -> second -> rawServerIP(*(uint32_t*)(flowID + 4));
if (!getQuestion(flowItr -> second, packet.payload())) {
++numBadPackets;
delete flowItr -> second;
flowTable.erase(flowItr);
pthread_mutex_unlock(&flowTableLocks[bucket]);
return 0;
}
}
// We only process supported resource record types.
if (!isSupportedType(flowItr -> second -> queryType())) {
delete flowItr -> second;
flowTable.erase(flowItr);
pthread_mutex_unlock(&flowTableLocks[bucket]);
return 0;
}
if (qr == DNS_QUERY) {
flowItr->second->queryTime(packet.time());
flowItr->second->rawQueryFlags(*(uint16_t*)(packet.payload() + 2));
}
else {
flowItr->second->responseTime(packet.time());
flowItr->second->rawResponseFlags(*(uint16_t*)(packet.payload() + 2));
if (getAnswers(flowItr->second, packet.payload(),
packet.payloadSize()))
{
writer->write(flowItr -> second);
}
else {
delete flowItr -> second;
++numBadPackets;
}
flowTable.erase(flowItr);
}
pthread_mutex_unlock(&flowTableLocks[bucket]);
return 0;
}