shell脚本中关联数组的时间复杂度
我想知道在 shell 脚本中使用关联数组时如何构造/实现。
另外,我想知道基于 shell 脚本的关联数组的时间复杂度是否是最佳的,因为我们可以使用字母和数字作为它们各自的键。
编辑:他们使用什么哈希函数?
I would like to know how an associative array is constructed/implemented when used in shell scripts.
Also, I want to know if the time complexity of shell script based associative arrays are optimal since we can use alphabets as well as numbers as their respective keys.
EDIT: what hash function do they use??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用关联数组,则不能通过“使用字母和数字作为各自的键”来访问它;您使用的是字符串 - 任何数字都是字符表示,而不是实际的索引。
除了查看源代码之外,我找不到任何具体内容,但从大多数情况来看,它在内部似乎是作为哈希表(而不是树)实现的,因此您的访问和插入平均时间将是 O(1)。并没有变得更加优化。
If you're using an associative array, you're not accessing it via "use alphabets as well as numbers as their respective keys"; You're using strings - any numbers are the character representations, not an actual index.
I can't find anything concrete short of looking through the source, but by most accounts it appears that internally it's implemented as a hash table (rather than a tree) so your access and insert average time is going to be O(1). Doesn't get much more optimal.