本文整理汇总了Java中com.google.common.hash.BloomFilterStrategies.BitArray类的典型用法代码示例。如果您正苦于以下问题:Java BitArray类的具体用法?Java BitArray怎么用?Java BitArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitArray类属于com.google.common.hash.BloomFilterStrategies包,在下文中一共展示了BitArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
@VisibleForTesting
static <T> BloomFilter<T> create(
Funnel<? super T> funnel, long expectedInsertions, double fpp, Strategy strategy) {
checkNotNull(funnel);
checkArgument(
expectedInsertions >= 0, "Expected insertions (%s) must be >= 0", expectedInsertions);
checkArgument(fpp > 0.0, "False positive probability (%s) must be > 0.0", fpp);
checkArgument(fpp < 1.0, "False positive probability (%s) must be < 1.0", fpp);
checkNotNull(strategy);
if (expectedInsertions == 0) {
expectedInsertions = 1;
}
/*
* TODO(user): Put a warning in the javadoc about tiny fpp values, since the resulting size
* is proportional to -log(p), but there is not much of a point after all, e.g.
* optimalM(1000, 0.0000000000000001) = 76680 which is less than 10kb. Who cares!
*/
long numBits = optimalNumOfBits(expectedInsertions, fpp);
int numHashFunctions = optimalNumOfHashFunctions(expectedInsertions, numBits);
try {
return new BloomFilter<T>(new BitArray(numBits), numHashFunctions, funnel, strategy);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not create BloomFilter of " + numBits + " bits", e);
}
}
示例2: create
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
@VisibleForTesting
static <T> BloomFilter<T> create(Funnel<? super T> funnel, long expectedInsertions, double fpp, Strategy strategy) {
checkNotNull(funnel);
checkArgument(expectedInsertions >= 0, "Expected insertions (%s) must be >= 0", expectedInsertions);
checkArgument(fpp > 0.0, "False positive probability (%s) must be > 0.0", fpp);
checkArgument(fpp < 1.0, "False positive probability (%s) must be < 1.0", fpp);
checkNotNull(strategy);
if (expectedInsertions == 0) {
expectedInsertions = 1;
}
/*
* TODO(user): Put a warning in the javadoc about tiny fpp values, since the resulting size
* is proportional to -log(p), but there is not much of a point after all, e.g.
* optimalM(1000, 0.0000000000000001) = 76680 which is less than 10kb. Who cares!
*/
long numBits = optimalNumOfBits(expectedInsertions, fpp);
int numHashFunctions = optimalNumOfHashFunctions(expectedInsertions, numBits);
try {
return new BloomFilter<T>(new BitArray(numBits), numHashFunctions, funnel, strategy);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not create BloomFilter of " + numBits + " bits", e);
}
}
示例3: create
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Creates a {@link BloomFilter BloomFilter<T>} with the expected number of
* insertions and expected false positive probability.
*
* <p>Note that overflowing a {@code BloomFilter} with significantly more elements
* than specified, will result in its saturation, and a sharp deterioration of its
* false positive probability.
*
* <p>The constructed {@code BloomFilter<T>} will be serializable if the provided
* {@code Funnel<T>} is.
*
* <p>It is recommended that the funnel be implemented as a Java enum. This has the
* benefit of ensuring proper serialization and deserialization, which is important
* since {@link #equals} also relies on object identity of funnels.
*
* @param funnel the funnel of T's that the constructed {@code BloomFilter<T>} will use
* @param expectedInsertions the number of expected insertions to the constructed
* {@code BloomFilter<T>}; must be positive
* @param fpp the desired false positive probability (must be positive and less than 1.0)
* @return a {@code BloomFilter}
*/
public static <T> BloomFilter<T> create(
Funnel<T> funnel, int expectedInsertions /* n */, double fpp) {
checkNotNull(funnel);
checkArgument(expectedInsertions >= 0, "Expected insertions (%s) must be >= 0",
expectedInsertions);
checkArgument(fpp > 0.0, "False positive probability (%s) must be > 0.0", fpp);
checkArgument(fpp < 1.0, "False positive probability (%s) must be < 1.0", fpp);
if (expectedInsertions == 0) {
expectedInsertions = 1;
}
/*
* TODO(user): Put a warning in the javadoc about tiny fpp values,
* since the resulting size is proportional to -log(p), but there is not
* much of a point after all, e.g. optimalM(1000, 0.0000000000000001) = 76680
* which is less than 10kb. Who cares!
*/
long numBits = optimalNumOfBits(expectedInsertions, fpp);
int numHashFunctions = optimalNumOfHashFunctions(expectedInsertions, numBits);
try {
return new BloomFilter<T>(new BitArray(numBits), numHashFunctions, funnel,
BloomFilterStrategies.MURMUR128_MITZ_32);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not create BloomFilter of " + numBits + " bits", e);
}
}
示例4: create
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Creates a {@code Builder} of a {@link BloomFilter BloomFilter<T>}, with the expected number
* of insertions and expected false positive probability.
*
* <p>Note that overflowing a {@code BloomFilter} with significantly more elements
* than specified, will result in its saturation, and a sharp deterioration of its
* false positive probability.
*
* <p>The constructed {@code BloomFilter<T>} will be serializable if the provided
* {@code Funnel<T>} is.
*
* <p>It is recommended the funnel is implemented as a Java enum. This has the benefit of ensuring
* proper serialization and deserialization, which is important since {@link #equals} also relies
* on object identity of funnels.
*
* @param funnel the funnel of T's that the constructed {@code BloomFilter<T>} will use
* @param expectedInsertions the number of expected insertions to the constructed
* {@code BloomFilter<T>}; must be positive
* @param fpp the desired false positive probability (must be positive and less than 1.0)
* @return a {@code BloomFilter}
*/
public static <T> BloomFilter<T> create(
Funnel<T> funnel, int expectedInsertions /* n */, double fpp) {
checkNotNull(funnel);
checkArgument(expectedInsertions >= 0, "Expected insertions (%s) must be >= 0",
expectedInsertions);
checkArgument(fpp > 0.0, "False positive probability (%s) must be > 0.0", fpp);
checkArgument(fpp < 1.0, "False positive probability (%s) must be < 1.0", fpp);
if (expectedInsertions == 0) {
expectedInsertions = 1;
}
/*
* TODO(user): Put a warning in the javadoc about tiny fpp values,
* since the resulting size is proportional to -log(p), but there is not
* much of a point after all, e.g. optimalM(1000, 0.0000000000000001) = 76680
* which is less that 10kb. Who cares!
*/
long numBits = optimalNumOfBits(expectedInsertions, fpp);
int numHashFunctions = optimalNumOfHashFunctions(expectedInsertions, numBits);
try {
return new BloomFilter<T>(new BitArray(numBits), numHashFunctions, funnel,
BloomFilterStrategies.MURMUR128_MITZ_32);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not create BloomFilter of " + numBits + " bits", e);
}
}
示例5: BloomFilter
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Creates a BloomFilter.
*/
private BloomFilter(
BitArray bits, int numHashFunctions, Funnel<? super T> funnel, Strategy strategy) {
checkArgument(numHashFunctions > 0, "numHashFunctions (%s) must be > 0", numHashFunctions);
checkArgument(
numHashFunctions <= 255, "numHashFunctions (%s) must be <= 255", numHashFunctions);
this.bits = checkNotNull(bits);
this.numHashFunctions = numHashFunctions;
this.funnel = checkNotNull(funnel);
this.strategy = checkNotNull(strategy);
}
示例6: readFrom
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Reads a byte stream, which was written by {@linkplain #writeTo(OutputStream)}, into a
* {@code BloomFilter<T>}.
*
* The {@code Funnel} to be used is not encoded in the stream, so it must be provided here.
* <b>Warning:</b> the funnel provided <b>must</b> behave identically to the one used to populate
* the original Bloom filter!
*
* @throws IOException if the InputStream throws an {@code IOException}, or if its data does not
* appear to be a BloomFilter serialized using the {@linkplain #writeTo(OutputStream)} method.
*/
public static <T> BloomFilter<T> readFrom(InputStream in, Funnel<? super T> funnel)
throws IOException {
checkNotNull(in, "InputStream");
checkNotNull(funnel, "Funnel");
int strategyOrdinal = -1;
int numHashFunctions = -1;
int dataLength = -1;
try {
DataInputStream din = new DataInputStream(in);
// currently this assumes there is no negative ordinal; will have to be updated if we
// add non-stateless strategies (for which we've reserved negative ordinals; see
// Strategy.ordinal()).
strategyOrdinal = din.readByte();
numHashFunctions = UnsignedBytes.toInt(din.readByte());
dataLength = din.readInt();
Strategy strategy = BloomFilterStrategies.values()[strategyOrdinal];
long[] data = new long[dataLength];
for (int i = 0; i < data.length; i++) {
data[i] = din.readLong();
}
return new BloomFilter<T>(new BitArray(data), numHashFunctions, funnel, strategy);
} catch (RuntimeException e) {
String message =
"Unable to deserialize BloomFilter from InputStream."
+ " strategyOrdinal: "
+ strategyOrdinal
+ " numHashFunctions: "
+ numHashFunctions
+ " dataLength: "
+ dataLength;
throw new IOException(message, e);
}
}
示例7: readFrom
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Reads a byte stream, which was written by {@linkplain #writeTo(OutputStream)}, into a
* {@code BloomFilter<T>}.
*
* The {@code Funnel} to be used is not encoded in the stream, so it must be provided here.
* <b>Warning:</b> the funnel provided <b>must</b> behave identically to the one used to populate
* the original Bloom filter!
*
* @throws IOException if the InputStream throws an {@code IOException}, or if its data does not
* appear to be a BloomFilter serialized using the {@linkplain #writeTo(OutputStream)} method.
*/
public static <T> BloomFilter<T> readFrom(InputStream in, Funnel<T> funnel) throws IOException {
checkNotNull(in, "InputStream");
checkNotNull(funnel, "Funnel");
int strategyOrdinal = -1;
int numHashFunctions = -1;
int dataLength = -1;
try {
DataInputStream din = new DataInputStream(in);
// currently this assumes there is no negative ordinal; will have to be updated if we
// add non-stateless strategies (for which we've reserved negative ordinals; see
// Strategy.ordinal()).
strategyOrdinal = din.readByte();
numHashFunctions = UnsignedBytes.toInt(din.readByte());
dataLength = din.readInt();
Strategy strategy = BloomFilterStrategies.values()[strategyOrdinal];
long[] data = new long[dataLength];
for (int i = 0; i < data.length; i++) {
data[i] = din.readLong();
}
return new BloomFilter<T>(new BitArray(data), numHashFunctions, funnel, strategy);
} catch (RuntimeException e) {
String message =
"Unable to deserialize BloomFilter from InputStream."
+ " strategyOrdinal: "
+ strategyOrdinal
+ " numHashFunctions: "
+ numHashFunctions
+ " dataLength: "
+ dataLength;
throw new IOException(message, e);
}
}
示例8: BloomFilter
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Creates a BloomFilter.
*/
private BloomFilter(BitArray bits, int numHashFunctions, Funnel<? super T> funnel, Strategy strategy) {
checkArgument(numHashFunctions > 0, "numHashFunctions (%s) must be > 0", numHashFunctions);
checkArgument(numHashFunctions <= 255, "numHashFunctions (%s) must be <= 255", numHashFunctions);
this.bits = checkNotNull(bits);
this.numHashFunctions = numHashFunctions;
this.funnel = checkNotNull(funnel);
this.strategy = checkNotNull(strategy);
}
示例9: readFrom
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Reads a byte stream, which was written by {@linkplain #writeTo(OutputStream)}, into a
* {@code BloomFilter<T>}.
*
* The {@code Funnel} to be used is not encoded in the stream, so it must be provided here.
* <b>Warning:</b> the funnel provided <b>must</b> behave identically to the one used to populate
* the original Bloom filter!
*
* @throws IOException if the InputStream throws an {@code IOException}, or if its data does not
* appear to be a BloomFilter serialized using the {@linkplain #writeTo(OutputStream)} method.
*/
public static <T> BloomFilter<T> readFrom(InputStream in, Funnel<T> funnel)
throws IOException {
checkNotNull(in, "InputStream");
checkNotNull(funnel, "Funnel");
int strategyOrdinal = -1;
int numHashFunctions = -1;
int dataLength = -1;
try {
DataInputStream din = new DataInputStream(in);
// currently this assumes there is no negative ordinal; will have to be updated if we
// add non-stateless strategies (for which we've reserved negative ordinals; see
// Strategy.ordinal()).
strategyOrdinal = din.readByte();
numHashFunctions = UnsignedBytes.toInt(din.readByte());
dataLength = din.readInt();
Strategy strategy = BloomFilterStrategies.values() [strategyOrdinal];
long[] data = new long[dataLength];
for (int i = 0; i < data.length; i++) {
data[i] = din.readLong();
}
return new BloomFilter<T>(new BitArray(data), numHashFunctions, funnel, strategy);
} catch (RuntimeException e) {
IOException ioException = new IOException("Unable to deserialize BloomFilter from InputStream." + " strategyOrdinal: "
+ strategyOrdinal
+ " numHashFunctions: "
+ numHashFunctions + " dataLength: " + dataLength);
ioException.initCause(e);
throw ioException;
}
}
示例10: readFrom
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Reads a byte stream, which was written by {@linkplain #writeTo(OutputStream)}, into a
* {@code BloomFilter<T>}.
*
* The {@code Funnel} to be used is not encoded in the stream, so it must be provided here.
* <b>Warning:</b> the funnel provided <b>must</b> behave identically to the one used to populate
* the original Bloom filter!
*
* @throws IOException if the InputStream throws an {@code IOException}, or if its data does not
* appear to be a BloomFilter serialized using the {@linkplain #writeTo(OutputStream)} method.
*/
public static <T> BloomFilter<T> readFrom(InputStream in, Funnel<T> funnel)
throws IOException {
checkNotNull(in, "InputStream");
checkNotNull(funnel, "Funnel");
int strategyOrdinal = -1;
int numHashFunctions = -1;
int dataLength = -1;
try {
DataInputStream din = new DataInputStream(in);
// currently this assumes there is no negative ordinal; will have to be updated if we
// add non-stateless strategies (for which we've reserved negative ordinals; see
// Strategy.ordinal()).
strategyOrdinal = din.readByte();
numHashFunctions = UnsignedBytes.toInt(din.readByte());
dataLength = din.readInt();
Strategy strategy = BloomFilterStrategies.values() [strategyOrdinal];
long[] data = new long[dataLength];
for (int i = 0; i < data.length; i++) {
data[i] = din.readLong();
}
return new BloomFilter<T>(new BitArray(data), numHashFunctions, funnel, strategy);
} catch (RuntimeException e) {
IOException ioException = new IOException("Unable to deserialize BloomFilter from InputStream." + " strategyOrdinal: "
+ strategyOrdinal
+ " numHashFunctions: "
+ numHashFunctions + " dataLength: " + dataLength);
ioException.initCause(e);
throw ioException;
}
}
示例11: readFrom
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Reads a byte stream, which was written by {@linkplain #writeTo(OutputStream)}, into a
* {@code BloomFilter<T>}.
*
* The {@code Funnel} to be used is not encoded in the stream, so it must be provided here.
* <b>Warning:</b> the funnel provided <b>must</b> behave identically to the one used to populate
* the original Bloom filter!
*
* @throws IOException if the InputStream throws an {@code IOException}, or if its data does not
* appear to be a BloomFilter serialized using the {@linkplain #writeTo(OutputStream)} method.
*/
public static <T> BloomFilter<T> readFrom(InputStream in, Funnel<T> funnel) throws IOException {
checkNotNull(in, "InputStream");
checkNotNull(funnel, "Funnel");
int strategyOrdinal = -1;
int numHashFunctions = -1;
int dataLength = -1;
try {
DataInputStream din = new DataInputStream(in);
// currently this assumes there is no negative ordinal; will have to be updated if we
// add non-stateless strategies (for which we've reserved negative ordinals; see
// Strategy.ordinal()).
strategyOrdinal = din.readByte();
numHashFunctions = UnsignedBytes.toInt(din.readByte());
dataLength = din.readInt();
Strategy strategy = BloomFilterStrategies.values()[strategyOrdinal];
long[] data = new long[dataLength];
for (int i = 0; i < data.length; i++) {
data[i] = din.readLong();
}
return new BloomFilter<T>(new BitArray(data), numHashFunctions, funnel, strategy);
} catch (RuntimeException e) {
IOException ioException =
new IOException(
"Unable to deserialize BloomFilter from InputStream."
+ " strategyOrdinal: "
+ strategyOrdinal
+ " numHashFunctions: "
+ numHashFunctions
+ " dataLength: "
+ dataLength);
ioException.initCause(e);
throw ioException;
}
}
示例12: BloomFilter
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Creates a BloomFilter.
*/
private BloomFilter(BitArray bits, int numHashFunctions, Funnel<T> funnel,
Strategy strategy) {
checkArgument(numHashFunctions > 0,
"numHashFunctions (%s) must be > 0", numHashFunctions);
checkArgument(numHashFunctions <= 255,
"numHashFunctions (%s) must be <= 255", numHashFunctions);
this.bits = checkNotNull(bits);
this.numHashFunctions = numHashFunctions;
this.funnel = checkNotNull(funnel);
this.strategy = checkNotNull(strategy);
}
示例13: BloomFilter
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Creates a BloomFilter.
*/
private BloomFilter(BitArray bits, int numHashFunctions, Funnel<? super T> funnel,
Strategy strategy) {
checkArgument(numHashFunctions > 0,
"numHashFunctions (%s) must be > 0", numHashFunctions);
checkArgument(numHashFunctions <= 255,
"numHashFunctions (%s) must be <= 255", numHashFunctions);
this.bits = checkNotNull(bits);
this.numHashFunctions = numHashFunctions;
this.funnel = checkNotNull(funnel);
this.strategy = checkNotNull(strategy);
}
示例14: create
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
@VisibleForTesting
static <T> BloomFilter<T> create(
Funnel<? super T> funnel, int expectedInsertions /* n */, double fpp, Strategy strategy) {
checkNotNull(funnel);
checkArgument(expectedInsertions >= 0, "Expected insertions (%s) must be >= 0",
expectedInsertions);
checkArgument(fpp > 0.0, "False positive probability (%s) must be > 0.0", fpp);
checkArgument(fpp < 1.0, "False positive probability (%s) must be < 1.0", fpp);
checkNotNull(strategy);
if (expectedInsertions == 0) {
expectedInsertions = 1;
}
/*
* TODO(user): Put a warning in the javadoc about tiny fpp values,
* since the resulting size is proportional to -log(p), but there is not
* much of a point after all, e.g. optimalM(1000, 0.0000000000000001) = 76680
* which is less than 10kb. Who cares!
*/
long numBits = optimalNumOfBits(expectedInsertions, fpp);
int numHashFunctions = optimalNumOfHashFunctions(expectedInsertions, numBits);
try {
return new BloomFilter<T>(new BitArray(numBits), numHashFunctions, funnel, strategy);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not create BloomFilter of " + numBits + " bits", e);
}
}
示例15: readFrom
import com.google.common.hash.BloomFilterStrategies.BitArray; //导入依赖的package包/类
/**
* Reads a byte stream, which was written by {@linkplain #writeTo(OutputStream)}, into
* a {@code BloomFilter<T>}.
*
* The {@code Funnel} to be used is not encoded in the stream, so it must be provided here.
* <b>Warning:</b> the funnel provided <b>must</b> behave identically to the one used to
* populate the original Bloom filter!
*
* @throws IOException if the InputStream throws an {@code IOException}, or if its data does
* not appear to be a BloomFilter serialized using the
* {@linkplain #writeTo(OutputStream)} method.
*/
public static <T> BloomFilter<T> readFrom(InputStream in, Funnel<T> funnel) throws IOException {
checkNotNull(in, "InputStream");
checkNotNull(funnel, "Funnel");
int strategyOrdinal = -1;
int numHashFunctions = -1;
int dataLength = -1;
try {
DataInputStream din = new DataInputStream(in);
// currently this assumes there is no negative ordinal; will have to be updated if we
// add non-stateless strategies (for which we've reserved negative ordinals; see
// Strategy.ordinal()).
strategyOrdinal = din.readByte();
numHashFunctions = UnsignedBytes.toInt(din.readByte());
dataLength = din.readInt();
Strategy strategy = BloomFilterStrategies.values()[strategyOrdinal];
long[] data = new long[dataLength];
for (int i = 0; i < data.length; i++) {
data[i] = din.readLong();
}
return new BloomFilter<T>(new BitArray(data), numHashFunctions, funnel, strategy);
} catch (RuntimeException e) {
IOException ioException = new IOException(
"Unable to deserialize BloomFilter from InputStream."
+ " strategyOrdinal: " + strategyOrdinal
+ " numHashFunctions: " + numHashFunctions
+ " dataLength: " + dataLength);
ioException.initCause(e);
throw ioException;
}
}