From 86fa63028b35c5a4d6399d9196547c249d103ff7 Mon Sep 17 00:00:00 2001 From: weiihann Date: Tue, 21 Jan 2025 21:31:16 +0800 Subject: [PATCH] add AppendZeros --- core/trie/bitarray.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/trie/bitarray.go b/core/trie/bitarray.go index 90fe8b3667..c44d24ba34 100644 --- a/core/trie/bitarray.go +++ b/core/trie/bitarray.go @@ -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. @@ -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: