datastructure

package
v0.0.0-...-d1e1ff0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T comparable] map[T]struct{}

Set is a data container, like slice, but element of set is not duplicate

func NewSet

func NewSet[T comparable](items ...T) Set[T]

NewSet return a instance of set

func NewSetFromSlice

func NewSetFromSlice[T comparable](items []T) Set[T]

NewSetFromSlice create a set from slice

func (Set[T]) Add

func (s Set[T]) Add(items ...T)

Add items to set

func (Set[T]) AddIfNotExist

func (s Set[T]) AddIfNotExist(item T) bool

AddIfNotExist checks if 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 (Set[T]) AddIfNotExistBy

func (s Set[T]) AddIfNotExistBy(item T, checker func(element T) bool) bool

AddIfNotExistBy checks if item exists in the set and pass the `checker` function it adds the item to set and returns true if it does not exists in the set and function `checker` returns true, or else it does nothing and returns false.

func (Set[T]) Clone

func (s Set[T]) Clone() Set[T]

Clone return a copy of set

func (Set[T]) Contain

func (s Set[T]) Contain(item T) bool

Contain checks if set contains item or not

func (Set[T]) ContainAll

func (s Set[T]) ContainAll(other Set[T]) bool

ContainAll checks if set contains other set

func (Set[T]) Delete

func (s Set[T]) Delete(items ...T)

Delete item of set

func (Set[T]) EachWithBreak

func (s Set[T]) EachWithBreak(iteratee func(item T) bool)

EachWithBreak iterates over elements of a set and invokes function for each element, when iteratee return false, will break the for each loop.

func (Set[T]) Equal

func (s Set[T]) Equal(other Set[T]) bool

Equal checks if two set has same elements or not

func (Set[T]) Intersection

func (s Set[T]) Intersection(other Set[T]) Set[T]

Intersection creates a new set whose element both be contained in set s and other

func (Set[T]) IsEmpty

func (s Set[T]) IsEmpty() bool

IsEmpty checks the set is empty or not

func (Set[T]) Iterate

func (s Set[T]) Iterate(fn func(item T))

Iterate call function by every element of set

func (Set[T]) Minus

func (s Set[T]) Minus(comparedSet Set[T]) Set[T]

Minus creates an set of whose element in origin set but not in compared set

func (Set[T]) Pop

func (s Set[T]) Pop() (v T, ok bool)

Pop delete the top element of set then return it, if set is empty, return nil-value of T and false.

func (Set[T]) Size

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

Size get the number of elements in set

func (Set[T]) SymmetricDifference

func (s Set[T]) SymmetricDifference(other Set[T]) Set[T]

SymmetricDifference creates a new set whose element is in set1 or set2, but not in both sets

func (Set[T]) Union

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

Union creates a new set contain all element of set s and other

func (Set[T]) Values

func (s Set[T]) Values() []T

Values return all values of set

Jump to

Keyboard shortcuts

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