當前位置: 首頁>>代碼示例>>Java>>正文


Java Funnel類代碼示例

本文整理匯總了Java中com.google.common.hash.Funnel的典型用法代碼示例。如果您正苦於以下問題:Java Funnel類的具體用法?Java Funnel怎麽用?Java Funnel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Funnel類屬於com.google.common.hash包,在下文中一共展示了Funnel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的com.google.common.hash.Funnel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。