Q242FreeSystemVerilog
Estimate the densest page in a bounded stream
Interview prompt
Question
Process address observations online while storing at most MAX_ENTRIES page counters. Return an approximate densest page and its estimated density.
Starting point
Question code
class StreamingPageCounter #(int MAX_ENTRIES = 64);
function void observe(longint unsigned addr);
function void get_densest(
output longint unsigned page_base,
output int unsigned estimated_density
);
endclassReviewed example
Trace one case
Input
MAX_ENTRIES=2; observed pages=[0x1000,0x2000,0x3000,0x3000,0x3000]Expected output
approximate densest page=0x3000; estimated density=4 (true density=3)Space-Saving replaces one minimum counter and inherits its error, so the bounded estimate may overcount but still identifies the heavy page.
What to cover
Requirements
- Increment exact counters for pages already tracked.
- Add unseen pages while capacity remains.
- When full, replace a minimum counter using the Space-Saving estimate.
- Document that bounded storage produces an approximation.

