package b.d;

import java.util.ConcurrentModificationException;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public class h<K, V> {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static Object[] f684a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static int f685b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static Object[] f686c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static int f687d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int[] f688e = d.f655a;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Object[] f689f = d.f657c;
    public int g = 0;

    public static void b(int[] iArr, Object[] objArr, int i) {
        if (iArr.length == 8) {
            synchronized (h.class) {
                if (f687d < 10) {
                    objArr[0] = f686c;
                    objArr[1] = iArr;
                    for (int i2 = (i << 1) - 1; i2 >= 2; i2--) {
                        objArr[i2] = null;
                    }
                    f686c = objArr;
                    f687d++;
                }
            }
            return;
        }
        if (iArr.length == 4) {
            synchronized (h.class) {
                if (f685b < 10) {
                    objArr[0] = f684a;
                    objArr[1] = iArr;
                    for (int i3 = (i << 1) - 1; i3 >= 2; i3--) {
                        objArr[i3] = null;
                    }
                    f684a = objArr;
                    f685b++;
                }
            }
        }
    }

    public final void a(int i) {
        if (i == 8) {
            synchronized (h.class) {
                Object[] objArr = f686c;
                if (objArr != null) {
                    this.f689f = objArr;
                    f686c = (Object[]) objArr[0];
                    this.f688e = (int[]) objArr[1];
                    objArr[1] = null;
                    objArr[0] = null;
                    f687d--;
                    return;
                }
            }
        } else if (i == 4) {
            synchronized (h.class) {
                Object[] objArr2 = f684a;
                if (objArr2 != null) {
                    this.f689f = objArr2;
                    f684a = (Object[]) objArr2[0];
                    this.f688e = (int[]) objArr2[1];
                    objArr2[1] = null;
                    objArr2[0] = null;
                    f685b--;
                    return;
                }
            }
        }
        this.f688e = new int[i];
        this.f689f = new Object[i << 1];
    }

    public int c(Object obj, int i) {
        int i2 = this.g;
        if (i2 == 0) {
            return -1;
        }
        try {
            int iA = d.a(this.f688e, i2, i);
            if (iA < 0 || obj.equals(this.f689f[iA << 1])) {
                return iA;
            }
            int i3 = iA + 1;
            while (i3 < i2 && this.f688e[i3] == i) {
                if (obj.equals(this.f689f[i3 << 1])) {
                    return i3;
                }
                i3++;
            }
            for (int i4 = iA - 1; i4 >= 0 && this.f688e[i4] == i; i4--) {
                if (obj.equals(this.f689f[i4 << 1])) {
                    return i4;
                }
            }
            return ~i3;
        } catch (ArrayIndexOutOfBoundsException unused) {
            throw new ConcurrentModificationException();
        }
    }

    public void clear() {
        int i = this.g;
        if (i > 0) {
            int[] iArr = this.f688e;
            Object[] objArr = this.f689f;
            this.f688e = d.f655a;
            this.f689f = d.f657c;
            this.g = 0;
            b(iArr, objArr, i);
        }
        if (this.g > 0) {
            throw new ConcurrentModificationException();
        }
    }

    public boolean containsKey(Object obj) {
        return d(obj) >= 0;
    }

    public boolean containsValue(Object obj) {
        return f(obj) >= 0;
    }

    public int d(Object obj) {
        return obj == null ? e() : c(obj, obj.hashCode());
    }

    public int e() {
        int i = this.g;
        if (i == 0) {
            return -1;
        }
        try {
            int iA = d.a(this.f688e, i, 0);
            if (iA < 0 || this.f689f[iA << 1] == null) {
                return iA;
            }
            int i2 = iA + 1;
            while (i2 < i && this.f688e[i2] == 0) {
                if (this.f689f[i2 << 1] == null) {
                    return i2;
                }
                i2++;
            }
            for (int i3 = iA - 1; i3 >= 0 && this.f688e[i3] == 0; i3--) {
                if (this.f689f[i3 << 1] == null) {
                    return i3;
                }
            }
            return ~i2;
        } catch (ArrayIndexOutOfBoundsException unused) {
            throw new ConcurrentModificationException();
        }
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof h) {
            h hVar = (h) obj;
            if (this.g != hVar.g) {
                return false;
            }
            for (int i = 0; i < this.g; i++) {
                try {
                    K kG = g(i);
                    V vJ = j(i);
                    Object obj2 = hVar.get(kG);
                    if (vJ == null) {
                        if (obj2 != null || !hVar.containsKey(kG)) {
                            return false;
                        }
                    } else if (!vJ.equals(obj2)) {
                        return false;
                    }
                } catch (ClassCastException | NullPointerException unused) {
                    return false;
                }
            }
            return true;
        }
        if (obj instanceof Map) {
            Map map = (Map) obj;
            if (this.g != map.size()) {
                return false;
            }
            for (int i2 = 0; i2 < this.g; i2++) {
                try {
                    K kG2 = g(i2);
                    V vJ2 = j(i2);
                    Object obj3 = map.get(kG2);
                    if (vJ2 == null) {
                        if (obj3 != null || !map.containsKey(kG2)) {
                            return false;
                        }
                    } else if (!vJ2.equals(obj3)) {
                        return false;
                    }
                } catch (ClassCastException | NullPointerException unused2) {
                }
            }
            return true;
        }
        return false;
    }

    public int f(Object obj) {
        int i = this.g * 2;
        Object[] objArr = this.f689f;
        if (obj == null) {
            for (int i2 = 1; i2 < i; i2 += 2) {
                if (objArr[i2] == null) {
                    return i2 >> 1;
                }
            }
            return -1;
        }
        for (int i3 = 1; i3 < i; i3 += 2) {
            if (obj.equals(objArr[i3])) {
                return i3 >> 1;
            }
        }
        return -1;
    }

    public K g(int i) {
        return (K) this.f689f[i << 1];
    }

    public V get(Object obj) {
        return getOrDefault(obj, null);
    }

    public V getOrDefault(Object obj, V v) {
        int iD = d(obj);
        return iD >= 0 ? (V) this.f689f[(iD << 1) + 1] : v;
    }

    public V h(int i) {
        Object[] objArr = this.f689f;
        int i2 = i << 1;
        V v = (V) objArr[i2 + 1];
        int i3 = this.g;
        int i4 = 0;
        if (i3 <= 1) {
            b(this.f688e, objArr, i3);
            this.f688e = d.f655a;
            this.f689f = d.f657c;
        } else {
            int i5 = i3 - 1;
            int[] iArr = this.f688e;
            if (iArr.length <= 8 || i3 >= iArr.length / 3) {
                if (i < i5) {
                    int i6 = i + 1;
                    int i7 = i5 - i;
                    System.arraycopy(iArr, i6, iArr, i, i7);
                    Object[] objArr2 = this.f689f;
                    System.arraycopy(objArr2, i6 << 1, objArr2, i2, i7 << 1);
                }
                Object[] objArr3 = this.f689f;
                int i8 = i5 << 1;
                objArr3[i8] = null;
                objArr3[i8 + 1] = null;
            } else {
                a(i3 > 8 ? i3 + (i3 >> 1) : 8);
                if (i3 != this.g) {
                    throw new ConcurrentModificationException();
                }
                if (i > 0) {
                    System.arraycopy(iArr, 0, this.f688e, 0, i);
                    System.arraycopy(objArr, 0, this.f689f, 0, i2);
                }
                if (i < i5) {
                    int i9 = i + 1;
                    int i10 = i5 - i;
                    System.arraycopy(iArr, i9, this.f688e, i, i10);
                    System.arraycopy(objArr, i9 << 1, this.f689f, i2, i10 << 1);
                }
            }
            i4 = i5;
        }
        if (i3 != this.g) {
            throw new ConcurrentModificationException();
        }
        this.g = i4;
        return v;
    }

    public int hashCode() {
        int[] iArr = this.f688e;
        Object[] objArr = this.f689f;
        int i = this.g;
        int i2 = 1;
        int i3 = 0;
        int iHashCode = 0;
        while (i3 < i) {
            Object obj = objArr[i2];
            iHashCode += (obj == null ? 0 : obj.hashCode()) ^ iArr[i3];
            i3++;
            i2 += 2;
        }
        return iHashCode;
    }

    public V i(int i, V v) {
        int i2 = (i << 1) + 1;
        Object[] objArr = this.f689f;
        V v2 = (V) objArr[i2];
        objArr[i2] = v;
        return v2;
    }

    public boolean isEmpty() {
        return this.g <= 0;
    }

    public V j(int i) {
        return (V) this.f689f[(i << 1) + 1];
    }

    public V put(K k, V v) {
        int i;
        int iC;
        int i2 = this.g;
        if (k == null) {
            iC = e();
            i = 0;
        } else {
            int iHashCode = k.hashCode();
            i = iHashCode;
            iC = c(k, iHashCode);
        }
        if (iC >= 0) {
            int i3 = (iC << 1) + 1;
            Object[] objArr = this.f689f;
            V v2 = (V) objArr[i3];
            objArr[i3] = v;
            return v2;
        }
        int i4 = ~iC;
        int[] iArr = this.f688e;
        if (i2 >= iArr.length) {
            int i5 = 4;
            if (i2 >= 8) {
                i5 = (i2 >> 1) + i2;
            } else if (i2 >= 4) {
                i5 = 8;
            }
            Object[] objArr2 = this.f689f;
            a(i5);
            if (i2 != this.g) {
                throw new ConcurrentModificationException();
            }
            int[] iArr2 = this.f688e;
            if (iArr2.length > 0) {
                System.arraycopy(iArr, 0, iArr2, 0, iArr.length);
                System.arraycopy(objArr2, 0, this.f689f, 0, objArr2.length);
            }
            b(iArr, objArr2, i2);
        }
        if (i4 < i2) {
            int[] iArr3 = this.f688e;
            int i6 = i4 + 1;
            System.arraycopy(iArr3, i4, iArr3, i6, i2 - i4);
            Object[] objArr3 = this.f689f;
            System.arraycopy(objArr3, i4 << 1, objArr3, i6 << 1, (this.g - i4) << 1);
        }
        int i7 = this.g;
        if (i2 == i7) {
            int[] iArr4 = this.f688e;
            if (i4 < iArr4.length) {
                iArr4[i4] = i;
                Object[] objArr4 = this.f689f;
                int i8 = i4 << 1;
                objArr4[i8] = k;
                objArr4[i8 + 1] = v;
                this.g = i7 + 1;
                return null;
            }
        }
        throw new ConcurrentModificationException();
    }

    public V putIfAbsent(K k, V v) {
        V orDefault = getOrDefault(k, null);
        return orDefault == null ? put(k, v) : orDefault;
    }

    public V remove(Object obj) {
        int iD = d(obj);
        if (iD >= 0) {
            return h(iD);
        }
        return null;
    }

    public boolean remove(Object obj, Object obj2) {
        int iD = d(obj);
        if (iD < 0) {
            return false;
        }
        V vJ = j(iD);
        if (obj2 != vJ && (obj2 == null || !obj2.equals(vJ))) {
            return false;
        }
        h(iD);
        return true;
    }

    public V replace(K k, V v) {
        int iD = d(k);
        if (iD >= 0) {
            return i(iD, v);
        }
        return null;
    }

    public boolean replace(K k, V v, V v2) {
        int iD = d(k);
        if (iD < 0) {
            return false;
        }
        V vJ = j(iD);
        if (vJ != v && (v == null || !v.equals(vJ))) {
            return false;
        }
        i(iD, v2);
        return true;
    }

    public int size() {
        return this.g;
    }

    public String toString() {
        if (isEmpty()) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.g * 28);
        sb.append('{');
        for (int i = 0; i < this.g; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            K kG = g(i);
            if (kG != this) {
                sb.append(kG);
            } else {
                sb.append("(this Map)");
            }
            sb.append('=');
            V vJ = j(i);
            if (vJ != this) {
                sb.append(vJ);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        return sb.toString();
    }
}
