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 (2817L/17K).

sclass AllOnAll<A, B> implements Producer<Pair<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);
  }
  
  public 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 3 computer(s): mqqgnosmbjvj, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1023892
Snippet name: AllOnAll
Eternal ID of this version: #1023892/12
Text MD5: 058d4a2e59a8d567cedf4912bb83e31c
Transpilation MD5: f065994c6abb106ba7accb3f74326b57
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-12-25 15:48:49
Source code size: 860 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 55 / 194
Version history: 11 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1023892 & http://1023892.tinybrain.de