Util

util functions

// todo

DS

set:

ref: golang-set

sub := Util.NewSet[int]()
sub.Add(1)
sub.Add(2)
sub.Add(3)

sup := sub.Clone()

fmt.Println("s is subset of sup:", sub.IsSubOf(sup))
fmt.Println("s is proper subset of sup:", sub.IsProperSubOf(sup))
sup.Add(4)
fmt.Println("s is subset of sup:", sub.IsSubOf(sup))
fmt.Println("s is proper subset of sup:", sub.IsProperSubOf(sup))

fmt.Println("to slice:", sub.ToSlice())
fmt.Println("items:", sub.Items())

fmt.Println("sup contains sub:", sup.ContainsAll(sub.Items()...))
fmt.Println("sub contains sup:", sub.ContainsAll(sup.Items()...))

fmt.Println("diff:", sup.Diff(sub))

// Output:
s is subset of sup: true
s is proper subset of sup: false
s is subset of sup: true
s is proper subset of sup: true
to slice: [1 2 3]
items: [1 2 3]
sup contains sub: true
sub contains sup: false
diff: set[4]

pair:

最后更新于

这有帮助吗?