MCPcopy Create free account
hub / github.com/github/gh-aw / MergeUnique

Function MergeUnique

pkg/sliceutil/sliceutil.go:94–118  ·  view source on GitHub ↗

MergeUnique returns a deduplicated slice that starts with base and appends any items from extra that are not already present in base. Order is preserved.

(base []T, extra ...T)

Source from the content-addressed store, hash-verified

92// MergeUnique returns a deduplicated slice that starts with base and appends any
93// items from extra that are not already present in base. Order is preserved.
94func MergeUnique[T comparable](base []T, extra ...T) []T {
95 capacity := len(base)
96 if len(extra) <= int(^uint(0)>>1)-capacity {
97 capacity += len(extra)
98 }
99
100 seen := make(map[T]struct{}, capacity)
101 result := make([]T, 0, capacity)
102 for _, item := range base {
103 if _, exists := seen[item]; !exists {
104 seen[item] = struct{}{}
105 result = append(result, item)
106 }
107 }
108 for _, item := range extra {
109 if _, exists := seen[item]; !exists {
110 seen[item] = struct{}{}
111 result = append(result, item)
112 }
113 }
114 if sliceutilLog.Enabled() {
115 sliceutilLog.Printf("MergeUnique: base=%d extra=%d result=%d", len(base), len(extra), len(result))
116 }
117 return result
118}
119
120// Exclude returns a new slice containing the items from base that do not appear
121// in the exclude set. Order of remaining items is preserved.

Callers 15

TestAddUniqueWorkflowFunction · 0.92
buildMissingToolsSummaryFunction · 0.92
buildMissingDataSummaryFunction · 0.92
buildMCPFailuresSummaryFunction · 0.92
mergeUniqueLoggedFunction · 0.92
mergeEventConfigFunction · 0.92
appendCacheMemoryToolsFunction · 0.92
MergeSafeOutputsMethod · 0.92
mergeSafeOutputConfigFunction · 0.92

Calls 2

EnabledMethod · 0.45
PrintfMethod · 0.45

Tested by 4

TestAddUniqueWorkflowFunction · 0.74
TestMergeUniqueFunction · 0.68