package androidx.compose.runtime;

import androidx.compose.runtime.collection.MultiValueMap;
import java.util.ArrayList;
import java.util.List;
import n.C2566A;
import n.N;

/* JADX INFO: loaded from: classes.dex */
final class Pending {
    private int groupIndex;
    private final C2566A groupInfos;
    private final List<KeyInfo> keyInfos;
    private final w4.h keyMap$delegate;
    private final int startIndex;
    private final List<KeyInfo> usedKeys;

    public Pending(List<KeyInfo> list, int i6) {
        this.keyInfos = list;
        this.startIndex = i6;
        if (i6 < 0) {
            PreconditionsKt.throwIllegalArgumentException("Invalid start index");
        }
        this.usedKeys = new ArrayList();
        C2566A c2566a = new C2566A();
        int size = list.size();
        int nodes = 0;
        for (int i7 = 0; i7 < size; i7++) {
            KeyInfo keyInfo = this.keyInfos.get(i7);
            c2566a.i(keyInfo.getLocation(), new GroupInfo(i7, nodes, keyInfo.getNodes()));
            nodes += keyInfo.getNodes();
        }
        this.groupInfos = c2566a;
        this.keyMap$delegate = m1.g.k(new J4.a() { // from class: androidx.compose.runtime.Pending$keyMap$2
            @Override // J4.a
            public /* bridge */ /* synthetic */ Object invoke() {
                return MultiValueMap.m158boximpl(m39invokefVlnmYg());
            }

            /* JADX INFO: renamed from: invoke-fVlnmYg, reason: not valid java name */
            public final N m39invokefVlnmYg() {
                N nMultiMap = ComposerImplKt.multiMap(this.this$0.getKeyInfos().size());
                Pending pending = this.this$0;
                int size2 = pending.getKeyInfos().size();
                for (int i8 = 0; i8 < size2; i8++) {
                    KeyInfo keyInfo2 = pending.getKeyInfos().get(i8);
                    MultiValueMap.m157addimpl(nMultiMap, ComposerImplKt.getJoinedKey(keyInfo2), keyInfo2);
                }
                return nMultiMap;
            }
        });
    }

    public final int getGroupIndex() {
        return this.groupIndex;
    }

    public final List<KeyInfo> getKeyInfos() {
        return this.keyInfos;
    }

    /* JADX INFO: renamed from: getKeyMap-fVlnmYg, reason: not valid java name */
    public final N m38getKeyMapfVlnmYg() {
        return ((MultiValueMap) this.keyMap$delegate.getValue()).m176unboximpl();
    }

    public final KeyInfo getNext(int i6, Object obj) {
        return (KeyInfo) MultiValueMap.m171removeFirstimpl(m38getKeyMapfVlnmYg(), obj != null ? new JoinedKey(Integer.valueOf(i6), obj) : Integer.valueOf(i6));
    }

    public final int getStartIndex() {
        return this.startIndex;
    }

    public final List<KeyInfo> getUsed() {
        return this.usedKeys;
    }

    public final int nodePositionOf(KeyInfo keyInfo) {
        GroupInfo groupInfo = (GroupInfo) this.groupInfos.b(keyInfo.getLocation());
        if (groupInfo != null) {
            return groupInfo.getNodeIndex();
        }
        return -1;
    }

    public final boolean recordUsed(KeyInfo keyInfo) {
        return this.usedKeys.add(keyInfo);
    }

    public final void registerInsert(KeyInfo keyInfo, int i6) {
        this.groupInfos.i(keyInfo.getLocation(), new GroupInfo(-1, i6, 0));
    }

