Quantcast
Channel: Hacker News
Viewing all articles
Browse latest Browse all 25817

Lispy sets

$
0
0
I've been playing around with adding ordered sets to Common Lisp lately. I started out by pulling my usual tricks, skip lists and binary searched/dynamically grown vectors; but none of them turned out the way I wanted; I always had the feeling I was fighting the language rather than enjoying the ride, which is unusual.

So I turned a new page; took a deep breath; and brain dumped the most naive, workable solution I could think of. Like Lisp's built in sets; slists store their items as lists, with the difference that they're sorted and keep track of length and tail. This allows them to implement ordering and more in 150 lines of reasonable code; while being significantly (currently around 400x on my machine) faster than built in (as in SBCL) functionality for set operations. Once again, keeping it simple proves to be a successful strategy.


And here is the benchmark on which I base these outrageous claims, and a print out from my machine; there's more in the repo:



peace, out


Viewing all articles
Browse latest Browse all 25817

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>