mirror of
https://github.com/jimeh/rbheap.git
synced 2026-02-19 12:56:46 +00:00
29 lines
514 B
Go
29 lines
514 B
Go
package main
|
|
|
|
// DiffSect removes all items in `a` from `b`, then removes all items from `b`
|
|
// which are not in `c`. Effectively: intersect(difference(b, a), c)
|
|
func DiffSect(a, b, c *[]string) *[]string {
|
|
result := []string{}
|
|
mapA := map[string]bool{}
|
|
mapC := map[string]bool{}
|
|
|
|
for _, x := range *a {
|
|
mapA[x] = true
|
|
}
|
|
|
|
for _, x := range *c {
|
|
mapC[x] = true
|
|
}
|
|
|
|
for _, x := range *b {
|
|
_, okA := mapA[x]
|
|
_, okC := mapC[x]
|
|
|
|
if !okA && okC {
|
|
result = append(result, x)
|
|
}
|
|
}
|
|
|
|
return &result
|
|
}
|