sets

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CounterSet

type CounterSet[T comparable] map[T]int

A CounterSet is map with keys of type T and values representing a count. The Increment() function is used to change the count value. A CounterSet it is not safe for concurrency and its order is not guaranteed.

func (CounterSet[T]) Increment

func (s CounterSet[T]) Increment(key T, cnt int) (int, int, bool)

Increment increments the CounterSet value for 'key' by 'cnt' and returns the old and new value. The bool returns true if the key was pre-existing. Negative cnt values are ok. Increment is not safe for concurrency.

func (CounterSet[T]) Reset

func (s CounterSet[T]) Reset(key T)

Reset resets the CounterSet value for 'key' to 0. If the key is not present in the map, it is added and set to 0. Reset is not safe for concurrency.

func (CounterSet[T]) Value

func (s CounterSet[T]) Value(key T) (int, bool)

Value returns the value for the provided key, or false if it doesn't exist.

type Set

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

Set is a collection of unique elements

func MapKeysToStringSet

func MapKeysToStringSet[V any](m map[string]V) Set[string]

func New

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

New creates a new Set from a slice of keys.

func NewByteSet

func NewByteSet() Set[byte]

NewByteSet returns a new Set[byte]

func NewInt64Set

func NewInt64Set() Set[int64]

NewInt64Set returns a new Set[int64]

func NewIntSet

func NewIntSet() Set[int]

NewIntSet returns a new Set[int]

func NewStringSet

func NewStringSet() Set[string]

NewStringSet returns a new Set[string]

func (Set[T]) Add

func (s Set[T]) Add(val T) bool

Add inserts a value into the Set if does not already exist. True is returned only if the value was inserted.

func (Set[T]) Clone

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

Clone returns a new independent copy of the set.

func (Set[T]) Contains

func (s Set[T]) Contains(val T) bool

Contains checks if a value is in the set.

func (Set[T]) Keys

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

Keys returns the set elements as a slice in an unpredictable order.

func (Set[T]) Merge

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

Merge adds all elements from another set into this one.

func (Set[T]) Remove

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

Remove deletes a value from the set.

func (Set[T]) Set

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

Set inserts a value into the set.

func (Set[T]) SetAll

func (s Set[T]) SetAll(vals []T)

func (Set[T]) Sorted

func (s Set[T]) Sorted(less func(a, b T) int) []T

Sorted returns the set elements as a sorted slice.

type StringCounterSet

type StringCounterSet = CounterSet[string]

StringCounterSet is CounterSet with string keys

func NewStringCounterSet

func NewStringCounterSet() StringCounterSet

NewStringCounterSet returns a new StringCounterSet

func NewStringCounterSetCap

func NewStringCounterSetCap(capacity int) StringCounterSet

NewStringCounterSetCap returns a new StringCounterSet with a capacity set.

Jump to

Keyboard shortcuts

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