282 lines
7.9 KiB
Java
282 lines
7.9 KiB
Java
package gnu.trove;
|
|
|
|
import java.io.IOException;
|
|
import java.io.ObjectInputStream;
|
|
import java.io.ObjectOutputStream;
|
|
import java.lang.reflect.Array;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.Set;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class THashSet<E> extends TObjectHash<E> implements Set<E> {
|
|
|
|
private final class HashProcedure implements TObjectProcedure<E> {
|
|
private int a;
|
|
|
|
HashProcedure() {
|
|
}
|
|
|
|
public int a() {
|
|
return this.a;
|
|
}
|
|
|
|
@Override // gnu.trove.TObjectProcedure
|
|
public final boolean execute(E e) {
|
|
this.a += THashSet.this._hashingStrategy.computeHashCode(e);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public THashSet() {
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
|
objectInputStream.defaultReadObject();
|
|
int readInt = objectInputStream.readInt();
|
|
setUp(readInt);
|
|
while (true) {
|
|
int i = readInt - 1;
|
|
if (readInt <= 0) {
|
|
return;
|
|
}
|
|
add(objectInputStream.readObject());
|
|
readInt = i;
|
|
}
|
|
}
|
|
|
|
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
|
|
objectOutputStream.defaultWriteObject();
|
|
objectOutputStream.writeInt(this._size);
|
|
SerializationProcedure serializationProcedure = new SerializationProcedure(objectOutputStream);
|
|
if (!forEach(serializationProcedure)) {
|
|
throw serializationProcedure.b;
|
|
}
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public boolean add(E e) {
|
|
int insertionIndex = insertionIndex(e);
|
|
if (insertionIndex < 0) {
|
|
return false;
|
|
}
|
|
Object[] objArr = this._set;
|
|
Object obj = objArr[insertionIndex];
|
|
objArr[insertionIndex] = e;
|
|
postInsertHook(obj == null);
|
|
return true;
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public boolean addAll(Collection<? extends E> collection) {
|
|
int size = collection.size();
|
|
ensureCapacity(size);
|
|
Iterator<? extends E> it = collection.iterator();
|
|
boolean z = false;
|
|
while (true) {
|
|
int i = size - 1;
|
|
if (size <= 0) {
|
|
return z;
|
|
}
|
|
if (add(it.next())) {
|
|
z = true;
|
|
}
|
|
size = i;
|
|
}
|
|
}
|
|
|
|
@Override // gnu.trove.THash
|
|
public void clear() {
|
|
super.clear();
|
|
Object[] objArr = this._set;
|
|
int length = objArr.length;
|
|
while (true) {
|
|
int i = length - 1;
|
|
if (length <= 0) {
|
|
return;
|
|
}
|
|
objArr[i] = null;
|
|
length = i;
|
|
}
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public boolean containsAll(Collection<?> collection) {
|
|
Iterator<?> it = collection.iterator();
|
|
while (it.hasNext()) {
|
|
if (!contains(it.next())) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public boolean equals(Object obj) {
|
|
if (!(obj instanceof Set)) {
|
|
return false;
|
|
}
|
|
Set set = (Set) obj;
|
|
if (set.size() != size()) {
|
|
return false;
|
|
}
|
|
return containsAll(set);
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public int hashCode() {
|
|
HashProcedure hashProcedure = new HashProcedure();
|
|
forEach(hashProcedure);
|
|
return hashProcedure.a();
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection, java.lang.Iterable
|
|
public Iterator<E> iterator() {
|
|
return new TObjectHashIterator(this);
|
|
}
|
|
|
|
@Override // gnu.trove.THash
|
|
protected void rehash(int i) {
|
|
int capacity = capacity();
|
|
Object[] objArr = this._set;
|
|
this._set = new Object[i];
|
|
while (true) {
|
|
int i2 = capacity - 1;
|
|
if (capacity <= 0) {
|
|
return;
|
|
}
|
|
if (objArr[i2] != null && objArr[i2] != TObjectHash.REMOVED) {
|
|
Object obj = objArr[i2];
|
|
int insertionIndex = insertionIndex(obj);
|
|
if (insertionIndex < 0) {
|
|
throwObjectContractViolation(this._set[(-insertionIndex) - 1], obj);
|
|
}
|
|
this._set[insertionIndex] = obj;
|
|
}
|
|
capacity = i2;
|
|
}
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public boolean remove(Object obj) {
|
|
int index = index(obj);
|
|
if (index < 0) {
|
|
return false;
|
|
}
|
|
removeAt(index);
|
|
return true;
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public boolean removeAll(Collection<?> collection) {
|
|
int size = collection.size();
|
|
Iterator<?> it = collection.iterator();
|
|
boolean z = false;
|
|
while (true) {
|
|
int i = size - 1;
|
|
if (size <= 0) {
|
|
return z;
|
|
}
|
|
if (remove(it.next())) {
|
|
z = true;
|
|
}
|
|
size = i;
|
|
}
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public boolean retainAll(Collection<?> collection) {
|
|
int size = size();
|
|
Iterator<E> it = iterator();
|
|
boolean z = false;
|
|
while (true) {
|
|
int i = size - 1;
|
|
if (size <= 0) {
|
|
return z;
|
|
}
|
|
if (!collection.contains(it.next())) {
|
|
it.remove();
|
|
z = true;
|
|
}
|
|
size = i;
|
|
}
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public Object[] toArray() {
|
|
Object[] objArr = new Object[size()];
|
|
forEach(new ToObjectArrayProcedure(objArr));
|
|
return objArr;
|
|
}
|
|
|
|
public String toString() {
|
|
final StringBuilder sb = new StringBuilder();
|
|
forEach(new TObjectProcedure<E>(this) { // from class: gnu.trove.THashSet.1
|
|
@Override // gnu.trove.TObjectProcedure
|
|
public boolean execute(E e) {
|
|
if (sb.length() != 0) {
|
|
StringBuilder sb2 = sb;
|
|
sb2.append(',');
|
|
sb2.append(' ');
|
|
}
|
|
StringBuilder sb3 = sb;
|
|
if (e == this) {
|
|
e = (E) "(this set)";
|
|
}
|
|
sb3.append(e);
|
|
return true;
|
|
}
|
|
});
|
|
sb.append(']');
|
|
sb.insert(0, '[');
|
|
return sb.toString();
|
|
}
|
|
|
|
public THashSet(TObjectHashingStrategy<E> tObjectHashingStrategy) {
|
|
super(tObjectHashingStrategy);
|
|
}
|
|
|
|
public THashSet(int i) {
|
|
super(i);
|
|
}
|
|
|
|
@Override // java.util.Set, java.util.Collection
|
|
public <T> T[] toArray(T[] tArr) {
|
|
int size = size();
|
|
if (tArr.length < size) {
|
|
tArr = (T[]) ((Object[]) Array.newInstance(tArr.getClass().getComponentType(), size));
|
|
}
|
|
Iterator<E> it = iterator();
|
|
for (int i = 0; i < size; i++) {
|
|
tArr[i] = it.next();
|
|
}
|
|
if (tArr.length > size) {
|
|
tArr[size] = null;
|
|
}
|
|
return tArr;
|
|
}
|
|
|
|
public THashSet(int i, TObjectHashingStrategy<E> tObjectHashingStrategy) {
|
|
super(i, tObjectHashingStrategy);
|
|
}
|
|
|
|
public THashSet(int i, float f) {
|
|
super(i, f);
|
|
}
|
|
|
|
public THashSet(int i, float f, TObjectHashingStrategy<E> tObjectHashingStrategy) {
|
|
super(i, f, tObjectHashingStrategy);
|
|
}
|
|
|
|
public THashSet(Collection<? extends E> collection) {
|
|
this(collection.size());
|
|
addAll(collection);
|
|
}
|
|
|
|
public THashSet(Collection<? extends E> collection, TObjectHashingStrategy<E> tObjectHashingStrategy) {
|
|
this(collection.size(), tObjectHashingStrategy);
|
|
addAll(collection);
|
|
}
|
|
}
|