Skip to content

Instantly share code, notes, and snippets.

@arwagner
Last active December 15, 2015 08:28
Show Gist options
  • Save arwagner/5230640 to your computer and use it in GitHub Desktop.
Save arwagner/5230640 to your computer and use it in GitHub Desktop.
(defrecord Hashtable [hash-function data])
(defn create-hashtable [f]
(Hashtable. f {}))
(defn contains? [ht item]
(let [map (:data ht)
key ((:hash-function ht) item)]
(map key)))
(defn contains-any-like? [item ht]
(let [map (:data ht)
key ((:hash-function ht) item)]
(clojure.core/contains? (vec (keys map)) key)))
(defn insert [ht item]
(let [map (:data ht)
key ((:hash-function ht) item)
similar (map key)]
(assoc ht
:map
(assoc (:map ht)
key
(set (conj similar item))))))
(def my-empty (create-hashtable #(mod % 5)))
(def with-one (insert my-empty 2))
(def with-another (insert with-one 7))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment