本文整理汇总了C++中hash_map::count方法的典型用法代码示例。如果您正苦于以下问题:C++ hash_map::count方法的具体用法?C++ hash_map::count怎么用?C++ hash_map::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hash_map
的用法示例。
在下文中一共展示了hash_map::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_trackData
void read_trackData()
{
FILE *fp = fopen("trackData1.txt","r");
int value;
char *cur;
char buf[200];
int trackid, albumid, artistid;
while(! feof(fp) ) {
fgets(buf, 200, fp);
if (feof(fp)) break;
trackid = atoi(strtok(buf, "|"));
if(imap.count(trackid) == 0 )
continue;
int iid = imap[trackid];
items[iid].type = TRACK;
cur = strtok(NULL, "|");
if (cur[0] != 'N') {
albumid = atoi(cur);
items[iid].albumid = albumMap[albumid];
}
cur = strtok(NULL, "|");
if (cur[0] != 'N') {
artistid = atoi(cur);
items[iid].artistid = artistMap[artistid];
}
while( (cur = strtok(NULL, "|")) != NULL) {
int value = atoi(cur);
int gid = genreMap[value];
genreItemMap.insert(hash_multimap<int,int>::value_type(iid, gid));
}
}
}
示例2: read_albumData
void read_albumData()
{
FILE *fp = fopen("albumData1.txt","r");
int value;
char *cur;
char buf[200];
int trackid, albumid, artistid;
int aid = 0;
while(! feof(fp) ) {
fgets(buf, 200, fp);
if (feof(fp)) break;
albumid = atoi(strtok(buf, "|"));
albumMap[albumid] = aid;
if (imap.count(albumid) != 0) {
int iid = imap[albumid];
cur = strtok(NULL, "|");
items[iid].albumid = aid;
if (cur[0] != 'N') {
items[iid].artistid = artistMap[atoi(cur)];
}
while( (cur = strtok(NULL, "|")) != NULL) {
int value = atoi(cur);
int gid = genreMap[value];
genreItemMap.insert(hash_multimap<int,int>::value_type(iid, gid));
}
}
aid++;
}
}
示例3: preOrder
int preOrder(Node* head, int sum, int preSum, int level, int &maxlen, hash_map<int, int> &sumMap)
{
if (head == NULL)
return maxlen;
int curSum = preSum + head->value;
if (sumMap.count(curSum - sum) == 1)
{
maxlen = (level - sumMap[curSum - sum]) > maxlen ? (level - sumMap[curSum - sum]) : maxlen;
}
if (sumMap.count(curSum) == 0)
{
sumMap.insert(make_pair(curSum, level));
}
maxlen = preOrder(head->left, sum, curSum, level + 1, maxlen, sumMap);
maxlen = preOrder(head->right, sum, curSum, level + 1, maxlen, sumMap);
if (level == sumMap[curSum])
{
sumMap.erase(curSum);
}
return maxlen;
}
示例4: read_validate
void read_validate()
{
int uid, n, iid, stmp, day, hr, min, sec;
double score;
ssize_t didx = 0;
unsigned int uidx=0, ridx=0, iidx=0;
ssize_t size;
char *data = (char *)open_read("validationIdx1.txt", &size);
int sum = 0;
while(1) {
if ( parseInt(data, &didx, &uid, size) ) {
break;
}
uidx = umap[uid];
parseInt(data, &didx, &n, size);
//users[uidx].nu = n;
for(int i = 0; i < n; i++) {
parseInt(data, &didx, &iid, size);
parseInt(data, &didx, &stmp, size);
parseInt(data, &didx, &day, size);
parseInt(data, &didx, &hr, size);
parseInt(data, &didx, &min, size);
parseInt(data, &didx, &sec, size);
score = (double)stmp / SCORENORM;
day -= 2672;
if( imap.count(iid) == 0) {
iidx = imaplen;
imaplen ++;
imap[iid] = iidx;
items[iidx].id = iid;
items[iidx].count = 0;
items[iidx].artistid = -1;
items[iidx].albumid = -1;
} else {
iidx = imap[iid];
assert(items[iidx].id == iid);
}
validations[ridx].item = iidx;
validations[ridx].rating = score;
validations[ridx].day = day;
ridx++;
}
}
munmap(data, size);
nValidations = ridx;
printf("nValidations = %d\n", nValidations);
}
示例5: read_tests
void read_tests()
{
int uid, n, iid, stmp, day, hr, min, sec;
double score;
ssize_t didx = 0;
unsigned int uidx=0, ridx=0, iidx=0;
ssize_t size;
char *data = (char *)open_read("testIdx1.txt", &size);
int sum = 0;
while(1) {
if ( parseInt(data, &didx, &uid, size) ) {
break;
}
uidx = umap[uid];
parseInt(data, &didx, &n, size);
if (n != 6) printf("Error size not 6!=%d\n", n);
//users[uidx].qu = n;
for(int i =0; i < n; i++) {
parseInt(data, &didx, &iid, size);
parseInt(data, &didx, &day, size);
parseInt(data, &didx, &hr, size);
parseInt(data, &didx, &min, size);
parseInt(data, &didx, &sec, size);
day -= 2672;
if( imap.count(iid) == 0) {
iidx = imaplen;
imaplen ++;
imap[iid] = iidx;
items[iidx].id = iid;
items[iidx].count = 0;
items[iidx].albumid = -1;
items[iidx].artistid = -1;
} else {
iidx = imap[iid];
assert(items[iidx].id == iid);
}
tests[ridx].item = iidx;
tests[ridx].rating = 0;
tests[ridx].day = day;
ridx++;
}
}
munmap(data, size);
nTests = ridx;
printf("nTests = %d %d\n", nTests, ridx);
}
示例6: read_genres
void read_genres()
{
FILE *fp = fopen("genreData1.txt","r");
int lines = 0, value;
int gid = 0;
while(! feof(fp) ) {
fscanf(fp, "%d\n", &value);
if(feof(fp)) break;
genreMap[value] = gid;
if(imap.count(value) > 0) {
int iid = imap[value];
items[iid].type = GENRE;
genreItemMap.insert(hash_multimap<int,int>::value_type(iid, gid));
}
gid++;
}
}
示例7: check_for_repetitions
bool check_for_repetitions(sol s,int iter,int n) {
visita v,nova;
int lenght;
steps_since_last_change++;
if(visitas.count(s.custo)) {
//printf("jah visitei\n");
v = visitas[s.custo];
visitas[s.custo].freq++;
lenght = iter - v.iter;
visitas[s.custo].iter = iter;
//printf("freq : %d\n",v.freq+1);
if( v.freq+1 > REP) {
chaotic++;
if(chaotic > MAXCHAOS) {
chaotic = 0;
//visitas.clear();
return false;
}
}
//if(lenght < cicle_max){
moving_average = 0.05*lenght + 0.95*moving_average;
list_size = Mult(list_size,INCREASE);
steps_since_last_change = 0;
//}
if(list_size >= n*n) {
list_size = Mult(list_size,DECREASE/2.0);
list_size = ( list_size < 2 ) ? 2 : list_size;
}
}
else {
nova.custo = s.custo;
nova.iter = iter;
nova.freq = 1;
visitas[s.custo] = nova;
}
//printf("moving_average : %.3lf, steps_since_last_change: %d\n",moving_average,steps_since_last_change);
if(steps_since_last_change > MAX_STEPS) {
//printf("list_size : %d, dec : %.3lf\n",list_size,dec);
list_size = Mult(list_size,DECREASE);
list_size = ( list_size < 2 ) ? 2 : list_size;
steps_since_last_change = 0;
}
return true;
}
示例8: read_artists
void read_artists()
{
FILE *fp = fopen("artistData1.txt","r");
int lines = 0, value;
int aid = 0;
while(! feof(fp) ) {
fscanf(fp, "%d\n", &value);
if(feof(fp)) break;
artistMap[value] = aid;
if(imap.count(value) != 0) {
int iid = imap[value];
items[iid].type = ARTIST;
items[iid].artistid = aid;
items[iid].albumid = -1;
}
aid++;
}
}
示例9: main
int main() {
int T, n;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
cur.clear();
for(int i = 0; i < n; i++) {
scanf("%d", &A[i]);
if(!cur.count(A[i])) last[i] = -1;
else last[i] = cur[A[i]];
cur[A[i]] = i;
}
int L = 0, R = 0, ans = 0;
while(R < n) {
while(R < n && last[R] < L) R++;
ans = max(ans, R - L);
L++;
}
printf("%d\n", ans);
}
return 0;
}
示例10: create_stack_boxes
int create_stack_boxes(vector<box> boxes, box bottom, vector<box> & stack, hash_map stack_map) {
if(bottom != NULL && stack_map.count(bottom) > 0) {
stack = stack_map[bottom];
}
int max_height = 0;
vector<box> max_stack;
for(int i = 0; i < boxes.size(); i++) {
if(canbeabove(boxes[i], bottom)) {
vector<box> new_stack;
int stack_height = create_stack_boxes(boxes, boxes[i], new_stack, stack_map);
if(stack_height > max_height) {
max_height = stack_height;
max_stack = new_stack;
}
}
}
if(bottom != NULL) {
max_stack[0] = bottom;
}
stack_map[bottom] = max_stack;
}
示例11: url_parse
bool request_handler::url_parse(const std::string& url,
std::string& request_path,
hash_map< std::string, std::vector<std::string> >& query_params)
{
std::string::size_type path_len;
try
{
path_len = url.find_first_of("?");
}
catch (std::exception& e)
{
path_len = url.size();
}
try
{
request_path = libtorrent::unescape_string(url.substr(0, path_len));
}
catch (std::runtime_error& exc)
{
return false;
}
std::string query_string = url.substr(path_len + 1, url.size() - (path_len + 1));
str query_copy = strdup(query_string.c_str());
boost::shared_ptr<char> fancy(query_copy, free);
str query = query_copy;
str kvpairs = strsep(&query, '&');
for (; kvpairs != NULL; kvpairs = strsep(&query, '&')) {
if (*kvpairs == 0)
continue;
str kvpairs2 = strdup(kvpairs);
boost::shared_ptr<char> fancy(kvpairs2, free);
str skey = strsep(&kvpairs2, '=');
if (skey == NULL || *skey == 0)
continue;
str sval = strsep(&kvpairs2, '=');
if (sval == NULL || *sval == 0)
continue;
std::string key;
std::string val;
try
{
key = libtorrent::unescape_string(skey);
}
catch (std::runtime_error& exc)
{
return false;
}
try
{
val = libtorrent::unescape_string(sval);
}
catch (std::runtime_error& exc)
{
return false;
}
//logger << key << " = " << val << std::endl;
if (query_params.count(key))
{
std::vector<std::string>& vals = query_params[key];
vals.push_back(val);
}
else
{
std::vector<std::string> vals;
vals.push_back(val);
query_params[key] = vals;
}
}
return true;
}
示例12: read_data
void read_data()
{
int uid, n, iid, stmp, day, hr, min, sec;
double score;
ssize_t didx = 0;
unsigned int uidx=0, ridx=0, iidx=0;
ssize_t size;
char *data = (char *)open_read("trainIdx1.txt", &size);
int sum = 0;
int start = 0;
mu = 0;
while(1) {
if ( parseInt(data, &didx, &uid, size) ) {
break;
}
//printf("' %c\n", data[didx-1]);
if (umap.count(uid) == 0) {
uidx = umaplen;
umaplen++;
umap[uid] = uidx;
users[uidx].id = uid;
} else {
uidx = imap[uid];
}
parseInt(data, &didx, &n, size);
users[uidx].count = n;
users[uidx].start = start;
start += n;
for(int i =0; i < n; i++) {
parseInt(data, &didx, &iid, size);
parseInt(data, &didx, &stmp, size);
parseInt(data, &didx, &day, size);
parseInt(data, &didx, &hr, size);
parseInt(data, &didx, &min, size);
parseInt(data, &didx, &sec, size);
score = (double) stmp / SCORENORM;
day -= 2672;
mu += score;
if( imap.count(iid) == 0) {
iidx = imaplen;
imaplen ++;
imap[iid] = iidx;
items[iidx].id = iid;
items[iidx].count = 0;
items[iidx].artistid = -1;
items[iidx].albumid = -1;
} else {
iidx = imap[iid];
assert(items[iidx].id == iid);
}
items[iidx].count += 1;
ratings[ridx].item = iidx;
ratings[ridx].rating = score;
ratings[ridx].day = day;
assert(ratings[ridx].rating <= 100);
ridx++;
}
}
munmap(data, size);
read_validate();
read_tests();
nItems = imaplen;
nUsers = umaplen;
nRatings = ridx;
mu /= (double)ridx;
printf("nRatings = %d\n", nRatings);
printf("mu = %lg\n", mu);
char vfile[256];
strcpy(vfile, tmpdir);
strcat(vfile,"values");
FILE *tmp = fopen(vfile, "w");
fprintf(tmp, "%u %u %u %u %u %25.18lg\n", nRatings, nUsers, nItems, nValidations, nTests, mu);
for(int i = 0 ; i < nUsers; i++ ) {
fprintf(tmp, "%d\n", users[i].id);
}
for(int i = 0 ; i < nItems; i++ ) {
fprintf(tmp, "%d\n", items[i].id);
}
fclose(tmp);
}
示例13: getChild
Node* getChild(str s) {
if (children.count(s)) return children[s];
else return NULL;
}
示例14: dfs
ll dfs(int dep,int now,int *b)
{
if (now==m+1)
{
int a[10];
for (int i=1;i<=m;i++)
{
a[i]=(dep-1)*m+i;
f[a[i]]=a[i];
if (b[i]!=26)
f[b[i]]=b[i];
}
for (int i=1;i<=m;i++)
if (U[c[dep][i]])
Union(a[i],b[i]);
for (int i=2;i<=m;i++)
if (L[c[dep][i]] && R[c[dep][i-1]])
Union(a[i],a[i-1]);
for (int i=m-1;i;i--)
if (R[c[dep][i]] && L[c[dep][i+1]])
Union(a[i],a[i+1]);
for (int i=1;i<=m;i++)
a[i]=find(a[i]);
if (dep==n)
return(a[m]==1);
else
{
bool flag=false;
for (int i=1;i<=m;i++)
{
if (!D[c[dep][i]])
a[i]=26;
if (a[i]==1)
flag=true;
}
ull state=0;
state=dep*lq+now;
for (int i=1;i<=m;i++)
state=state*lq+a[i];
for (int i=1;i<=12;i++)
state=state*lq+(v[i]+1);
if (M.count(state))
return(M[state]);
ll ret=0;
if (flag)
ret=dfs(dep+1,1,a);
M[state]=ret;
return(ret);
}
}
ll ret=0;
for (int i=1;i<=12;i++)
{
if (v[i]==0)
continue;
v[i]--;
c[dep][now]=i;
ret+=dfs(dep,now+1,b);
v[i]++;
}
return(ret);
}
示例15: calculateGraphs
unsigned BUDataStructures::calculateGraphs(const Function *F,
std::vector<const Function*> &Stack,
unsigned &NextID,
hash_map<const Function*, unsigned> &ValMap) {
assert(!ValMap.count(F) && "Shouldn't revisit functions!");
unsigned Min = NextID++, MyID = Min;
ValMap[F] = Min;
Stack.push_back(F);
// FIXME! This test should be generalized to be any function that we have
// already processed, in the case when there isn't a main or there are
// unreachable functions!
if (F->isDeclaration()) { // sprintf, fprintf, sscanf, etc...
// No callees!
Stack.pop_back();
ValMap[F] = ~0;
return Min;
}
DSGraph* Graph = getOrFetchDSGraph(F);
// Find all callee functions.
std::vector<const Function*> CalleeFunctions;
GetAllAuxCallees(Graph, CalleeFunctions);
std::sort(CalleeFunctions.begin(), CalleeFunctions.end());
std::vector<const Function*>::iterator uid = std::unique(CalleeFunctions.begin(), CalleeFunctions.end());
CalleeFunctions.resize(uid - CalleeFunctions.begin());
// The edges out of the current node are the call site targets...
for (unsigned i = 0, e = CalleeFunctions.size(); i != e; ++i) {
const Function *Callee = CalleeFunctions[i];
unsigned M;
// Have we visited the destination function yet?
hash_map<const Function*, unsigned>::iterator It = ValMap.find(Callee);
if (It == ValMap.end()) // No, visit it now.
M = calculateGraphs(Callee, Stack, NextID, ValMap);
else // Yes, get it's number.
M = It->second;
if (M < Min) Min = M;
}
assert(ValMap[F] == MyID && "SCC construction assumption wrong!");
if (Min != MyID)
return Min; // This is part of a larger SCC!
// If this is a new SCC, process it now.
if (Stack.back() == F) { // Special case the single "SCC" case here.
DEBUG(errs() << "Visiting single node SCC #: " << MyID << " fn: "
<< F->getName() << "\n");
Stack.pop_back();
DEBUG(errs() << " [BU] Calculating graph for: " << F->getName()<< "\n");
calculateGraph(Graph);
DEBUG(errs() << " [BU] Done inlining: " << F->getName() << " ["
<< Graph->getGraphSize() << "+" << Graph->getAuxFunctionCalls().size()
<< "]\n");
if (MaxSCC < 1) MaxSCC = 1;
// Should we revisit the graph? Only do it if there are now new resolvable
// callees or new callees
GetAllAuxCallees(Graph, CalleeFunctions);
if (CalleeFunctions.size()) {
DEBUG(errs() << "Recalculating " << F->getName() << " due to new knowledge\n");
ValMap.erase(F);
return calculateGraphs(F, Stack, NextID, ValMap);
} else {
ValMap[F] = ~0U;
return MyID;
}
} else {
// SCCFunctions - Keep track of the functions in the current SCC
//
std::vector<DSGraph*> SCCGraphs;
unsigned SCCSize = 1;
const Function *NF = Stack.back();
ValMap[NF] = ~0U;
DSGraph* SCCGraph = getDSGraph(NF);
// First thing first, collapse all of the DSGraphs into a single graph for
// the entire SCC. Splice all of the graphs into one and discard all of the
// old graphs.
//
while (NF != F) {
Stack.pop_back();
NF = Stack.back();
ValMap[NF] = ~0U;
DSGraph* NFG = getDSGraph(NF);
if (NFG != SCCGraph) {
// Update the Function -> DSG map.
for (DSGraph::retnodes_iterator I = NFG->retnodes_begin(),
E = NFG->retnodes_end(); I != E; ++I)
setDSGraph(I->first, SCCGraph);
SCCGraph->spliceFrom(NFG);
delete NFG;
++SCCSize;
}
//.........这里部分代码省略.........