Summary
The corporate action linked list uses 0 as both "null pointer" (no next/prev/head/tail) and as a valid array index (the "sentinel" at position 0). The ambiguity is resolved by physical position (reserving index 0 via an array length bump) rather than by making values unambiguous.
Problem
prev = 0 could mean "no previous node" or "the node at array index 0." The code works because:
- Index 0 is reserved (sentinel push)
- Traversal checks
current != 0 before indexing
- Convention: no code follows a 0 pointer
This is fragile — any new code that indexes s.nodes[pointer] without checking pointer != 0 silently reads a zero-initialized slot that looks like a cancelled node.
Alternative
Use type(uint256).max as the null sentinel value instead of 0. Then:
prev = type(uint256).max → unambiguously "no previous node"
prev = 0 → unambiguously "the node at index 0"
- Index 0 available for real data (no sentinel push needed)
- Value-level disambiguation, not positional
Trade-offs
Priority
Low — current design works correctly. This is a design purity concern, not a bug. Worth considering for a v2 of the data structure.
Summary
The corporate action linked list uses
0as both "null pointer" (no next/prev/head/tail) and as a valid array index (the "sentinel" at position 0). The ambiguity is resolved by physical position (reserving index 0 via an array length bump) rather than by making values unambiguous.Problem
prev = 0could mean "no previous node" or "the node at array index 0." The code works because:current != 0before indexingThis is fragile — any new code that indexes
s.nodes[pointer]without checkingpointer != 0silently reads a zero-initialized slot that looks like a cancelled node.Alternative
Use
type(uint256).maxas the null sentinel value instead of0. Then:prev = type(uint256).max→ unambiguously "no previous node"prev = 0→ unambiguously "the node at index 0"Trade-offs
type(uint256).maxcomparisons are marginally more expensive than!= 0Priority
Low — current design works correctly. This is a design purity concern, not a bug. Worth considering for a v2 of the data structure.