bitvec

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 2 Imported by: 0

README

bitvec

fast / thread-safe bitvectors for Go.

bitvec provides performance-optimzied bit vectors. BitVec is a non-thread-safe implementation; ABitVec ensures atomicity.

Documentation

Overview

Package bitvec is bit-vector with atomic and non-atomic access

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ABitVec

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

ABitVec is a bitvector backed by an array of uint64. Bits are referenced by bucket (uint64) and bit within the bucket.

func AFromList added in v0.3.0

func AFromList(size uint64, lst []uint64) ABitVec

func NewAtomic

func NewAtomic(size uint64) ABitVec

NewAtomic returns a new bitvector with the given size

func (ABitVec) Clear

func (bv ABitVec) Clear(k uint64) error

Clear sets bit `k` to false unconditionally.

func (ABitVec) Get

func (bv ABitVec) Get(k uint64) (bool, error)

Get will return true if the bit is set; false otherwise.

func (ABitVec) GetBucket

func (bv ABitVec) GetBucket(k uint64) uint64

GetBucket returns the int64 bucket

func (ABitVec) GetBuckets4

func (bv ABitVec) GetBuckets4(a, b, c, d uint64) (x, y, z, w uint64)

GetBuckets4 returns buckets 4 at a time.

func (ABitVec) Set

func (bv ABitVec) Set(k uint64) error

Set sets bit `k` to true unconditionally.

func (ABitVec) TrySet

func (bv ABitVec) TrySet(k uint64) bool

TrySet will set the bit located at `k` if it is unset and will return true if the bit flipped, false otherwise.

func (ABitVec) TrySetWith

func (bv ABitVec) TrySetWith(old uint64, k uint64) bool

TrySetWith performs TrySet but the caller is responsible for passing in the old bucket.

type BitVec

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

BitVec is a nonatomic bit vector.

func New

func New(size uint64) BitVec

New creates a non-atomic bitvector with a given size.

func (BitVec) Clear

func (bv BitVec) Clear(k uint64) error

Clear sets bit `k` to false unconditionally.

func (BitVec) Get

func (bv BitVec) Get(k uint64) (bool, error)

Get will return true if the bit is set; false otherwise.

func (BitVec) Set

func (bv BitVec) Set(k uint64) error

Set sets bit `k` to true unconditionally.

func (BitVec) TrySet

func (bv BitVec) TrySet(k uint64) bool

TrySet will try to set the bit and will return true if set is successful, false if bit is already set.

Jump to

Keyboard shortcuts

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