set

package
v2.12.5 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generic

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

Generic is a generic set collection. The zero value of Generic is an empty instance ready to use. A zero Generic set value shall not be copied, or it may result incorrect behavior.

func New

func New[T comparable](vals ...T) Generic[T]

New creates a set instance and add the given values into the set.

func NewWithSize

func NewWithSize[T comparable](size int) Generic[T]

NewWithSize creates a set instance with given initial size.

func (*Generic[T]) Add

func (s *Generic[T]) Add(vals ...T)

Add adds the given values into the set.

func (Generic[T]) Contains

func (s Generic[T]) Contains(vals ...T) bool

Contains returns true if the set contains all the values.

func (Generic[T]) ContainsAny

func (s Generic[T]) ContainsAny(vals ...T) bool

ContainsAny returns true if the set contains any of the values.

func (*Generic[T]) Delete

func (s *Generic[T]) Delete(vals ...T)

Delete deletes values from the set.

func (Generic[T]) Diff

func (s Generic[T]) Diff(other Generic[T]) Generic[T]

Diff returns a new set about the values which other set doesn't contain.

func (Generic[T]) DiffSlice

func (s Generic[T]) DiffSlice(other []T) Generic[T]

DiffSlice is similar to Diff, but takes a slice as parameter.

func (Generic[T]) FilterContains

func (s Generic[T]) FilterContains(slice []T) []T

FilterContains returns a new slice which contains values that present in the provided slice and also present in the set.

func (Generic[T]) FilterNotContains

func (s Generic[T]) FilterNotContains(slice []T) []T

FilterNotContains returns a new slice which contains values that present in the provided slice but don't present in the set.

func (Generic[T]) Intersect

func (s Generic[T]) Intersect(other Generic[T]) Generic[T]

Intersect returns a new set about values which other set also contains.

func (Generic[T]) IntersectSlice

func (s Generic[T]) IntersectSlice(other []T) Generic[T]

IntersectSlice is similar to Intersect, but takes a slice as parameter.

func (Generic[T]) Iterate

func (s Generic[T]) Iterate(fn func(T))

Iterate iterates the set in no particular order and calls the given function for each set element.

func (Generic[T]) Map

func (s Generic[T]) Map() map[T]bool

Map converts the set into a map of type map[T]bool.

func (Generic[T]) MarshalJSON

