本文整理汇总了C++中map_type::count方法的典型用法代码示例。如果您正苦于以下问题:C++ map_type::count方法的具体用法?C++ map_type::count怎么用?C++ map_type::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map_type
的用法示例。
在下文中一共展示了map_type::count方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find
/**
* Return a pointer to the element associated with the given handle,
* or a null pointer if this Map does not hold the handle.
*
* Note that you will also get NULL as result if the given handle has
* previously been associated with NULL.
*/
Handled* find(uint32_t handle) {
bool handleFound = content.count(handle);
if(handleFound) {
return &(content[handle]);
} else {
return 0;
}
}
示例2: del
static void del(map_type & x, const key_type & v)
{
if (x.count(v) != 0)
{
x.erase(v);
}
else
{
PyErr_SetString(PyExc_IndexError, "Index out of range");
boost::python::throw_error_already_set();
}
}
示例3: set
static void set(map_type & x, const key_type & v, mapped_type & m)
{
if (x.count(v) == 0)
{
x.insert(std::make_pair(v, m));
}
else
{
PyErr_SetString(PyExc_IndexError, "Value already set");
boost::python::throw_error_already_set();
}
}
示例4: get
static mapped_type get(map_type & x, const key_type & v)
{
if (x.count(v) != 0)
{
return x.at(v);
}
else
{
PyErr_SetString(PyExc_IndexError, "Index out of range");
boost::python::throw_error_already_set();
}
}
示例5: scan_and_count
static void scan_and_count(void const * area, size_t size, map_type const & m, map2_type & m2)
{
unsigned char const * p = static_cast<unsigned char const *>(area);
for(size_t n = 0; n + sizeof(shared_ptr_layout) <= size; p += pointer_align, n += pointer_align)
{
shared_ptr_layout const * q = reinterpret_cast<shared_ptr_layout const *>(p);
if(q->pn.id == abt_boost::detail::shared_count_id && q->pn.pi != 0 && m.count(q->pn.pi) != 0)
{
++m2[q->pn.pi];
}
}
}
示例6: listen
size_t listen(dht::DhtRunner& node, std::string chain, map_type& map)
{
std::future<size_t> token = node.listen(chain,
[&map](const std::vector<std::shared_ptr<dht::Value>>& values)
{
// For every value found...
for (const auto& value : values)
{
// Unpack then register and display it, if it's a new value.
std::string content = value->unpack<std::string>();
if(!map.count(content))
{
map.insert(std::make_pair(content, get_timestamp()));
disp(content);
}
}
// Continue lookup until no values are left.
return true;
});
if(token.wait_for(std::chrono::seconds(1)) != std::future_status::ready)
{
verbose("Warning: Could not create a listener since 1000ms.");
verbose(" Trying again for 30s...");
if(token.wait_for(std::chrono::seconds(30))
!= std::future_status::ready)
verbose("Error: Failure.");
else
verbose(" Done.");
}
auto v = token.get();
verbose("Starting listening to "
+ chain
+ " with token "
+ std::to_string(v) + ".");
return v;
}
示例7: strategy_c1
void strategy_c1(graph_type& graph, const string &q_entity, vec &f_q, map_type &index_of_kb, mat & Ws, vector<pair<double, AnswerInfo>> &answers){
if (index_of_kb.count(q_entity) == 0){
cout << "key error: can't find " << q_entity << "in index_of_kb" << endl;
}
static uniform_real_distribution<double> distribution(0.0, 1.0);
static default_random_engine generator;
unsigned start_index = index_of_kb.size();
for (auto &item1 : graph[q_entity]){
for (auto &candidate : item1.second){
vector<unsigned> answer_vec;
answer_vec.push_back(index_of_kb[q_entity]);
answer_vec.push_back(index_of_kb[item1.first]); // add relation in path
answer_vec.push_back(index_of_kb[candidate]);
double prob = min(1.0, 100.0 / graph[candidate].size());
unordered_set<unsigned> subgraph_set;
// add subgraph
for (auto & item2 : graph[candidate]){
if (distribution(generator) <= prob){
subgraph_set.insert(start_index + index_of_kb[item2.first]);
for (auto & obj : item2.second){
subgraph_set.insert(start_index + index_of_kb[obj]);
}
}
}
//cout << "Element number of subgraph = " << subgraph_set.size() << endl;
copy(subgraph_set.begin(), subgraph_set.end(), back_inserter(answer_vec));
auto score = scoreFunc(f_q, answer_vec, Ws);
answers.push_back(std::move(make_pair(score * 1.5, std::move(AnswerInfo{ candidate, q_entity, 1 }))));
}
}
//sort(answers.begin(), answers.end(), [](const pair<double, string> &lhs, const pair<double, string>&rhs){return lhs.first > rhs.first; });
}
示例8: beam_search_c2
void beam_search_c2(graph_type& graph, const string &q_entity, vec &f_q, map_type &index_of_kb, mat & Ws, vector<pair<double, AnswerInfo>> &answers){
priority_queue<triple_type, vector<triple_type>, Cmp> pq;
static uniform_real_distribution<double> distribution(0.0, 1.0);
static default_random_engine generator;
if (index_of_kb.count(q_entity) == 0){
cout << "key error: can't find " << q_entity << "in index_of_kb" << endl;
}
for (auto &item1 : graph[q_entity]){
auto rel1 = item1.first;
for (auto m : item1.second){ // mediator entity
for (auto item2 : graph[m]){
auto rel2 = item2.first; // the 2nd hop relation
vector<unsigned> answer_vec;
answer_vec.push_back(index_of_kb[q_entity]);
answer_vec.push_back(index_of_kb[rel1]);
answer_vec.push_back(index_of_kb[rel2]);
double score = scoreFunc(f_q, answer_vec, Ws);
if (pq.empty() < 10){
pq.push(std::move(make_tuple(score, rel1, rel2)));
}
else if (get<0>(pq.top()) < score){
pq.pop();
pq.push(std::move(make_tuple(score, rel1, rel2)));
}
}
}
}
unsigned start_index = index_of_kb.size();
while (!pq.empty()){
auto e = pq.top();
pq.pop();
string rel1 = get<1>(e);
string rel2 = get<2>(e);
for (auto & meditor_node : graph[q_entity][rel1]){
for (auto answer_node : graph[meditor_node][rel2]){
vector<unsigned> answer_vec;
answer_vec.push_back(index_of_kb[q_entity]);
answer_vec.push_back(index_of_kb[rel1]);
answer_vec.push_back(index_of_kb[rel2]);
answer_vec.push_back(index_of_kb[answer_node]);
// add subgraph
unordered_set<unsigned> subgraph_set;
for (auto & item : graph[answer_node]){
double prob = min(1.0, 100.0 / graph[answer_node].size());
if (distribution(generator) <= prob){
subgraph_set.insert(start_index + index_of_kb[item.first]); // relation linking to answer node
for (auto & o : item.second)
subgraph_set.insert(start_index + index_of_kb[o]);
}
}
//cout << "Element number of subgraph = " << subgraph_set.size() << endl;
copy(subgraph_set.begin(), subgraph_set.end(), back_inserter(answer_vec));
auto score = scoreFunc(f_q, answer_vec, Ws);
answers.push_back(std::move(make_pair(score, std::move(AnswerInfo{ answer_node, q_entity, 2}))));
}
}
}
//sort(answers.begin(), answers.end(), [](const pair<double, string> &lhs, const pair<double, string>&rhs){return lhs.first > rhs.first; });
}
示例9: has
bool has(const std::string &id) const {
return _objects.count(id) > 0;
}