Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

30
LINES

< > BotCompany Repo | #1011925 // parallelMap

JavaX fragment (include)

1  
static <A extends Collection<? extends Collection>> L parallelMap(A l, fO f) ctex {
2  
  ret parallelMap(iterator((Collection) l), f);
3  
}
4  
5  
static L parallelMap(Iterator<? extends Collection> it, fO f) ctex {
6  
  final new L<Pair<O, Int>> out;
7  
    
8  
  int poolSize = coresToUse(), queueSize = 10;
9  
  NotifyingBlockingThreadPoolExecutor e = new(poolSize, queueSize, 15, TimeUnit.SECONDS);
10  
    
11  
  try {
12  
    int i = 0;
13  
    for (fO o : iterable(it)) {
14  
      ++i;
15  
      final int _i = i;
16  
      e.execute(r { pcall {
17  
        O x = callF(f, o);
18  
        synchronized(out) {
19  
          out.add(pair(x, _i));
20  
        }
21  
      }});
22  
    }
23  
    e.shutdown();
24  
    e.awaitTermination(1, TimeUnit.DAYS);
25  
  } finally {
26  
    e.shutdown();
27  
  }
28  
    
29  
  ret firstOfPairs(sortBySecondOfPairs_inPlace(out));
30  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1011925
Snippet name: parallelMap
Eternal ID of this version: #1011925/8
Text MD5: 7ca418b27415874df6364888881cf3e5
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-14 01:26:51
Source code size: 801 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 486 / 506
Version history: 7 change(s)
Referenced in: [show references]