public BloomFilterBuf(long expectedEntries, long maxEntries) { if (expectedEntries > maxEntries) { bloomFilter = new BloomKFilter(maxEntries); } else { bloomFilter = new BloomKFilter(expectedEntries); } }
public Aggregation(long expectedEntries) { bf = new BloomKFilter(expectedEntries); }
/** * Deserialize a bloom filter * Read a byte stream, which was written by {@linkplain #serialize(OutputStream, BloomKFilter)} * into a {@code BloomKFilter} * * @param in input bytestream * @return deserialized BloomKFilter */ public static BloomKFilter deserialize(InputStream in) throws IOException { if (in == null) { throw new IOException("Input stream is null"); } try { DataInputStream dataInputStream = new DataInputStream(in); int numHashFunc = dataInputStream.readByte(); int bitsetArrayLen = dataInputStream.readInt(); long[] data = new long[bitsetArrayLen]; for (int i = 0; i < bitsetArrayLen; i++) { data[i] = dataInputStream.readLong(); } return new BloomKFilter(data, numHashFunc); } catch (RuntimeException e) { throw new IOException("Unable to deserialize BloomKFilter", e); } }
public Aggregation(long expectedEntries) { ByteArrayOutputStream bytesOut = null; try { BloomKFilter bf = new BloomKFilter(expectedEntries); bytesOut = new ByteArrayOutputStream(); BloomKFilter.serialize(bytesOut, bf); bfBytes = bytesOut.toByteArray(); } catch (Exception err) { throw new IllegalArgumentException("Error creating aggregation buffer", err); } finally { IOUtils.closeStream(bytesOut); } }
/** * Deserialize a bloom filter * Read a byte stream, which was written by {@linkplain #serialize(OutputStream, BloomKFilter)} * into a {@code BloomKFilter} * * @param in input bytestream * @return deserialized BloomKFilter */ public static BloomKFilter deserialize(InputStream in) throws IOException { if (in == null) { throw new IOException("Input stream is null"); } try { DataInputStream dataInputStream = new DataInputStream(in); int numHashFunc = dataInputStream.readByte(); int bitsetArrayLen = dataInputStream.readInt(); long[] data = new long[bitsetArrayLen]; for (int i = 0; i < bitsetArrayLen; i++) { data[i] = dataInputStream.readLong(); } return new BloomKFilter(data, numHashFunc); } catch (RuntimeException e) { IOException io = new IOException("Unable to deserialize BloomKFilter"); io.initCause(e); throw io; } }