Tuesday 15 June 2010

pointers - In Go, how to determine offset of slice within an array? -


I know that a1 is a piece within the array a Is it possible to determine the a1 offset in relation to the introduction of a ? (Basically indicative arithmetic simulation)?

  a: = [..] int8 {3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3 , 2} a1: = a [3:14] FMT println (a1, "length", lane (a1), "and offset", / * offset (a1, a) * /)  

There is a way to do this:

  a: = [...] Int8 {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2} a1: = a [3:14] fmt.Println (A 1, "length", lane (a1), "and offset", cap (a) -cap (a1))  

expression a [p: e] < A piece with capacitance of / code> gives cap (A) - P . Looking at slices a1 and backing sir a , you can call p = cap (a) - cap (a1)

Can be calculated as


No comments:

Post a Comment