Documentation ¶
Index ¶
- type BitSet
- func (b *BitSet) And(bitSets ...*BitSet) *BitSet
- func (b *BitSet) AndNot(bitSet ...*BitSet) *BitSet
- func (b *BitSet) Binary(sep string) string
- func (b *BitSet) Bytes() []byte
- func (b *BitSet) Clear()
- func (b *BitSet) Count(start, end int) int
- func (b *BitSet) Get(offset int) bool
- func (b *BitSet) Not() *BitSet
- func (b *BitSet) Or(bitSet ...*BitSet) *BitSet
- func (b *BitSet) Range(f func(offset int, truth bool) bool)
- func (b *BitSet) Set(offset int, value bool) (bool, error)
- func (b *BitSet) Size() int
- func (b *BitSet) String() string
- func (b *BitSet) Sub(start, end int) *BitSet
- func (b *BitSet) Xor(bitSet ...*BitSet) *BitSet
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/andeya/goutil/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 NewFromHex ¶
NewFromHex creates a bit set object from hex string.
func (*BitSet) AndNot ¶
AndNot returns all the "&^" bit sets. NOTE:
If the bitSets are empty, returns b.
func (*BitSet) Binary ¶
Binary returns the bit set by binary type. NOTE:
Paramter sep is the separator between chars.
func (*BitSet) Count ¶
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 ¶
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) Range ¶
Range calls f sequentially for each bit present in the bit set. If f returns false, range stops the iteration.
func (*BitSet) Set ¶
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.
Click to show internal directories.
Click to hide internal directories.