<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      多線程處理N維度topk問題demo--[c++]

      問題

      -對多維度特征進行topk排序,使用c++ 優先隊列模擬最大堆.

      
      /*
      ----------------------------------
      Version    : ??
      File Name :     dm2.py
      Description :   
      Author  :       xijun1
      Email   :      
      Date    :       2018/12/7
      -----------------------------------
      Change Activity  :   2018/12/7
      -----------------------------------
      __author__ = 'xijun1'
      */
      #include <iostream>
      #include <queue>
      #include <unordered_map>
      #include <future>
      using namespace std;
      
      class MinHeapUtil {
      private:
      
          struct HeapGreatcompare
          {
              // min heap
              bool operator()(const pair<unsigned int, int>& node_a, const pair<unsigned int, int>& node_b) {
                  return node_a.second > node_b.second;
              }
          };
      
      
          std::vector< std::priority_queue< std::pair<unsigned int, int>, std::vector< std::pair<unsigned  int, int> > ,HeapGreatcompare> > pq_mat;
          unsigned  int max_topk;
      public:
           bool setShape(const int dim  , const unsigned int max_topk );
           int getdim(){
               return  this->pq_mat.size();
           }
           int getMaxTopK(){
               return this->max_topk;
           }
           size_t getSize( int k ){
               return this->pq_mat[ k ].size();
           }
           int push_back(std::vector<std::pair<unsigned int, int>  >& data , int k );
           int push_back( std::pair<unsigned int, int>   word_prob , int k );
          int push_back( std::pair<unsigned int, int>   &word_prob , int k );
           std::pair<unsigned int , int >get_itop(int k){
               auto word_prob = this->pq_mat[ k ].top();
               this->pq_mat[ k ].pop();
               return word_prob;
           }
      };
      
      bool MinHeapUtil::setShape(const int dim, const unsigned  int max_topk) {
          this->pq_mat.resize(dim );
          this->max_topk = max_topk;
          return true;
      }
       int  MinHeapUtil::push_back(std::vector< std::pair<unsigned int, int> > &data ,int k) {
      
          for (auto const& word_prob : data) {
              this->pq_mat[ k ].push(std::make_pair(word_prob.second, word_prob.first));
              if ( this->pq_mat[ k ].size() > this->max_topk)  //維護這個K大小
                  this->pq_mat[ k ].pop();
          }
           return  0;
      }
      int MinHeapUtil::push_back(std::pair<unsigned int, int> word_prob, int k) {
      
          if( this->pq_mat[k].size() < this->max_topk || this->pq_mat[ k ].top().second < word_prob.second) {
              this->pq_mat[k].push(word_prob);
              if (this->pq_mat[k].size() > this->max_topk)  //維護這個K大小
                  this->pq_mat[k].pop();
          }
          return  0;
      
      }
      
      
      int MinHeapUtil::push_back(std::pair<unsigned int, int> &word_prob, int k) {
          this->pq_mat[k].push(word_prob);
          if (this->pq_mat[k].size() > this->max_topk)  //維護這個K大小
              this->pq_mat[k].pop();
          return 0;
      }
      std::unordered_map<unsigned int , std::vector< int > > test_data;
      int  main() {
          MinHeapUtil top_words ;
      
          top_words.setShape(5,4);
          int total_size = 5;
      
      //    MinHeapUtil.push_back(std::pair<unsigned int, int>(8,2),0);
      //    MinHeapUtil.push_back(std::pair<unsigned int, int>(7,3),0);
      //    MinHeapUtil.push_back(std::pair<unsigned int, int>(6,4),0);
      //    MinHeapUtil.push_back(std::pair<unsigned int, int>(5,5),0);
      //    MinHeapUtil.push_back(std::pair<unsigned int, int>(4,6),0);
      //    MinHeapUtil.push_back(std::pair<unsigned int, int>(3,7),0);
      //    MinHeapUtil.push_back(std::pair<unsigned int, int>(2,4),0);
      //    MinHeapUtil.push_back(std::pair<unsigned int, int>(1,8),0);
          for (int j = 0; j < 1000000; ++j) {
              std::vector< int > tmp(5);
              for (int i = 0; i < 5; ++i) {
                  tmp[i] = j*5 + i;
              }
              test_data[j] = std::move(tmp);
          }
          struct save_func
          {
              void operator () (int tn  ,int thread_nums,int total_size , MinHeapUtil *top_words )
              {
                  std::cout<<tn <<" : "<< thread_nums<<" : "<<total_size<<std::endl;
                  for (int i = tn; i < total_size ; i+=thread_nums) {
                      for ( auto word_key : test_data) {
                          //std::cout<<word_key.first;
                          top_words->push_back( std::pair<unsigned int, int>(word_key.first, word_key.second[ i ] ) , i );
                      }
                  }
                  std::cout << "func " << tn << std::endl;
              }
          } func;
          unsigned thread_nums = 8;
          std::vector<std::future< void >> muliti_topword_threads;
      
          for (unsigned tn = 0; tn < thread_nums; ++tn)
              muliti_topword_threads.emplace_back(
                      std::async(std::launch::async, func, (int)tn,(int)thread_nums,total_size,&top_words));
      
          for (unsigned tn = 0; tn < thread_nums; ++tn)
              muliti_topword_threads[tn].get();
      
          for (int k = 0; k < total_size; ++k) {
              size_t range = top_words.getSize( k );
              for (int i = 0; i < range; ++i) {
                  auto temp = top_words.get_itop( k );
                  std::cout <<"k:"<<k<<"  ( " << temp.first << "     " << temp.second << ")\n";
              }
          }
          return 0;
      }
      
      
      
      

      --結果

      01 :  : 88 :  : 55
      
      2 : 8 : 5
      3 : 8 : 5
      4 : 8 : 5
      5 : 8 : 5
      func 5
      6 : 8 : 5
      func 6
      7 : 8 : 5
      func 7
      func 1
      func 4
      func 0
      func 2
      func 3
      k:0  ( 999996     4999980)
      k:0  ( 999997     4999985)
      k:0  ( 999998     4999990)
      k:0  ( 999999     4999995)
      k:1  ( 999996     4999981)
      k:1  ( 999997     4999986)
      k:1  ( 999998     4999991)
      k:1  ( 999999     4999996)
      k:2  ( 999996     4999982)
      k:2  ( 999997     4999987)
      k:2  ( 999998     4999992)
      k:2  ( 999999     4999997)
      k:3  ( 999996     4999983)
      k:3  ( 999997     4999988)
      k:3  ( 999998     4999993)
      k:3  ( 999999     4999998)
      k:4  ( 999996     4999984)
      k:4  ( 999997     4999989)
      k:4  ( 999998     4999994)
      k:4  ( 999999     4999999)
      
      posted @ 2018-12-12 11:40  龔細軍  閱讀(528)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 少妇伦子伦精品无吗| 日韩av一区二区不卡在线| 精品人妻一区二区三区四区在线| 亚洲天堂成年人在线视频| 99久久99这里只有免费费精品| 日日噜久久人妻一区二区| 人妻少妇精品中文字幕| 欧美亚洲国产日韩一区二区| 亚洲色在线v中文字幕| 色视频在线观看免费视频| 国产系列高清精品第一页| 18无码粉嫩小泬无套在线观看| 亚洲一区三区三区成人久| 曲沃县| 中文国产人精品久久蜜桃| 中文字幕av日韩有码| 国产亚洲AV电影院之毛片| 色综合天天综合网中文伊| 色窝窝免费一区二区三区| 天天躁日日躁狠狠躁中文字幕| 欧美精品高清在线观看| 国产主播精品福利午夜二区 | 亚洲中文字幕伊人久久无码| 亚洲国产v高清在线观看| 精品一二三四区在线观看| 国产免费又黄又爽又色毛| 欧美老少配性行为| 人妻人人澡人人添人人爽| 欧美大胆老熟妇乱子伦视频| 国产日韩入口一区二区| 成人国产精品日本在线观看| 亚洲av免费成人精品区| 国产播放91色在线观看| 激情四射激情五月综合网| 亚洲人妻精品一区二区| 欧美一本大道香蕉综合视频| 国产精品无码无片在线观看3d| 免费午夜无码视频在线观看| 亚洲精品乱码久久久久久按摩高清| 免费超爽大片黄| 福利一区二区1000|