Documentation
¶
Overview ¶
Package mask provides utilities for managing bitmasks in Go, supporting various mask sizes through build configurations.
The mask package implements functionality to manipulate and compare bitmasks, with support for configurable sizes (64, 256, 512, or 1024 bits) based on build tags. A fixed-size Mask256 is also available regardless of build configuration.
Mask Types ¶
The package defines two primary types:
- Mask: A variable-sized bitmask whose size depends on build tags
- Mask256: A fixed 256-bit bitmask available in all configurations
Basic Usage ¶
Creating and manipulating masks:
// Create a new mask var m mask.Mask // Set bits in the mask m.Mark(3) // Set bit 3 m.Mark(42) // Set bit 42 // Check if a bit is set if m.Contains(3) { // Bit 3 is set } // Clear a bit m.Unmark(3)
Comparing Masks ¶
Masks can be compared for various conditions:
var m1, m2 mask.Mask m1.Mark(1) m1.Mark(2) m2.Mark(2) m2.Mark(3) // Check if m1 contains all bits in m2 if m1.ContainsAll(m2) { // m1 has all bits set that are set in m2 } // Check if m1 contains any bits in m2 if m1.ContainsAny(m2) { // m1 and m2 share at least one bit } // Check if m1 contains none of the bits in m2 if m1.ContainsNone(m2) { // m1 and m2 have no bits in common } // Check if a mask is empty (no bits set) if m1.IsEmpty() { // No bits are set in m1 }
Build Configurations ¶
The package supports different bit sizes through build tags:
- Default: 64-bit mask (no build tag required)
- m256: 256-bit mask
- m512: 512-bit mask
- m1024: 1024-bit mask
Example of building with a specific configuration:
go build -tags m256
The Mask256 type is always available with a fixed 256-bit size, regardless of which build configuration is used.
Index ¶
Constants ¶
const (
MaxBits = 64
)
MaxBits defines the maximum number of bits supported by this mask implementation
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mask ¶
type Mask [maskSize]uint64
func (Mask) ContainsAll ¶
ContainsAll checks if all bits set in the other mask are also set in this mask
func (Mask) ContainsAny ¶
ContainsAny checks if any bit set in the other mask is also set in this mask
func (Mask) ContainsNone ¶
ContainsNone checks if none of the bits set in the other mask are set in this mask Returns false if the other mask is empty
type Mask256 ¶
type Mask256 [256]uint64
Mask256 represents a 256-element bit mask using an array of uint64
func (Mask256) ContainsAll ¶
ContainsAll returns true if this mask contains all bits set in the other mask
func (Mask256) ContainsAny ¶
ContainsAny returns true if this mask contains any bits set in the other mask
func (Mask256) ContainsNone ¶
ContainsNone returns true if this mask contains none of the bits set in the other mask