本文整理汇总了C++中map_type::size方法的典型用法代码示例。如果您正苦于以下问题:C++ map_type::size方法的具体用法?C++ map_type::size怎么用?C++ map_type::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map_type
的用法示例。
在下文中一共展示了map_type::size方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compare
static bool compare(map_type const & MA, map_type const & MB)
{
std::vector < std::pair<std::string,std::string> > SA, SB;
for ( typename map_type::const_iterator ita = MA.begin(); ita != MA.end(); ++ita )
SA.push_back(std::pair<std::string,std::string>(ita->first,ita->second));
for ( typename map_type::const_iterator ita = MB.begin(); ita != MB.end(); ++ita )
SB.push_back(std::pair<std::string,std::string>(ita->first,ita->second));
std::sort(SA.begin(),SA.end());
std::sort(SB.begin(),SB.end());
uint64_t ia = 0, ib = 0;
for ( ; ia != SA.size() && ib != SB.size() ; ++ia, ++ib )
if ( SA[ia] != SB[ib] )
{
#if 0
std::cerr << printPair(SA[ia]) << " != " << printPair(SB[ib]) << std::endl;
for ( uint64_t i = 0; i < SA.size(); ++i )
std::cerr << SA[i].first << ";";
std::cerr << MA.size();
std::cerr << std::endl;
for ( uint64_t i = 0; i < SB.size(); ++i )
std::cerr << SB[i].first << ";";
std::cerr << MB.size();
std::cerr << std::endl;
#endif
return SA[ia] < SB[ib];
}
return ia < ib;
}
示例2: main
int main(int argc, const char** argv)
{
std::string text;
for(int i = 1; i < argc; ++i)
{
cout << "Processing file " << argv[i] << endl;
std::ifstream fs(argv[i]);
load_file(text, fs);
fs.close();
// construct our iterators:
boost::sregex_iterator m1(text.begin(), text.end(), expression);
boost::sregex_iterator m2;
std::for_each(m1, m2, ®ex_callback);
// copy results:
cout << class_index.size() << " matches found" << endl;
map_type::iterator c, d;
c = class_index.begin();
d = class_index.end();
while(c != d)
{
cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
++c;
}
class_index.erase(class_index.begin(), class_index.end());
}
return 0;
}
示例3: execute
inline void operation_sequence::execute(int id)
{
log_.push_back(id);
if (!failed_ && last_executed_ < id) {
if (++total_executed_ == operations_.size())
success_ = true;
last_executed_ = id;
} else {
success_ = false;
failed_ = true;
}
}
示例4: find_unreachable_objects_impl
static void find_unreachable_objects_impl(map_type const & m, map2_type & m2)
{
// scan objects for shared_ptr members, compute internal counts
{
std::cout << "... " << m.size() << " objects in m.\n";
for(map_type::const_iterator i = m.begin(); i != m.end(); ++i)
{
abt_boost::detail::sp_counted_base const * p = static_cast<abt_boost::detail::sp_counted_base const *>(i->first);
BOOST_ASSERT(p->use_count() != 0); // there should be no inactive counts in the map
m2[ i->first ];
scan_and_count(i->second.first, i->second.second, m, m2);
}
std::cout << "... " << m2.size() << " objects in m2.\n";
}
// mark reachable objects
{
open_type open;
for(map2_type::iterator i = m2.begin(); i != m2.end(); ++i)
{
abt_boost::detail::sp_counted_base const * p = static_cast<abt_boost::detail::sp_counted_base const *>(i->first);
if(p->use_count() != i->second) open.push_back(p);
}
std::cout << "... " << open.size() << " objects in open.\n";
for(open_type::iterator j = open.begin(); j != open.end(); ++j)
{
m2.erase(*j);
}
while(!open.empty())
{
void const * p = open.front();
open.pop_front();
map_type::const_iterator i = m.find(p);
BOOST_ASSERT(i != m.end());
scan_and_mark(i->second.first, i->second.second, m2, open);
}
}
// m2 now contains the unreachable objects
}
示例5: main
int main(int argc, const char** argv)
{
std::string text;
for(int i = 1; i < argc; ++i)
{
cout << "Processing file " << argv[i] << endl;
std::ifstream fs(argv[i]);
load_file(text, fs);
fs.close();
IndexClasses(text);
cout << class_index.size() << " matches found" << endl;
map_type::iterator c, d;
c = class_index.begin();
d = class_index.end();
while(c != d)
{
cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
++c;
}
class_index.erase(class_index.begin(), class_index.end());
}
return 0;
}
示例6: 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; });
}
示例7: keyCount
virtual size_t keyCount() const { return m_map.size(); }
示例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: size
size_type size() const {
return pa.size();
}