NEWTON
Asked
5 months ago
7
views
0
I have an array of structs that I want to iterate through in Cairo, how can I achieve this?
ㅤ This question was originally posted on Triality
0
You can do this through recursion. A key difference between iterating through an array of structs vs an array of felts is that each recursive call should increase the array index by <YourStruct>.SIZE
, vs. just incrementing it by 1
for an array of felts. For example:
struct Point:
member x : felt
member y : felt
end
func yourFunc(points: Point*, points_len : felt):
if points_len == 0:
return ()
end
let p: Point = points[0]
# do whatever you wish with p
# recursively call yourFunc, but increase the location in the array by Point.SIZE
yourFunc(points + Point.SIZE, points_len - 1)
end
ㅤ This answer was originally posted on Triality
answered
6 months ago
Which is this extension that shows you errors before compilation ser?
Revoked References exercise from Cairo-lang
How many time does it take for stark to eth starkgate bridge process?
Cairo: let vs tempvar what is the difference?
Is there a Cairo equivalent to Keccak256(abi.encode(parameters))?
Is it possible to import local python files into hints?
How do I create AX (ArgentX) contract using starknetjs?