func (s Generic[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface, the set will be marshaled as a slice []T.

func (Generic[T]) MarshalYAML

func (s Generic[T]) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler interface of the yaml package, the set will be marshaled as a slice []T.

func (Generic[T]) Size

func (s Generic[T]) Size() int

Size returns the size of the set collection.

func (Generic[T]) Slice

func (s Generic[T]) Slice() []T

Slice converts the set into a slice of type []T.

func (Generic[T]) Union

func (s Generic[T]) Union(other Generic[T]) Generic[T]

Union returns a new set about values either in the set or the other set.

func (Generic[T]) UnionSlice

func (s Generic[T]) UnionSlice(other []T) Generic[T]

UnionSlice is similar to Union, but takes a slice as parameter.

func (*Generic[T]) UnmarshalJSON

func (s *Generic[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler interface, it will unmarshal a slice []T to the set.

func (*Generic[T]) UnmarshalYAML

func (s *Generic[T]) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements yaml.Unmarshaler interface of the yaml package, it will unmarshal a slice []T to the set.

type Int

type Int struct {
	Generic[int]
}

Int is an int set collection. The zero value of Int is an empty instance ready to use. A zero Int value shall not be copied, or it may result incorrect behavior.

This type is mainly for compatibility with old code, the generic implementation Generic[int] is favored over this.

func NewInt

func NewInt(vals ...int) Int

NewInt creates an Int set instance.

func NewIntWithSize

func NewIntWithSize(size int) Int

NewIntWithSize creates an Int set instance with given initial size.

func (Int) Del

func (s Int) Del(vals ...int)

func (Int) Diff

func (s Int) Diff(other Int) Int

func (Int) DiffSlice

func (s Int) DiffSlice(other []int) Int

func (Int) FilterExclude

func (s Int) FilterExclude(slice []int) []int

func (Int) FilterInclude

func (s Int) FilterInclude(slice []int) []int

func (Int) Intersect

func (s Int) Intersect(other Int) Int

func (Int) IntersectSlice

func (s Int) IntersectSlice(other []int) Int

func (Int) Union

func (s Int) Union(other Int) Int

func (Int) UnionSlice

func (s Int) UnionSlice(other []int) Int

type Int32

type Int32 struct {
	Generic[int32]
}

Int32 is an int32 set collection. The zero value of Int32 is an empty instance ready to use. A zero Int32 value shall not be copied, or it may result incorrect behavior.

This type is mainly for compatibility with old code, the generic implementation Generic[int32] is favored over this.

func NewInt32

func NewInt32(vals ...int32) Int32

NewInt32 creates an Int32 set instance.

func NewInt32WithSize

func NewInt32WithSize(size int) Int32

NewInt32WithSize creates an Int32 set instance with given initial size.

func (Int32) Del

func (s Int32) Del(vals ...int32)

func (Int32) Diff

func (s Int32) Diff(other Int32) Int32

func (Int32) DiffSlice

func (s Int32) DiffSlice(other []int32) Int32

func (Int32) FilterExclude

func (s Int32) FilterExclude(slice []int32) []int32

func (Int32) FilterInclude

func (s Int32) FilterInclude(slice []int32) []int32

func (Int32) Intersect

func (s Int32) Intersect(other Int32) Int32

func (Int32) IntersectSlice

func (s Int32) IntersectSlice(other []int32) Int32

func (Int32) Union

func (s Int32) Union(other Int32) Int32

func (Int32) UnionSlice

func (s Int32) UnionSlice(other []int32) Int32

type Int64

type Int64 struct {
	Generic[int64]
}

Int64 is an int64 set collection. The zero value of Int64 is an empty instance ready to use. A zero Int64 value shall not be copied, or it may result incorrect behavior.

This type is mainly for compatibility with old code, the generic implementation Generic[int64] is favored over this.

func NewInt64

func NewInt64(vals ...int64) Int64

NewInt64 creates an Int64 set instance.

func NewInt64WithSize

func NewInt64WithSize(size int) Int64

NewInt64WithSize creates an Int64 set instance with given initial size.

func (Int64) Del

func (s Int64) Del(vals ...int64)

func (Int64) Diff

func (s Int64) Diff(other Int64) Int64

func (Int64) DiffSlice

func (s Int64) DiffSlice(other []int64) Int64

func (Int64) FilterExclude

func (s Int64) FilterExclude(slice []int64) []int64

func (Int64) FilterInclude

func (s Int64) FilterInclude(slice []int64) []int64

func (Int64) Intersect

func (s Int64) Intersect(other Int64) Int64

func (Int64) IntersectSlice

func (s Int64) IntersectSlice(other []int64) Int64

func (Int64) Union

func (s Int64) Union(other Int64) Int64

func (Int64) UnionSlice

func (s Int64) UnionSlice(other []int64) Int64

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is a set collection of any type. The zero value of Set is an empty instance ready to use. A zero Set value shall not be copied, or it may result incorrect behavior.

func NewSet

func NewSet(vals ...any) Set

NewSet creates a Set instance and add the given values into the set. If given only one param which is a slice, the elements of the slice will be added into the set using reflection.

func NewSetWithSize

func NewSetWithSize(size int) Set

NewSetWithSize creates a Set instance with given initial size.

func (*Set) Add

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

Add adds the given values into the set. If given only one param which is a slice, the elements of the slice will be added into the set using reflection.

func (Set) Contains

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

Contains returns true if the set contains all the values.

func (Set) ContainsAny

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

ContainsAny returns true if the set contains any of the values.

func (*Set) Del deprecated

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

Del deletes values from the set.

Deprecated: Del has been renamed to Delete.

func (*Set) Delete

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

Delete deletes values from the set.

func (Set) Diff

func (s Set) Diff(other Set) Set

Diff returns a new Set about the values which other sets don't contain.

func (Set) DiffSlice

func (s Set) DiffSlice(other any) Set

DiffSlice is similar to Diff, but takes a slice as parameter. Param other must be a slice of []any or slice of the concrete element type, else it panics.

func (Set) FilterContains

func (s Set) FilterContains(slice any) any

FilterContains returns a new slice which contains values that present in the provided slice and also present in the Set. Param slice must be a slice of []any or slice of the concrete element type, else it panics.

func (Set) FilterExclude deprecated

func (s Set) FilterExclude(slice any) any

FilterExclude returns a new slice which contains values that present in the provided slice but don't present in the Set. Param slice must be a slice of []any or slice of the concrete element type, else it panics.

Deprecated: FilterExclude has been renamed to FilterNotContains.

func (Set) FilterInclude deprecated

func (s Set) FilterInclude(slice any) any

FilterInclude returns a new slice which contains values that present in the provided slice and also present in the Set. Param slice must be a slice of []any or slice of the concrete element type, else it panics.

Deprecated: FilterInclude has been renamed to FilterContains.

func (Set) FilterNotContains

func (s Set) FilterNotContains(slice any) any

FilterNotContains returns a new slice which contains values that present in the provided slice but don't present in the Set. Param slice must be a slice of []any or slice of the concrete element type, else it panics.

func (Set) Intersect

func (s Set) Intersect(other Set) Set

Intersect returns new Set about values which other set also contains.

func (Set) IntersectSlice

func (s Set) IntersectSlice(other any) Set

IntersectSlice is similar to Intersect, but takes a slice as parameter. Param other must be a slice of []any or slice of the concrete element type, else it panics.

func (Set) Iterate

func (s Set) Iterate(fn func(any))

Iterate iterates the set in no particular order and calls the given function for each set element.

func (Set) Map

func (s Set) Map() map[any]bool

Map converts set into a map of type map[any]bool.

func (Set) MarshalJSON

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

MarshalJSON implements json.Marshaler interface, the set will be marshaled as a slice []any.

func (Set) MarshalYAML

func (s Set) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler interface of the yaml package, the set will be marshaled as a slice []any.

func (Set) Size

func (s Set) Size() int

Size returns the size of the set.

func (Set) Slice

func (s Set) Slice() []any

Slice converts set into a slice of type []any.

func (Set) Union

func (s Set) Union(other Set) Set

Union returns new Set about values either in the set or the other set.

func (Set) UnionSlice

func (s Set) UnionSlice(other any) Set

UnionSlice is similar to Union, but takes a slice as parameter. Param other must be a slice of []any or slice of the concrete element type, else it panics.

func (*Set) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler interface, it will unmarshal a slice []any to the set.

func (*Set) UnmarshalYAML

func (s *Set) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements yaml.Unmarshaler interface of the yaml package, it will unmarshal a slice []any to the set.

type String

type String struct {
	Generic[string]
}

String is a string set collection. The zero value of String is an empty instance ready to use. A zero String value shall not be copied, or it may result incorrect behavior.

This type is mainly for compatibility with old code, the generic implementation Generic[string] is favored over this.

func NewString

func NewString(vals ...string) String

NewString creates a String set instance.

func NewStringWithSize

func NewStringWithSize(size int) String

NewStringWithSize creates a String set instance with given initial size.

func (String) Del

func (s String) Del(vals ...string)

func (String) Diff

func (s String) Diff(other String) String

func (String) DiffSlice

func (s String) DiffSlice(other []string) String

func (String) FilterExclude

func (s String) FilterExclude(slice []string) []string

func (String) FilterInclude

func (s String) FilterInclude(slice []string) []string

func (String) Intersect

func (s String) Intersect(other String) String

func (String) IntersectSlice

func (s String) IntersectSlice(other []string) String

func (String) Union

func (s String) Union(other String) String

func (String) UnionSlice

func (s String) UnionSlice(other []string) String

Jump to

Keyboard shortcuts

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