@author Ka Ming Nip
| 38 | * @author Ka Ming Nip |
| 39 | */ |
| 40 | public class BloomFilter implements BloomFilterInterface { |
| 41 | protected AbstractLargeBitBuffer bitArray; |
| 42 | protected int numHash; |
| 43 | protected long size; |
| 44 | protected HashFunction hashFunction; |
| 45 | protected long popcount = -1; |
| 46 | |
| 47 | public BloomFilter(long size, int numHash, HashFunction hashFunction) { |
| 48 | |
| 49 | this.size = size; |
| 50 | try { |
| 51 | //System.out.println("unsafe"); |
| 52 | this.bitArray = new UnsafeBitBuffer(size); |
| 53 | } |
| 54 | catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { |
| 55 | this.bitArray = new LargeBitBuffer(size); |
| 56 | } |
| 57 | this.numHash = numHash; |
| 58 | this.hashFunction = hashFunction; |
| 59 | } |
| 60 | |
| 61 | private static final String LABEL_SEPARATOR = ":"; |
| 62 | private static final String LABEL_SIZE = "size"; |
| 63 | private static final String LABEL_NUM_HASH = "numhash"; |
| 64 | private static final String LABEL_FPR = "fpr"; |
| 65 | |
| 66 | public BloomFilter(File desc, File bits, HashFunction hashFunction) throws FileNotFoundException, IOException { |
| 67 | this(desc, bits, hashFunction, true); |
| 68 | } |
| 69 | |
| 70 | public BloomFilter(File desc, File bits, HashFunction hashFunction, boolean loadBits) throws FileNotFoundException, IOException { |
| 71 | |
| 72 | BufferedReader br = new BufferedReader(new FileReader(desc)); |
| 73 | String line; |
| 74 | while ((line = br.readLine()) != null) { |
| 75 | String[] entry = line.split(LABEL_SEPARATOR); |
| 76 | String key = entry[0]; |
| 77 | String val = entry[1]; |
| 78 | switch(key) { |
| 79 | case LABEL_SIZE: |
| 80 | size = Long.parseLong(val); |
| 81 | break; |
| 82 | case LABEL_NUM_HASH: |
| 83 | numHash = Integer.parseInt(val); |
| 84 | break; |
| 85 | } |
| 86 | } |
| 87 | br.close(); |
| 88 | |
| 89 | this.hashFunction = hashFunction; |
| 90 | |
| 91 | try { |
| 92 | //System.out.println("unsafe"); |
| 93 | this.bitArray = new UnsafeBitBuffer(size); |
| 94 | } |
| 95 | catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { |
| 96 | this.bitArray = new LargeBitBuffer(size); |
| 97 | } |
nothing calls this directly
no outgoing calls
no test coverage detected