unstable

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Entries

func Entries[A constraints.Ordered, V any](t *Table[A, V]) []*base.Pair[A, V]

Entries returns a sorted slice of entries, using the natural sort order

of the table's keys

Types

type Table

type Table[A any, V any] struct {
	Set     func(A, V) bool
	Delete  func(A) *V
	Get     func(A) *V
	Len     func() int
	ToSlice func() []*base.Pair[A, V]
	Merge   func(*Table[A, V]) *Table[A, V]
	//Intersect  func(*Table[A, V]) *Table[A, *Pair[V, V]]
	//Difference func(*Table[A, V]) *Table[A, V]
	Iterator func() iterable.Iterator[*base.Pair[A, V]]
}

func Empty

func Empty[A comparable, V any]() *Table[A, V]

func FromSlice

func FromSlice[A comparable, V any](elems []*base.Pair[A, V]) *Table[A, V]

func FromSliceBy

func FromSliceBy[A any, K comparable, V any](projection func(A) K, elems []*base.Pair[A, V]) *Table[A, V]

func NewTable

func NewTable[A comparable, V any](elems iterable.Iterable[*base.Pair[A, V]]) *Table[A, V]

func NewTableBy

func NewTableBy[A any, K comparable, V any](projection func(A) K, initialElements iterable.Iterable[*base.Pair[A, V]]) *Table[A, V]

NewTableBy allows creation of a table from an element type which isn't comparable.

Why is 'comparable' required?  Because this table implementation uses a map.
Unfortunately, it's not possible to add implementations of user-defined types for comparable.
This uses a projection function to create a `comparable` key.
VERY VERY VERY IMPORTANT NOTES about the projection function:
- it should be a pure function (no side effects)
- it should make intuitive sense
- don't mix tables which use different projections -- the results will be unpredictable and won't make sense

func (*Table[A, V]) Contains

func (t *Table[A, V]) Contains(a A) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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