summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/IntHashMap.java
blob: fff9d7acd6c8af16394d4242e62559e7263d0555 (plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package net.minecraft.server;

import java.util.HashSet;
import java.util.Set;

public class IntHashMap {

    private transient IntHashMapEntry[] a = new IntHashMapEntry[16];
    private transient int b;
    private int c = 12;
    private final float d = 0.75F;
    private transient volatile int e;
    // private Set f = new HashSet(); // CraftBukkit - expensive and unused

    public IntHashMap() {}

    private static int g(int i) {
        i ^= i >>> 20 ^ i >>> 12;
        return i ^ i >>> 7 ^ i >>> 4;
    }

    private static int a(int i, int j) {
        return i & j - 1;
    }

    public Object get(int i) {
        int j = g(i);

        for (IntHashMapEntry inthashmapentry = this.a[a(j, this.a.length)]; inthashmapentry != null; inthashmapentry = inthashmapentry.c) {
            if (inthashmapentry.a == i) {
                return inthashmapentry.b;
            }
        }

        return null;
    }

    public boolean b(int i) {
        return this.c(i) != null;
    }

    final IntHashMapEntry c(int i) {
        int j = g(i);

        for (IntHashMapEntry inthashmapentry = this.a[a(j, this.a.length)]; inthashmapentry != null; inthashmapentry = inthashmapentry.c) {
            if (inthashmapentry.a == i) {
                return inthashmapentry;
            }
        }

        return null;
    }

    public void a(int i, Object object) {
        // this.f.add(Integer.valueOf(i)); // CraftBukkit
        int j = g(i);
        int k = a(j, this.a.length);

        for (IntHashMapEntry inthashmapentry = this.a[k]; inthashmapentry != null; inthashmapentry = inthashmapentry.c) {
            if (inthashmapentry.a == i) {
                inthashmapentry.b = object;
                return;
            }
        }

        ++this.e;
        this.a(j, i, object, k);
    }

    private void h(int i) {
        IntHashMapEntry[] ainthashmapentry = this.a;
        int j = ainthashmapentry.length;

        if (j == 1073741824) {
            this.c = Integer.MAX_VALUE;
        } else {
            IntHashMapEntry[] ainthashmapentry1 = new IntHashMapEntry[i];

            this.a(ainthashmapentry1);
            this.a = ainthashmapentry1;
            this.c = (int) ((float) i * this.d);
        }
    }

    private void a(IntHashMapEntry[] ainthashmapentry) {
        IntHashMapEntry[] ainthashmapentry1 = this.a;
        int i = ainthashmapentry.length;

        for (int j = 0; j < ainthashmapentry1.length; ++j) {
            IntHashMapEntry inthashmapentry = ainthashmapentry1[j];

            if (inthashmapentry != null) {
                ainthashmapentry1[j] = null;

                IntHashMapEntry inthashmapentry1;

                do {
                    inthashmapentry1 = inthashmapentry.c;
                    int k = a(inthashmapentry.d, i);

                    inthashmapentry.c = ainthashmapentry[k];
                    ainthashmapentry[k] = inthashmapentry;
                    inthashmapentry = inthashmapentry1;
                } while (inthashmapentry1 != null);
            }
        }
    }

    public Object d(int i) {
        // this.f.remove(Integer.valueOf(i)); // CraftBukkit
        IntHashMapEntry inthashmapentry = this.e(i);

        return inthashmapentry == null ? null : inthashmapentry.b;
    }

    final IntHashMapEntry e(int i) {
        int j = g(i);
        int k = a(j, this.a.length);
        IntHashMapEntry inthashmapentry = this.a[k];

        IntHashMapEntry inthashmapentry1;
        IntHashMapEntry inthashmapentry2;

        for (inthashmapentry1 = inthashmapentry; inthashmapentry1 != null; inthashmapentry1 = inthashmapentry2) {
            inthashmapentry2 = inthashmapentry1.c;
            if (inthashmapentry1.a == i) {
                ++this.e;
                --this.b;
                if (inthashmapentry == inthashmapentry1) {
                    this.a[k] = inthashmapentry2;
                } else {
                    inthashmapentry.c = inthashmapentry2;
                }

                return inthashmapentry1;
            }

            inthashmapentry = inthashmapentry1;
        }

        return inthashmapentry1;
    }

    public void c() {
        ++this.e;
        IntHashMapEntry[] ainthashmapentry = this.a;

        for (int i = 0; i < ainthashmapentry.length; ++i) {
            ainthashmapentry[i] = null;
        }

        this.b = 0;
    }

    private void a(int i, int j, Object object, int k) {
        IntHashMapEntry inthashmapentry = this.a[k];

        this.a[k] = new IntHashMapEntry(i, j, object, inthashmapentry);
        if (this.b++ >= this.c) {
            this.h(2 * this.a.length);
        }
    }

    static int f(int i) {
        return g(i);
    }
}