diff options
Diffstat (limited to 'skate/set')
-rw-r--r-- | skate/set/set.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/skate/set/set.go b/skate/set/set.go index 29cd3ef..b762cb8 100644 --- a/skate/set/set.go +++ b/skate/set/set.go @@ -76,11 +76,11 @@ func (s Set) Intersection(t Set) Set { // Union returns the union of two sets. func (s Set) Union(t Set) Set { u := New() - for _, v := range s.Slice() { - u.Add(v) + for k := range s { + u.Add(k) } - for _, v := range t.Slice() { - u.Add(v) + for k := range t { + u.Add(k) } return u } @@ -102,7 +102,7 @@ func (s Set) Sorted() (result []string) { return } -// TopK returns at most k elements. +// TopK returns at most k sorted elements. func (s Set) TopK(k int) Set { var top []string for i, v := range s.Sorted() { @@ -113,7 +113,7 @@ func (s Set) TopK(k int) Set { return FromSlice(top) } -// Product returns a slice of pairs, representing the cartesian product. +// Product returns a slice of pairs, representing the cartesian product of two sets. func (s Set) Product(t Set) (result [][]string) { for k := range s { for l := range t { @@ -123,7 +123,8 @@ func (s Set) Product(t Set) (result [][]string) { return } -// Jaccard returns the jaccard index of sets s and t. +// Jaccard returns the jaccard index of sets s and t, between 0 and 1, where 1 +// means equality. func (s Set) Jaccard(t Set) float64 { if s.IsEmpty() && t.IsEmpty() { return 1 |