Sets

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComparableSet

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

ComparableSet is a set that uses the == operator to compare elements.

func NewComparableSet

func NewComparableSet[T comparable](elems []T) *ComparableSet[T]

NewComparableSet creates a new ComparableSet.

Parameters:

  • elems: The elements to add to the set.

Returns:

  • *ComparableSet[T]: A new ComparableSet.

Behaviors:

  • It ignores duplicate elements.

func (*ComparableSet[T]) Add

func (s *ComparableSet[T]) Add(elem T)

Add adds an element to the set.

Parameters:

  • elem: The element to add.

Behaviors:

  • If the element is already in the set, the function does nothing.

func (*ComparableSet[T]) Clear

func (s *ComparableSet[T]) Clear()

Clear removes all elements from the set.

func (*ComparableSet[T]) Copy

func (s *ComparableSet[T]) Copy() uc.Copier

Copy returns a copy of the set.

Returns:

  • *ComparableSet[T]: A copy of the set.

func (*ComparableSet[T]) Difference

func (s *ComparableSet[T]) Difference(other *ComparableSet[T]) *ComparableSet[T]

Difference returns the difference of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *ComparableSet[T]: The difference of the set with the other set.

func (*ComparableSet[T]) Equals

func (s *ComparableSet[T]) Equals(other uc.Equaler) bool

Equals checks if the set is equal to another set.

Parameters:

  • other: The other set to compare.

Returns:

  • bool: True if the sets are equal, false otherwise.

func (*ComparableSet[T]) HasElem

func (s *ComparableSet[T]) HasElem(elem T) bool

HasElem checks if the set has the element.

Parameters:

  • elem: The element to check.

Returns:

  • bool: True if the set has the element, false otherwise.

func (*ComparableSet[T]) Intersection

func (s *ComparableSet[T]) Intersection(other *ComparableSet[T]) *ComparableSet[T]

Intersection returns the intersection of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *ComparableSet[T]: The intersection of the set with the other set.

func (*ComparableSet[T]) IsEmpty

func (s *ComparableSet[T]) IsEmpty() bool

IsEmpty checks if the set is empty.

Returns:

  • bool: True if the set is empty, false otherwise.

func (*ComparableSet[T]) IsSubset

func (s *ComparableSet[T]) IsSubset(other *ComparableSet[T]) bool

IsSubset checks if the set is a subset of another set.

Parameters:

  • other: The other set to check.

Returns:

  • bool: True if the set is a subset of the other set, false otherwise.

func (*ComparableSet[T]) Iterator

func (s *ComparableSet[T]) Iterator() uc.Iterater[T]

Iterator returns an iterator for the set.

Returns:

  • uc.Iterater[T]: An iterator for the set.

func (*ComparableSet[T]) Remove

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

Remove removes an element from the set.

Parameters:

  • elem: The element to remove.

Behaviors:

  • If the element is not in the set, the function does nothing.

func (*ComparableSet[T]) Size

func (s *ComparableSet[T]) Size() int

Size returns the number of elements in the set.

Returns:

  • int: The number of elements in the set.

func (*ComparableSet[T]) Slice

func (s *ComparableSet[T]) Slice() []T

Slice returns a slice of the elements in the set.

Returns:

  • []T: A slice of the elements in the set.

func (*ComparableSet[T]) String

func (s *ComparableSet[T]) String() string

String returns a string representation of the set.

Returns:

  • string: The string representation of the set.

func (*ComparableSet[T]) SymmetricDifference

func (s *ComparableSet[T]) SymmetricDifference(other *ComparableSet[T]) *ComparableSet[T]

SymmetricDifference returns the symmetric difference of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *ComparableSet[T]: The symmetric difference of the set with the other set.

func (*ComparableSet[T]) Union

func (s *ComparableSet[T]) Union(other *ComparableSet[T]) *ComparableSet[T]

Union returns the union of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *ComparableSet[T]: The union of the set with the other set.

type EqualSet

type EqualSet[T uc.Objecter] struct {
	// contains filtered or unexported fields
}

EqualSet is a set that uses the Equals method to compare elements.

func NewEqualSet

func NewEqualSet[T uc.Objecter](elems []T) *EqualSet[T]

NewEqualSet creates a new EqualSet.

Returns:

  • *EqualSet: A new EqualSet.

func (*EqualSet[T]) Add

func (s *EqualSet[T]) Add(elem T)

Add adds an element to the set.

Parameters:

  • elem: The element to add.

Behaviors:

  • If the element is already in the set, the function does nothing.

func (*EqualSet[T]) Clear

func (s *EqualSet[T]) Clear()

Clear removes all elements from the set.

func (*EqualSet[T]) Copy

func (s *EqualSet[T]) Copy() uc.Copier

