what-the-bank/sources/com/google/common/collect/CompactLinkedHashSet.java

166 lines
5.3 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class CompactLinkedHashSet<E> extends CompactHashSet<E> {
private static final int ENDPOINT = -2;
private transient int firstEntry;
private transient int lastEntry;
private transient int[] predecessor;
private transient int[] successor;
public static <E> CompactLinkedHashSet<E> create() {
return new CompactLinkedHashSet<>();
}
public static <E> CompactLinkedHashSet<E> create(Collection<? extends E> collection) {
CompactLinkedHashSet<E> createWithExpectedSize = createWithExpectedSize(collection.size());
createWithExpectedSize.addAll(collection);
return createWithExpectedSize;
}
@SafeVarargs
public static <E> CompactLinkedHashSet<E> create(E... eArr) {
CompactLinkedHashSet<E> createWithExpectedSize = createWithExpectedSize(eArr.length);
Collections.addAll(createWithExpectedSize, eArr);
return createWithExpectedSize;
}
public static <E> CompactLinkedHashSet<E> createWithExpectedSize(int i) {
return new CompactLinkedHashSet<>(i);
}
CompactLinkedHashSet() {
}
CompactLinkedHashSet(int i) {
super(i);
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.CompactHashSet
public void init(int i) {
super.init(i);
this.firstEntry = -2;
this.lastEntry = -2;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.CompactHashSet
public int allocArrays() {
int allocArrays = super.allocArrays();
this.predecessor = new int[allocArrays];
this.successor = new int[allocArrays];
return allocArrays;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.CompactHashSet
public Set<E> convertToHashFloodingResistantImplementation() {
Set<E> convertToHashFloodingResistantImplementation = super.convertToHashFloodingResistantImplementation();
this.predecessor = null;
this.successor = null;
return convertToHashFloodingResistantImplementation;
}
private int getPredecessor(int i) {
return this.predecessor[i] - 1;
}
@Override // com.google.common.collect.CompactHashSet
int getSuccessor(int i) {
return this.successor[i] - 1;
}
private void setSuccessor(int i, int i2) {
this.successor[i] = i2 + 1;
}
private void setPredecessor(int i, int i2) {
this.predecessor[i] = i2 + 1;
}
private void setSucceeds(int i, int i2) {
if (i == -2) {
this.firstEntry = i2;
} else {
setSuccessor(i, i2);
}
if (i2 == -2) {
this.lastEntry = i;
} else {
setPredecessor(i2, i);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.CompactHashSet
public void insertEntry(int i, E e, int i2, int i3) {
super.insertEntry(i, e, i2, i3);
setSucceeds(this.lastEntry, i);
setSucceeds(i, -2);
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.CompactHashSet
public void moveLastEntry(int i, int i2) {
int size = size() - 1;
super.moveLastEntry(i, i2);
setSucceeds(getPredecessor(i), getSuccessor(i));
if (i < size) {
setSucceeds(getPredecessor(size), i);
setSucceeds(i, getSuccessor(size));
}
this.predecessor[size] = 0;
this.successor[size] = 0;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.CompactHashSet
public void resizeEntries(int i) {
super.resizeEntries(i);
this.predecessor = Arrays.copyOf(this.predecessor, i);
this.successor = Arrays.copyOf(this.successor, i);
}
@Override // com.google.common.collect.CompactHashSet
int adjustAfterRemove(int i, int i2) {
return i >= size() ? i2 : i;
}
@Override // com.google.common.collect.CompactHashSet, java.util.AbstractCollection, java.util.Collection, java.util.Set
public Object[] toArray() {
return ObjectArrays.toArrayImpl(this);
}
@Override // com.google.common.collect.CompactHashSet, java.util.AbstractCollection, java.util.Collection, java.util.Set
public <T> T[] toArray(T[] tArr) {
return (T[]) ObjectArrays.toArrayImpl(this, tArr);
}
@Override // com.google.common.collect.CompactHashSet, java.util.AbstractCollection, java.util.Collection, java.util.Set
public void clear() {
if (needsAllocArrays()) {
return;
}
this.firstEntry = -2;
this.lastEntry = -2;
int[] iArr = this.predecessor;
if (iArr != null) {
Arrays.fill(iArr, 0, size(), 0);
Arrays.fill(this.successor, 0, size(), 0);
}
super.clear();
}
@Override // com.google.common.collect.CompactHashSet
int firstEntryIndex() {
return this.firstEntry;
}
}