Skip to content

Commit d1fdd8c

Browse files
committed
add method to set length
1 parent ac358b1 commit d1fdd8c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/lib/provable/dynamic-array.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,19 @@ class DynamicArrayBase<ProvableValue = any, Value = any> {
321321
this.length = oldLength.sub(n).seal();
322322
}
323323

324+
/**
325+
* Sets the length of the current array to a new value, checking that the
326+
* new length is less or equal than the capacity.
327+
*
328+
* @param newLength
329+
*
330+
* **Warning**: This does not change (add nor remove) the values of the array.
331+
*/
332+
setLengthTo(n: Field): void {
333+
n.assertLessThanOrEqual(new Field(this.capacity));
334+
this.length = n;
335+
}
336+
324337
/**
325338
* Push a value, without changing the capacity.
326339
*

0 commit comments

Comments
 (0)