util

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrByteLengthMissMatch = fmt.Errorf("provided bytes do not have the same length for bit operations")

Functions

func And

func And(dst, a []byte)

And casts the first part of the byte slices (length divisible by 8) into uint64 and then performs AND on the slices of uint64. The excess elements that could not be cast are ANDed conventionally. The whole operation is performed in place. Panic if a and dst do not have the same length. Only tested on x86-64.

func AndXor

func AndXor(dst, a, b []byte)

AndXor casts the first part of the byte slices (length divisible by 8) into uint64 and then performs AND on the slices of uint64 (with a) and then performs XOR (with b). The excess elements that could not be cast are operated on conventionally. The whole operation is performed in place. Panic if a, b and dst do not have the same length. Only tested on x86-64.

func BitExtract

func BitExtract(b []byte, i int) byte

BitExtract returns the ith bit in b

func ConcurrentBitOp

func ConcurrentBitOp(f func([]byte, []byte), dst, a []byte)

ConcurrentBitOp performs an in-place bitwise operation, f, on each byte from a with dst if they are both the same length.

func ConcurrentDoubleBitOp

func ConcurrentDoubleBitOp(f func([]byte, []byte, []byte), dst, a, b []byte)

ConcurrentDoubleBitOp performs an in-place double bitwise operation, f, on each byte from a with dst if they are both the same length

func ConcurrentTransposeTall

func ConcurrentTransposeTall(matrix [][]byte) [][]byte

ConcurrentTransposeTall tranposes a tall (64 column) matrix. If the input matrix does not have a multiple of 512 rows (tall), panic. First it determines how many 512x512 bit blocks are necessary to contain the matrix. The blocks are divided among the number of workers. If there are fewer blocks than workers, this function operates as though it were single-threaded. For those small sets, performance could be improved by limiting the number of workers to the number of blocks but this incurs a performance penalty and it is much more likely that there will be more blocks than workers/cpu cores. Each goroutine, iterates over the blocks for which it is responsible. For each block it generates a BitVect from the matrix at the appropriate index, performs a cache-oblivious, in-place, contiguous transpose on the BitVect, and finally writes the result to a shared final output matrix. The last worker is responsible for any excess blocks which were not evenly divisible into the number of workers.

func ConcurrentTransposeWide

func ConcurrentTransposeWide(matrix [][]byte) [][]byte

ConcurrentTransposeWide tranposes a wide (512 row) matrix. If the input matrix does not have a multiple of 64 columns (wide), panic. First it determines how many 512x512 bit blocks are necessary to contain the matrix. The blocks are divided among the number of workers. If there are fewer blocks than workers, this function operates as though it were single-threaded. For those small sets, performance could be improved by limiting the number of workers to the number of blocks but this incurs a performance penalty and it is much more likely that there will be more blocks than workers/cpu cores. Each goroutine iterates over the blocks for which it is responsible. For each block it generates a BitVect from the matrix at the appropriate index, performs a cache-oblivious, in-place, contiguous transpose on the BitVect, and finally writes the result to a shared final output matrix. The last worker is responsible for any excess blocks which were not evenly divisible into the number of workers.

func Count

func Count(r io.Reader) (int64, error)

Count counts the number of lines in a file

func DoubleXor

func DoubleXor(dst, a, b []byte)

DoubleXor casts the first part of the byte slices (length divisible by 8) into uint64 and then performs XOR on the slices of uint64 (first with a and then with b). The excess elements that could not be cast are XORed conventionally. The whole operation is performed in place. Panic if a, b and dst do not have the same length. Only tested on x86-64.

func Exhaust

func Exhaust(n int64, r io.Reader) <-chan []byte

Exhaust consumes all the identifiers in r, It expects that each indentifier is line separated with \n at the end of each line.

func IsBitSet

func IsBitSet(b []byte, i int) bool

IsBitSet returns true if bit i is set in a byte slice. It extracts bits from the least significant bit (i = 0) to the most significant bit (i = 7).

func Pad

func Pad(n, multiple int) int

Pad returns the total padded length such that n is padded to a multiple of multiple.

func PadBitMap

func PadBitMap(n, multiple int) int

PadBitMap returns the total padded length such that n is padded to a multiple of multiple bytes to fit in a bitmap.

func SafeReadLine

func SafeReadLine(r *bufio.Reader) (line []byte, err error)

SafeReadLine blocks until a whole line can be read or r returns an error. warning: expects lines to be \n separated

func SampleRandomBitMatrix

func SampleRandomBitMatrix(row, col int) ([][]uint8, error)

SampleRandomBitMatrix allocates a 2D byte matrix of dimension row x col, and adds extra rows of 0s to have the number of rows be a multiple of 512, fills each entry in the byte matrix with pseudorandom byte values from a rand reader.

func Sel

func Sel(ctx context.Context, f func() error) error

Sel runs a single stage for protocol

func Sels

func Sels(fs ...func() error) chan error

Sels runs multiple stages for a protocol

func Xor

func Xor(dst, a []byte)

Xor casts the first part of the byte slices (length divisible by 8) into uint64 and then performs XOR on the slices of uint64. The excess elements that could not be cast are XORed conventionally. The whole operation is performed in place. Panic if a and dst do not have the same length. Only tested on x86-64.

Types

type BitVect

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

A BitVect is a matrix of 512 by 512 bits encoded into a contiguous slice of uint64 elements.

Jump to

Keyboard shortcuts

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