ds

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package ds implements common generic data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapSlice

func MapSlice[T, R any](input []T, f func(T) R) []R

Map elements of one slice and create a new slice with those mapped values.

func ReverseSeq

func ReverseSeq[V any](i iter.Seq[V]) iter.Seq[V]

Reverse a Seq

func ReverseSeq2

func ReverseSeq2[K comparable, V any](i iter.Seq2[K, V]) iter.Seq2[K, V]

Reverse a Seq2

func ReverseSlice

func ReverseSlice[V any](s []V) iter.Seq[V]

Iterate over the elements of a slice in reverse order.

Types

type OrderedMap

type OrderedMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

OrderedMap implements a map with ordered keys. It iterates in insertion order.

func MakeOrderedMap

func MakeOrderedMap[K comparable, V any]() OrderedMap[K, V]

MakeOrderedMap creates a new ordered map value

func NewOrderedMap

func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]

NewOrderedMap instantiates a new ordered map

func NewOrderedMapWithCap

func NewOrderedMapWithCap[K comparable, V any](cap int) *OrderedMap[K, V]

NewOrderedMap instantiates a new ordered map with the given capacity

func NewOrderedMapWithPairs

func NewOrderedMapWithPairs[K comparable, V any](pairs ...Pair[K, V]) *OrderedMap[K, V]

NewOrderedMap instantiates a new ordered map with the given pairs

func (*OrderedMap[K, V]) All

func (m *OrderedMap[K, V]) All() iter.Seq2[K, V]

All returns an iterator that iterates over all key value pairs in insertion order

func (*OrderedMap[K, V]) Delete

func (m *OrderedMap[K, V]) Delete(key K) bool

Delete removes the given key and returns true when the key was found

func (*OrderedMap[K, V]) Get

func (m *OrderedMap[K, V]) Get(key K) V

Get return the value for the given key

func (*OrderedMap[K, V]) GetOk

func (m *OrderedMap[K, V]) GetOk(key K) (V, bool)

GetOK returns the value for the given key an a bool flag that is false when the key is not present

func (*OrderedMap[K, V]) Includes

func (m *OrderedMap[K, V]) Includes(key K) bool

Includes checks if the given key exists within the map

func (*OrderedMap[K, V]) Insert

func (m *OrderedMap[K, V]) Insert(key K, val V) bool

Insert adds a new pair if the key is not already present in the map otherwise it does nothing and returns false

func (*OrderedMap[K, V]) InsertGet

func (m *OrderedMap[K, V]) InsertGet(key K, val V) V

Insert adds a new pair if the key is not already present in the map and returns the newly added value otherwise it does nothing and returns the already existing value

func (*OrderedMap[K, V]) Set

func (m *OrderedMap[K, V]) Set(key K, val V) *OrderedMap[K, V]

Set adds a new key value pair or sets an existing key to the given value

type Pair

type Pair[K comparable, V any] struct {
	Key   K
	Value V
}

func MakePair

func MakePair[K comparable, V any](key K, val V) Pair[K, V]

func NewPair

func NewPair[K comparable, V any](key K, val V) *Pair[K, V]

type Set

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

func MakeSet

func MakeSet[V comparable](values ...V) Set[V]

func (Set[V]) Add

func (s Set[V]) Add(val V)

func (Set[V]) Concat

func (s Set[V]) Concat(sets ...Set[V]) Set[V]

Returns a new set containing the elements of all given sets

func (Set[V]) ConcatMut

func (s Set[V]) ConcatMut(sets ...Set[V])

Mutate the set by adding the elements of all given sets

func (Set[V]) Contains

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

func (Set[V]) Remove

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

Jump to

Keyboard shortcuts

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