-
Notifications
You must be signed in to change notification settings - Fork 4
/
buffer_slice_example_test.go
56 lines (42 loc) · 1.06 KB
/
buffer_slice_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2021 Hirotsuna Mizuno. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
package bitarray_test
import (
"fmt"
"github.com/tunabay/go-bitarray"
)
func ExampleBuffer_Slice() {
ba := bitarray.MustParse("0011-1010 0110-1111 110")
buf := bitarray.NewBufferFromBitArray(ba)
buf2 := buf.Slice(4, 14)
fmt.Println(buf2)
buf3 := buf.Slice(9, 13)
fmt.Println(buf3)
// Output:
// 1010011011
// 1101
}
func ExampleBuffer_SliceToEnd() {
ba := bitarray.MustParse("0011-1010 0110-1")
buf := bitarray.NewBufferFromBitArray(ba)
fmt.Println(buf.SliceToEnd(4))
fmt.Println(buf.SliceToEnd(9))
// Output:
// 101001101
// 1101
}
func ExampleBuffer_Slice_update() {
ba := bitarray.MustParse("1000-0000 0000-01")
buf := bitarray.NewBufferFromBitArray(ba)
sub := buf.Slice(6, 10)
fmt.Println(buf, sub)
sub.FillBitsAt(0, 4, 1)
fmt.Println(buf, sub)
buf.FillBitsAt(7, 2, 0)
fmt.Println(buf, sub)
// Output:
// 10000000000001 0000
// 10000011110001 1111
// 10000010010001 1001
}