本文整理汇总了C++中hash_map::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ hash_map::clear方法的具体用法?C++ hash_map::clear怎么用?C++ hash_map::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hash_map
的用法示例。
在下文中一共展示了hash_map::clear方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calc
int calc(char s[])
{
len = strlen(s);
Manacher(s,len);
sum[0] = s[0];
for (int i = 1; i < len; i++)
sum[i] = sum[i-1]*muts+s[i];
int res = 0;
uint tmp;
int nt = 0;
hash.clear();
//odd
for (int i = 0; i < len; i++)
if (Mp[i*2+2]%2 == 0)
{
int pl = Mp[i*2+2]/2;
if (i+pl < nt || pl == 0) continue;
for (int j = i-pl+1; j <= i; j++)
{
tmp = gethashcode(j,i);
if (hash.find(tmp,i-j+1) != -1) break;
hash.insert(tmp,i-j+1);
}
nt = i+pl;
}
res += hash.N;
nt = 0;
hash.clear();
//even
for (int i = 0; i < len; i++)
if (Mp[i*2+3] > 1)
{
int pl = Mp[i*2+3]/2;
if (i+pl < nt || pl == 0) continue;
for (int j = i-pl+1; j <= i; j++)
{
tmp = gethashcode(j,i);
if (hash.find(tmp,i-j+1) != -1) break;
hash.insert(tmp,i-j+1);
}
nt = i+pl;
}
res += hash.N;
return res;
}
示例2: read_words
void read_words(const string filename) {
assert(!open_word_list);
ifstream fin(filename.c_str());
assert(fin.is_open());
_all_words.clear();
word_list.clear();
word_list.push_back("");
assert(word_list.at(NO_WORD) == "");
word_map.clear();
word_map[""] = NO_WORD; // FIXME: Don't use [] operator
unsigned i;
string word;
while(!fin.eof()) {
fin >> i >> ws >> word >> ws;
word_list.push_back(word);
assert(word_list.at(i) == word);
word_map[word] = i; // FIXME: Don't use [] operator
_all_words.push_back(i);
// if (word == "*content*") _Word_CONTENT = i;
}
assert(word_list.size() == word_map.size());
cerr << "Read " << word_list.size()-1 << " words from '" << filename << "'\n";
fin.close();
open_word_list = true;
}
示例3: initRTS
void initRTS(int **&tabu,int n) {
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
tabu[i][j] = -INF;
list_size = 2;
chaotic = 0;
moving_average = 0.0;
steps_since_last_change = 0;
visitas.clear();
}
示例4: InitHatLevData
void InitHatLevData( // init the global HAT data needed for this pyr level
const Image& img, // in
int ilev) // in
{
if (ilev <= HAT_START_LEV) // we use HATs only at upper pyr levs
{
hat_g.Init_(img, PatchWidth(ilev));
#if CACHE
if (TRACE_CACHE) // show results from previous run
lprintf("[calls %d hitrate %.2f cachesize %d]\n",
ncalls_g, double(nhits_g) / ncalls_g, cache_g.size());
cache_g.clear();
#endif
}
}
示例5: 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;
}
示例6: main
int main(int argc, char** argv) {
SatProblem cnf;
cnf.parse(stdin);
size_t count = 0;
while (count < 100) {
cerr << "count = " << count << endl;
equivalences.clear();
implications.clear();
for (size_t i = 0; i < cnf.clauses.size(); ++i) {
if (cnf.clauses[i].size() == 0) {
abort();
} else if (cnf.clauses[i].size() == 1) {
addEquivalence(cnf.clauses[i][0], TRUE);
addEquivalence(invert(cnf.clauses[i][0]), FALSE);
} else if (cnf.clauses[i].size() == 2) {
implications[invert(cnf.clauses[i][0])].push_back(cnf.clauses[i][1]);
implications[invert(cnf.clauses[i][1])].push_back(cnf.clauses[i][0]);
} else {
// Do nothing
}
}
done.clear();
for (hash_map<Lit, vector<Lit> >::const_iterator i = implications.begin();
i != implications.end(); ++i) {
vector<Lit> stack;
// cerr << "Exploring " << i->first << endl;
explore(i->first, stack);
}
vector<Clause> oldClauses = cnf.clauses;
cnf.clauses.clear();
for (size_t i = 0; i < oldClauses.size(); ++i) {
Clause cl = oldClauses[i];
for (size_t j = 0; j < cl.size(); ++j) {
cl[j] = normalize(cl[j]);
}
cnf.addClause(cl);
}
for (size_t i = 0; i < cnf.interfaceVariables.size(); ++i) {
InterfaceVariable& iv = cnf.interfaceVariables[i];
for (size_t j = 0; j < iv.second.size(); ++j) {
Lit oldLit = iv.second[j];
Lit newLit = normalize(oldLit);
iv.second[j] = newLit;
}
}
if (equivalences.empty()) break; // No changes
++count;
}
cnf.unparse(stdout);
return 0;
}
示例7: main
//.........这里部分代码省略.........
break;
}
}
if(flag == 0)
{
pair<string, long long int> tempPair = make_pair(tree1, tempCount);
finalTree.push_back(tempPair);
}
}
*/
/******************write non-isomorphic trees into file***********/
int frequentTree = 0;
ofstream fileTree;
fileTree.open(("resultTree_"+intToString(subgraphSize)+".txt").c_str());
for (hash_map<std::string, long long int>::iterator it = treeInt.begin(); it != treeInt.end(); it++)
{
if(it->second > (THR*subgraphCounter))
{
frequentTree++;
//fileTree<< it->first<<" "<<it->second<<"\n";
}
}
fileTree.close();
printf("OutTree: %d\n", frequentTree);
treeInt.clear();
finalTree.clear();
gettimeofday(&treeover, 0);
cout<<"Time of dealing with tree after Partition before graph: "<<(treeover.tv_sec - tvPartition.tv_sec + (double)(treeover.tv_usec - tvPartition.tv_usec) / CLOCKS_PER_SEC)<<endl;
/****************************************************************/
/*****************graph isomorphic********************************/
int graphSize = graphInt.size();
//cout<<"graphSize:"<<graphSize<<endl;
vector<bool> CountedGraph(graphSize, true);
int flag = 0;
int flag2 = 0;
//degree sequence
/*1210 2013**/
for (hash_map<std::string, long long int>::iterator it = graphInt.begin(); it != graphInt.end(); it++)
{
const std::string *graph1 = &(it->first);
//cout<<"Graph1 = " << *graph1 <<endl;
std::string gds1 = graphDegreeSequence(*graph1,subgraphSize,AsciiToInt);
long long int tempCount = it->second;
//vector<const std::string*> tempGraphs;
//tempGraphs.push_back(graph1);
if(degreeSeqCount.find(gds1)==degreeSeqCount.end())
{
degreeSeqCount[gds1] = tempCount;
vector<const std::string*> tempGraphsTemp;
tempGraphsTemp.push_back(graph1);
degreeSeq[gds1] = tempGraphsTemp;
示例8: fun
int fun(){
int key = getKey(cur);
int d;
queue<Node> q;
dis.clear();
pred.clear();
q.push(cur);
dis[key] = 0;
pred[key] = -1;
Node next;
Iter it;
while(!q.empty()){
cur = q.front(); q.pop();
if(cur.x == gx && cur.y == gy){
//backtrace(getKey(cur));
return dis[getKey(cur)];
}
d = dis[getKey(cur)];
// up;
next = cur;
if(next.x>0 && tab[next.x-1][next.y] ==0
&& reach(next, next.x+1,next.y)){
next.a = next.x; next.b = next.y;
next.x --;
key = getKey(next);
it = dis.find(key);
if(it==dis.end() || it->second > d + 1){
q.push(next);
pred[key] = getKey(cur);
dis[key] = d + 1;
}
}
// dn;
next = cur;
if(next.x <h-1 &&tab[next.x+1][next.y]==0
&& reach(next, next.x-1, next.y)){
next.a = next.x; next.b = next.y;
next.x++;
key = getKey(next);
it = dis.find(key);
if(it==dis.end() || it->second > d + 1){
q.push(next);
pred[key] = getKey(cur);
dis[key] = d + 1;
}
}
// left;
next = cur;
if(next.y>0 && tab[next.x][next.y-1] ==0
&&reach(next, next.x,next.y+1)){
next.a = next.x; next.b = next.y;
next.y--;
key = getKey(next);
it = dis.find(key);
if(it==dis.end() || it->second > d + 1){
q.push(next);
pred[key] = getKey(cur);
dis[key] = d + 1;
}
}
// right;
next = cur;
if(next.y<w-1&& tab[next.x][next.y+1]==0&&reach(next,next.x,next.y-1)){
next.a = next.x; next.b = next.y;
next.y++;
key = getKey(next);
it = dis.find(key);
if(it==dis.end() || it->second > d + 1){
q.push(next);
pred[key] = getKey(cur);
dis[key] = d + 1;
}
}
}
return -1;
}
示例9: mapLoadDefaultColour
void mapLoadDefaultColour()
{
if(g_dayColourUnits.size()&&g_nightColourUnits.size())
{
return;
}
g_dayColourUnits.clear();
g_nightColourUnits.clear();
size_t maxTableSize = sizeof(g_roadColourTable) / sizeof(TMapColourEntry);
for(size_t i = 0; i < maxTableSize; i++){ //load road
ColourUnit cUnit;
cUnit.type = ROAD_ARC_MISC;
RGBCOLOUR colour = g_navDisplay->getColour(g_roadColourTable[i].colourIndex);
cUnit.colour.red = colour.red;
cUnit.colour.green = colour.green;
cUnit.colour.blue = colour.blue;
cUnit.colour.alpha = colour.alpha;
cUnit.typeIndex = i;
if(g_dayColourUnits.find(g_roadColourTable[i].legend) == g_dayColourUnits.end())
{
g_dayColourUnits.insert(ColourPair(g_roadColourTable[i].legend, cUnit));
g_nightColourUnits.insert(ColourPair(g_roadColourTable[i].legend, cUnit));
}
}
TElevationPalette *pElevationPalette = g_navDisplay->getElevationPalette();
for(size_t i = 0; i < numberOfGradients; i++){ //load gradient
ColourUnit cUnit;
if(i < pElevationPalette->elevationThresholdsCount){
cUnit.type = GRADIENT_ENABLE;
TElevationPaletteEntry entry = pElevationPalette->elevationPalette[i];
cUnit.colour.red = entry.r;
cUnit.colour.green = entry.g;
cUnit.colour.blue = entry.b;
cUnit.colour.alpha = entry.elevation;
}else{
cUnit.type = GRADIENT_DISABLE;
}
if(g_dayColourUnits.find(STR_GRADIENT[i]) == g_dayColourUnits.end())
{
g_dayColourUnits.insert(ColourPair(STR_GRADIENT[i], cUnit));
g_nightColourUnits.insert(ColourPair(STR_GRADIENT[i], cUnit));
}
}
maxTableSize = sizeof(g_polyColourTable) /
sizeof(TPolyMapColourEntry) - 1; //last one is elevation, so skip
for(size_t i = 0; i < maxTableSize; i++) { //load poly
ColourUnit cUnit;
cUnit.type = POLY_CITY;
RGBCOLOUR colour = g_navDisplay->getPolygonFillColour(g_polyColourTable[i].polyClass);
cUnit.colour.red = colour.red;
cUnit.colour.green = colour.green;
cUnit.colour.blue = colour.blue;
cUnit.colour.alpha = colour.alpha;
cUnit.typeIndex = i;
if(g_dayColourUnits.find(g_polyColourTable[i].polyName) == g_dayColourUnits.end())
{
g_dayColourUnits.insert(ColourPair(g_polyColourTable[i].polyName, cUnit));
g_nightColourUnits.insert(ColourPair(g_polyColourTable[i].polyName, cUnit));
}
}
g_currentColourType = DAY;
}
示例10: main
int main()
{
freopen("1.in","r",stdin);
freopen("3.out","w",stdout);
int totcas;
scanf("%d",&totcas);
//totcas = 20;
hash.init();
for (int cas = 1; cas <= totcas; cas++)
{
//for (int i = 0;i < maxn-10;i++)
// s[i] = rand()%1+'a';
//s[maxn-10] = 0;
scanf("%s",s);
len = strlen(s);
Manacher(s,len);
sum[0] = s[0];
mutpower[0] = 1;
for (int i = 1; i < len; i++)
{
mutpower[i] = (long long)mutpower[i-1]*muts%mods;
sum[i] = (sum[i-1]+(long long)s[i]*mutpower[i])%mods;
}
int res = 0;
int tmp;
//for (int i = 0;i < len*2+2;i++)
// printf("%2d ",Mp[i]);
//printf("\n");
if (cas == 10)
{
for (int i = 10000;i < len;i++)
for (int j = i-100;j <= i;j++)
printf("%d\n",gethashcode(j,i));
}
hash.clear();
//odd
for (int i = 0; i < len; i++)
if (Mp[i*2+2]%2 == 0)
{
int pl = Mp[i*2+2]/2;
for (int j = i-pl+1; j <= i; j++)
{
tmp = gethashcode(j,i);
if (hash.fint(tmp) != -1) break;
hash.insert(tmp);
}
}
res += hash.N;
hash.clear();
//even
for (int i = 0; i < len; i++)
if (Mp[i*2+3] > 1)
{
int pl = Mp[i*2+3]/2;
for (int j = i-pl+1; j <= i; j++)
{
tmp = gethashcode(j,i);
if (hash.fint(tmp) != -1) break;
hash.insert(tmp);
}
}
res += hash.N;
printf("Case #%d: %d\n",cas,res);
}
return 0;
}
示例11: YglCacheReset
void YglCacheReset(void) {
g_TexHash.clear();
}
示例12: read_labels
/// \todo Make some assertion about # of constit. labels, and/or that
/// they are the lowest numbered ones?
void read_labels(const string filename) {
assert(!open_label_list);
ifstream fin(filename.c_str());
assert(fin.is_open());
_all_labels.clear();
_all_constituent_labels.clear();
_all_terminal_labels.clear();
_max_label = 0;
label_list.clear();
label_map.clear();
terminal_set.clear();
constituent_set.clear();
unsigned i, is_terminal, cnt;
string label;
while(!fin.eof()) {
fin >> i >> ws >> is_terminal >> ws >> cnt >> label >> ws;
if (i == NO_LABEL)
label = "";
label_list.push_back(label);
assert(label_list.at(i) == label);
label_map[label] = i; // FIXME: Don't use [] operator
if (i != NO_LABEL) {
_all_labels.push_back(i);
if (is_terminal) {
terminal_set.insert(i, true);
_all_terminal_labels.push_back(i);
} else {
constituent_set.insert(i, true);
_all_constituent_labels.push_back(i);
}
if (i > _max_label) _max_label = i+1;
}
}
assert(label_list.at(NO_LABEL) == "");
assert(label_map[""] == NO_LABEL); // FIXME: Don't use [] operator
assert(label_list.size() == label_map.size());
// assert(label_map.size() == terminal_set.size() + constituent_set.size() + 1);
terminal_set.lock();
constituent_set.lock();
/*
Debug::log(1) << "Read " << constituent_set.size() << " constituents, " << \
terminal_set.size() << " terminals from '" << filename << "'\n";
*/
fin.close();
open_label_list = true;
if (is_label_string("ADJP")) _Label_ADJP = string_to_label("ADJP");
if (is_label_string("ADVP")) _Label_ADVP = string_to_label("ADVP");
if (is_label_string("AUX")) _Label_AUX = string_to_label("AUX");
if (is_label_string("AUXG")) _Label_AUXG = string_to_label("AUXG");
if (is_label_string("CC")) _Label_CC = string_to_label("CC");
if (is_label_string("CD")) _Label_CD = string_to_label("CD");
if (is_label_string("COLON")) _Label_COLON = string_to_label(":");
if (is_label_string("COMMA")) _Label_COMMA = string_to_label(",");
if (is_label_string("CONJP")) _Label_CONJP = string_to_label("CONJP");
if (is_label_string("DOLLAR")) _Label_DOLLAR = string_to_label("$");
if (is_label_string("DT")) _Label_DT = string_to_label("DT");
if (is_label_string("EX")) _Label_EX = string_to_label("EX");
if (is_label_string("FRAG")) _Label_FRAG = string_to_label("FRAG");
if (is_label_string("FW")) _Label_FW = string_to_label("FW");
if (is_label_string("HASH")) _Label_HASH = string_to_label("#");
if (is_label_string("IN")) _Label_IN = string_to_label("IN");
if (is_label_string("INTJ")) _Label_INTJ = string_to_label("INTJ");
if (is_label_string("JJ")) _Label_JJ = string_to_label("JJ");
if (is_label_string("JJR")) _Label_JJR = string_to_label("JJR");
if (is_label_string("JJS")) _Label_JJS = string_to_label("JJS");
if (is_label_string("LS")) _Label_LS = string_to_label("LS");
if (is_label_string("LST")) _Label_LST = string_to_label("LST");
if (is_label_string("MD")) _Label_MD = string_to_label("MD");
if (is_label_string("NAC")) _Label_NAC = string_to_label("NAC");
if (is_label_string("NN")) _Label_NN = string_to_label("NN");
if (is_label_string("NNP")) _Label_NNP = string_to_label("NNP");
if (is_label_string("NNPS")) _Label_NNPS = string_to_label("NNPS");
if (is_label_string("NNS")) _Label_NNS = string_to_label("NNS");
if (is_label_string("NP")) _Label_NP = string_to_label("NP");
if (is_label_string("NPB")) _Label_NPB = string_to_label("NPB");
if (is_label_string("NX")) _Label_NX = string_to_label("NX");
if (is_label_string("POS")) _Label_POS = string_to_label("POS");
if (is_label_string("PP")) _Label_PP = string_to_label("PP");
if (is_label_string("PRN")) _Label_PRN = string_to_label("PRN");
if (is_label_string("PRP")) _Label_PRP = string_to_label("PRP");
if (is_label_string("PRPP")) _Label_PRPP = string_to_label("PRP$");
if (is_label_string("PRT")) _Label_PRT = string_to_label("PRT");
if (is_label_string("QP")) _Label_QP = string_to_label("QP");
if (is_label_string("RB")) _Label_RB = string_to_label("RB");
if (is_label_string("RBR")) _Label_RBR = string_to_label("RBR");
if (is_label_string("RBS")) _Label_RBS = string_to_label("RBS");
if (is_label_string("RP")) _Label_RP = string_to_label("RP");
if (is_label_string("RRC")) _Label_RRC = string_to_label("RRC");
//.........这里部分代码省略.........