vector

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package vector contains binary vector abstractions.

Index

Constants

View Source
const MaxInteger = ^word(0)
View Source
const WordSize = uint(unsafe.Sizeof(word(0))) << 3

Variables

This section is empty.

Functions

This section is empty.

Types

type Vector

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

Vector represents binary vector This type is immutable

func New

func New() *Vector

New returns empty vector

func (*Vector) And

func (v *Vector) And(u, w *Vector) *Vector

And sets v to u AND w and returns v

func (*Vector) Bits

func (v *Vector) Bits() []byte

Bits returns all bits of vector as slice of bytes

func (*Vector) Cmp

func (v *Vector) Cmp(u *Vector) int

Cmp compares vector v and vector u and returns -1 if v < u

0 if v == u
1 if v > u

v < u if len(u) > len(v) or len(u)==len(v) and for some i holds v[0]=u[0],..., v[i-1]=u[i-1], v[i] < u[i] For example,

10 < 000110
000010 < 000110

func (*Vector) Concatenate

func (v *Vector) Concatenate(u, w *Vector) *Vector

Concatenate sets v to concatenation of u and w and returns v

func (*Vector) Get

func (v *Vector) Get(i uint) byte

Get returns i-th bit of vector

func (*Vector) Iter

func (v *Vector) Iter() <-chan byte

Iter iterates over elements

func (*Vector) LaTeXString

func (v *Vector) LaTeXString() string

LaTeXString returns string of vector representation to use in LaTeX matrix environment Example: 0101011 -> 0&1&0&1&0&1&1

func (*Vector) Len

func (v *Vector) Len() uint

Len returns length of vector v

func (*Vector) Not

func (v *Vector) Not(u *Vector) *Vector

Not sets v to ^u and returns v

func (*Vector) Or

func (v *Vector) Or(u, w *Vector) *Vector

Or sets v to u OR w and returns v

func (*Vector) Parse

func (v *Vector) Parse(s string) (*Vector, error)

Parse converts string to Vector and sets v to result, returns v Function supports the following filler for zero symbol:

"0" == "0", "-", "*"

Example:

"--110-1- - - 1-  * 11 0 " -> 0011001000100110

func (*Vector) PrettyString

func (v *Vector) PrettyString() string

PrettyString returns pretty formatted string of vector representation Example: 0101011 -> -1-1-11

func (*Vector) Resize

func (v *Vector) Resize(w *Vector, r int) *Vector

Resize resizes vector w and sets the result to v, returns v

func (*Vector) RotateLeft

func (v *Vector) RotateLeft(w *Vector, r uint) *Vector

RotateLeft cyclical shifts vector w for r position left and sets vector v to shifted w, returns v That's it v = w rotl r

func (*Vector) RotateRight

func (v *Vector) RotateRight(w *Vector, r uint) *Vector

RotateRight cyclical shifts vector w for r position right and sets vector v to shifted w, returns v That's it v = w rotr r

func (*Vector) SetBit

func (v *Vector) SetBit(w *Vector, i uint, b byte) *Vector

SetBit sets v to vector w with change coordinate i by bit b % 2 m = w[i] <- b%2

func (*Vector) SetBitArray

func (v *Vector) SetBitArray(array []byte) *Vector

SetBitArray converts bit array to Vector and sets v to the result

func (*Vector) SetBytes

func (v *Vector) SetBytes(b []byte, n uint) *Vector

SetBytes packs byte array b into the vector of length n and sets v to that new vector

Examples:
SetBytes([]byte{0x01, 0x02, 0x03}, 24) -> 000000010000001000000011
SetBytes([]byte{0x01, 0x02, 0x03}, 11) -> 00000001000
SetBytes([]byte{0x01, 0x02, 0x03}, 30) -> 000000010000001000000011000000
SetBytes([]byte{}, 3) -> 000

func (*Vector) SetRandom

func (v *Vector) SetRandom(n uint) *Vector

SetRandom sets v to a random vector of length n

func (*Vector) SetSupport

func (v *Vector) SetSupport(n uint, sup []uint) *Vector

SetSupport sets v to vector with units from the support array Example:

v.SetSupport(10, []int{0, 1, 5, 9}) -> 1100010001

func (*Vector) SetUnits

func (v *Vector) SetUnits(n uint) *Vector

SetUnits sets v to a units vector of length n

func (*Vector) SetV

func (v *Vector) SetV(u *Vector) *Vector

SetV sets v to u, returns v

func (*Vector) SetZero

func (v *Vector) SetZero(n uint) *Vector

SetZero sets v to a units vector of length n, returns v

func (*Vector) ShiftLeft

func (v *Vector) ShiftLeft(w *Vector, r uint) *Vector

ShiftLeft shifts vector w for r position left and sets vector v to shifted w, returns v That's it v = w << r

func (*Vector) ShiftRight

func (v *Vector) ShiftRight(w *Vector, r uint) *Vector

ShiftRight shifts vector w for r position right and sets vector v to shifted w, returns v That's it v = w >> r

func (*Vector) String

func (v *Vector) String() string

String returns string representation of Vector

func (*Vector) Support

func (v *Vector) Support() []uint

Support returns support of vector. support is set of 1's indexes of vector

func (*Vector) Wt

func (v *Vector) Wt() uint

Wt returns Hamming weight of vector

func (*Vector) Xor

func (v *Vector) Xor(u, w *Vector) *Vector

Xor sets v to u XOR w and returns v

func (*Vector) Zeros

func (v *Vector) Zeros() []uint

Zeros returns set of 0's indexes of vector.

Jump to

Keyboard shortcuts

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