Libraryless. Click here for Pure Java version (2252L/14K).
1 | sclass AllOnAllWithUpdates<A, B> { |
2 | long aCounter, bCounter; |
3 | new TreeMap<Long, A> aList; |
4 | new TreeMap<Long, B> bList; |
5 | LPair<LongRange> todo = new LinkedList; |
6 | LPair<Long> todo2 = new LinkedList; |
7 | |
8 | synchronized void newA(A a) { |
9 | long c = aCounter++; |
10 | aList.put(c, a); |
11 | addPair(todo, longRange_one(c), longRange(0, bCounter)); |
12 | } |
13 | |
14 | synchronized void newB(B b) { |
15 | long c = bCounter++; |
16 | bList.put(c, b); |
17 | addPair(todo, longRange(0, aCounter), longRange_one(c)); |
18 | } |
19 | |
20 | synchronized void updateA(A a) { |
21 | removeValue(aList, a); |
22 | newA(a); |
23 | } |
24 | |
25 | synchronized void updateB(B b) { |
26 | removeValue(bList, b); |
27 | newB(b); |
28 | } |
29 | |
30 | synchronized Pair<A, B> next() { |
31 | while licensed { |
32 | while (empty(todo2)) { |
33 | if (empty(todo)) null; |
34 | Pair<LongRange> p = popFirst(todo); |
35 | addAll(todo2, outerProduct_pairs(keys(subMap_longRange(aList, p.a)), keys(subMap_longRange(bList, p.b)))); |
36 | } |
37 | Pair<Long> p = popFirst(todo2); |
38 | A a = aList.get(p.a); |
39 | B b = bList.get(p.b); |
40 | if (a != null && b != null) ret pair(a, b); |
41 | } |
42 | null; |
43 | } |
44 | } |
Began life as a copy of #1023892
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1023903 |
Snippet name: | AllOnAllWithUpdates |
Eternal ID of this version: | #1023903/11 |
Text MD5: | 5028f2ad8136bc9ab2c6bebd93e563df |
Transpilation MD5: | 86c2340fd59852984527276e79ee2566 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-07-12 02:19:36 |
Source code size: | 1150 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 279 / 738 |
Version history: | 10 change(s) |
Referenced in: | [show references] |