github.com/tunabay/go-bitarray@v1.3.1/bitarray_sort_example_test.go (about) 1 // Copyright (c) 2021 Hirotsuna Mizuno. All rights reserved. 2 // Use of this source code is governed by the MIT license that can be found in 3 // the LICENSE file. 4 5 package bitarray_test 6 7 import ( 8 "fmt" 9 10 "github.com/tunabay/go-bitarray" 11 ) 12 13 func ExampleSlice_Sort() { 14 bas := bitarray.Slice{ 15 bitarray.MustParse("1111-1111 0000"), 16 bitarray.MustParse("1111-1111 0"), 17 bitarray.MustParse("0000-0000 0000"), 18 bitarray.MustParse("0"), 19 bitarray.MustParse("0101-00"), 20 } 21 22 bas.Sort() 23 for i, ba := range bas { 24 fmt.Printf("%d: % b\n", i, ba) 25 } 26 27 // Output: 28 // 0: 0 29 // 1: 00000000 0000 30 // 2: 010100 31 // 3: 11111111 0 32 // 4: 11111111 0000 33 } 34 35 func ExampleSlice_Search() { 36 bas := bitarray.Slice{ 37 bitarray.MustParse("1111-1111 0000"), 38 bitarray.MustParse("1111-1111 0"), 39 bitarray.MustParse("0000-0000 0000"), 40 bitarray.MustParse("0"), 41 bitarray.MustParse("0101-00"), 42 } 43 44 bas.Sort() 45 46 x := bitarray.MustParse("0o776") 47 idx := bas.Search(x) 48 fmt.Printf("%d: %b (%o)\n", idx, bas[idx], bas[idx]) 49 50 // Output: 51 // 3: 111111110 (776) 52 }