From 0a42ad5ded7f8ccb540b2fa6c0f9163efc822de1 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Wed, 17 Aug 2011 16:06:58 +0300 Subject: Reverted back types dumper to display only used types for features --- generator/dumper.cpp | 76 ++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 47 deletions(-) (limited to 'generator/dumper.cpp') diff --git a/generator/dumper.cpp b/generator/dumper.cpp index 1d311af81a..d1f7527cdb 100644 --- a/generator/dumper.cpp +++ b/generator/dumper.cpp @@ -10,81 +10,62 @@ namespace feature { class TypesCollector - { + { + vector m_currFeatureTypes; + public: - typedef map value_type; + typedef unordered_map, size_t> value_type; value_type m_stats; - size_t m_namesCount; size_t m_totalCount; TypesCollector() : m_namesCount(0), m_totalCount(0) {} - void operator() (FeatureType & f, uint32_t) + void operator()(FeatureType & f, uint32_t) { ++m_totalCount; if (!f.GetPreferredDrawableName().empty()) ++m_namesCount; + m_currFeatureTypes.clear(); f.ForEachTypeRef(*this); + CHECK(!m_currFeatureTypes.empty(), ("Feature without any type???")); + pair found = m_stats.insert(make_pair(m_currFeatureTypes, 1)); + if (!found.second) + found.first->second++; } - void operator() (uint32_t type) + void operator()(uint32_t type) { - ++m_stats[type]; + m_currFeatureTypes.push_back(type); } }; - struct GreaterSecond + template + static bool SortFunc(T const & first, T const & second) { - template bool operator() (T const & t1, T const & t2) - { - return (t1.second > t2.second); - } - }; - - namespace - { - void CallCollect(ClassifObject * p, vector & path, TypesCollector & c); - - void CollectRecursive(ClassifObject * p, vector & path, TypesCollector & c) - { - path.push_back(p->GetName()); - - c(classif().GetTypeByPath(path)); - CallCollect(p, path, c); - - path.pop_back(); - } - - void CallCollect(ClassifObject * p, vector & path, TypesCollector & c) - { - p->ForEachObject(bind(&CollectRecursive, _1, ref(path), ref(c))); - } + return first.second > second.second; } void DumpTypes(string const & fPath) { - // get all types from mwm file TypesCollector doClass; feature::ForEachFromDat(fPath, doClass); - // add types from initial classificator (to get full mapping) - vector path; - CallCollect(classif().GetMutableRoot(), path, doClass); - - // sort types by frequency - typedef vector > vec_to_sort; + typedef pair, size_t> stats_elem_type; + typedef vector vec_to_sort; vec_to_sort vecToSort(doClass.m_stats.begin(), doClass.m_stats.end()); - sort(vecToSort.begin(), vecToSort.end(), GreaterSecond()); - - // print types to out stream - Classificator & c = classif(); - for (vec_to_sort::iterator i = vecToSort.begin(); i != vecToSort.end(); ++i) - cout << c.GetFullObjectName(i->first) << endl; + sort(vecToSort.begin(), vecToSort.end(), &SortFunc); - //cout << "Total features: " << doClass.m_totalCount << endl; - //cout << "Features with names: " << doClass.m_namesCount << endl; + for (vec_to_sort::iterator it = vecToSort.begin(); it != vecToSort.end(); ++it) + { + cout << it->second << " "; + for (size_t i = 0; i < it->first.size(); ++i) + cout << classif().GetFullObjectName(it->first[i]) << " "; + cout << endl; + } + cout << "Total features: " << doClass.m_totalCount << endl; + cout << "Features with names: " << doClass.m_namesCount << endl; } class NamesCollector @@ -130,9 +111,10 @@ namespace feature typedef vector VecToSortT; VecToSortT vecToSort(doClass.m_stats.begin(), doClass.m_stats.end()); - sort(vecToSort.begin(), vecToSort.end(), GreaterSecond()); + sort(vecToSort.begin(), vecToSort.end(), &SortFunc); for (VecToSortT::iterator it = vecToSort.begin(); it != vecToSort.end(); ++it) cout << it->second << " " << it->first << endl; } + } -- cgit v1.2.3