本文整理汇总了C++中std::tr1::unordered_map::rehash方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::rehash方法的具体用法?C++ unordered_map::rehash怎么用?C++ unordered_map::rehash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::tr1::unordered_map
的用法示例。
在下文中一共展示了unordered_map::rehash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
read_cmd_options(argc,argv);
// sender stats and stop flags
count = new uint64_t[nsenders];
shut = new int[nsenders];
for (int i = 0; i < nsenders; i++) count[i] = shut[i] = 0;
// setup UDP port
const int socket = ::socket(PF_INET6, SOCK_DGRAM, 0);
if (socket == -1)
throw std::runtime_error(std::string("socket(): ") + ::strerror(errno));
struct sockaddr_in6 address;
::memset(&address, 0, sizeof(address));
address.sin6_family = AF_INET6;
address.sin6_addr = in6addr_any;
address.sin6_port = htons(port);
if (-1 == ::bind(socket, reinterpret_cast<sockaddr*>(&address),
sizeof(address)))
throw std::runtime_error(std::string("bind(): ") + ::strerror(errno));
// scale maxactive by number of generators
// oset/iset = active key sets for outer/inner keys
// olist/ilist = doubly-linked lists so can delete least recently used
// mactive = # of keys in active set for inner keys
// okv/ikv = outer/inner key-value hash tables
// ofree = index of 1st free element in linked list of free oset elements
maxactive *= nsenders;
Kouter *oset = new Kouter[maxactive];
Kinner *iset = new Kinner[maxactive];
MyDoubleLinkedList<Kouter*> olist;
MyDoubleLinkedList<Kinner*> ilist;
int mactive = 0;
Kouter *ofree = oset;
for (int i = 0; i < maxactive; i++)
oset[i].next = &oset[i+1];
oset[maxactive-1].next = NULL;
// pre-allocate to maxactive per generator, in agreement with generator #3
okv.rehash(ceil(maxactive / okv.max_load_factor()));
ikv.rehash(ceil(maxactive / ikv.max_load_factor()));
// packet buffer length of 64 bytes per datum is ample
int maxbuf = 64*perpacket;
std::vector<char> buffer(maxbuf);
int ipacket;
// loop on reading packets
Kouter *okey;
Kinner *ikey;
int max = 0;
while (true) {
// read a packet with Nbytes
const int nbytes = ::recv(socket,&buffer[0],buffer.size()-1,0);
buffer[nbytes] = '\0';
// check if STOP packet
// exit if have received STOP packet from every sender
if (nbytes < 8) {
if (shutdown(&buffer[0])) break;
continue;
}
nrecv++;
// tally stats on packets from each sender
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
//.........这里部分代码省略.........