fixvec

package
v0.0.0-...-f51322b Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT, MIT Imports: 1 Imported by: 0

README

fixvec

fixvec is a Go library for a vector representation of values using fixed bits.

fixvec provides a vector representation of value using fixed bits. Conceptually, fixvec represents a vector V[0...num), and each value V[i] can represent in [0...2^(blen)). The total working space is num * blen bits (+ some small overhead).

Usage

import "github.com/hillbig/fixvec"

// fv represents V[0...1000), 0 <= V[i] < 2^10
// fv requires 1000 * 10 = 10000bits = 1250 bytes.
fv := fixvec.New(1000, 10)  
                               
// use Set(ind, val) to set value V[ind]= val
fv.Set(10, 777)

// use Get(ind) to get value V[ind]
fmt.Printf("%d\n", fv.Get(10)) // 777

// Encode to binary representation
bytes, err := fv.MarshalBinary() 

// Decode from binary presentation
newfv := fixvec.NewFixVec(0, 0)
err := newfv.UnmarshalBinary(bytes) 

Documentation

Overview

package fixvec provides a vector representation of value using fixed bits

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FixVec

type FixVec interface {
	// Get returns V[ind]
	Get(ind uint64) uint64

	// Set sets V[ind] = val (val will be masked by &((1 << blen) -1))
	Set(ind uint64, val uint64)

	// Blen returns the number of bits for value representation
	Blen() uint8

	// KeysNum returns the number of elemens in V
	Num() uint64

	// MarshalBinary encodes FixVec into a binary form and returns the result.
	MarshalBinary() ([]byte, error)

	// UnmarshalBinary decodes the FixVec from a binary from generated MarshalBinary
	UnmarshalBinary([]byte) error
}

FixVec provides a vector representation of value using fixed bits Conceptually, FixVec represents a vector V[0...num), and each value V[i] can represent in [0...2^(blen)) The total working space is num * blen bits (+ some small overhead).

func New

func New(n uint64, bl uint8) FixVec

New returns FixVec represents V[0...n) where each element is less than (1 << blen).

func NewFromArray

func NewFromArray(vs []uint64) FixVec

NewFromArray returns a FixVec represents V[0...n) where each element V[i] equals to vs[i]

Jump to

Keyboard shortcuts

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