/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "stats-dist.h"
#include "sort.h"
/* In order to have a vaguely accurate 95th percentile, you need way
more than 20 in your subsample. */
struct stats_dist {
unsigned int sample_count;
unsigned int count;
bool sorted;
};
{
}
{
i_assert(sample_count > 0);
i_malloc(sizeof(struct stats_dist) +
sizeof(uint64_t) * sample_count);
return stats;
}
{
}
{
}
{
} else {
}
}
{
}
{
}
{
}
{
}
{
return 0;
}
{
return;
: stats->sample_count;
}
{
return 0;
/* cast-away const - reading requires sorting */
: stats->sample_count;
}
/* This is independent of the stats framework, useful for any selection task */
{
/* With out of range fractions, we can give the caller what
they probably want rather than just crashing. */
if (fraction >= 1.)
return range - 1;
if (fraction <= 0.)
return 0;
/* Exact boundaries belong to the open range below them.
As FP isn't exact, and ratios may be specified inexactly,
include a small amount of fuzz around the exact boundary. */
idx--;
return idx;
}
{
return 0;
/* cast-away const - reading requires sorting */
: stats->sample_count;
}