Documentation
¶
Index ¶
- Variables
- type LinkedList
- type Set
- func (s *Set) Add(val any) bool
- func (s *Set) Append(vals ...any) int
- func (s *Set) Cap() int
- func (s *Set) Cardinality() int
- func (s *Set) Clear()
- func (s *Set) Clone() *Set
- func (s *Set) Contains(vals ...any) bool
- func (s *Set) ContainsAny(vals ...any) bool
- func (s *Set) ContainsOne(val any) bool
- func (s *Set) Difference(other *Set) *Set
- func (s *Set) Each(f func(any))
- func (s *Set) Equal(other *Set) bool
- func (s *Set) Intersect(other *Set) *Set
- func (s *Set) IsEmpty() bool
- func (s *Set) IsProperSubset(other *Set) bool
- func (s *Set) IsProperSuperset(other *Set) bool
- func (s *Set) IsSubset(other *Set) bool
- func (s *Set) IsSuperset(other *Set) bool
- func (s *Set) Iter() <-chan any
- func (s *Set) Iterator() <-chan any
- func (s *Set) Len() int
- func (s *Set) MarshalJSON() ([]byte, error)
- func (s *Set) Pop() (any, bool)
- func (s *Set) Remove(i any)
- func (s *Set) RemoveAll(i ...any)
- func (s *Set) SymmetricDifference(other *Set) *Set
- func (s *Set) ToSlice() []any
- func (s *Set) Union(other *Set) *Set
- func (s *Set) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ContainerExports = map[string]interface{}{ "NewSet": NewSet, "NewUnsafeSet": NewUnsafeSet, "NewLinkedList": NewLinkedList, }
Functions ¶
This section is empty.
Types ¶
type LinkedList ¶
func NewLinkedList ¶
func NewLinkedList() *LinkedList
func (*LinkedList) ToSlice ¶
func (l *LinkedList) ToSlice() []any
type Set ¶
func NewUnsafeSet ¶
NewUnsafeSet creates a new set that is not thread-safe Example: ``` s = container.NewUnsafeSet("1", "2") ```
func (*Set) Add ¶
Add add an element to set Example: ``` s = container.NewSet() assert s.Add("1") == true ```
func (*Set) Append ¶
Append add multiple elements to set Example: ``` assert s.Append("1", "2", "3") == 3 ```
func (*Set) Cap ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Len returns the number of elements in the set Example: ``` s = container.NewSet("1", "2") assert s.Len() == 2 ```
func (*Set) MarshalJSON ¶
func (*Set) Pop ¶
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 ¶
Remove removes the given element from the set Example: ``` s = container.NewSet("1", "2") s.Remove("1") assert s.Len() == 1 ```
func (*Set) RemoveAll ¶
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 ¶
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 ¶
ToSlice returns the elements of the set as a slice Example: ``` s = container.NewSet("1", "2") s.ToSlice() // ["1", "2"] ```
func (*Set) Union ¶
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"] ```