SmallDictionary>>removeAll or >>empty?

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

SmallDictionary>>removeAll or >>empty?

Simon Denier-3
Stupid question: how do I remove all entities from a SmallDictionary

Let's take:
d := SmallDictionary new.
d add: $d -> 4.
d add: $e -> 5.
d

If I do
d empty

then d size = 0 and d do: behaves as if there is nothing
BUT someone can still perform
d at: $d -> 5

If I do
d removeAll

I get a MessageNotUnderstood: SmallInteger>>key
because #removeAll inherited from Collection expects a different  
structure

--
  Simon




_______________________________________________
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: SmallDictionary>>removeAll or >>empty?

Lukas Renggli
SmallDictionary comes from the refactoring engine. It is a highly
optimized dictionary originally intended for parse-tree matching. The
method #empty does not make sense outside that context.

The method #removeAll is implemented in Collection. I don't think that
this implementation can ever work in any concrete collection
implementation, because it modifies the collection while iterating
over it (lint would know that). Most classes override it with
something sensible though.

Lukas

2009/12/5 Simon Denier <[hidden email]>:

> Stupid question: how do I remove all entities from a SmallDictionary
>
> Let's take:
> d := SmallDictionary new.
> d add: $d -> 4.
> d add: $e -> 5.
> d
>
> If I do
> d empty
>
> then d size = 0 and d do: behaves as if there is nothing
> BUT someone can still perform
> d at: $d -> 5
>
> If I do
> d removeAll
>
> I get a MessageNotUnderstood: SmallInteger>>key
> because #removeAll inherited from Collection expects a different
> structure
>
> --
>  Simon
>
>
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
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: SmallDictionary>>removeAll or >>empty?

Stéphane Ducasse
this is strange since I recall nicolas or somebody proposing a real removalAll.
So I would have thought it would work.

Stef

On Dec 5, 2009, at 5:49 PM, Lukas Renggli wrote:

> SmallDictionary comes from the refactoring engine. It is a highly
> optimized dictionary originally intended for parse-tree matching. The
> method #empty does not make sense outside that context.
>
> The method #removeAll is implemented in Collection. I don't think that
> this implementation can ever work in any concrete collection
> implementation, because it modifies the collection while iterating
> over it (lint would know that). Most classes override it with
> something sensible though.
>
> Lukas
>
> 2009/12/5 Simon Denier <[hidden email]>:
>> Stupid question: how do I remove all entities from a SmallDictionary
>>
>> Let's take:
>> d := SmallDictionary new.
>> d add: $d -> 4.
>> d add: $e -> 5.
>> d
>>
>> If I do
>> d empty
>>
>> then d size = 0 and d do: behaves as if there is nothing
>> BUT someone can still perform
>> d at: $d -> 5
>>
>> If I do
>> d removeAll
>>
>> I get a MessageNotUnderstood: SmallInteger>>key
>> because #removeAll inherited from Collection expects a different
>> structure
>>
>> --
>>  Simon
>>
>>
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
>
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>
> _______________________________________________
> 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: SmallDictionary>>removeAll or >>empty?

Nicolas Cellier
Lukas is speaking of default Collection>>removeAll which has few
chances to work.
But subclasses do a better job, that's why I did not bother...
Cheers

Nicolas

2009/12/5 Stéphane Ducasse <[hidden email]>:

> this is strange since I recall nicolas or somebody proposing a real removalAll.
> So I would have thought it would work.
>
> Stef
>
> On Dec 5, 2009, at 5:49 PM, Lukas Renggli wrote:
>
>> SmallDictionary comes from the refactoring engine. It is a highly
>> optimized dictionary originally intended for parse-tree matching. The
>> method #empty does not make sense outside that context.
>>
>> The method #removeAll is implemented in Collection. I don't think that
>> this implementation can ever work in any concrete collection
>> implementation, because it modifies the collection while iterating
>> over it (lint would know that). Most classes override it with
>> something sensible though.
>>
>> Lukas
>>
>> 2009/12/5 Simon Denier <[hidden email]>:
>>> Stupid question: how do I remove all entities from a SmallDictionary
>>>
>>> Let's take:
>>> d := SmallDictionary new.
>>> d add: $d -> 4.
>>> d add: $e -> 5.
>>> d
>>>
>>> If I do
>>> d empty
>>>
>>> then d size = 0 and d do: behaves as if there is nothing
>>> BUT someone can still perform
>>> d at: $d -> 5
>>>
>>> If I do
>>> d removeAll
>>>
>>> I get a MessageNotUnderstood: SmallInteger>>key
>>> because #removeAll inherited from Collection expects a different
>>> structure
>>>
>>> --
>>>  Simon
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>
>>
>>
>>
>> --
>> Lukas Renggli
>> http://www.lukas-renggli.ch
>>
>> _______________________________________________
>> 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
Reply | Threaded
Open this post in threaded view
|

Re: SmallDictionary>>removeAll or >>empty?

Simon Denier-3
In reply to this post by Lukas Renggli

