Time complexity of associative arrays in shell scripts

本秂侑毒 提交于 2019-12-12 04:27:49

问题


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??


回答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.



来源:https://stackoverflow.com/questions/5710043/time-complexity-of-associative-arrays-in-shell-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!