-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneStore.java
79 lines (65 loc) · 1.6 KB
/
GeneStore.java
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
import java.util.Hashtable;
import java.util.Enumeration;
import java.lang.Math;
class WormTuple {
WormControl W;
int reference_count;
}
public class GeneStore {
static Hashtable H=new Hashtable(2000);
static void register(int uid, WormControl wc) {
WormTuple wt=new WormTuple();
wt.W=wc; wt.reference_count=1;
H.put(uid,wt);
}
static WormControl getWormControl(int uid) {
WormTuple wt=(WormTuple)H.get(uid);
if (wt!=null) return wt.W; else return null;
}
static void increment(int uid){
WormTuple wt=(WormTuple)H.get(uid);
if (wt!=null) wt.reference_count++;
}
static void decrement(int uid){
WormTuple wt=(WormTuple)H.get(uid);
if (wt!=null) {
wt.reference_count--;
if (wt.reference_count==0) H.remove(uid);
}
}
static void unregister(int uid) {
decrement(uid);
}
static void status(int uid) {
WormTuple wt=(WormTuple)H.get(uid);
if (wt!=null) {
System.out.println("value "+wt.reference_count);
} else System.out.println("UID NOT PRESENT");
}
public static void main(String [] args) {
WormControl wc=new WormControl();
register(12,wc);
register(13,wc);
register(14,wc);
register(15,wc);
status(12);
increment(12);
increment(12);
status(12);
decrement(12);
decrement(12);
unregister(12);
status(12);
TouchStore T=new TouchStore();
T.touch(13);
T.touch(14);
T.touch(15);
T.touch(15);
System.out.println(T.select());
status(15);
T.clear();
status(15);
System.out.println(T.select());
getWormControl(15);
}
}