You certainly can implement such a thing. The source to the bytes Index 
function is in the bytes_platform.go files, as it is optimized per 
platform: https://golang.org/src/bytes/bytes_amd64.go is the amd64 one, for 
example. Looking at it is a good way to see how such a thing is implemented.

A naive implementation would be something like 
this: https://play.golang.org/p/75H1DSWryQ

But actually looking at the rest of the bytes implementation will give some 
insight into more efficient ways to do it

On Tuesday, November 14, 2017 at 9:21:35 AM UTC-6, Christian LeMoussel 
wrote:
>
> bytes package implements Index <https://golang.org/pkg/bytes/#Index> function 
> (func Index(s, sep []byte) int) that returns the index of the first 
> instance of sep in s, or -1 if sep is not present in s. 
> Do you think it's possible to do the same thing with uint32 slice (func 
> Index(s, sep []uint32) int)?
>
> eg: https://play.golang.org/p/kSu3lqsbRH
>     buffer := "83f9eed5fb46f700c1caca"
>     searchByte := []byte{0x65, 0x65, 0x64, 0x35, 0x66, 0x62, 0x34, 0x36, 
> 0x66, 0x37} // eed5fb46f7
>     if bytes.Index([]byte(buffer), searchByte) != -1 {
>         fmt.Println("OK")
>     }
>     
>     
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to