    public final void registerMoveNode(int i6, int i7, int i8) {
        char c6;
        long j4;
        char c7;
        long j6;
        char c8 = 7;
        long j7 = -9187201950435737472L;
        if (i6 > i7) {
            C2566A c2566a = this.groupInfos;
            Object[] objArr = c2566a.f21458c;
            long[] jArr = c2566a.f21456a;
            int length = jArr.length - 2;
            if (length < 0) {
                return;
            }
            int i9 = 0;
            while (true) {
                long j8 = jArr[i9];
                if ((((~j8) << c8) & j8 & j7) != j7) {
                    int i10 = 8 - ((~(i9 - length)) >>> 31);
                    int i11 = 0;
                    while (i11 < i10) {
                        if ((j8 & 255) < 128) {
                            c7 = c8;
                            GroupInfo groupInfo = (GroupInfo) objArr[(i9 << 3) + i11];
                            j6 = j7;
                            int nodeIndex = groupInfo.getNodeIndex();
                            if (i6 <= nodeIndex && nodeIndex < i6 + i8) {
                                groupInfo.setNodeIndex((nodeIndex - i6) + i7);
                            } else if (i7 <= nodeIndex && nodeIndex < i6) {
                                groupInfo.setNodeIndex(nodeIndex + i8);
                            }
                        } else {
                            c7 = c8;
                            j6 = j7;
                        }
                        j8 >>= 8;
                        i11++;
                        c8 = c7;
                        j7 = j6;
                    }
                    c6 = c8;
                    j4 = j7;
                    if (i10 != 8) {
                        return;
                    }
                } else {
                    c6 = c8;
                    j4 = j7;
                }
                if (i9 == length) {
                    return;
                }
                i9++;
                c8 = c6;
                j7 = j4;
            }
        } else {
            if (i7 <= i6) {
                return;
            }
            C2566A c2566a2 = this.groupInfos;
            Object[] objArr2 = c2566a2.f21458c;
            long[] jArr2 = c2566a2.f21456a;
            int length2 = jArr2.length - 2;
            if (length2 < 0) {
                return;
            }
            int i12 = 0;
            while (true) {
                long j9 = jArr2[i12];
                if ((((~j9) << 7) & j9 & (-9187201950435737472L)) != -9187201950435737472L) {
                    int i13 = 8 - ((~(i12 - length2)) >>> 31);
                    for (int i14 = 0; i14 < i13; i14++) {
                        if ((j9 & 255) < 128) {
                            GroupInfo groupInfo2 = (GroupInfo) objArr2[(i12 << 3) + i14];
                            int nodeIndex2 = groupInfo2.getNodeIndex();
                            if (i6 <= nodeIndex2 && nodeIndex2 < i6 + i8) {
                                groupInfo2.setNodeIndex((nodeIndex2 - i6) + i7);
                            } else if (i6 + 1 <= nodeIndex2 && nodeIndex2 < i7) {
                                groupInfo2.setNodeIndex(nodeIndex2 - i8);
                            }
                        }
                        j9 >>= 8;
                    }
                    if (i13 != 8) {
                        return;
                    }
                }
                if (i12 == length2) {
                    return;
                } else {
                    i12++;
                }
            }
        }
    }

