Zig Master: Let's Create a Stack!

Sdílet
Vložit
  • čas přidán 21. 08. 2024
  • Help me create more content like this!
    www.paypal.com...
    With all the knowledge we've acquired so far, we can build our very own data structure in Zig. In this episode, we'll build a stack that can handle growth via heap allocation and as a bonus we even make it generic. NOTE: I had a little off-by-one bug in the code shown in the video where I compared the slice length plus one as greater than or equal to, when it should be just greater than (in the push method). I made the fix and the code in the repo is now correct.
    The code: codeberg.org/d...
    Relevant Links:
    - ziglang.org/do...
    Thumbnail artwork courtesy of: www.deviantart...

Komentáře • 8

  • @EliasDorneles
    @EliasDorneles Před měsícem +2

    This is great stuff, man!
    This example is exactly what I needed: it answers several questions I had and gives a great example of generic data structure!
    Thank you so much for this!

  • @raptorate2872
    @raptorate2872 Před měsícem +5

    Hello Dude thanks for all your help, you are a lifesaver for those who want to learn zig. May i ask how to navigate through the 2 different playlists you have. It would seem like they have overlapping concepts.

    • @dudethebuilder
      @dudethebuilder  Před měsícem +3

      Thanks for the support. I would recommend watching the videos in Zig in Depth first, specifically those that pertain to the language and not the build system or project tools. Then you can catch up with recent changes with the videos in Zig Master.

  • @juanpablouriolbalbin887
    @juanpablouriolbalbin887 Před měsícem +1

    I think you are allocating new memory even though you still have space for one more element. In your example, you double the capacity from 8 to 16 when you add the 7th element (index 6). Therefore, you still have space for an 8th element.

    • @dudethebuilder
      @dudethebuilder  Před 28 dny +2

      Correct! I noticed that just as I finished recording the video and added a note to the description. The actual code on the repo has been fixed. Thanks for the heads-up.