bitset

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2015 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package bitset implements a Bitset and a small Bits.

Index

Constants

View Source
const (
	Uint0 uint = 0
)

u_1 is uint 1

Variables

This section is empty.

Functions

func BitCount

func BitCount(n uint64) int

BitCount return count of 1 bit in uint64

func BitCountUint

func BitCountUint(x uint) int

BitCountUint return count of 1 bit in uint

Types

type Bits

type Bits uint64

Bits is a lightweight bitset implementation based on a uint64 number, it's not safety for concurrent.

func BitsFrom

func BitsFrom(b uint) *Bits

BitsFrom create a Bits, all bits of number is copied

func BitsList

func BitsList(bits ...uint) *Bits

BitsList create a Bits, set all bits in list to 1

func NewBits

func NewBits() *Bits

func (*Bits) BitCount

func (s *Bits) BitCount() int

BitCount return the count of bits set to 1

func (*Bits) Flip

func (s *Bits) Flip(index uint)

Flip bit at given index

func (*Bits) FlipAll

func (s *Bits) FlipAll()

FlipAll flip all bits

func (*Bits) IsSet

func (s *Bits) IsSet(index uint) bool

IsSet chech whether bit at given index is set to 1

func (*Bits) Set

func (s *Bits) Set(index uint)

Set bit at given index to 1

func (*Bits) SetAll

func (s *Bits) SetAll()

SetAll set all bits to 1

func (*Bits) SetBefore

func (s *Bits) SetBefore(index uint)

SetBefore set all bits before index to 1, index bit is not included

func (*Bits) SetSince

func (s *Bits) SetSince(index uint)

SetSince set all bits since index to 1, index bit is include

func (*Bits) SetTo

func (s *Bits) SetTo(index uint, val bool)

SetTo set bit at given index to 1 if val is true, else set to 0

func (*Bits) Uint

func (s *Bits) Uint() uint

Uint return uint display of Bits

func (*Bits) Uint64

func (s *Bits) Uint64() uint64

Uint64 return uint64 display of Bits

func (*Bits) Unset

func (s *Bits) Unset(index uint)

Unset set bit at given index to 0

func (*Bits) UnsetAll

func (s *Bits) UnsetAll()

UnsetAll set all bits to 0

func (*Bits) UnsetBefore

func (s *Bits) UnsetBefore(index uint)

UnsetBefore set all bits before index to 0, index bit is not included

func (*Bits) UnsetSince

func (s *Bits) UnsetSince(index uint)

UnsetSince set all bits since index to 0, index bit is include

type Bitset

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

Bitset is a bitset based on a uint64 array

func NewBitset

func NewBitset(length uint, indexs ...uint) *Bitset

NewBitset return a new bitset with given length, all index in list are set to 1

func (*Bitset) BitCount

func (s *Bitset) BitCount() int

BitCount return 1 bits count in bitset

func (*Bitset) Bits

func (s *Bitset) Bits() []uint

Bits return all index of bits set to 1

func (*Bitset) Clone

func (s *Bitset) Clone() *Bitset

Clone return a new bitset same as current

func (*Bitset) Diff

func (s *Bitset) Diff(b *Bitset) *Bitset

Diff calculate difference between current and another bitset

func (*Bitset) Except

func (s *Bitset) Except(index ...uint) *Bitset

Except set all bits except given index to 1, the except bits set to 0

func (*Bitset) Flip

func (s *Bitset) Flip(index uint) *Bitset

Flip the index bit, expand the bitset if index out of length range

func (*Bitset) FlipAll

func (s *Bitset) FlipAll() *Bitset

FlipAll flip all the index bit

func (*Bitset) Intersection

func (s *Bitset) Intersection(b *Bitset) *Bitset

Intersection another bitset to current bitset

func (*Bitset) IsSet

func (s *Bitset) IsSet(index uint) bool

IsSet check whether or not index bit is set

func (*Bitset) Length

func (s *Bitset) Length(l uint) uint

Length change the bitset's length, if zero, only return current length.

Only when new length is larger or half less than now, the allocation will occurred

func (*Bitset) Set

func (s *Bitset) Set(index uint) *Bitset

Set set index bit to 1, expand the bitset if index out of length range

func (*Bitset) SetAll

func (s *Bitset) SetAll() *Bitset

SetAll set all bits to 1

func (*Bitset) SetTo

func (s *Bitset) SetTo(index uint, value bool) *Bitset

SetTo set index bit to 1 if value is true, otherwise 0

func (*Bitset) Uint

func (s *Bitset) Uint() uint

Uint return first uint unit

func (*Bitset) Uint64

func (s *Bitset) Uint64() uint64

Uint64 return first uint64 unit

func (*Bitset) Union

func (s *Bitset) Union(b *Bitset) *Bitset

Union union another bitset to current bitset, expand the bitset if index out of length range

func (*Bitset) UnitCount

func (s *Bitset) UnitCount() uint

UnitCount return bitset's unit count

func (*Bitset) UnitLen

func (s *Bitset) UnitLen() uint

UnitLen return unit length of bitset

func (*Bitset) Unset

func (s *Bitset) Unset(index uint) *Bitset

Unset set index bit to 0, expand the bitset if index out of length range

func (*Bitset) UnsetAll

func (s *Bitset) UnsetAll() *Bitset

UnsetAll set all bits to 0

Jump to

Keyboard shortcuts

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