Great post!
Some minor clarifications:
I believe what you’re looking for is either std.SinglyLinkedList
(for LIFO) or std.DoublyLinkedList
(which used to be named TailQueue
, and before that just LinkedList
). EDIT: Or std.fifo.LinearFifo
for FIFO, see this comment
There’s been quite a bit of discussion around the naming/implementation of these data structures, but it’s rather spread out. Here’s a few relevant links:
- Extend std.LinkedList with single/tailq and circularq variants · Issue #2384 · ziglang/zig · GitHub
- Add SinglyLinkedList by daurnimator · Pull Request #2424 · ziglang/zig · GitHub
- https://freenode.irclog.whitequark.org/zig/2019-06-10 (
Ctrl + F
for “TailQueue”) - Proposal: Unify the interfaces of the data structures in standard library · Issue #8233 · ziglang/zig · GitHub
- std: Rename `TailQueue` to `DoublyLinkedList` by jayschwa · Pull Request #16996 · ziglang/zig · GitHub
I’d instead say “pointer to an array of N items.” Might not seem like much of a difference, but since arrays are value types in Zig, it makes the difference between *[N]T
(where N
must be comptime known) and []T
with a len
of N
a bit more clear.
Here’s a relevant thread: Are sentinels only intended for null terminators?
@kristoff gave the better explanation here, but an additional thing that’s slightly interesting to note is that the language itself is not aware of heap allocation at all–heap allocation (and therefore out-of-memory) is fully a “userland” concept, so there’s currently no way for the compiler to insert checks for out-of-memory conditions even if it wanted to.
(this somewhat ties into something I’ve written about before)