Libraryless. Click here for Pure Java version (3198L/20K).
1 | sclass AllOnAll<A, B> implements Producer<Pair<A, B>> { |
2 | new L<A> aList; |
3 | new L<B> bList; |
4 | LPair<IntRange> todo = new LinkedList; |
5 | LPair<A, B> todo2 = new LinkedList; |
6 | |
7 | void addA(A a) { newA(a); } |
8 | void addAIfNotNull(A a) { if (a != null) newA(a); } |
9 | |
10 | synchronized void newA(A a) { |
11 | add(aList, a); |
12 | addPair(todo, intRange_last(aList), intRange(0, l(bList))); |
13 | } |
14 | |
15 | synchronized void newAs(Iterable<A> l) { |
16 | fOr (A a : l) newA(a); |
17 | } |
18 | |
19 | void addB(B b) { newB(b); } |
20 | void addBIfNotNull(B b) { if (b != null) newB(b); } |
21 | |
22 | synchronized void newB(B b) { |
23 | add(bList, b); |
24 | addPair(todo, intRange(0, l(aList)), intRange_last(bList)); |
25 | } |
26 | |
27 | synchronized void newBs(Iterable<B> l) { |
28 | fOr (B b : l) newB(b); |
29 | } |
30 | |
31 | public synchronized Pair<A, B> next() { |
32 | while (empty(todo2)) { |
33 | if (empty(todo)) null; |
34 | Pair<IntRange> p = popFirst(todo); |
35 | addAll(todo2, outerProduct_pairs(subList(aList, p.a), subList(bList, p.b))); |
36 | } |
37 | ret popFirst(todo2); |
38 | } |
39 | |
40 | synchronized L cloneBList() { |
41 | ret clonedList(bList); |
42 | } |
43 | |
44 | L<A> getAs() { ret aList; } |
45 | L<B> getBs() { ret bList; } |
46 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1023892 |
Snippet name: | AllOnAll |
Eternal ID of this version: | #1023892/17 |
Text MD5: | b294e321494f56ff4c717f18587745be |
Transpilation MD5: | 5590e5cf40969241cb47f270bca9e1ef |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-06-20 20:09:36 |
Source code size: | 1176 bytes / 46 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 455 / 965 |
Version history: | 16 change(s) |
Referenced in: | [show references] |