Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created August 23, 2011 06:08
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/1164458 to your computer and use it in GitHub Desktop.
Save swannodette/1164458 to your computer and use it in GitHub Desktop.
java.clj
(set! *warn-on-reflection* true)
(set! *unchecked-math* true)
(definterface IChain
(kill [^long nth])
(getFirst ^long [])
(shout [^long nth]))
(deftype Chain [^java.util.ArrayList persons
^{:unsynchronized-mutable true :tag long} index
^{:unsynchronized-mutable true :tag long} size]
IChain
(kill [this nth]
(set! index 0)
(while (> size 1)
(.shout this nth)))
(getFirst [this]
(.get persons 0))
(shout [this nth]
(while (< index size)
(.remove persons index)
(set! index (+ index (dec nth)))
(set! size (dec size)))
(set! index (- index size))))
(defn run []
(let [al (java.util.ArrayList.)
n 40]
(dotimes [x n]
(.add al (inc x)))
(let [chain (Chain. al 0 n)]
(.kill chain 3))))
(comment
;; 1.19s
(dotimes [_ 10]
(time
(dotimes [_ 1e6]
(run))))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment