-
好书分享帖
2016-10-31 12:36《生活在别处》。很喜欢其中的一段“遇见是两个人的事,离开却是一个人的决定,遇见是一个开始,离开却是为了遇见下一个离开。这是一个流行离开的世界,但是我们都不擅长告别。”
-
Java 排序遍历求助
2016-08-27 23:26package com.cyb.algorithm; import java.util.BitSet; public class BloomFilter { //分配bitSet空间 private static final int DEFAULT_SIZE = 1<<28; private BitSet bitSet = new BitSet(DEFAULT_SIZE); //哈希函数的种子(采用质数) private static final int[] seeds = new int []{5,7,11,13,31,37,61}; //哈希函数 private HashFunction[] func = new HashFunction[seeds.length]; public BloomFilter() { for(int i=0;i<seeds.length;i++){ func[i] = new HashFunction(DEFAULT_SIZE,seeds[i]); } } //添加字符串 public void add(String value){ for(HashFunction f : func){ bitSet.set(f.hash(value),true); } } //判断是否被标记过 public boolean contains(String value){ if (value == null) { return false; } boolean result = true; for(HashFunction f : func){ result = result && bitSet.get(f.hash(value)); } return result; } } public class HashFunction { private int capacity; private int seed; public HashFunction(){ } public HashFunction(int capacity, int seed) { this.capacity = capacity; this.seed = seed; } public int hash(String value) { int result = 0; int len = value.length(); for(int i=0;i<len;i++){ result = seed * result + value.charAt(i); } return (capacity-1) & result; } }
文章出自 http://www.cnblogs.com/heaad/archive/2011/01/02/1924195.html