If you need a jumptable in Common Lisp, the naive way is to just expand to the equivalent ecase form:
Unfortunately, in most Common Lisp implementations, this simply expands to a linear series of checks for each value in turn, which is really not great if there are more than just a few cases.
This library provides
ejumpcase, which is much more efficient. On CCL, it actually expands to an
ecase which expands to a bunch of
ifs, but a later stage of compilation actually detects the repeated comparisons on the index variable and converts them into a nice jumptable. So
ejumpcase is ultimately O(1) on CCL. On other Common Lisp implementations,
ejumpcase expands to a binary search implemented as a tree of
if forms, offering still vastly superior performance compared to the typical
ecase expansion (if there are more than a few cases). But this really ought to be O(1), so help is requested to add such support for other Common Lisp implementations. Please open an issue or pull request if you know how to add support for this on other Common Lisp implementations.
You can quickly get some rough test results like this: