Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Sep 19, 2024
1 parent 04054b9 commit 2fde09f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import (
"github.com/keilerkonzept/topk/internal/sizeof"
)

// Bucket is a single sketch counter together with the corresponding item's fingerprint.'
type Bucket struct {
Fingerprint uint32
Count uint32
}

// Sketch is a top-k sketch.
// The entire structure is serializable using any serialization method - all fields and sub-structs are exported and can be reasonably serialized.
type Sketch struct {
K int // Keep track of top `K` items in the min-heap..
Width int // Number of buckets per hash function.
Expand All @@ -29,6 +32,11 @@ type Sketch struct {
Heap *heap.Min // Top-K min-heap.
}

// New returns a sliding top-k sketch with the given `k` (number of top items to keep) and `windowSize` (in ticks).`
// - The depth defaults to `max(3, log(k))` unless the [WithDepth] option is set.
// - The width defaults to `max(256, k*log(k))` unless the [WithWidth] option is set.
// - The decay parameter defaults to 0.9 unless the [WithDecay] option is set.
// - The decay LUT size defaults to 256 unless the [WithDecayLUTSize] option is set.
func New(k int, opts ...Option) *Sketch {
log_k := int(math.Ceil(math.Log(float64(k))))

Expand Down
8 changes: 8 additions & 0 deletions sliding/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/keilerkonzept/topk/internal/sizeof"
)

// Sketch is a sliding-window top-k sketch.
// The entire structure is serializable using any serialization method - all fields and sub-structs are exported and can be reasonably serialized.
type Sketch struct {
K int // Keep track of top `K` items in the min-heap..
Width int // Number of buckets per hash function.
Expand All @@ -33,6 +35,12 @@ type Sketch struct {
Heap *heap.Min // Top-K min-heap.
}

// New returns a sliding top-k sketch with the given `k` (number of top items to keep) and `windowSize` (in ticks).`
// - The depth defaults to `max(3, log(k))` unless the [WithDepth] option is set.
// - The width defaults to `max(256, k*log(k))` unless the [WithWidth] option is set.
// - The bucket history length defaults to `windowSize` unless the [WithBucketHistoryLength] option is set.
// - The decay parameter defaults to 0.9 unless the [WithDecay] option is set.
// - The decay LUT size defaults to 256 unless the [WithDecayLUTSize] option is set.
func New(k, windowSize int, opts ...Option) *Sketch {
log_k := int(math.Ceil(math.Log(float64(k))))

Expand Down

0 comments on commit 2fde09f

Please sign in to comment.