| 1 |
package sketch; |
| 2 |
|
| 3 |
import kmer.AbstractKmerTable; |
| 4 |
import structures.LongList; |
| 5 |
|
| 6 |
public class Whitelist { |
| 7 |
|
| 8 |
public static void initialize(AbstractKmerTable[] tableArray){ |
| 9 |
assert(keySets==null); |
| 10 |
keySets=tableArray; |
| 11 |
} |
| 12 |
|
| 13 |
public static void apply(Sketch s){ |
| 14 |
assert(exists()); |
| 15 |
LongList list=new LongList(s.keys.length); |
| 16 |
for(long key : s.keys){ |
| 17 |
if(contains(key)){ |
| 18 |
list.add(key); |
| 19 |
} |
| 20 |
} |
| 21 |
if(list.size()!=s.keys.length){ |
| 22 |
s.keys=list.toArray(); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
public static boolean contains(long key){ |
| 28 |
if(keySets==null){return true;} |
| 29 |
int way=(int)(key%ways); |
| 30 |
return keySets[way].getValue(key)>0; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
public static boolean containsRaw(long key){ |
| 35 |
return contains(Long.MAX_VALUE-key); |
| 36 |
} |
| 37 |
|
| 38 |
public static boolean exists(){ |
| 39 |
return keySets!=null; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
private static AbstractKmerTable[] keySets; |
| 44 |
private static final int ways=31; |
| 45 |
|
| 46 |
} |