program

package
v0.0.0-...-9033d6b Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const FileHeader = "slice_id.Program v0\n"
View Source
const NullFileHeader = "slice_id.null\n"

Variables

View Source
var InvalidHeader = errors.New("Invalid file header")

Functions

func DotEdge

func DotEdge(from, to int, right bool, ports bool) string

func IndexType

func IndexType[S interface{ SIndex | Index }]() uint8

func InvalidSymbolType

func InvalidSymbolType(expected, actual byte) error

func ReadHeader

func ReadHeader(r *bufio.Reader) (bool, uint64, error)

Types

type Index

type Index interface {
	uint8 | uint16 | uint32 | uint64
}

Index represents a position in an array.

type Instruction

type Instruction[T str.Symbol, I SIndex, S Index] struct {
	Index S
	Low   I
	High  I
	Pivot T
}

Instruction represents a single step in the execution of a Program. Each instruction describes:

  • A comparison operation for the state machine to perform, at a single index in the input string, and
  • A pair of Program array indices referring to the next instruction to execute, one for each outcome of the comparison operation.
  • The Program array indices are signed, with a negative value representing both the termination condition and the final output value to return.

func (Instruction[T, I, S]) Graph

func (i Instruction[T, I, S]) Graph(index int, ports bool) []string

func (*Instruction[T, I, S]) Read

func (i *Instruction[T, I, S]) Read(r io.Reader) error

func (Instruction[T, I, S]) String

func (i Instruction[T, I, S]) String() string

func (Instruction[T, I, S]) Write

func (i Instruction[T, I, S]) Write(w io.Writer) error

type Interface

type Interface[S str.Symbol, T str.String[S]] interface {
	Identify(b T) int
	Length() int
	Graph(w io.Writer, cluster bool, ports bool) error
	Write(io.Writer) error
	// contains filtered or unexported methods
}

Interface is a duplicate of [slice_id.Set], implemented by Program.

func Load

func Load[T str.Symbol](r io.Reader, length uint64) (Interface[T, str.String[T]], error)

func NewAuto

func NewAuto[T str.Symbol](m slice.Slice[T], o options.Options) Interface[T, str.String[T]]

NewAuto calls New, automatically determining the appropriate Index and SIndex types to use.

type Program

type Program[T str.Symbol, I SIndex, S Index] []Instruction[T, I, S]

Program is a collection of Instruction objects, that implements a [Set]. The Program begins execution at the last Instruction in the Program, and repeatedly jumps to and executes the next Instruction based on the jump target defined by the current Instruction.

  • The type parameter T defines the [Symbol] type of the [String] type the program matches.
  • I defines the SIndex type used in the Low and High fields of each Instruction.
  • S identifies the Index type used in the Index field of each Instruction.

func New

func New[T str.Symbol, I SIndex, S Index](m slice.Slice[T], o options.Options) Program[T, I, S]

New compiles a slice.Slice to a Program with a given SIndex and Index type. The resulting Program implements a [slice_id.Set] reprenting all the Strings in the Slice. The resulting Program has a size of i*(n-1) bytes, with n being the length of the Slice, and i being the Instruction size. See the Instruction type for more information on how the Instruction size is determined.

func (Program[T, I, S]) Graph

func (p Program[T, I, S]) Graph(w io.Writer, cluster, ports bool) error

func (Program[T, I, S]) Identify

func (p Program[T, I, S]) Identify(b str.String[T]) int

func (Program[T, I, S]) Length

func (p Program[T, I, S]) Length() int

Length() returns the number of Strings represented by this Program.

func (Program[T, I, S]) String

func (p Program[T, I, S]) String() string

String() generates a string representation of a Program, for debugging purposes.

func (Program[T, I, S]) Write

func (p Program[T, I, S]) Write(w io.Writer) error

type SIndex

type SIndex interface {
	int8 | int16 | int32 | int64
}

SIndex is a Signed Index. If a SIndex is positive, it represents a position in an array. If a SIndex is negative, it represents an arbitrary value, in the form of -(n+1).

Jump to

Keyboard shortcuts

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