forked from qijinhaocode/large-file-processing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.java
More file actions
112 lines (98 loc) · 2.41 KB
/
Utils.java
File metadata and controls
112 lines (98 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package xin.twodog.PingCAP;
import java.io.File;
public class Utils {
/**
* 随机生成单词
*
* @param min 最小长度
* @param max 最大长度
* @return
*/
public static String creatWord(int min, int max) {
int count = (int) (Math.random() * (max - min + 1)) + min;
String str = "";
for (int i = 0; i < count; i++) {
str += (char) ((int) (Math.random() * 26) + 'a');
}
return str;
}
/**
* 返回文件内存大小
*
* @param filePath
* @return
* @throws Exception
*/
public static Long getFileMem(String filePath) {
File localFile = new File(filePath);
return localFile.length();
}
/**
* 删除文件
*
* @param filePath
*/
public static void delFile(String filePath) {
File localFile = new File(filePath);
localFile.delete();
}
/**
* DEKHash算法
*
* @param str
* @return
*/
public static int DEKHash(String str) {
int hash = str.length();
for (int i = 0; i < str.length(); i++) {
hash = ((hash << 5) ^ (hash >> 27)) ^ str.charAt(i);
}
return (hash & 0x7FFFFFFF);
}
/**
* APHash算法
*
* @param str
* @return
*/
public static int APHash(String str) {
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str.charAt(i) ^ (hash >> 3)) :
(~((hash << 11) ^ str.charAt(i) ^ (hash >> 5)));
}
return hash;
}
/**
* 改进的32位FNV算法1
*
* @param data 字符串
* @param data
* @return int值
*/
public static int FNVHash1(String data) {
final int p = 16777619;
int hash = (int) 2166136261L;
for (int i = 0; i < data.length(); i++)
hash = (hash ^ data.charAt(i)) * p;
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
}
/**
* JS hash 算法
*
* @param str
* @return
*/
public static int JSHash(String str) {
int hash = 1315423911;
for (int i = 0; i < str.length(); i++) {
hash ^= ((hash << 5) + str.charAt(i) + (hash >> 2));
}
return (hash & 0x7FFFFFFF);
}
}