fixing list query diagnosis antrian
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user