diff --git a/AK/Statistics.h b/AK/Statistics.h index 0c193d7ed4..071f016475 100644 --- a/AK/Statistics.h +++ b/AK/Statistics.h @@ -17,12 +17,19 @@ namespace AK { static constexpr int ODD_NAIVE_MEDIAN_CUTOFF = 200; static constexpr int EVEN_NAIVE_MEDIAN_CUTOFF = 350; -template +template> class Statistics { public: Statistics() = default; ~Statistics() = default; + explicit Statistics(ContainerType&& existing_container) + : m_values(forward(existing_container)) + { + for (auto const& value : m_values) + m_sum += value; + } + void add(T const& value) { // FIXME: Check for an overflow @@ -107,11 +114,11 @@ public: return summation; } - Vector const& values() const { return m_values; } + ContainerType const& values() const { return m_values; } size_t size() const { return m_values.size(); } private: - Vector m_values; + ContainerType m_values; T m_sum {}; };