package tm;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import jn.i;
import jn.o;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import sm.k0;

/* loaded from: classes3.dex */
public final class d implements Map, Serializable, en.d {
    public static final a C = new a(null);
    private static final d D;
    private tm.e A;
    private boolean B;

    /* renamed from: p, reason: collision with root package name */
    private Object[] f36342p;

    /* renamed from: q, reason: collision with root package name */
    private Object[] f36343q;

    /* renamed from: r, reason: collision with root package name */
    private int[] f36344r;

    /* renamed from: s, reason: collision with root package name */
    private int[] f36345s;

    /* renamed from: t, reason: collision with root package name */
    private int f36346t;

    /* renamed from: u, reason: collision with root package name */
    private int f36347u;

    /* renamed from: v, reason: collision with root package name */
    private int f36348v;

    /* renamed from: w, reason: collision with root package name */
    private int f36349w;

    /* renamed from: x, reason: collision with root package name */
    private int f36350x;

    /* renamed from: y, reason: collision with root package name */
    private tm.f f36351y;

    /* renamed from: z, reason: collision with root package name */
    private g f36352z;

    /* loaded from: classes3.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(k kVar) {
            this();
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final int c(int i10) {
            int d10;
            d10 = o.d(i10, 1);
            return Integer.highestOneBit(d10 * 3);
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final int d(int i10) {
            return Integer.numberOfLeadingZeros(i10) + 1;
        }

        public final d e() {
            return d.D;
        }
    }

    /* loaded from: classes3.dex */
    public static final class b extends C0860d implements Iterator, en.a {
        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public b(d map) {
            super(map);
            t.g(map, "map");
        }

        @Override // java.util.Iterator
        /* renamed from: h, reason: merged with bridge method [inline-methods] */
        public c next() {
            a();
            if (b() >= d().f36347u) {
                throw new NoSuchElementException();
            }
            int b10 = b();
            f(b10 + 1);
            g(b10);
            c cVar = new c(d(), c());
            e();
            return cVar;
        }

        public final void i(StringBuilder sb2) {
            t.g(sb2, "sb");
            if (b() >= d().f36347u) {
                throw new NoSuchElementException();
            }
            int b10 = b();
            f(b10 + 1);
            g(b10);
            Object obj = d().f36342p[c()];
            if (obj == d()) {
                sb2.append("(this Map)");
            } else {
                sb2.append(obj);
            }
            sb2.append('=');
            Object[] objArr = d().f36343q;
            t.d(objArr);
            Object obj2 = objArr[c()];
            if (obj2 == d()) {
                sb2.append("(this Map)");
            } else {
                sb2.append(obj2);
            }
            e();
        }

        public final int m() {
            if (b() >= d().f36347u) {
                throw new NoSuchElementException();
            }
            int b10 = b();
            f(b10 + 1);
            g(b10);
            Object obj = d().f36342p[c()];
            int hashCode = obj != null ? obj.hashCode() : 0;
            Object[] objArr = d().f36343q;
            t.d(objArr);
            Object obj2 = objArr[c()];
            int hashCode2 = hashCode ^ (obj2 != null ? obj2.hashCode() : 0);
            e();
            return hashCode2;
        }
    }

    /* loaded from: classes3.dex */
    public static final class c implements Map.Entry, en.a {

        /* renamed from: p, reason: collision with root package name */
        private final d f36353p;

        /* renamed from: q, reason: collision with root package name */
        private final int f36354q;

        public c(d map, int i10) {
            t.g(map, "map");
            this.f36353p = map;
            this.f36354q = i10;
        }

        @Override // java.util.Map.Entry
        public boolean equals(Object obj) {
            if (obj instanceof Map.Entry) {
                Map.Entry entry = (Map.Entry) obj;
                if (t.b(entry.getKey(), getKey()) && t.b(entry.getValue(), getValue())) {
                    return true;
                }
            }
            return false;
        }

        @Override // java.util.Map.Entry
        public Object getKey() {
            return this.f36353p.f36342p[this.f36354q];
        }

        @Override // java.util.Map.Entry
        public Object getValue() {
            Object[] objArr = this.f36353p.f36343q;
            t.d(objArr);
            return objArr[this.f36354q];
        }

