timetable

package module
v0.0.0-...-61986a0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: MIT Imports: 4 Imported by: 0

README

timetable

A timetable constrained with capacity.

Example: Let's say a car has 4 passenger sits. People want to book places, this library is here to check it's doable (no more than 4 passengers on this car at anytime of the voyage).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInput      = errors.New("wrong input")
	ErrConstraint = errors.New("constraint fail")
	ErrOverflow   = errors.New("overflow")
)

Errors ...

Functions

This section is empty.

Types

type NoopWhen

type NoopWhen struct{}

NoopWhen ...

func (NoopWhen) When

func (NoopWhen) When(t time.Time, _ time.Duration) *time.Time

When ...

type Number

type Number interface {
	constraints.Float | constraints.Integer
}

type Point

type Point[T Number] struct {
	Time time.Time
	Val  T
}

Point represent a moment in time

type TimeTable

type TimeTable[T Number] struct {
	Rel        []Point[T]
	Constraint Whener
	Max        T
}

TimeTable ...

func New

func New[T Number](max T, nd Whener) *TimeTable[T]

New ...

func (*TimeTable[T]) Add

func (tt *TimeTable[T]) Add(from time.Time, dur time.Duration, cap T) error

Add will add the time else returns an error

func (TimeTable[T]) Clone

func (tt TimeTable[T]) Clone() TimeTable[T]

Clone ...

func (TimeTable[T]) Merge

func (tt TimeTable[T]) Merge(other TimeTable[T]) *TimeTable[T]

Merge ...

func (*TimeTable[T]) When

func (tt *TimeTable[T]) When(from time.Time, dur time.Duration, cap T) *time.Time

When returns the soonest time from "from" that satisfies constraints else it will return a nil Pointer

type Whener

type Whener interface {
	When(time.Time, time.Duration) *time.Time
}

Whener ...

Jump to

Keyboard shortcuts

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