matrix

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: MIT Imports: 1 Imported by: 0

README

matrix

Coverage

Go Report Card Go Reference

All you need to work with matrix

Documentation

Index

Constants

View Source
const (
	InvalidIndexError = "InvalidIndexError"
	NilMatrixObject   = "NilMatrixObject"
	InvalidMatrixSize = "InvalidMatrixSize"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Matrix

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

Matrix represent simple square of any type data

func NewMatrix

func NewMatrix[T any](data []T, rows, columns int) (*Matrix[T], error)

New Matrix create matrix from slice of data with spicified size

func NewMatrixFromPoints added in v1.3.0

func NewMatrixFromPoints[T any](points PairIterator, value T) *Matrix[T]

NewMatrixFromPoints create matrix of int with filled by `value` cells from `points`. Other cells filled by default value for type T.

func NewZeroMatrix

func NewZeroMatrix[T any](rows, columns int) *Matrix[T]

NewZeroMatrix create default initialized matrix with specified size

func (*Matrix[T]) AllOfColumn

func (m *Matrix[T]) AllOfColumn(col int, f func(cell T) bool) (bool, error)

AllOfColumn check `f` for each value on `col`

func (*Matrix[T]) AllOfRow

func (m *Matrix[T]) AllOfRow(row int, f func(cell T) bool) (bool, error)

AllOfRow check `f` for each value on `row`

func (*Matrix[T]) AnyOfPoints added in v1.1.0

func (m *Matrix[T]) AnyOfPoints(points PairIterator, f func(cell T) bool) (bool, error)

AnyOfPoints check if for any of `points` success functor `f`

func (*Matrix[T]) ColumnData

func (m *Matrix[T]) ColumnData(col int) ([]T, error)

ColumnData get slice of values stored in spicified column

func (*Matrix[T]) Filtered added in v1.2.0

func (m *Matrix[T]) Filtered(f func(cell T) bool) ([]struct{ Row, Column int }, error)

Filtered get slice of points {row, column} represents matrix points which satisfy `f`

func (*Matrix[T]) Get added in v1.1.0

func (m *Matrix[T]) Get(row, column int) (T, error)

Get `value` from matrix on [row,column]

func (*Matrix[T]) MirrorColumns added in v1.2.0

func (m *Matrix[T]) MirrorColumns() error

MirrorColumns reverse column order

func (*Matrix[T]) MirrorRows added in v1.2.0

func (m *Matrix[T]) MirrorRows() error

MirrorRows reverse row order

func (*Matrix[T]) RemoveRow added in v1.3.0

func (m *Matrix[T]) RemoveRow(r int) error

RemoveRow remove `r` row and shift previous rows down

func (*Matrix[T]) Rotate added in v1.2.0

func (m *Matrix[T]) Rotate() error

Rotate rotate matrix to 90 grad

func (*Matrix[T]) RowData

func (m *Matrix[T]) RowData(row int) ([]T, error)

RowData get slice of values stored in spicified row

func (*Matrix[T]) Set added in v1.1.0

func (m *Matrix[T]) Set(row, column int, value T) error

Set value `value` to cell [row, column]

func (*Matrix[T]) SetBatch added in v1.1.0

func (m *Matrix[T]) SetBatch(value T, points PairIterator) error

SetBatch set `value` to each point [row, column] from slice `points`

func (*Matrix[T]) ShiftRowsDown

func (m *Matrix[T]) ShiftRowsDown() error

ShiftRowsDown shift all rows down to 1 row. First row make default values row.

func (*Matrix[T]) Transpose added in v1.2.0

func (m *Matrix[T]) Transpose() error

Transpose transpose matrix

type PairIterator added in v1.2.0

type PairIterator interface {
	// Begin set iterator to begin
	Begin()
	// Next iterate to the next element or to the first element (if it is first call) and return true if element exists
	Next() bool
	// First get first value from pair
	First() int
	// Second get second value from pair
	Second() int
}

PairIterator interface for iteraing on any collection with 2 values

Jump to

Keyboard shortcuts

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