slidingwindow

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: MIT Imports: 3 Imported by: 0

README

slidingwindow

GitHub release Github Build Status GoDoc

Sliding window implementation for Golang

Installation

$ go get github.com/gaius-qi/slidingwindow

Usage

package main

import (
    "fmt"

    "github.com/gaius-qi/slidingwindow"
)

func main() {
    window := slidingwindow.NewWindow(10, 4)
    window.AddCount(0)
    fmt.Printf("Window moved to %d, window.Count())
}

Issues

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Window

type Window interface {
	// Start is the left position of the window.
	Start() uint

	// Size is the size of the window.
	Size() uint

	// Count is total count of events happened in the window.
	Count() uint

	// Len is the length of bitset.
	Len() uint

	// AddCount increments the accumulated count by n.
	AddCount(n uint)

	// IsFinished returns streaming window execution status.
	IsFinished() bool

	// WindowStatus describe the window status.
	Status() *WindowStatus
}

Window the p2p streaming window.

func NewWindow

func NewWindow(len uint, size uint) (Window, error)

NewWindow creates a new window.

type WindowStatus

type WindowStatus struct {
	bitset.BitSet
	// contains filtered or unexported fields
}

WindowStatus describe the window status, which data are available.

func (*WindowStatus) AddCount

func (w *WindowStatus) AddCount(n uint)

func (*WindowStatus) Count

func (w *WindowStatus) Count() uint

func (*WindowStatus) IsFinished

func (w *WindowStatus) IsFinished() bool

func (*WindowStatus) Size

func (w *WindowStatus) Size() uint

func (*WindowStatus) Start

func (w *WindowStatus) Start() uint

func (*WindowStatus) Status

func (w *WindowStatus) Status() *WindowStatus

Jump to

Keyboard shortcuts

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