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

34
LINES

< > BotCompany Repo | #1022458 // transitiveHullOfFunction

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

Transpiled version (2602L) is out of date.

1  
// f : A -> Collection<A>
2  
// trace_out collects what the function returns
3  
// returns hashset including input
4  
static <A> Set<A> mapLike transitiveHullOfFunction(O f, A input, O... _) {
5  
  final Set<A> seen = optPar(_, seen := (Set) lithashset(input));
6  
  final Int max = cast optPar max(_);
7  
  Map trace_out = cast optPar trace_out(_);
8  
  
9  
  // Make pool of iterators
10  
  final new LinkedList<Iterator<A>> pool;
11  
  pool.add(iterator((Iterable<A>) callF(f, input)));
12  
  int n = 0;
13  
    
14  
  while ping (!empty(pool) && (max == null || n < max)) {
15  
    Iterator<A> it = first(pool);
16  
    if (!it.hasNext()) continue with removeFirst(pool);
17  
    
18  
    // Get entry and check if seen already
19  
    A entry = it.next();
20  
    if (!seen.add(entry)) continue;
21  
22  
    // found new entry - return and schedule for further analysis
23  
    Collection<A> newStuff = cast callF(f, entry);
24  
    mapPut(trace_out, entry, newStuff);
25  
    if (nempty(newStuff))
26  
      pool.add(iterator(newStuff));
27  
    ++n;
28  
  }
29  
  ret seen;
30  
}
31  
32  
static <A> Set<A> transitiveHullOfFunction(IF1<A, Cl<A>> f, A input, O... _) {
33  
  ret transitiveHullOfFunction((O) f, input, _);
34  
}

Author comment

Began life as a copy of #1022233

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1022458
Snippet name: transitiveHullOfFunction
Eternal ID of this version: #1022458/12
Text MD5: c6fcbd862c354aae5022fd2f5c7e8fc6
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 21:47:54
Source code size: 1143 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 320 / 432
Version history: 11 change(s)
Referenced in: [show references]