Skip to content

Commit 7cd54d2

Browse files
committed
Add Buffer.FillBits().
1 parent 25012bf commit 7cd54d2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

buffer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ func (buf *Buffer) Resize(nBits int, align Alignment) {
158158
buf.off = 0
159159
}
160160

161+
// FillBits sets all the bits in the buffer to the value bit, 0 or 1.
162+
func (buf *Buffer) FillBits(bit byte) {
163+
buf.FillBitsAt(0, buf.nBits, bit)
164+
}
165+
161166
// FillBitsAt sets the nBits bits starting at off to the value bit.
162167
func (buf *Buffer) FillBitsAt(off, nBits int, bit byte) {
163168
switch {

buffer_example_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,13 @@ func ExampleBuffer_Len() {
9595
// Output:
9696
// 4096
9797
}
98+
99+
func ExampleBuffer_FillBits() {
100+
buf := bitarray.NewBuffer(12)
101+
102+
buf.Slice(5, 10).FillBits(1)
103+
fmt.Printf("% b\n", buf)
104+
105+
// Output:
106+
// 00000111 1100
107+
}

0 commit comments

Comments
 (0)