topk

package module
v0.0.0-...-b18ffa8 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 6 Imported by: 1

README

TopK: "filtered space saving" streaming topk algorithm

A modified version of http://github.com/dgryski/go-topk with the following changes

Documentation

Overview

Package topk implements the Filtered Space-Saving TopK streaming algorithm

The original Space-Saving algorithm: https://icmi.cs.ucsb.edu/research/tech_reports/reports/2005-23.pdf

The Filtered Space-Saving enhancement: http://www.l2f.inesc-id.pt/~fmmb/wiki/uploads/Work/misnis.ref0a.pdf

This implementation follows the algorithm of the FSS paper, but not the suggested implementation. Specifically, we use a heap instead of a sorted list of monitored items, and since we are also using a map to provide O(1) access on update also don't need the c_i counters in the hash table.

Licensed under the MIT license.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	Key   string `json:"key"`
	Count int    `json:"count"`
	Error int    `json:"error"`
}

Element is a TopK item

type Stream

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

Stream calculates the TopK elements for a stream

func (*Stream) Decode

func (s *Stream) Decode(r io.Reader) error

Decode ...

func (*Stream) DecodeMsgp

func (s *Stream) DecodeMsgp(r *msgp.Reader) error

DecodeMsgp ...

func (*Stream) Encode

func (s *Stream) Encode(w io.Writer) error

Encode ...

func (*Stream) EncodeMsgp

func (s *Stream) EncodeMsgp(w *msgp.Writer) error

EncodeMsgp ...

func (*Stream) Estimate

func (s *Stream) Estimate(x string) Element

Estimate returns an estimate for the item x

func (*Stream) Insert

func (s *Stream) Insert(x string, count int) Element

Insert adds an element to the stream to be tracked It returns an estimation for the just inserted element

func (*Stream) Keys

func (s *Stream) Keys() []Element

Keys returns the current estimates for the most frequent elements

func (*Stream) Merge

func (s *Stream) Merge(other *Stream) error

Merge ...

type TopK

type TopK struct {
	*Stream
	// contains filtered or unexported fields
}

This is a simple wrapper around the Stream struct, more of a helper of sort

func New

func New(k int) *TopK

func NewWithScaleFactor

func NewWithScaleFactor(k, m int) *TopK

func (*TopK) Count

func (t *TopK) Count() int

Returns number of items inserted into the TopK

func (*TopK) Decode

func (t *TopK) Decode(r io.Reader) error

Decode ...

func (*TopK) DecodeMsgp

func (t *TopK) DecodeMsgp(r *msgp.Reader) error

DecodeMsgp ...

func (*TopK) Encode

func (t *TopK) Encode(w io.Writer) error

Encode ...

func (*TopK) EncodeMsgp

func (t *TopK) EncodeMsgp(w *msgp.Writer) error

EncodeMsgp ...

func (*TopK) Insert

func (t *TopK) Insert(x string, count int) Element

func (*TopK) Keys

func (t *TopK) Keys() []Element

func (*TopK) Merge

func (t *TopK) Merge(other *TopK) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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