Documentation
¶
Index ¶
- Variables
- func Cap() uint
- type BitSet
- func (b *BitSet) All() bool
- func (b *BitSet) Any() bool
- func (b *BitSet) Clear(i uint) *BitSet
- func (b *BitSet) ClearAll() *BitSet
- func (b *BitSet) Compact() *BitSet
- func (b *BitSet) Count() uint
- func (b *BitSet) Flip(i uint) *BitSet
- func (b *BitSet) FlipRange(start, end uint) *BitSet
- func (b *BitSet) Iterate() iter.Seq[uint]
- func (b *BitSet) Len() uint
- func (b *BitSet) MarshalBinary() ([]byte, error)
- func (b *BitSet) MarshalJSON() ([]byte, error)
- func (b *BitSet) None() bool
- func (b *BitSet) ReadFrom(stream io.Reader) (int64, error)
- func (b *BitSet) Set(i uint) *BitSet
- func (b *BitSet) SetAll() *BitSet
- func (b *BitSet) SetTo(i uint, value bool) *BitSet
- func (b *BitSet) Shrink(lastbitindex uint) *BitSet
- func (b *BitSet) String() string
- func (b *BitSet) Test(i uint) bool
- func (b *BitSet) UnmarshalBinary(data []byte) error
- func (b *BitSet) UnmarshalJSON(data []byte) error
- func (b *BitSet) WriteTo(stream io.Writer) (int64, error)
Constants ¶
This section is empty.
Variables ¶
var BinaryOrder binary.ByteOrder = binary.BigEndian
var Encoding = base64.URLEncoding
Functions ¶
func Cap ¶
func Cap() uint
Cap returns the total possible capacity, or number of bits that can be stored in the BitSet theoretically. Under 32-bit system, it is 4294967295 and under 64-bit system, it is 18446744073709551615. Note that this is further limited by the maximum allocation size in Go, and your available memory, as any Go data structure.
Types ¶
type BitSet ¶
type BitSet struct {
// contains filtered or unexported fields
}
func (*BitSet) All ¶
All returns true if all bits are set, false otherwise. Returns true for empty sets.
func (*BitSet) Compact ¶
Compact shrinks BitSet to so that we preserve all set bits, while minimizing memory usage. Compact calls Shrink.
func (*BitSet) Len ¶
Len returns the number of bits in the BitSet. Note that it differ from Count function.
func (*BitSet) MarshalBinary ¶
MarshalBinary encodes a BitSet into a binary form and returns the result. Please see WriteTo for details.
func (*BitSet) MarshalJSON ¶
MarshalJSON marshals a BitSet as a JSON structure
func (*BitSet) None ¶
None returns true if no bit is set, false otherwise. Returns true for empty sets.
func (*BitSet) ReadFrom ¶
ReadFrom reads a BitSet from a stream written using WriteTo The format is: 1. uint64 length 2. []uint64 set See WriteTo for details. Upon success, the number of bytes read is returned. If the current BitSet is not large enough to hold the data, it is extended. In case of error, the BitSet is either left unchanged or made empty if the error occurs too late to preserve the content.
Performance: if this function is used to read from a disk or network connection, it might be beneficial to wrap the stream in a bufio.Reader. E.g.,
f, err := os.Open("myfile")
r := bufio.NewReader(f)
func (*BitSet) Set ¶
Set bit i to 1, the capacity of the bitset is automatically increased accordingly. Warning: using a very large value for 'i' may lead to a memory shortage and a panic: the caller is responsible for providing sensible parameters in line with their memory capacity. The memory usage is at least slightly over i/8 bytes.
func (*BitSet) SetTo ¶
SetTo sets bit i to value. Warning: using a very large value for 'i' may lead to a memory shortage and a panic: the caller is responsible for providing sensible parameters in line with their memory capacity.
func (*BitSet) Shrink ¶
Shrink shrinks BitSet so that the provided value is the last possible set value. It clears all bits > the provided index and reduces the size and length of the set.
func (*BitSet) String ¶
String creates a string representation of the BitSet. It is only intended for human-readable output and not for serialization.
func (*BitSet) UnmarshalBinary ¶
UnmarshalBinary decodes the binary form generated by MarshalBinary. Please see WriteTo for details.
func (*BitSet) UnmarshalJSON ¶
UnmarshalJSON unmarshals a BitSet from JSON created using MarshalJSON
func (*BitSet) WriteTo ¶
WriteTo writes a BitSet to a stream. The format is: 1. uint64 length 2. []uint64 set The length is the number of bits in the BitSet.
The set is a slice of uint64s containing between length and length + 63 bits. It is interpreted as a big-endian array of uint64s by default (see BinaryOrder()) meaning that the first 8 bits are stored at byte index 7, the next 8 bits are stored at byte index 6... the bits 64 to 71 are stored at byte index 8, etc. If you change the binary order, you need to do so for both reading and writing. We recommend using the default binary order.
Upon success, the number of bytes written is returned.
Performance: if this function is used to write to a disk or network connection, it might be beneficial to wrap the stream in a bufio.Writer. E.g.,
f, err := os.Create("myfile")
w := bufio.NewWriter(f)