bitmatrix

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: MIT Imports: 5 Imported by: 0

README

bitmatrix

GoDoc

BitMatrix provides an efficient bit matrix implementation.

This is inspired by Kjeld Petersen's BinMatrix implementation (https://senseis.xmp.net/?BinMatrix#diag6).

The BitMatrix can be used as an efficient data structure for the implementation of boardgames where are there are two types of stones, like Go, Checkers, Othelo, Connect4.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeWidth

func EncodeWidth(x int, y int, w int) int

Types

type BitMatrix

type BitMatrix interface {
	// New returns a new BitMatrix. It does not change the receiver.
	New(size int) BitMatrix

	// None sets all the bits of the receiver matrix to 0.
	// It returns the receiver matrix to support chaining.
	None() BitMatrix

	// Size returns the size of the matrix size x size.
	// It does not change the receiver matrix.
	Size() int

	// Set sets the index position in the receiver matrix to 1.
	// It returns the receiver matrix to support chaining.
	Set(index int) BitMatrix

	// Is returns true if the bit at the index is 1.
	// It does not change the receiver matrix.
	Is(index int) bool

	// Equal compares the receiver matrix with the argument matrix.
	// It does not change the receiver matrix.
	Equal(matrix BitMatrix) bool

	// Count returns the number of 1 bits of the receiver matrix.
	// It does not change the receiver matrix.
	Count() int

	// Clones creates and returns a clone of the receiver matrix.
	// It does not change the receiver matrix.
	Clone() BitMatrix

	// Up shifts all the bits of the receiver matrix up.
	// The bottom row is filled with 0s.
	// It returns the receiver matrix to support chaining.
	Up() BitMatrix

	// Down shifts all the bits of the receiver matrix down.
	// The top row is filled with 0s.
	// It returns the receiver matrix to support chaining.
	Down() BitMatrix

	// Left shifts all the bits of the receiver matrix to the left.
	// The leftmost column is filled with 0s.
	// It returns the receiver matrix to support chaining.
	Left() BitMatrix

	// Right shifts all the bits of the receiver matrix to the right.
	// The rightmost column is filled with 0s.
	// It returns the receiver matrix to support chaining.
	Right() BitMatrix

	// Inverse inverts all bits of receiver matrix.
	// It returns the receiver matrix to support chaining.
	Inverse() BitMatrix

	// Or performs a boolean OR operation of the receiver and the argument matrix.
	// The receiver is changed to the result of the operation.
	// It returns the receiver matrix to support chaining.
	Or(BitMatrix) BitMatrix

	// And performs a boolean AND operation of the receiver and the argument matrix.
	// The receiver is changed to the result of the operation.
	// It returns the receiver matrix to support chaining.
	And(BitMatrix) BitMatrix

	// Xor performs a boolean XOR operation of the receiver and the argument matrix.
	// The receiver is changed to the result of the operation.
	// It returns the receiver matrix to support chaining.
	Xor(BitMatrix) BitMatrix

	// Minuns performs a boolean MINUS operation of the receiver and the argument matrix.
	// The receiver is changed to the result of the operation.
	// It returns the receiver matrix to support chaining.
	Minus(BitMatrix) BitMatrix

	// Read reads the board 2 dimensional slice and sets all the bits of the receiver matrix.
	// It returns the receiver matrix to support chaining.
	Read(board [][]int) BitMatrix
}

func New

func New(size int) BitMatrix

New creates a size x size matrix of bits

Jump to

Keyboard shortcuts

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