set

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package set contains some nifty tools for manipulating sets of data, including implementations for slices AND maps. This package should probably make its way into rosetta, once things settle down.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy[V Value, S Set[V]](from S, to S)

Copy returns a new store that contains the same items as the given store.

func Each

func Each[V Value, S Set[V]](set Set[V], f func(V))

Each calls the given function for each item in the set.

func Intersect

func Intersect[V Value, S Set[V]](left S, right S, target S)

Intersect returns a new store that contains only the items that are in both stores.

func MaxKey

func MaxKey[V Value, S Set[V]](set S) string

MaxKey returns the key of the item with the largest value.

func Reduce

func Reduce[V Value, S Set[V], R any](set S, f func(V, R) R) R

Reduce performs a "reduce" operation on the given store.

Types

type Map

type Map[V Value] map[string]V

Map is a simple in-memory map-based set for arbitrary data.

func NewMap

func NewMap[V Value](values ...V) Map[V]

NewMap returns a new Map that is populated with the given items.

func (Map[V]) Delete

func (set Map[V]) Delete(key string)

Delete removes an item from the set.

func (Map[V]) Get

func (set Map[V]) Get(key string) (V, bool)

Get returns the object with the given ID. If no object with the given ID is found, Get returns an empty object.

func (Map[V]) GetAll

func (set Map[V]) GetAll() <-chan V

GetAll returns a channel that will yield all of the items in the set.

func (Map[V]) Keys

func (set Map[V]) Keys() []string

Keys returns a list of all the keys in the set.

func (Map[V]) Len

func (set Map[V]) Len() int

Len returns the number of items in the set.

func (Map[V]) Put

func (set Map[V]) Put(value V)

Put adds/updates an item in the set.

type Set

type Set[V Value] interface {
	Len() int
	Keys() []string
	Get(key string) (V, bool)
	GetAll() <-chan V
	Put(value V)
	Delete(key string)
}

TODO: Should we migrate the `set` package to Rosetta? Interop with other libs, like `sliceof` and `mapof`? Set interface defines the functions that a set must implement

type Slice

type Slice[V Value] []V

Slice is a simple in-memory slice-based set for arbitrary data.

func NewSlice

func NewSlice[V Value](values ...V) Slice[V]

NewSlice returns a new Slice that is populated with the given items.

func (*Slice[V]) Append added in v0.6.0

func (set *Slice[V]) Append(value V)

func (*Slice[V]) Delete

func (set *Slice[V]) Delete(key string)

Delete removes an item from the set.

func (Slice[V]) Get

func (set Slice[V]) Get(key string) (V, bool)

Get returns the object with the given ID. If no object with the given ID is found, Get returns an empty object.

func (Slice[V]) GetAll

func (set Slice[V]) GetAll() <-chan V

GetAll returns a channel that will yield all of the items in the store.

func (*Slice[V]) GetPointer added in v0.6.0

func (set *Slice[V]) GetPointer(name string) (any, bool)

func (Slice[V]) Keys

func (set Slice[V]) Keys() []string

Keys returns a list of all the keys in the set.

func (Slice[V]) Len

func (set Slice[V]) Len() int

Len returns the number of items in the set.

func (Slice[V]) Length

func (set Slice[V]) Length() int

func (Slice[V]) Less

func (set Slice[V]) Less(i int, j int) bool

func (*Slice[V]) Put

func (set *Slice[V]) Put(value V)

Put adds/updates an item in the set.

func (*Slice[V]) Remove

func (set *Slice[V]) Remove(name string)

func (*Slice[V]) Sort

func (set *Slice[V]) Sort()

func (*Slice[V]) Swap

func (set *Slice[V]) Swap(i int, j int)

type Value

type Value interface {
	ID() string
}

Value interface represents a keyed value that can be stored in a set

Jump to

Keyboard shortcuts

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