Skip to content

Commit

Permalink
core/bloom: move bit operation functions to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
manav2401 committed Jan 19, 2023
1 parent 9fd22b1 commit 09655fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
24 changes: 0 additions & 24 deletions core/bloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,27 +333,3 @@ func getOrCreateBloomFilter(key string, opts *BloomOpts) (*Bloom, error) {

return obj.Value.(*Bloom), nil
}

// setBit sets the bit at index `b` to "1" in `buf`.
func setBit(buf []byte, b uint64) {
idx, offset := b/8, 7-b%8
if idx >= uint64(len(buf)) {
return
}

buf[idx] = buf[idx] | 1<<offset
}

// isBitSet checks if the bit at index `b` is set to "1" or not in `buf`.
func isBitSet(buf []byte, b uint64) bool {
idx, offset := b/8, 7-b%8
if idx >= uint64(len(buf)) {
return false
}

if buf[idx]&(1<<offset) == 1<<offset {
return true
} else {
return false
}
}
25 changes: 25 additions & 0 deletions core/bloom_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package core

// setBit sets the bit at index `b` to "1" in `buf`.
func setBit(buf []byte, b uint64) {
idx, offset := b/8, 7-b%8
if idx >= uint64(len(buf)) {
return
}

buf[idx] = buf[idx] | 1<<offset
}

// isBitSet checks if the bit at index `b` is set to "1" or not in `buf`.
func isBitSet(buf []byte, b uint64) bool {
idx, offset := b/8, 7-b%8
if idx >= uint64(len(buf)) {
return false
}

if buf[idx]&(1<<offset) == 1<<offset {
return true
} else {
return false
}
}

0 comments on commit 09655fc

Please sign in to comment.