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

65
LINES

< > BotCompany Repo | #1028478 // AllOnAll_probabilistic_forTransformers [dev., possibly faster than AllOnAll_probabilistic, not that easy to make]

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

Transpiled version (3252L) is out of date.

1  
sclass AllOnAll_probabilistic_forTransformers implements Producer<Pair<F1, O>> {
2  
  replace A with F1.
3  
  replace B with O.
4  
  
5  
  // We're grouping both a's and b's by the type accepted by the transformers.
6  
  // Of course things are never this easy because types have subtypes...
7  
  
8  
  new MultiMap<Class, A> aList;
9  
  new MultiMap<Class, B> bList;
10  
  LPair<Cl<A>, Cl<B>> todo = new LinkedList; // this is still non-probabilistic
11  
  MultiSetMap<Double, Pair<A, B>> todo2 = multiSetMap_outerDescTreeMap_innerLinkedHashSet();
12  
  
13  
  persistently swappable double probabilityForPair(A a, B b) { ret 1.0; }
14  
15  
  void addA(A a) { newA(a); }
16  
  void addAIfNotNull(A a) { if (a != null) newA(a); }
17  
  
18  
  synchronized void newA(A a) {
19  
    add(aList, a);
20  
    multiSetCombine(bList.get(classesForA(a));
21  
    IntRange rB = intRange(0, l(bList));
22  
    if (empty(rB)) ret;
23  
    addPair(todo, intRange_last(aList), rB);
24  
  }
25  
  
26  
  synchronized void newAs(Iterable<A> l) {
27  
    fOr (A a : l) newA(a);
28  
  }
29  
  
30  
  void addB(B b) { newB(b); }
31  
  void addBIfNotNull(B b) { if (b != null) newB(b); }
32  
  
33  
  synchronized void newB(B b) {
34  
    add(bList, b);
35  
    IntRange rA = intRange(0, l(aList));
36  
    if (empty(rA)) ret;
37  
    addPair(todo, rA, intRange_last(bList));
38  
  }
39  
  
40  
  synchronized void newBs(Iterable<B> l) {
41  
    fOr (B b : l) newB(b);
42  
  }
43  
  
44  
  public synchronized Pair<A, B> next() {
45  
    Pair<IntRange> p;
46  
    while ((p = popFirst(todo)) != null)
47  
      for (A a : subList(aList, p.a))
48  
        for (B b : subList(bList, p.b))
49  
          addAPair(a, b, probabilityForPair(a, b));
50  
51  
    ret popFirstValueFromMultiSetMap(todo2);
52  
  }
53  
  
54  
  private void addAPair(A a, B b, double probability) {
55  
    if (probability > 0)
56  
      todo2.put(probability, pair(a, b));
57  
  }
58  
  
59  
  synchronized L cloneBList() {
60  
    ret clonedList(bList);
61  
  }
62  
  
63  
  L<A> getAs() { ret aList; }
64  
  L<B> getBs() { ret bList; }
65  
}

Author comment

Began life as a copy of #1028466

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: #1028478
Snippet name: AllOnAll_probabilistic_forTransformers [dev., possibly faster than AllOnAll_probabilistic, not that easy to make]
Eternal ID of this version: #1028478/6
Text MD5: da612c9ea01993dfc369c6e4d549020b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-06-21 01:43:59
Source code size: 1915 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 176 / 260
Version history: 5 change(s)
Referenced in: [show references]