@@ -34,11 +34,17 @@ pub struct Morphism<G: Group> {
3434fn msm_pr < G : Group > ( scalars : & [ G :: Scalar ] , bases : & [ G ] ) -> G {
3535 let mut acc = G :: identity ( ) ;
3636 for ( s, p) in scalars. iter ( ) . zip ( bases. iter ( ) ) {
37- acc = acc + ( * p * s. clone ( ) ) ;
37+ acc += * p * s;
3838 }
3939 acc
4040}
4141
42+ impl < G : Group > Default for Morphism < G > {
43+ fn default ( ) -> Self {
44+ Self :: new ( )
45+ }
46+ }
47+
4248impl < G : Group > Morphism < G > {
4349 /// Creates a new empty Morphism.
4450 pub fn new ( ) -> Self {
@@ -65,8 +71,8 @@ impl<G: Group> Morphism<G> {
6571 /// Computes all linear combinations using the provided scalars and returns their group outputs.
6672 pub fn evaluate ( & self , scalars : & [ <G as Group >:: Scalar ] ) -> Vec < G > {
6773 self . linear_combination . iter ( ) . map ( |lc| {
68- let coefficients: Vec < _ > = lc. scalar_indices . iter ( ) . map ( |& i| scalars[ i] . clone ( ) ) . collect ( ) ;
69- let elements: Vec < _ > = lc. element_indices . iter ( ) . map ( |& i| self . group_elements [ i] . clone ( ) ) . collect ( ) ;
74+ let coefficients: Vec < _ > = lc. scalar_indices . iter ( ) . map ( |& i| scalars[ i] ) . collect ( ) ;
75+ let elements: Vec < _ > = lc. element_indices . iter ( ) . map ( |& i| self . group_elements [ i] ) . collect ( ) ;
7076 msm_pr ( & coefficients, & elements)
7177 } ) . collect ( )
7278 }
8793 pub image : Vec < usize > ,
8894}
8995
96+ impl < G > Default for GroupMorphismPreimage < G >
97+ where
98+ G : Group + GroupEncoding ,
99+ {
100+ fn default ( ) -> Self {
101+ Self :: new ( )
102+ }
103+ }
104+
90105impl < G > GroupMorphismPreimage < G >
91106where
92107 G : Group + GroupEncoding ,
@@ -143,15 +158,15 @@ where
143158 /// Set the value of group elements at a given index, inside the list of allocated group elements.
144159 pub fn set_elements ( & mut self , elements : & [ ( usize , G ) ] ) {
145160 for & ( i, ref elt) in elements {
146- self . morphism . group_elements [ i] = elt. clone ( ) ;
161+ self . morphism . group_elements [ i] = * elt;
147162 }
148163 }
149164
150165 /// Return the group elements corresponding to the image indices.
151166 pub fn image ( & self ) -> Vec < G > {
152167 let mut result = Vec :: new ( ) ;
153168 for i in & self . image {
154- result. push ( self . morphism . group_elements [ * i] . clone ( ) ) ;
169+ result. push ( self . morphism . group_elements [ * i] ) ;
155170 }
156171 result
157172 }
0 commit comments