diff --git a/src/hint_processor/usort.zig b/src/hint_processor/usort.zig index 89abe22e..a847e4c9 100644 --- a/src/hint_processor/usort.zig +++ b/src/hint_processor/usort.zig @@ -86,12 +86,13 @@ pub fn usortBody( } else |_| {} var positions_dict = std.AutoHashMap(Felt252, std.ArrayList(u64)).init(allocator); - defer positions_dict.deinit(); - defer { + errdefer { var it = positions_dict.valueIterator(); while (it.next()) |v| { v.deinit(); } + + positions_dict.deinit(); } var output = std.ArrayList(Felt252).init(allocator); @@ -104,8 +105,17 @@ pub fn usortBody( else => {}, } - var entry = positions_dict.getPtr(val) orelse - @constCast(&std.ArrayList(u64).init(allocator)); + var entry = positions_dict.getPtr(val) orelse blk: { + var nval = std.ArrayList(u64).init(allocator); + errdefer nval.deinit(); + + const res = try positions_dict.getOrPutValue( + val, + nval, + ); + + break :blk res.value_ptr; + }; try entry.append(i); } diff --git a/src/integration_tests.zig b/src/integration_tests.zig index 4a28aca1..244263a5 100644 --- a/src/integration_tests.zig +++ b/src/integration_tests.zig @@ -79,9 +79,9 @@ pub fn main() void { // .{ .pathname = "cairo_programs/example_blake2s.json", .layout = "all_cairo" }, .{ .pathname = "cairo_programs/example_program.json", .layout = "all_cairo" }, .{ .pathname = "cairo_programs/factorial.json", .layout = "plain" }, - // TODO: FailedToComputeOp0 error + // TODO: HintNotImplemented error // .{ .pathname = "cairo_programs/fast_ec_add_v2.json", .layout = "all_cairo" }, - // TODO: FailedToComputeOp0 error + // TODO: HintNotImplemented error // .{ .pathname = "cairo_programs/fast_ec_add_v3.json", .layout = "all_cairo" }, .{ .pathname = "cairo_programs/fibonacci.json", .layout = "plain" }, // TODO: HintNotImplemented error uint384 hint @@ -147,8 +147,7 @@ pub fn main() void { .{ .pathname = "cairo_programs/normalize_address.json", .layout = "all_cairo" }, .{ .pathname = "cairo_programs/not_main.json", .layout = "all_cairo" }, - // TODO: panic attempt to use null value - // .{ .pathname = "cairo_programs/operations_with_data_structures.json", .layout = "all_cairo" }, + .{ .pathname = "cairo_programs/operations_with_data_structures.json", .layout = "all_cairo" }, // TODO: hint not implemented sha256 // .{ .pathname = "cairo_programs/packed_sha256_test.json", .layout = "all_cairo" }, @@ -223,8 +222,7 @@ pub fn main() void { .{ .pathname = "cairo_programs/unsafe_keccak.json", .layout = "all_cairo" }, .{ .pathname = "cairo_programs/unsigned_div_rem.json", .layout = "all_cairo" }, .{ .pathname = "cairo_programs/use_imported_module.json", .layout = "all_cairo" }, - // TODO: panic attempt to use null value - // .{ .pathname = "cairo_programs/usort.json", .layout = "all_cairo" }, + .{ .pathname = "cairo_programs/usort.json", .layout = "all_cairo" }, }; var ok_count: usize = 0;