jimu-decompiled/sources/com/google/common/collect/ObjectCountHashMap.java
2025-05-13 19:24:51 +02:00

316 lines
8.4 KiB
Java

package com.google.common.collect;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.AbstractObjectCountMap;
import com.google.common.collect.Multiset;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Set;
/* loaded from: classes.dex */
class ObjectCountHashMap<K> extends AbstractObjectCountMap<K> {
private transient int[] g;
transient long[] h;
private transient float i;
private transient int j;
class HashEntrySetView extends AbstractObjectCountMap<K>.EntrySetView {
HashEntrySetView() {
super();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
public Iterator<Multiset.Entry<K>> iterator() {
return new AbstractObjectCountMap<K>.Itr<Multiset.Entry<K>>() { // from class: com.google.common.collect.ObjectCountHashMap.HashEntrySetView.1
{
ObjectCountHashMap objectCountHashMap = ObjectCountHashMap.this;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.AbstractObjectCountMap.Itr
public Multiset.Entry<K> a(int i) {
return new AbstractObjectCountMap.MapEntry(i);
}
};
}
}
ObjectCountHashMap() {
a(3, 1.0f);
}
private static int a(long j) {
return (int) (j >>> 32);
}
private static long a(long j, int i) {
return (j & (-4294967296L)) | (i & 4294967295L);
}
private static int b(long j) {
return (int) j;
}
public static <K> ObjectCountHashMap<K> h(int i) {
return new ObjectCountHashMap<>(i);
}
public static <K> ObjectCountHashMap<K> i() {
return new ObjectCountHashMap<>();
}
private static int[] j(int i) {
int[] iArr = new int[i];
Arrays.fill(iArr, -1);
return iArr;
}
private void k(int i) {
int length = this.h.length;
if (i > length) {
int max = Math.max(1, length >>> 1) + length;
if (max < 0) {
max = Integer.MAX_VALUE;
}
if (max != length) {
g(max);
}
}
}
private void l(int i) {
if (this.g.length >= 1073741824) {
this.j = Integer.MAX_VALUE;
return;
}
int i2 = ((int) (i * this.i)) + 1;
int[] j = j(i);
long[] jArr = this.h;
int length = j.length - 1;
for (int i3 = 0; i3 < this.c; i3++) {
int a = a(jArr[i3]);
int i4 = a & length;
int i5 = j[i4];
j[i4] = i3;
jArr[i3] = (a << 32) | (i5 & 4294967295L);
}
this.j = i2;
this.g = j;
}
void a(int i, float f) {
Preconditions.a(i >= 0, "Initial capacity must be non-negative");
Preconditions.a(f > 0.0f, "Illegal load factor");
int a = Hashing.a(i, f);
this.g = j(a);
this.i = f;
this.a = new Object[i];
this.b = new int[i];
this.h = i(i);
this.j = Math.max(1, (int) (a * f));
}
@Override // com.google.common.collect.AbstractObjectCountMap
int b(Object obj) {
int a = Hashing.a(obj);
int i = this.g[j() & a];
while (i != -1) {
long j = this.h[i];
if (a(j) == a && Objects.a(obj, this.a[i])) {
return i;
}
i = b(j);
}
return -1;
}
@Override // com.google.common.collect.AbstractObjectCountMap
public int c(Object obj) {
return b(obj, Hashing.a(obj));
}
@Override // com.google.common.collect.AbstractObjectCountMap
int e(int i) {
return b(this.a[i], a(this.h[i]));
}
void f(int i) {
int h = h() - 1;
if (i >= h) {
this.a[i] = null;
this.b[i] = 0;
this.h[i] = -1;
return;
}
Object[] objArr = this.a;
objArr[i] = objArr[h];
int[] iArr = this.b;
iArr[i] = iArr[h];
objArr[h] = null;
iArr[h] = 0;
long[] jArr = this.h;
long j = jArr[h];
jArr[i] = j;
jArr[h] = -1;
int a = a(j) & j();
int[] iArr2 = this.g;
int i2 = iArr2[a];
if (i2 == h) {
iArr2[a] = i;
return;
}
while (true) {
long j2 = this.h[i2];
int b = b(j2);
if (b == h) {
this.h[i2] = a(j2, i);
return;
}
i2 = b;
}
}
void g(int i) {
this.a = Arrays.copyOf(this.a, i);
this.b = Arrays.copyOf(this.b, i);
long[] jArr = this.h;
int length = jArr.length;
long[] copyOf = Arrays.copyOf(jArr, i);
if (i > length) {
Arrays.fill(copyOf, length, i, -1L);
}
this.h = copyOf;
}
private static long[] i(int i) {
long[] jArr = new long[i];
Arrays.fill(jArr, -1L);
return jArr;
}
ObjectCountHashMap(AbstractObjectCountMap<K> abstractObjectCountMap) {
a(abstractObjectCountMap.h(), 1.0f);
int e = abstractObjectCountMap.e();
while (e != -1) {
a((ObjectCountHashMap<K>) abstractObjectCountMap.b(e), abstractObjectCountMap.c(e));
e = abstractObjectCountMap.d(e);
}
}
private int j() {
return this.g.length - 1;
}
private int b(Object obj, int i) {
int j = j() & i;
int i2 = this.g[j];
if (i2 == -1) {
return 0;
}
int i3 = -1;
while (true) {
if (a(this.h[i2]) == i && Objects.a(obj, this.a[i2])) {
int i4 = this.b[i2];
if (i3 == -1) {
this.g[j] = b(this.h[i2]);
} else {
long[] jArr = this.h;
jArr[i3] = a(jArr[i3], b(jArr[i2]));
}
f(i2);
this.c--;
this.d++;
return i4;
}
int b = b(this.h[i2]);
if (b == -1) {
return 0;
}
i3 = i2;
i2 = b;
}
}
ObjectCountHashMap(int i) {
this(i, 1.0f);
}
ObjectCountHashMap(int i, float f) {
a(i, f);
}
@Override // com.google.common.collect.AbstractObjectCountMap
public int a(K k, int i) {
CollectPreconditions.b(i, "count");
long[] jArr = this.h;
Object[] objArr = this.a;
int[] iArr = this.b;
int a = Hashing.a(k);
int j = j() & a;
int i2 = this.c;
int[] iArr2 = this.g;
int i3 = iArr2[j];
if (i3 == -1) {
iArr2[j] = i2;
} else {
while (true) {
long j2 = jArr[i3];
if (a(j2) == a && Objects.a(k, objArr[i3])) {
int i4 = iArr[i3];
iArr[i3] = i;
return i4;
}
int b = b(j2);
if (b == -1) {
jArr[i3] = a(j2, i2);
break;
}
i3 = b;
}
}
if (i2 != Integer.MAX_VALUE) {
int i5 = i2 + 1;
k(i5);
a(i2, k, i, a);
this.c = i5;
if (i2 >= this.j) {
l(this.g.length * 2);
}
this.d++;
return 0;
}
throw new IllegalStateException("Cannot contain more than Integer.MAX_VALUE elements!");
}
@Override // com.google.common.collect.AbstractObjectCountMap
Set<Multiset.Entry<K>> b() {
return new HashEntrySetView();
}
void a(int i, K k, int i2, int i3) {
this.h[i] = (i3 << 32) | 4294967295L;
this.a[i] = k;
this.b[i] = i2;
}
@Override // com.google.common.collect.AbstractObjectCountMap
public int a(Object obj) {
int b = b(obj);
if (b == -1) {
return 0;
}
return this.b[b];
}
@Override // com.google.common.collect.AbstractObjectCountMap
public void a() {
this.d++;
Arrays.fill(this.a, 0, this.c, (Object) null);
Arrays.fill(this.b, 0, this.c, 0);
Arrays.fill(this.g, -1);
Arrays.fill(this.h, -1L);
this.c = 0;
}
}