MZ
Size: a a a
MZ
RI
data class ClassA(val fieldId: String)
data class ClassB(val fieldId: String)
fun merge(typeA: Collection<ClassA>, typeB: Collection<ClassB>): Map<ClassA, ClassB> {
// Assume that typeB big en ought, so constant lookup is more important
val lookupB = typeB.associateBy { it.fieldId }
return typeA.fold(mutableMapOf()) { acc, classA ->
lookupB[classA.fieldId]?.let {
acc.put(classA, it)
}
acc
}
}
MZ
MZ
RI
MZ
RI
MZ
RI
AN
VS
fun merge(typeA: Collection<ClassA>, typeB: Collection<ClassB>): Map<ClassA, ClassB> {
// Assume that typeB big en ought, so constant lookup is more important
val lookupB = typeB.associateBy { it.fieldId }
return typeA.asSequence()
.filter { it.fieldId in lookupB }
.associateWith { lookupB[it.fieldId]!! }
}
VS
MZ
AN
AN
MZ
MZ
AN
И
И