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

33
LINES

< > BotCompany Repo | #1023892 - AllOnAll

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2799L/17K).

sclass AllOnAll<A, B> {
  new L<A> aList;
  new L<B> bList;
  LPair<IntRange> todo = new LinkedList;
  LPair<A, B> todo2 = new LinkedList;

  synchronized void newA(A a) {
    add(aList, a);
    addPair(todo, intRange_last(aList), intRange(0, l(bList)));
  }
  
  synchronized void newAs(Iterable<A> l) {
    fOr (A a : l) newA(a);
  }
  
  synchronized void newB(B b) {
    add(bList, b);
    addPair(todo, intRange(0, l(aList)), intRange_last(bList));
  }
  
  synchronized void newBs(Iterable<B> l) {
    fOr (B b : l) newB(b);
  }
  
  synchronized Pair<A, B> next() {
    while (empty(todo2)) {
      if (empty(todo)) null;
      Pair<IntRange> p = popFirst(todo);
      addAll(todo2, outerProduct_pairs(subList(aList, p.a), subList(bList, p.b)));
    }
    ret popFirst(todo2);
  }
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1023892
Snippet name: AllOnAll
Eternal ID of this version: #1023892/11
Text MD5: b8af014f88172f14e1d5a36dc92bac30
Transpilation MD5: 64fa0d8a85ca4105ca2fd3370db03434
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-05 16:08:09
Source code size: 821 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 36 / 142
Version history: 10 change(s)
Referenced in: [show references]