Skip to content

Commit

Permalink
neater cond
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Aug 23, 2024
1 parent ac6d8d9 commit d1a738c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/com/ambrosebs/map.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
(ns com.ambrosebs.map
(:refer-clojure :exclude [bit-shift-right
bit-shift-left
hash-map])
hash-map
cond])
(:require [clojure.core :as core])
(:import (clojure.lang IPersistentMap MapEntry Box)
(java.util.concurrent.atomic AtomicReference)))
Expand All @@ -25,6 +26,19 @@
(defmacro identical-ints? [x y]
`(com.ambrosebs.map.Util/identicalInts ~x ~y))

;; does not test keywords
(defmacro cond [& [c1 c2 :as clauses]]
(when clauses
(when-not (next clauses)
(throw (IllegalArgumentException.
"cond requires an even number of forms")))
(if (keyword? c1)
c2
(list 'if c1
c2
(cons `cond (next (next clauses)))))))


(defonce ^:private NOT-FOUND
(Object.))

Expand Down Expand Up @@ -144,7 +158,7 @@
;(prn "create-node")
(let [key1hash (core/hash key1)]
(cond
(= key1hash key2hash)
(identical-ints? key1hash key2hash)
(hash-collision-node-ctor
nil
key1hash
Expand Down

0 comments on commit d1a738c

Please sign in to comment.