@@ -13,15 +13,19 @@ use itertools::Itertools as _;
13
13
pub trait ArrayOpBuilder : Dataflow {
14
14
/// Adds a new array operation to the dataflow graph and return the wire
15
15
/// representing the new array.
16
- ///
16
+ ///
17
17
/// # Arguments
18
- ///
18
+ ///
19
19
/// * `elem_ty` - The type of the elements in the array.
20
20
/// * `values` - An iterator over the values to initialize the array with.
21
21
///
22
22
/// # Errors
23
- ///
23
+ ///
24
24
/// If building the operation fails.
25
+ ///
26
+ /// # Returns
27
+ ///
28
+ /// The wire representing the new array.
25
29
fn add_new_array (
26
30
& mut self ,
27
31
elem_ty : Type ,
@@ -34,6 +38,22 @@ pub trait ArrayOpBuilder: Dataflow {
34
38
Ok ( out)
35
39
}
36
40
41
+ /// Adds an array get operation to the dataflow graph.
42
+ ///
43
+ /// # Arguments
44
+ ///
45
+ /// * `elem_ty` - The type of the elements in the array.
46
+ /// * `size` - The size of the array.
47
+ /// * `input` - The wire representing the array.
48
+ /// * `index` - The wire representing the index to get.
49
+ ///
50
+ /// # Errors
51
+ ///
52
+ /// If building the operation fails.
53
+ ///
54
+ /// # Returns
55
+ ///
56
+ /// The wire representing the value at the specified index in the array.
37
57
fn add_array_get (
38
58
& mut self ,
39
59
elem_ty : Type ,
@@ -49,6 +69,25 @@ pub trait ArrayOpBuilder: Dataflow {
49
69
Ok ( out)
50
70
}
51
71
72
+ /// Adds an array set operation to the dataflow graph.
73
+ ///
74
+ /// This operation sets the value at a specified index in the array.
75
+ ///
76
+ /// # Arguments
77
+ ///
78
+ /// * `elem_ty` - The type of the elements in the array.
79
+ /// * `size` - The size of the array.
80
+ /// * `input` - The wire representing the array.
81
+ /// * `index` - The wire representing the index to set.
82
+ /// * `value` - The wire representing the value to set at the specified index.
83
+ ///
84
+ /// # Errors
85
+ ///
86
+ /// Returns an error if building the operation fails.
87
+ ///
88
+ /// # Returns
89
+ ///
90
+ /// The wire representing the updated array after the set operation.
52
91
fn add_array_set (
53
92
& mut self ,
54
93
elem_ty : Type ,
@@ -67,6 +106,25 @@ pub trait ArrayOpBuilder: Dataflow {
67
106
Ok ( out)
68
107
}
69
108
109
+ /// Adds an array swap operation to the dataflow graph.
110
+ ///
111
+ /// This operation swaps the values at two specified indices in the array.
112
+ ///
113
+ /// # Arguments
114
+ ///
115
+ /// * `elem_ty` - The type of the elements in the array.
116
+ /// * `size` - The size of the array.
117
+ /// * `input` - The wire representing the array.
118
+ /// * `index1` - The wire representing the first index to swap.
119
+ /// * `index2` - The wire representing the second index to swap.
120
+ ///
121
+ /// # Errors
122
+ ///
123
+ /// Returns an error if building the operation fails.
124
+ ///
125
+ /// # Returns
126
+ ///
127
+ /// The wire representing the updated array after the swap operation.
70
128
fn add_array_swap (
71
129
& mut self ,
72
130
elem_ty : Type ,
@@ -85,6 +143,23 @@ pub trait ArrayOpBuilder: Dataflow {
85
143
Ok ( out)
86
144
}
87
145
146
+ /// Adds an array pop-left operation to the dataflow graph.
147
+ ///
148
+ /// This operation removes the leftmost element from the array.
149
+ ///
150
+ /// # Arguments
151
+ ///
152
+ /// * `elem_ty` - The type of the elements in the array.
153
+ /// * `size` - The size of the array.
154
+ /// * `input` - The wire representing the array.
155
+ ///
156
+ /// # Errors
157
+ ///
158
+ /// Returns an error if building the operation fails.
159
+ ///
160
+ /// # Returns
161
+ ///
162
+ /// The wire representing the Option<elemty, array<SIZE-1, elemty>>
88
163
fn add_array_pop_left (
89
164
& mut self ,
90
165
elem_ty : Type ,
@@ -98,6 +173,23 @@ pub trait ArrayOpBuilder: Dataflow {
98
173
Ok ( self . add_dataflow_op ( op, vec ! [ input] ) ?. out_wire ( 0 ) )
99
174
}
100
175
176
+ /// Adds an array pop-right operation to the dataflow graph.
177
+ ///
178
+ /// This operation removes the rightmost element from the array.
179
+ ///
180
+ /// # Arguments
181
+ ///
182
+ /// * `elem_ty` - The type of the elements in the array.
183
+ /// * `size` - The size of the array.
184
+ /// * `input` - The wire representing the array.
185
+ ///
186
+ /// # Errors
187
+ ///
188
+ /// Returns an error if building the operation fails.
189
+ ///
190
+ /// # Returns
191
+ ///
192
+ /// The wire representing the Option<elemty, array<SIZE-1, elemty>>
101
193
fn add_array_pop_right (
102
194
& mut self ,
103
195
elem_ty : Type ,
@@ -111,6 +203,16 @@ pub trait ArrayOpBuilder: Dataflow {
111
203
Ok ( self . add_dataflow_op ( op, vec ! [ input] ) ?. out_wire ( 0 ) )
112
204
}
113
205
206
+ /// Adds an operation to discard an empty array from the dataflow graph.
207
+ ///
208
+ /// # Arguments
209
+ ///
210
+ /// * `elem_ty` - The type of the elements in the array.
211
+ /// * `input` - The wire representing the array.
212
+ ///
213
+ /// # Errors
214
+ ///
215
+ /// Returns an error if building the operation fails.
114
216
fn add_array_discard_empty ( & mut self , elem_ty : Type , input : Wire ) -> Result < ( ) , BuildError > {
115
217
// TODO Add an OpLoadError variant to BuildError
116
218
self . add_dataflow_op (
0 commit comments