Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม

Counting Bloom Filter (บลูมฟิลเตอร์แบบนับ) ในโครงสร้างข้อมูล

Basic Concept

Counting Bloom Filter = Generalized Data Structure ของ Bloom Filter
ใช้ Test ว่า Count ของ Element ใดๆ < Threshold θ หรือไม่ (Given Sequence of Elements)

Generalized Form → False Positives Possible, No False Negatives
Query Returns: "Possibly ≥ θ" หรือ "Definitely < θ"

Algorithm Description

  1. Parameters: n, k เหมือน Bloom Filter, m = จำนวน Counters (ขยายจาก m Bits)
  2. Empty Filter: m Counters ทั้งหมด = 0
  3. k Hash Functions: Map Element → m Counter Positions (Uniform Random)
  4. k = Constant ≪ m, Proportional to Elements to Add

Insert Element

Hash Element ด้วย k Functions → k Array Positions → Increment Counters by 1 ทุก Position

Query Element with Threshold θ

  1. Hash Element → k Counter Positions
  2. ถ้า Counter ใด < θ → Count Definitely < θ (เพราะถ้า ≥ θ ทุก Counter จะ ≥ θ)
  3. ถ้า All Counters ≥ θ → Either Count ≥ θ จริง, หรือ False Positive (Counters ≥ θ โดยโชค)
  4. False Positive = All ≥ θ แต่ Count จริง < θ → Minimize เหมือน Bloom Filter

สรุป

Counting Bloom Filter = Bloom Filter + Counters แทน Bits
รองรับ: Insert, Delete (Decrement), Count Threshold Queries
No False Negatives, False Positives Possible
Space: m Counters (Typically 4-bit) แทน m Bits