package androidx.datastore.preferences.protobuf;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

/* JADX INFO: loaded from: classes.dex */
public abstract class f1 extends AbstractMap {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final /* synthetic */ int f2067f = 0;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public List f2068a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Map f2069b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f2070c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public volatile e1 f2071d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Map f2072e;

    /* JADX WARN: Removed duplicated region for block: B:13:0x0024  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int a(Comparable comparable) {
        int i10;
        int i11;
        int size = this.f2068a.size();
        int i12 = size - 1;
        if (i12 < 0) {
            i10 = 0;
            while (i10 <= i12) {
                int i13 = (i10 + i12) / 2;
                int iCompareTo = comparable.compareTo(((c1) this.f2068a.get(i13)).f2050a);
                if (iCompareTo < 0) {
                    i12 = i13 - 1;
                } else {
                    if (iCompareTo <= 0) {
                        return i13;
                    }
                    i10 = i13 + 1;
                }
            }
            i11 = i10 + 1;
        } else {
            int iCompareTo2 = comparable.compareTo(((c1) this.f2068a.get(i12)).f2050a);
            if (iCompareTo2 > 0) {
                i11 = size + 1;
            } else {
                if (iCompareTo2 == 0) {
                    return i12;
                }
                i10 = 0;
                while (i10 <= i12) {
                }
                i11 = i10 + 1;
            }
        }
        return -i11;
    }

    public final void b() {
        if (this.f2070c) {
            throw new UnsupportedOperationException();
        }
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final void clear() {
        b();
        if (!this.f2068a.isEmpty()) {
            this.f2068a.clear();
        }
        if (this.f2069b.isEmpty()) {
            return;
        }
        this.f2069b.clear();
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final boolean containsKey(Object obj) {
        Comparable comparable = (Comparable) obj;
        return a(comparable) >= 0 || this.f2069b.containsKey(comparable);
    }

    public final Map.Entry d(int i10) {
        return (Map.Entry) this.f2068a.get(i10);
    }

    public final Set e() {
        return this.f2069b.isEmpty() ? Collections.emptySet() : this.f2069b.entrySet();
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Set entrySet() {
        if (this.f2071d == null) {
            this.f2071d = new e1(this);
        }
        return this.f2071d;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof f1)) {
            return super.equals(obj);
        }
        f1 f1Var = (f1) obj;
        int size = size();
        if (size != f1Var.size()) {
            return false;
        }
        int size2 = this.f2068a.size();
        if (size2 != f1Var.f2068a.size()) {
            return entrySet().equals(f1Var.entrySet());
        }
        for (int i10 = 0; i10 < size2; i10++) {
            if (!d(i10).equals(f1Var.d(i10))) {
                return false;
            }
        }
        if (size2 != size) {
            return this.f2069b.equals(f1Var.f2069b);
        }
        return true;
    }

    public final SortedMap g() {
        b();
        if (this.f2069b.isEmpty() && !(this.f2069b instanceof TreeMap)) {
            TreeMap treeMap = new TreeMap();
            this.f2069b = treeMap;
            this.f2072e = treeMap.descendingMap();
        }
        return (SortedMap) this.f2069b;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Object get(Object obj) {
        Comparable comparable = (Comparable) obj;
        int iA = a(comparable);
        return iA >= 0 ? ((c1) this.f2068a.get(iA)).f2051b : this.f2069b.get(comparable);
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final int hashCode() {
        int size = this.f2068a.size();
        int iHashCode = 0;
        for (int i10 = 0; i10 < size; i10++) {
            iHashCode += ((c1) this.f2068a.get(i10)).hashCode();
        }
        return this.f2069b.size() > 0 ? iHashCode + this.f2069b.hashCode() : iHashCode;
    }

    public final Object i(Comparable comparable, Object obj) {
        b();
        int iA = a(comparable);
        if (iA >= 0) {
            return ((c1) this.f2068a.get(iA)).setValue(obj);
        }
        b();
        if (this.f2068a.isEmpty() && !(this.f2068a instanceof ArrayList)) {
            this.f2068a = new ArrayList(16);
        }
        int i10 = -(iA + 1);
        if (i10 >= 16) {
            return g().put(comparable, obj);
        }
        if (this.f2068a.size() == 16) {
            c1 c1Var = (c1) this.f2068a.remove(15);
            g().put(c1Var.f2050a, c1Var.f2051b);
        }
        this.f2068a.add(i10, new c1(this, comparable, obj));
        return null;
    }

    public final Object j(int i10) {
        b();
        Object obj = ((c1) this.f2068a.remove(i10)).f2051b;
        if (!this.f2069b.isEmpty()) {
            Iterator it = g().entrySet().iterator();
            List list = this.f2068a;
            Map.Entry entry = (Map.Entry) it.next();
            list.add(new c1(this, (Comparable) entry.getKey(), entry.getValue()));
            it.remove();
        }
        return obj;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Object remove(Object obj) {
        b();
        Comparable comparable = (Comparable) obj;
        int iA = a(comparable);
        if (iA >= 0) {
            return j(iA);
        }
        if (this.f2069b.isEmpty()) {
            return null;
        }
        return this.f2069b.remove(comparable);
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final int size() {
        return this.f2069b.size() + this.f2068a.size();
    }
}
