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.

// trace_out collects what the function returns
// returns LinkedHashSet including input (objects are in order of discovery)
sclass TransitiveHull<A> implements SteppableAndIF0<Set<A>> {
  IF1<A, Iterable<A>> f;
  new LinkedHashSet<A> seen;
  new LinkedList<Iterator<A>> pool;
  Int max;
  
  *(IF1<A, Iterable<A>> *f, A starter) { add(starter); }
  
  void add(A a) {
    pool.add(singletonIterator(a));
  }
  
  public bool step() {
    if (max != null && l(seen) >= max) false;
    if (empty(pool)) false;
    Iterator<A> it = first(pool);
    if (!it.hasNext()) {
      removeFirst(pool);
      true;
    }
    process(it.next());
    true;
  }
  
  void process(A entry) {
    if (!seen.add(entry)) ret;

    // found new entry - return and schedule for further analysis
    Iterable<A> newStuff = f.get(entry);
    onGotCollection(entry, newStuff);
    if (nempty(newStuff))
      pool.add(iterator(newStuff));
  }
  
  swappable void onGotCollection(A entry, Iterable<A> newStuff) {
  }
  
  public Set<A> get() { ret seen; }
}

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: 234 / 438
Version history: 10 change(s)
Referenced in: [show references]