func (s Set) Length() int {
	var count int
	for _, bucket := range s.vals {
		count = count + len(bucket)
	}
	return count
}
Length returns the number of values in the set.
package set
import (
	"sort"
)
func (s Set) Add(val interface{}) {
	hv := s.rules.Hash(val)
	if _, ok := s.vals[hv]; !ok {
		s.vals[hv] = make([]interface{}, 0, 1)
	}
	bucket := s.vals[hv]
	for _, ev := range bucket {
		if s.rules.Equivalent(val, ev) {
			return
		}
	}
	s.vals[hv] = append(bucket, val)
}
func (s Set) Remove(val interface{}) {
	hv := s.rules.Hash(val)
	bucket, ok := s.vals[hv]
	if !ok {
		return
	}
	for i, ev := range bucket {
		if s.rules.Equivalent(val, ev) {
			newBucket := make([]interface{}, 0, len(bucket)-1)
			newBucket = append(newBucket, bucket[:i]...)
			newBucket = append(newBucket, bucket[i+1:]...)
			if len(newBucket) > 0 {
				s.vals[hv] = newBucket
			} else {
				delete(s.vals, hv)
			}
			return
		}
	}
}
func (s Set) Has(val interface{}) bool {
	hv := s.rules.Hash(val)
	bucket, ok := s.vals[hv]
	if !ok {
		return false
	}
	for _, ev := range bucket {
		if s.rules.Equivalent(val, ev) {
			return true
		}
	}
	return false
}
func (s Set) Copy() Set {
	ret := NewSet(s.rules)
	for k, v := range s.vals {
		ret.vals[k] = v
	}
	return ret
}
func (s Set) Iterator() *Iterator {
	vals := s.Values()
	return &Iterator{
		vals: vals,
		idx:  -1,
	}
}
func (s Set) EachValue(cb func(interface{})) {
	it := s.Iterator()
	for it.Next() {
		cb(it.Value())
	}
}
func (s Set) Values() []interface{} {
	var ret []interface{}
	bucketIDs := make([]int, 0, len(s.vals))
	for id := range s.vals {
		bucketIDs = append(bucketIDs, id)
	}
	sort.Ints(bucketIDs)
	for _, bucketID := range bucketIDs {
		ret = append(ret, s.vals[bucketID]...)
	}
	if orderRules, ok := s.rules.(OrderedRules); ok {
		sort.SliceStable(ret, func(i, j int) bool {
			return orderRules.Less(ret[i], ret[j])
		})
	}
	return ret
}