Skip Lists
debt(d8/e5/b3/t5)
Closest to 'silent in production until users hit it' (d9), slightly better at d8. The detection_hints flag automated:no, and there are no listed tools that catch misuse. Common mistakes like fixed levels or max level too low degrade performance silently — no compiler, linter, or SAST tool flags these; only runtime profiling or load testing reveals the O(n) degradation before users notice.
Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix suggests switching to Redis sorted sets, which is more than a one-line patch — it involves replacing a custom data structure with Redis, updating call sites, adding a Redis dependency, and potentially restructuring data access patterns across a component. Not a simple one-liner nor a full architectural rewrite.
Closest to 'localised tax' (b3). Skip list choice is scoped to specific sorted-collection use cases (web/cli contexts). If using Redis sorted sets as recommended, the burden is contained to the data-access layer; if implementing custom skip lists, the burden is confined to that component. Most of the codebase is unaffected by this choice.
Closest to 'notable trap — a documented gotcha most devs eventually learn' (t5). The misconception field directly states that developers wrongly assume skip lists are always inferior to balanced BSTs due to probabilistic nature, not understanding they have equivalent expected complexity and often better practical performance. This is a well-documented but commonly held wrong belief, fitting t5 rather than a more severe trap.
Also Known As
TL;DR
Explanation
A skip list is a layered linked list: the bottom layer has all elements in sorted order; each higher layer contains a random subset of the elements below, acting as express lanes. Search: start at the top layer, move right until the next element is too large, then drop down — O(log n) expected. Insert: coin flips determine which layers the new element appears in. Redis uses skip lists for sorted sets (ZADD/ZRANGE). Advantages over balanced BSTs: simpler implementation, easier lock-free concurrent modification.
Common Misconception
Why It Matters
Common Mistakes
- Fixed levels instead of probabilistic promotion — breaks expected O(log n)
- Maximum level too low — degrades to O(n)
- Using skip list where a hash map suffices — add ordering only when needed
- Concurrent modifications without proper synchronisation
Code Examples
// Assuming zadd is O(1):
for ($i = 0; $i < 1000000; $i++) {
$redis->zadd('leaderboard', $score, $userId);
// 1M * O(log n) = O(n log n) total — expected but surprising
}
// Pipeline for bulk inserts:
$pipeline = $redis->pipeline();
foreach ($scores as $userId => $score) {
$pipeline->zadd('leaderboard', $score, $userId);
}
$pipeline->execute(); // Single round trip for all insertions