NEWTON

NEWTON


Popular tags

    Cairo: How do I iterate through an array of structs?

    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

      cairocairo-langstarknet

    1 answers

    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

    Your answer

    NEWTON

    NEWTON