Permalink
Browse files

clean up, better naming and return values

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
1 parent a390c21 commit bddf280b124e95c5b1adb96b4646822167d4b03c @ibdknox committed Jun 10, 2011
Showing with 30 additions and 28 deletions.
  1. +4 −3 project.clj
  2. +6 −25 src/simpledb/core.clj
  3. +20 −0 test/simpledb/test/core.clj
View
7 project.clj
@@ -1,4 +1,5 @@
-(defproject simpledb "1.0.0-SNAPSHOT"
- :description "FIXME: write description"
- :dependencies [[org.clojure/clojure "1.2.1"]]
+(defproject simpledb "0.1.1"
+ :description "A simple in-memory database for use with prototypes."
+ :dependencies [[org.clojure/clojure "1.2.1"]]
+ :dev-dependencies [[lein-clojars "0.6.0"]]
:main simpledb.core)
View
31 src/simpledb/core.clj
@@ -6,19 +6,21 @@
(defonce *db* (atom {}))
(defonce *timer* (. Executors newScheduledThreadPool 1))
-(defn store! [k v]
+(defn put! [k v]
(swap! *db* assoc k v)
- nil)
+ [k v])
(defn get [k]
(clojure.core/get @*db* k))
(defn remove! [k]
(swap! *db* dissoc k)
- nil)
+ k)
(defn update! [k f & args]
- (swap! *db* #(assoc % k (apply f (clojure.core/get % k) args))))
+ (get
+ (swap! *db* #(assoc % k (apply f (clojure.core/get % k) args)))
+ k))
(defn persist-db []
(let [cur @*db*]
@@ -40,24 +42,3 @@
(read-db)
(.. Runtime getRuntime (addShutdownHook (Thread. persist-db)))
(. *timer* (scheduleAtFixedRate persist-db (long 5) (long 5) (. TimeUnit MINUTES))))
-
-(init)
-
-(defn write-test []
- (let [t (System/currentTimeMillis)]
- (loop [iter 0]
- (if (>= (- (System/currentTimeMillis) t) 1000)
- (println iter)
- (do
- (store! iter iter)
- (recur (inc iter)))))))
-
-(defn read-test []
- (let [t (System/currentTimeMillis)]
- (loop [iter 0]
- (if (>= (- (System/currentTimeMillis) t) 1000)
- (println iter)
- (do
- (get iter)
- (recur (inc iter)))))))
-
View
20 test/simpledb/test/core.clj
@@ -4,3 +4,23 @@
(deftest replace-me ;; FIXME: write
(is false "No tests have been written."))
+
+(defn write-test []
+ (let [t (System/currentTimeMillis)]
+ (loop [iter 0]
+ (if (>= (- (System/currentTimeMillis) t) 1000)
+ (println iter)
+ (do
+ (store! iter iter)
+ (recur (inc iter)))))))
+
+(defn read-test []
+ (let [t (System/currentTimeMillis)]
+ (loop [iter 0]
+ (if (>= (- (System/currentTimeMillis) t) 1000)
+ (println iter)
+ (do
+ (get iter)
+ (recur (inc iter)))))))
+
+

0 comments on commit bddf280

Please sign in to comment.