mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-22 20:54:26 +08:00
chore: 文件路径调整
This commit is contained in:
parent
7691dec175
commit
bbaccac646
@ -1,69 +0,0 @@
|
|||||||
package com.youlai.mall.pms.common.util;
|
|
||||||
|
|
||||||
import com.google.common.hash.Funnel;
|
|
||||||
import com.google.common.hash.Hashing;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 布隆过滤器,摘录自Google-guava包
|
|
||||||
*
|
|
||||||
* @author DaniR
|
|
||||||
* @date 2021/6/23 20:30
|
|
||||||
*/
|
|
||||||
public class BloomFilterUtils<T> {
|
|
||||||
private final int numHashFunctions;
|
|
||||||
|
|
||||||
private final int bitSize;
|
|
||||||
|
|
||||||
private final Funnel<T> funnel;
|
|
||||||
|
|
||||||
|
|
||||||
public BloomFilterUtils(Funnel<T> funnel, int expectedInsertions, double fpp) {
|
|
||||||
checkArgument(funnel != null, "funnel不能为空");
|
|
||||||
checkArgument(
|
|
||||||
expectedInsertions >= 0, "Expected insertions (%s) must be >= 0", expectedInsertions);
|
|
||||||
checkArgument(fpp > 0.0, "False positive probability (%s) must be > 0.0", fpp);
|
|
||||||
checkArgument(fpp < 1.0, "False positive probability (%s) must be < 1.0", fpp);
|
|
||||||
this.funnel = funnel;
|
|
||||||
// 计算bit数组长度
|
|
||||||
bitSize = optimalNumOfBits(expectedInsertions, fpp);
|
|
||||||
// 计算hash方法执行次数
|
|
||||||
numHashFunctions = optimalNumOfHashFunctions(expectedInsertions, bitSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] murmurHash(T value) {
|
|
||||||
int[] offset = new int[numHashFunctions];
|
|
||||||
|
|
||||||
long hash64 = Hashing.murmur3_128().hashObject(value, funnel).asLong();
|
|
||||||
int hash1 = (int) hash64;
|
|
||||||
int hash2 = (int) (hash64 >>> 32);
|
|
||||||
for (int i = 1; i <= numHashFunctions; i++) {
|
|
||||||
int combinedHash = hash1 + i * hash2;
|
|
||||||
if (combinedHash < 0) {
|
|
||||||
combinedHash = ~combinedHash;
|
|
||||||
}
|
|
||||||
offset[i - 1] = combinedHash % bitSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算bit数组长度
|
|
||||||
*/
|
|
||||||
private int optimalNumOfBits(long n, double p) {
|
|
||||||
if (p == 0) {
|
|
||||||
// 设定最小期望长度
|
|
||||||
p = Double.MIN_VALUE;
|
|
||||||
}
|
|
||||||
return (int) (-n * Math.log(p) / (Math.log(2) * Math.log(2)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算hash方法执行次数
|
|
||||||
*/
|
|
||||||
private int optimalNumOfHashFunctions(long n, long m) {
|
|
||||||
return Math.max(1, (int) Math.round((double) m / n * Math.log(2)));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package com.youlai.mall.ums.config;
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
|
||||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class RestTemplateConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RestTemplate restTemplate(ClientHttpRequestFactory simpleClientHttpRequestFactory) {
|
|
||||||
return new RestTemplate(simpleClientHttpRequestFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
|
|
||||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
|
||||||
factory.setReadTimeout(5000);//单位为ms
|
|
||||||
factory.setConnectTimeout(5000);//单位为ms
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user