package j1;

/* loaded from: classes.dex */
public final class m {

    /* renamed from: a, reason: collision with root package name */
    private int f23500a;

    /* renamed from: b, reason: collision with root package name */
    private int[] f23501b = new int[16];

    /* renamed from: c, reason: collision with root package name */
    private int[] f23502c = new int[16];

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

    /* renamed from: e, reason: collision with root package name */
    private int f23504e;

    public m() {
        int[] iArr = new int[16];
        int i10 = 0;
        while (i10 < 16) {
            int i11 = i10 + 1;
            iArr[i10] = i11;
            i10 = i11;
        }
        this.f23503d = iArr;
    }

    private final int b() {
        int length = this.f23503d.length;
        if (this.f23504e >= length) {
            int i10 = length * 2;
            int[] iArr = new int[i10];
            int i11 = 0;
            while (i11 < i10) {
                int i12 = i11 + 1;
                iArr[i11] = i12;
                i11 = i12;
            }
            sm.o.o(this.f23503d, iArr, 0, 0, 0, 14, null);
            this.f23503d = iArr;
        }
        int i13 = this.f23504e;
        this.f23504e = this.f23503d[i13];
        return i13;
    }

    private final void c(int i10) {
        int[] iArr = this.f23501b;
        int length = iArr.length;
        if (i10 <= length) {
            return;
        }
        int i11 = length * 2;
        int[] iArr2 = new int[i11];
        int[] iArr3 = new int[i11];
        sm.o.o(iArr, iArr2, 0, 0, 0, 14, null);
        sm.o.o(this.f23502c, iArr3, 0, 0, 0, 14, null);
        this.f23501b = iArr2;
        this.f23502c = iArr3;
    }

    private final void d(int i10) {
        this.f23503d[i10] = this.f23504e;
        this.f23504e = i10;
    }

    private final void g(int i10) {
        int i11;
        int[] iArr = this.f23501b;
        int i12 = this.f23500a >> 1;
        while (i10 < i12) {
            int i13 = (i10 + 1) << 1;
            int i14 = i13 - 1;
            if (i13 >= this.f23500a || (i11 = iArr[i13]) >= iArr[i14]) {
                if (iArr[i14] >= iArr[i10]) {
                    return;
                }
                i(i14, i10);
                i10 = i14;
            } else {
                if (i11 >= iArr[i10]) {
                    return;
                }
                i(i13, i10);
                i10 = i13;
            }
        }
    }

    private final void h(int i10) {
        int[] iArr = this.f23501b;
        int i11 = iArr[i10];
        while (i10 > 0) {
            int i12 = ((i10 + 1) >> 1) - 1;
            if (iArr[i12] <= i11) {
                return;
            }
            i(i12, i10);
            i10 = i12;
        }
    }

    private final void i(int i10, int i11) {
        int[] iArr = this.f23501b;
        int[] iArr2 = this.f23502c;
        int[] iArr3 = this.f23503d;
        int i12 = iArr[i10];
        iArr[i10] = iArr[i11];
        iArr[i11] = i12;
        int i13 = iArr2[i10];
        iArr2[i10] = iArr2[i11];
        iArr2[i11] = i13;
        iArr3[iArr2[i10]] = i10;
        iArr3[iArr2[i11]] = i11;
    }

    public final int a(int i10) {
        c(this.f23500a + 1);
        int i11 = this.f23500a;
        this.f23500a = i11 + 1;
        int b10 = b();
        this.f23501b[i11] = i10;
        this.f23502c[i11] = b10;
        this.f23503d[b10] = i11;
        h(i11);
        return b10;
    }

    public final int e(int i10) {
        return this.f23500a > 0 ? this.f23501b[0] : i10;
    }

    public final void f(int i10) {
        int i11 = this.f23503d[i10];
        i(i11, this.f23500a - 1);
        this.f23500a--;
        h(i11);
        g(i11);
        d(i10);
    }
}
