vector

package
v0.0.0-...-ada8b72 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package vector implements an immutable persistent vector.

An immutable persistent vector has copy-on-write behaviour: Each “modification” of the vector (insertion, replacement or deletion) creates a copy, leaving the original unmodified. Under the hood, copy-on-write retains most of the memory held by the original, and creates a new incarnation of parts of the structure only. Thus, most of the structure/memory is shared between original and copy, transparently to clients.

Immutable vectors are inherently concurrency-safe.

Status

Awaiting Go 1.18 with generics.

License

Governed by a 3-Clause BSD license. License file may be found in the root folder of this module.

Copyright © 2022 Norbert Pillmayer <norbert@pillmayer.com>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	// contains filtered or unexported fields
}

Option is a type to help initializing vectors at creation time.

func DegreeExponent

func DegreeExponent(n int) Option

DegreeExponent is an option to indirectyl set the degree of the underlying tree for a vector. The degree of the tree will be 2^exp. Accepted exponents are [1…5]; default is 3, i.e. a degree of 8.

Use it like this:

vec := vector.Immutable[int](DegreeExponent(5))

type Vector

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

func Immutable

func Immutable[T any](opts ...Option) Vector[T]

func (Vector[T]) Get

func (v Vector[T]) Get(i int) T

func (Vector[T]) Last

func (v Vector[T]) Last() maybe.Maybe[T]

func (Vector[T]) Len

func (v Vector[T]) Len() int

func (Vector[T]) Pop

func (v Vector[T]) Pop() Vector[T]

func (Vector[T]) Push

func (v Vector[T]) Push(value T) Vector[T]

func (Vector[T]) Set

func (v Vector[T]) Set(i int, value T) Vector[T]

Jump to

Keyboard shortcuts

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