core/bloombits: AddBloom index parameter and fixes variable names
This commit is contained in:
parent
f585f9eee8
commit
6ff2c02991
|
@ -49,21 +49,24 @@ func NewGenerator(sections uint) (*Generator, error) {
|
||||||
|
|
||||||
// AddBloom takes a single bloom filter and sets the corresponding bit column
|
// AddBloom takes a single bloom filter and sets the corresponding bit column
|
||||||
// in memory accordingly.
|
// in memory accordingly.
|
||||||
func (b *Generator) AddBloom(bloom types.Bloom) error {
|
func (b *Generator) AddBloom(index uint, bloom types.Bloom) error {
|
||||||
// Make sure we're not adding more bloom filters than our capacity
|
// Make sure we're not adding more bloom filters than our capacity
|
||||||
if b.nextBit >= b.sections {
|
if b.nextBit >= b.sections {
|
||||||
return errSectionOutOfBounds
|
return errSectionOutOfBounds
|
||||||
}
|
}
|
||||||
|
if b.nextBit != index {
|
||||||
|
return errors.New("bloom filter with unexpected index")
|
||||||
|
}
|
||||||
// Rotate the bloom and insert into our collection
|
// Rotate the bloom and insert into our collection
|
||||||
byteMask := b.nextBit / 8
|
byteIndex := b.nextBit / 8
|
||||||
bitMask := byte(1) << byte(7-b.nextBit%8)
|
bitMask := byte(1) << byte(7-b.nextBit%8)
|
||||||
|
|
||||||
for i := 0; i < types.BloomBitLength; i++ {
|
for i := 0; i < types.BloomBitLength; i++ {
|
||||||
bloomByteMask := types.BloomByteLength - 1 - i/8
|
bloomByteIndex := types.BloomByteLength - 1 - i/8
|
||||||
bloomBitMask := byte(1) << byte(i%8)
|
bloomBitMask := byte(1) << byte(i%8)
|
||||||
|
|
||||||
if (bloom[bloomByteMask] & bloomBitMask) != 0 {
|
if (bloom[bloomByteIndex] & bloomBitMask) != 0 {
|
||||||
b.blooms[i][byteMask] |= bitMask
|
b.blooms[i][byteIndex] |= bitMask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.nextBit++
|
b.nextBit++
|
||||||
|
|
|
@ -44,7 +44,7 @@ func TestGenerator(t *testing.T) {
|
||||||
t.Fatalf("failed to create bloombit generator: %v", err)
|
t.Fatalf("failed to create bloombit generator: %v", err)
|
||||||
}
|
}
|
||||||
for i, bloom := range input {
|
for i, bloom := range input {
|
||||||
if err := gen.AddBloom(bloom); err != nil {
|
if err := gen.AddBloom(uint(i), bloom); err != nil {
|
||||||
t.Fatalf("bloom %d: failed to add: %v", i, err)
|
t.Fatalf("bloom %d: failed to add: %v", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ func (b *BloomIndexer) Reset(section uint64) {
|
||||||
// Process implements core.ChainIndexerBackend, adding a new header's bloom into
|
// Process implements core.ChainIndexerBackend, adding a new header's bloom into
|
||||||
// the index.
|
// the index.
|
||||||
func (b *BloomIndexer) Process(header *types.Header) {
|
func (b *BloomIndexer) Process(header *types.Header) {
|
||||||
b.gen.AddBloom(header.Bloom)
|
b.gen.AddBloom(uint(header.Number.Uint64()-b.section*b.size), header.Bloom)
|
||||||
b.head = header.Hash()
|
b.head = header.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) {
|
||||||
if header == nil {
|
if header == nil {
|
||||||
b.Fatalf("Error creating bloomBits data")
|
b.Fatalf("Error creating bloomBits data")
|
||||||
}
|
}
|
||||||
bc.AddBloom(header.Bloom)
|
bc.AddBloom(uint(i-sectionIdx*sectionSize), header.Bloom)
|
||||||
}
|
}
|
||||||
sectionHead := core.GetCanonicalHash(db, (sectionIdx+1)*sectionSize-1)
|
sectionHead := core.GetCanonicalHash(db, (sectionIdx+1)*sectionSize-1)
|
||||||
for i := 0; i < types.BloomBitLength; i++ {
|
for i := 0; i < types.BloomBitLength; i++ {
|
||||||
|
|
Loading…
Reference in New Issue