Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created July 23, 2012 18:33
Show Gist options
  • Save amalloy/3165282 to your computer and use it in GitHub Desktop.
Save amalloy/3165282 to your computer and use it in GitHub Desktop.
(set! *unchecked-math* true)
(deftype RingBuffer [^long start ^long len buf meta]
IPersistentStack
(peek [this]
(nth buf (mod start (count buf))))
(pop [this]
(if (zero? len)
(throw (IllegalStateException. "Can't pop empty queue"))
(RingBuffer. (mod (inc start) (count buf)) (dec len) (assoc buf start nil) meta))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment