collections

package module
v0.0.0-...-f0935ab Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: Unlicense Imports: 1 Imported by: 3

README

Badgerodon Collections

Useful collections:

  • Deque
  • List
  • Map
  • Queue
  • Set
  • Stack

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSlice

func NewSlice[T any](collection Collection[T]) []T

NewSlice creates a new slice from a collection.

Types

type Collection

type Collection[T any] interface {
	ForEach(callback func(T) bool)
	Size() int
}

func Map

func Map[TFrom, TTo any](c Collection[TFrom], f func(TFrom) TTo) Collection[TTo]

Map maps all the values in a collection to a new collection.

type Deque

type Deque[T any] interface {
	Clear()
	PeekBack() (value T, ok bool)
	PeekFront() (value T, ok bool)
	PopBack() (value T, ok bool)
	PopFront() (value T, ok bool)
	PushBack(value T)
	PushFront(value T)
	Size() int
}

A Deque is a double-ended queue.

func NewDeque

func NewDeque[T any]() Deque[T]

NewDeque creates a new Deque implemented using a slice as a ring buffer.

type Dictionary

type Dictionary[TKey, TValue any] interface {
	Clear()
	Delete(key TKey)
	ForEach(callback func(Pair[TKey, TValue]) bool)
	Get(key TKey) (value TValue, ok bool)
	Keys() Collection[TKey]
	Set(key TKey, value TValue)
	Size() int
	Values() Collection[TValue]
}

A Dictionary is a collection of key value pairs.

func NewDictionary

func NewDictionary[TKey comparable, TValue any]() Dictionary[TKey, TValue]

NewDictionary creates a new Dictionary implemented using a map.

func NewSortedDictionary

func NewSortedDictionary[TKey, TValue any](less func(TKey, TKey) bool) Dictionary[TKey, TValue]

NewSortedDictionary creates a new Dictionary implemented using a btree, providing sorted iteration by the less function.

type Pair

type Pair[T1, T2 any] struct {
	First  T1
	Second T2
}

A Pair is a pair of values.

func NewPair

func NewPair[T1, T2 any](first T1, second T2) Pair[T1, T2]

NewPair creates a new Pair.

type Queue

type Queue[T any] interface {
	Clear()
	Peek() (value T, ok bool)
	Pop() (value T, ok bool)
	Push(value T)
	Size() int
}

A Queue is a collection that supports FIFO operations.

func NewQueue

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

NewQueue creates a new Queue implemented using a slice.

type Set

type Set[T any] interface {
	Add(value T)
	Clear()
	Delete(value T)
	ForEach(callback func(T) bool)
	Has(value T) bool
	Size() int
}

A Set is a unique collection of values.

func NewSet

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

NewSet creates a new Set implemented using a map.

func NewSortedSet

func NewSortedSet[T any](less func(T, T) bool) Set[T]

NewSortedSet creates a new Set implemented using a btree, providing sorted iteration by the less function.

type Stack

type Stack[T any] interface {
	Clear()
	Peek() (value T, ok bool)
	Pop() (value T, ok bool)
	Push(value T)
	Size() int
}

A Stack is a collection that supports LIFO operations.

func NewStack

func NewStack[T any]() Stack[T]

NewStack creates a new Stack implemented using a slice.

Jump to

Keyboard shortcuts

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