Use LinkedHashMap in DynamicSynchableGroup so iteration order is preserved

This commit is contained in:
DBotThePony 2025-04-04 21:41:57 +07:00
parent d35da8c7f4
commit a54382b74e
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -190,7 +190,7 @@ class DynamicSynchableGroup<T : Any>(
private data class Slot<T : Any>(val value: T, val id: Int)
private val remoteStates = ArrayList<RemoteState>()
private val value2slot = HashMap<T, Slot<T>>()
private val value2slot = LinkedHashMap<T, Slot<T>>()
private val id2slot = Int2ObjectOpenHashMap<Slot<T>>()
private val idAllocator = IDAllocator()
@ -323,11 +323,7 @@ class DynamicSynchableGroup<T : Any>(
}
override fun remove(element: T): Boolean {
if (element !in value2slot) {
return false
}
val slot = value2slot.remove(element)!!
val slot = value2slot.remove(element) ?: return false
checkNotNull(id2slot.remove(slot.id))
remoteStates.forEach { it.remove(slot) }
idAllocator.release(slot.id)