Skip to content

Commit

Permalink
add AppendZeros
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Jan 21, 2025
1 parent 4593de5 commit 86fa630
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/trie/bitarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ func (b *BitArray) AppendBit(x *BitArray, bit uint8) *BitArray {
return b.Append(x, new(BitArray).SetBit(bit))
}

// Sets the bit array to the concatenation of x and n zeros.
func (b *BitArray) AppendZeros(x *BitArray, n uint8) *BitArray {
return b.Append(x, new(BitArray).Zeros(n))
}

// Sets the bit array to a subset of x from startPos (inclusive) to endPos (exclusive),
// where position 0 is the MSB. If startPos >= endPos or if startPos >= x.len,
// returns an empty BitArray.
Expand Down Expand Up @@ -796,6 +801,15 @@ func (b *BitArray) Ones(length uint8) *BitArray {
return b
}

func (b *BitArray) Zeros(length uint8) *BitArray {
b.len = length
b.words[0] = 0
b.words[1] = 0
b.words[2] = 0
b.words[3] = 0
return b
}

// Returns the position of the first '1' bit in the array, scanning from most significant to least significant bit.
// The bit position is counted from the least significant bit, starting at 0.
// For example:
Expand Down

0 comments on commit 86fa630

Please sign in to comment.