implemented recursive dedupe and compile

This commit is contained in:
Hazel Noack
2025-10-07 13:05:52 +02:00
parent 6fd2478359
commit bd62068e09
4 changed files with 243 additions and 4 deletions

View File

@@ -37,3 +37,38 @@ type Source struct {
SourceType *SourceType
ObjectType ObjectType
}
func dedupeSources(inputSources []Source) []Source {
urlMapping := map[string]int{}
deduped := []Source{}
for _, source := range inputSources {
if mergeWithIndex, ok := urlMapping[source.Url]; ok {
// has to merge current source with source at index
if source.ObjectType != "" {
deduped[mergeWithIndex].ObjectType = source.ObjectType
}
if source.SourceType != nil {
deduped[mergeWithIndex].SourceType = source.SourceType
}
} else {
// just appending
urlMapping[source.Url] = len(deduped)
deduped = append(deduped, source)
}
}
return deduped
}
func sourceIndices(sources []Source) []string {
res := []string{}
for _, source := range sources {
res = append(res, "url"+source.Url)
}
return res
}