Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
accumulation_vector.tcc
Go to the documentation of this file.
1 /** @file
2  *****************************************************************************
3 
4  Implementation of interfaces for an accumulation vector.
5 
6  See accumulation_vector.hpp .
7 
8  *****************************************************************************
9  * @author This file is part of libsnark, developed by SCIPR Lab
10  * and contributors (see AUTHORS).
11  * @copyright MIT license (see LICENSE file)
12  *****************************************************************************/
13 
14 #ifndef ACCUMULATION_VECTOR_TCC_
15 #define ACCUMULATION_VECTOR_TCC_
16 
17 namespace libsnark
18 {
19 
20 template<typename T>
21 bool accumulation_vector<T>::operator==(
22  const accumulation_vector<T> &other) const
23 {
24  return (this->first == other.first && this->rest == other.rest);
25 }
26 
27 template<typename T> bool accumulation_vector<T>::is_fully_accumulated() const
28 {
29  return rest.empty();
30 }
31 
32 template<typename T> size_t accumulation_vector<T>::domain_size() const
33 {
34  return rest.domain_size();
35 }
36 
37 template<typename T> size_t accumulation_vector<T>::size() const
38 {
39  return rest.domain_size();
40 }
41 
42 template<typename T> size_t accumulation_vector<T>::size_in_bits() const
43 {
44  const size_t first_size_in_bits = T::size_in_bits();
45  const size_t rest_size_in_bits = rest.size_in_bits();
46  return first_size_in_bits + rest_size_in_bits;
47 }
48 
49 template<typename T>
50 template<typename FieldT>
51 accumulation_vector<T> accumulation_vector<T>::accumulate_chunk(
52  const typename std::vector<FieldT>::const_iterator &it_begin,
53  const typename std::vector<FieldT>::const_iterator &it_end,
54  const size_t offset) const
55 {
56  std::pair<T, sparse_vector<T>> acc_result =
57  rest.template accumulate<FieldT>(it_begin, it_end, offset);
58  T new_first = first + acc_result.first;
59  return accumulation_vector<T>(
60  std::move(new_first), std::move(acc_result.second));
61 }
62 
63 template<typename T>
64 std::ostream &operator<<(std::ostream &out, const accumulation_vector<T> &v)
65 {
66  out << v.first << OUTPUT_NEWLINE;
67  out << v.rest << OUTPUT_NEWLINE;
68 
69  return out;
70 }
71 
72 template<typename T>
73 std::istream &operator>>(std::istream &in, accumulation_vector<T> &v)
74 {
75  in >> v.first;
76  libff::consume_OUTPUT_NEWLINE(in);
77  in >> v.rest;
78  libff::consume_OUTPUT_NEWLINE(in);
79 
80  return in;
81 }
82 
83 } // namespace libsnark
84 
85 #endif // ACCUMULATION_VECTOR_TCC_