简体   繁体   中英

what am i doing wrong in this bloom filter implementation?

I have this bit table for a segmented bloom filter. Here every column is managed by a single hash function.

unsigned char bit_table_[ROWS][COLUMNS];//bit_table now have 8*ROWS*COLUMNS bits
unsigned char bit_mask[bits_per_char] = { 0x01,0x02,0x04,0x08,
                                          0x10,0x20,0x40,0x80};

There are ROWS number of hash functions each of which handles the setting and checking of COLUMNS*8 bits.

Elements are hashed and bit_index and bit are calculated as

compute_indices(unsigned int hash)
{
   bit_index=hash%COLUMNS;
   bit=bit_index%8;
}

Now insetion is done as

for (std::size_t i = 0; i < ROWS; ++i)
      {
        hash=compute_hash(i,set_element);
        compute_indices(hash);
        bit_table_[i][bit_index ] |= bit_mask[bit]; 
      }

And the query is

for (std::size_t i = 0; i < ROWS; ++i)
      {
     hash=compute_hash(i,set_element);
      compute_indices(hash);

      if (((bit_table_[i][bit_index])& bit_mask[bit]) != bit_mask[bit])
         {
            return false;
         }      
  }

My problem is the bloom filter gets full too soon and I suspect that i am not using the individual bits of the characters correctly. For example i suppose i should have something like:

bit_table_[i][bit_index][bit]|=bit_mask[bit];

for insertion but, since the bit_table is declared as two dimensional array i am not allowed to do this.

What should i do to make use of the individual bits of the char array?

English is my second language, so you might have trouble understanding my question. I would be happy to explain my points more if requested.

EDIT: compute_hash(i,set_elemnt) uses predefined salt values to compute hash value of the element to be inserted or queried.

There is an error in your compute_indices method.

You are computing a column index and then apply a modulo 8 on this column index. At the end you will always use the same bit in a column. For example for the column 10, you will always use the bit 2.

You should have :

compute_indices(unsigned int hash)
{
    int bitIndex = hash % (COLUMNS * 8);
    bit_index= bitIndex / 8;
    bit = bitIndex % 8;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM