File: collection.go

package info (click to toggle)
aws-nuke 2.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,852 kB
  • sloc: makefile: 17; sh: 1
file content (50 lines) | stat: -rw-r--r-- 745 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package types

type Collection []string

func (c Collection) Intersect(o Collection) Collection {
	mo := o.toMap()

	result := Collection{}
	for _, t := range c {
		if mo[t] {
			result = append(result, t)
		}
	}

	return result
}

func (c Collection) Remove(o Collection) Collection {
	mo := o.toMap()

	result := Collection{}
	for _, t := range c {
		if !mo[t] {
			result = append(result, t)
		}
	}

	return result
}

func (c Collection) Union(o Collection) Collection {
	ms := c.toMap()

	result := []string(c)
	for _, oi := range o {
		if !ms[oi] {
			result = append(result, oi)
		}
	}

	return Collection(result)
}

func (c Collection) toMap() map[string]bool {
	m := map[string]bool{}
	for _, t := range c {
		m[t] = true
	}
	return m
}