A Two-Way Dictionary
Extending the Dictionary
Issue: 9.5 (July/August 2011)
Author: Marc Zeedar editor-at-rbdeveloper.com
Article Description: No description available.
Article Length (in bytes): 13,384
Starting Page Number: 63
RBD Number: 9509
9509.zip Updated: Tuesday, July 5, 2011 at 11:18 AM
Related Link(s): None
Known Limitations: None
Excerpt of article text...
I've written in the past about how wonderful dictionary objects are for data storage. I use them all the time. I like them better than arrays because they're faster for data retrieval and because they are based upon the variant datatype, you can store anything inside them (even other dictionaries). But dictionaries aren't the end-all and sometimes you can extend them or enhance them to create new objects that are even more powerful.
For example, how about a SortedDictionary? It always keeps itself in sort order even as you add new contents. (I'll leave you to write that one.)
You can also create dictionary variations that are optimized for the specific kind of data you're working with. That's what we're going to do today, but in a generic way that allows us to reuse this new class in all sorts of programs.
I'm talking about a Two-Way Dictionary. A normal dictionary is a key-value setup: that means you need the key to find its value. For most situations that's fine. But what if you had the value but not the key? Wouldn't it be nice to pass either the key or the value and get back its opposite?
...End of Excerpt. Please purchase the magazine to read the full article.
Article copyrighted by REALbasic Developer magazine. All rights reserved.