fix queue bug

This commit is contained in:
Boof2015
2026-07-13 02:33:48 -04:00
parent 261d095090
commit a485bdacd1
3 changed files with 116 additions and 47 deletions
+29
View File
@@ -2,6 +2,8 @@ export interface KeyedQueueEntry {
key: string;
}
export type QueueIndexByKey = Record<string, number>;
export interface QueueItemRemoveAction<T extends KeyedQueueEntry> {
absoluteIndex: number;
nextEntries: T[];
@@ -13,6 +15,33 @@ export interface SelectedQueueAction<T extends KeyedQueueEntry> {
entriesWithoutSelected: T[];
}
export function indexQueueEntriesByKey<T extends KeyedQueueEntry>(
entries: readonly T[]
): QueueIndexByKey {
const out: QueueIndexByKey = {};
entries.forEach((entry, index) => {
out[entry.key] = index;
});
return out;
}
export function moveQueueEntry<T>(entries: readonly T[], from: number, to: number): T[] {
const nextEntries = [...entries];
if (
from === to ||
from < 0 ||
to < 0 ||
from >= nextEntries.length ||
to >= nextEntries.length
) {
return nextEntries;
}
const [moved] = nextEntries.splice(from, 1);
nextEntries.splice(to, 0, moved);
return nextEntries;
}
export function removeQueueEntryAt<T extends KeyedQueueEntry>(
entries: readonly T[],
localIndex: number,