On Sun, 11 Jul 2010, Joel Turnbull wrote:
What is the group's recommendation for creating a sequential Dictionary? i.e. A Dictionary who's associations are ordered.
Is there any precedent for this? Or does it sound like I'm barking up the wrong tree?
In my model, I've subclassed Dictionary into QuantityDictionary to store line items, where the key is the item and the value is the quantity of the item. It validates that the value is always a numeric, removes the association when the value goes below zero, and other stuff specific to my application.
Now I'm finding it makes sense to be able to order these associations. Imagine a recipe ingredient list, where you add and edit quantities of ingredients, and you want to put the ingredients that you use earliest in the recipe at the top of the ingredient list.
Before I put any more work into it, I just wanted to make sure that a sequential dictionary makes sense, and get your ideas on how to generally go about implementing that?
A "sequential dictionary" can mean a lot of different things. There are some implementations with different semantics available. See these for example: http://squeaksource.com/BTree.html http://forum.world.st/OrderedDictionary-td277320.html If you just want to iterate over your dictionary once in the sorted order, then the best thing to do is to collect your data into an array, sort the array, then iterate over that sorted array. Levente
Thanks.