Last active
December 15, 2015 08:28
-
-
Save arwagner/5230640 to your computer and use it in GitHub Desktop.
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
(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