-
Notifications
You must be signed in to change notification settings - Fork 684
feat(byte_array): add get(usize) and index(usize) to ByteSpan
#8427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(byte_array): add get(usize) and index(usize) to ByteSpan
#8427
Conversation
f840c46 to
bcf3c7d
Compare
d2487b7 to
235db8b
Compare
TomerStarkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomerStarkware reviewed 2 of 2 files at r2, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @orizi)
235db8b to
eeaa0bf
Compare
bcf3c7d to
04b763d
Compare
04b763d to
c03411e
Compare
45abe52 to
afd7694
Compare
8885cbb to
a4243a8
Compare
9ab073e to
b38e4cc
Compare
a4243a8 to
6769953
Compare
b38e4cc to
20ea89a
Compare
6769953 to
19ce8b6
Compare
20ea89a to
bc5dfbf
Compare
19ce8b6 to
4bf4932
Compare
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed all commit messages.
Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
corelib/src/byte_array.cairo line 703 at r4 (raw file):
fn at(self: @ByteSpan, index: usize) -> Option<u8> { let actual_index = index.checked_add(upcast(self.first_char_start_offset))?; let (word_index, index_in_word) = DivRem::div_rem(actual_index, BYTES_IN_BYTES31_NONZERO);
use bounded_int::div_rem and get index_in_word in [0,30] range.
you can use bounded_int::constrain later to decide if it is accessing the lower or upper word.
Code quote:
let (word_index, index_in_word) = DivRem::div_rem(actual_index, BYTES_IN_BYTES31_NONZERO);corelib/src/byte_array.cairo line 713 at r4 (raw file):
if word_index == self.data.len() && index_in_word < upcast(self.remainder_len) { // index_in_word is from MSB, we need index from LSB. let index_in_remainder = upcast(self.remainder_len) - 1 - index_in_word;
bounded_int::sub as well.
Code quote:
let index_in_remainder = upcast(self.remainder_len) - 1 - index_in_word;bc5dfbf to
50fdc8e
Compare
02d1817 to
826e33e
Compare
5148fd0 to
2dd37d7
Compare
826e33e to
1b13525
Compare
giladchase
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware)
corelib/src/byte_array.cairo line 1014 at r9 (raw file):
Previously, orizi wrote…
should work.
Messes up semantic:
thread '<unnamed>' panicked at crates/cairo-lang-semantic/src/items/constant.rs:839:19:
Variant extract failed: `Extern(ExternFunctionId(f830))` is not of variant `GenericFunctionId::Impl`
When debugging it i switched it the +30 to -30 and it passed semantic (but failed in the logic of course), meaning probably semantic is having problems deciding what type to evaluate this to (maybe it tries to evaluate the type after the addition before taking the Div into account?).
Maybe this is a bug in semantic.
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed all commit messages.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @giladchase and @TomerStarkware)
corelib/src/byte_array.cairo line 1014 at r9 (raw file):
Previously, giladchase wrote…
Messes up semantic:
thread '<unnamed>' panicked at crates/cairo-lang-semantic/src/items/constant.rs:839:19: Variant extract failed: `Extern(ExternFunctionId(f830))` is not of variant `GenericFunctionId::Impl`When debugging it i switched it the
+30to-30and it passed semantic (but failed in the logic of course), meaning probably semantic is having problems deciding what type to evaluate this to (maybe it tries to evaluate the type after the addition before taking the Div into account?).
Maybe this is a bug in semantic.
lets go with `(Bounded::::MAX / 31 + 1).into(); instead.
1b13525 to
ec6fe60
Compare
2dd37d7 to
e75d288
Compare
ec6fe60 to
2a75931
Compare
giladchase
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware)
corelib/src/byte_array.cairo line 1014 at r9 (raw file):
Previously, orizi wrote…
lets go with `(Bounded::::MAX / 31 + 1).into(); instead.
Nice, done.
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 1 of 1 files at r12, all commit messages.
Reviewable status: 4 of 5 files reviewed, all discussions resolved (waiting on @TomerStarkware)
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 1 of 1 files at r11.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @giladchase)
e75d288 to
f21ae74
Compare
2a75931 to
d1a4067
Compare
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 1 of 1 files at r13, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @giladchase)
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @giladchase)
corelib/src/test/byte_array_test.cairo line 715 at r13 (raw file):
assert_eq!(span[61], '#', "byte 61 - first in last_word"); assert_eq!(span.get(62_usize), Some('$'), "byte 62 - last in last_word"); assert_eq!(span.get(63_usize), None);
remove useless expect.
Code quote:
assert_eq!(span.get(30_usize), Some('f'), "byte 30 - last of 1nd word");
assert_eq!(span[31], 'g', "byte 31 - first of 2nd word");
assert_eq!(span.get(60_usize), Some('9'), "byte 60 - last of 2nd word");
assert_eq!(span[61], '#', "byte 61 - first in last_word");
assert_eq!(span.get(62_usize), Some('$'), "byte 62 - last in last_word");
assert_eq!(span.get(63_usize), None);d1a4067 to
9e255e1
Compare
Merge activity
|
c8b0b6b to
81d99a8
Compare
giladchase
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)
corelib/src/test/byte_array_test.cairo line 715 at r13 (raw file):
Previously, orizi wrote…
remove useless expect.
Done.
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 1 of 1 files at r14, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @giladchase)
81d99a8 to
7ce15d9
Compare
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 2 of 2 files at r15, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @giladchase)

No description provided.