Initial commit
This commit is contained in:
131
sources/gnu/trove/THash.java
Normal file
131
sources/gnu/trove/THash.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package gnu.trove;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public abstract class THash implements Cloneable {
|
||||
protected static final int DEFAULT_INITIAL_CAPACITY = 4;
|
||||
protected static final float DEFAULT_LOAD_FACTOR = 0.8f;
|
||||
protected static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
|
||||
protected static final int JUST_CREATED_CAPACITY = -1;
|
||||
protected transient int _deadkeys;
|
||||
protected transient int _free;
|
||||
protected final float _loadFactor;
|
||||
protected int _maxSize;
|
||||
protected transient int _size;
|
||||
|
||||
public THash() {
|
||||
this(-1, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
private void compactIfNecessary() {
|
||||
if (this._deadkeys <= this._size || capacity() <= 42) {
|
||||
return;
|
||||
}
|
||||
compact();
|
||||
}
|
||||
|
||||
private void computeMaxSize(int i) {
|
||||
this._maxSize = Math.max(0, Math.min(i - 1, (int) (i * this._loadFactor)));
|
||||
this._free = i - this._size;
|
||||
this._deadkeys = 0;
|
||||
}
|
||||
|
||||
protected int calculateGrownCapacity() {
|
||||
return capacity() << 1;
|
||||
}
|
||||
|
||||
protected abstract int capacity();
|
||||
|
||||
public void clear() {
|
||||
this._size = 0;
|
||||
this._free = capacity();
|
||||
this._deadkeys = 0;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException unused) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void compact() {
|
||||
rehash(PrimeFinder.a(((int) (size() / this._loadFactor)) + 2));
|
||||
computeMaxSize(capacity());
|
||||
}
|
||||
|
||||
public void ensureCapacity(int i) {
|
||||
if (i > this._maxSize - size()) {
|
||||
rehash(PrimeFinder.a(((int) (i + (size() / this._loadFactor))) + 2));
|
||||
computeMaxSize(capacity());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this._size == 0;
|
||||
}
|
||||
|
||||
protected final void postInsertHook(boolean z) {
|
||||
if (z) {
|
||||
this._free--;
|
||||
} else {
|
||||
this._deadkeys--;
|
||||
}
|
||||
int i = this._size + 1;
|
||||
this._size = i;
|
||||
if (i > this._maxSize || this._free == 0) {
|
||||
rehash(PrimeFinder.a(calculateGrownCapacity()));
|
||||
computeMaxSize(capacity());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void rehash(int i);
|
||||
|
||||
protected void removeAt(int i) {
|
||||
this._size--;
|
||||
this._deadkeys++;
|
||||
compactIfNecessary();
|
||||
}
|
||||
|
||||
protected int setUp(int i) {
|
||||
int a = i == -1 ? 0 : PrimeFinder.a(i);
|
||||
computeMaxSize(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
public final void startCompactingOnRemove(boolean z) {
|
||||
int i = this._deadkeys;
|
||||
if (i > 0) {
|
||||
throw new IllegalStateException("Unpaired stop/startCompactingOnRemove");
|
||||
}
|
||||
this._deadkeys = i + capacity();
|
||||
if (z) {
|
||||
compactIfNecessary();
|
||||
}
|
||||
}
|
||||
|
||||
public final void stopCompactingOnRemove() {
|
||||
int i = this._deadkeys;
|
||||
if (i < 0) {
|
||||
throw new IllegalStateException("Unpaired stop/startCompactingOnRemove");
|
||||
}
|
||||
this._deadkeys = i - capacity();
|
||||
}
|
||||
|
||||
public final void trimToSize() {
|
||||
compact();
|
||||
}
|
||||
|
||||
public THash(int i) {
|
||||
this(i, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public THash(int i, float f) {
|
||||
this._loadFactor = f;
|
||||
setUp(i != -1 ? ((int) (i / f)) + 1 : -1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user