Created
August 21, 2013 00:16
-
-
Save swannodette/6288965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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