Closed enitrat closed 3 months ago
@enitrat I'll Like to handle this.
It's not possible yet as mentioned
Ohhhh.... Sorry, I just noticed the PR was still being reviewed.
@enitrat very interested in this, would love to work on this
@Enenche23 Hi, thanks for the comment. How would you tackle this issue?
To get started
use core::nullable::NullableTrait;
use core::dict::Felt252DictEntryTrait;
fn main() {
let temperatures = array![20, 19, 26];
let mut pixels: Felt252Dict<Nullable<Array<u8>>> = Default::default();
pixels.insert(0, NullableTrait::new(temperatures));
println!("Before insertion: {:?}", get_array_entry(ref pixels, 0));
append_value(ref pixels, 0, 30);
println!("After insertion: {:?}", get_array_entry(ref pixels, 0));
}
fn append_value(ref pixels: Felt252Dict<Nullable<Array<u8>>>, index: felt252, value: u8) {
let (entry, temperatures) = pixels.entry(0);
let mut unboxed_val = temperatures.deref_or(array![]);
unboxed_val.append(value);
pixels = entry.finalize(NullableTrait::new(unboxed_val));
}
fn get_array_entry(ref pixels: Felt252Dict<Nullable<Array<u8>>>, index: felt252) -> Span<u8> {
let (entry, _temperatures) = pixels.entry(0);
let mut temperatures = _temperatures.deref_or(array![]);
let temps = temperatures.span();
pixels = entry.finalize(NullableTrait::new(temperatures));
temps
}
can y'all assign this issue to me after the PR on randomness gets merged
@TAdev0 @enitrat
Just a small correction for the "get started" code (see https://github.com/cairo-book/cairo-book/issues/421#issuecomment-2093305126) - pixels.entry
should be called with index
for the function to work correctly:
fn append_value(ref pixels: Felt252Dict<Nullable<Array<u8>>>, index: felt252, value: u8) {
let (entry, temperatures) = pixels.entry(index); // was .entry(0)
// ...
fn get_array_entry(ref pixels: Felt252Dict<Nullable<Array<u8>>>, index: felt252) -> Span<u8> {
let (entry, _temperatures) = pixels.entry(index); // was .entry(0)
@misicnenad do you want to work on this btw?
@enitrat that would be awesome!
@okhaimie-dev removing you from this one as you already have another one active
@misicnenad I think we can have this sub-section in https://book.cairo-lang.org/ch03-02-dictionaries.html
@enitrat would that mean that we should then remove the unimplemented sub-section 11.2?
@misicnenad yes, we would have everything under 3.2 Dictionaries
This will now be possible following https://github.com/starkware-libs/cairo/pull/4340 . However, it requires a specific way of interacting with the dictionary: instead of calling
get
, we will have to callentry
.