datastructure

package
v16.8.4 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 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[Value comparable] struct {
	// contains filtered or unexported fields
}

Set is a data structure that contains unique values. This data structure is not safe for concurrent accesses.

func NewSet

func NewSet[Value comparable]() *Set[Value]

NewSet returns a new ready-to-use set.

func SetFromSlice

func SetFromSlice[Value comparable](slice []Value) *Set[Value]

SetFromSlice creates a new set that is prepopulated with the values from the given slice. The slice values will be deduplicated. This can be more efficient than manually creating and populating the set with values as the underlying data structure will already be preallocated.

func SetFromValues

func SetFromValues[Value comparable](values ...Value) *Set[Value]

SetFromValues creates a new set that is populated with the provided values. The values will be deduplicated. This can be more efficient than manually creating and populating the set with values as the underlying data structure will already be preallocated.

func (*Set[Value]) Add

func (s *Set[Value]) Add(v Value) bool

Add adds the given value to the set. Returns `true` if the value was added, and `false` in case no change was made to the set.

func (*Set[Value]) Equal

func (s *Set[Value]) Equal(o *Set[Value]) bool

Equal determines whether the set is equal to another set. Two sets are equal when they contain the exact same values.

func (*Set[Value]) HasValue

func (s *Set[Value]) HasValue(v Value) bool

HasValue determines whether the given value is contained in the set.

func (*Set[Value]) IsEmpty

func (s *Set[Value]) IsEmpty() bool

IsEmpty determines whether the set is empty.

func (*Set[Value]) Len

func (s *Set[Value]) Len() int

Len returns the number of entries contained in the set.

func (*Set[Value]) Remove

func (s *Set[Value]) Remove(v Value) bool

Remove removes the given value from the set. Returns `true` if the value was removed, and `false` in case no change was made to the set.

func (*Set[Value]) Values

func (s *Set[Value]) Values() []Value

Values returns an array of all values that have been added to the set. The array is newly allocated and can be modified without affecting the set itself. The order of values is not guaranteed.

Jump to

Keyboard shortcuts

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