github.com/tunabay/go-bitarray@v1.3.1/bitarray_search_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 ExampleBitArray_HasPrefix() { 14 ba := bitarray.MustParse("1010-1111 0000-1111 10") 15 16 fmt.Println(ba.HasPrefix(bitarray.MustParse("10101"))) 17 fmt.Println(ba.HasPrefix(bitarray.MustParse("111"))) 18 19 // Output: 20 // true 21 // false 22 } 23 24 func ExampleBitArray_HasSuffix() { 25 ba := bitarray.MustParse("1010-1111 0000-1111 10") 26 27 fmt.Println(ba.HasSuffix(bitarray.MustParse("11110"))) 28 fmt.Println(ba.HasSuffix(bitarray.MustParse("111"))) 29 30 // Output: 31 // true 32 // false 33 } 34 35 func ExampleBitArray_Index() { 36 haystack := bitarray.MustParse("0010-1011 0001-0101 0101-0111 111") 37 needle := bitarray.MustParse("1010") 38 39 fmt.Println(haystack.Index(needle)) 40 41 // Output: 42 // 2 43 } 44 45 func ExampleBitArray_LastIndex() { 46 haystack := bitarray.MustParse("0010-1011 0001-0101 0101-0111 111") 47 needle := bitarray.MustParse("1010") 48 49 fmt.Println(haystack.LastIndex(needle)) 50 51 // Output: 52 // 17 53 } 54 55 func ExampleBitArray_AllIndex() { 56 haystack := bitarray.MustParse("0010-1011 0001-0101 0101-0111 111") 57 needle := bitarray.MustParse("1010") 58 59 fmt.Println(haystack.AllIndex(needle)) 60 61 // Output: 62 // [2 11 13 15 17] 63 }