lisp-random / bloom-filter.lisp

Diff from to

bloom-filter.lisp

    (error "HASH-FUNCTION must be specified for a bloom filter.")
    :type (function (t) (integer 0))))
 
-(defun bloom-filter-length (bf)
-  (length (bloom-filter-bits bf)))
-
-(defun bloom-filter-insert (bf object)
-  (setf (bloom-filter-bits bf)
-        (logior (bloom-filter-bits bf)
-                (funcall (bloom-filter-hash-function bf) object)))
-  (incf (bloom-filter-count bf)))
-
 (declaim (inline log-contains-p))
 (defun log-contains-p (a b)
   "Does the integer B contain all of the 1 bits that A has?"
 
 (defun bloom-filter-add (bf object)
   "Add OBJECT to the Bloom filter BF."
+  (incf (bloom-filter-count bf))
   (setf (bloom-filter-bits bf)
-        (logand (bloom-filter-bits bf)
-                (funcall (bloom-filter-hash-function bf) object))))
+        (logior (bloom-filter-bits bf)
+                (funcall (bloom-filter-hash-function bf) object)))
+  bf)
 
 (defun bloom-filter-contains-p (bf object)
   "Does the Bloom filter BF contain the object OBJECT?"
          (bit-prob (- 1.0d0 (/ m=k))))
     (expt (- 1.0d0 (expt bit-prob (* n m=k)))
           m=k)))
+
+(defun make-generic-bloom-filter ()
+  "Make a generic Bloom filter, working on any element type."
+  (make-bloom-filter :size (logcount most-positive-fixnum)
+                     :hash-function #'sxhash))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.