package zp;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/* loaded from: classes3.dex */
public class n0 {

    /* renamed from: b, reason: collision with root package name */
    private static final AtomicIntegerFieldUpdater f53569b = AtomicIntegerFieldUpdater.newUpdater(n0.class, "_size");
    private volatile int _size;

    /* renamed from: a, reason: collision with root package name */
    private o0[] f53570a;

    private final o0[] f() {
        o0[] o0VarArr = this.f53570a;
        if (o0VarArr == null) {
            o0[] o0VarArr2 = new o0[4];
            this.f53570a = o0VarArr2;
            return o0VarArr2;
        }
        if (c() < o0VarArr.length) {
            return o0VarArr;
        }
        Object[] copyOf = Arrays.copyOf(o0VarArr, c() * 2);
        kotlin.jvm.internal.t.f(copyOf, "copyOf(this, newSize)");
        o0[] o0VarArr3 = (o0[]) copyOf;
        this.f53570a = o0VarArr3;
        return o0VarArr3;
    }

    private final void j(int i10) {
        f53569b.set(this, i10);
    }

    private final void k(int i10) {
        while (true) {
            int i11 = (i10 * 2) + 1;
            if (i11 >= c()) {
                return;
            }
            o0[] o0VarArr = this.f53570a;
            kotlin.jvm.internal.t.d(o0VarArr);
            int i12 = i11 + 1;
            if (i12 < c()) {
                o0 o0Var = o0VarArr[i12];
                kotlin.jvm.internal.t.d(o0Var);
                o0 o0Var2 = o0VarArr[i11];
                kotlin.jvm.internal.t.d(o0Var2);
                if (((Comparable) o0Var).compareTo(o0Var2) < 0) {
                    i11 = i12;
                }
            }
            o0 o0Var3 = o0VarArr[i10];
            kotlin.jvm.internal.t.d(o0Var3);
            o0 o0Var4 = o0VarArr[i11];
            kotlin.jvm.internal.t.d(o0Var4);
            if (((Comparable) o0Var3).compareTo(o0Var4) <= 0) {
                return;
            }
            m(i10, i11);
            i10 = i11;
        }
    }

    private final void l(int i10) {
        while (i10 > 0) {
            o0[] o0VarArr = this.f53570a;
            kotlin.jvm.internal.t.d(o0VarArr);
            int i11 = (i10 - 1) / 2;
            o0 o0Var = o0VarArr[i11];
            kotlin.jvm.internal.t.d(o0Var);
            o0 o0Var2 = o0VarArr[i10];
            kotlin.jvm.internal.t.d(o0Var2);
            if (((Comparable) o0Var).compareTo(o0Var2) <= 0) {
                return;
            }
            m(i10, i11);
            i10 = i11;
        }
    }

    private final void m(int i10, int i11) {
        o0[] o0VarArr = this.f53570a;
        kotlin.jvm.internal.t.d(o0VarArr);
        o0 o0Var = o0VarArr[i11];
        kotlin.jvm.internal.t.d(o0Var);
        o0 o0Var2 = o0VarArr[i10];
        kotlin.jvm.internal.t.d(o0Var2);
        o0VarArr[i10] = o0Var;
        o0VarArr[i11] = o0Var2;
        o0Var.setIndex(i10);
        o0Var2.setIndex(i11);
    }

    public final void a(o0 o0Var) {
        o0Var.e(this);
        o0[] f10 = f();
        int c10 = c();
        j(c10 + 1);
        f10[c10] = o0Var;
        o0Var.setIndex(c10);
        l(c10);
    }

    public final o0 b() {
        o0[] o0VarArr = this.f53570a;
        if (o0VarArr != null) {
            return o0VarArr[0];
        }
        return null;
    }

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

    public final boolean d() {
        return c() == 0;
    }

    public final o0 e() {
        o0 b10;
        synchronized (this) {
            b10 = b();
        }
        return b10;
    }

    public final boolean g(o0 o0Var) {
        boolean z10;
        synchronized (this) {
            if (o0Var.m() == null) {
                z10 = false;
            } else {
                h(o0Var.getIndex());
                z10 = true;
            }
        }
        return z10;
    }

    public final o0 h(int i10) {
        o0[] o0VarArr = this.f53570a;
        kotlin.jvm.internal.t.d(o0VarArr);
        j(c() - 1);
        if (i10 < c()) {
            m(i10, c());
            int i11 = (i10 - 1) / 2;
            if (i10 > 0) {
                o0 o0Var = o0VarArr[i10];
                kotlin.jvm.internal.t.d(o0Var);
                o0 o0Var2 = o0VarArr[i11];
                kotlin.jvm.internal.t.d(o0Var2);
                if (((Comparable) o0Var).compareTo(o0Var2) < 0) {
                    m(i10, i11);
                    l(i11);
                }
            }
            k(i10);
        }
        o0 o0Var3 = o0VarArr[c()];
        kotlin.jvm.internal.t.d(o0Var3);
        o0Var3.e(null);
        o0Var3.setIndex(-1);
        o0VarArr[c()] = null;
        return o0Var3;
    }

    public final o0 i() {
        o0 h10;
        synchronized (this) {
            h10 = c() > 0 ? h(0) : null;
        }
        return h10;
    }
}
