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;
			}
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, &regex_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;
}
Exemple #3
0
 /** Compute the sum of all the elements
  * Implements compensated summation
  */
 double sum() {
     double s=0.;
     for (map_type::iterator it=map.begin(),itend=map.end();it!=itend;++it) {
         s += it->second;
     }
     return s;
 }
Exemple #4
0
 //! conversion to clause
 clause_type clause() const {
     clause_type C;
     const iterator pa_end = pa.end();
     for (iterator i = pa.begin(); i != pa_end; ++i)
         C.ls.insert(literal_type(i->first, i->second));
     return C;
 }
Exemple #5
0
 /** Compute the max of the element values
  * This operation returns the first element if the vector is empty.
  */
 mwIndex max_index() {
     mwIndex index=0;
     double maxval=std::numeric_limits<double>::min();
     for (map_type::iterator it=map.begin(),itend=map.end();it!=itend;++it) {
         if (it->second>maxval) { maxval = it->second; index = it->first; }
     }
     return index;
 }
Exemple #6
0
 void flush(){
     enterExclusive();
     map_type::iterator iter = _item_map.begin();
     for(; iter != _item_map.end(); ++iter){
         iter->second->flush();
     }
     leaveExclusive();
 }
Exemple #7
0
 void print() const{
     enterExclusive();
     map_type::const_iterator iter = _item_map.begin();
     for(; iter != _item_map.end(); ++iter){
         iter->second->print();
     }
     leaveExclusive();
 }
Exemple #8
0
void
mapper::_free_map(map_type &m) {
    map_type::iterator i = m.begin();
    for (; i != m.end(); i++) {
        if (i->first)  free((void *)i->first);
        if (i->second) free((void *)i->second);
    }
    m.clear();
}
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
}
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;
}
Exemple #11
0
static std::string urlEncodeParams(map_type const &params)
{
	std::string result;

	typename map_type::const_iterator it;
	for(it=params.begin(); it!=params.end(); it++) {
		if( result.size() ) {
			result += "&";
		}
		urlEncode(it->first.c_str(),result);
		if( !it->second.empty() ) {
			result += "=";
			urlEncode(it->second.c_str(),result);
		}
	}

	return result;
}
Exemple #12
0
 static size_type alphabet_size_and_map(const reference_type rac, size_type n, map_type& map, inv_map_type& inv_map, value_type& first_symbol) {
     if (n > 0)
         first_symbol = rac[0];
     map.clear();
     inv_map.clear();
     size_type alphabet_size = 0;
     for (size_type i=0; i<n; ++i) {
         if (map.find(rac[i]) == map.end()) {
             map[rac[i]]    = 1;
         }
     }
     for (typename map_type::iterator it = map.begin(); it != map.end(); ++it) { // this preserves the order
         it->second = alphabet_size;
         inv_map[alphabet_size] = it->first;
         ++alphabet_size;
     }
     return alphabet_size;
 }
label_type most_common(const gather_type& total) {
    typedef gather_type::map_type map_type;
    const map_type m = total.get();

    label_type best_label = 0;
    size_t best_freq = 0;

    for (map_type::const_iterator it = m.begin(); it != m.end(); it++) {
        label_type label = it->first;
        size_t freq = it->second;

        if (freq > best_freq || (freq == best_freq && label < best_label)) {
            best_label = label;
            best_freq = freq;
        }
    }

    return best_label;
}
Exemple #14
0
		virtual map_type::iterator begin() 					 		 { return m_map.begin(); }
Exemple #15
0
		virtual map_type::const_iterator begin() const					 		 { return m_map.begin(); }
 ~basic_parameter_map() {
   for (typename map_type::iterator it = begin(); it != end(); ++it) {
     delete it->second;
   }
 }
Exemple #17
0
int main(int argc, char *argv[])
{
    int file_count = argc - 1;          //要開幾個檔案
    if(file_count > 3) {
        cout << "檔案數量必須小於3個" <<endl;
        exit(EXIT_FAILURE);
    }else if(file_count <=0){
        cout << "請輸入檔案\n程式執行語法為: ./WordAnal [FirstTextFile] [SecondTextFile] [ThirdTextFile]" <<endl;
        exit(EXIT_FAILURE);
    }

    pthread_t threads[3];               //執行緒
    pthread_attr_t attr;
    pthread_attr_init(&attr);           //取得pthread預設屬性
    pthread_mutex_init(&mutex,NULL);    //初始化mutex

    string f[20];
    fstream fileptr;                    //檔案指標
    for(int i=1;i < argc;i++)
    {
        fileptr.open(argv[i],ios::in);
        if(!fileptr.is_open()) {
            cout << "開啟檔案錯誤\n請輸入正確檔名\n";
            exit(EXIT_FAILURE);
        }else{
            f[i-1].assign((istreambuf_iterator<char>(fileptr)), (istreambuf_iterator<char>()));     //讀入整個檔案到f[i-1]裡
            fileptr.close();
        }
    }

    for (int i = 0; i < file_count; ++i)        //開啟執行緒
        pthread_create(&threads[i],&attr,runner,f+i);
    
    pthread_attr_destroy(&attr);                //釋放attr

    for (int i = 0; i < file_count; ++i)        //等待所有執行緒結束
        pthread_join(threads[i],NULL);
    

    //最後排序
    typedef multimap<int, string,greater<int> > multimap_type;
    multimap_type multi;
    multimap_type::iterator multiter;

    for (iter = m.begin(); iter != m.end(); iter++)
        multi.insert(multimap_type::value_type(iter->second,iter->first));
    


    //輸出
    cout << "次數            單字"<<endl;
    for(multiter = multi.begin();multiter != multi.end();multiter++)
    {
        if(multiter->first < 10)
            cout << "   ";
        else if(multiter->first <100)
            cout << "  ";
        else if(multiter->first < 1000)
            cout << " ";
        cout << multiter->first << "            " << multiter->second << endl;
    }
    
    return 0;
}
	~HandleMap() {
		map_iter iter = content.begin();
		for(;iter != content.end(); ++iter) {
			handlePool->release(iter->first);
		}
	}
Exemple #19
0
 varset_type var() const {
     varset_type V;
     const iterator pa_end = pa.end();
     for (iterator i = pa.begin(); i != pa_end; ++i) V.insert(i->first);
     return V;
 }
typename std::enable_if<can_sort>::type
kv_sort( map_type & m ) {
    std::sort( m.begin(), m.end(),
	       asap::pair_cmp<typename map_type::value_type,
	       typename map_type::value_type>() );
}