-
Notifications
You must be signed in to change notification settings - Fork 4
/
bitarray_sort_example_test.go
52 lines (42 loc) · 1.01 KB
/
bitarray_sort_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
// 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 ExampleSlice_Sort() {
bas := bitarray.Slice{
bitarray.MustParse("1111-1111 0000"),
bitarray.MustParse("1111-1111 0"),
bitarray.MustParse("0000-0000 0000"),
bitarray.MustParse("0"),
bitarray.MustParse("0101-00"),
}
bas.Sort()
for i, ba := range bas {
fmt.Printf("%d: % b\n", i, ba)
}
// Output:
// 0: 0
// 1: 00000000 0000
// 2: 010100
// 3: 11111111 0
// 4: 11111111 0000
}
func ExampleSlice_Search() {
bas := bitarray.Slice{
bitarray.MustParse("1111-1111 0000"),
bitarray.MustParse("1111-1111 0"),
bitarray.MustParse("0000-0000 0000"),
bitarray.MustParse("0"),
bitarray.MustParse("0101-00"),
}
bas.Sort()
x := bitarray.MustParse("0o776")
idx := bas.Search(x)
fmt.Printf("%d: %b (%o)\n", idx, bas[idx], bas[idx])
// Output:
// 3: 111111110 (776)
}