Copy returns a copy of the set.

Returns:

  • *EqualSet[T]: A copy of the set.

func (*EqualSet[T]) Difference

func (s *EqualSet[T]) Difference(other *EqualSet[T]) *EqualSet[T]

Difference returns the difference of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *EqualSet[T]: The difference of the set with the other set.

func (*EqualSet[T]) Equals

func (s *EqualSet[T]) Equals(other uc.Equaler) bool

Equals checks if the set is equal to another set.

Parameters:

  • other: The other set to compare.

Returns:

  • bool: True if the sets are equal, false otherwise.

func (*EqualSet[T]) HasElem

func (s *EqualSet[T]) HasElem(elem T) bool

HasElem checks if the set has the element.

Parameters:

  • elem: The element to check.

Returns:

  • bool: True if the set has the element, false otherwise.

func (*EqualSet[T]) Intersection

func (s *EqualSet[T]) Intersection(other *EqualSet[T]) *EqualSet[T]

Intersection returns the intersection of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *EqualSet[T]: The intersection of the set with the other set.

func (*EqualSet[T]) IsEmpty

func (s *EqualSet[T]) IsEmpty() bool

IsEmpty checks if the set is empty.

Returns:

  • bool: True if the set is empty, false otherwise.

func (*EqualSet[T]) IsSubset

func (s *EqualSet[T]) IsSubset(other *EqualSet[T]) bool

IsSubset checks if the set is a subset of another set.

Parameters:

  • other: The other set to check.

Returns:

  • bool: True if the set is a subset of the other set, false otherwise.

func (*EqualSet[T]) Iterator

func (s *EqualSet[T]) Iterator() uc.Iterater[T]

Iterator returns an iterator for the set.

Returns:

  • uc.Iterater[T]: An iterator for the set.

func (*EqualSet[T]) Remove

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

Remove removes an element from the set.

Parameters:

  • elem: The element to remove.

Behaviors:

  • If the element is not in the set, the function does nothing.

func (*EqualSet[T]) Size

func (s *EqualSet[T]) Size() int

Size returns the number of elements in the set.

Returns:

  • int: The number of elements in the set.

func (*EqualSet[T]) Slice added in v0.3.32

func (s *EqualSet[T]) Slice() []T

slice returns a slice of the elements in the set.

Returns:

  • []T: A slice of the elements in the set.

func (*EqualSet[T]) String

func (s *EqualSet[T]) String() string

String returns a string representation of the set.

Returns:

  • string: The string representation of the set.

func (*EqualSet[T]) SymmetricDifference

func (s *EqualSet[T]) SymmetricDifference(other *EqualSet[T]) *EqualSet[T]

SymmetricDifference returns the symmetric difference of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *EqualSet[T]: The symmetric difference of the set with the other set.

func (*EqualSet[T]) Union

func (s *EqualSet[T]) Union(other *EqualSet[T]) *EqualSet[T]

Union returns the union of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *EqualSet[T]: The union of the set with the other set.

type LessSet

type LessSet[T any] struct {
	// contains filtered or unexported fields
}

LessSet is a set that uses the Equals method to compare elements.

func NewLessSet

func NewLessSet[T any](elems []T, sf uts.SortFunc[T]) *LessSet[T]

NewLessSet creates a new LessSet.

Parameters:

  • elems: The elements to add to the set.
  • sf: The sort function to use.

Returns:

  • *LessSet: A new LessSet.

Behaviors:

  • If the sort function is nil, the function returns nil.

func (*LessSet[T]) Add

func (s *LessSet[T]) Add(elem T)

Add adds an element to the set.

Parameters:

  • elem: The element to add.

Behaviors:

  • If the element is already in the set, the function does nothing.

func (*LessSet[T]) Clear

func (s *LessSet[T]) Clear()

Clear removes all elements from the set.

func (*LessSet[T]) Copy

func (s *LessSet[T]) Copy() uc.Copier

Copy returns a copy of the set.

Returns:

  • *LessSet[T]: A copy of the set.

func (*LessSet[T]) Difference

func (s *LessSet[T]) Difference(other *LessSet[T]) *LessSet[T]

Difference returns the difference of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *LessSet[T]: The difference of the set with the other set.

func (*LessSet[T]) Equals

func (s *LessSet[T]) Equals(other uc.Equaler) bool

Equals checks if the set is equal to another set.

Parameters:

  • other: The other set to compare.

Returns:

  • bool: True if the sets are equal, false otherwise.

func (*LessSet[T]) Find

func (s *LessSet[T]) Find(elem T) (int, bool)

Find finds an element in the set.

Parameters:

  • elem: The element to find.

Returns:

  • int: The index of the element in the set.
  • bool: True if the element is in the set, false otherwise.

