model

package
v0.16.0-dev.0-7-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package model provides modeling components, such as domains and ranges.

Create individual integer domains.

d1 := model.NewDomain() // empty domain
d2 := model.NewDomain(model.NewRange(1, 10))
d3 := model.NewDomain(model.NewRange(1, 10), model.MewRange(21, 30))
d4 := model.Singleton(42)
d5 := model.Multiple(2, 4, 6, 8)

Create sequences of domains.

domains1 := model.NewDomains(d1, d2, d3, d4, d5)
domains2 := model.Repeat(5, d1) // 5 empty domains

Index

Constants

View Source
const (
	// MaxInt is the maximum value for an integer.
	MaxInt int = (1<<bits.UintSize)/2 - 1
	// MinInt is the minimum value for an integer.
	MinInt = (1 << bits.UintSize) / -2
)

Constants for integer bounds.

Variables

This section is empty.

Functions

This section is empty.

Types

type Domain

type Domain interface {
	// Add values to a domain.
	Add(...int) Domain
	// AtLeast updates the domain to the subdomain of at least some value.
	AtLeast(int) Domain
	// AtMost updates the domain to the subdomain of at most some value.
	AtMost(int) Domain
	// Cmp lexically compares two integer domains. It returns a negative value
	// if the receiver is less, 0 if they are equal, and a positive value if
	// the receiver domain is greater.
	Cmp(Domain) int
	// Contains returns true if a domain contains a given value.
	Contains(int) bool
	// Empty is true if a domain is empty.
	Empty() bool
	// Iterator over a domain.
	Iterator() Iterator
	// Len of a domain, counting all values within ranges.
	Len() int
	// Max of a domain and a boolean indicating it is nonempty.
	Max() (int, bool)
	// Min of a domain and a boolean indicating it is nonempty.
	Min() (int, bool)
	// Remove values from a domain.
	Remove(...int) Domain
	// Slice representation of a domain.
	Slice() []int
	// Value returns an int and true if a domain is singleton.
	Value() (int, bool)
}

A Domain of integers.

func Multiple

func Multiple(values ...int) Domain

Multiple creates a domain containing multiple integer values.

func NewDomain

func NewDomain(ranges ...Range) Domain

NewDomain creates a domain of integers.

func Singleton

func Singleton(value int) Domain

Singleton creates a domain containing one integer value.

type Domains

type Domains interface {
	// Add values to a domain by index.
	Add(int, ...int) Domains
	// Assign a singleton value to a domain by index.
	Assign(int, int) Domains
	// AtLeast updates the domain to the subdomain of at least some value.
	AtLeast(int, int) Domains
	// AtMost updates the domain to the subdomain of at most some value.
	AtMost(int, int) Domains
	// Cmp lexically compares two sequences of integer domains.
	Cmp(Domains) int
	// Domain by index.
	Domain(int) Domain
	// Empty is true if all domains are empty.
	Empty() bool
	// Len returns the number of domains.
	Len() int
	// Remove values from a domain by index.
	Remove(int, ...int) Domains
	// Singleton is true if all domains are Singleton.
	Singleton() bool
	// Slices convert domains to a slice of int slices.
	Slices() [][]int
	// Values returns the values of a sequence of singleton domains/
	Values() ([]int, bool)

	// First returns the first domain index with length above 1.
	First() (int, bool)
	// Largest returns the index of the largest domain with length above 1 by
	// number of elements.
	Largest() (int, bool)
	// Last returns the last domain index with length above 1.
	Last() (int, bool)
	// Maximum returns the index of the domain containing the maximum value with
	// length above 1.
	Maximum() (int, bool)
	// Minimum returns the index of the domain containing the minimum value with
	// length above 1.
	Minimum() (int, bool)
	// Smallest returns the index of the smallest domain with length above 1 by
	// number of elements.
	Smallest() (int, bool)
}

Domains of integers.

func NewDomains

func NewDomains(domains ...Domain) Domains

NewDomains creates a sequence of domains.

func Repeat

func Repeat(n int, d Domain) Domains

Repeat a domain n times.

type Iterator

type Iterator interface {
	Next() bool
	Value() int
}

An Iterator allows one to iterate over a range or a domain.

it := model.Domain(model.Range(1, 10)).Iterator()
for it.Next() {
    fmt.Println(it.Value()) // 1, ..., 10
}

type Range

type Range interface {
	Min() int
	Max() int
}

A Range of integers.

func NewRange

func NewRange(min, max int) Range

NewRange create a new integer range.

Jump to

Keyboard shortcuts

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