container

package
v1.4.4-alpha1202-diff-... Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContainerExports = map[string]interface{}{
	"NewSet":        NewSet,
	"NewUnsafeSet":  NewUnsafeSet,
	"NewLinkedList": NewLinkedList,
}

Functions

This section is empty.

Types

type LinkedList

type LinkedList struct {
	*list.List
}

func NewLinkedList

func NewLinkedList() *LinkedList

func (*LinkedList) ToSlice

func (l *LinkedList) ToSlice() []any

type Set

type Set struct {
	mapset.Set[any]
}

func NewSet

func NewSet(vals ...any) (s *Set)

NewSet creates a new set Example: ``` s = container.NewSet("1", "2") ```

func NewUnsafeSet

func NewUnsafeSet(vals ...any) (s *Set)

NewUnsafeSet creates a new set that is not thread-safe Example: ``` s = container.NewUnsafeSet("1", "2") ```

func (*Set) Add

func (s *Set) Add(val any) bool

Add add an element to set Example: ``` s = container.NewSet() assert s.Add("1") == true ```

func (*Set) Append

func (s *Set) Append(vals ...any) int

Append add multiple elements to set Example: ``` assert s.Append("1", "2", "3") == 3 ```

func (*Set) Cap

func (s *Set) Cap() int

Cap returns the number of elements in the set, same as Len Example: ``` s = container.NewSet("1", "2") assert s.Cap() == 2 ```

func (*Set) Cardinality

func (s *Set) Cardinality() int

Cardinality returns the number of elements in the set Example: ``` s = container.NewSet("1", "2") assert s.Cardinality() == 2 ```

func (*Set) Clear

func (s *Set) Clear()

Clear removes all elements from the set Example: ``` s = container.NewSet("1", "2") s.Clear() assert s.Len() == 0 ```

func (*Set) Clone

func (s *Set) Clone() *Set

Clone returns a new set with the same elements as the original set Example: ``` s = container.NewSet("1", "2") s2 = s.Clone() assert s2.Equal(s) ```

func (*Set) Contains

func (s *Set) Contains(vals ...any) bool

Contains checks if the set contains the given elements Example: ``` s = container.NewSet("1", "2") assert s.Contains("1", "2") == true assert s.Contains("3") == false ```

func (*Set) ContainsAny

func (s *Set) ContainsAny(vals ...any) bool

ContainsAny checks if the set contains any of the given elements Example: ``` s = container.NewSet("1", "2") assert s.ContainsAny("2", "3") == true assert s.ContainsAny("1") == true assert s.ContainsAny("3", "4") == false ```

func (*Set) ContainsOne

func (s *Set) ContainsOne(val any) bool

ContainsOne checks if the set contains the given element Example: ``` s = container.NewSet("1", "2") assert s.ContainsOne("1") == true assert s.ContainsOne("3") == false ```

func (*Set) Difference

func (s *Set) Difference(other *Set) *Set

Difference returns a new set with the elements that are in the original set but not in the other set Example: ``` s = container.NewSet("1", "2") s2 = container.NewSet("2", "3") s3 = s.Difference(s2) // ["1"] ```

func (*Set) Each

func (s *Set) Each(f func(any))

Each applies the given function to each element in the set Example: ``` s = container.NewSet("1", "2") s.Each(func(val) { println(val) }) ```

func (*Set) Equal

func (s *Set) Equal(other *Set) bool

Equal checks if the set is equal to another set Example: ``` s = container.NewSet("1", "2") s2 = container.NewSet("2", "1") s3 = container.NewSet("1", "2", "3") assert s.Equal(s2) == true assert s.Equal(s3) == false ```

func (*Set) Intersect

func (s *Set) Intersect(other *Set) *Set

Intersect returns a new set with the elements that are in both sets Example: ``` s = container.NewSet("1", "2") s2 = container.NewSet("2", "3") s3 = s.Intersect(s2) // ["2"] ```

func (*Set) IsEmpty