func (*LessSet[T]) HasElem

func (s *LessSet[T]) HasElem(elem T) bool

HasElem checks if the set has the element.

Parameters:

  • elem: The element to check.

Returns:

  • bool: True if the set has the element, false otherwise.

func (*LessSet[T]) Intersection

func (s *LessSet[T]) Intersection(other *LessSet[T]) *LessSet[T]

Intersection returns the intersection of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *LessSet[T]: The intersection of the set with the other set.

func (*LessSet[T]) IsEmpty

func (s *LessSet[T]) IsEmpty() bool

IsEmpty checks if the set is empty.

Returns:

  • bool: True if the set is empty, false otherwise.

func (*LessSet[T]) IsSubset

func (s *LessSet[T]) IsSubset(other *LessSet[T]) bool

IsSubset checks if the set is a subset of another set.

Parameters:

  • other: The other set to check.

Returns:

  • bool: True if the set is a subset of the other set, false otherwise.

func (*LessSet[T]) Iterator

func (s *LessSet[T]) Iterator() uc.Iterater[T]

Iterator returns an iterator for the set.

Returns:

  • uc.Iterater[T]: An iterator for the set.

func (*LessSet[T]) Remove

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

Remove removes an element from the set.

Parameters:

  • elem: The element to remove.

Behaviors:

  • If the element is not in the set, the function does nothing.

func (*LessSet[T]) Size

func (s *LessSet[T]) Size() int

Size returns the number of elements in the set.

Returns:

  • int: The number of elements in the set.

func (*LessSet[T]) Slice

func (s *LessSet[T]) Slice() []T

Slice returns a slice of the elements in the set.

Returns:

  • []T: A slice of the elements in the set.

func (*LessSet[T]) String

func (s *LessSet[T]) String() string

String returns a string representation of the set.

Returns:

  • string: The string representation of the set.

func (*LessSet[T]) SymmetricDifference

func (s *LessSet[T]) SymmetricDifference(other *LessSet[T]) *LessSet[T]

SymmetricDifference returns the symmetric difference of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *LessSet[T]: The symmetric difference of the set with the other set.

func (*LessSet[T]) Union

func (s *LessSet[T]) Union(other *LessSet[T]) *LessSet[T]

Union returns the union of the set with another set.

Parameters:

  • other: The other set.

Returns:

  • *LessSet[T]: The union of the set with the other set.

type Seter

type Seter[T any] interface {
	// IsEmpty checks if the set is empty.
	//
	// Returns:
	//  - bool: True if the set is empty, false otherwise.
	IsEmpty() bool

	// Size returns the number of elements in the set.
	//
	// Returns:
	//  - int: The number of elements in the set.
	Size() int

	// HasElem checks if the set has the element.
	//
	// Parameters:
	//  - elem: The element to check.
	//
	// Returns:
	//  - bool: True if the set has the element, false otherwise.
	HasElem(elem T) bool

	// Add adds an element to the set.
	//
	// Parameters:
	//  - elem: The element to add.
	//
	// Behaviors:
	//  - If the element is already in the set, the function does nothing.
	Add(elem T)

	// Remove removes an element from the set.
	//
	// Parameters:
	//  - elem: The element to remove.
	//
	// Behaviors:
	//  - If the element is not in the set, the function does nothing.
	Remove(elem T)

	// Union returns the union of the set with another set.
	//
	// Parameters:
	//  - other: The other set.
	//
	// Returns:
	//  - Seter[T]: The union of the set with the other set.
	Union(other Seter[T]) Seter[T]

	// Intersection returns the intersection of the set with another set.
	//
	// Parameters:
	//  - other: The other set.
	//
	// Returns:
	//  - Seter[T]: The intersection of the set with the other set.
	Intersection(other Seter[T]) Seter[T]

	// Difference returns the difference of the set with another set.
	//
	// Parameters:
	//  - other: The other set.
	//
	// Returns:
	//  - Seter[T]: The difference of the set with the other set.
	Difference(other Seter[T]) Seter[T]

	// SymmetricDifference returns the symmetric difference of the set with another set.
	//
	// Parameters:
	//  - other: The other set.
	//
	// Returns:
	//  - Seter[T]: The symmetric difference of the set with the other set.
	SymmetricDifference(other Seter[T]) Seter[T]

	// IsSubset checks if the set is a subset of another set.
	//
	// Parameters:
	//  - other: The other set.
	//
	// Returns:
	//  - bool: True if the set is a subset of the other set, false otherwise.
	IsSubset(other Seter[T]) bool

	// Clear removes all elements from the set.
	Clear()

	fmt.Stringer
	uc.Objecter
	uc.Slicer[T]
}

Seter is an interface for a set.

Jump to

Keyboard shortcuts

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