byteset

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: MIT-0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteSet

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

ByteSet is a set of bytes (8 bit values).

Internally, set membership is stored by a 256 bit bit array, each bit corresponding to a byte value. If a bit is set, the byte equal to its index is part of the set.

func Complement

func Complement(set ByteSet) ByteSet

Complement returns the complement of the ByteSet.

func FromIter

func FromIter(bytes iter.Seq[byte]) (set ByteSet)

FromIter creates a ByteSet from the specified iter.Seq of bytes.

func FromSeq

func FromSeq(bytes seqs.Seq[byte]) ByteSet

FromSeq creates a ByteSet from the specified seqs.Seq of bytes.

func FromValues

func FromValues(bytes ...byte) ByteSet

FromValues creates a ByteSet of the specified bytes.

Example:

s := ByteSetFromValues('a', '!', 42)
// s will now look like this:
//          63                  42:'*'   33:'!'                             0
//           |                    |        |                                |
// bits[0]   0000000000000000000001000000001000000000000000000000000000000000
//         127                           97:'a'                             64
//           |                             |                                |
// bits[1]   0000000000000000000000000000001000000000000000000000000000000000
//         191                                                              128
//           |                                                              |
// bits[2]   0000000000000000000000000000000000000000000000000000000000000000
//         255                                                              192
//           |                                                              |
// bits[3]   0000000000000000000000000000000000000000000000000000000000000000
assert(s.Contains('*'))
assert(!s.Contains('A'))
assert(s.Len() == 3)
assert(slices.Collect(s.Values) == []byte{33, 42, 97})

func Intersection

func Intersection(sets ...ByteSet) (set ByteSet)

Intersection returns the intersection of the specified [ByteSet]s. NOTE: Returns a ByteSet matching every byte if sets is empty.

func RelativeComplement

func RelativeComplement(setA, setB ByteSet) (set ByteSet)

RelativeComplement returns the relative complement of set A in set B.

This is also known as the set difference of B and A, denoted B \ A or B - A.

func Union

func Union(sets ...ByteSet) (set ByteSet)

Union returns the union of the specified [ByteSet]s.

func (ByteSet) Cardinality

func (set ByteSet) Cardinality() (core.Cardinal, bool)

func (ByteSet) Contains

func (set ByteSet) Contains(b byte) bool

Contains return whether the ByteSet contains the specified byte

func (ByteSet) ForEachUntil

func (set ByteSet) ForEachUntil(yield func(byte) bool)

func (ByteSet) Len

func (set ByteSet) Len() (n int)

func (ByteSet) Values

func (set ByteSet) Values(yield func(byte) bool)

Jump to

Keyboard shortcuts

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