From 196519767b42f9f7df1175a5c3f27f00750a7b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kami=C5=84ski?= Date: Fri, 20 Oct 2023 15:27:42 +0200 Subject: [PATCH] Use anonymous generic impl parameters (#197) ## Pull Request type Please check the type of change your PR introduces: - [ ] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no API changes) - [ ] Build-related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? Issue Number: N/A ## What is the new behavior? - - - ## Does this introduce a breaking change? - [ ] Yes - [ ] No ## Other information --- src/ascii/src/integer.cairo | 54 ++++----- src/bytes/src/utils.cairo | 6 +- src/data_structures/src/array_ext.cairo | 108 ++++++------------ src/data_structures/src/stack.cairo | 12 +- .../src/tests/stack_test.cairo | 22 ++-- src/data_structures/src/tests/vec_test.cairo | 68 +++-------- src/data_structures/src/vec.cairo | 12 +- src/encoding/src/reversible.cairo | 27 ++--- src/linalg/src/dot.cairo | 9 +- src/merkle_tree/src/merkle_tree.cairo | 8 +- src/numeric/src/cumsum.cairo | 4 +- src/numeric/src/diff.cairo | 9 +- src/numeric/src/interpolate.cairo | 18 +-- src/numeric/src/trapezoidal_rule.cairo | 24 ++-- src/searching/src/binary_search.cairo | 4 +- src/searching/src/dijkstra.cairo | 5 +- src/sorting/src/bubble_sort.cairo | 8 +- src/sorting/src/merge_sort.cairo | 12 +- src/storage/src/list.cairo | 8 +- 19 files changed, 146 insertions(+), 272 deletions(-) diff --git a/src/ascii/src/integer.cairo b/src/ascii/src/integer.cairo index 535be864..42c85760 100644 --- a/src/ascii/src/integer.cairo +++ b/src/ascii/src/integer.cairo @@ -18,14 +18,14 @@ trait ToAsciiArrayTrait { // e.g. 123 -> [49, 50, 51] impl ToAsciiArrayTraitImpl< T, - impl TPartialOrd: PartialOrd, - impl TDivRem: DivRem, - impl TInto: Into, - impl TryInto: TryInto, - impl TTryIntoZero: TryInto>, - impl TZeroable: Zeroable, - impl TDrop: Drop, - impl TCopy: Copy, + +PartialOrd, + +DivRem, + +Into, + +TryInto, + +TryInto>, + +Zeroable, + +Drop, + +Copy, > of ToAsciiArrayTrait { fn to_ascii_array(self: T) -> Array { let mut new_arr = self.to_inverse_ascii_array(); @@ -54,19 +54,19 @@ impl ToAsciiArrayTraitImpl< } } -// generic implementation for small integers "1000" impl SmallIntegerToAsciiTraitImpl< T, - impl TPartialOrd: PartialOrd, - impl TDivRem: DivRem, - impl TInto: Into, - impl TTryInto: TryInto, - impl TTryIntoZero: TryInto>, - impl TZeroable: Zeroable, - impl TDrop: Drop, - impl TCopy: Copy, + +PartialOrd, + +DivRem, + +Into, + +TryInto, + +TryInto>, + +Zeroable, + +Drop, + +Copy, > of ToAsciiTrait { fn to_ascii(self: T) -> felt252 { if self <= 9.try_into().unwrap() { @@ -86,19 +86,19 @@ impl SmallIntegerToAsciiTraitImpl< } } -// generic implementation for big integers u128 +// generic implementation for big integers u128 // to transform its integers into a string represented as multiple felt252 if there is overflow // e.g. max_num + 123 -> ["max_num", "123"] impl BigIntegerToAsciiTraitImpl< T, - impl TPartialOrd: PartialOrd, - impl TDivRem: DivRem, - impl TInto: Into, - impl TTryInto: TryInto, - impl TTryIntoZero: TryInto>, - impl TZeroable: Zeroable, - impl TDrop: Drop, - impl TCopy: Copy, + +PartialOrd, + +DivRem, + +Into, + +TryInto, + +TryInto>, + +Zeroable, + +Drop, + +Copy, > of ToAsciiTrait> { fn to_ascii(self: T) -> Array { let mut data = ArrayTrait::new(); @@ -141,7 +141,7 @@ impl BigIntegerToAsciiTraitImpl< // -------------------------------------------------------------------------- // // for u256 // // -------------------------------------------------------------------------- // -// have to implement separately for u256 because +// have to implement separately for u256 because // it doesn't have the same implementations as the generic version impl U256ToAsciiArrayTraitImpl of ToAsciiArrayTrait { fn to_ascii_array(self: u256) -> Array { diff --git a/src/bytes/src/utils.cairo b/src/bytes/src/utils.cairo index 54cdf1a6..e514288d 100644 --- a/src/bytes/src/utils.cairo +++ b/src/bytes/src/utils.cairo @@ -32,9 +32,7 @@ fn keccak_u128s_be(mut input: Span, n_bytes: usize) -> u256 { /// return the minimal value /// support u8, u16, u32, u64, u128, u256 -fn uint_min, impl TPartialOrd: PartialOrd, impl TCopy: Copy>( - l: T, r: T -) -> T { +fn uint_min, +PartialOrd, +Copy>(l: T, r: T) -> T { if l <= r { l } else { @@ -219,7 +217,7 @@ fn read_sub_u128(value: u128, value_size: usize, offset: usize, size: usize) -> /// - right_size: the size of right part in bytes /// Returns: /// - value: the joined u128 -/// Examples: +/// Examples: /// u128_join(0x010203, 0xaabb, 2) -> 0x010203aabb /// u128_join(0x010203, 0, 2) -> 0x0102030000 fn u128_join(left: u128, right: u128, right_size: usize) -> u128 { diff --git a/src/data_structures/src/array_ext.cairo b/src/data_structures/src/array_ext.cairo index 2fc6f898..5d535bb3 100644 --- a/src/data_structures/src/array_ext.cairo +++ b/src/data_structures/src/array_ext.cairo @@ -5,51 +5,35 @@ trait ArrayTraitExt { fn append_all(ref self: Array, ref arr: Array); fn pop_front_n(ref self: Array, n: usize); fn reverse(self: @Array) -> Array; - fn contains>(self: @Array, item: T) -> bool; + fn contains<+PartialEq>(self: @Array, item: T) -> bool; fn concat(self: @Array, a: @Array) -> Array; - fn index_of>(self: @Array, item: T) -> Option; - fn occurrences_of>(self: @Array, item: T) -> usize; - fn min, impl TPartialOrd: PartialOrd>( - self: @Array - ) -> Option; - fn index_of_min, impl TPartialOrd: PartialOrd>( - self: @Array - ) -> Option; - fn max, impl TPartialOrd: PartialOrd>( - self: @Array - ) -> Option; - fn index_of_max, impl TPartialOrd: PartialOrd>( - self: @Array - ) -> Option; - fn dedup>(self: @Array) -> Array; - fn unique>(self: @Array) -> Array; + fn index_of<+PartialEq>(self: @Array, item: T) -> Option; + fn occurrences_of<+PartialEq>(self: @Array, item: T) -> usize; + fn min<+PartialEq, +PartialOrd>(self: @Array) -> Option; + fn index_of_min<+PartialEq, +PartialOrd>(self: @Array) -> Option; + fn max<+PartialEq, +PartialOrd>(self: @Array) -> Option; + fn index_of_max<+PartialEq, +PartialOrd>(self: @Array) -> Option; + fn dedup<+PartialEq>(self: @Array) -> Array; + fn unique<+PartialEq>(self: @Array) -> Array; } trait SpanTraitExt { fn pop_front_n(ref self: Span, n: usize); fn pop_back_n(ref self: Span, n: usize); fn reverse(self: Span) -> Array; - fn contains>(self: Span, item: T) -> bool; + fn contains<+PartialEq>(self: Span, item: T) -> bool; fn concat(self: Span, a: Span) -> Span; - fn index_of>(self: Span, item: T) -> Option; - fn occurrences_of>(self: Span, item: T) -> usize; - fn min, impl TPartialOrd: PartialOrd>( - self: Span - ) -> Option; - fn index_of_min, impl TPartialOrd: PartialOrd>( - self: Span - ) -> Option; - fn max, impl TPartialOrd: PartialOrd>( - self: Span - ) -> Option; - fn index_of_max, impl TPartialOrd: PartialOrd>( - self: Span - ) -> Option; - fn dedup>(self: Span) -> Array; - fn unique>(self: Span) -> Array; + fn index_of<+PartialEq>(self: Span, item: T) -> Option; + fn occurrences_of<+PartialEq>(self: Span, item: T) -> usize; + fn min<+PartialEq, +PartialOrd>(self: Span) -> Option; + fn index_of_min<+PartialEq, +PartialOrd>(self: Span) -> Option; + fn max<+PartialEq, +PartialOrd>(self: Span) -> Option; + fn index_of_max<+PartialEq, +PartialOrd>(self: Span) -> Option; + fn dedup<+PartialEq>(self: Span) -> Array; + fn unique<+PartialEq>(self: Span) -> Array; } -impl ArrayImpl, impl TDrop: Drop> of ArrayTraitExt { +impl ArrayImpl, +Drop> of ArrayTraitExt { fn append_all(ref self: Array, ref arr: Array) { match arr.pop_front() { Option::Some(v) => { @@ -77,7 +61,7 @@ impl ArrayImpl, impl TDrop: Drop> of ArrayTraitExt self.span().reverse() } - fn contains>(self: @Array, item: T) -> bool { + fn contains<+PartialEq>(self: @Array, item: T) -> bool { self.span().contains(item) } @@ -104,48 +88,40 @@ impl ArrayImpl, impl TDrop: Drop> of ArrayTraitExt ret } - fn index_of>(self: @Array, item: T) -> Option { + fn index_of<+PartialEq>(self: @Array, item: T) -> Option { self.span().index_of(item) } - fn occurrences_of>(self: @Array, item: T) -> usize { + fn occurrences_of<+PartialEq>(self: @Array, item: T) -> usize { self.span().occurrences_of(item) } - fn min, impl TPartialOrd: PartialOrd>( - self: @Array - ) -> Option { + fn min<+PartialEq, +PartialOrd>(self: @Array) -> Option { self.span().min() } - fn index_of_min, impl TPartialOrd: PartialOrd>( - self: @Array - ) -> Option { + fn index_of_min<+PartialEq, +PartialOrd>(self: @Array) -> Option { self.span().index_of_min() } - fn max, impl TPartialOrd: PartialOrd>( - self: @Array - ) -> Option { + fn max<+PartialEq, +PartialOrd>(self: @Array) -> Option { self.span().max() } - fn index_of_max, impl TPartialOrd: PartialOrd>( - mut self: @Array - ) -> Option { + fn index_of_max<+PartialEq, +PartialOrd>(mut self: @Array) -> Option { self.span().index_of_max() } - fn dedup>(mut self: @Array) -> Array { + fn dedup<+PartialEq>(mut self: @Array) -> Array { self.span().dedup() } - fn unique>(mut self: @Array) -> Array { + fn unique<+PartialEq>(mut self: @Array) -> Array { self.span().unique() } } -impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { +impl SpanImpl, +Drop> of SpanTraitExt { fn pop_front_n(ref self: Span, mut n: usize) { loop { if n == 0 { @@ -183,7 +159,7 @@ impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { response } - fn contains>(mut self: Span, item: T) -> bool { + fn contains<+PartialEq>(mut self: Span, item: T) -> bool { loop { match self.pop_front() { Option::Some(v) => { if *v == item { @@ -216,7 +192,7 @@ impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { ret.span() } - fn index_of>(mut self: Span, item: T) -> Option { + fn index_of<+PartialEq>(mut self: Span, item: T) -> Option { let mut index = 0_usize; loop { match self.pop_front() { @@ -231,7 +207,7 @@ impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { } } - fn occurrences_of>(mut self: Span, item: T) -> usize { + fn occurrences_of<+PartialEq>(mut self: Span, item: T) -> usize { let mut count = 0_usize; loop { match self.pop_front() { @@ -243,9 +219,7 @@ impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { } } - fn min, impl TPartialOrd: PartialOrd>( - mut self: Span - ) -> Option { + fn min<+PartialEq, +PartialOrd>(mut self: Span) -> Option { let mut min = match self.pop_front() { Option::Some(item) => *item, Option::None => { return Option::None; }, @@ -260,9 +234,7 @@ impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { } } - fn index_of_min, impl TPartialOrd: PartialOrd>( - mut self: Span - ) -> Option { + fn index_of_min<+PartialEq, +PartialOrd>(mut self: Span) -> Option { let mut index = 0; let mut index_of_min = 0; let mut min: T = match self.pop_front() { @@ -281,9 +253,7 @@ impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { } } - fn max, impl TPartialOrd: PartialOrd>( - mut self: Span - ) -> Option { + fn max<+PartialEq, +PartialOrd>(mut self: Span) -> Option { let mut max = match self.pop_front() { Option::Some(item) => *item, Option::None => { return Option::None; }, @@ -298,9 +268,7 @@ impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { } } - fn index_of_max, impl TPartialOrd: PartialOrd>( - mut self: Span - ) -> Option { + fn index_of_max<+PartialEq, +PartialOrd>(mut self: Span) -> Option { let mut index = 0; let mut index_of_max = 0; let mut max = match self.pop_front() { @@ -319,7 +287,7 @@ impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { } } - fn dedup>(mut self: Span) -> Array { + fn dedup<+PartialEq>(mut self: Span) -> Array { if self.len() == 0 { return array![]; } @@ -340,7 +308,7 @@ impl SpanImpl, impl TDrop: Drop> of SpanTraitExt { ret } - fn unique>(mut self: Span) -> Array { + fn unique<+PartialEq>(mut self: Span) -> Array { let mut ret = array![]; loop { match self.pop_front() { diff --git a/src/data_structures/src/stack.cairo b/src/data_structures/src/stack.cairo index efc6b940..0389112b 100644 --- a/src/data_structures/src/stack.cairo +++ b/src/data_structures/src/stack.cairo @@ -39,16 +39,14 @@ struct Felt252Stack { len: usize, } -impl DestructFeltStack< - T, impl TDrop: Drop, impl TFelt252DictValue: Felt252DictValue -> of Destruct> { +impl DestructFeltStack, +Felt252DictValue> of Destruct> { fn destruct(self: Felt252Stack) nopanic { self.elements.squash(); } } impl Felt252StackImpl< - T, impl TCopy: Copy, impl TDrop: Drop, impl TFelt252DictValue: Felt252DictValue, + T, +Copy, +Drop, +Felt252DictValue, > of StackTrait, T> { #[inline(always)] /// Creates a new Stack instance. @@ -116,15 +114,13 @@ struct NullableStack { len: usize, } -impl DestructNullableStack> of Destruct> { +impl DestructNullableStack> of Destruct> { fn destruct(self: NullableStack) nopanic { self.elements.squash(); } } -impl NullableStackImpl< - T, impl TCopy: Copy, impl TDrop: Drop, -> of StackTrait, T> { +impl NullableStackImpl, +Drop,> of StackTrait, T> { #[inline(always)] fn new() -> NullableStack { let elements: Felt252Dict> = Default::default(); diff --git a/src/data_structures/src/tests/stack_test.cairo b/src/data_structures/src/tests/stack_test.cairo index 6cdda8e6..980f4d0e 100644 --- a/src/data_structures/src/tests/stack_test.cairo +++ b/src/data_structures/src/tests/stack_test.cairo @@ -15,9 +15,7 @@ fn stack_is_empty_test>(stack: @S) { assert(stack.is_empty(), 'stack should be empty'); } -fn stack_push_test< - S, T, impl Stack: StackTrait, impl TDrop: Drop, impl SDestruct: Destruct ->( +fn stack_push_test, +Drop, impl SDestruct: Destruct>( ref stack: S, val_1: T, val_2: T ) { stack.push(val_1); @@ -31,9 +29,9 @@ fn stack_peek_test< S, T, impl Stack: StackTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, + +Drop, + +Copy, + +PartialEq, impl SDestruct: Destruct >( ref stack: S, val_1: T, val_2: T @@ -52,9 +50,9 @@ fn stack_pop_test< S, T, impl Stack: StackTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, + +Drop, + +Copy, + +PartialEq, impl SDestruct: Destruct >( ref stack: S, val_1: T, val_2: T @@ -75,9 +73,9 @@ fn stack_push_pop_push_test< S, T, impl Stack: StackTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, + +Drop, + +Copy, + +PartialEq, impl SDestruct: Destruct >( ref stack: S, val_1: T, val_2: T, val_3: T diff --git a/src/data_structures/src/tests/vec_test.cairo b/src/data_structures/src/tests/vec_test.cairo index 57075948..bf571263 100644 --- a/src/data_structures/src/tests/vec_test.cairo +++ b/src/data_structures/src/tests/vec_test.cairo @@ -11,13 +11,7 @@ fn vec_new_test>(vec: @V) { } fn vec_len_test< - V, - T, - impl Vec: VecTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, - impl SDestruct: Destruct + V, T, impl Vec: VecTrait, +Drop, +Copy, +PartialEq, impl SDestruct: Destruct >( ref vec: V, val_1: T ) { @@ -26,13 +20,7 @@ fn vec_len_test< } fn vec_get_test< - V, - T, - impl Vec: VecTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, - impl SDestruct: Destruct + V, T, impl Vec: VecTrait, +Drop, +Copy, +PartialEq, impl SDestruct: Destruct >( ref vec: V, val_1: T ) { @@ -42,13 +30,7 @@ fn vec_get_test< } fn vec_at_test< - V, - T, - impl Vec: VecTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, - impl SDestruct: Destruct + V, T, impl Vec: VecTrait, +Drop, +Copy, +PartialEq, impl SDestruct: Destruct >( ref vec: V, val_1: T ) { @@ -58,13 +40,7 @@ fn vec_at_test< } fn vec_at_out_of_bounds_test< - V, - T, - impl Vec: VecTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, - impl SDestruct: Destruct + V, T, impl Vec: VecTrait, +Drop, +Copy, +PartialEq, impl SDestruct: Destruct >( ref vec: V ) { @@ -72,13 +48,7 @@ fn vec_at_out_of_bounds_test< } fn vec_push_test< - V, - T, - impl Vec: VecTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, - impl SDestruct: Destruct + V, T, impl Vec: VecTrait, +Drop, +Copy, +PartialEq, impl SDestruct: Destruct >( ref vec: V, val_1: T ) { @@ -88,13 +58,7 @@ fn vec_push_test< } fn vec_set_test< - V, - T, - impl Vec: VecTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, - impl SDestruct: Destruct + V, T, impl Vec: VecTrait, +Drop, +Copy, +PartialEq, impl SDestruct: Destruct >( ref vec: V, val_1: T, val_2: T ) { @@ -105,13 +69,7 @@ fn vec_set_test< } fn vec_set_test_expect_error< - V, - T, - impl Vec: VecTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, - impl SDestruct: Destruct + V, T, impl Vec: VecTrait, +Drop, +Copy, +PartialEq, impl SDestruct: Destruct >( ref vec: V, val_1: T, val_2: T ) { @@ -123,9 +81,9 @@ fn vec_index_trait_test< V, T, impl Vec: VecTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, + +Drop, + +Copy, + +PartialEq, impl SDestruct: Destruct, impl VIndex: Index >( @@ -141,9 +99,9 @@ fn vec_index_trait_out_of_bounds_test< V, T, impl Vec: VecTrait, - impl TDrop: Drop, - impl TCopy: Copy, - impl TPartialEq: PartialEq, + +Drop, + +Copy, + +PartialEq, impl SDestruct: Destruct, impl VIndex: Index >( diff --git a/src/data_structures/src/vec.cairo b/src/data_structures/src/vec.cairo index 85a3c51c..1ad1dac7 100644 --- a/src/data_structures/src/vec.cairo +++ b/src/data_structures/src/vec.cairo @@ -74,18 +74,14 @@ struct Felt252Vec { len: usize, } -impl DestructFeltVec< - T, impl TDrop: Drop, impl TFelt252DictValue: Felt252DictValue -> of Destruct> { +impl DestructFeltVec, +Felt252DictValue> of Destruct> { fn destruct(self: Felt252Vec) nopanic { self.items.squash(); } } -impl Felt252VecImpl< - T, impl TDrop: Drop, impl TCopy: Copy, impl TFelt252DictValue: Felt252DictValue -> of VecTrait, T> { +impl Felt252VecImpl, +Copy, +Felt252DictValue> of VecTrait, T> { fn new() -> Felt252Vec { Felt252Vec { items: Default::default(), len: 0 } } @@ -125,13 +121,13 @@ struct NullableVec { len: usize, } -impl DestructNullableVec> of Destruct> { +impl DestructNullableVec> of Destruct> { fn destruct(self: NullableVec) nopanic { self.items.squash(); } } -impl NullableVecImpl, impl TCopy: Copy> of VecTrait, T> { +impl NullableVecImpl, +Copy> of VecTrait, T> { fn new() -> NullableVec { NullableVec { items: Default::default(), len: 0 } } diff --git a/src/encoding/src/reversible.cairo b/src/encoding/src/reversible.cairo index 1858d7e5..f1fde240 100644 --- a/src/encoding/src/reversible.cairo +++ b/src/encoding/src/reversible.cairo @@ -25,31 +25,24 @@ trait ReversibleBits { #[inline] fn reversing< T, - impl TCopy: Copy, - impl TZeroable: Zeroable, - impl TTryInto: TryInto>, - impl TDivRem: DivRem, - impl TDrop: Drop, - impl TMulEq: MulEq, - impl TRem: Rem, - impl TAddEq: AddEq + +Copy, + +Zeroable, + +TryInto>, + +DivRem, + +Drop, + +MulEq, + +Rem, + +AddEq >( word: T, size: usize, step: T ) -> (T, T) { - let result = TZeroable::zero(); + let result = Zeroable::zero(); reversing_partial_result(word, result, size, step) } #[inline] fn reversing_partial_result< - T, - impl TCopy: Copy, - impl TDivRem: DivRem, - impl TTryInto: TryInto>, - impl TDrop: Drop, - impl TMulEq: MulEq, - impl TRem: Rem, - impl TAddEq: AddEq + T, +Copy, +DivRem, +TryInto>, +Drop, +MulEq, +Rem, +AddEq >( mut word: T, mut onto: T, size: usize, step: T ) -> (T, T) { diff --git a/src/linalg/src/dot.cairo b/src/linalg/src/dot.cairo index ac201047..6ae5353b 100644 --- a/src/linalg/src/dot.cairo +++ b/src/linalg/src/dot.cairo @@ -8,14 +8,7 @@ use array::SpanTrait; /// * `ys` - The second sequence of len L. /// # Returns /// * `T` - The dot product. -fn dot< - T, - impl TMul: Mul, - impl TAddEq: AddEq, - impl TZeroable: Zeroable, - impl TCopy: Copy, - impl TDrop: Drop, ->( +fn dot, +AddEq, +Zeroable, +Copy, +Drop,>( mut xs: Span, mut ys: Span ) -> T { // [Check] Inputs diff --git a/src/merkle_tree/src/merkle_tree.cairo b/src/merkle_tree/src/merkle_tree.cairo index e9f5f425..83fbd6cd 100644 --- a/src/merkle_tree/src/merkle_tree.cairo +++ b/src/merkle_tree/src/merkle_tree.cairo @@ -96,9 +96,7 @@ trait MerkleTreeTrait { } /// MerkleTree Legacy implementation. -impl MerkleTreeImpl< - T, impl THasher: HasherTrait, impl TCopy: Copy, impl TDrop: Drop -> of MerkleTreeTrait { +impl MerkleTreeImpl, +Copy, +Drop> of MerkleTreeTrait { /// Create a new merkle tree instance. fn new() -> MerkleTree { MerkleTree { hasher: HasherTrait::new() } @@ -181,7 +179,7 @@ impl MerkleTreeImpl< /// * `index` - The index of the given. /// * `hasher` - The hasher to use. /// * `proof` - The proof array to fill. -fn compute_proof, impl TDrop: Drop>( +fn compute_proof, +Drop>( mut nodes: Array, mut hasher: T, index: u32, ref proof: Array ) { // Break if we have reached the top of the tree @@ -222,7 +220,7 @@ fn compute_proof, impl TDrop: Drop>( /// * `hasher` - The hasher to use. /// # Returns /// The next layer of nodes. -fn get_next_level, impl TDrop: Drop>( +fn get_next_level, +Drop>( mut nodes: Span, ref hasher: T ) -> Array { let mut next_level: Array = array![]; diff --git a/src/numeric/src/cumsum.cairo b/src/numeric/src/cumsum.cairo index 38ddbc7c..ddb92a7a 100644 --- a/src/numeric/src/cumsum.cairo +++ b/src/numeric/src/cumsum.cairo @@ -7,9 +7,7 @@ use option::OptionTrait; /// * `sequence` - The sequence to operate. /// # Returns /// * `Array` - The cumulative sum of sequence. -fn cumsum, impl TCopy: Copy, impl TDrop: Drop,>( - mut sequence: Span -) -> Array { +fn cumsum, +Copy, +Drop,>(mut sequence: Span) -> Array { // [Check] Inputs assert(sequence.len() >= 1, 'Array must have at least 1 elt'); diff --git a/src/numeric/src/diff.cairo b/src/numeric/src/diff.cairo index 61a62d99..76251801 100644 --- a/src/numeric/src/diff.cairo +++ b/src/numeric/src/diff.cairo @@ -8,14 +8,7 @@ use zeroable::Zeroable; /// * `sequence` - The sorted sequence to operate. /// # Returns /// * `Array` - The discrete difference of sorted sequence. -fn diff< - T, - impl TPartialOrd: PartialOrd, - impl TSub: Sub, - impl TCopy: Copy, - impl TDrop: Drop, - impl TZeroable: Zeroable, ->( +fn diff, +Sub, +Copy, +Drop, +Zeroable,>( mut sequence: Span ) -> Array { // [Check] Inputs diff --git a/src/numeric/src/interpolate.cairo b/src/numeric/src/interpolate.cairo index 7ed45565..123346a0 100644 --- a/src/numeric/src/interpolate.cairo +++ b/src/numeric/src/interpolate.cairo @@ -28,15 +28,15 @@ enum Extrapolation { /// * `T` - The interpolated y at x. fn interpolate< T, - impl TPartialOrd: PartialOrd, - impl TNumericLiteral: NumericLiteral, - impl TAdd: Add, - impl TSub: Sub, - impl TMul: Mul, - impl TDiv: Div, - impl TZeroable: Zeroable, - impl TCopy: Copy, - impl TDrop: Drop, + +PartialOrd, + +NumericLiteral, + +Add, + +Sub, + +Mul, + +Div, + +Zeroable, + +Copy, + +Drop, >( x: T, xs: Span, ys: Span, interpolation: Interpolation, extrapolation: Extrapolation ) -> T { diff --git a/src/numeric/src/trapezoidal_rule.cairo b/src/numeric/src/trapezoidal_rule.cairo index ff2ab73f..33cdcbdb 100644 --- a/src/numeric/src/trapezoidal_rule.cairo +++ b/src/numeric/src/trapezoidal_rule.cairo @@ -11,17 +11,17 @@ use traits::Into; /// * `T` - The approximate integral. fn trapezoidal_rule< T, - impl TPartialOrd: PartialOrd, - impl TNumericLiteral: NumericLiteral, - impl TAdd: Add, - impl TAddEq: AddEq, - impl TSub: Sub, - impl TMul: Mul, - impl TDiv: Div, - impl TCopy: Copy, - impl TDrop: Drop, - impl TZeroable: Zeroable, - impl TInto: Into, + +PartialOrd, + +NumericLiteral, + +Add, + +AddEq, + +Sub, + +Mul, + +Div, + +Copy, + +Drop, + +Zeroable, + +Into, >( xs: Span, ys: Span ) -> T { @@ -40,5 +40,5 @@ fn trapezoidal_rule< value += (*xs[index + 1] - *xs[index]) * (*ys[index] + *ys[index + 1]); index += 1; }; - value / TInto::into(2) + value / Into::into(2_u8) } diff --git a/src/searching/src/binary_search.cairo b/src/searching/src/binary_search.cairo index 734e061c..3780e824 100644 --- a/src/searching/src/binary_search.cairo +++ b/src/searching/src/binary_search.cairo @@ -1,8 +1,6 @@ use array::SpanTrait; -fn binary_search< - T, impl TCopy: Copy, impl TDrop: Drop, impl TEq: PartialEq, impl TOr: PartialOrd ->( +fn binary_search, +Drop, +PartialEq, +PartialOrd>( span: Span, val: T ) -> Option { // Initial check diff --git a/src/searching/src/dijkstra.cairo b/src/searching/src/dijkstra.cairo index ca5d2b7f..036f0a00 100644 --- a/src/searching/src/dijkstra.cairo +++ b/src/searching/src/dijkstra.cairo @@ -31,9 +31,7 @@ trait GraphTrait { fn shortest_path(ref self: Graph>>, source: u32) -> Felt252Dict; } -impl DestructGraph< - T, impl TDrop: Drop, impl TFelt252DictValue: Felt252DictValue -> of Destruct> { +impl DestructGraph, +Felt252DictValue> of Destruct> { fn destruct(self: Graph) nopanic { self.adj_nodes.squash(); } @@ -192,4 +190,3 @@ fn is_node_visited(ref nodes: Array, current_node: u32) -> bool { }; is_visited } - diff --git a/src/sorting/src/bubble_sort.cairo b/src/sorting/src/bubble_sort.cairo index fa45a336..304c10dc 100644 --- a/src/sorting/src/bubble_sort.cairo +++ b/src/sorting/src/bubble_sort.cairo @@ -1,16 +1,12 @@ //! Bubble sort algorithm use array::ArrayTrait; -// Bubble sort +// Bubble sort /// # Arguments /// * `array` - Array to sort /// # Returns /// * `Array` - Sorted array -fn bubble_sort_elements< - T, impl TCopy: Copy, impl TDrop: Drop, impl TPartialOrd: PartialOrd ->( - mut array: Array -) -> Array { +fn bubble_sort_elements, +Drop, +PartialOrd>(mut array: Array) -> Array { if array.len() <= 1 { return array; } diff --git a/src/sorting/src/merge_sort.cairo b/src/sorting/src/merge_sort.cairo index 0b816a22..a86ebbbd 100644 --- a/src/sorting/src/merge_sort.cairo +++ b/src/sorting/src/merge_sort.cairo @@ -6,9 +6,7 @@ use array::ArrayTrait; /// * `arr` - Array to sort /// # Returns /// * `Array` - Sorted array -fn merge, impl TDrop: Drop, impl TPartialOrd: PartialOrd>( - mut arr: Array -) -> Array { +fn merge, +Drop, +PartialOrd>(mut arr: Array) -> Array { let len = arr.len(); if len <= 1 { return arr; @@ -36,7 +34,7 @@ fn merge, impl TDrop: Drop, impl TPartialOrd: PartialO /// * `right_arr_ix` - Right array index /// # Returns /// * `Array` - Sorted array -fn merge_recursive, impl TDrop: Drop, impl TPartialOrd: PartialOrd>( +fn merge_recursive, +Drop, +PartialOrd>( mut left_arr: Array, mut right_arr: Array, ref result_arr: Array, @@ -71,9 +69,7 @@ fn merge_recursive, impl TDrop: Drop, impl TPartialOrd /// * `index` - The index to split the array at. /// # Returns /// * `(Array, Array)` - The two arrays. -fn split_array, impl TDrop: Drop>( - ref arr: Array, index: usize -) -> (Array, Array) { +fn split_array, +Drop>(ref arr: Array, index: usize) -> (Array, Array) { let mut arr1 = array![]; let mut arr2 = array![]; let len = arr.len(); @@ -91,7 +87,7 @@ fn split_array, impl TDrop: Drop>( /// * `count` - The number of elements to fill. /// # Returns /// * `Array` - The filled array. -fn fill_array, impl TDrop: Drop>( +fn fill_array, +Drop>( ref arr: Array, ref fill_arr: Array, index: usize, count: usize ) { if count == 0 { diff --git a/src/storage/src/list.cairo b/src/storage/src/list.cairo index 1d7f40fc..84e2f356 100644 --- a/src/storage/src/list.cairo +++ b/src/storage/src/list.cairo @@ -32,7 +32,7 @@ trait ListTrait { fn from_span(ref self: List, span: Span); } -impl ListImpl, impl TDrop: Drop, impl TStore: Store> of ListTrait { +impl ListImpl, +Drop, +Store> of ListTrait { fn len(self: @List) -> u32 { *self.len } @@ -130,9 +130,7 @@ impl ListImpl, impl TDrop: Drop, impl TStore: Store } } -impl AListIndexViewImpl< - T, impl TCopy: Copy, impl TDrop: Drop, impl TStore: Store -> of IndexView, u32, T> { +impl AListIndexViewImpl, +Drop, +Store> of IndexView, u32, T> { fn index(self: @List, index: u32) -> T { self.get(index).expect('List index out of bounds') } @@ -186,7 +184,7 @@ fn calculate_base_and_offset_for_index( (segment_base, offset.try_into().unwrap() * storage_size) } -impl ListStore> of Store> { +impl ListStore> of Store> { fn read(address_domain: u32, base: StorageBaseAddress) -> SyscallResult> { let len: u32 = Store::read(address_domain, base).unwrap_syscall(); let storage_size: u8 = Store::::size();