lookup

package
v1.8.17-evmc.6.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package lookup defines feed lookup algorithms and provides tools to place updates so they can be found

Index

Constants

View Source
const DefaultLevel = HighestLevel

DefaultLevel sets what level will be chosen to search when there is no hint

View Source
const EpochLength = 8

EpochLength stores the serialized binary length of an Epoch

View Source
const HighestLevel = 25 // default is 25 (~1 year)

HighestLevel sets the lowest frequency the algorithm will operate at, as a power of 2. 25 -> 2^25 equals to roughly one year.

View Source
const LowestLevel uint8 = 0 // default is 0 (1 second)

LowestLevel establishes the frequency resolution of the lookup algorithm as a power of 2.

View Source
const MaxTime uint64 = (1 << 56) - 1

MaxTime contains the highest possible time value an Epoch can handle

Variables

View Source
var NoClue = Epoch{}

NoClue is a hint that can be provided when the Lookup caller does not have a clue about where the last update may be

Functions

func FluzCapacitorAlgorithm

func FluzCapacitorAlgorithm(now uint64, hint Epoch, read ReadFunc) (value interface{}, err error)

FluzCapacitorAlgorithm works by narrowing the epoch search area if an update is found going back and forth in time First, it will attempt to find an update where it should be now if the hint was really the last update. If that lookup fails, then the last update must be either the hint itself or the epochs right below. If however, that lookup succeeds, then the update must be that one or within the epochs right below. see the guide for a more graphical representation

func GetNextLevel

func GetNextLevel(last Epoch, now uint64) uint8

GetNextLevel returns the frequency level a next update should be placed at, provided where the last update was and what time it is now. This is the first nonzero bit of the XOR of 'last' and 'now', counting from the highest significant bit but limited to not return a level that is smaller than the last-1

Types

type Algorithm

type Algorithm func(now uint64, hint Epoch, read ReadFunc) (value interface{}, err error)

Algorithm is the function signature of a lookup algorithm

Lookup finds the update with the highest timestamp that is smaller or equal than 'now' It takes a hint which should be the epoch where the last known update was If you don't know in what epoch the last update happened, simply submit lookup.NoClue read() will be called on each lookup attempt Returns an error only if read() returns an error Returns nil if an update was not found

type Epoch

type Epoch struct {
	Time  uint64 `json:"time"`  // Time stores the time at which the update or lookup takes place
	Level uint8  `json:"level"` // Level indicates the frequency level as the exponent of a power of 2
}

Epoch represents a time slot at a particular frequency level

func GetFirstEpoch

func GetFirstEpoch(now uint64) Epoch

GetFirstEpoch returns the epoch where the first update should be located based on what time it is now.

func GetNextEpoch

func GetNextEpoch(last Epoch, now uint64) Epoch

GetNextEpoch returns the epoch where the next update should be located according to where the previous update was and what time it is now.

func Hint

func Hint(last uint64) Epoch

Hint creates a hint based only on the last known update time

func (*Epoch) After

func (e *Epoch) After(epoch Epoch) bool

After returns true if this epoch occurs later or exactly at the other epoch.

func (*Epoch) Base

func (e *Epoch) Base() uint64

Base returns the base time of the Epoch

func (*Epoch) Equals

func (e *Epoch) Equals(epoch Epoch) bool

Equals compares two epochs and returns true if they refer to the same time period.

func (*Epoch) ID

func (e *Epoch) ID() EpochID

ID Returns the unique identifier of this epoch

func (*Epoch) MarshalBinary

func (e *Epoch) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaller interface

func (*Epoch) String

func (e *Epoch) String() string

String implements the Stringer interface.

func (*Epoch) UnmarshalBinary

func (e *Epoch) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaller interface

type EpochID

type EpochID [8]byte

EpochID is a unique identifier for an Epoch, based on its level and base time.

type ReadFunc

type ReadFunc func(epoch Epoch, now uint64) (interface{}, error)

ReadFunc is a handler called by Lookup each time it attempts to find a value It should return <nil> if a value is not found It should return <nil> if a value is found, but its timestamp is higher than "now" It should only return an error in case the handler wants to stop the lookup process entirely.

Jump to

Keyboard shortcuts

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