ds

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ds provides some fundamental data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendMap

func AppendMap[K comparable, V any, M ~map[K]V](m *M, key K, value V)

AppendMap appends key to the map, optionally initializing map if nil.

func Equals

func Equals[T comparable](s, t []T) bool

func HasSuffix

func HasSuffix[T comparable](s, suffix []T) bool

func MergeMap

func MergeMap[K comparable, V any](m1, m2 map[K]V) map[K]V

func SliceOfPtr

func SliceOfPtr[T any](s []T) []*T

Types

type Mutex

type Mutex[K comparable] struct {
	// contains filtered or unexported fields
}

Mutex is a simple replacement for golang.org/x/sync/singleflight. Includes ideas from https://cs.opensource.google/go/x/sync/+/master:singleflight/singleflight.go;drc=30421366ff761c80b137fb5084b32278ed41fab0.

func NewMutex

func NewMutex[K comparable]() *Mutex[K]

func (*Mutex[K]) Lock

func (m *Mutex[K]) Lock(key K)

func (*Mutex[K]) TryLock

func (m *Mutex[K]) TryLock(key K) (ok bool)

func (*Mutex[K]) Unlock

func (m *Mutex[K]) Unlock(key K)

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue represents a simple queue.

TODO: switch to github.com/emirpasic/gods once generics version is out?

func NewQueue

func NewQueue[T any]() *Queue[T]

func (*Queue[T]) DeleteIf

func (q *Queue[T]) DeleteIf(predicate func(elt T) bool) (deleted int)

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

func (*Queue[T]) Pop

func (q *Queue[T]) Pop() (elt T)

func (*Queue[T]) Push

func (q *Queue[T]) Push(elt T)

Jump to

Keyboard shortcuts

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