        @Override // java.util.Map.Entry
        public int hashCode() {
            Object key = getKey();
            int hashCode = key != null ? key.hashCode() : 0;
            Object value = getValue();
            return hashCode ^ (value != null ? value.hashCode() : 0);
        }

        @Override // java.util.Map.Entry
        public Object setValue(Object obj) {
            this.f36353p.t();
            Object[] p10 = this.f36353p.p();
            int i10 = this.f36354q;
            Object obj2 = p10[i10];
            p10[i10] = obj;
            return obj2;
        }

        public String toString() {
            StringBuilder sb2 = new StringBuilder();
            sb2.append(getKey());
            sb2.append('=');
            sb2.append(getValue());
            return sb2.toString();
        }
    }

    /* renamed from: tm.d$d, reason: collision with other inner class name */
    /* loaded from: classes3.dex */
    public static class C0860d {

        /* renamed from: p, reason: collision with root package name */
        private final d f36355p;

        /* renamed from: q, reason: collision with root package name */
        private int f36356q;

        /* renamed from: r, reason: collision with root package name */
        private int f36357r;

        /* renamed from: s, reason: collision with root package name */
        private int f36358s;

        public C0860d(d map) {
            t.g(map, "map");
            this.f36355p = map;
            this.f36357r = -1;
            this.f36358s = map.f36349w;
            e();
        }

        public final void a() {
            if (this.f36355p.f36349w != this.f36358s) {
                throw new ConcurrentModificationException();
            }
        }

        public final int b() {
            return this.f36356q;
        }

        public final int c() {
            return this.f36357r;
        }

        public final d d() {
            return this.f36355p;
        }

        public final void e() {
            while (this.f36356q < this.f36355p.f36347u) {
                int[] iArr = this.f36355p.f36344r;
                int i10 = this.f36356q;
                if (iArr[i10] >= 0) {
                    return;
                } else {
                    this.f36356q = i10 + 1;
                }
            }
        }

        public final void f(int i10) {
            this.f36356q = i10;
        }

        public final void g(int i10) {
            this.f36357r = i10;
        }

        public final boolean hasNext() {
            return this.f36356q < this.f36355p.f36347u;
        }

        public final void remove() {
            a();
            if (!(this.f36357r != -1)) {
                throw new IllegalStateException("Call next() before removing element from the iterator.".toString());
            }
            this.f36355p.t();
            this.f36355p.X(this.f36357r);
            this.f36357r = -1;
            this.f36358s = this.f36355p.f36349w;
        }
    }

    /* loaded from: classes3.dex */
    public static final class e extends C0860d implements Iterator, en.a {
        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public e(d map) {
            super(map);
            t.g(map, "map");
        }

        @Override // java.util.Iterator
        public Object next() {
            a();
            if (b() >= d().f36347u) {
                throw new NoSuchElementException();
            }
            int b10 = b();
            f(b10 + 1);
            g(b10);
            Object obj = d().f36342p[c()];
            e();
            return obj;
        }
    }

    /* loaded from: classes3.dex */
    public static final class f extends C0860d implements Iterator, en.a {
        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public f(d map) {
            super(map);
            t.g(map, "map");
        }

        @Override // java.util.Iterator
        public Object next() {
            a();
            if (b() >= d().f36347u) {
                throw new NoSuchElementException();
            }
            int b10 = b();
            f(b10 + 1);
            g(b10);
            Object[] objArr = d().f36343q;
            t.d(objArr);
            Object obj = objArr[c()];
            e();
            return obj;
        }
    }

    static {
        d dVar = new d(0);
        dVar.B = true;
        D = dVar;
    }

    private d(Object[] objArr, Object[] objArr2, int[] iArr, int[] iArr2, int i10, int i11) {
        this.f36342p = objArr;
        this.f36343q = objArr2;
        this.f36344r = iArr;
        this.f36345s = iArr2;
        this.f36346t = i10;
        this.f36347u = i11;
        this.f36348v = C.d(I());
    }

    private final boolean A(Map map) {
        return size() == map.size() && y(map.entrySet());
    }

