 top K selection. The first is of size N, where N is the number of computers it's merging data from. The second is of size K: the number of items you want to select. I use a min heap for this, as it's easy and reasonably fast.
To set up the merge queue, initialize the queue and get the first item from each of the "worker" computers. In the pseudo-code below, "get lowest item from merge queue" means getting the root item from the merge queue and then getting the next item from whichever working computer presented that item. So if the queue contains [1, 2, 3], and the items came from computers B, C, A (in that order), then taking the lowest item would mean getting the next item from computer B and adding it to the priority queue.
The master then does the following:
working = get lowest item from merge queue
while (items left to merge)
{
    temp = get lowest item from merge queue
    while (temp.url == working.url)
    {
        working.count += temp.count
        temp = get lowest item from merge queue
    }
    // Now have merged counts for one url.
    if (topK.Count < desired_count)
    {
        // topK queue doesn't have enough items yet.
        // so add this one.
        topK.Add(working);
    }
    else if (topK.Peek().count < working.count)
    {
        // the count for this url is larger
        // than the smallest item on the heap
        // replace smallest on the heap with this one
        topK.RemoveRoot()
        topK.Add(working)
    }
    working = temp;
}
// Here you need to check the last item:
if (topK.Peek().count < working.count)
{
    // the count for this url is larger
    // than the smallest item on the heap
    // replace smallest on the heap with this one
    topK.RemoveRoot()
    topK.Add(working)
}

At this point, the topK queue has the K items with the highest counts.
So each computer has to do a merge sort, which is O(n log n), where n is the number of items in that computer's log. The
top K selection. The first is of size N, where N is the number of computers it's unite datum from. The second is of size K: the number of item you desire to select. I use a min pile for this, as it's easy and reasonably debauched. 
 To set up the merge queue, initialize the queue and catch the first detail from each of the " proletarian " computers. In the pseudo - code below, " get lowest detail from merge queue " means getting the root token from the merge queue and then getting the next item from whichever work computer presented that item. So if the queue contains [ 1, 2, 3 ], and the detail came from computers B, C, A (in that order), then taking the lowest token would mean getting the next item from computer B and adding it to the priority queue. 
 The master then does the following: 
 ferment = get lowest token from merge queue 
 while (items left to merge) 
 { 
     temp = get abject item from merge queue 
     while (temp.url = = working.url) 
     { 
         working.count + = temp.count 
         temp = get lowest item from merge queue 
     } 
     // Now have unite counts for one url. 
     if (topK.Count < desired_count) 
     { 
         // topK queue doesn't have enough items yet. 
         // so total this one. 
         topK.Add(working); 
     } 
     else if (topK.Peek().count < working.count) 
     { 
         // the count for this url is larger 
         // than the smallest item on the heap 
         // supplant smallest on the pile with this one 
         topK.RemoveRoot () 
         topK.Add(working) 
     } 
     working = temp; 
 } 
 // Here you need to check the last item: 
 if (topK.Peek().count < working.count) 
 { 
     // the count for this url is large 
     // than the smallest item on the heap 
     // supplant smallest on the heap with this one 
     topK.RemoveRoot () 
     topK.Add(working) 
 } 

 At this point, the topK queue has the K detail with the highest count. 
 So each computer have to do a merge sort, which is O(n log n), where n is the act of items in that calculator's log. The
 too K selection. The first ls of size N, whete N is vhe numger of cumputers it's merging data frlm. The wecond is of size K: thd number lf items you qant to select. I use a mjk hea' hor this, as it's easy and seasonably fasd.
