diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-05-04 22:30:59 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-05-04 22:30:59 +0200 |
commit | 223d1d5ba445c38c287da43c0599d2b2b03ecd87 (patch) | |
tree | b8bdceec560f08136d585b918b57f64715107990 | |
parent | 74667c6b466932daeddb2ab66131dfae1a74cb97 (diff) | |
download | refcat-223d1d5ba445c38c287da43c0599d2b2b03ecd87.tar.gz refcat-223d1d5ba445c38c287da43c0599d2b2b03ecd87.zip |
set: some tweaks
-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 |