code wiki / (root) / sketch_count_sketch_negative_bench.nx

sketch_count_sketch_negative_bench.nx

buildroot/runtime/sketch_count_sketch_negative_bench.nx

5341 B165 linesdepth 7pulls 14 transitivereach 0 importersview sourcekind benchtopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_count_sketch_negative_bench.nx -- negative-insert capability bench. CLAIM TO VALIDATE: CountSketch (Charikar et al. 2002) natively supports NEGATIVE inserts -- it tracks the SIGNED sum of inserts per key (a TURNSTILE stream). Apache DataSketches queues but does NOT ship CountSketch; their only frequency primitive (CMS) handles INSERT-ONLY streams (cash-register). Every other in-tree frequency primitive (SpaceSaving, MisraGries, LossyCounting) is also INSERT-ONLY. This bench demonstrates: CountSketch correctly tracks net counts under mixed +/- inserts; CMS (forced to accept negative inserts) silently corrupts. CAPABILITY EXCEED across the entire freq family. WORKLOAD: Per-key insert pattern (item 1): +1000, +500, -200, -100, +50, -50 Net per item 1: 1200 Item 2: +800, -100, +200 -> net 900 Item 3: +300, -50 -> net 250 Plus 200 singleton-positive noise items. MEASUREMENT: - CountSketch must return est within reasonable noise band of NET count - CMS estimate is UNRELIABLE under negative inserts (rows can go negative; the min-over-rows guarantee breaks). We document this by asserting CountSketch is materially closer to truth.

dependencies 5 imports · 0 importers

syscalls.nx sketch_count_sketch.nx sketch_cms.nx sketch_comparator.nx sketch_types.nx sketch_count_sketch_negative_b

imports: syscalls.nxsketch_count_sketch.nxsketch_cms.nxsketch_comparator.nxsketch_types.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_cs_alloc nx_cms_alloc nx_cs_add nx_cs_h1 nx_cs_h2 nx_cs_sign write_bn nx_cms_add murmur3_32 mm_load_u32_le mm_rotl32 nx_cms_row_index nx_cs_estimate nx_cs_h1 ↻ nx_cs_h2 ↻ nx_cs_sign ↻ iabs_n nx_cms_estimate murmur3_32 ↻ nx_cms_row_index ↻ nx_cmp_accuracy nx_cmp_iabs

structs

none

consts

none

functions

34func iabs_n(x: i64) -> i64
called by 1: main
39func write_bn(buf: *u8, value: i64) -> i64
called by 1: main
50func main() -> i64