@@ -21,78 +21,65 @@ pub type OrionResult<T> = std::result::Result<T, OrionPCSError>;
21
21
* IMPLEMENTATIONS FOR ORION EXPANDER GRAPH *
22
22
********************************************/
23
23
24
- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
25
- pub struct WeightedEdge < F : Field > {
26
- pub index : usize ,
27
- pub weight : F ,
28
- }
29
-
30
- impl < F : Field > WeightedEdge < F > {
31
- #[ inline( always) ]
32
- pub fn new ( index : usize , mut rng : impl rand:: RngCore ) -> Self {
33
- Self {
34
- index,
35
- weight : F :: random_unsafe ( & mut rng) ,
36
- }
37
- }
38
- }
24
+ type Edge = usize ;
39
25
40
- type Neighboring < F > = Vec < WeightedEdge < F > > ;
26
+ type Neighboring = Vec < Edge > ;
41
27
42
28
#[ derive( Clone ) ]
43
- pub struct OrionExpanderGraph < F : Field > {
29
+ pub struct OrionExpanderGraph {
44
30
// L R vertices size book keeping:
45
31
// keep track of message length (l), and "compressed" code length (r)
46
32
pub l_vertices_size : usize ,
47
33
pub r_vertices_size : usize ,
48
34
49
35
// neighboring stands for all (weighted) connected vertices of a vertex.
50
- // In this context, the weighted_neighborings stands for the neighborings
36
+ // In this context, the neighborings stands for the neighborings
51
37
// of vertices in R set of the bipariate graph, which explains why it has
52
38
// size of l_vertices_size, while each neighboring reserved r_vertices_size
53
39
// capacity.
54
- pub weighted_neighborings : Vec < Neighboring < F > > ,
40
+ pub neighborings : Vec < Neighboring > ,
55
41
}
56
42
57
- impl < F : Field > OrionExpanderGraph < F > {
43
+ impl OrionExpanderGraph {
58
44
pub fn new (
59
45
l_vertices_size : usize ,
60
46
r_vertices_size : usize ,
61
47
expanding_degree : usize ,
62
48
mut rng : impl rand:: RngCore ,
63
49
) -> Self {
64
- let mut weighted_neighborings : Vec < Neighboring < F > > =
50
+ let mut neighborings : Vec < Neighboring > =
65
51
vec ! [ Vec :: with_capacity( l_vertices_size) ; r_vertices_size] ;
66
52
67
53
( 0 ..l_vertices_size) . for_each ( |l_index| {
68
54
let random_r_vertices = index:: sample ( & mut rng, r_vertices_size, expanding_degree) ;
69
55
70
- random_r_vertices. iter ( ) . for_each ( |r_index| {
71
- weighted_neighborings [ r_index ] . push ( WeightedEdge :: new ( l_index , & mut rng ) )
72
- } )
56
+ random_r_vertices
57
+ . iter ( )
58
+ . for_each ( |r_index| neighborings [ r_index ] . push ( l_index ) )
73
59
} ) ;
74
60
75
61
Self {
76
- weighted_neighborings ,
62
+ neighborings ,
77
63
l_vertices_size,
78
64
r_vertices_size,
79
65
}
80
66
}
81
67
82
68
#[ inline( always) ]
83
- pub fn expander_mul ( & self , l_vertices : & [ F ] , r_vertices : & mut [ F ] ) -> OrionResult < ( ) > {
69
+ pub fn expander_mul < F : Field > (
70
+ & self ,
71
+ l_vertices : & [ F ] ,
72
+ r_vertices : & mut [ F ] ,
73
+ ) -> OrionResult < ( ) > {
84
74
if l_vertices. len ( ) != self . l_vertices_size || r_vertices. len ( ) != self . r_vertices_size {
85
75
return Err ( OrionPCSError :: ParameterUnmatchError ) ;
86
76
}
87
77
88
78
r_vertices
89
79
. iter_mut ( )
90
- . zip ( self . weighted_neighborings . iter ( ) )
80
+ . zip ( self . neighborings . iter ( ) )
91
81
. for_each ( |( ri, ni) | {
92
- * ri = ni
93
- . iter ( )
94
- . map ( |WeightedEdge { index, weight } | l_vertices[ * index] * weight)
95
- . sum ( ) ;
82
+ * ri = ni. iter ( ) . map ( |& edge_i| l_vertices[ edge_i] ) . sum ( ) ;
96
83
} ) ;
97
84
98
85
Ok ( ( ) )
@@ -139,15 +126,15 @@ impl OrionCodeParameter {
139
126
}
140
127
141
128
#[ derive( Clone ) ]
142
- pub struct OrionExpanderGraphPositioned < F : Field > {
143
- pub graph : OrionExpanderGraph < F > ,
129
+ pub struct OrionExpanderGraphPositioned {
130
+ pub graph : OrionExpanderGraph ,
144
131
145
132
pub input_starts : usize ,
146
133
pub output_starts : usize ,
147
134
pub output_ends : usize ,
148
135
}
149
136
150
- impl < F : Field > OrionExpanderGraphPositioned < F > {
137
+ impl OrionExpanderGraphPositioned {
151
138
#[ inline( always) ]
152
139
pub fn new (
153
140
input_starts : usize ,
@@ -170,7 +157,7 @@ impl<F: Field> OrionExpanderGraphPositioned<F> {
170
157
}
171
158
172
159
#[ inline( always) ]
173
- pub fn expander_mul ( & self , buffer : & mut [ F ] , scratch : & mut [ F ] ) -> OrionResult < ( ) > {
160
+ pub fn expander_mul < F : Field > ( & self , buffer : & mut [ F ] , scratch : & mut [ F ] ) -> OrionResult < ( ) > {
174
161
let input_ref = & buffer[ self . input_starts ..self . output_starts ] ;
175
162
let output_ref = & mut scratch[ self . output_starts ..self . output_ends + 1 ] ;
176
163
@@ -183,24 +170,24 @@ impl<F: Field> OrionExpanderGraphPositioned<F> {
183
170
184
171
// TODO: Orion code ascii code explanation for g0s and g1s, how they encode msg
185
172
#[ derive( Clone ) ]
186
- pub struct OrionCode < F : Field > {
173
+ pub struct OrionCode {
187
174
pub params : OrionCodeParameter ,
188
175
189
176
// g0s (affecting left side alphabets of the codeword)
190
177
// generated from the largest to the smallest
191
- pub g0s : Vec < OrionExpanderGraphPositioned < F > > ,
178
+ pub g0s : Vec < OrionExpanderGraphPositioned > ,
192
179
193
180
// g1s (affecting right side alphabets of the codeword)
194
181
// generated from the smallest to the largest
195
- pub g1s : Vec < OrionExpanderGraphPositioned < F > > ,
182
+ pub g1s : Vec < OrionExpanderGraphPositioned > ,
196
183
}
197
184
198
- impl < F : Field > OrionCode < F > {
185
+ impl OrionCode {
199
186
pub fn new ( params : OrionCodeParameter , mut rng : impl rand:: RngCore ) -> Self {
200
187
let mut recursive_code_msg_code_starts: Vec < ( usize , usize ) > = Vec :: new ( ) ;
201
188
202
- let mut g0s: Vec < OrionExpanderGraphPositioned < F > > = Vec :: new ( ) ;
203
- let mut g1s: Vec < OrionExpanderGraphPositioned < F > > = Vec :: new ( ) ;
189
+ let mut g0s: Vec < OrionExpanderGraphPositioned > = Vec :: new ( ) ;
190
+ let mut g1s: Vec < OrionExpanderGraphPositioned > = Vec :: new ( ) ;
204
191
205
192
let mut g0_input_starts = 0 ;
206
193
let mut g0_output_starts = params. input_message_len ;
@@ -254,7 +241,7 @@ impl<F: Field> OrionCode<F> {
254
241
}
255
242
256
243
#[ inline( always) ]
257
- pub fn encode ( & self , msg : & [ F ] ) -> OrionResult < Vec < F > > {
244
+ pub fn encode < F : Field > ( & self , msg : & [ F ] ) -> OrionResult < Vec < F > > {
258
245
if msg. len ( ) != self . msg_len ( ) {
259
246
return Err ( OrionPCSError :: ParameterUnmatchError ) ;
260
247
}
0 commit comments