topk

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

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

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 6 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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) Clear

func (s *Stream) Clear()

Clear resets the Stream to its initial empty state. Clear does not change the size of the Stream. Clear is not thread-safe, should not use it concurrently with other methods.

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) Clear

func (t *TopK) Clear()

Clear resets the TopK to its initial empty state. Clear preserves the initial k value. Clear is not thread-safe, should not use it concurrently with other methods.

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
⌂ 换网址