bitarray

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2017 License: MIT Imports: 4 Imported by: 2

README

BitArray for Golang Build Status GoDoc

Installation

go get github.com/damnever/bitarray

Example

package main

import "github.com/damnever/bitarray"

func main() {
    bits := bitarray.New(64)

    bits.Put(8, 1)  // set value of the bit to 1 by index 8, return old bit.
    bits.Get(8)     // get value of the bit by index 8
    bits.Set(9, 16) // set all bits to 1 between 9 and 16 , both 9 and 16 included.
    bits.Count()   // get the count of bit 1
    // Clear/Not/Eq/Leq/Lt/ToArray ...
}

Documentation

Overview

BitArray for Golang.

Index

Constants

View Source
const (
	BitsPW int = _BytesPW * 8
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BitArray

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

func New

func New(length int) *BitArray

New create a new BitArray with length(bits).

func (*BitArray) Clear

func (bits *BitArray) Clear(low int, high int) error

Clear set the value of all bits to 0, which index range between low and high, both low and high included. low must less than high, and low/high cannot out of range [0, BitArray.Len()).

func (*BitArray) Count

func (bits *BitArray) Count() int

Count return the count of bit 1.

func (*BitArray) Eq

func (bits *BitArray) Eq(obits *BitArray) bool

Eq check whether the BitArray is equal to another BitArray. If length isn't same, return false.

func (*BitArray) Get

func (bits *BitArray) Get(n int) (int, error)

Get return the bit by index n. If index out of range [0, BitArray.Len()), return error.

func (*BitArray) Len

func (bits *BitArray) Len() int

Len return the length of the BitArray.

func (*BitArray) Leq

func (bits *BitArray) Leq(obits *BitArray) bool

Leq check whether the BitArray is the subset of the another. If length isn't same, return false.

func (*BitArray) Lt

func (bits *BitArray) Lt(obits *BitArray) bool

Lt check whether the BitArray is the proper subset of the another. If length isn't same, return false.

func (*BitArray) Not

func (bits *BitArray) Not(low int, high int) error

Not flips the value of all bits, which index range between low and high, both low and high included. low must less than high, and low/high cannot out of range [0, BitArray.Len()).

func (*BitArray) Put

func (bits *BitArray) Put(n int, bit int) (int, error)

Put set the nth bit with 0/1, and return the old value of nth bit. If index out of range [0, BitArray.Len()), return error.

func (*BitArray) Set

func (bits *BitArray) Set(low int, high int) error

Set the value of all bits to 1, which index range between low and high, both low and high included. low must less than high, and low/high cannot out of range [0, BitArray.Len()).

func (*BitArray) ToArray

func (bits *BitArray) ToArray() []int

Convert the BitArray to a array of integers, and return.

Jump to

Keyboard shortcuts

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