时间shell脚本关联数组的复杂性数组、复杂性、脚本、时间

2023-09-11 23:29:52 作者:甜味

我想知道如何关联数组构造/执行shell脚本中使用时。

I would like to know how an associative array is constructed/implemented when used in shell scripts.

另外,我想知道,如果shell脚本的时间复杂度基础的关联数组是最佳的,因为我们可以用字母和数字作为各自的密钥。

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.

编辑:他们使用什么样的哈希函数??

what hash function do they use??

推荐答案

如果您使用的是关联数组,你不通过使用字母和数字作为各自的钥匙对其进行访问;您正在使用的字符串 - 任何数字字符重新presentations,而不是实际的指数

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.

我找不到翻翻源任何具体短暂的,但大多数人认为它出现在内部它实现为一个哈希表(而不是树),所以您的访问,并插入平均时间将是O( 1)。没有得到更多的优化。

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.