1#ifndef __JASTRONOMY__JGARAGE__
2#define __JASTRONOMY__JGARAGE__
27 template<
class T, const
size_t factor = 0>
46 return accumulate(this->begin(), this->end(), 0, [](
const size_t n,
const value_type& buffer) {
return n + buffer.size(); });
61 return *min_element(i->begin(), i->end());
65 throw length_error(
"No data.");
80 return *max_element(i->begin(), i->end());
84 throw length_error(
"No data.");
96 return value * factor;
107 const size_t index =
getKey(value);
109 if (index >= this->size()) {
110 this->resize(index + 1);
113 (*this)[index].push_back(value);
123 template<
class JFunction_t>
124 void put(
const size_t N,
const JFunction_t&
object)
126 for (
size_t i = 0; i != N; ++i) {
137 template<
class JFunction_t>
141 for (
const T x : *i) {
158 if (P < 0.0 || P > 1.0) {
159 throw out_of_range(
"Invalid probability.");
162 const size_t N = this->
getN();
163 const size_t M = N - (P * N);
166 throw length_error(
"No data.");
169 if (M == 0) {
return getMin(); }
170 if (M == N) {
return getMax(); }
176 while ((n -= q->size()) > M) {
182 typename value_type::iterator p = next(buffer.begin(), M - n);
184 nth_element(buffer.begin(), p, buffer.end());
200 const size_t N = this->
getN();
201 const int M =
getKey(value);
204 throw length_error(
"No data.");
208 int i = this->size() - 1;
210 for ( ; i != -1 && i > M; --i) {
211 n += (*this)[i].size();
215 for (
const T x : (*
this)[i]) {
222 return (
double) n / (double) N;
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary container for statistical analysis of a large number of positive (or zero) values.
std::vector< std::vector< T > > map_type
void put(const size_t N, const JFunction_t &object)
Add values to container.
T getMax() const
Get maximal value.
static size_t getKey(const T value)
Get hash key corresponding to given value.
double getProbability(const T value) const
Get maximal probability corresponding given minimal value.
map_type::const_iterator const_iterator
T getValue(const double P) const
Get minimal value corresponding given maximal probability.
map_type::value_type value_type
size_t getN() const
Get total number of values.
map_type::const_reverse_iterator const_reverse_iterator
void operator()(const JFunction_t &object) const
For-each method.
T getMin() const
Get minimal value.
void put(const T value)
Add value to container.