/** @file ***************************************************************************** Declaration of interfaces for a sparse vector. ***************************************************************************** * @author This file is part of libsnark, developed by SCIPR Lab * and contributors (see AUTHORS). * @copyright MIT license (see LICENSE file) *****************************************************************************/ #ifndef SPARSE_VECTOR_HPP_ #define SPARSE_VECTOR_HPP_ #include namespace libsnark { template struct sparse_vector; template std::ostream& operator<<(std::ostream &out, const sparse_vector &v); template std::istream& operator>>(std::istream &in, sparse_vector &v); /** * A sparse vector is a list of indices along with corresponding values. * The indices are selected from the set {0,1,...,domain_size-1}. */ template struct sparse_vector { std::vector indices; std::vector values; size_t domain_size_ = 0; sparse_vector() = default; sparse_vector(const sparse_vector &other) = default; sparse_vector(sparse_vector &&other) = default; sparse_vector(std::vector &&v); /* constructor from std::vector */ sparse_vector& operator=(const sparse_vector &other) = default; sparse_vector& operator=(sparse_vector &&other) = default; T operator[](const size_t idx) const; bool operator==(const sparse_vector &other) const; bool operator==(const std::vector &other) const; bool is_valid() const; bool empty() const; size_t domain_size() const; // return domain_size_ size_t size() const; // return the number of indices (representing the number of non-zero entries) size_t size_in_bits() const; // return the number bits needed to store the sparse vector /* return a pair consisting of the accumulated value and the sparse vector of non-accumulated values */ template std::pair > accumulate(const typename std::vector::const_iterator &it_begin, const typename std::vector::const_iterator &it_end, const size_t offset) const; friend std::ostream& operator<< (std::ostream &out, const sparse_vector &v); friend std::istream& operator>> (std::istream &in, sparse_vector &v); }; template std::ostream& operator<<(std::ostream& out, const sparse_vector &v); template std::istream& operator>>(std::istream& in, sparse_vector &v); } // libsnark #include "common/data_structures/sparse_vector.tcc" #endif // SPARSE_VECTOR_HPP_