datastructure

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 1 Imported by: 8

Documentation

Overview

Package datastructure contains some data structure. Set is a data container, like slice, but element of set is not duplicate.

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 FromSlice added in v2.3.0

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

FromSlice create a set from given slice.

func New added in v2.3.0

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

New create a instance of set from given values.

func (Set[T]) Add

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

Add items to set

func (Set[T]) AddIfNotExist added in v2.1.11

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 added in v2.1.11

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 added in v2.1.17

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 added in v2.0.3

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

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

func (Set[T]) Pop added in v2.1.17

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 added in v2.0.3

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]) ToSlice added in v2.3.0

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

ToSlice returns a slice containing all values of the set.

func (Set[T]) ToSortedSlice added in v2.3.0

func (s Set[T]) ToSortedSlice(less func(v1, v2 T) bool) []T

ToSortedSlice returns a sorted slice containing all values of the set.

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 Deprecated: Values function is deprecated and will be removed in future versions. Please use ToSlice() function instead.

The ToSlice() function provides the same functionality as Values and returns a slice containing all values of the set.

Jump to

Keyboard shortcuts

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