package androidx.collection; import kotlin.collections.ArraysKt___ArraysJvmKt; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.SourceDebugExtension; @SourceDebugExtension({"SMAP\nCircularIntArray.kt\nKotlin\n*S Kotlin\n*F\n+ 1 CircularIntArray.kt\nandroidx/collection/CircularIntArray\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n+ 3 CollectionPlatformUtils.jvm.kt\nandroidx/collection/CollectionPlatformUtils\n*L\n1#1,213:1\n1#2:214\n26#3:215\n26#3:216\n26#3:217\n26#3:218\n26#3:219\n26#3:220\n26#3:221\n*S KotlinDebug\n*F\n+ 1 CircularIntArray.kt\nandroidx/collection/CircularIntArray\n*L\n100#1:215\n113#1:216\n139#1:217\n156#1:218\n169#1:219\n181#1:220\n193#1:221\n*E\n"}) /* loaded from: classes.dex */ public final class CircularIntArray { private int capacityBitmask; private int[] elements; private int head; private int tail; public CircularIntArray() { this(0, 1, null); } public final void clear() { this.tail = this.head; } public final boolean isEmpty() { return this.head == this.tail; } public final int size() { return (this.tail - this.head) & this.capacityBitmask; } public CircularIntArray(int i) { if (i < 1) { throw new IllegalArgumentException("capacity must be >= 1".toString()); } if (i > 1073741824) { throw new IllegalArgumentException("capacity must be <= 2^30".toString()); } i = Integer.bitCount(i) != 1 ? Integer.highestOneBit(i - 1) << 1 : i; this.capacityBitmask = i - 1; this.elements = new int[i]; } public /* synthetic */ CircularIntArray(int i, int i2, DefaultConstructorMarker defaultConstructorMarker) { this((i2 & 1) != 0 ? 8 : i); } private final void doubleCapacity() { int[] iArr = this.elements; int length = iArr.length; int i = this.head; int i2 = length - i; int i3 = length << 1; if (i3 < 0) { throw new RuntimeException("Max array capacity exceeded"); } int[] iArr2 = new int[i3]; ArraysKt___ArraysJvmKt.copyInto(iArr, iArr2, 0, i, length); ArraysKt___ArraysJvmKt.copyInto(this.elements, iArr2, i2, 0, this.head); this.elements = iArr2; this.head = 0; this.tail = length; this.capacityBitmask = i3 - 1; } public final void addFirst(int i) { int i2 = (this.head - 1) & this.capacityBitmask; this.head = i2; this.elements[i2] = i; if (i2 == this.tail) { doubleCapacity(); } } public final void addLast(int i) { int[] iArr = this.elements; int i2 = this.tail; iArr[i2] = i; int i3 = this.capacityBitmask & (i2 + 1); this.tail = i3; if (i3 == this.head) { doubleCapacity(); } } public final int popFirst() { int i = this.head; if (i == this.tail) { CollectionPlatformUtils collectionPlatformUtils = CollectionPlatformUtils.INSTANCE; throw new ArrayIndexOutOfBoundsException(); } int i2 = this.elements[i]; this.head = (i + 1) & this.capacityBitmask; return i2; } public final int popLast() { int i = this.head; int i2 = this.tail; if (i == i2) { CollectionPlatformUtils collectionPlatformUtils = CollectionPlatformUtils.INSTANCE; throw new ArrayIndexOutOfBoundsException(); } int i3 = this.capacityBitmask & (i2 - 1); int i4 = this.elements[i3]; this.tail = i3; return i4; } public final void removeFromStart(int i) { if (i <= 0) { return; } if (i > size()) { CollectionPlatformUtils collectionPlatformUtils = CollectionPlatformUtils.INSTANCE; throw new ArrayIndexOutOfBoundsException(); } this.head = this.capacityBitmask & (this.head + i); } public final void removeFromEnd(int i) { if (i <= 0) { return; } if (i > size()) { CollectionPlatformUtils collectionPlatformUtils = CollectionPlatformUtils.INSTANCE; throw new ArrayIndexOutOfBoundsException(); } this.tail = this.capacityBitmask & (this.tail - i); } public final int getFirst() { int i = this.head; if (i == this.tail) { CollectionPlatformUtils collectionPlatformUtils = CollectionPlatformUtils.INSTANCE; throw new ArrayIndexOutOfBoundsException(); } return this.elements[i]; } public final int getLast() { int i = this.head; int i2 = this.tail; if (i == i2) { CollectionPlatformUtils collectionPlatformUtils = CollectionPlatformUtils.INSTANCE; throw new ArrayIndexOutOfBoundsException(); } return this.elements[(i2 - 1) & this.capacityBitmask]; } public final int get(int i) { if (i < 0 || i >= size()) { CollectionPlatformUtils collectionPlatformUtils = CollectionPlatformUtils.INSTANCE; throw new ArrayIndexOutOfBoundsException(); } return this.elements[this.capacityBitmask & (this.head + i)]; } }