package o;

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

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.mf0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public class C1878mf0 {
    public static final /* synthetic */ AtomicIntegerFieldUpdater b = AtomicIntegerFieldUpdater.newUpdater(C1878mf0.class, "_size$volatile");
    private volatile /* synthetic */ int _size$volatile;
    public AbstractRunnableC0359Nw[] a;

    public final void a(AbstractRunnableC0359Nw abstractRunnableC0359Nw) {
        abstractRunnableC0359Nw.d((C0385Ow) this);
        AbstractRunnableC0359Nw[] abstractRunnableC0359NwArr = this.a;
        AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = b;
        if (abstractRunnableC0359NwArr == null) {
            abstractRunnableC0359NwArr = new AbstractRunnableC0359Nw[4];
            this.a = abstractRunnableC0359NwArr;
        } else if (atomicIntegerFieldUpdater.get(this) >= abstractRunnableC0359NwArr.length) {
            abstractRunnableC0359NwArr = (AbstractRunnableC0359Nw[]) Arrays.copyOf(abstractRunnableC0359NwArr, atomicIntegerFieldUpdater.get(this) * 2);
            this.a = abstractRunnableC0359NwArr;
        }
        int i = atomicIntegerFieldUpdater.get(this);
        atomicIntegerFieldUpdater.set(this, i + 1);
        abstractRunnableC0359NwArr[i] = abstractRunnableC0359Nw;
        abstractRunnableC0359Nw.m = i;
        while (i > 0) {
            Object[] objArr = this.a;
            int i2 = (i - 1) / 2;
            if (objArr[i2].compareTo(objArr[i]) <= 0) {
                return;
            }
            c(i, i2);
            i = i2;
        }
    }

    public final AbstractRunnableC0359Nw b(int i) {
        Object[] objArr = this.a;
        AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = b;
        atomicIntegerFieldUpdater.set(this, atomicIntegerFieldUpdater.get(this) - 1);
        if (i < atomicIntegerFieldUpdater.get(this)) {
            c(i, atomicIntegerFieldUpdater.get(this));
            int i2 = (i - 1) / 2;
            if (i <= 0 || objArr[i].compareTo(objArr[i2]) >= 0) {
                while (true) {
                    int i3 = i * 2;
                    int i4 = i3 + 1;
                    if (i4 >= atomicIntegerFieldUpdater.get(this)) {
                        break;
                    }
                    Object[] objArr2 = this.a;
                    int i5 = i3 + 2;
                    if (i5 >= atomicIntegerFieldUpdater.get(this) || objArr2[i5].compareTo(objArr2[i4]) >= 0) {
                        i5 = i4;
                    }
                    if (objArr2[i].compareTo(objArr2[i5]) <= 0) {
                        break;
                    }
                    c(i, i5);
                    i = i5;
                }
            } else {
                c(i, i2);
                while (i2 > 0) {
                    Object[] objArr3 = this.a;
                    int i6 = (i2 - 1) / 2;
                    if (objArr3[i6].compareTo(objArr3[i2]) <= 0) {
                        break;
                    }
                    c(i2, i6);
                    i2 = i6;
                }
            }
        }
        AbstractRunnableC0359Nw abstractRunnableC0359Nw = objArr[atomicIntegerFieldUpdater.get(this)];
        abstractRunnableC0359Nw.d(null);
        abstractRunnableC0359Nw.m = -1;
        objArr[atomicIntegerFieldUpdater.get(this)] = null;
        return abstractRunnableC0359Nw;
    }

    public final void c(int i, int i2) {
        AbstractRunnableC0359Nw[] abstractRunnableC0359NwArr = this.a;
        AbstractRunnableC0359Nw abstractRunnableC0359Nw = abstractRunnableC0359NwArr[i2];
        AbstractRunnableC0359Nw abstractRunnableC0359Nw2 = abstractRunnableC0359NwArr[i];
        abstractRunnableC0359NwArr[i] = abstractRunnableC0359Nw;
        abstractRunnableC0359NwArr[i2] = abstractRunnableC0359Nw2;
        abstractRunnableC0359Nw.m = i;
        abstractRunnableC0359Nw2.m = i2;
    }
}
