← 中文资源

简体中文版本

跳表命令行工具

一个 Node 命令行工具:实现概率层级跳表,从标准输入接受 insert/search 并打印搜索结果。

阅读英文原文

功能说明

实现最大 16 层 0.5 晋升概率跳表。insert 随机分配层级并在各层链接节点;search 从顶层向下走,每层前跳。两者期望 O(log n)。运行 printf “insert 5\ninsert 1\ninsert 3\nsearch 3\nsearch 2” | node skiplist.mjs 输出 found、not found。内存非持久;层级分布概率性最坏 O(n) 期望 O(log n);未实现删除。

运行方式

printf "insert 5\ninsert 1\ninsert 3\nsearch 3\nsearch 2" | node skiplist.mjs

限制与后续

当前跳表命令行工具实现覆盖最常见的使用路径。本译文依据英文原文完整重写,代码与命令与英文版本严格一致,可在本地按运行方式复现并核对结果。The skip list is in-memory and not persisted. The level distribution is probabilistic, so the worst case is O(n) though the expected case is O(log n). No deletion is implemented.若用于生产,请先补充输入校验、错误处理与日志,再结合自身环境调整node版本。