zeek/scripts/base/frameworks/sumstats/plugins/topk.bro
Bernhard Amann 2f48008c42 implement merging for top-k.
I am not (entirely) sure that this is mathematically correct, but
I am (more and more) getting the feeling that it... might be.

In any case - this was the last step and now it should work
in cluster settings.
2013-04-24 06:17:51 -07:00

31 lines
518 B
Text

@load base/frameworks/sumstats
module SumStats;
export {
redef enum Calculation += {
TOPK
};
redef record ResultVal += {
topk: opaque of topk &default=topk_init(500);
};
}
hook observe_hook(r: Reducer, val: double, obs: Observation, rv: ResultVal)
{
if ( TOPK in r$apply )
{
topk_add(rv$topk, obs);
}
}
hook compose_resultvals_hook(result: ResultVal, rv1: ResultVal, rv2: ResultVal)
{
result$topk = topk_init(500);
topk_merge(result$topk, rv1$topk);
topk_merge(result$topk, rv2$topk);
}