INNER CODE UNIT · Go

RemoveOverlap

benbusby/yeetfile · shared/utils.go:106

func RemoveOverlap[T comparable](source []T, remove []T) []T {
	// Create a map to store the elements to be removed for quick lookup
	toRemove := make(map[T]struct{}, len(remove))
	for _, item := range remove {
		toRemove[item] = struct{}{}
	}

	// Create a new slice to store the filtered elements
	var filtered []T
	for _, item := range source {
		if _, found := toRemove[item]; !found {
			filtered = append(filtered, item)
		}
	}

	return filtered
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…