开发者

What Are Collections Implemented As In VB6?

开发者 https://www.devze.com 2022-12-25 07:48 出处:网络
So a collection in VB6 keeps track of a key for each object, and you can look up the object by its key.

So a collection in VB6 keeps track of a key for each object, and you can look up the object by its key.

Does that mean collections are implemented as some sort of hashtable under the hood? I realize you can have multiple items with the same key in a collect开发者_如何转开发ion, hence the SOME SORT.

Anybody know what type data structure a VB6 collection is supposed to represent?


As far as I know, the VBA Collection is implemented as a linked list (used by Integer indexes and For Each...Next) and a hash table (used by keys). And as Raven said, you can't have multiple items with the same key.

Edited:

@MarkJ: I should have given my cite for this: Hardcore Visual Basic 2nd Ed. by Bruce McKinney, published by Microsoft Press 1997 ISBN 1-57231-422-2

Quotes:

Page 191 - The Collection Class

"To put it simply, the Collection class is a souped-up C++ version of the CList class [...]. In fact, if you enhance CList to be a doubly linked list and give it a few more features (and perhaps use a hash table to look up string keys), you'll have a collection class much like the one provided with Visual Basic."

Page 197 - Performance

"And, as a matter of fact, I have been told by Visual Basic developers that Collections are doubly linked lists (with additional features to support indexing)."

Now, McKinney was more of a journalist than a programmer, and not a developer. However, he did work for Microsoft, and have contacts in the VB and VBA teams. His explanation works for me.

Incidentally, the reason for the doubly-linked list is to make it efficient to insert items at both the beginning and end of the collection.

0

精彩评论

暂无评论...
验证码 换一张
取 消