Sequential Dictionary

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Sequential Dictionary

Joel Turnbull-2

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?

Thanks.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Sequential Dictionary

Stéphane Ducasse
Hi Joel

On Jul 11, 2010, at 5:00 PM, Joel Turnbull wrote:

>
> What is the group's recommendation for creating a sequential Dictionary? i.e. A Dictionary who's associations are ordered.

look at the one in Seaside :)
Lukas told me that they implemented one where the order of traversal using do: is the order of key/val addition.

> 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?
>
> Thanks.
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Sequential Dictionary

Levente Uzonyi-2
In reply to this post by Joel Turnbull-2
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.
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Sequential Dictionary

Joel Turnbull-2

Spent some time but was not quite able to get OrderedDictionary working. However I see the idea is for the Dictionary to hold an OrderedCollection that is synchronized with the Dictionary's array.

I think that's enough for me to go on to implement my own for the limited dictionary protocol I need to support.

I looked in the Seaside packages for subclasses of Dictionary, or classes named like Dictionary, but I didn't find anything.

I got a little lost looking at BTree, I should probably take the time to look at that  someday.

Thanks guys.



On Sun, Jul 11, 2010 at 11:45 AM, Levente Uzonyi <[hidden email]> wrote:
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.


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Sequential Dictionary

hernanmd
Hi Joel,

You may try the attached OrderedDictionary, I've been using it for some time.
Cheers,

Hernán

2010/7/12 Joel Turnbull <[hidden email]>:

>
> Spent some time but was not quite able to get OrderedDictionary working.
> However I see the idea is for the Dictionary to hold an OrderedCollection
> that is synchronized with the Dictionary's array.
>
> I think that's enough for me to go on to implement my own for the limited
> dictionary protocol I need to support.
>
> I looked in the Seaside packages for subclasses of Dictionary, or classes
> named like Dictionary, but I didn't find anything.
>
> I got a little lost looking at BTree, I should probably take the time to
> look at that  someday.
>
> Thanks guys.
>
>
>
> On Sun, Jul 11, 2010 at 11:45 AM, Levente Uzonyi <[hidden email]> wrote:
>>
>> 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.
>>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

OrderedDictionary.st (11K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Sequential Dictionary

Joel Turnbull-2

Thank you, it's working beautifully Hernán :)


2010/7/12 Hernán Morales Durand <[hidden email]>
Hi Joel,

You may try the attached OrderedDictionary, I've been using it for some time.
Cheers,

Hernán

2010/7/12 Joel Turnbull <[hidden email]>:
>
> Spent some time but was not quite able to get OrderedDictionary working.
> However I see the idea is for the Dictionary to hold an OrderedCollection
> that is synchronized with the Dictionary's array.
>
> I think that's enough for me to go on to implement my own for the limited
> dictionary protocol I need to support.
>
> I looked in the Seaside packages for subclasses of Dictionary, or classes
> named like Dictionary, but I didn't find anything.
>
> I got a little lost looking at BTree, I should probably take the time to
> look at that  someday.
>
> Thanks guys.
>
>
>
> On Sun, Jul 11, 2010 at 11:45 AM, Levente Uzonyi <[hidden email]> wrote:
>>
>> 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.
>>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project