Skip to content

Commit b67f6a9

Browse files
committed
data_structures dependency update
1 parent 00d5251 commit b67f6a9

4 files changed

Lines changed: 46 additions & 7 deletions

File tree

Scarb.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ dependencies = [
1919
[[package]]
2020
name = "alexandria_data_structures"
2121
version = "0.2.0"
22-
dependencies = [
23-
"alexandria_encoding",
24-
]
2522

2623
[[package]]
2724
name = "alexandria_encoding"

packages/data_structures/Scarb.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@ edition = "2023_11"
88
[tool]
99
fmt.workspace = true
1010

11-
[dependencies]
12-
alexandria_encoding = { path = "../encoding", version = "0.2.0" }
13-
1411
[dev-dependencies]
1512
cairo_test.workspace = true

packages/data_structures/src/byte_appender.cairo

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use alexandria_encoding::reversible::reversing;
21
use core::byte_array::ByteArrayTrait;
32
use core::integer::u512;
3+
use core::num::traits::Zero;
4+
use core::ops::{MulAssign, AddAssign};
45
use super::bit_array::{one_shift_left_bytes_felt252, one_shift_left_bytes_u128};
56

67
/// Generic support trait for appending signed and unsigned integers onto byte storage.
@@ -284,3 +285,46 @@ impl ByteAppenderImpl<T, +Drop<T>, +ByteAppenderSupportTrait<T>> of ByteAppender
284285

285286
impl ArrayU8ByteAppenderImpl = ByteAppenderImpl<Array<u8>>;
286287
impl ByteArrayByteAppenderImpl = ByteAppenderImpl<ByteArray>;
288+
289+
290+
#[inline]
291+
pub fn reversing<
292+
T,
293+
+Copy<T>,
294+
+Zero<T>,
295+
+TryInto<T, NonZero<T>>,
296+
+DivRem<T>,
297+
+Drop<T>,
298+
+MulAssign<T, T>,
299+
+Rem<T>,
300+
+AddAssign<T, T>
301+
>(
302+
word: T, size: usize, step: T
303+
) -> (T, T) {
304+
let result = Zero::zero();
305+
reversing_partial_result(word, result, size, step)
306+
}
307+
308+
#[inline]
309+
pub fn reversing_partial_result<
310+
T,
311+
+Copy<T>,
312+
+DivRem<T>,
313+
+TryInto<T, NonZero<T>>,
314+
+Drop<T>,
315+
+MulAssign<T, T>,
316+
+Rem<T>,
317+
+AddAssign<T, T>
318+
>(
319+
mut word: T, mut onto: T, size: usize, step: T
320+
) -> (T, T) {
321+
let mut i: usize = 0;
322+
while i != size {
323+
let (new_word, remainder) = DivRem::div_rem(word, step.try_into().unwrap());
324+
word = new_word;
325+
onto *= step.into();
326+
onto += remainder;
327+
i += 1;
328+
};
329+
(onto, word)
330+
}

packages/encoding/src/reversible.cairo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub trait ReversibleBits<T> {
2323
fn reverse_bits(self: @T) -> T;
2424
}
2525

26+
// [Erim]: Duplicated function in data_structures::byte_appender. Use that one for package management
2627
#[inline]
2728
pub fn reversing<
2829
T,

0 commit comments

Comments
 (0)