当前位置: 首页>>代码示例>>Java>>正文


Java BloomFilter.put方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:ruanyi,项目名称:bloomfilter-center,代码行数:24,代码来源:BloomFilterWrapper.java

示例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"));

}
 
开发者ID:sameeraxiomine,项目名称:largelda,代码行数:13,代码来源:BloomFilterTest.java

示例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);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:36,代码来源:H2CacheImpl.java

示例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);
  }
}
 
开发者ID:zillabyte,项目名称:motherbrain,代码行数:11,代码来源:Unique.java

示例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) {}
      }
}
 
开发者ID:OpenSocial,项目名称:activitystreams,代码行数:13,代码来源:ClasspathPreloader.java

示例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;
}
 
开发者ID:koendeschacht,项目名称:count-db,代码行数:10,代码来源:TestBloomFiltersSpeed.java

示例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;
}
 
开发者ID:haogrgr,项目名称:haogrgr-test,代码行数:11,代码来源:HBBloomFilter.java

示例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;
}
 
开发者ID:alibov,项目名称:StreamAid,代码行数:7,代码来源:ChunkySpread.java

示例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();
}
 
开发者ID:jordw,项目名称:heftydb,代码行数:54,代码来源:TableBloomFilterPerformance.java


注:本文中的com.google.common.hash.BloomFilter.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。