table

package
v0.0.0-...-917641f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package table implements a loose 2d collection of values

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sparse

type Sparse struct {
	RowIDs, ColIDs types.A
	Data           types.M
}

Sparse represents a table where the data is stored in a map accessed by the row and column ids. Not all row-col pairs may have a corresponding value (hence the sparse). In addition, deletion of rowIDs and column IDs do not automatically delete the corresponding data -- that is expected to be handled in a late garbage-collection phase.

The row ID and column ID collections can also be used to store other row-ID specific or column-ID specific data but in that case, the caller must implement a rowKey and/or colKey function that maps these to the corresponding key in the data map. This is only used by GC().

Under some very contrived conditions, RowIDs and ColIDs may contain duplicates. For this reason, the callers should take care when iterating these arrays. To maintain consistency, only the first occurrence of an ID should be considered and all further occurrences ignored.

func (Sparse) Apply

func (s Sparse) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value:Apply

func (Sparse) Cell

func (s Sparse) Cell(row, col interface{}) (interface{}, bool)

Cell returns the value at a given cell position. The bool return value indicates if the element exists or not

func (Sparse) GC

func (s Sparse) GC(rowKey, colKey func(interface{}) interface{}) (Sparse, changes.Change)

GC finds all cells that are orphaned by prior row/column deletes and clears them out. It returns the changes matching the delete as well. The rowKey and colKey functions provide the mapping from the corresponding IDs to the key. These can be nil to indicate the IDs are themselves the keys into the Data map.

func (Sparse) RemoveCell

func (s Sparse) RemoveCell(row, col interface{}) (Sparse, changes.Change)

RemoveCell removes the value of a cell (which need not exist)

func (Sparse) SpliceCols

func (s Sparse) SpliceCols(offset, remove int, ids []interface{}) (Sparse, changes.Change)

SpliceCols splices a set of colIDs at the provided offset, first removing the specified count of IDs

func (Sparse) SpliceRows

func (s Sparse) SpliceRows(offset, remove int, ids []interface{}) (Sparse, changes.Change)

SpliceRows splices a set of rowIDs at the provided offset, first removing the specified count of IDs.

func (Sparse) UpdateCell

func (s Sparse) UpdateCell(row, col, value interface{}) (Sparse, changes.Change)

UpdateCell updates the value of a cell (which need not exist)

Jump to

Keyboard shortcuts

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