shbf
shifting_bloom_filter · C extension providing Bloom filter, shifting Bloom filter, and count-min sketch PostgreSQL data types and functions.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100686 | shbf | shifting_bloom_filter | 1.0.0 | FUNC | Unknown | C |
Usage
Sources:
shbf implements Count-Min Sketch, ordinary Bloom filter, and three Shifting Bloom Filter variants as compact probabilistic PostgreSQL values. These structures trade exact answers for bounded memory: positive membership and association results can be false positives, and frequency estimates can be overestimates.
Core Workflow
Create a filter with a planned bit count m and expected element count n. Insert functions return a new value, so always assign the result; they do not persistently mutate the stored datum in place.
Use a Count-Min Sketch for approximate frequencies.
Important Objects
cms: Count-Min Sketch;new_cms(error_bound, confidence)defaults to0.001and0.99, withinsert_cmsandquery_cmsfor approximate counts.bf: ordinary Bloom filter;new_bf(m, n),insert_bf, andquery_bfprovide membership operations.new_shbf_m(m, n),insert_shbf_m,query_shbf_m: shifting membership filter.new_shbf_a(m, n),insert_shbf_a,query_shbf_a: association filter for two sets.new_shbf_x(m, n, max_x),insert_shbf_x,query_shbf_x: multiplicity filter up to a planned maximum.
query_shbf_a returns encoded states: -1 absent; 0 second set; 1 first set; 2 both; 3 first-or-second; 4 both-or-second; 5 both-or-first; 6 any of the three membership states. Ambiguous codes are a consequence of collisions.
Sizing and Safety
Choose positive m, n, and max_x values from a measured workload, and keep inserted multiplicities within the planned bound. The reviewed constructors do little validation: zero or invalid sizes can reach division, modulo, allocation, or offset arithmetic in C. Test sizing and saturation outside production before storing a filter.
These types provide no deletion, merge aggregate, index operator class, automatic resize, or exact confidence report. Keep authoritative data elsewhere and treat the filter as an acceleration or telemetry summary only. The upstream project is compact research-oriented code; validate serialization across architectures and PostgreSQL upgrades before using stored values as durable data.