Created
August 23, 2011 06:08
-
-
Save swannodette/1164458 to your computer and use it in GitHub Desktop.
java.clj
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
(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