datarithms

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

README

Datarithms

This module includes practical algorithms and data structures for our Mirror project.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinarySearchFileByDate

func BinarySearchFileByDate(file string, lastUpdated time.Time, parse func(line string) (time.Time, error)) (offset int64, err error)

BinarySearchFileByDate returns the offset of the first line which date is after lastUpdated this could panic if the parse function isn't guaranteed to work on every line of the file

func Verify

func Verify(s *Schedule, tasks []Task) bool

Verifies that the schedule has increasing target times, all of them are within the cycle (0.0 <= t <= 1.0), and that each task will be synced the correct number of times

Types

type CircularQueue

type CircularQueue[T any] struct {
	// contains filtered or unexported fields
}

Thread Safe circular queue implmentation using a slice for byte slices

func CircularQueueInit

func CircularQueueInit[T any](capacity int) *CircularQueue[T]

Creates a new circular queue of given capacity

func (*CircularQueue[T]) All

func (q *CircularQueue[T]) All() []T

Returns all the elements of the queue

func (*CircularQueue[T]) Capacity

func (q *CircularQueue[T]) Capacity() int

Returns the capacity of the queue

func (*CircularQueue[T]) Front

func (q *CircularQueue[T]) Front() T

Returns the element at the front of the queue

func (*CircularQueue[T]) Len

func (q *CircularQueue[T]) Len() int

Returns the number of elements in the queue

func (*CircularQueue[T]) Pop

func (q *CircularQueue[T]) Pop() (element T, err error)

Pops the element at the front of the queue If the queue is empty, returns the zero value followed by an error

func (*CircularQueue[T]) Push

func (q *CircularQueue[T]) Push(element T)

Adds a new element to the queue

type Job

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

type Schedule

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

Schedule is a struct that holds a list of tasks and their corresponding target time to run The invariant is that the target time must be increasing in the jobs list. So the excutation algorithm is trivial. Run the task, sleep until the next target time, repeat.

func BuildSchedule

func BuildSchedule(tasks []Task) *Schedule

Scheduling algorithm

func (*Schedule) NextJob

func (s *Schedule) NextJob() (short string, dt time.Duration)

Returns the job to run and how long to sleep until the next job

v iterator

[ ] -> [ ] -> [ ] -> [ ]

current time ^    ^ new iterator
             |----|
               dt

run this job sleep until the next job and change to the next job

type Task

type Task struct {
	// Short name of the project
	Short string

	// How many times does the project sync per day
	Syncs int
}

fed as input to the scheduling algorithm

Jump to

Keyboard shortcuts

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