红宝石阵内部 [英] ruby array internals
本文介绍了红宝石阵内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在内部实现红宝石阵列(主要是在CRuby,但任何其他的信息是值得欢迎的)?
How are ruby arrays internally implemented (mainly in CRuby, but any other info is welcomed)?
他们是可扩展的阵列像C ++载体或者是他们基于列表?什么是移位/不印字的复杂性和索引访问一个元素?
Are they growable arrays like a c++ vector or are they list based? What's the complexity of shift/unshift and accessing an element by index?
推荐答案
他们是可扩展的阵列其中增长底。
They're growable arrays which "grow at the end".
移
是 O(1)
,不印字
为 O(N)
和索引访问是 O(1)
。据我所知,这适用于所有Ruby实现真实的,但它肯定MRI做。
shift
is O(1)
, unshift
is O(n)
and accessing by index is O(1)
. To the best of my knowledge this holds true for all ruby implementations, but it definitely does in MRI.
这篇关于红宝石阵内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文