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

30
LINES

< > BotCompany Repo | #1025019 // transitiveHullOfFunction_multipleInputs

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

Libraryless. Click here for Pure Java version (2234L/14K).

1  
// f : A -> Collection<A>
2  
// trace_out collects what the function returns
3  
static <A> Set<A> mapLike transitiveHullOfFunction_multipleInputs(O f, Cl<A> inputs, O... _) {
4  
  final HashSet<A> seen = asHashSet(inputs);
5  
  final Int max = cast optPar max(_);
6  
  Map trace_out = cast optPar trace_out(_);
7  
  
8  
  // Make pool of iterators
9  
  final new LinkedList<Iterator<A>> pool;
10  
  fOr (A input : inputs)
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  
}

Author comment

Began life as a copy of #1022458

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025019
Snippet name: transitiveHullOfFunction_multipleInputs
Eternal ID of this version: #1025019/3
Text MD5: 7af36670d4aa483864259eecf39a4419
Transpilation MD5: ce8e34251e0779fc46a2ee6ca49518cc
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-01 13:16:43
Source code size: 999 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 165 / 242
Version history: 2 change(s)
Referenced in: [show references]