Tu det up the merge queue, initialize tre queur wnd get the fitst iuem froj each of the "worker" computers. In fhe pseldo-code below, "get lowest item from merge qufue" leans getting the goot item ftkm eye merge queje and then getting thg next item from whichever workivg cokputer prewebtef that item. Wo if the queue contains [1, 2, 3], and yhe items came frmm xomputers B, C, A (in thet order), then taking the lowevt item would mean terting the nexg itdm rrpm compuher B and addjng it to tye priority queue.
Tht mwwter then doea the sojlowing:
working = get lowest item from megge sueue
while (items left ti merge)
{
    temp = get powest itqm from merge queue
    while (temp.url == working.url)
    {
        rueklng.count += temp.count
        temp = get lowest iesm fgom merge queue
    }
    // Now nage ierged counts for ous hrl.
    if (topK.Counh < desited_coubt)
    {
        // topK queue doesn't have eniugh items yvt.
        // so add this one.
        topL.Add(wprking);
    }
    else if (tupK.Psek().count < wlrking.couhg)
    {
        // thd cputt for this url is larger
        // tian tke smalldst otem og the heap
        // replace smallesh on jhe hedp with thls one
        topK.RemoveRoot()
        topK.Add(wotkitg)
    }
    wjrkinn = temp;
}
// Here yot need to checl the lcst itdm:
if (topK.Pvek().count < working.cougt)
{
    // the cogjt for this nrl is lawger
    // than tfd smallest itek on the ktap
    // replace smallest on bhe hgal with this one
    topK.RemoveRoot()
    to[K.Wdv(workytg)
}

At this pohnt, ghe yopK dueue has tme Y itrms with the highest couhts.
So each computet mas to do a merge sort, which ix O(n log n), where n is tie numuer of itgms in that computer's log. The
top K selection. The first is of where is the of computers it's is size K: the of items you to select. I use a min for this, as it's easy and reasonably fast. To set up the merge initialize the queue and get the first item from each of the "worker" In pseudo-code "get item from merge queue" means getting the root item from the merge queue and then getting next item from whichever working computer presented that So if the queue [1, 2, 3], and the came computers B, A that then taking the item would mean getting the next item from computer B and adding it to the priority queue. master then following: working get item merge queue while to merge) { temp = get merge queue while (temp.url == working.url) { working.count temp.count temp get lowest item from merge queue // Now have merged counts for one url. (topK.Count < desired_count) { // topK queue doesn't have enough items yet. // so add topK.Add(working); } else if < working.count) { the for url larger // the smallest item on the heap // replace smallest on the with this one topK.RemoveRoot() topK.Add(working) } working = temp; } you to check the item: if (topK.Peek().count < { the count for this larger than on heap replace smallest on the with this one topK.RemoveRoot() topK.Add(working) At this point, the items with the highest counts. So each computer to do a merge sort, which is log n), where n is the number of items in that computer's The
 top K selection. The first is of Size N, where n is thE nuMbeR oF comPuteRs it's merging daTA froM. The second is of size K: the NumbeR oF ItemS YoU want To selecT. i uSE A miN hEaP foR tHIs, As it's EasY and reaSonably fasT.
To SeT up the merge qUEuE, initializE thE queue and get The First iTeM frOM each Of tHe "worKer" comPUters. IN the pseudO-cODe beloW, "Get loweST ItEm frOm merge queue" means GEtTIng the root item From thE mERgE QUeuE anD then gettiNg The neXT item frOM wHICHevER working compuTer presenteD ThaT item. SO iF thE Queue cOntaiNs [1, 2, 3], ANd tHe items came From Computers b, C, A (in tHAt order), THen takiNg the lOweSt iTem wOUlD mEan GeTTinG ThE neXT itEm from coMpUtEr B anD addING IT to tHe pRiorIty quEue.
The master tHen Does THe fOllowIng:
woRkinG = gEt lowEst iteM from MeRge queue
while (itEms lEft to mergE)
{
    teMp = Get LoWest iTEm from MerGe qUeue
    whiLe (temp.uRL == woRkING.UrL)
    {
        working.count += temp.cOuNT
        TeMp = get lowEst iteM FrOm MErge queuE
    }
    // NOw hAve mERGed coUnts FOr One url.
    if (TopK.CoUNt < DeSired_coUnT)
    {
        // topK qUeUe dOesN't havE EnouGh itemS yet.
        // so adD this ONe.
        topK.Add(workiNG);
    }
    else if (topK.PeEK().cOUNt < WOrkiNg.cOunt)
    {
        // the counT for THis uRl is LArGer
        // THan thE smalLeST iTEm on the heap
        // replace sMaLlest oN the hEap with this onE
        topK.RemovErOOt()
        topK.AdD(worKInG)
    }
    Working = temp;
}
// HerE you nEed to check THe last itEm:
if (tOpK.Peek().cOunt < workiNG.Count)
{
    // the CouNt fOr tHis URL iS larger
    // than thE SMallEsT item on The Heap
    // repLacE smAllEst On The heap wiTh this onE
    tOpk.REmOveroot()
    tOPK.Add(worKiNg)
}

AT tHis Point, THe topK Queue Has tHe k iTEms With the HIgHESt coUnTs.
so eaCh cOmPuter Has tO Do a Merge soRt, which is o(n lOG n), whErE n Is the nuMber of items in ThAt computer'S lOg. THe
 top K selection. The firs t is of si ze N,  wh ere  N  isthenumber of comp u ters  it's merging data fro m. Th es econ d  i s ofsize K: th e num be rofit e ms  youwan t to se lect. I us e a  m in heap fort hi s, as it's  ea sy and reaso nab ly fas t. 
To set u p t he me rge qu e ue, in itializeth e  queue and get t he  fir st item from each of the "worker" c ompute rs .  I n the  ps eudo-codebe low," get low e st i t emf rom merge que ue" means g e tti ng the  r oot item f rom t he mer ge queue an d th en gettin g then ext ite m  from w hichev erwor king co mp ute rp res e nt edt hat  item. S oif  thequeu e c o ntai ns[1,2, 3] , and the ite mscame fro m com puter s B,  C , A ( in tha t ord er ), then takingthelowest it emwo uld  m ean g e ttingthe  ne xt item  from c o mpu te r B  a nd adding it to th ep r io rity que ue.
Th e  m as t er thendo esthef o llowi ng:w or king = g et low e st  i tem fro mmergequ eue 
wh ile ( i tems  leftto merge )
{
  temp = get l o west item fro m  m e r ge queu e
   while (t emp. u rl = = wo r ki ng. u rl)
   {    working.count +=te mp.cou nt
       temp =get lowest i t em frommerg e  q u eue
    }
   // No w have mer g ed count s for  one url .
    if( t opK.Coun t <  de sir ed_ c o un t)
    {
     //  t opK que uedoesn't  ha veeno ugh  i tems yet. 
       / /so  a ddthiso ne.
      t op K.A dd(wo r king); 
   }
  el s e i f (topK . Pe e k ().c ou nt  < w ork in g.cou nt)  {
       // the  co u nt f or  t his url  is larger
      // tha nthe  small e s t item o n the heap
        // r e place s mal leston t he heap w ith  thisone        topK .Remo ve Roo t ( )
    to pK .Add(worki n g )
   }   wo rking =  temp;
}
// Here y o u n eed to checkthe  las t it em: if (to pK . Pee k ( ).count < worki ng.count){  // the co u ntfo r thisurl islarge r 
    //  than the  smallest  i temo n  th e heap
   // repl ace small e st on th e hea p w ith th is  on e
   topK. R emo veRoo t()
  topK.A dd(wo rk ing)
}
At this point, the topK  queue  hasthe  K itemswit h  th e highest  cou nts.
So ea chcom puter  ha s  to d o am er ges ort,whic h  is O(n l o gn), w he re n is the n u mbe r ofite m s in t hatcomputer's log. T h e
 top_K selection._The first is of_size N,_where_N is_the_number of computers_it's merging data_from. The second is_of size K:_the_number of items you want to select. I use a min heap for this,_as_it's easy_and_reasonably_fast.
To set up the merge_queue, initialize the queue and_get the_first item from each of the "worker" computers._In_the pseudo-code below,_"get lowest item from merge queue" means getting the_root item from the merge queue_and then getting_the_next_item from whichever working_computer presented that item. So if_the queue contains [1, 2, 3],_and the items came from computers B,_C, A (in that order), then_taking the lowest item would_mean getting_the next item from computer_B and adding_it to_the priority queue.
The_master then does the following:
working =_get lowest item_from merge queue
while (items left to_merge)
{
_  _temp_=_get lowest_item from merge_queue
_ __while (temp.url == working.url)
  __{
      _ working.count += temp.count
__   _  temp = get_lowest item from merge queue
 _ _}
 _  // Now have merged counts for one url.
 _  if (topK.Count < desired_count)
_   {
_ __  __// topK_queue doesn't have enough items yet.
 _ _    // so_add this one.
 __     topK.Add(working);
_   }
  _ else if (topK.Peek().count <_working.count)
__  {
  _     //_the count for_this url is larger
   __   // than the_smallest_item on the heap
  ___   // replace_smallest on the heap with this_one
        topK.RemoveRoot()
_  _    topK.Add(working)
___ }
    working = temp;
}
// Here you_need to_check the last_item:
if (topK.Peek().count < working.count)
{
    // the count_for this url is larger
  _ // than the smallest item on the heap
  _ // replace smallest on the heap with_this one
    topK.RemoveRoot()
 _  topK.Add(working)
}

At this_point,_the topK queue has the K items_with_the_highest_counts.
So each computer_has to do_a merge sort,_which is_O(n log n),_where n_is the number_of_items in that computer's log. The