gset

package
v2.0.0-...-cbac34e Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package gset provides kinds of concurrent-safe/unsafe sets.

Index

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
}

func NewIntSet

func NewIntSet(safe ...bool) *IntSet

New create and returns a new set, which contains un-repeated items. The parameter <unsafe> used to specify whether using set in un-concurrent-safety, which is false in default.

func NewIntSetFrom

func NewIntSetFrom(items []int, safe ...bool) *IntSet

NewIntSetFrom returns a new set from <items>.

func (*IntSet) Add

func (set *IntSet) Add(item ...int) *IntSet

Add adds one or multiple items to the set.

func (*IntSet) Clear

func (set *IntSet) Clear() *IntSet

Clear deletes all items of the set.

func (*IntSet) Complement

func (set *IntSet) Complement(full *IntSet) (newSet *IntSet)

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) Contains

func (set *IntSet) Contains(item int) bool

Contains checks whether the set contains <item>.

func (*IntSet) Diff

func (set *IntSet) Diff(others ...*IntSet) (newSet *IntSet)

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) Equal

func (set *IntSet) Equal(other *IntSet) bool

Equal checks whether the two sets equal.

func (*IntSet) Intersect

func (set *IntSet) Intersect(others ...*IntSet) (newSet *IntSet)

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

func (set *IntSet) IsSubsetOf(other *IntSet) bool

IsSubsetOf checks whether the current set is a sub-set of <other>.

func (*IntSet) Iterator

func (set *IntSet) Iterator(f func(v int) bool) *IntSet

Iterator iterates the set with given callback function <f>, if <f> returns true then continue iterating; or false to stop.

func (*IntSet) Join

func (set *IntSet) Join(glue string) string

Join joins items with a string <glue>.

func (*IntSet) LockFunc

func (set *IntSet) LockFunc(f func(m map[int]struct{}))

LockFunc locks writing with callback function <f>.

func (*IntSet) MarshalJSON

func (set *IntSet) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*IntSet) Merge

func (set *IntSet) Merge(others ...*IntSet) *IntSet

Merge adds items from <others> sets into <set>.

func (*IntSet) Pop

func (set *IntSet) Pop() int

Pops randomly pops an item from set.

func (*IntSet) Pops

func (set *IntSet) Pops(size int) []int

Pops randomly pops <size> items from set.

func (*IntSet) RLockFunc

func (set *IntSet) RLockFunc(f func(m map[int]struct{}))

RLockFunc locks reading with callback function <f>.

func (*IntSet) Remove

func (set *IntSet) Remove(item int) *IntSet

Remove deletes <item> from set.

func (*IntSet) Size

func (set *IntSet) Size() int

Size returns the size of the set.

func (*IntSet) Slice

func (set *IntSet) Slice() []int

Slice returns the a of items of the set as slice.

func (*IntSet) String

func (set *IntSet) String() string

String returns items as a string, which are joined by char ','.

func (*IntSet) Sum

func (set *IntSet) Sum() (sum int)

Sum sums items. Note: The items should be converted to int type, or you'd get a result that you unexpected.

func (*IntSet) Union

func (set *IntSet) Union(others ...*IntSet) (newSet *IntSet)

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>.

type Set

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

func New

func New(safe ...bool) *Set

New create and returns a new set, which contains un-repeated items. The parameter <unsafe> used to specify whether using set in un-concurrent-safety, which is false in default.

func NewFrom

func NewFrom(items interface{}, safe ...bool) *Set

NewFrom returns a new set from <items>. Parameter <items> can be either a variable of any type, or a slice.

func NewSet

func NewSet(safe ...bool) *Set

See New.

func (*Set) Add

func (set *Set) Add(item ...interface{}) *Set

Add adds one or multiple items to the set.

func (*Set) Clear

func (set *Set) Clear() *Set

Clear deletes all items of the set.

func (*Set) Complement

func (set *Set) Complement(full *Set) (newSet *Set)

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) Contains

func (set *Set) Contains(item interface{}) bool

Contains checks whether the set contains <item>.

func (*Set) Diff

func (set *Set) Diff(others ...*Set) (newSet *Set)

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) Equal

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

Equal checks whether the two sets equal.

func (*Set) Intersect

func (set *Set) Intersect(others ...*Set) (newSet *Set)

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

func (set *Set) IsSubsetOf(other *Set) bool

IsSubsetOf checks whether the current set is a sub-set of <other>.

func (*Set) Iterator

func (set *Set) Iterator(f func(v interface{}) bool) *Set

Iterator iterates the set with given callback function <f>, if <f> returns true then continue iterating; or false to stop.