    public final void registerMoveSlot(int i6, int i7) {
        char c6;
        long j4;
        char c7;
        long j6;
        char c8 = 7;
        long j7 = -9187201950435737472L;
        if (i6 > i7) {
            C2566A c2566a = this.groupInfos;
            Object[] objArr = c2566a.f21458c;
            long[] jArr = c2566a.f21456a;
            int length = jArr.length - 2;
            if (length < 0) {
                return;
            }
            int i8 = 0;
            while (true) {
                long j8 = jArr[i8];
                if ((((~j8) << c8) & j8 & j7) != j7) {
                    int i9 = 8 - ((~(i8 - length)) >>> 31);
                    int i10 = 0;
                    while (i10 < i9) {
                        if ((j8 & 255) < 128) {
                            c7 = c8;
                            GroupInfo groupInfo = (GroupInfo) objArr[(i8 << 3) + i10];
                            j6 = j7;
                            int slotIndex = groupInfo.getSlotIndex();
                            if (slotIndex == i6) {
                                groupInfo.setSlotIndex(i7);
                            } else if (i7 <= slotIndex && slotIndex < i6) {
                                groupInfo.setSlotIndex(slotIndex + 1);
                            }
                        } else {
                            c7 = c8;
                            j6 = j7;
                        }
                        j8 >>= 8;
                        i10++;
                        c8 = c7;
                        j7 = j6;
                    }
                    c6 = c8;
                    j4 = j7;
                    if (i9 != 8) {
                        return;
                    }
                } else {
                    c6 = c8;
                    j4 = j7;
                }
                if (i8 == length) {
                    return;
                }
                i8++;
                c8 = c6;
                j7 = j4;
            }
        } else {
            if (i7 <= i6) {
                return;
            }
            C2566A c2566a2 = this.groupInfos;
            Object[] objArr2 = c2566a2.f21458c;
            long[] jArr2 = c2566a2.f21456a;
            int length2 = jArr2.length - 2;
            if (length2 < 0) {
                return;
            }
            int i11 = 0;
            while (true) {
                long j9 = jArr2[i11];
                if ((((~j9) << 7) & j9 & (-9187201950435737472L)) != -9187201950435737472L) {
                    int i12 = 8 - ((~(i11 - length2)) >>> 31);
                    for (int i13 = 0; i13 < i12; i13++) {
                        if ((j9 & 255) < 128) {
                            GroupInfo groupInfo2 = (GroupInfo) objArr2[(i11 << 3) + i13];
                            int slotIndex2 = groupInfo2.getSlotIndex();
                            if (slotIndex2 == i6) {
                                groupInfo2.setSlotIndex(i7);
                            } else if (i6 + 1 <= slotIndex2 && slotIndex2 < i7) {
                                groupInfo2.setSlotIndex(slotIndex2 - 1);
                            }
                        }
                        j9 >>= 8;
                    }
                    if (i12 != 8) {
                        return;
                    }
                }
                if (i11 == length2) {
                    return;
                } else {
                    i11++;
                }
            }
        }
    }

    public final void setGroupIndex(int i6) {
        this.groupIndex = i6;
    }

    public final int slotPositionOf(KeyInfo keyInfo) {
        GroupInfo groupInfo = (GroupInfo) this.groupInfos.b(keyInfo.getLocation());
        if (groupInfo != null) {
            return groupInfo.getSlotIndex();
        }
        return -1;
    }

    public final boolean updateNodeCount(int i6, int i7) {
        int nodeIndex;
        GroupInfo groupInfo = (GroupInfo) this.groupInfos.b(i6);
        if (groupInfo == null) {
            return false;
        }
        int nodeIndex2 = groupInfo.getNodeIndex();
        int nodeCount = i7 - groupInfo.getNodeCount();
        groupInfo.setNodeCount(i7);
        if (nodeCount == 0) {
            return true;
        }
        C2566A c2566a = this.groupInfos;
        Object[] objArr = c2566a.f21458c;
        long[] jArr = c2566a.f21456a;
        int length = jArr.length - 2;
        if (length < 0) {
            return true;
        }
        int i8 = 0;
        while (true) {
            long j4 = jArr[i8];
            if ((((~j4) << 7) & j4 & (-9187201950435737472L)) != -9187201950435737472L) {
                int i9 = 8 - ((~(i8 - length)) >>> 31);
                for (int i10 = 0; i10 < i9; i10++) {
                    if ((255 & j4) < 128) {
                        GroupInfo groupInfo2 = (GroupInfo) objArr[(i8 << 3) + i10];
                        if (groupInfo2.getNodeIndex() >= nodeIndex2 && !groupInfo2.equals(groupInfo) && (nodeIndex = groupInfo2.getNodeIndex() + nodeCount) >= 0) {
                            groupInfo2.setNodeIndex(nodeIndex);
                        }
                    }
                    j4 >>= 8;
                }
                if (i9 != 8) {
                    return true;
                }
            }
            if (i8 == length) {
                return true;
            }
            i8++;
        }
    }

    public final int updatedNodeCountOf(KeyInfo keyInfo) {
        GroupInfo groupInfo = (GroupInfo) this.groupInfos.b(keyInfo.getLocation());
        return groupInfo != null ? groupInfo.getNodeCount() : keyInfo.getNodes();
    }
}
