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

41
LINES

< > BotCompany Repo | #1031545 // TransitiveHull - class version of transitiveHullOfFunction

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

Transpiled version (3458L) is out of date.

1  
// trace_out collects what the function returns
2  
// returns LinkedHashSet including input (objects are in order of discovery)
3  
sclass TransitiveHull<A> implements SteppableAndIF0<Set<A>> {
4  
  IF1<A, Iterable<A>> f;
5  
  new LinkedHashSet<A> seen;
6  
  new LinkedList<Iterator<A>> pool;
7  
  Int max;
8  
  
9  
  *(IF1<A, Iterable<A>> *f, A starter) { add(starter); }
10  
  
11  
  void add(A a) {
12  
    pool.add(singletonIterator(a));
13  
  }
14  
  
15  
  public bool step() {
16  
    if (max != null && l(seen) >= max) false;
17  
    if (empty(pool)) false;
18  
    Iterator<A> it = first(pool);
19  
    if (!it.hasNext()) {
20  
      removeFirst(pool);
21  
      true;
22  
    }
23  
    process(it.next());
24  
    true;
25  
  }
26  
  
27  
  void process(A entry) {
28  
    if (!seen.add(entry)) ret;
29  
30  
    // found new entry - return and schedule for further analysis
31  
    Iterable<A> newStuff = f.get(entry);
32  
    onGotCollection(entry, newStuff);
33  
    if (nempty(newStuff))
34  
      pool.add(iterator(newStuff));
35  
  }
36  
  
37  
  swappable void onGotCollection(A entry, Iterable<A> newStuff) {
38  
  }
39  
  
40  
  public Set<A> get() { ret seen; }
41  
}

Author comment

Began life as a copy of #1022458

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031545
Snippet name: TransitiveHull - class version of transitiveHullOfFunction
Eternal ID of this version: #1031545/11
Text MD5: 9c29810e462678db8b44e9661be57382
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-21 22:26:00
Source code size: 1074 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 125 / 289
Version history: 10 change(s)
Referenced in: [show references]