本文整理汇总了Java中com.google.common.hash.BloomFilter.put方法的典型用法代码示例。如果您正苦于以下问题:Java BloomFilter.put方法的具体用法?Java BloomFilter.put怎么用?Java BloomFilter.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.hash.BloomFilter
的用法示例。
在下文中一共展示了BloomFilter.put方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import com.google.common.hash.BloomFilter; //导入方法依赖的package包/类
/**
* add
*
* @param element
* @return
*/
public boolean add(CharSequence element) {
if (element == null) {
return false;
}
initCharset();
BloomFilter<CharSequence> bf = this.bloomfilters.get(0);
if (getBloomfilterBucketLength() > 1) {
byte[] datas = element.toString().getBytes(this.charset);
int bfIndex = Math.abs(Hashing.murmur3_128().hashBytes(datas).asInt()) % getBloomfilterBucketLength();
bf = this.bloomfilters.get(bfIndex);
}
synchronized (bf) {
bf.put(element);
numberOfAddedElements++;
return true;
}
}
示例2: main
import com.google.common.hash.BloomFilter; //导入方法依赖的package包/类
public static void main(String[] args) {
BloomFilter<String> strsBloom = BloomFilter.create(stringFunnel, Integer.MAX_VALUE, 0.5);
int cnt=0;
for(long i=0;i<4000001;i++){
cnt=cnt+1;
strsBloom.put(Long.toString(i));
}
System.out.println(cnt);
System.out.println(strsBloom.mightContain("5000000"));
}
示例3: put
import com.google.common.hash.BloomFilter; //导入方法依赖的package包/类
void put(K key, ValueHolder<V> holder) {
if (holder.clean) {
return;
}
BloomFilter<K> b = bloomFilter;
if (b != null) {
b.put(key);
bloomFilter = b;
}
SqlHandle c = null;
try {
c = acquire();
if (c.put == null) {
c.put =
c.conn.prepareStatement("MERGE INTO data (k, v, created, accessed) VALUES(?,?,?,?)");
}
try {
keyType.set(c.put, 1, key);
c.put.setObject(2, holder.value, Types.JAVA_OBJECT);
c.put.setTimestamp(3, new Timestamp(holder.created));
c.put.setTimestamp(4, TimeUtil.nowTs());
c.put.executeUpdate();
holder.clean = true;
} finally {
c.put.clearParameters();
}
} catch (SQLException e) {
log.warn("Cannot put into cache " + url, e);
c = close(c);
} finally {
release(c);
}
}
示例4: process
import com.google.common.hash.BloomFilter; //导入方法依赖的package包/类
@Override
protected void process(MapTuple t, OutputCollector c) throws OperationException, InterruptedException {
BloomFilter<MapTuple> filter = getFilter(c.getCurrentBatch());
if (filter.mightContain(t)) {
// Do nothing...
} else {
filter.put(t);
c.emit(t);
}
}
示例5: load
import com.google.common.hash.BloomFilter; //导入方法依赖的package包/类
private void load(
Collection col,
Receiver<TypeValue> receiver,
BloomFilter<CharSequence> filter) {
if (col != null && receiver != null)
for (ASObject obj : col.items())
if (obj.id() != null && (filter == null || filter.put(obj.id()))) {
try {
receiver.receive(obj);
} catch (Throwable t) {}
}
}
示例6: putValues
import com.google.common.hash.BloomFilter; //导入方法依赖的package包/类
private static long putValues(BloomFilter<Long> bloomFilter2) {
long start = System.currentTimeMillis();
for (int i = 0; i < NUM_OF_VALUES; i++) {
if (i % 3 == 0) {
bloomFilter2.put((long) i);
}
}
return System.currentTimeMillis() - start;
}
示例7: put
import com.google.common.hash.BloomFilter; //导入方法依赖的package包/类
/**
* 将元素加入BloomFilter
* @return true:可能是第一次put, false:一定是第一次put
*/
public boolean put(T t) {
final BloomFilter<T> temp = filter;
boolean result = temp.put(t);
filter = temp;
return result;
}
示例8: inheritBloomFilterAndAddSelf
import com.google.common.hash.BloomFilter; //导入方法依赖的package包/类
private boolean inheritBloomFilterAndAddSelf(final int treeID, final BloomFilter<NodeAddress> toBeInherited) {
final boolean res = !toBeInherited.mightContain(network.getAddress());
toBeInherited.put(network.getAddress());
bloomFilter.put(treeID, toBeInherited);
return res;
}
示例9: main
import com.google.common.hash.BloomFilter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
TestFileHelper.createTestDirectory();
KeyValueGenerator keyValueGenerator = new KeyValueGenerator();
Value value = new Value(keyValueGenerator.testValue(100));
System.out.println("Writing bloom filter");
Paths paths = ConfigGenerator.testPaths();
TableBloomFilterWriter filterWriter = TableBloomFilterWriter.open(1, paths, RECORD_COUNT);
BloomFilter<Key> guavaFilter = BloomFilter.create(new Funnel<Key>() {
@Override
public void funnel(Key key, PrimitiveSink primitiveSink) {
primitiveSink.putBytes(key.data().array());
}
}, RECORD_COUNT, 0.01);
for (int i = 0; i < RECORD_COUNT; i++) {
value.data().rewind();
filterWriter.write(new Key(ByteBuffers.fromString(i + ""), i));
guavaFilter.put(new Key(ByteBuffers.fromString(i + ""), i));
}
filterWriter.finish();
System.out.println("Reading bloom filter");
TableBloomFilter tableBloomFilter = TableBloomFilter.read(1, paths);
double hits = 0;
double misses = 0;
double ghits = 0;
double gmisses = 0;
for (int i = RECORD_COUNT * 2; i > RECORD_COUNT; i--) {
if (tableBloomFilter.mightContain(new Key(ByteBuffers.fromString(i + ""), i))) {
hits++;
} else {
misses++;
}
if (guavaFilter.mightContain(new Key(ByteBuffers.fromString(i + ""), i))) {
ghits++;
} else {
gmisses++;
}
}
System.out.println("False positive rate: " + hits / (hits + misses));
System.out.println("Guava positive rate: " + ghits / (ghits + gmisses));
TestFileHelper.cleanUpTestFiles();
}