在https://github.com/Workiva/go-datastructures/tree/master/bitarray中定义的's'在哪里?

Sea*_*rry 1 go go-guru

我没看到在哪里s定义.大师不会告诉我.我得到的只是"没有标识符的对象",但它知道k它旁边的权利.以下是链接代码的典型代码段:

func getIndexAndRemainder(k uint64) (uint64, uint64) {
    return k / s, k % s
}
Run Code Online (Sandbox Code Playgroud)

一个字母的变量名称肯定会让你更难以找到.我找了通常的嫌疑人:var s uint64,s := ...什么都没有.显然,它需要是某个地方定义的全球价值.

这让我有两个问题:

  1. s来自哪里?
  2. 如果不在这里问我怎么才能找到它?

编辑:对于其他偶然发现此事的人.

Guru失败了,因为我没有在适当的Go工作区下检查包的源代码,方法是将git clone放在/ some/path/src下并设置GOPATH为/ some/path.因此,虽然我认为GOPATH=. guru definition s会起作用,GOPATH但却被忽略了.大师可以找到,k因为它在文件中,但它不知道如何查看其他文件.

我的grep失败的原因const使用简单=而不是a :=.我将在将来贪图时记住这一点.

Jea*_*nal 5

它定义于go-datastructures/bitarray/block.go:

// s denotes the size of any element in the block array.
// For a block of uint64, s will be equal to 64
// For a block of uint32, s will be equal to 32
// and so on...
const s = uint64(unsafe.Sizeof(block(0)) * 8)
Run Code Online (Sandbox Code Playgroud)

由于变量s未在函数中定义,并且没有包名称或别名作为前缀,因此它必须是包的全局(变量或常量)bitarray.

一旦知道了,我就浏览了go-datastructures/bitarray没有后缀的文件夹中的每个文件_test,我找了一个顶级声明s.