func (*Set) Join

func (set *Set) Join(glue string) string

Join joins items with a string <glue>.

func (*Set) LockFunc

func (set *Set) LockFunc(f func(m map[interface{}]struct{}))

LockFunc locks writing with callback function <f>.

func (*Set) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Set) Merge

func (set *Set) Merge(others ...*Set) *Set

Merge adds items from <others> sets into <set>.

func (*Set) Pop

func (set *Set) Pop() interface{}

Pops randomly pops an item from set.

func (*Set) Pops

func (set *Set) Pops(size int) []interface{}

Pops randomly pops <size> items from set.

func (*Set) RLockFunc

func (set *Set) RLockFunc(f func(m map[interface{}]struct{}))

RLockFunc locks reading with callback function <f>.

func (*Set) Remove

func (set *Set) Remove(item interface{}) *Set

Remove deletes <item> from set.

func (*Set) Size

func (set *Set) Size() int

Size returns the size of the set.

func (*Set) Slice

func (set *Set) Slice() []interface{}

Slice returns the a of items of the set as slice.

func (*Set) String

func (set *Set) String() string

String returns items as a string, which are joined by char ','.

func (*Set) Sum

func (set *Set) Sum() (sum int)

Sum sums items. Note: The items should be converted to int type, or you'd get a result that you unexpected.

func (*Set) Union

func (set *Set) Union(others ...*Set) (newSet *Set)

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>.

type StrSet

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

func NewStrSet

func NewStrSet(safe ...bool) *StrSet

New create and returns a new set, which contains un-repeated items. The parameter <unsafe> used to specify whether using set in un-concurrent-safety, which is false in default.

func NewStrSetFrom

func NewStrSetFrom(items []string, safe ...bool) *StrSet

NewStrSetFrom returns a new set from <items>.

func (*StrSet) Add

func (set *StrSet) Add(item ...string) *StrSet

Add adds one or multiple items to the set.

func (*StrSet) Clear

func (set *StrSet) Clear() *StrSet

Clear deletes all items of the set.

func (*StrSet) Complement

func (set *StrSet) Complement(full *StrSet) (newSet *StrSet)

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) Contains

func (set *StrSet) Contains(item string) bool

Contains checks whether the set contains <item>.

func (*StrSet) Diff

func (set *StrSet) Diff(others ...*StrSet) (newSet *StrSet)

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) Equal

func (set *StrSet) Equal(other *StrSet) bool

Equal checks whether the two sets equal.

func (*StrSet) Intersect

func (set *StrSet) Intersect(others ...*StrSet) (newSet *StrSet)

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

func (set *StrSet) IsSubsetOf(other *StrSet) bool

IsSubsetOf checks whether the current set is a sub-set of <other>.

func (*StrSet) Iterator

func (set *StrSet) Iterator(f func(v string) bool) *StrSet

Iterator iterates the set with given callback function <f>, if <f> returns true then continue iterating; or false to stop.

func (*StrSet) Join

func (set *StrSet) Join(glue string) string

Join joins items with a string <glue>.

func (*StrSet) LockFunc

func (set *StrSet) LockFunc(f func(m map[string]struct{}))

LockFunc locks writing with callback function <f>.

func (*StrSet) MarshalJSON

func (set *StrSet) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*StrSet) Merge

func (set *StrSet) Merge(others ...*StrSet) *StrSet

Merge adds items from <others> sets into <set>.

func (*StrSet) Pop

func (set *StrSet) Pop() string

Pops randomly pops an item from set.

func (*StrSet) Pops

func (set *StrSet) Pops(size int) []string

Pops randomly pops <size> items from set.

func (*StrSet) RLockFunc

func (set *StrSet) RLockFunc(f func(m map[string]struct{}))

RLockFunc locks reading with callback function <f>.

func (*StrSet) Remove

func (set *StrSet) Remove(item string) *StrSet

Remove deletes <item> from set.

func (*StrSet) Size

func (set *StrSet) Size() int

Size returns the size of the set.

func (*StrSet) Slice

func (set *StrSet) Slice() []string

Slice returns the a of items of the set as slice.

func (*StrSet) String

func (set *StrSet) String() string

String returns items as a string, which are joined by char ','.

func (*StrSet) Sum

func (set *StrSet) Sum() (sum int)

Sum sums items. Note: The items should be converted to int type, or you'd get a result that you unexpected.

func (*StrSet) Union

func (set *StrSet) Union(others ...*StrSet) (newSet *StrSet)

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>.

Jump to

Keyboard shortcuts

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