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 | package Torello.JavaDoc.SyntaxHiLite;
import Torello.Java.UnreachableError;
import java.io.File;
public class HLC64 extends AbstractHashCodeHLC<Long>
{
public HLC64(String cacheSaveDirectory)
{ super(cacheSaveDirectory, Long.class); }
public Long computeCacheKey(
final String codeTypeParam,
final boolean includeLineNumbers,
final byte styleNum,
final String sourceCodeAsString
)
{
final long FNV_PRIME = 0x100000001b3L;
long hash = 0xcbf29ce484222325L;
// Mix in codeTypeParam
for (int i = 0; i < codeTypeParam.length(); i++) {
hash ^= codeTypeParam.charAt(i);
hash *= FNV_PRIME;
}
// Mix in includeLineNumbers
hash ^= (includeLineNumbers ? 1 : 0);
hash *= FNV_PRIME;
// Mix in styleNum
hash ^= styleNum;
hash *= FNV_PRIME;
// Mix in sourceCodeAsString
for (int i = 0; i < sourceCodeAsString.length(); i++) {
hash ^= sourceCodeAsString.charAt(i);
hash *= FNV_PRIME;
}
return hash;
}
String getSubDirName(Long hashCode)
{
final long absVal = (hashCode.longValue() < 0)
? -hashCode.longValue()
: hashCode.longValue();
return
this.cacheSaveDirectory +
zeroPad10e4(absVal % AbstractHashCodeHLC.NUM_DIRS) + File.separator;
}
private static String zeroPad10e4(final long l)
{
if (l < 10) return "000" + l;
if (l < 100) return "00" + l;
if (l < 1000) return "0" + l;
if (l < 10000) return "" + l;
throw new UnreachableError();
}
}
|