本文整理汇总了Java中com.google.common.hash.Funnel类的典型用法代码示例。如果您正苦于以下问题:Java Funnel类的具体用法?Java Funnel怎么用?Java Funnel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Funnel类属于com.google.common.hash包,在下文中一共展示了Funnel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: readBloomFilterFromfile
import com.google.common.hash.Funnel; //导入依赖的package包/类
static BloomFilter<String> readBloomFilterFromfile(String bloomFilterFilePath) throws IOException {
Funnel<String> memberFunnel = new Funnel<String>() {
public void funnel(String memberId, PrimitiveSink sink) {
sink.putString(memberId, Charsets.UTF_8);
}
};
try
{
FileInputStream fis = new FileInputStream(new File(bloomFilterFilePath));
return BloomFilter.readFrom(fis, memberFunnel);
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
开发者ID:dream-lab,项目名称:echo,代码行数:18,代码来源:EdgentFilter_RBI.java
示例2: create
import com.google.common.hash.Funnel; //导入依赖的package包/类
@VisibleForTesting
static <T> CuckooFilter<T> create(Funnel<? super T> funnel, long capacity, double fpp,
CuckooStrategy cuckooStrategy) {
checkNotNull(funnel);
checkArgument(capacity > 0, "Expected insertions (%s) must be > 0", capacity);
checkArgument(fpp > 0.0D, "False positive probability (%s) must be > 0.0", fpp);
checkArgument(fpp < 1.0D, "False positive probability (%s) must be < 1.0", fpp);
checkNotNull(cuckooStrategy);
int numEntriesPerBucket = optimalEntriesPerBucket(fpp);
long numBuckets = optimalNumberOfBuckets(capacity, numEntriesPerBucket);
int numBitsPerEntry = optimalBitsPerEntry(fpp, numEntriesPerBucket);
try {
return new CuckooFilter<T>(new CuckooTable(numBuckets,
numEntriesPerBucket, numBitsPerEntry), funnel, cuckooStrategy, fpp);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not create CuckooFilter of " + numBuckets +
" buckets, " + numEntriesPerBucket + " entries per bucket, " + numBitsPerEntry +
" bits per entry", e);
}
}
开发者ID:bdupras,项目名称:guava-probably,代码行数:23,代码来源:CuckooFilter.java
示例3: ensureGeneric
import com.google.common.hash.Funnel; //导入依赖的package包/类
@Test
public void ensureGeneric() {
class SuperClass {
}
class SubClass extends SuperClass {
}
CuckooFilter<SuperClass> filter = CuckooFilter.create(
new Funnel<SuperClass>() {
public void funnel(SuperClass from, PrimitiveSink into) {
into.putInt(from.hashCode());
}
}, 1000, 0.03D);
assertTrue(filter.add(new SuperClass()));
assertTrue(filter.add(new SubClass()));
}
开发者ID:bdupras,项目名称:guava-probably,代码行数:18,代码来源:CuckooFilterTest.java
示例4: GrowthTracker
import com.google.common.hash.Funnel; //导入依赖的package包/类
GrowthTracker(
final SerializableFunction<OutputT, KeyT> keyFn,
final Coder<KeyT> outputKeyCoder,
GrowthState<OutputT, KeyT, TerminationStateT> state,
Growth.TerminationCondition<?, TerminationStateT> terminationCondition) {
this.coderFunnel =
new Funnel<OutputT>() {
@Override
public void funnel(OutputT from, PrimitiveSink into) {
try {
// Rather than hashing the output itself, hash the output key.
KeyT outputKey = keyFn.apply(from);
outputKeyCoder.encode(outputKey, Funnels.asOutputStream(into));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
this.terminationCondition = terminationCondition;
this.state = state;
this.isOutputComplete = state.isOutputComplete;
this.pollWatermark = state.pollWatermark;
this.terminationState = state.terminationState;
this.pending = Lists.newLinkedList(state.pending);
}
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:Watch.java
示例5: CaptchaService
import com.google.common.hash.Funnel; //导入依赖的package包/类
@Autowired
public CaptchaService(UserInfoValidator userInfoValidator, LsPushProperties lsPushProperties,
JavaMailSender mailSender, TemplateEngine templateEngine, ObjectMapper objectMapper,
UserRepository userRepo) {
mUserInfoValidator = userInfoValidator;
serverName = lsPushProperties.getServerName();
serverUrl = lsPushProperties.getServerUrl();
serverEmail = lsPushProperties.getServerEmail();
mMailSender = mailSender;
mTemplateEngine = templateEngine;
mObjectMapper = objectMapper;
mUserRepo = userRepo;
mAuthCodeMap = CacheBuilder.newBuilder()
.initialCapacity(100)
.maximumSize(500)
.expireAfterWrite(30, TimeUnit.MINUTES)
.build();
mStringFunnel = (Funnel<String>) (from, into) -> into.putString(from, StandardCharsets.UTF_8);
resetBloomFilter();
}
开发者ID:TomeOkin,项目名称:LsPush-Server,代码行数:22,代码来源:CaptchaService.java
示例6: getSessionWithCheck
import com.google.common.hash.Funnel; //导入依赖的package包/类
protected AccountSession getSessionWithCheck(CryptoToken cryptoToken, boolean isExpire) {
Funnel<AccountSession> sessionFunnel = isExpire ? mExpireSessionFunnel : mRefreshSessionFunnel;
AccountSession session;
try {
byte[] json = Crypto.decrypt(cryptoToken);
session = mObjectMapper.readValue(json, AccountSession.class);
} catch (Exception e) {
logger.warn("decrypt token failure", e);
return null;
}
byte[] sessionData = Hashing.sipHash24().hashObject(session, sessionFunnel).asBytes();
String sessionString = new String(sessionData, StandardCharsets.UTF_8);
if (!sessionString.equals(session.getSession())) {
logger.warn("session not equal");
return null;
}
return session;
}
开发者ID:TomeOkin,项目名称:LsPush-Server,代码行数:21,代码来源:AuthService.java
示例7: CollisionHandler
import com.google.common.hash.Funnel; //导入依赖的package包/类
public CollisionHandler(int numFilters, int size) {
filters = new ArrayList<>();
for(int i = 0;i < numFilters;++i) {
BloomFilter<Long> collisionFilter = BloomFilter.create(new Funnel<Long>() {
/**
* Sends a stream of data from the {@code from} object into the sink {@code into}. There
* is no requirement that this data be complete enough to fully reconstitute the object
* later.
*
* @param from
* @param into
*/
@Override
public void funnel(Long from, Sink into) {
into.putLong(from);
}
}, size);
filters.add(collisionFilter);
}
}
开发者ID:cestella,项目名称:streaming_outliers,代码行数:22,代码来源:CSVProjector.java
示例8: getInternalTransactionHash
import com.google.common.hash.Funnel; //导入依赖的package包/类
private String getInternalTransactionHash(final Transaction transaction) {
return Hashing.sha1().hashObject(transaction, new Funnel<Transaction>() {
private static final long serialVersionUID = 9193015056720554840L;
@Override
public void funnel(final Transaction from, final PrimitiveSink into) {
into.putUnencodedChars(from.getReference())
.putUnencodedChars(from.getSource().getName())
.putUnencodedChars(from.getDestination().getName())
.putFloat(from.getAmount().floatValue())
.putLong(from.getCreationDate());
}
}).toString();
}
开发者ID:yopeio,项目名称:payment-api,代码行数:17,代码来源:TransactionService.java
示例9: getFilter
import com.google.common.hash.Funnel; //导入依赖的package包/类
private BloomFilter<MapTuple> getFilter(Object batch) {
if (_filters.containsKey(batch) == false) {
Funnel<MapTuple> funnel = new Funnel<MapTuple>() {
private static final long serialVersionUID = 3504134639163725164L;
@Override
public void funnel(MapTuple from, PrimitiveSink into) {
if (_uniqueFields == null) {
into.putString(from.values().toString(), Charset.defaultCharset());
} else {
for(String f : _uniqueFields) {
into.putString(from.get(f).toString(), Charset.defaultCharset());
}
}
}
};
logger().info("Creating unique filter with max expected capacity of: " + _expectedSize);
_filters.put(batch, BloomFilter.create(funnel, _expectedSize));
}
return _filters.get(batch);
}
开发者ID:zillabyte,项目名称:motherbrain,代码行数:22,代码来源:Unique.java
示例10: put
import com.google.common.hash.Funnel; //导入依赖的package包/类
public <T> boolean put(T object, Funnel<? super T> funnel, int numHashFunctions, int[] cells) {
// TODO(user): when the murmur's shortcuts are implemented, update this code
long hash64 = Hashing.murmur3_128().newHasher().putObject(object, funnel).hash().asLong();
int hash1 = (int) hash64;
int hash2 = (int) (hash64 >>> 32);
boolean bitsChanged = false;
for (int i = 1; i <= numHashFunctions; i++) {
int nextHash = hash1 + i * hash2;
if (nextHash < 0) {
nextHash = ~nextHash;
}
int pos = nextHash % cells.length;
bitsChanged |= (cells[pos] != MAX_VAL);
cells[pos] = MAX_VAL;
}
return bitsChanged;
}
开发者ID:mayconbordin,项目名称:streaminer,代码行数:18,代码来源:StableBloomFilter.java
示例11: mightContain
import com.google.common.hash.Funnel; //导入依赖的package包/类
public <T> boolean mightContain(T object, Funnel<? super T> funnel, int numHashFunctions, int[] cells) {
long hash64 = Hashing.murmur3_128().newHasher().putObject(object, funnel).hash().asLong();
int hash1 = (int) hash64;
int hash2 = (int) (hash64 >>> 32);
for (int i = 1; i <= numHashFunctions; i++) {
int nextHash = hash1 + i * hash2;
if (nextHash < 0) {
nextHash = ~nextHash;
}
int pos = nextHash % cells.length;
if (cells[pos] == 0) {
return false;
}
}
return true;
}
开发者ID:mayconbordin,项目名称:streaminer,代码行数:17,代码来源:StableBloomFilter.java
示例12: hash
import com.google.common.hash.Funnel; //导入依赖的package包/类
private int hash() {
// Guava documentation recommends using putUnencodedChars to hash raw character bytes within any encoding
// unless cross-language compatibility is needed. See the Hasher.putString documentation for more info.
Funnel<TrafficSelector> selectorFunnel = (from, into) -> from.criteria()
.forEach(c -> into.putUnencodedChars(c.toString()));
HashFunction hashFunction = Hashing.murmur3_32();
HashCode hashCode = hashFunction.newHasher()
.putUnencodedChars(deviceId.toString())
.putObject(selector, selectorFunnel)
.putInt(priority)
.putUnencodedChars(tableId.toString())
.hash();
return hashCode.asInt();
}
开发者ID:opennetworkinglab,项目名称:onos,代码行数:17,代码来源:DefaultFlowRule.java
示例13: getCredentials
import com.google.common.hash.Funnel; //导入依赖的package包/类
@Override
public Object getCredentials()
{
AllowAllUser user = (AllowAllUser) getPrincipal();
if (user != null) {
return Hashing.sha256().hashObject(user, new Funnel<AllowAllUser>()
{
@Override
public void funnel(AllowAllUser from, PrimitiveSink into)
{
Set<String> fromGroups = from.getGroups();
String fromName = from.getUserName();
into.putString(fromName, Charsets.UTF_8);
for (String fromGroup : fromGroups) {
into.putString(fromGroup, Charsets.UTF_8);
}
}
});
}
return null;
}
开发者ID:airbnb,项目名称:airpal,代码行数:26,代码来源:AllowAllToken.java
示例14: hashCode
import com.google.common.hash.Funnel; //导入依赖的package包/类
@Override
public int hashCode() {
final HashFunction hf = Hashing.md5();
return hf.newHasher()
.putString(extractedPath)
.putObject(archive, new Funnel<JarFile>() {
@Override
public void funnel(JarFile from, PrimitiveSink into) {
into
.putString(from.getName())
.putString(Optional.fromNullable(from.getComment()).or(""));
}
private static final long serialVersionUID = 3109141395123855989L;
}).hash().asInt();
}
开发者ID:ayld,项目名称:Facade,代码行数:19,代码来源:ExplodedJar.java
示例15: DirectDiskUrlFilter
import com.google.common.hash.Funnel; //导入依赖的package包/类
/**
* @param filterPath 原Guava序列化存储的文件路径
* @param funnel 原Guava BloomFilter使用的Funnel
* @throws IOException
*/
public DirectDiskUrlFilter(String filterPath, Funnel<CharSequence> funnel) throws IOException {
filterFile = new File(filterPath);
raf = new RandomAccessFile(filterFile, "rw");
/* jump strategyOrdinal value */
raf.readByte();
numHashFunctions = UnsignedBytes.toInt(raf.readByte());
dataLength = raf.readInt();
bitsSize = (long) dataLength * 64L;
bits = new Bits();
this.funnel = funnel;
}
开发者ID:xiongbeer,项目名称:Cobweb,代码行数:17,代码来源:DirectDiskUrlFilter.java
示例16: hash
import com.google.common.hash.Funnel; //导入依赖的package包/类
private int hash() {
Funnel<TrafficSelector> selectorFunnel = (from, into) -> from.criteria()
.stream()
.forEach(c -> into.putString(c.toString(), Charsets.UTF_8));
HashFunction hashFunction = Hashing.murmur3_32();
HashCode hashCode = hashFunction.newHasher()
.putString(deviceId.toString(), Charsets.UTF_8)
.putObject(selector, selectorFunnel)
.putInt(priority)
.putInt(tableId)
.hash();
return hashCode.asInt();
}
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:DefaultFlowRule.java
示例17: getOrCreate
import com.google.common.hash.Funnel; //导入依赖的package包/类
private BloomFilter<Seed> getOrCreate(String segment) {
BloomFilter<Seed> seedBloomFilter = bloomFilters.get(segment);
if (seedBloomFilter != null) {
return seedBloomFilter;
}
synchronized (segment.intern()) {
seedBloomFilter = bloomFilters.get(segment);
if (seedBloomFilter != null) {
return seedBloomFilter;
}
long expectedNumber = NumberUtils.toLong(VSCrawlerContext.vsCrawlerConfigFileWatcher.loadedProperties()
.getProperty(VSCrawlerConstant.VSCRAWLER_SEED_MANAGER_EXPECTED_SEED_NUMBER), 1000000L);
// any way, build a filter instance if not exist
seedBloomFilter = BloomFilter.create(new Funnel<Seed>() {
@Override
public void funnel(Seed from, PrimitiveSink into) {
into.putString(seedKeyResolver.resolveSeedKey(from), Charset.defaultCharset());
}
}, expectedNumber);
bloomFilters.put(segment, seedBloomFilter);
}
return seedBloomFilter;
}
开发者ID:virjar,项目名称:vscrawler,代码行数:27,代码来源:BerkeleyDBSeedManager.java
示例18: SerializableSaltedHasher
import com.google.common.hash.Funnel; //导入依赖的package包/类
SerializableSaltedHasher(long seedNSalt, long addlSipSeed, Funnel<? super T> funnel, Algorithm alg) {
checkNotNull(alg);
checkNotNull(funnel);
this.alg = alg;
this.funnel = funnel;
this.seedNSalt = seedNSalt;
this.addlSipSeed = addlSipSeed;
hasher = configureHash(alg, seedNSalt, addlSipSeed);
}
开发者ID:MGunlogson,项目名称:CuckooFilter4J,代码行数:10,代码来源:SerializableSaltedHasher.java
示例19: create
import com.google.common.hash.Funnel; //导入依赖的package包/类
static <T> SerializableSaltedHasher<T> create(Algorithm alg, Funnel<? super T> funnel) {
checkNotNull(alg);
checkNotNull(funnel);
SecureRandom randomer = new SecureRandom();
long seedNSalt = randomer.nextLong();
long addlSipSeed = randomer.nextLong();
return new SerializableSaltedHasher<>(seedNSalt, addlSipSeed, funnel, alg);
}
开发者ID:MGunlogson,项目名称:CuckooFilter4J,代码行数:9,代码来源:SerializableSaltedHasher.java
示例20: add
import com.google.common.hash.Funnel; //导入依赖的package包/类
public <T> boolean add(T object, Funnel<? super T> funnel, CuckooTable table) {
final long hash64 = hash(object, funnel).asLong();
final int hash1 = hash1(hash64);
final int hash2 = hash2(hash64);
final int fingerprint = fingerprint(hash2, table.numBitsPerEntry);
final long index = index(hash1, table.numBuckets);
return putEntry(fingerprint, table, index) ||
putEntry(fingerprint, table, altIndex(index, fingerprint, table.numBuckets));
}
开发者ID:bdupras,项目名称:guava-probably,代码行数:11,代码来源:CuckooStrategyMurmurBealDupras32.java
注:本文中的com.google.common.hash.Funnel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论