set

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

README

set: Mathematical sets and their operations.

set.OSet[K] Ordered set based off a btree.

- #### set.Hset[K] Unordered set based off a hashamp.

Documentation

Index

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]) Clone

func (s HSet[T]) Clone() HSet[T]

Clone returns a new set with a shallow copy of each of the keys.

func (HSet[T]) Complement

func (s HSet[T]) Complement(q HSet[T]) (c HSet[T])

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[K]) Contains

func (s HSet[K]) Contains(k K) bool

func (HSet[T]) Difference

func (s HSet[T]) Difference(q HSet[T]) (d HSet[T])

Difference(S, Q) 'S-Q' returns a new Set with the keys in S but not Q.

func (HSet[T]) Equal

func (s HSet[T]) Equal(q HSet[T]) bool

Equal (S==Q) iff S and Q contain exactly the same keys.

func (HSet[K]) Insert

func (s HSet[K]) Insert(k K)

func (HSet[T]) Intersection

func (s HSet[T]) Intersection(q HSet[T]) (is HSet[T])

Intersection (A ∩ B) returns a new set containing the keys that are in both a and b.

func (HSet[K]) Len

func (s HSet[K]) Len() int

func (HSet[K]) Remove

func (s HSet[K]) Remove(k K)

func (HSet[K]) String

func (s HSet[K]) String() 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.

func (HSet[T]) Union

func (s HSet[T]) Union(q HSet[T]) (u HSet[T])

Union of S and Q (S ∪ Q) returns a new set with the keys of both S and Q.

func (HSet[K]) With

func (s HSet[K]) With(k K) HSet[K]

With Inserts a key K, returning the same set.

func (HSet[K]) WithKeys

func (s HSet[K]) WithKeys(keys ...K) HSet[K]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL