Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created August 27, 2011 01:29
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/1174834 to your computer and use it in GitHub Desktop.
Save swannodette/1174834 to your computer and use it in GitHub Desktop.
redblack.clj
;; 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)))))
@frenchy64
Copy link

I quite like the column syntax here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment