diff options
author | Zsolt Felfoldi <zsfelfoldi@gmail.com> | 2017-09-06 07:43:00 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-09-06 16:14:20 +0800 |
commit | 6ff2c02991e60a8db54c2f60027442277fd889c0 (patch) | |
tree | c92ecb1a45cb9096a0c528f4b4b9eed92026f65d /core | |
parent | f585f9eee8cb18423c23fe8b517b5b4cbe3b3755 (diff) | |
download | dexon-6ff2c02991e60a8db54c2f60027442277fd889c0.tar dexon-6ff2c02991e60a8db54c2f60027442277fd889c0.tar.gz dexon-6ff2c02991e60a8db54c2f60027442277fd889c0.tar.bz2 dexon-6ff2c02991e60a8db54c2f60027442277fd889c0.tar.lz dexon-6ff2c02991e60a8db54c2f60027442277fd889c0.tar.xz dexon-6ff2c02991e60a8db54c2f60027442277fd889c0.tar.zst dexon-6ff2c02991e60a8db54c2f60027442277fd889c0.zip |
core/bloombits: AddBloom index parameter and fixes variable names
Diffstat (limited to 'core')
-rw-r--r-- | core/bloombits/generator.go | 13 | ||||
-rw-r--r-- | core/bloombits/generator_test.go | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/core/bloombits/generator.go b/core/bloombits/generator.go index 04a7f5146..540085450 100644 --- a/core/bloombits/generator.go +++ b/core/bloombits/generator.go @@ -49,21 +49,24 @@ func NewGenerator(sections uint) (*Generator, error) { // AddBloom takes a single bloom filter and sets the corresponding bit column // 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 if b.nextBit >= b.sections { return errSectionOutOfBounds } + if b.nextBit != index { + return errors.New("bloom filter with unexpected index") + } // Rotate the bloom and insert into our collection - byteMask := b.nextBit / 8 + byteIndex := b.nextBit / 8 bitMask := byte(1) << byte(7-b.nextBit%8) 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) - if (bloom[bloomByteMask] & bloomBitMask) != 0 { - b.blooms[i][byteMask] |= bitMask + if (bloom[bloomByteIndex] & bloomBitMask) != 0 { + b.blooms[i][byteIndex] |= bitMask } } b.nextBit++ diff --git a/core/bloombits/generator_test.go b/core/bloombits/generator_test.go index f4aa9551c..f9bcef96e 100644 --- a/core/bloombits/generator_test.go +++ b/core/bloombits/generator_test.go @@ -44,7 +44,7 @@ func TestGenerator(t *testing.T) { t.Fatalf("failed to create bloombit generator: %v", err) } 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) } } |