Documentation ¶
Index ¶
- type IntSet
- func (set *IntSet) Add(item ...int)
- func (set *IntSet) AddIfNotExist(item int) bool
- func (set *IntSet) AddIfNotExistFunc(item int, f func() bool) bool
- func (set *IntSet) AddIfNotExistFuncLock(item int, f func() bool) bool
- func (set *IntSet) Clear()
- func (set *IntSet) Complement(full *IntSet) (newSet *IntSet)
- func (set *IntSet) Contains(item int) bool
- func (set *IntSet) DeepCopy() interface{}
- func (set *IntSet) Diff(others ...*IntSet) (newSet *IntSet)
- func (set *IntSet) Equal(other *IntSet) bool
- func (set *IntSet) Intersect(others ...*IntSet) (newSet *IntSet)
- func (set *IntSet) IsSubsetOf(other *IntSet) bool
- func (set *IntSet) Iterator(f func(v int) bool)
- func (set *IntSet) Join(glue string) string
- func (set *IntSet) LockFunc(f func(m map[int]struct{}))
- func (set *IntSet) MarshalJSON() ([]byte, error)
- func (set *IntSet) Merge(others ...*IntSet) *IntSet
- func (set *IntSet) Pop() int
- func (set *IntSet) Pops(size int) []int
- func (set *IntSet) RLockFunc(f func(m map[int]struct{}))
- func (set *IntSet) Remove(item int)
- func (set *IntSet) Size() int
- func (set *IntSet) Slice() []int
- func (set *IntSet) String() string
- func (set *IntSet) Sum() (sum int)
- func (set *IntSet) Union(others ...*IntSet) (newSet *IntSet)
- func (set *IntSet) UnmarshalJSON(b []byte) error
- func (set *IntSet) UnmarshalValue(value interface{}) (err error)
- func (set *IntSet) Walk(f func(item int) int) *IntSet
- type Set
- func (set *Set) Add(items ...interface{})
- func (set *Set) AddIfNotExist(item interface{}) bool
- func (set *Set) AddIfNotExistFunc(item interface{}, f func() bool) bool
- func (set *Set) AddIfNotExistFuncLock(item interface{}, f func() bool) bool
- func (set *Set) Clear()
- func (set *Set) Complement(full *Set) (newSet *Set)
- func (set *Set) Contains(item interface{}) bool
- func (set *Set) DeepCopy() interface{}
- func (set *Set) Diff(others ...*Set) (newSet *Set)
- func (set *Set) Equal(other *Set) bool
- func (set *Set) Intersect(others ...*Set) (newSet *Set)
- func (set *Set) IsSubsetOf(other *Set) bool
- func (set *Set) Iterator(f func(v interface{}) bool)
- func (set *Set) Join(glue string) string
- func (set *Set) LockFunc(f func(m map[interface{}]struct{}))
- func (set *Set) MarshalJSON() ([]byte, error)
- func (set *Set) Merge(others ...*Set) *Set
- func (set *Set) Pop() interface{}
- func (set *Set) Pops(size int) []interface{}
- func (set *Set) RLockFunc(f func(m map[interface{}]struct{}))
- func (set *Set) Remove(item interface{})
- func (set *Set) Size() int
- func (set *Set) Slice() []interface{}
- func (set *Set) String() string
- func (set *Set) Sum() (sum int)
- func (set *Set) Union(others ...*Set) (newSet *Set)
- func (set *Set) UnmarshalJSON(b []byte) error
- func (set *Set) UnmarshalValue(value interface{}) (err error)
- func (set *Set) Walk(f func(item interface{}) interface{}) *Set
- type StrSet
- func (set *StrSet) Add(item ...string)
- func (set *StrSet) AddIfNotExist(item string) bool
- func (set *StrSet) AddIfNotExistFunc(item string, f func() bool) bool
- func (set *StrSet) AddIfNotExistFuncLock(item string, f func() bool) bool
- func (set *StrSet) Clear()
- func (set *StrSet) Complement(full *StrSet) (newSet *StrSet)
- func (set *StrSet) Contains(item string) bool
- func (set *StrSet) ContainsI(item string) bool
- func (set *StrSet) DeepCopy() interface{}
- func (set *StrSet) Diff(others ...*StrSet) (newSet *StrSet)
- func (set *StrSet) Equal(other *StrSet) bool
- func (set *StrSet) Intersect(others ...*StrSet) (newSet *StrSet)
- func (set *StrSet) IsSubsetOf(other *StrSet) bool
- func (set *StrSet) Iterator(f func(v string) bool)
- func (set *StrSet) Join(glue string) string
- func (set *StrSet) LockFunc(f func(m map[string]struct{}))
- func (set *StrSet) MarshalJSON() ([]byte, error)
- func (set *StrSet) Merge(others ...*StrSet) *StrSet
- func (set *StrSet) Pop() string
- func (set *StrSet) Pops(size int) []string
- func (set *StrSet) RLockFunc(f func(m map[string]struct{}))
- func (set *StrSet) Remove(item string)
- func (set *StrSet) Size() int
- func (set *StrSet) Slice() []string
- func (set *StrSet) String() string
- func (set *StrSet) Sum() (sum int)
- func (set *StrSet) Union(others ...*StrSet) (newSet *StrSet)
- func (set *StrSet) UnmarshalJSON(b []byte) error
- func (set *StrSet) UnmarshalValue(value interface{}) (err error)
- func (set *StrSet) Walk(f func(item string) string) *StrSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IntSet ¶
type IntSet struct {
// contains filtered or unexported fields
}
IntSet is consisted of int items.
func NewIntSet ¶
NewIntSet create and returns a new set, which contains un-repeated items. The parameter `safe` is used to specify whether using set in concurrent-safety, which is false in default.
func NewIntSetFrom ¶
NewIntSetFrom returns a new set from `items`.
func (*IntSet) AddIfNotExist ¶
AddIfNotExist checks whether item exists in the set, it adds the item to set and returns true if it does not exists in the set, or else it does nothing and returns false.
Note that, if `item` is nil, it does nothing and returns false.
func (*IntSet) AddIfNotExistFunc ¶
AddIfNotExistFunc checks whether item exists in the set, it adds the item to set and returns true if it does not exists in the set and function `f` returns true, or else it does nothing and returns false.
Note that, the function `f` is executed without writing lock.
func (*IntSet) AddIfNotExistFuncLock ¶
AddIfNotExistFuncLock checks whether item exists in the set, it adds the item to set and returns true if it does not exists in the set and function `f` returns true, or else it does nothing and returns false.
Note that, the function `f` is executed without writing lock.
func (*IntSet) Complement ¶
Complement returns a new set which is the complement from `set` to `full`. Which means, all the items in `newSet` are in `full` and not in `set`.
It returns the difference between `full` and `set` if the given set `full` is not the full set of `set`.
func (*IntSet) DeepCopy ¶
func (set *IntSet) DeepCopy() interface{}
DeepCopy implements interface for deep copy of current type.
func (*IntSet) Diff ¶
Diff returns a new set which is the difference set from `set` to `other`. Which means, all the items in `newSet` are in `set` but not in `other`.
func (*IntSet) Intersect ¶
Intersect returns a new set which is the intersection from `set` to `other`. Which means, all the items in `newSet` are in `set` and also in `other`.
func (*IntSet) IsSubsetOf ¶
IsSubsetOf checks whether the current set is a sub-set of `other`.
func (*IntSet) Iterator ¶
Iterator iterates the set readonly with given callback function `f`, if `f` returns true then continue iterating; or false to stop.
func (*IntSet) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*IntSet) Sum ¶
Sum sums items. Note: The items should be converted to int type, or you'd get a result that you unexpected.
func (*IntSet) Union ¶
Union returns a new set which is the union of `set` and `other`. Which means, all the items in `newSet` are in `set` or in `other`.
func (*IntSet) UnmarshalJSON ¶
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*IntSet) UnmarshalValue ¶
UnmarshalValue is an interface implement which sets any type of value for set.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is consisted of interface{} items.
func New ¶
New create and returns a new set, which contains un-repeated items. The parameter `safe` is used to specify whether using set in concurrent-safety, which is false in default.
func NewFrom ¶
NewFrom returns a new set from `items`. Parameter `items` can be either a variable of any type, or a slice.
func (*Set) Add ¶
func (set *Set) Add(items ...interface{})
Add adds one or multiple items to the set.
func (*Set) AddIfNotExist ¶
AddIfNotExist checks whether item exists in the set, it adds the item to set and returns true if it does not exists in the set, or else it does nothing and returns false.
Note that, if `item` is nil, it does nothing and returns false.
func (*Set) AddIfNotExistFunc ¶
AddIfNotExistFunc checks whether item exists in the set, it adds the item to set and returns true if it does not exist in the set and function `f` returns true, or else it does nothing and returns false.
Note that, if `item` is nil, it does nothing and returns false. The function `f` is executed without writing lock.
func (*Set) AddIfNotExistFuncLock ¶
AddIfNotExistFuncLock checks whether item exists in the set, it adds the item to set and returns true if it does not exists in the set and function `f` returns true, or else it does nothing and returns false.
Note that, if `item` is nil, it does nothing and returns false. The function `f` is executed within writing lock.
func (*Set) Complement ¶
Complement returns a new set which is the complement from `set` to `full`. Which means, all the items in `newSet` are in `full` and not in `set`.
It returns the difference between `full` and `set` if the given set `full` is not the full set of `set`.
func (*Set) DeepCopy ¶
func (set *Set) DeepCopy() interface{}
DeepCopy implements interface for deep copy of current type.
func (*Set) Diff ¶
Diff returns a new set which is the difference set from `set` to `others`. Which means, all the items in `newSet` are in `set` but not in `others`.
func (*Set) Intersect ¶
Intersect returns a new set which is the intersection from `set` to `others`. Which means, all the items in `newSet` are in `set` and also in `others`.
func (*Set) IsSubsetOf ¶
IsSubsetOf checks whether the current set is a sub-set of `other`.
func (*Set) Iterator ¶
Iterator iterates the set readonly with given callback function `f`, if `f` returns true then continue iterating; or false to stop.
func (*Set) LockFunc ¶
func (set *Set) LockFunc(f func(m map[interface{}]struct{}))
LockFunc locks writing with callback function `f`.
func (*Set) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*Set) RLockFunc ¶
func (set *Set) RLockFunc(f func(m map[interface{}]struct{}))
RLockFunc locks reading with callback function `f`.
func (*Set) Slice ¶
func (set *Set) Slice() []interface{}
Slice returns all items of the set as slice.
func (*Set) Sum ¶
Sum sums items. Note: The items should be converted to int type, or you'd get a result that you unexpected.
func (*Set) Union ¶
Union returns a new set which is the union of `set` and `others`. Which means, all the items in `newSet` are in `set` or in `others`.
func (*Set) UnmarshalJSON ¶
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*Set) UnmarshalValue ¶
UnmarshalValue is an interface implement which sets any type of value for set.
type StrSet ¶
type StrSet struct {
// contains filtered or unexported fields
}
StrSet is consisted of string items.
func NewStrSet ¶
NewStrSet create and returns a new set, which contains un-repeated items. The parameter `safe` is used to specify whether using set in concurrent-safety, which is false in default.
func NewStrSetFrom ¶
NewStrSetFrom returns a new set from `items`.
func (*StrSet) AddIfNotExist ¶
AddIfNotExist checks whether item exists in the set, it adds the item to set and returns true if it does not exist in the set, or else it does nothing and returns false.
func (*StrSet) AddIfNotExistFunc ¶
AddIfNotExistFunc checks whether item exists in the set, it adds the item to set and returns true if it does not exists in the set and function `f` returns true, or else it does nothing and returns false.
Note that, the function `f` is executed without writing lock.
func (*StrSet) AddIfNotExistFuncLock ¶
AddIfNotExistFuncLock checks whether item exists in the set, it adds the item to set and returns true if it does not exists in the set and function `f` returns true, or else it does nothing and returns false.
Note that, the function `f` is executed without writing lock.
func (*StrSet) Complement ¶
Complement returns a new set which is the complement from `set` to `full`. Which means, all the items in `newSet` are in `full` and not in `set`.
It returns the difference between `full` and `set` if the given set `full` is not the full set of `set`.
func (*StrSet) ContainsI ¶
ContainsI checks whether a value exists in the set with case-insensitively. Note that it internally iterates the whole set to do the comparison with case-insensitively.
func (*StrSet) DeepCopy ¶
func (set *StrSet) DeepCopy() interface{}
DeepCopy implements interface for deep copy of current type.
func (*StrSet) Diff ¶
Diff returns a new set which is the difference set from `set` to `other`. Which means, all the items in `newSet` are in `set` but not in `other`.
func (*StrSet) Intersect ¶
Intersect returns a new set which is the intersection from `set` to `other`. Which means, all the items in `newSet` are in `set` and also in `other`.
func (*StrSet) IsSubsetOf ¶
IsSubsetOf checks whether the current set is a sub-set of `other`.
func (*StrSet) Iterator ¶
Iterator iterates the set readonly with given callback function `f`, if `f` returns true then continue iterating; or false to stop.
func (*StrSet) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*StrSet) Sum ¶
Sum sums items. Note: The items should be converted to int type, or you'd get a result that you unexpected.
func (*StrSet) Union ¶
Union returns a new set which is the union of `set` and `other`. Which means, all the items in `newSet` are in `set` or in `other`.
func (*StrSet) UnmarshalJSON ¶
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*StrSet) UnmarshalValue ¶
UnmarshalValue is an interface implement which sets any type of value for set.