本文整理汇总了C++中unordered_map::size方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::size方法的具体用法?C++ unordered_map::size怎么用?C++ unordered_map::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_map
的用法示例。
在下文中一共展示了unordered_map::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: numSimilarGroups
int numSimilarGroups(vector<string>& A) {
int res = 0;
unordered_map<string,string> ancestors;
for(int i=0; i<A.size(); ++i)
{
auto lhs_anc_iter = ancestors.find(A[i]);
for(int j=i+1; j<A.size(); ++j)
{
if(isgroup(A[i], A[j]))
{
if (lhs_anc_iter!=ancestors.end()) {
group[lhs_anc_iter->second].insert(A[j]);
ancestors[A[j]]=lhs_anc_iter->second;
}
else {
auto rhs_anc_iter = ancestors.find(A[j]);
if (rhs_anc_iter!=ancestors.end()) {
group[rhs_anc_iter->second].insert(A[i]);
ancestors[A[i]]=rhs_anc_iter->second;
}
else {
group[A[i]].insert(A[j]);
ancestors[A[j]] = A[i];
}
}
}
}
if (group.find(A[i])==group.end() && ancestors.find(A[i]) == ancestors.end())
{
++res;
//output(A[i] + "\n");
}
}
// merge groups
int merge_cnt = 0;
while(group.size()>1) {
merge_cnt =0;
for(auto iter: group)
{
auto& vec = iter.second;
for(auto wd: vec)
{
if (mergegroup(iter.first, wd))
merge_cnt++;
}
}
for(auto iter=group.begin(); iter!=group.end();)
{
if(iter->second.empty()) iter = group.erase(iter);
else ++iter;
}
if(merge_cnt==0 )
break;
}
return res + group.size();
}
示例2: return
bool operator<(const Equation& other)const
{
//return quant.size()-extra_weight>other.quant.size()-other.extra_weight;
return (quant.size()>other.quant.size()?true:(quant.size()==other.quant.size()
&& extra_weight>other.extra_weight?true:false));
}
示例3: init_utility_matrix
void init_utility_matrix(const unordered_map<string, size_t> &items, const unordered_map<string, size_t> &users,
vector<vector<float>>utility_matrix) {
for (size_t user = 0; user < users.size(); user++) {
for (size_t item = 0; item < items.size(); item++)
utility_matrix[user][item] = FLOAT_NONE_VALUE;
}
}
示例4: id_of
int id_of(string &s, unordered_map<string, int> &mp) {
auto it = mp.find(s);
if (it == mp.end()) {
mp.insert({s, mp.size()});
return mp.size() - 1;
} else return it->second;
}
示例5: readBinaryLine
unordered_map<string, int>
LoadParticles::read_plyBinaryHeader(FILE *data,
unordered_map<string, int> parameters) {
parameters = {};
string line = readBinaryLine(data);
if (line != "ply") {
cerr << "Error: loading corrupt ply-file:";
throw 20;
}
line = readBinaryLine(data);
if (line != "format binary_little_endian 1.0") {
cerr << "Error: error loading binary ply-file:";
throw 20;
}
int position = 0;
int nParticles = 0;
while (line != "end_header") {
line = readBinaryLine(data);
vector<string> lineSplit;
boost::trim_if(line, boost::is_any_of("\t "));
boost::split(lineSplit, line, boost::is_any_of("\t "),
boost::token_compress_on);
if (lineSplit[0] == "comment")
continue;
if (lineSplit[0] == "element") {
if (lineSplit[1] == "vertex") {
nParticles = stoi(lineSplit[2]);
} else {
cerr << "Error: only vertex element supported in ply file" << endl;
cerr << "found: " << lineSplit[1] << endl;
throw 20;
}
}
if (lineSplit[0] == "property") {
if (lineSplit[1] == "double") {
parameters[lineSplit[2]] = position;
position++;
} else {
cerr << "Error: in ply 'property'' only 'double' is supported" << endl;
cerr << "found: " << lineSplit[1] << endl;
throw 20;
}
}
}
m_timeStep = 0;
m_nColumns = parameters.size();
m_nParticles = nParticles;
m_chunkLength = nParticles * parameters.size();
return parameters;
}
示例6: solve
void solve(int start, string &s, vector<string> &words)
{
//m stores info, m1 stores current info
unordered_map<string, int>::iterator it;
int p1 = start, p2 = start, len = words[0].length(), cur = 0;
m1.clear();
while(p2 + len - 1 < s.length())
{
while(cur != m.size() && p2 + len - 1 < s.length())
{
string tmp = s.substr(p2, len);
it = m.find(tmp);
if(it == m.end())
{
p2 += len;
p1 = p2;
cur = 0;
m1.clear();
continue;
}
else if(it->second == m1[tmp])
{
string tmp2 = "";
while(p1 != p2 && tmp2 != tmp)
{
tmp2 = s.substr(p1, len);
if(m1.find(tmp2) != m1.end())
{
if(m1[tmp2] == m[tmp2])
cur--;
m1[tmp2]--;
}
p1 += len;
}
continue;
}
m1[tmp]++;
if(it->second == m1[tmp])
cur++;
p2 += len;
}
while(cur == m.size() && p1 <= p2)
{
ans.push_back(p1);
string tmp = s.substr(p1, len);
it = m1.find(tmp);
if(it == m1.end())
{
p1 += len;
continue;
}
it->second--;
if(it->second < m[tmp])
cur--;
p1 += len;
}
}
}
示例7: RunThread2
void RunThread2()
{
//int gameDiff = D2CLIENT_GetDifficulty();
int gameDiff = 1;
BnetData* pData = (*p_D2LAUNCH_BnData);
char* accountNameChar = pData->szAccountName;
char* charName = pData->szPlayerName; //GetCharName();
std::string accountNameCharString(accountNameChar);
std::string charNameCharString(charName);
string jsonData = "{\"data\":{\"AccountName\":\"" + accountNameCharString + "\",\"CharName\":\"" + charNameCharString + "\",";
jsonData += "\"GameDiff\":\"" + std::to_string(gameDiff) + "\",\"CompressedData\":[";
unordered_map<unsigned int, unsigned __int64>::const_iterator it;
for (it = _pickedItems.begin(); it != _pickedItems.end(); it++) {
jsonData += "{\"ItemKey\":\"" + std::to_string((*it).first) + "\", \"ItemValue\":\"" + std::to_string((*it).second) + "\"},";
}
if (_pickedItems.size() > 0) {
jsonData.pop_back(); // remove last ,
}
jsonData += "], \"Timers\":[";
unordered_map<int, int>::const_iterator it2;
for (it2 = _timers.begin(); it2 != _timers.end(); it2++) {
jsonData += "{\"LvlNo\":\"" + std::to_string((*it2).first) + "\", \"Time\":\"" + std::to_string((*it2).second) + "\"},";
}
if (_timers.size() > 0) {
jsonData.pop_back(); // remove last ,
}
jsonData += "]}}\n";
//_oldItems.clear();
//SetCharName(""); // will be reset in core loop the fuck is this
DWORD dwWrite, dwRead;
bool flg = WriteFile(hPipe, jsonData.c_str(), jsonData.size(), &dwWrite, NULL);
}
示例8: runComparison
void TestSchemaEvolution::runComparison() {
CPPUNIT_ASSERT(unique_classes_current_.size() == unique_classes_.size());
for (auto cl : unique_classes_) {
std::cout << "Checking " << cl.first << " " << cl.second << std::endl;
//std::cout << "unique_classes_current_.insert(std::make_pair(\"" << cl.first << "\", " << cl.second << "));" << std::endl;
CPPUNIT_ASSERT(unique_classes_.find(cl.first) != unique_classes_.end());
CPPUNIT_ASSERT(unique_classes_[cl.first] == unique_classes_current_[cl.first]);
}
}
示例9: main
int main()
{
// freopen("in.txt","r",stdin);
string name,party,club;
char ins[100],*ptr;
int TC,tmp,ans;
TC = atoi(gets(ins));
gets(ins);
while(TC--)
{
name_set.clear(); party_set.clear(); club_set.clear();
memset(graph,0,sizeof(graph));
N = 1;
while(gets(ins) && strlen(ins))
{
ptr = strtok(ins," ");
name = string(ptr);
ptr = strtok(NULL," ");
party = string(ptr);
graph[get(name_set,name)][get(party_set,party)] = 1;
while(ptr = strtok(NULL," "))
{
club = string(ptr);
graph[source()][get(club_set,club)] = 1;
graph[get(club_set,club)][get(name_set,name)] = 1;
}
}
tmp = (club_set.size() - 1) / 2;
for(unordered_map<string,int>::iterator it = party_set.begin();it != party_set.end();it++)
graph[it->second][target()] = tmp;
ans = 0;
visited.reset();
while(tmp = maxflow(source(),INT_MAX))
{
ans += tmp;
visited.reset();
}
if(ans != club_set.size()) printf("Impossible.\n");
else
for(unordered_map<string,int>::iterator it_name = name_set.begin();it_name != name_set.end();it_name++)
for(unordered_map<string,int>::iterator it_club = club_set.begin();it_club != club_set.end();it_club++)
if(graph[it_name->second][it_club->second])
{
printf("%s %s\n",(it_name->first).c_str(),(it_club->first).c_str());
break;
}
if(TC) printf("\n");
}
return 0;
}
示例10: set
void set(int key, int value) {
//If the node info exists in the map, refresh the value of the node
//Swap the node from the original place to the head of the list
if (hmap.find(key) != hmap.end()){
ListNode *existNode = hmap[key];
existNode->val = value;
deleteNode(existNode);
setHead(existNode);
}
//else, create a new node in the list, and update the map as well
else{
ListNode *createNode = new ListNode(key, value);
//If the size of hash map exceeds the capacity of the cache,
//delete key of the end, and add key of the newly created node to hash map
//Meanwhile, remove the end node from the list, and insert the new node to the list
if (hmap.size() >= capacity){
hmap.erase(end->key);
deleteNode(end);
setHead(createNode);
}
//else, add the newly created node directly to the list
else setHead(createNode);
hmap[key] = createNode;
}
}
示例11: set
void set(int key, int value) {
if (get(key) != -1) {
hashMap[key]->val = value;
return;
}
if (hashMap.size() == capacity) {
Node *old = head->next;
hashMap.erase(old->key);
old->next->prev = head;
head->next = old->next;
old->next = nullptr;
old->prev = nullptr;
}
Node *newNode = new Node(key, value);
hashMap[key] = newNode;
newNode->prev = tail->prev;
newNode->next = tail;
newNode->prev->next = newNode;
tail->prev = newNode;
return;
}
示例12: put
void put(int key, int value) {
auto it = db.find(key);
auto iter = itcache.find(key);
if(it!=db.end()) {
(it->second.second)++;
it->second.first = value;
int newfreq = it->second.second;
int curfreq = newfreq-1;
cache[curfreq].erase(iter->second);
cache[newfreq].push_front(key);
itcache[key] = cache[newfreq].begin();
return;
}
if(itcache.size() == n) {
if(cache[minfreq].size() == 0)
return;
int keytodel = cache[minfreq].back();
cache[minfreq].pop_back();
itcache.erase(keytodel);
db.erase(keytodel);
}
minfreq = 1;
db[key] = make_pair(value, 1);
cache[1].push_front(key);
itcache[key] = cache[1].begin();
}
示例13: FontScore
/* static */
int FontUtils::FontScore(const unordered_map<char32, inT64>& ch_map,
const string& fontname,
int* raw_score,
vector<bool>* ch_flags) {
PangoFontInfo font_info;
if (!font_info.ParseFontDescriptionName(fontname)) {
tprintf("ERROR: Could not parse %s\n", fontname.c_str());
}
PangoFont* font = font_info.ToPangoFont();
PangoCoverage* coverage = pango_font_get_coverage(font, NULL);
if (ch_flags) {
ch_flags->clear();
ch_flags->reserve(ch_map.size());
}
*raw_score = 0;
int ok_chars = 0;
for (unordered_map<char32, inT64>::const_iterator it = ch_map.begin();
it != ch_map.end(); ++it) {
bool covered = (IsWhitespace(it->first) ||
(pango_coverage_get(coverage, it->first)
== PANGO_COVERAGE_EXACT));
if (covered) {
++(*raw_score);
ok_chars += it->second;
}
if (ch_flags) {
ch_flags->push_back(covered);
}
}
return ok_chars;
}
示例14: subsetsWithDup
vector<vector<int>> subsetsWithDup(unordered_map<int, int>& mapNums) {
vector<vector<int>> ret = {{}};
vector<vector<int>> tret = {};
if(mapNums.size() == 0) return ret;
int count = (mapNums.begin())->second;
int nums = (mapNums.begin())->first;
mapNums.erase(mapNums.begin());
vector<vector<int>> tmp = subsetsWithDup(mapNums);
for(int i=0; i<count; i++) {
vector<int> t(i+1, nums);
tret.push_back(t);
}
for(auto t:tmp)
if(t.size()) ret.push_back(t);
for(auto tr:tret)
ret.push_back(tr);
for(auto tr : tret) {
for(auto t : tmp) {
if(!t.size()) continue;
vector<int> tt(tr.begin(), tr.end());
tt.insert(tt.begin(), t.begin(), t.end());
ret.push_back(tt);
}
}
return ret;
}
示例15: set
void set(int key, int value)
{
auto itItemMap = m_itemMap.find(key);
if (itItemMap != m_itemMap.end())
{
// The item with this key exists in the
// cache, so promote the item to the list
// tail. Note that itItemMap->second is
// updated with the new value.
Promote(itItemMap->second);
// Set the value.
itItemMap->second->value = value;
}
else
{
// Check whether the cache has used all
// its capacity.
if (m_itemMap.size() >= m_capacity)
{
// Erase the least recently used item.
m_itemMap.erase(m_items.front().key);
m_items.pop_front();
}
// Insert the item into the list and the key-to-list-iterator
// pair into the map.
m_itemMap.insert(make_pair(
key, m_items.insert(m_items.end(), Item(key, value))));
}
}