Skip to content

Commit

Permalink
Add BitSet()
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Dec 26, 2024
1 parent 23c46f0 commit fa237e8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/trie/bitarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,22 @@ func (b *BitArray) Equal(x *BitArray) bool {
}

// Returns true if bit n-th is set, where n = 0 is LSB.
// The n must be <= 255.
func (b *BitArray) IsBitSet(n uint8) bool {
return b.BitSet(n) == 1
}

// Returns the bit value at position n, where n = 0 is LSB.
// If n is out of bounds, returns 0.
func (b *BitArray) BitSet(n uint8) uint8 {
if n >= b.len {
return false
return 0
}

return (b.words[n/64] & (1 << (n % 64))) != 0
if (b.words[n/64] & (1 << (n % 64))) != 0 {
return 1
}

return 0
}

// Serialises the BitArray into a bytes buffer in the following format:
Expand Down

0 comments on commit fa237e8

Please sign in to comment.