segmented

package
v0.0.0-...-ecc870c Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package segmented provides a 2-dimensional indexed append-only array type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array[K hamap.KeyInterface, T any] struct {
	// contains filtered or unexported fields
}

Array is a 2D indexed append-only array where each segment is indexed by a key.

func New

func New[K hamap.KeyInterface, T any]() *Array[K, T]

New allocates a new instance of an indexed 2D append-only array.

func (*Array[K, T]) Append

func (i *Array[K, T]) Append(t ...T)

Append appends onto the last uncommited segment.

func (*Array[K, T]) Cut

func (i *Array[K, T]) Cut(key K) (s Segment)

Cut commits the pending segment under key and returns the segment identifier. Returns Segment{Start: -1} if the key already exists.

func (*Array[K, T]) Get

func (i *Array[K, T]) Get(key K) Segment

Get returns the segment by key. Returns nil if key doesn't exist.

func (*Array[K, T]) GetItems

func (i *Array[K, T]) GetItems(key K) []T

GetItems returns the segment items by key. Returns nil if key doesn't exist.

func (*Array[K, T]) GetSegment

func (i *Array[K, T]) GetSegment(s Segment) []T

GetSegment returns the segment.

func (*Array[K, T]) Len

func (i *Array[K, T]) Len() int

Len returns the number of stored segments.

func (*Array[K, T]) Reset

func (i *Array[K, T]) Reset()

Reset removes all stored segments.

func (*Array[K, T]) VisitAll

func (i *Array[K, T]) VisitAll(fn func(key K, s Segment))

VisitAll calls fn for every stored segment.

type Segment

type Segment struct{ Index, Start, End int }

Segment defines the logical index and the start and end indexes of a segment.

Jump to

Keyboard shortcuts

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