1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
package sketch;
import kmer.AbstractKmerTable;
import structures.LongList;
public class Whitelist {
public static void initialize(AbstractKmerTable[] tableArray){
assert(keySets==null);
keySets=tableArray;
}
public static void apply(Sketch s){
assert(exists());
LongList list=new LongList(s.keys.length);
for(long key : s.keys){
if(contains(key)){
list.add(key);
}
}
if(list.size()!=s.keys.length){
s.keys=list.toArray();
}
}
/** Hashed value from an actual sketch */
public static boolean contains(long key){
if(keySets==null){return true;}
int way=(int)(key%ways);
return keySets[way].getValue(key)>0;
}
/** Raw hashed value which has not yet been subtracted from Long.MAX_VALUE */
public static boolean containsRaw(long key){
return contains(Long.MAX_VALUE-key);
}
public static boolean exists(){
return keySets!=null;
}
/** Hold codes. A code X such that X%WAYS=Y will be stored in keySets[Y] */
private static AbstractKmerTable[] keySets;
private static final int ways=31;
}
|