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

29
LINES

< > BotCompany Repo | #1003859 // containsOneOf - possibly slow with array as 2nd argument; fast with Set

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

Libraryless. Click here for Pure Java version (2798L/16K).

1  
// unclear semantics when l is a special set (e.g. ciSet)
2  
3  
static <A> bool containsOneOf(Collection<A> l, A... x) {
4  
  if (l instanceof Set) {
5  
    if (x != null)
6  
      for (A a : x)
7  
        if (l.contains(a))
8  
          true;
9  
  } else {
10  
    for (A a : unnull(l))
11  
      if (eqOneOf(a, x))
12  
        true;
13  
  }
14  
  false;
15  
}
16  
17  
static <A> bool containsOneOf(Collection<A> l, Set<A> set) {
18  
  if (set == null) false;
19  
  for (A a : unnull(l))
20  
    if (set.contains(a))
21  
      true;
22  
  false;
23  
}
24  
25  
static bool containsOneOf(S s, S... x) {
26  
  for (S o : x)
27  
    if (contains(s, o)) true;
28  
  false;
29  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003859
Snippet name: containsOneOf - possibly slow with array as 2nd argument; fast with Set
Eternal ID of this version: #1003859/9
Text MD5: 84965dbb1088def45e1c19dfd54bc25d
Transpilation MD5: cfb00185f39a27c6b5f305361fcf7644
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-05 00:50:26
Source code size: 601 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 517 / 532
Version history: 8 change(s)
Referenced in: [show references]