Created
August 27, 2011 01:29
-
-
Save swannodette/1174834 to your computer and use it in GitHub Desktop.
redblack.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
;; 400ms | |
(let [t [:black [:red [:red 1 2 3] 3 4] 5 6]] | |
(dotimes [_ 10] | |
(time | |
(dotimes [_ 1e6] | |
(match [t] | |
[(([:black ([:red ([:red _ _ _] ::m/vector) _ _] ::m/vector) _ _] ::m/vector) | | |
([:black ([:red _ _ ([:red _ _ _] ::m/vector)] ::m/vector) _ _] ::m/vector) | | |
([:black _ _ ([:red ([:red _ _ _] ::m/vector) _ _] ::m/vector)] ::m/vector))] :valid | |
:else :invalid))))) | |
;; ideally sugar so we can write | |
(let [t [:black [:red [:red 1 2 3] 3 4] 5 6]] | |
(dotimes [_ 10] | |
(time | |
(dotimes [_ 1e6] | |
(match [t] | |
[(or [:black [:red [:red _ _ _] _ _] _ _] | |
[:black [:red _ _ [:red _ _ _]] _ _] | |
[:black _ _ [:red [:red _ _ _] _ _]])] :valid | |
:else :invalid))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I quite like the column syntax here.