Skip to content

Commit 720672a

Browse files
committed
add remaining docstrings
1 parent 01fadad commit 720672a

File tree

1 file changed

+105
-3
lines changed
  • hugr-core/src/std_extensions/collections/array

1 file changed

+105
-3
lines changed

hugr-core/src/std_extensions/collections/array/builder.rs

+105-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ use itertools::Itertools as _;
1313
pub trait ArrayOpBuilder: Dataflow {
1414
/// Adds a new array operation to the dataflow graph and return the wire
1515
/// representing the new array.
16-
///
16+
///
1717
/// # Arguments
18-
///
18+
///
1919
/// * `elem_ty` - The type of the elements in the array.
2020
/// * `values` - An iterator over the values to initialize the array with.
2121
///
2222
/// # Errors
23-
///
23+
///
2424
/// If building the operation fails.
25+
///
26+
/// # Returns
27+
///
28+
/// The wire representing the new array.
2529
fn add_new_array(
2630
&mut self,
2731
elem_ty: Type,
@@ -34,6 +38,22 @@ pub trait ArrayOpBuilder: Dataflow {
3438
Ok(out)
3539
}
3640

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.
3757
fn add_array_get(
3858
&mut self,
3959
elem_ty: Type,
@@ -49,6 +69,25 @@ pub trait ArrayOpBuilder: Dataflow {
4969
Ok(out)
5070
}
5171

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.
5291
fn add_array_set(
5392
&mut self,
5493
elem_ty: Type,
@@ -67,6 +106,25 @@ pub trait ArrayOpBuilder: Dataflow {
67106
Ok(out)
68107
}
69108

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.
70128
fn add_array_swap(
71129
&mut self,
72130
elem_ty: Type,
@@ -85,6 +143,23 @@ pub trait ArrayOpBuilder: Dataflow {
85143
Ok(out)
86144
}
87145

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>>
88163
fn add_array_pop_left(
89164
&mut self,
90165
elem_ty: Type,
@@ -98,6 +173,23 @@ pub trait ArrayOpBuilder: Dataflow {
98173
Ok(self.add_dataflow_op(op, vec![input])?.out_wire(0))
99174
}
100175

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>>
101193
fn add_array_pop_right(
102194
&mut self,
103195
elem_ty: Type,
@@ -111,6 +203,16 @@ pub trait ArrayOpBuilder: Dataflow {
111203
Ok(self.add_dataflow_op(op, vec![input])?.out_wire(0))
112204
}
113205

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.
114216
fn add_array_discard_empty(&mut self, elem_ty: Type, input: Wire) -> Result<(), BuildError> {
115217
// TODO Add an OpLoadError variant to BuildError
116218
self.add_dataflow_op(

0 commit comments

Comments
 (0)