1 #ifndef BARRY_STATSDB_HPP
2 #define BARRY_STATSDB_HPP 1
21 template<
typename T =
double>
25 std::unordered_map<size_t, size_t> index;
26 std::vector< double > data;
30 typename std::unordered_map<size_t, size_t>::iterator iter;
37 size_t add(
const std::vector< T > & x,
size_t * h_precomp);
41 const std::unordered_map<size_t,size_t> &
get_index()
const {
return index;};
44 void reserve(
size_t n,
size_t k);
54 size_t make_hash(const std::vector< T > & x) const;
60 const std::vector< T > & x,
67 if (h_precomp ==
nullptr)
75 index.insert({h, 0u});
78 data.insert(
data.end(), x.begin(), x.end());
91 throw std::length_error(
92 "The value you are trying to add doesn't have the same lenght used in the database."
95 #if __cplusplus > 201700L
96 auto iter2 = index.try_emplace(h,
data.size());
101 data[(iter2.first)->second] += 1.0;
107 data.insert(
data.end(), x.begin(), x.end());
111 iter = index.find(h);
113 if (iter == index.end())
117 index.insert({h,
data.size()});
119 data.insert(
data.end(), x.begin(), x.end());
127 data[(*iter).second] += 1.0;
144 ans.reserve(index.size());
146 for (
size_t i = 0u;
i < n; ++
i)
149 std::vector< double > tmp(k, 0.0);
151 for (
size_t j = 1u;
j < (k + 1u); ++
j)
152 tmp[
j - 1u] =
data[
i * (k + 1) +
j];
155 std::make_pair<std::vector<double>,
size_t>(
157 static_cast<size_t>(
data[
i * (k + 1u)])
207 size_t grand_total = 0u;
211 for (
size_t i = 0u;
i < n; ++
i)
216 for (
size_t j = 1u;
j < (k + 1u); ++
j)
220 grand_total +=
static_cast<size_t>(
data[
i * (k + 1u)]);
243 std::size_t hash =
hasher(x[0u]);
249 for (
size_t i = 1u;
i < x.size(); ++
i)
250 hash ^=
hasher(x[
i]) + 0x9e3779b9 + (hash<<6) + (hash>>2);
#define BARRY_MAX_NUM_ELEMENTS
Frequency table of vectors.
void reserve(size_t n, size_t k)
Counts_type as_vector() const
const std::vector< double > & get_data() const
const std::unordered_map< size_t, size_t > & get_index() const
size_t make_hash(const std::vector< T > &x) const
size_t add(const std::vector< T > &x, size_t *h_precomp)
size_t size() const noexcept
Number of unique elements in the table. (.
Data_Type &&counter_ data(std::move(counter_.data))
Data_Type hasher(counter_.hasher)
Data_Type &&counter_ noexcept
std::vector< std::pair< std::vector< double >, size_t > > Counts_type