本文整理汇总了C++中unordered_map::find方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::find方法的具体用法?C++ unordered_map::find怎么用?C++ unordered_map::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_map
的用法示例。
在下文中一共展示了unordered_map::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set
void set(int key, int value) {
auto iter = mm.find(key);
if(iter != mm.end()){
iter->second->second = value;
ll.splice(ll.begin(), ll, iter->second); // move the record
}
else {
if(mm.size() == cap){
auto back = ll.back(); // NOTICE: back() returns a reference
mm.erase(back.first);
ll.pop_back();
}
ll.emplace_front(key, value);
mm[key] = ll.begin();
}
}
示例2: SMITHLABException
static void
get_chrom(const bool VERBOSE, const GenomicRegion &r,
const unordered_map<string, string>& chrom_files,
GenomicRegion &chrom_region, string &chrom) {
const unordered_map<string, string>::const_iterator
fn(chrom_files.find(r.get_chrom()));
if (fn == chrom_files.end())
throw SMITHLABException("could not find chrom: " + r.get_chrom());
chrom.clear();
read_fasta_file(fn->second, r.get_chrom(), chrom);
if (chrom.empty())
throw SMITHLABException("could not find chrom: " + r.get_chrom());
else {
chrom_region.set_chrom(r.get_chrom());
}
}
示例3: createIndices
void createIndices(vector<int>& nums, int which)
{
for (int i = 0; i < (int)nums.size(); i++)
{
unordered_map<int, IndexNode*>::iterator it = mIndices.find(nums[i]);
if (it != mIndices.end())
{
it->second->append(which, i);
}
else
{
mIndices.insert(pair<int, IndexNode *>(nums[i], new IndexNode(nums[i], which, i)));
}
}
}
示例4: search
list<int> search (string &str)
{
if (str.length() == 0)
return indexes;
else
{
char first = str[0];
if (children.find (first) != children.end())
{
string remainder = str.substr (1);
return (children[first].search(remainder));
}
}
return list<int>();
}
示例5: put
void put(int key, int value) {
auto it = data.find(key);
if (it != data.end()) {
access_order.splice(access_order.begin(), access_order, it->second.second);
data[key] = {value, access_order.begin()};
} else {
if (current_capacity == _capacity) {
data.erase(*access_order.rbegin());
access_order.pop_back();
} else {
current_capacity++;
}
access_order.push_front(key);
data[key] = {value, access_order.begin()};
}
}
示例6: helper
int helper(long n, unordered_map<long, int> &numStepsMap) {
if (n <= 1)
return 0;
if (numStepsMap.find(n) != numStepsMap.end())
return numStepsMap[n];
int res;
if (n % 2 == 0) {
res = 1 + helper(n / 2, numStepsMap);
} else {
res = 1 + min( helper(n - 1, numStepsMap), helper(n + 1, numStepsMap) );
}
numStepsMap[n] = res;
return res;
}
示例7: findRoot
int findRoot(unordered_map<int, int> &dj, int x) {
if (dj.find(x) == dj.end()) {
return x;
}
int r = x;
while (r != dj[r]) {
r = dj[r];
}
int k = x;
while (x != r) {
x = dj[x];
dj[k] = r;
k = x;
}
return r;
}
示例8: operator
int32_t operator()(df::coord p1, df::coord p2) {
if ( p1 == p2 ) return 0;
auto i1 = pointCost->find(p1);
auto i2 = pointCost->find(p2);
if ( i1 == pointCost->end() && i2 == pointCost->end() )
return p1 < p2;
if ( i1 == pointCost->end() )
return true;
if ( i2 == pointCost->end() )
return false;
cost_t c1 = (*i1).second;
cost_t c2 = (*i2).second;
if ( c1 != c2 )
return c1 < c2;
return p1 < p2;
}
示例9: backTrace
void backTrace(string s) {
if (bt.find(s) == bt.end()) {
// End of back trac
vector<string> r(res);
r.push_back(s);
reverse(r.begin(), r.end());
ans.push_back(r);
return;
}
unordered_set<string> &v = bt[s];
res.push_back(s);
for (auto it = v.begin(); it != v.end(); ++it) {
backTrace(*it);
}
res.pop_back();
}
示例10: findSubstring
vector<int> findSubstring(string S, vector<string> &L)
{
vector<int> result;
if(L.size() == 0)
return result;
size_t wordLen = L[0].size();
size_t wordNum = L.size();
size_t wordsLen = wordLen * wordNum;
if(S.size() < wordsLen)
return result;
//cout << "wordLen \t" << wordLen << endl;
//cout << "wordNum \t" << wordNum<< endl;
//cout << "wordsLen\t" << wordsLen << endl;
initMap(L);
//printMap();
for(size_t i = 0; i <= S.size() - wordsLen; i++)
{
size_t j = i;
for( /**/; j < (i + wordsLen); j += wordLen)
{
//cout << "j\t" << j << endl;
//printMap();
string tmp = S.substr(j, wordLen);
if(m_map.find(tmp) != m_map.end() && m_map[tmp] > 0)
{
m_map[tmp]--;
}
else
{
break;
}
}
//cout << "==j\t" << j << endl;
if(j >= (i+wordsLen))
{
result.push_back(i);
}
initMap(L);
}
return result;
}
示例11: containsTile
df::building *Buildings::findAtTile(df::coord pos)
{
auto occ = Maps::getTileOccupancy(pos);
if (!occ || !occ->bits.building)
return NULL;
// Try cache lookup in case it works:
auto cached = locationToBuilding.find(pos);
if (cached != locationToBuilding.end())
{
auto building = df::building::find(cached->second);
if (building && building->z == pos.z &&
building->isSettingOccupancy() &&
containsTile(building, pos, false))
{
return building;
}
}
// The authentic method, i.e. how the game generally does this:
auto &vec = df::building::get_vector();
for (size_t i = 0; i < vec.size(); i++)
{
auto bld = vec[i];
if (pos.z != bld->z ||
pos.x < bld->x1 || pos.x > bld->x2 ||
pos.y < bld->y1 || pos.y > bld->y2)
continue;
if (!bld->isSettingOccupancy())
continue;
if (bld->room.extents && bld->isExtentShaped())
{
auto etile = getExtentTile(bld->room, pos);
if (!etile || !*etile)
continue;
}
return bld;
}
return NULL;
}
示例12: runtime_error
static void
get_chrom(const MappedRead &mr,
const vector<string> &all_chroms,
const unordered_map<string, size_t> &chrom_lookup,
GenomicRegion &chrom_region, string &chrom) {
const unordered_map<string, size_t>::const_iterator
the_chrom(chrom_lookup.find(mr.r.get_chrom()));
if (the_chrom == chrom_lookup.end())
throw runtime_error("could not find chrom: " + mr.r.get_chrom());
chrom = all_chroms[the_chrom->second];
if (chrom.empty())
throw runtime_error("could not find chrom: " + mr.r.get_chrom());
chrom_region.set_chrom(mr.r.get_chrom());
}
示例13: short_event_name
// Reduce an event name to a short string.
string LocalState::short_event_name (string longname)
{
string shortname;
auto siter = short_evname.find(longname);
if (siter == short_evname.end()) {
// Unknown name: Make up something for now, but we really ought to fix the
// code to match the run-time library.
static size_t id = 1;
char sname[25];
sprintf(sname, "E%lu", id++);
shortname = string(sname);
short_evname[longname] = shortname;
}
else
shortname = siter->second;
return shortname;
}
示例14: set
void set(int key, int value) {
if (dict.find(key) != dict.end())
{
data.splice(data.begin(), data, dict[key]);
dict[key]->val = value;
}
else
{
if (data.size() == capacity)
{
dict.erase(data.back().key);
data.pop_back();
}
data.push_front(Node(key, value));
}
dict[key] = data.begin();
}
示例15: extract
bool extract(const string &str, vector<pair<string, double> > &keywords, size_t topN) const
{
vector<string> words;
if (!_segment.cut(str, words))
{
LogError("segment cut(%s) failed.", str.c_str());
return false;
}
map<string, double> wordmap;
for (vector<string>::iterator iter = words.begin(); iter != words.end(); iter++)
{
if (_isSingleWord(*iter))
{
continue;
}
wordmap[*iter] += 1.0;
}
for (map<string, double>::iterator itr = wordmap.begin(); itr != wordmap.end(); )
{
if (_stopWords.end() != _stopWords.find(itr->first))
{
wordmap.erase(itr++);
continue;
}
unordered_map<string, double>::const_iterator cit = _idfMap.find(itr->first);
if (cit != _idfMap.end())
{
itr->second *= cit->second;
}
else
{
itr->second *= _idfAverage;
}
itr ++;
}
keywords.clear();
std::copy(wordmap.begin(), wordmap.end(), std::inserter(keywords, keywords.begin()));
topN = min(topN, keywords.size());
partial_sort(keywords.begin(), keywords.begin() + topN, keywords.end(), _cmp);
keywords.resize(topN);
return true;
}