window

package
v0.0.0-...-b628505 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PtrOffSize 指针偏移量大小
	PtrOffSize = uint64(8)
)

Variables

View Source
var (
	ErrBucketBuilderIsNil    = errors.New("invalid parameters, Builder is nil")
	ErrWindowNotSegmentation = errors.New("invalid parameters,window is not segmentation")
	ErrTimeBehindStart       = errors.New("time already behind bucketStart")
)

Functions

func SetContext

func SetContext(context context.Context) options.Option

SetContext 设置context

func SetInterval

func SetInterval(interval time.Duration) options.Option

SetInterval 设置间隔时间

func SetSize

func SetSize(size uint) options.Option

SetSize 设置大小

Types

type AtomicArray

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

AtomicArray 封装原子操作, 底层维护 []*Bucket

func NewAtomicArray

func NewAtomicArray(length uint64, bucketSize uint64, Builder BucketBuilder) *AtomicArray

NewAtomicArray 初始化 AtomicArray, startTime 为当前时间

func NewAtomicArrayWithTime

func NewAtomicArrayWithTime(length uint64, bucketSize uint64, now uint64, Builder BucketBuilder) *AtomicArray

NewAtomicArrayWithTime 初始化 AtomicArray, 需要手动传入 startTime 作为时间戳

type Bucket

type Bucket struct {
	// Start 存储了这个桶的起始时间
	Start uint64

	// Value 实际挂载对象
	Value atomic.Value
}

Bucket 滑动窗口的承载的最小元素

type BucketBuilder

type BucketBuilder interface {
	// NewEmptyBucket 生成一个空桶
	NewEmptyBucket() interface{}

	// Reset 重置桶
	Reset(b *Bucket, startTime uint64) *Bucket
}

BucketBuilder Bucket 生成器

type Index

type Index struct {
	Name  string
	Score uint
}

Index 指标信息

type LeapArray

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

LeapArray 基于 Bucket 实现的 leap array 例如: bucketSize == 200ms,intervalSize == 1000ms,所以n = 5 假设当前是 时间是888ms 构建下图

 B0       B1      B2     B3      B4
 |_______|_______|_______|_______|_______|
1000    1200    1400    1600    800    (1000)
                                      ^
                                    time=888

func NewLeapArray

func NewLeapArray(n uint64, intervalSize uint64, builder BucketBuilder) (*LeapArray, error)

NewLeapArray 初始化 leap array

func (*LeapArray) GetBucket

func (s *LeapArray) GetBucket(builder BucketBuilder) (*Bucket, error)

GetBucket 获取桶,封装 getBucketOfTime

func (*LeapArray) Values

func (s *LeapArray) Values() []*Bucket

Values getValueOfTime 封装

func (*LeapArray) ValuesChick

func (s *LeapArray) ValuesChick(now uint64, chick TimeChick) []*Bucket

ValuesChick 加入自定义 TimeChick 过滤value

type SlidingWindow

type SlidingWindow interface {

	// Shutdown 优雅关闭
	Shutdown()

	// AddIndex 添加指标信息
	AddIndex(k string, v uint)

	// Show 展示信息
	Show() []interface{}
	// contains filtered or unexported methods
}

SlidingWindow 滑动窗口接口化

func NewWindow

func NewWindow(options ...options.Option) SlidingWindow

NewWindow 实例化

type TimeChick

type TimeChick func(uint64) bool

TimeChick 自定义校验 时间戳 函数

type Window

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

Window 窗口对象

func (*Window) AddIndex

func (w *Window) AddIndex(k string, v uint)

AddIndex 添加指标

func (*Window) Show

func (w *Window) Show() []interface{}

Show 展示total

func (*Window) Shutdown

func (w *Window) Shutdown()

Shutdown 关闭

Jump to

Keyboard shortcuts

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