This commit is contained in:
debris 2015-11-28 17:10:14 +01:00
parent f0f70f801e
commit e769406b92

View File

@ -81,7 +81,7 @@ impl<'a, D> ChainFilter<'a, D> where D: FilterDataSource
for i in 0..self.index_size { for i in 0..self.index_size {
indexes.insert(BloomIndex { indexes.insert(BloomIndex {
level: new_level, level: new_level,
index: offset + i index: offset + i,
}); });
} }
@ -101,7 +101,7 @@ impl<'a, D> Filter for ChainFilter<'a, D> where D: FilterDataSource
let bloom_index = self.bloom_index(block_number, level); let bloom_index = self.bloom_index(block_number, level);
let new_bloom = match self.data_source.bloom_at_index(&bloom_index) { let new_bloom = match self.data_source.bloom_at_index(&bloom_index) {
Some(old_bloom) => old_bloom | bloom, Some(old_bloom) => old_bloom | bloom,
None => bloom.clone() None => bloom.clone(),
}; };
result.insert(bloom_index, new_bloom); result.insert(bloom_index, new_bloom);
@ -125,15 +125,15 @@ impl<'a, D> Filter for ChainFilter<'a, D> where D: FilterDataSource
Some(to_shift) => { Some(to_shift) => {
*to_shift = &blooms[i] | to_shift; *to_shift = &blooms[i] | to_shift;
false false
}, }
None => true None => true,
}; };
// it hasn't been modified yet // it hasn't been modified yet
if is_new_bloom { if is_new_bloom {
let new_bloom = match self.data_source.bloom_at_index(&bloom_index) { let new_bloom = match self.data_source.bloom_at_index(&bloom_index) {
Some(old_bloom) => old_bloom | &blooms[i], Some(old_bloom) => old_bloom | &blooms[i],
None => blooms[i].clone() None => blooms[i].clone(),
}; };
result.insert(bloom_index, new_bloom); result.insert(bloom_index, new_bloom);
} }
@ -157,7 +157,7 @@ impl<'a, D> Filter for ChainFilter<'a, D> where D: FilterDataSource
.filter(|li| li != &reset_index) .filter(|li| li != &reset_index)
.map(|li| self.data_source.bloom_at_index(&li)) .map(|li| self.data_source.bloom_at_index(&li))
.filter_map(|b| b) .filter_map(|b| b)
.fold(H2048::new(), | acc, bloom | { &acc | bloom }); .fold(H2048::new(), |acc, bloom| &acc | bloom);
reset_index = index.clone(); reset_index = index.clone();
result.insert(index, &new_bloom | bloom); result.insert(index, &new_bloom | bloom);
@ -172,7 +172,11 @@ impl<'a, D> Filter for ChainFilter<'a, D> where D: FilterDataSource
} }
/// returns numbers of blocks that may contain Address /// returns numbers of blocks that may contain Address
fn blocks_with_address(&self, address: &Address, from_block: usize ,to_block: usize) -> Vec<usize> { fn blocks_with_address(&self,
address: &Address,
from_block: usize,
to_block: usize)
-> Vec<usize> {
let mut bloom = H2048::new(); let mut bloom = H2048::new();
bloom.shift_bloom(&address.sha3()); bloom.shift_bloom(&address.sha3());
self.blocks_with_bloom(&bloom, from_block, to_block) self.blocks_with_bloom(&bloom, from_block, to_block)