func (s *Set) IsEmpty() bool

IsEmpty checks if the set is empty Example: ``` s = container.NewSet() assert s.IsEmpty() == true s2 = container.NewSet("1") assert s2.IsEmpty() == false ```

func (*Set) IsProperSubset

func (s *Set) IsProperSubset(other *Set) bool

IsProperSubset checks if the set is a proper subset of another set Example: ``` s = container.NewSet("1", "2") s2 = container.NewSet("1", "2", "3") assert s.IsProperSubset(s2) == true assert s.IsProperSubset(s) == false ```

func (*Set) IsProperSuperset

func (s *Set) IsProperSuperset(other *Set) bool

IsProperSuperset checks if the set is a proper superset of another set Example: ``` s = container.NewSet("1", "2") s2 = container.NewSet("1", "2", "3") assert s.IsProperSuperset(s2) == false assert s.IsProperSuperset(s) == false assert s2.IsProperSuperset(s) == true ```

func (*Set) IsSubset

func (s *Set) IsSubset(other *Set) bool

IsSubset checks if the set is a subset of another set Example: ``` s = container.NewSet("1", "2") s2 = container.NewSet("1", "2", "3") s3 = container.NewSet("2", "3") assert s.IsSubset(s2) == true assert s.IsSubset(s) == true assert s.IsSubset(s3) == false ```

func (*Set) IsSuperset

func (s *Set) IsSuperset(other *Set) bool

IsSuperset checks if the set is a superset of another set Example: ``` s = container.NewSet("1", "2") s2 = container.NewSet("1", "2", "3") assert s.IsSuperset(s2) == false assert s.IsSuperset(s) == true assert s2.IsSuperset(s) == true ```

func (*Set) Iter

func (s *Set) Iter() <-chan any

Iter returns a channel that can be used to iterate over the elements in the set Example: ``` s = container.NewSet("1", "2") for val = range s.Iter() { println(val) } ```

func (*Set) Iterator

func (s *Set) Iterator() <-chan any

Iterator returns a channel that can be used to iterate over the elements in the set Example: ``` s = container.NewSet("1", "2") for val = range s.Iterator() { println(val) } ```

func (*Set) Len

func (s *Set) Len() int

Len returns the number of elements in the set Example: ``` s = container.NewSet("1", "2") assert s.Len() == 2 ```

func (*Set) MarshalJSON

func (s *Set) MarshalJSON() ([]byte, error)

func (*Set) Pop

func (s *Set) Pop() (any, bool)

Pop removes and returns an arbitrary element from the set Example: ``` s = container.NewSet("1", "2") v, ok = s.Pop() assert ok == true // v maybe 1 or 2 ```

func (*Set) Remove

func (s *Set) Remove(i any)

Remove removes the given element from the set Example: ``` s = container.NewSet("1", "2") s.Remove("1") assert s.Len() == 1 ```

func (*Set) RemoveAll

func (s *Set) RemoveAll(i ...any)

RemoveAll removes the given elements from the set Example: ``` s = container.NewSet("1", "2") s.RemoveAll("1", "2") assert s.Len() == 0 ```

func (*Set) SymmetricDifference

func (s *Set) SymmetricDifference(other *Set) *Set

SymmetricDifference returns a new set with the elements that are in either set but not in both Example: ``` s = container.NewSet("1", "2") s2 = container.NewSet("2", "3") s3 = s.SymmetricDifference(s2) // ["1", "3"] ```

func (*Set) ToSlice

func (s *Set) ToSlice() []any

ToSlice returns the elements of the set as a slice Example: ``` s = container.NewSet("1", "2") s.ToSlice() // ["1", "2"] ```

func (*Set) Union

func (s *Set) Union(other *Set) *Set

Union returns a new set with the elements that are in either set Example: ``` s = container.NewSet("1", "2") s2 = container.NewSet("2", "3") s3 = s.Union(s2) // ["1", "2", "3"] ```

func (*Set) UnmarshalJSON

func (s *Set) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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