tudocomp
– The TU Dortmund Compression Framework
HashArray.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include<array>
4 
7 
8 namespace tdc {namespace esp {
9  using in_t = BitPackingVectorSlice<dynamic_t>;
10 
11  template<size_t N, typename T = size_t>
12  struct Array {
14 
15  std::array<T, N> m_data;
16  Array() {
17  for(size_t i = 0; i < N; i++) {
18  m_data[i] = 0;
19  }
20  }
21  Array(in_t v) {
22  DCHECK_EQ(v.size(), N);
23  for(size_t i = 0; i < N; i++) {
24  m_data[i] = v[i];
25  }
26  }
27  Array(const std::array<T, N>& v): Array(in_t(v)) {}
28 
29  inline in_t as_view() const {
30  return in_t(m_data);
31  }
32  };
33 
34  template<size_t N, typename T>
35  bool operator==(const Array<N, T>& lhs, const Array<N, T>& rhs) {
36  for(size_t i = 0; i < N; i++) {
37  if (lhs.m_data[i] != rhs.m_data[i]) return false;
38  }
39  return true;
40  }
41 }}
42 namespace std {
43  template<size_t N, typename T>
44  struct hash<tdc::esp::Array<N, T>>
45  {
46  size_t operator()(const tdc::esp::Array<N, T>& x) const {
47  return std::hash<tdc::ConstGenericView<T>>()(
49  x.m_data.data(),
50  x.m_data.size()
51  });
52  }
53  };
54 }
BitPackingVectorSlice< dynamic_t > in_t
Definition: HashArray.hpp:9
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
in_t as_view() const
Definition: HashArray.hpp:29
A const view into a slice of memory.
size_type size() const
Returns size of the View.
bool operator==(const Array< N, T > &lhs, const Array< N, T > &rhs)
Definition: HashArray.hpp:35
size_t operator()(const tdc::esp::Array< N, T > &x) const
Definition: HashArray.hpp:46
std::array< T, N > m_data
Definition: HashArray.hpp:15
Array(const std::array< T, N > &v)
Definition: HashArray.hpp:27
ConstGenericView< T > in_t
Definition: HashArray.hpp:13