Documentation ¶
Index ¶
- type HSet
- func (s HSet[K]) AsSlice() []K
- func (s HSet[T]) Clone() HSet[T]
- func (s HSet[T]) Complement(q HSet[T]) (c HSet[T])
- func (s HSet[K]) Contains(k K) bool
- func (s HSet[T]) Difference(q HSet[T]) (d HSet[T])
- func (s HSet[T]) Equal(q HSet[T]) bool
- func (s HSet[K]) Insert(k K)
- func (s HSet[T]) Intersection(q HSet[T]) (is HSet[T])
- func (s HSet[K]) Len() int
- func (s HSet[K]) Remove(k K)
- func (s HSet[K]) String() string
- func (s HSet[T]) Union(q HSet[T]) (u HSet[T])
- func (s HSet[K]) With(k K) HSet[K]
- func (s HSet[K]) WithKeys(keys ...K) HSet[K]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HSet ¶
type HSet[K comparable] map[K]struct{}
HSet is a non-concurrency-safe set backed by a map[T]bool. The set must be initialized before use, either via make(HSet) or New[Hset[K]]
func (HSet[K]) AsSlice ¶
func (s HSet[K]) AsSlice() []K
Keys returns a slice of the keys of S. No order is guaranteed.
func (HSet[T]) Complement ¶
Complement (S ∆ Q, sometimes called 'symmetric difference') returns a new set containing the keys that in S xor Q.
fmt.Println(Complement[int](New[int](1, 2), New[int](2,3))) Output: true
func (HSet[T]) Difference ¶
Difference(S, Q) 'S-Q' returns a new Set with the keys in S but not Q.
func (HSet[T]) Intersection ¶
Intersection (A ∩ B) returns a new set containing the keys that are in both a and b.
func (HSet[K]) String ¶
String() returns "{k0, k1, k2}"... where ki is the ith key formatted as though with "%v". The keys are always returned in a consistent order. The sort rules are those used by the stdlib's internal/fmtsort:
- when applicable, nil compares low
- ints, floats, and strings order by <
- NaN compares less than non-NaN floats
- bool compares false before true
- complex compares real, then imag
- pointers compare by machine address
- channel values compare by machine address
- structs compare each field in turn
- arrays compare each element in turn; otherwise identical arrays compare by length.
- interface values compare first by reflect.Type describing the concrete type; and then by concrete value as described in the previous rules.