What Are Collections Implemented As In VB6?

后端 未结 1 1154
忘掉有多难
忘掉有多难 2020-12-10 04:41

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 ha

相关标签:
1条回答
  • 2020-12-10 05:39

    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 讨论(0)
提交回复
热议问题