bitset

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: Apache-2.0, MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitSet

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

BitSet bit set

Example
package main

import (
	"fmt"

	"github.com/21888/go-tagexpr-new/goutil-loc/bitset"
)

func main() {
	bs, _ := bitset.NewFromHex("c020")
	fmt.Println("Origin:", bs.Binary(" "))
	not := bs.Not()
	fmt.Println("Not:", not.Binary(" "))
	fmt.Println("AndNot:", not.AndNot(bitset.New(1, 1)).Binary(" "))
	fmt.Println("And:", not.And(bitset.New(1<<1, 1<<1)).Binary(" "))
	fmt.Println("Or:", not.Or(bitset.New(1<<7, 1<<7)).Binary(" "))
	fmt.Println("Xor:", not.Xor(bitset.New(1<<7, 1<<7)).Binary(" "))

	not.Range(func(k int, v bool) bool {
		fmt.Println(v)
		return true
	})

}
Output:

Origin: 11000000 00100000
Not: 00111111 11011111
AndNot: 00111110 11011110
And: 00000010 00000010
Or: 10111111 11011111
Xor: 10111111 01011111
false
false
true
true
true
true
true
true
true
true
false
true
true
true
true
true

func New

func New(init ...byte) *BitSet

New creates a bit set object.

func NewFromHex

func NewFromHex(s string) (*BitSet, error)

NewFromHex creates a bit set object from hex string.

func (*BitSet) And

func (b *BitSet) And(bitSets ...*BitSet) *BitSet

And returns all the "AND" bit sets. NOTE:

If the bitSets are empty, returns b.

func (*BitSet) AndNot

func (b *BitSet) AndNot(bitSet ...*BitSet) *BitSet

AndNot returns all the "&^" bit sets. NOTE:

If the bitSets are empty, returns b.

func (*BitSet) Binary

func (b *BitSet) Binary(sep string) string

Binary returns the bit set by binary type. NOTE:

Paramter sep is the separator between chars.

func (*BitSet) Bytes

func (b *BitSet) Bytes() []byte

Bytes returns the bit set copy bytes.

func (*BitSet) Clear

func (b *BitSet) Clear()

Clear clears the bit set.

func (*BitSet) Count

func (b *BitSet) Count(start, end int) int

Count counts the amount of bit set to 1 within the specified range of the bit set. NOTE:

0 means the 1st bit, -1 means the bottom 1th bit, -2 means the bottom 2th bit and so on.

func (*BitSet) Get

func (b *BitSet) Get(offset int) bool

Get gets the bit bool value on the specified offset. NOTE:

0 means the 1st bit, -1 means the bottom 1th bit, -2 means the bottom 2th bit and so on;
If offset>=len(b.set), returns false.

func (*BitSet) Not

func (b *BitSet) Not() *BitSet

Not returns ^b.

func (*BitSet) Or

func (b *BitSet) Or(bitSet ...*BitSet) *BitSet

Or returns all the "OR" bit sets. NOTE:

If the bitSets are empty, returns b.

func (*BitSet) Range

func (b *BitSet) Range(f func(offset int, truth bool) bool)

Range calls f sequentially for each bit present in the bit set. If f returns false, range stops the iteration.

func (*BitSet) Set

func (b *BitSet) Set(offset int, value bool) (bool, error)

Set sets the bit bool value on the specified offset, and returns the value of before setting. NOTE:

0 means the 1st bit, -1 means the bottom 1th bit, -2 means the bottom 2th bit and so on;
If offset>=len(b.set), automatically grow the bit set;
If the bit offset is out of the left range, returns error.

func (*BitSet) Size

func (b *BitSet) Size() int

Size returns the bits size.

func (*BitSet) String

func (b *BitSet) String() string

String returns the bit set by hex type.

func (*BitSet) Sub

func (b *BitSet) Sub(start, end int) *BitSet

Sub returns the bit subset within the specified range of the bit set. NOTE:

0 means the 1st bit, -1 means the bottom 1th bit, -2 means the bottom 2th bit and so on.

func (*BitSet) Xor

func (b *BitSet) Xor(bitSet ...*BitSet) *BitSet

Xor returns all the "XOR" bit sets. NOTE:

If the bitSets are empty, returns b.

Jump to

Keyboard shortcuts

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