lights

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package lights provides ways to represent a set of lights

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder builds Set instances. The zero value is an empty Builder ready for use.

func NewBuilder

func NewBuilder(other Set) *Builder

NewBuilder returns a new instance with other as its initial contents.

func (*Builder) Add

func (b *Builder) Add(other Set) *Builder

Add adds the lights in other to this instance.

func (*Builder) AddOne

func (b *Builder) AddOne(light int) *Builder

AddOne adds one light to this instance.

func (*Builder) Build

func (b *Builder) Build() Set

Build returns the lights in this instance as a Set.

func (*Builder) Clear

func (b *Builder) Clear() *Builder

Clear changes this instance to contain no lights.

type Map

type Map map[int]int

Map represents a map of virtual light Ids to physical light ids. When a light fails, its replacement will be given a new id. This data structure allows a light to keep the same virtual id in the marvin system even after replacing it. The key is the virtual light Id, the value is the physical light id. If there is no mapping for a virtual light id, it maps to itself. Map instances are to be treated as immutable.

func (Map) Convert

func (m Map) Convert(virtualId int) int

Convert converts a virtual light Id to a physical light id.

type Set

type Set map[int]bool

Set represents a set of positive light Ids. nil represents all lights; An empty map or a map containing only false values represents no lights. Callers should treat Set instances as immutable.

var (
	// None represents no lights.
	None = make(Set, 0)

	// All represents all lights.
	All Set = nil
)

func InvString

func InvString(s string) (result Set, err error)

Unlike Parse, InvString is the exact inverse of String.

func New

func New(lightIds ...int) Set

New builds a new Set.

func Parse

func Parse(s string) (result Set, err error)

Parse parses comma separated light Ids as a Set. An empty string or a string with just spaces parses as all lights. Currently Parse will never return an instance representing no lights.

func (Set) Add

func (l Set) Add(other Set) Set

Add returns the union of this instance and other.

func (Set) Intersect

func (l Set) Intersect(other Set) Set

Intersect returns the intersection of this instance and other.

func (Set) IsAll

func (l Set) IsAll() bool

IsAll returns true if this instance represents all lights.

func (Set) IsNone

func (l Set) IsNone() bool

IsNone returns true if this instance has no lights.

func (Set) OverlapsWith

func (l Set) OverlapsWith(other Set) bool

OverlapsWith returns true if this instance and other share common lights

func (Set) Slice

func (l Set) Slice() (result []int, ok bool)

Slice returns this instance as a slice of light ids sorted in ascending order and true. If this instance represents all lights, returns an empty slice and true. If this instance represents no lights, returns an empty slice and false.

func (Set) String

func (l Set) String() string

String returns the lights comma separated in ascending order or "All" if this instance represents all lights or "None" if this instance represents no lights..

func (Set) Subtract

func (l Set) Subtract(other Set) Set

Subtract returns the light ids that are in this instance but not other. Subtract panics if this instance represents all lights.

Jump to

Keyboard shortcuts

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