Long2Int.java
1.75 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
package is2.util;
import is2.data.Long2IntInterface;
/**
* @author Bernd Bohnet, 01.09.2009
*
* Maps for the Hash Kernel the long values to the int values.
*/
final public class Long2Int implements Long2IntInterface {
public Long2Int() {
size=115911564;
}
public Long2Int(int s) {
size=s;
}
/** Integer counter for long2int */
final private int size; //0x03ffffff //0x07ffffff
/* (non-Javadoc)
* @see is2.sp09k9992.Long2IntIterface#size()
*/
public int size() {return size;}
/* (non-Javadoc)
* @see is2.sp09k9992.Long2IntIterface#start()
* has no meaning for this implementation
*/
final public void start() {}
/* (non-Javadoc)
* @see is2.sp09k9992.Long2IntIterface#l2i(long)
*/
final public int l2i(long l) {
if (l<0) return -1;
// this works well LAS 88.138
// int r= (int)(( l ^ (l&0xffffffff00000000L) >>> 29 ));//0x811c9dc5 ^ // 29
// return Math.abs(r % size);
// this works a bit better and good with 0x03ffffff
//
/*
long r= l;//26
l = (l>>12)&0xfffffffffffff000L;
r ^= l;//38
l = (l>>11)&0xffffffffffffc000L;
r ^= l;//49
l = (l>>9)& 0xffffffffffff0000L; //53
r ^= l;//58
l = (l>>7)&0xfffffffffffc0000L; //62
r ^=l;//65
int x = (int)r;
x = x % size;
// return x >= 0 ? x : -x ;// Math.abs(r % size);
*/
// 26 0x03ffffff
// together with 0x07ffffff 27 88.372
long r= l;// 27
l = (l>>13)&0xffffffffffffe000L;
r ^= l; // 40
l = (l>>11)&0xffffffffffff0000L;
r ^= l; // 51
l = (l>>9)& 0xfffffffffffc0000L; //53
r ^= l; // 60
l = (l>>7)& 0xfffffffffff00000L; //62
r ^=l; //67
int x = ((int)r) % size;
return x >= 0 ? x : -x ;
}
}