Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created August 21, 2013 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swannodette/6288965 to your computer and use it in GitHub Desktop.
Save swannodette/6288965 to your computer and use it in GitHub Desktop.
(deftype RingBuffer [^:mutable head ^:mutable tail arr]
Object
(length [this]
(- head tail))
(pop [this]
(when-not (== head tail)
(let [x (aget arr tail)]
(set! tail (inc tail))
x)))
(unshift [this x]
(aset arr head x)
(set! head (inc head))
nil))
(defn ring-buffer [n]
(RingBuffer. 0 0 (make-array n)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment