Skip to content

Commit

Permalink
add AppendBit()
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Jan 19, 2025
1 parent 7c4aeb3 commit 46de9ca
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/trie/bitarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
)

const (
maxUint64 = uint64(math.MaxUint64) // 0xFFFFFFFFFFFFFFFF
maxUint8 = uint8(math.MaxUint8)
maxUint64 = uint64(math.MaxUint64) // 0xFFFFFFFFFFFFFFFF
maxUint8 = uint8(math.MaxUint8)
MaxBitArraySize = 33 // (1 + 4 * 8) bytes
)

var emptyBitArray = new(BitArray)
Expand Down Expand Up @@ -318,6 +319,11 @@ func (b *BitArray) Append(x, y *BitArray) *BitArray {
return b.Lsh(x, y.len).Or(b, y)
}

// Sets the bit array to the concatenation of x and a single bit.
func (b *BitArray) AppendBit(x *BitArray, bit uint8) *BitArray {
return b.Append(b, new(BitArray).SetBit(bit))

Check warning on line 324 in core/trie/bitarray.go

View check run for this annotation

Codecov / codecov/patch

core/trie/bitarray.go#L323-L324

Added lines #L323 - L324 were not covered by tests
}

// Sets the bit array to x | y and returns the bit array.
func (b *BitArray) Or(x, y *BitArray) *BitArray {
b.words[0] = x.words[0] | y.words[0]
Expand Down

0 comments on commit 46de9ca

Please sign in to comment.