lset

package
v0.0.0-...-157c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Multi

type Multi[T comparable] []*Set[T]

Multi combines multiple sets and treats them as a single set

func NewMulti

func NewMulti[T comparable](ts ...*Set[T]) Multi[T]

NewMulti is a helper that infers type when creating a Multi

func (Multi[T]) AllContain

func (m Multi[T]) AllContain(t T) bool

AllContain returns true if every Set in Multi contains t. The slice is checked in order under the assumption that the slice is sorted from smallest to largest.

func (Multi[T]) Contains

func (m Multi[T]) Contains(t T) bool

Contains returns true if any Set in Multi contains t. The slice is checked in reverse order under the assumption that the slice is sorted from smallest to largest.

func (Multi[T]) Intersection

func (m Multi[T]) Intersection() *Set[T]

Intersection returns a set containing any value present in all sets.

func (Multi[T]) Sort

func (m Multi[T]) Sort()

Sort Multi from smallest to largest. This order is assumend for optimization of other methods, but is not necessary.

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set can contain values

func New

func New[T comparable](elements ...T) *Set[T]

New creates a set containing the provided values.

func (*Set[T]) Add

func (s *Set[T]) Add(elements ...T)

Add given elements to the set

func (*Set[T]) AddAll

func (s *Set[T]) AddAll(set *Set[T])

AddAll elements of another set to this set

func (*Set[T]) Contains

func (s *Set[T]) Contains(elem T) bool

Contains return true if elem is in the set

func (*Set[T]) Copy

func (s *Set[T]) Copy() *Set[T]

Copy the set

func (*Set[T]) Each

func (s *Set[T]) Each(fn func(T) (done bool))

Each calls fn for each element in the set. This avoids the allocation of creating a slice when iterating over the values.

func (*Set[T]) Len

func (s *Set[T]) Len() int

Len of the set

func (*Set[T]) Remove

func (s *Set[T]) Remove(elem T)

Remove elem from the set

func (*Set[T]) Slice

func (s *Set[T]) Slice() slice.Slice[T]

Slice returns the values in the set as a slice

Jump to

Keyboard shortcuts

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