lookup

package
v0.0.0-...-f8b7a73 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2019 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLevel = HighestLevel

默认级别设置没有提示时将选择搜索的级别

View Source
const EpochLength = 8

epoch length存储epoch的序列化二进制长度

View Source
const HighestLevel = 25 //默认值为25(~1年)

最高级别设置算法将以2的功率运行的最低频率。 25->2^25大约等于一年。

View Source
const LowestLevel uint8 = 0 //默认值为0(1秒)

LowestLevel将查找算法的频率分辨率设置为2的幂。

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

maxtime包含一个epoch可以处理的最大可能时间值

Variables

View Source
var NoClue = Epoch{}

noclue是一个提示,当查找调用程序没有 最后一次更新可能在哪里的线索

Functions

func FluzCapacitorAlgorithm

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

FluzCapacitorAlgorithm的工作原理是,如果找到更新,则缩小epoch搜索区域。 及时往返 首先,如果提示是 最后一次更新。如果查找失败,则最后一次更新必须是提示本身 或者下面的时代。但是,如果查找成功,则更新必须是 或者在下面的时代里。 有关更图形化的表示,请参阅指南。

func GetNextLevel

func GetNextLevel(last Epoch, now uint64) uint8

GetNextLevel返回下一次更新应处于的频率级别,前提是 上次更新是什么时间。 这是“last”和“now”的异或的第一个非零位,从最高有效位开始计数。 但仅限于不返回小于最后一个-1的级别

Types

type Algorithm

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

算法是查找算法的函数签名

查找查找具有小于或等于“now”的最高时间戳的更新 它接受了一个提示,应该是最后一次已知更新所在的时代。 如果您不知道最后一次更新发生在哪个时代,只需提交lookup.noclue 每次查找时都将调用read()。 仅当read()返回错误时才返回错误 如果未找到更新,则返回nil

type Epoch

type Epoch struct {
	Time  uint64 `json:"time"`  //时间存储更新或查找发生的时间
	Level uint8  `json:"level"` //级别表示频率级别,表示2次方的指数。
}

epoch表示特定频率级别的时隙

func GetFirstEpoch

func GetFirstEpoch(now uint64) Epoch

GetFirstEpoch返回第一次更新应位于的epoch 根据现在的时间。

func GetNextEpoch

func GetNextEpoch(last Epoch, now uint64) Epoch

getnextepoch返回下一个更新应位于的epoch 根据上次更新的位置 现在几点了。

func Hint

func Hint(last uint64) Epoch

提示仅基于上一次已知更新时间创建提示

func (*Epoch) After

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

如果此纪元发生在另一个纪元之后或正好发生在另一个纪元,则返回true。

func (*Epoch) Base

func (e *Epoch) Base() uint64

BASE返回纪元的基准时间

func (*Epoch) Equals

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

equals比较两个时期,如果它们引用同一时间段,则返回true。

func (*Epoch) ID

func (e *Epoch) ID() EpochID

id返回这个时代的唯一标识符

func (*Epoch) MarshalBinary

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

MarshalBinary实现Encoding.BinaryMarshaller接口

func (*Epoch) String

func (e *Epoch) String() string

字符串实现字符串接口。

func (*Epoch) UnmarshalBinary

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

UnmarshalBinary实现encoding.BinaryUnmarshaller接口

type EpochID

type EpochID [8]byte

epochid是一个时代的唯一标识符,基于它的级别和基准时间。

type ReadFunc

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

readfunc是lookup在每次试图查找值时调用的处理程序。 如果找不到值,它应该返回<nil> 如果找到一个值,它应该返回<nil>,但它的时间戳高于“now” 它只应在处理程序希望停止时返回错误。 完全查找过程。

Jump to

Keyboard shortcuts

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