simpleSet

package
v0.0.0-...-41ddf2c Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 4 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 simple set using an underlying map

func Cap

func Cap[T comparable](capacity int) Set[T]

Cap creates a simple set with capacity.

func New

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

New creates a simple set without capacity.

func With

func With[T comparable](values ...T) Set[T]

With creates a simple set with the given values as the keys in the map.

func (Set[T]) Clone

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

Clone creates a shallow clone of the set. This will not deep copying the values.

func (Set[T]) Count

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

Count gets the number of values in the set.

func (Set[T]) Has

func (s Set[T]) Has(value T) bool

Has determines if the given value is in the set.

func (Set[T]) Remove

func (s Set[T]) Remove(value T)

Remove removes the given value from the set. Has no effect if the value is not already set.

func (Set[T]) RemoveIf

func (s Set[T]) RemoveIf(predicate func(T) bool) bool

RemoveIf removes any value which the given predicate accepts. Returns true if any value was remove, otherwise false if none were removed.

func (Set[T]) RemoveTest

func (s Set[T]) RemoveTest(value T) bool

RemoveTest removes the given value from the set if it exists. Returns true if the value was removed, otherwise false if not set.

func (Set[T]) Set

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

Set the given value in the set. Has no effect if the value is already set.

func (Set[T]) SetTest

func (s Set[T]) SetTest(value T) bool

SetTest checks if the value exists or not before being set. Returns true if value is new, otherwise false if already set.

func (Set[T]) ToSlice

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

ToSlice gets all the values in the set in random order.

func (Set[T]) ToString

func (s Set[T]) ToString() string

ToString gets a comma separated list of the values sorted by the strings of the values.

Jump to

Keyboard shortcuts

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