    private final void B(int i10) {
        if (i10 < 0) {
            throw new OutOfMemoryError();
        }
        if (i10 > G()) {
            int e10 = sm.c.f35825p.e(G(), i10);
            this.f36342p = tm.c.e(this.f36342p, e10);
            Object[] objArr = this.f36343q;
            this.f36343q = objArr != null ? tm.c.e(objArr, e10) : null;
            int[] copyOf = Arrays.copyOf(this.f36344r, e10);
            t.f(copyOf, "copyOf(...)");
            this.f36344r = copyOf;
            int c10 = C.c(e10);
            if (c10 > I()) {
                T(c10);
            }
        }
    }

    private final void C(int i10) {
        if (Z(i10)) {
            T(I());
        } else {
            B(this.f36347u + i10);
        }
    }

    private final int E(Object obj) {
        int M = M(obj);
        int i10 = this.f36346t;
        while (true) {
            int i11 = this.f36345s[M];
            if (i11 == 0) {
                return -1;
            }
            if (i11 > 0) {
                int i12 = i11 - 1;
                if (t.b(this.f36342p[i12], obj)) {
                    return i12;
                }
            }
            i10--;
            if (i10 < 0) {
                return -1;
            }
            M = M == 0 ? I() - 1 : M - 1;
        }
    }

    private final int F(Object obj) {
        int i10 = this.f36347u;
        while (true) {
            i10--;
            if (i10 < 0) {
                return -1;
            }
            if (this.f36344r[i10] >= 0) {
                Object[] objArr = this.f36343q;
                t.d(objArr);
                if (t.b(objArr[i10], obj)) {
                    return i10;
                }
            }
        }
    }

    private final int I() {
        return this.f36345s.length;
    }

    private final int M(Object obj) {
        return ((obj != null ? obj.hashCode() : 0) * (-1640531527)) >>> this.f36348v;
    }

    private final boolean P(Collection collection) {
        boolean z10 = false;
        if (collection.isEmpty()) {
            return false;
        }
        C(collection.size());
        Iterator it = collection.iterator();
        while (it.hasNext()) {
            if (Q((Map.Entry) it.next())) {
                z10 = true;
            }
        }
        return z10;
    }

    private final boolean Q(Map.Entry entry) {
        int m10 = m(entry.getKey());
        Object[] p10 = p();
        if (m10 >= 0) {
            p10[m10] = entry.getValue();
            return true;
        }
        int i10 = (-m10) - 1;
        if (t.b(entry.getValue(), p10[i10])) {
            return false;
        }
        p10[i10] = entry.getValue();
        return true;
    }

    private final boolean R(int i10) {
        int M = M(this.f36342p[i10]);
        int i11 = this.f36346t;
        while (true) {
            int[] iArr = this.f36345s;
            if (iArr[M] == 0) {
                iArr[M] = i10 + 1;
                this.f36344r[i10] = M;
                return true;
            }
            i11--;
            if (i11 < 0) {
                return false;
            }
            M = M == 0 ? I() - 1 : M - 1;
        }
    }

    private final void S() {
        this.f36349w++;
    }

    private final void T(int i10) {
        S();
        if (this.f36347u > size()) {
            w();
        }
        int i11 = 0;
        if (i10 != I()) {
            this.f36345s = new int[i10];
            this.f36348v = C.d(i10);
        } else {
            sm.o.t(this.f36345s, 0, 0, I());
        }
        while (i11 < this.f36347u) {
            int i12 = i11 + 1;
            if (!R(i11)) {
                throw new IllegalStateException("This cannot happen with fixed magic multiplier and grow-only hash array. Have object hashCodes changed?");
            }
            i11 = i12;
        }
    }

