Skip to main content

Module topk

Module topk 

Source
Expand description

§Streaming Top-K Operator

Bounded heap of top-K items with retraction-based changelog emission.

Supports ORDER BY ... LIMIT N on unbounded streams by maintaining a sorted buffer of at most K entries. New events that rank within the top-K cause eviction of the worst entry and optional rank-change retractions.

§Emit Strategies

  • OnUpdate: Emit changelog on every state change (lowest latency)
  • OnWatermark: Buffer changes, emit on watermark advance
  • Periodic(interval): Emit on timer interval

§Ring 0 Constraints

  • entries pre-allocated to capacity K — no reallocation during process()
  • Sort keys use Vec<u8> memcomparable encoding for zero-branch comparison
  • Sorted Vec with binary search: O(log K) search + O(K) shift

Structs§

StreamingTopKOperator
Streaming top-K operator for ORDER BY ... LIMIT N.
TopKSortColumn
Configuration for a sort column in the top-K operator.

Enums§

TopKEmitStrategy
Emit strategy for the streaming top-K operator.

Functions§

encode_f64
Encodes an f64 value as memcomparable bytes.
encode_i64
Encodes an i64 value as memcomparable bytes.
encode_not_null
Encodes a non-null value marker into the sort key.
encode_null
Encodes a null value marker into the sort key.
encode_utf8
Encodes a UTF-8 string as memcomparable bytes.