Skip to content

Commit

Permalink
add AppendZeros
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Jan 23, 2025
1 parent e89c610 commit 8f22ebd
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))

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

View check run for this annotation

Codecov / codecov/patch

core/trie/bitarray.go#L325-L326

Added lines #L325 - L326 were not covered by tests
}

// 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))

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

View check run for this annotation

Codecov / codecov/patch

core/trie/bitarray.go#L330-L331

Added lines #L330 - L331 were not covered by tests
}

// 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

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

View check run for this annotation

Codecov / codecov/patch

core/trie/bitarray.go#L804-L810

Added lines #L804 - L810 were not covered by tests
}

// 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 8f22ebd

Please sign in to comment.