    private final void V(int i10) {
        int g10;
        g10 = o.g(this.f36346t * 2, I() / 2);
        int i11 = g10;
        int i12 = 0;
        int i13 = i10;
        do {
            i10 = i10 == 0 ? I() - 1 : i10 - 1;
            i12++;
            if (i12 > this.f36346t) {
                this.f36345s[i13] = 0;
                return;
            }
            int[] iArr = this.f36345s;
            int i14 = iArr[i10];
            if (i14 == 0) {
                iArr[i13] = 0;
                return;
            }
            if (i14 < 0) {
                iArr[i13] = -1;
            } else {
                int i15 = i14 - 1;
                if (((M(this.f36342p[i15]) - i10) & (I() - 1)) >= i12) {
                    this.f36345s[i13] = i14;
                    this.f36344r[i15] = i13;
                }
                i11--;
            }
            i13 = i10;
            i12 = 0;
            i11--;
        } while (i11 >= 0);
        this.f36345s[i13] = -1;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void X(int i10) {
        tm.c.f(this.f36342p, i10);
        V(this.f36344r[i10]);
        this.f36344r[i10] = -1;
        this.f36350x = size() - 1;
        S();
    }

    private final boolean Z(int i10) {
        int G = G();
        int i11 = this.f36347u;
        int i12 = G - i11;
        int size = i11 - size();
        return i12 < i10 && i12 + size >= i10 && size >= G() / 4;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Object[] p() {
        Object[] objArr = this.f36343q;
        if (objArr != null) {
            return objArr;
        }
        Object[] d10 = tm.c.d(G());
        this.f36343q = d10;
        return d10;
    }

    private final void w() {
        int i10;
        Object[] objArr = this.f36343q;
        int i11 = 0;
        int i12 = 0;
        while (true) {
            i10 = this.f36347u;
            if (i11 >= i10) {
                break;
            }
            if (this.f36344r[i11] >= 0) {
                Object[] objArr2 = this.f36342p;
                objArr2[i12] = objArr2[i11];
                if (objArr != null) {
                    objArr[i12] = objArr[i11];
                }
                i12++;
            }
            i11++;
        }
        tm.c.g(this.f36342p, i12, i10);
        if (objArr != null) {
            tm.c.g(objArr, i12, this.f36347u);
        }
        this.f36347u = i12;
    }

    public final b D() {
        return new b(this);
    }

    public final int G() {
        return this.f36342p.length;
    }

    public Set H() {
        tm.e eVar = this.A;
        if (eVar != null) {
            return eVar;
        }
        tm.e eVar2 = new tm.e(this);
        this.A = eVar2;
        return eVar2;
    }

    public Set J() {
        tm.f fVar = this.f36351y;
        if (fVar != null) {
            return fVar;
        }
        tm.f fVar2 = new tm.f(this);
        this.f36351y = fVar2;
        return fVar2;
    }

    public int K() {
        return this.f36350x;
    }

    public Collection L() {
        g gVar = this.f36352z;
        if (gVar != null) {
            return gVar;
        }
        g gVar2 = new g(this);
        this.f36352z = gVar2;
        return gVar2;
    }

    public final e O() {
        return new e(this);
    }

    public final boolean U(Map.Entry entry) {
        t.g(entry, "entry");
        t();
        int E = E(entry.getKey());
        if (E < 0) {
            return false;
        }
        Object[] objArr = this.f36343q;
        t.d(objArr);
        if (!t.b(objArr[E], entry.getValue())) {
            return false;
        }
        X(E);
        return true;
    }

    public final int W(Object obj) {
        t();
        int E = E(obj);
        if (E < 0) {
            return -1;
        }
        X(E);
        return E;
    }

    public final boolean Y(Object obj) {
        t();
        int F = F(obj);
        if (F < 0) {
            return false;
        }
        X(F);
        return true;
    }

    public final f a0() {
        return new f(this);
    }

    @Override // java.util.Map
    public void clear() {
        t();
        k0 it = new i(0, this.f36347u - 1).iterator();
        while (it.hasNext()) {
            int a10 = it.a();
            int[] iArr = this.f36344r;
            int i10 = iArr[a10];
            if (i10 >= 0) {
                this.f36345s[i10] = 0;
                iArr[a10] = -1;
            }
        }
        tm.c.g(this.f36342p, 0, this.f36347u);
        Object[] objArr = this.f36343q;
        if (objArr != null) {
            tm.c.g(objArr, 0, this.f36347u);
        }
        this.f36350x = 0;
        this.f36347u = 0;
        S();
    }

    @Override // java.util.Map
    public boolean containsKey(Object obj) {
        return E(obj) >= 0;
    }

    @Override // java.util.Map
    public boolean containsValue(Object obj) {
        return F(obj) >= 0;
    }

    @Override // java.util.Map
    public final /* bridge */ Set entrySet() {
        return H();
    }

    @Override // java.util.Map
    public boolean equals(Object obj) {
        return obj == this || ((obj instanceof Map) && A((Map) obj));
    }

    @Override // java.util.Map
    public Object get(Object obj) {
        int E = E(obj);
        if (E < 0) {
            return null;
        }
        Object[] objArr = this.f36343q;
        t.d(objArr);
        return objArr[E];
    }

    @Override // java.util.Map
    public int hashCode() {
        b D2 = D();
        int i10 = 0;
        while (D2.hasNext()) {
            i10 += D2.m();
        }
        return i10;
    }

    @Override // java.util.Map
    public boolean isEmpty() {
        return size() == 0;
    }

    @Override // java.util.Map
    public final /* bridge */ Set keySet() {
        return J();
    }

    public final int m(Object obj) {
        int g10;
        t();
        while (true) {
            int M = M(obj);
            g10 = o.g(this.f36346t * 2, I() / 2);
            int i10 = 0;
            while (true) {
                int i11 = this.f36345s[M];
                if (i11 <= 0) {
                    if (this.f36347u < G()) {
                        int i12 = this.f36347u;
                        int i13 = i12 + 1;
                        this.f36347u = i13;
                        this.f36342p[i12] = obj;
                        this.f36344r[i12] = M;
                        this.f36345s[M] = i13;
                        this.f36350x = size() + 1;
                        S();
                        if (i10 > this.f36346t) {
                            this.f36346t = i10;
                        }
                        return i12;
                    }
                    C(1);
                } else {
                    if (t.b(this.f36342p[i11 - 1], obj)) {
                        return -i11;
                    }
                    i10++;
                    if (i10 > g10) {
                        T(I() * 2);
                        break;
                    }
                    M = M == 0 ? I() - 1 : M - 1;
                }
            }
        }
    }

    @Override // java.util.Map
    public Object put(Object obj, Object obj2) {
        t();
        int m10 = m(obj);
        Object[] p10 = p();
        if (m10 >= 0) {
            p10[m10] = obj2;
            return null;
        }
        int i10 = (-m10) - 1;
        Object obj3 = p10[i10];
        p10[i10] = obj2;
        return obj3;
    }

    @Override // java.util.Map
    public void putAll(Map from) {
        t.g(from, "from");
        t();
        P(from.entrySet());
    }

    public final Map r() {
        t();
        this.B = true;
        if (size() > 0) {
            return this;
        }
        d dVar = D;
        t.e(dVar, "null cannot be cast to non-null type kotlin.collections.Map<K of kotlin.collections.builders.MapBuilder, V of kotlin.collections.builders.MapBuilder>");
        return dVar;
    }

    @Override // java.util.Map
    public Object remove(Object obj) {
        int W = W(obj);
        if (W < 0) {
            return null;
        }
        Object[] objArr = this.f36343q;
        t.d(objArr);
        Object obj2 = objArr[W];
        tm.c.f(objArr, W);
        return obj2;
    }

    @Override // java.util.Map
    public final /* bridge */ int size() {
        return K();
    }

    public final void t() {
        if (this.B) {
            throw new UnsupportedOperationException();
        }
    }

    public String toString() {
        StringBuilder sb2 = new StringBuilder((size() * 3) + 2);
        sb2.append("{");
        b D2 = D();
        int i10 = 0;
        while (D2.hasNext()) {
            if (i10 > 0) {
                sb2.append(", ");
            }
            D2.i(sb2);
            i10++;
        }
        sb2.append("}");
        String sb3 = sb2.toString();
        t.f(sb3, "toString(...)");
        return sb3;
    }

    @Override // java.util.Map
    public final /* bridge */ Collection values() {
        return L();
    }

    public final boolean y(Collection m10) {
        t.g(m10, "m");
        for (Object obj : m10) {
            if (obj != null) {
                try {
                    if (!z((Map.Entry) obj)) {
                    }
                } catch (ClassCastException unused) {
                }
            }
            return false;
        }
        return true;
    }

    public final boolean z(Map.Entry entry) {
        t.g(entry, "entry");
        int E = E(entry.getKey());
        if (E < 0) {
            return false;
        }
        Object[] objArr = this.f36343q;
        t.d(objArr);
        return t.b(objArr[E], entry.getValue());
    }

    public d() {
        this(8);
    }

    public d(int i10) {
        this(tm.c.d(i10), null, new int[i10], new int[C.c(i10)], 2, 0);
    }
}