On 5 déc. 2009, at 17:49, Lukas Renggli wrote:

> SmallDictionary comes from the refactoring engine. It is a highly
> optimized dictionary originally intended for parse-tree matching. The
> method #empty does not make sense outside that context.
>
> The method #removeAll is implemented in Collection. I don't think that
> this implementation can ever work in any concrete collection
> implementation, because it modifies the collection while iterating
> over it (lint would know that). Most classes override it with
> something sensible though.

Back from my trip, my neurons are still not 100% functional.

What would be a sensible implementation then?

Most straightforward I can think of:

SmallDictionary>>removeAll
 self initliaze

>
> Lukas
>
> 2009/12/5 Simon Denier <[hidden email]>:
>> Stupid question: how do I remove all entities from a SmallDictionary
>>
>> Let's take:
>> d := SmallDictionary new.
>> d add: $d -> 4.
>> d add: $e -> 5.
>> d
>>
>> If I do
>> d empty
>>
>> then d size = 0 and d do: behaves as if there is nothing
>> BUT someone can still perform
>> d at: $d -> 5
>>
>> If I do
>> d removeAll
>>
>> I get a MessageNotUnderstood: SmallInteger>>key
>> because #removeAll inherited from Collection expects a different
>> structure
>>
>> --
>>  Simon
>>
>>
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
>
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

--
 Simon




_______________________________________________
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: SmallDictionary>>removeAll or >>empty?

Nicolas Cellier
2009/12/7 Simon Denier <[hidden email]>:

>
> On 5 déc. 2009, at 17:49, Lukas Renggli wrote:
>
>> SmallDictionary comes from the refactoring engine. It is a highly
>> optimized dictionary originally intended for parse-tree matching. The
>> method #empty does not make sense outside that context.
>>
>> The method #removeAll is implemented in Collection. I don't think that
>> this implementation can ever work in any concrete collection
>> implementation, because it modifies the collection while iterating
>> over it (lint would know that). Most classes override it with
>> something sensible though.
>
> Back from my trip, my neurons are still not 100% functional.
>
> What would be a sensible implementation then?
>
> Most straightforward I can think of:
>
> SmallDictionary>>removeAll
>  self initliaze
>

or
    size := 0.
    keys atAllPut: nil.
    values atAllPut: nil.

>>
>> Lukas
>>
>> 2009/12/5 Simon Denier <[hidden email]>:
>>> Stupid question: how do I remove all entities from a SmallDictionary
>>>
>>> Let's take:
>>> d := SmallDictionary new.
>>> d add: $d -> 4.
>>> d add: $e -> 5.
>>> d
>>>
>>> If I do
>>> d empty
>>>
>>> then d size = 0 and d do: behaves as if there is nothing
>>> BUT someone can still perform
>>> d at: $d -> 5
>>>
>>> If I do
>>> d removeAll
>>>
>>> I get a MessageNotUnderstood: SmallInteger>>key
>>> because #removeAll inherited from Collection expects a different
>>> structure
>>>
>>> --
>>>  Simon
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>
>>
>>
>>
>> --
>> Lukas Renggli
>> http://www.lukas-renggli.ch
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
> --
>  Simon
>
>
>
>
> _______________________________________________
> 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: SmallDictionary>>removeAll or >>empty?

Stéphane Ducasse
In reply to this post by Simon Denier-3
publish the solution to smallDictionary like that we integrate it.


On Dec 7, 2009, at 4:47 PM, Simon Denier wrote:

>
> On 5 déc. 2009, at 17:49, Lukas Renggli wrote:
>
>> SmallDictionary comes from the refactoring engine. It is a highly
>> optimized dictionary originally intended for parse-tree matching. The
>> method #empty does not make sense outside that context.
>>
>> The method #removeAll is implemented in Collection. I don't think that
>> this implementation can ever work in any concrete collection
>> implementation, because it modifies the collection while iterating
>> over it (lint would know that). Most classes override it with
>> something sensible though.
>
> Back from my trip, my neurons are still not 100% functional.
>
> What would be a sensible implementation then?
>
> Most straightforward I can think of:
>
> SmallDictionary>>removeAll
> self initliaze
>
>>
>> Lukas
>>
>> 2009/12/5 Simon Denier <[hidden email]>:
>>> Stupid question: how do I remove all entities from a SmallDictionary
>>>
>>> Let's take:
>>> d := SmallDictionary new.
>>> d add: $d -> 4.
>>> d add: $e -> 5.
>>> d
>>>
>>> If I do
>>> d empty
>>>
>>> then d size = 0 and d do: behaves as if there is nothing
>>> BUT someone can still perform
>>> d at: $d -> 5
>>>
>>> If I do
>>> d removeAll
>>>
>>> I get a MessageNotUnderstood: SmallInteger>>key
>>> because #removeAll inherited from Collection expects a different
>>> structure
>>>
>>> --
>>> Simon
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>
>>
>>
>>
>> --
>> Lukas Renggli
>> http://www.lukas-renggli.ch
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
> --
> Simon
>
>
>
>
> _______________________________________________
> 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