问题描述
对于整数键,索引的速度是O(N)
,所以它看起来像一个列表.但显然(wqw 在 Unable to proper loop through keys AND values in a VB6 For Each loop中的评论)字符串键的访问时间是 O(log(N))
... 也许它是建立在单链表之上的树(索引列表元素)?
For integer keys the speed of indexing is O(N)
, so it looks like it is a list. But apparently (wqw's comment in Unable to properly loop through keys AND values in a VB6 For Each loop) access time for string keys is O(log(N))
... Maybe it is a tree built on top of single-linked list (indexing the list elements)?
我努力获取有关此的文档,但我只能找到如何使用 Collection
,而不是它的数据模型是什么.
I tried hard to get the documentation about this, but all I can find is how to use the Collection
, never what is its data model.
推荐答案
我怀疑你会发现很多关于 VBA.Collection 的实现细节的东西.(官方使用参考在 https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/collection-object)
I doubt you'll find much of anything regarding the implementation details of VBA.Collection. (Official usage reference at https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/collection-object)
一般建议是考虑改用 VBScript Dictionary 对象;如果您需要访问密钥,当然可以使用它.据此,字典在一定程度上也更快:https://fastexcel.wordpress.com/2012/07/10/comparing-two-lists-vba-udf-shootout-between-linear-search-binary-search-collection-and-dictionary/
The general advice is to consider using the VBScript Dictionary object instead; certainly use that instead if you need access to the keys. According to this, Dictionary is also faster up to a point: https://fastexcel.wordpress.com/2012/07/10/comparing-two-lists-vba-udf-shootout-between-linear-search-binary-search-collection-and-dictionary/
我自己完成的另一个替代方法是使用 .NET Hashtable(引用 mscorlib.dll).我没有针对 VBScript Dictionary 进行任何性能测试,所以如果值得付出努力,我就不做(但实现起来很有趣).Cannot iterate Hashtable in VBA (Excel)中有一个例子.
Another alternative I've done myself was to make use of the .NET Hashtable (making reference to mscorlib.dll). I've not done any performance tests of that versus VBScript Dictionary, so I don't if it's worth the effort (but it was fun to implement). An example is at Cannot iterate Hashtable in VBA (Excel).
这篇关于VBA/VB6 集合到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!