summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/LongHashMap.java
blob: 0e856131dc98949b7a7595a50a01af7172ec2351 (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
package net.minecraft.server;

public class LongHashMap {

    private transient LongHashMapEntry[] entries = new LongHashMapEntry[16];
    private transient int count;
    private int c = 12;
    private final float d = 0.75F;
    private transient volatile int e;

    public LongHashMap() {}

    private static int g(long i) {
        return a((int) (i ^ i >>> 32));
    }

    private static int a(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 int count() {
        return this.count;
    }

    public Object getEntry(long i) {
        int j = g(i);

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

        return null;
    }

    public boolean contains(long i) {
        return this.c(i) != null;
    }

    final LongHashMapEntry c(long i) {
        int j = g(i);

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

        return null;
    }

    public void put(long i, Object object) {
        int j = g(i);
        int k = a(j, this.entries.length);

        for (LongHashMapEntry longhashmapentry = this.entries[k]; longhashmapentry != null; longhashmapentry = longhashmapentry.c) {
            if (longhashmapentry.a == i) {
                longhashmapentry.b = object;
            }
        }

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

    private void b(int i) {
        LongHashMapEntry[] alonghashmapentry = this.entries;
        int j = alonghashmapentry.length;

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

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

    private void a(LongHashMapEntry[] alonghashmapentry) {
        LongHashMapEntry[] alonghashmapentry1 = this.entries;
        int i = alonghashmapentry.length;

        for (int j = 0; j < alonghashmapentry1.length; ++j) {
            LongHashMapEntry longhashmapentry = alonghashmapentry1[j];

            if (longhashmapentry != null) {
                alonghashmapentry1[j] = null;

                LongHashMapEntry longhashmapentry1;

                do {
                    longhashmapentry1 = longhashmapentry.c;
                    int k = a(longhashmapentry.d, i);

                    longhashmapentry.c = alonghashmapentry[k];
                    alonghashmapentry[k] = longhashmapentry;
                    longhashmapentry = longhashmapentry1;
                } while (longhashmapentry1 != null);
            }
        }
    }

    public Object remove(long i) {
        LongHashMapEntry longhashmapentry = this.e(i);

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

    final LongHashMapEntry e(long i) {
        int j = g(i);
        int k = a(j, this.entries.length);
        LongHashMapEntry longhashmapentry = this.entries[k];

        LongHashMapEntry longhashmapentry1;
        LongHashMapEntry longhashmapentry2;

        for (longhashmapentry1 = longhashmapentry; longhashmapentry1 != null; longhashmapentry1 = longhashmapentry2) {
            longhashmapentry2 = longhashmapentry1.c;
            if (longhashmapentry1.a == i) {
                ++this.e;
                --this.count;
                if (longhashmapentry == longhashmapentry1) {
                    this.entries[k] = longhashmapentry2;
                } else {
                    longhashmapentry.c = longhashmapentry2;
                }

                return longhashmapentry1;
            }

            longhashmapentry = longhashmapentry1;
        }

        return longhashmapentry1;
    }

    private void a(int i, long j, Object object, int k) {
        LongHashMapEntry longhashmapentry = this.entries[k];

        this.entries[k] = new LongHashMapEntry(i, j, object, longhashmapentry);
        if (this.count++ >= this.c) {
            this.b(2 * this.entries.length);
        }
    }

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