Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

bloom-filter

  1. Outdated egg!
  2. bloom-filter
  3. Documentation
    1. make-bloom-filter
    2. bloom-filter-set!
    3. bloom-filter-exists?
    4. bloom-filter?
    5. check-bloom-filter
    6. error-bloom-filter
    7. bloom-filter-algorithms
    8. bloom-filter-n
    9. bloom-filter-m
    10. bloom-filter-k
    11. bloom-filter-p-false-positive
    12. actual-k
    13. optimum-size
    14. desired-m
    15. optimum-k
    16. optimum-m
    17. p-false-positive
    18. p-random-one-bit
  4. Usage
  5. References
  6. Requirements
  7. Author
  8. Version history
  9. License

Documentation

Provides a simple Bloom Filter

Bloom Filter Object

make-bloom-filter

[procedure] (make-bloom-filter M MDPS [K]) --> bloom-filter

Returns a bloom-filter object with M bits of discrimination and a set of hash functions built from the supplied MDPS, a (list-of message-digest-primitive) objects.

The number of hashes, K, is not necessarily the same as the number of message-digests. A hash (here) is defined as an unsigned 32 bit integer. Most message-digests return more 32 bits of hash. The actual length of the hash is divided into 32 bit blocks to get the individual hashes.

The argument K will restrict the actual number of hashes to the "first" K, no matter how many more the supplied message-digests create. First in the order of MDPS.

[procedure] (make-bloom-filter P N MDPS) --> bloom-filter

Returns a bloom-filter object with M and K values chosen for the given population capacity N and probablity of false-positives P.

Selecting the optimal set of message-digests is beyond the scope of make-bloom-filter.

bloom-filter-set!

[procedure] (bloom-filter-set! BLOOM-FILTER OBJECT)

Add the specified OBJECT to the indicated BLOOM-FILTER.

bloom-filter-exists?

[procedure] (bloom-filter-exists? BLOOM-FILTER OBJECT) --> boolean

Is the specified OBJECT in the indicated BLOOM-FILTER.

bloom-filter?

check-bloom-filter

error-bloom-filter

[procedure] (bloom-filter? OBJ) --> boolean
[procedure] (check-bloom-filter LOC OBJ [NAM]) --> bloom-filter
[procedure] (error-bloom-filter LOC OBJ [NAM])

bloom-filter-algorithms

[procedure] (bloom-filter-algorithms BLOOM-FILTER) --> (list-of message-digest-primitive)

The mdps used for the filter.

bloom-filter-n

[procedure] (bloom-filter-n BLOOM-FILTER) --> fixnum

The current population - the number of objects added to the filter.

Not the population capacity.

bloom-filter-m

[procedure] (bloom-filter-m BLOOM-FILTER) --> fixnum

The number of bits of discrimination.

bloom-filter-k

[procedure] (bloom-filter-k BLOOM-FILTER) --> fixnum

The number of hashes. (See above.)

bloom-filter-p-false-positive

[procedure] (bloom-filter-p-false-positive BLOOM-FILTER [N]) --> number

The probability of a false-positive for the population capacity N, default is the current population, bloom-filter-n.

actual-k

[procedure] (actual-k MDPS) --> fixnum

Calculates the actual number of hashes for the MDPS.

optimum-size

[procedure] (optimum-size P N) --> fixnum fixnum

Returns 2 values, an optimal M, bits of discrimination, and K, number of hashes, for the given population size N and probability of false-positives P.

desired-m

[procedure] (desired-m P N [K]) --> fixnum fixnum number

Calculates a near-optimal number of bits of discrimination to meet the desired probability of false positives P, with the given population size N and number of hashes K. When the K parameter is missing optimum-k is used to calculate a value.

A multi-valued return of the calculated M, K, and P values. The calculated probability may be lower than the desired. The calculated M value will always be a fixnum.

optimum-k

[procedure] (optimum-k N M) --> fixnum

Optimal count of hashes for the given population size N and M bits of discrimination.

optimum-m

[procedure] (optimum-m K N) --> fixnum

Optimal count of bits of discrimination for the given population size N and K number of hashes.

p-false-positive

[procedure] (p-false-positive K N M) --> number

What is the probability of false positives for the population size N assuming K hashes and M bits of discrimination.

p-random-one-bit

[procedure] (p-random-one-bit K N M) --> number

Calculates the probablility of a random set bit for the given number of hash functions K, population size N, and bits of discrimination M.

Usage

(require-extension bloom-filter)

References

Nice exposition of Bloom Filter False Positive Probability.

Requirements

moremacros iset message-digest record-variants check-errors

setup-helper sha1 md5 sha2 test

Author

Kon Lovett

Version history

1.2.2
1.2.1
Fix bloom-filter-p-false-positive. Add types.
1.2.0
Add missing API.
1.1.8
Pick up the scraps.
1.1.7
Re-flow.
1.1.6
One more time.
1.1.5
* UNMAINTAINED *
1.1.4
Added optimum-size & make-bloom-filter variant. Calculations take the ceiling.
1.1.3
A little faster (10%). Better fixnum overflow detection.
1.1.2
Protect desired-m from fixnum representation overflow.
1.1.1
"Fix" for call of non-procedure - maybe. (Nope.)
1.1.0
A little faster (25%).
1.0.0
From the Chicken 3 version, with some changes. (No message-digest registry, for example.)

License

Copyright (C) 2010-2018 Kon Lovett. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.