fixing list query diagnosis antrian

This commit is contained in:
renaldybrada
2026-02-04 13:12:06 +07:00
parent c50c5f9d9e
commit 354a3b8561
4 changed files with 86 additions and 24 deletions
+21
View File
@@ -0,0 +1,21 @@
package shared
func MapChildToParent[P any, C any, K comparable](
parents []P,
children []C,
parentKey func(*P) K,
childKey func(C) K,
attach func(*P, C),
) {
index := make(map[K]*P)
for i := range parents {
index[parentKey(&parents[i])] = &parents[i]
}
for _, c := range children {
if p, ok := index[childKey(c)]; ok {
attach(p, c)
}
}
}