tags:

views:

179

answers:

1

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 collection, hence the SOME SORT.

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

+1  A: 

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.

Mark Bertenshaw
So does that mean there are both a linked list AND a hashtable existing side-by-side, holding references to the same item objects?And depending on how you iterate it, is uses the different data structures as needed?
Tom Tresansky
MarkJ
@MarkJ: I was hoping someone would be able to point me towards a resource which would clear up the speculation about the implementation.
Tom Tresansky
@Tom T: I know, and my point was that this answer doesn't do it.
MarkJ
Thanks for the update! I think this pretty much answers my question.
Tom Tresansky