Permalink
Browse files

dropped "make-" off the name, just use a map (drop struct), add swank…

…-clojure as a dev-dependency
  • Loading branch information...
1 parent ca1feec commit e94fc10f8df328df004a9760b067ec8828f0b6e4 @rn-superg rn-superg committed May 29, 2010
Showing with 15 additions and 13 deletions.
  1. +3 −2 project.clj
  2. +6 −5 src/com/github/kyleburton/clj_bloom.clj
  3. +6 −6 test/com/github/kyleburton/clj_bloom_test.clj
View
@@ -3,5 +3,6 @@
:warn-on-reflection true
:dependencies
[[org.clojure/clojure "1.1.0"]
- [org.clojure/clojure-contrib "1.1.0"]
- [swank-clojure "1.2.1"]])
+ [org.clojure/clojure-contrib "1.1.0"]]
+ :dev-dependencies
+ [[swank-clojure "1.2.1"]])
@@ -44,10 +44,11 @@
(fn [#^String s bits]
(map #(%1 s bits) hash-fns))))
-(defstruct bloom-filter :hash-fn :num-bits :bitarray :insertions)
-
-(defn make-bloom-filter [num-bits hash-fn]
- (struct bloom-filter hash-fn num-bits (java.util.BitSet. num-bits) (atom 0)))
+(defn bloom-filter [num-bits hash-fn]
+ {:hash-fn hash-fn
+ :num-bits num-bits
+ :bitarray (java.util.BitSet. num-bits)
+ :insertions (atom 0)})
(defn add! [filter #^String string]
(reset! (:insertions filter)
@@ -101,7 +102,7 @@
(defn make-optimal-filter [entries prob & [hash-fn]]
(let [[m k] (optimal-n-and-k entries prob)]
- (make-bloom-filter
+ (bloom-filter
m
(make-permuted-hash-fn
(or hash-fn make-hash-fn-crc32)
@@ -9,23 +9,23 @@
(is (= (.hashCode "foo1")
((bf/make-hash-fn-hash-code "1") "foo" 0xFFFFFFFF)))))
-(deftest make-bloom-filter-test
+(deftest bloom-filter-test
(testing "creating a bloom filter"
- (is (thrown? Exception (bf/make-bloom-filter)))
- (is (bf/make-bloom-filter 1024 (bf/make-crc32 5))))
+ (is (thrown? Exception (bf/bloom-filter)))
+ (is (bf/bloom-filter 1024 (bf/make-crc32 5))))
(testing "new bloom filters should be empty"
- (is (.isEmpty (:bitarray (bf/make-bloom-filter 1024 (bf/make-crc32 5)))))))
+ (is (.isEmpty (:bitarray (bf/bloom-filter 1024 (bf/make-crc32 5)))))))
(deftest add-test
(testing "add shoud not be empty"
- (let [filter (bf/make-bloom-filter 1024 (bf/make-crc32 5))]
+ (let [filter (bf/bloom-filter 1024 (bf/make-crc32 5))]
(bf/add! filter "foo")
(is (not (.isEmpty (:bitarray filter))))
(is (= 1 (bf/insertions filter))))))
(deftest include?-test
(testing "after adding, a string should be in the filter"
- (let [filter (bf/make-bloom-filter 1024 (bf/make-crc32 5))]
+ (let [filter (bf/bloom-filter 1024 (bf/make-crc32 5))]
(is (not (bf/include? filter "foo")))
(bf/add! filter "foo")
(is (bf/include? filter "foo"))

0 comments on commit e94fc10

Please sign in to comment.