reflect.DeepEqual() 在 Go 语言中的最坏时间复杂度是多少?

huangapple go评论76阅读模式
英文:

What is the worst-case time complexity of reflect.DeepEqual() in Go?

问题

我尝试分析源代码,但deepValueEqual()函数内部调用了许多其他函数,而且我必须承认,在这种情况下,递归的使用让我感到困惑。

是否有关于该函数最坏情况运行时间的官方文档?

*编辑:我不太理解在这种情况下如何定义输入大小,因为有两个interface{}类型的参数,这增加了我的困惑。也许这是因为我对时间复杂度不太熟悉。

英文:

I tried to analyze the source code, but many other functions are called from within deepValueEqual(), and I must admit that the use of recursion is throwing me off in this case.

Is there any official documentation of the function's worst-case running time?

*Edit: I don't quite understand how I would define input sizes in this case with two interface{} type arguments and it's adding to my confusion. Perhaps this is due to my unfamiliarity with time complexity.

答案1

得分: 1

reflect.DeepEqual()在Go语言中的最坏时间复杂度是O(n)。

需要注意的是,你的问题在形式上并不太有意义。"时间复杂度"是"输入大小"的函数,而如何衡量"输入大小"并没有明确定义。reflect.DeepEqual()只接受一个参数,所以它的时间复杂度是O(1),因为你不能将该函数应用于多个参数。你没有说明如何衡量一个参数的大小。

关于该函数的最坏情况运行时间是否有官方文档,答案是否定的。

英文:

> What is the worst-case time complexity of reflect.DeepEqual() in Go?

O(n).

Note that your question doesn't make much sense formally. "time complexity" is a function of "input size" and how you measure "input size" is not well defined. reflect.DeepEqual takes just one argument so its time complexity is O(1) simply because you cannot apply this function to more than one argument. How you measure the size of one argument you didn't tell.

> Is there any official documentation of the function's worst-case running time?

No.

huangapple
  • 本文由 发表于 2022年4月19日 14:33:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/71920581.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定