Long2IntExact.java
1.08 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
package is2.data;
/**
* @author Bernd Bohnet, 01.09.2009
*
* Maps for the Hash Kernel the long values to the int values.
*/
final public class Long2IntExact implements Long2IntInterface {
static gnu.trove.TLongIntHashMap mapt = new gnu.trove.TLongIntHashMap();
static int cnt=0;
public Long2IntExact() {
size=115911564;
}
public Long2IntExact(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;
int i = mapt.get(l);
if (i!=0) return i;
if (i==0 && cnt<size-1) {
cnt++;
mapt.put(l, cnt);
return cnt;
}
return -1;
}
}