bits

package module
v0.0.0-...-e74aa78 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

bits

ChatGPT wrote this!

  • Implements BitField using an array of unsigned integers.
  • Uses BitField to implement a PortRange struct.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitField

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

BitField struct holds a slice of uint64 integers for 64-bit blocks

func NewBitField

func NewBitField(n int) *BitField

NewBitField creates a BitField capable of holding 'n' bits

func (*BitField) ClearBit

func (bf *BitField) ClearBit(pos int)

ClearBit clears the bit at position 'pos' (sets it to 0)

func (*BitField) IsSet

func (bf *BitField) IsSet(pos int) bool

IsSet checks if the bit at position 'pos' is set (1)

func (*BitField) NextAvailableBitsInRange

func (bf *BitField) NextAvailableBitsInRange(start, end, n int) ([]int, error)

NextAvailableBitsInRange finds the next `n` available (unset) bits within a specified range [start, end). It does not require the bits to be consecutive.

func (*BitField) SetBit

func (bf *BitField) SetBit(pos int)

SetBit sets the bit at position 'pos' to 1

func (*BitField) SetNextAvailableBits

func (bf *BitField) SetNextAvailableBits(n int) ([]int, error)

SetNextAvailableBits finds and sets the next `n` available bits, returning their positions. It does not require the bits to be consecutive.

func (*BitField) String

func (bf *BitField) String() string

String returns a string representation of the BitField.

type PortRange

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

PortRange struct for managing a range of ports with a starting index and fixed size

func NewPortRange

func NewPortRange(startPort, size int) (*PortRange, error)

NewPortRange creates a new PortRange with a specified startPort and size

func (*PortRange) AllocateNextPorts

func (pr *PortRange) AllocateNextPorts(n int) ([]int, error)

AllocateNextPorts allocates the next `n` available ports in the range. It uses `SetNextAvailableBits` to find non-consecutive available ports.

func (*PortRange) IsPortAllocated

func (pr *PortRange) IsPortAllocated(port int) (bool, error)

IsPortAllocated checks if a specific port in the range is allocated

func (*PortRange) ReleasePorts

func (pr *PortRange) ReleasePorts(ports []int) error

ReleasePorts releases a specified list of ports in the range

func (*PortRange) SetPortAllocated

func (pr *PortRange) SetPortAllocated(port int) error

SetPortAllocated sets a specific port in the range as allocated

func (*PortRange) String

func (pr *PortRange) String() string

String returns a string representation of the allocated fields in the PortRange

Jump to

Keyboard shortcuts

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