Dictionary whose values are dictionaries

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

Dictionary whose values are dictionaries

Stephane Ducasse-3
Hi

I'm looking for an implementation of dictionary whose value is also a dictionary.

Stef
Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

CyrilFerlicot

On sam. 27 mai 2017 at 20:29, Stephane Ducasse <[hidden email]> wrote:
Hi

I'm looking for an implementation of dictionary whose value is also a dictionary.

Stef
Hi!

I don't remember the exact name but I know that an algo at synectique use such a collection. The name is something like Ktree or something like this but I don't have a computer to check this week end.

From my phone
Cyril
--
Cheers
Cyril Ferlicot
Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

philippeback
In reply to this post by Stephane Ducasse-3
Looks like a JsonObject

On Sat, May 27, 2017 at 8:28 PM, Stephane Ducasse <[hidden email]> wrote:
Hi

I'm looking for an implementation of dictionary whose value is also a dictionary.

Stef

Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

CyrilFerlicot
In reply to this post by CyrilFerlicot

On sam. 27 mai 2017 at 20:35, Cyril Ferlicot <[hidden email]> wrote:

On sam. 27 mai 2017 at 20:29, Stephane Ducasse <[hidden email]> wrote:
Hi

I'm looking for an implementation of dictionary whose value is also a dictionary.

Stef
Hi!

I don't remember the exact name but I know that an algo at synectique use such a collection. The name is something like Ktree or something like this but I don't have a computer to check this week end.

From my phone
Cyril
--
Cheers
Cyril Ferlicot


I think the exact name was KeyedTree. 

From my phone
Cyril
--
Cheers
Cyril Ferlicot
Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

Peter Kenny

Stef

 

Cyril is right; there is a class KeyedTree which is a subclass of Dictionary and is in effect a set of nested dictionaries. There was a brief discussion of this in April, initiated by Markus Böhm, who wanted a neat way of looking up entries in nested dictionaries. KeyedTree uses the idea of a path, which is an array of the successive keys needed to locate an entry in an embedded dictionary. Sven also saw this, and has extended NeoJSONObject to provide the same embedding and path lookup. To see Sven’s brief explanation, find the original thread, entitled “ [Pharo-users] Hot to retrieve values from Nested Dictionaries” (note the typo in the original post) starting on 24 April 2017, or see the class comment for NeoJSONObject.

 

Hope this helps.

 

Peter Kenny

 

 

From: Pharo-users [mailto:[hidden email]] On Behalf Of Cyril Ferlicot
Sent: 27 May 2017 19:42
To: Any question about pharo is welcome <[hidden email]>
Subject: Re: [Pharo-users] Dictionary whose values are dictionaries

 

 

On sam. 27 mai 2017 at 20:35, Cyril Ferlicot <[hidden email]> wrote:

 

On sam. 27 mai 2017 at 20:29, Stephane Ducasse <[hidden email]> wrote:

Hi

 

I'm looking for an implementation of dictionary whose value is also a dictionary.

 

Stef

Hi!

 

I don't remember the exact name but I know that an algo at synectique use such a collection. The name is something like Ktree or something like this but I don't have a computer to check this week end.

 

From my phone

Cyril

--

Cheers

Cyril Ferlicot

 

 

I think the exact name was KeyedTree. 

 

From my phone

Cyril

--

Cheers

Cyril Ferlicot

Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

vonbecmann
In reply to this post by Stephane Ducasse-3
hi,
  i'm using a multi-valued dictionary 


in the following way

itemsByKey := MultiValuedDictionary dictionary: IdentityDictionary collection: IdentityDictionary

so i can check the existence of an item by its key (an ordered pair)

(itemsByKey at: anItem key first ifAbsent: nil)
ifNotNil: 
[ :dict | 
(dict at: anItem key second ifAbsent: nil) 
ifNotNil: [ :found | ^ found ] ].


and i add an item like this

itemsByKey 
at: anItem key first 
add: (Association basicNew key: anItem key second value: anItem).

hth

On Sat, May 27, 2017 at 3:28 PM, Stephane Ducasse <[hidden email]> wrote:
Hi

I'm looking for an implementation of dictionary whose value is also a dictionary.

Stef



--
Bernardo E.C.

Sent from a cheap desktop computer in South America.
Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

monty-3
In reply to this post by Stephane Ducasse-3
You could just use a regular Dictionary, but with association keys:
        dict
                at: outerKey -> innerKey
                put: innerValue

Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

Stephane Ducasse-3
In reply to this post by Peter Kenny
Tx peter. It is great to see you around!.
It is on my todo to produce a booklet on Soup and your HTML scrapping tutorial :).
You will see it will be nice.
Stef

On Sat, May 27, 2017 at 10:41 PM, PBKResearch <[hidden email]> wrote:

Stef

 

Cyril is right; there is a class KeyedTree which is a subclass of Dictionary and is in effect a set of nested dictionaries. There was a brief discussion of this in April, initiated by Markus Böhm, who wanted a neat way of looking up entries in nested dictionaries. KeyedTree uses the idea of a path, which is an array of the successive keys needed to locate an entry in an embedded dictionary. Sven also saw this, and has extended NeoJSONObject to provide the same embedding and path lookup. To see Sven’s brief explanation, find the original thread, entitled “ [Pharo-users] Hot to retrieve values from Nested Dictionaries” (note the typo in the original post) starting on 24 April 2017, or see the class comment for NeoJSONObject.

 

Hope this helps.

 

Peter Kenny

 

 

From: Pharo-users [mailto:[hidden email]] On Behalf Of Cyril Ferlicot
Sent: 27 May 2017 19:42
To: Any question about pharo is welcome <[hidden email]>
Subject: Re: [Pharo-users] Dictionary whose values are dictionaries

 

 

On sam. 27 mai 2017 at 20:35, Cyril Ferlicot <[hidden email]> wrote:

 

On sam. 27 mai 2017 at 20:29, Stephane Ducasse <[hidden email]> wrote:

Hi

 

I'm looking for an implementation of dictionary whose value is also a dictionary.

 

Stef

Hi!

 

I don't remember the exact name but I know that an algo at synectique use such a collection. The name is something like Ktree or something like this but I don't have a computer to check this week end.

 

From my phone

Cyril

--

Cheers

Cyril Ferlicot

 

 

I think the exact name was KeyedTree. 

 

From my phone

Cyril

--

Cheers

Cyril Ferlicot


Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

Pharo Smalltalk Users mailing list
In reply to this post by Stephane Ducasse-3
Stephane Ducasse-3 wrote
> Hi
>
> I'm looking for an implementation of dictionary whose value is also a
> dictionary.
>
> Stef

1.  These go only one level down, but I have defined these methods on class
Dictionary.

at: firstKey at: secondKey
        ^ self at: firstKey at: secondKey ifAbsent: [ self errorKeyNotFound ]

at: firstKey at: secondKey ifAbsent: aZeroArgBlock
        | subDictionary |
        subDictionary := self at: firstKey ifAbsent: [ ^ aZeroArgBlock value ].
        ^ subDictionary at: secondKey ifAbsent: [ aZeroArgBlock value ]

at: firstKey at: secondKey ifAbsentPut: aZeroArgBlock
        | subDictionary |
        subDictionary := self at: firstKey ifAbsentPut: [ Dictionary new ].
        ^ subDictionary at: secondKey ifAbsentPut: [ aZeroArgBlock value ]

at: firstKey at: secondKey put: aValue
        | subDictionary |
        subDictionary := self at: firstKey ifAbsentPut: [ Dictionary new ].
        ^ subDictionary at: secondKey put: aValue

2.  I use this class for testing.

MockInstance>>
doesNotUnderstand: aMessage
        "
        Getter: If the value is already there, it is either a branch or a leaf, so
return it.
        Getter: If the value is missing, it is a branch, so add a new instance of
self and return it.
        Setter: It is a leaf, so add the value.

        | r |
        r := self new.
        r one two three: 3.
        r one two three

        (The above should return 3)
        "

        aMessage selector isUnary
                ifTrue: [ ^ self at: aMessage selector ifAbsentPut: [ self class new ] ].
        aMessage selector isKeyword
                ifTrue: [
                        aMessage numArgs = 1
                                ifTrue: [ ^ self at: aMessage selector allButLast put: aMessage
arguments first ] ].
        ^ super doesNotUnderstand: aMessage

at: aSymbol ifAbsentPut: aValue
        ^ self values at: aSymbol ifAbsentPut: aValue

at: aSymbol put: aValue
        self values at: aSymbol put: aValue

values
        ^ values ifNil: [ values := Dictionary new ]





--
View this message in context: http://forum.world.st/Dictionary-whose-values-are-dictionaries-tp4948453p4948484.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

Stan Silver
In reply to this post by Stephane Ducasse-3
Stephane Ducasse-3 wrote
Hi

I'm looking for an implementation of dictionary whose value is also a
dictionary.

Stef
1.  These go only one level down, but I have defined these methods on class Dictionary.

at: firstKey at: secondKey
        ^ self at: firstKey at: secondKey ifAbsent: [ self errorKeyNotFound ]

at: firstKey at: secondKey ifAbsent: aZeroArgBlock
        | subDictionary |
        subDictionary := self at: firstKey ifAbsent: [ ^ aZeroArgBlock value ].
        ^ subDictionary at: secondKey ifAbsent: [ aZeroArgBlock value ]

at: firstKey at: secondKey ifAbsentPut: aZeroArgBlock
        | subDictionary |
        subDictionary := self at: firstKey ifAbsentPut: [ Dictionary new ].
        ^ subDictionary at: secondKey ifAbsentPut: [ aZeroArgBlock value ]

at: firstKey at: secondKey put: aValue
        | subDictionary |
        subDictionary := self at: firstKey ifAbsentPut: [ Dictionary new ].
        ^ subDictionary at: secondKey put: aValue

2.  I use this class for testing.

MockInstance>>
doesNotUnderstand: aMessage
        "
        Getter: If the value is already there, it is either a branch or a leaf, so return it.
        Getter: If the value is missing, it is a branch, so add a new instance of self and return it.
        Setter: It is a leaf, so add the value.

        | r |
        r := self new.
        r one two three: 3.
        r one two three

        (The above should return 3)
        "

        aMessage selector isUnary
                ifTrue: [ ^ self at: aMessage selector ifAbsentPut: [ self class new ] ].
        aMessage selector isKeyword
                ifTrue: [
                        aMessage numArgs = 1
                                ifTrue: [ ^ self at: aMessage selector allButLast put: aMessage arguments first ] ].
        ^ super doesNotUnderstand: aMessage

at: aSymbol ifAbsentPut: aValue
        ^ self values at: aSymbol ifAbsentPut: aValue

at: aSymbol put: aValue
        self values at: aSymbol put: aValue

values
        ^ values ifNil: [ values := Dictionary new ]

Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

Stephane Ducasse-3
In reply to this post by CyrilFerlicot
Thanks cyril I was looking at it. 

On Sat, May 27, 2017 at 8:42 PM, Cyril Ferlicot <[hidden email]> wrote:

On sam. 27 mai 2017 at 20:35, Cyril Ferlicot <[hidden email]> wrote:

On sam. 27 mai 2017 at 20:29, Stephane Ducasse <[hidden email]> wrote:
Hi

I'm looking for an implementation of dictionary whose value is also a dictionary.

Stef
Hi!

I don't remember the exact name but I know that an algo at synectique use such a collection. The name is something like Ktree or something like this but I don't have a computer to check this week end.

From my phone
Cyril
--
Cheers
Cyril Ferlicot


I think the exact name was KeyedTree. 

From my phone
Cyril
--
Cheers
Cyril Ferlicot

Reply | Threaded
Open this post in threaded view
|

Re: Dictionary whose values are dictionaries

Stephane Ducasse-3
In reply to this post by Pharo Smalltalk Users mailing list
Thanks. This is nice. 
I'm thinking that the at:at: could be a nice addition to our Dictionary class. 


On Sun, May 28, 2017 at 4:24 PM, Stan Silver via Pharo-users <[hidden email]> wrote:


---------- Forwarded message ----------
From: Stan Silver <[hidden email]>
To: [hidden email]
Cc: 
Bcc: 
Date: Sun, 28 May 2017 07:24:06 -0700 (PDT)
Subject: Re: Dictionary whose values are dictionaries
Stephane Ducasse-3 wrote
> Hi
>
> I'm looking for an implementation of dictionary whose value is also a
> dictionary.
>
> Stef

1.  These go only one level down, but I have defined these methods on class
Dictionary.

at: firstKey at: secondKey
        ^ self at: firstKey at: secondKey ifAbsent: [ self errorKeyNotFound ]

at: firstKey at: secondKey ifAbsent: aZeroArgBlock
        | subDictionary |
        subDictionary := self at: firstKey ifAbsent: [ ^ aZeroArgBlock value ].
        ^ subDictionary at: secondKey ifAbsent: [ aZeroArgBlock value ]

at: firstKey at: secondKey ifAbsentPut: aZeroArgBlock
        | subDictionary |
        subDictionary := self at: firstKey ifAbsentPut: [ Dictionary new ].
        ^ subDictionary at: secondKey ifAbsentPut: [ aZeroArgBlock value ]

at: firstKey at: secondKey put: aValue
        | subDictionary |
        subDictionary := self at: firstKey ifAbsentPut: [ Dictionary new ].
        ^ subDictionary at: secondKey put: aValue

2.  I use this class for testing.

MockInstance>>
doesNotUnderstand: aMessage
        "
        Getter: If the value is already there, it is either a branch or a leaf, so
return it.
        Getter: If the value is missing, it is a branch, so add a new instance of
self and return it.
        Setter: It is a leaf, so add the value.

        | r |
        r := self new.
        r one two three: 3.
        r one two three

        (The above should return 3)
        "

        aMessage selector isUnary
                ifTrue: [ ^ self at: aMessage selector ifAbsentPut: [ self class new ] ].
        aMessage selector isKeyword
                ifTrue: [
                        aMessage numArgs = 1
                                ifTrue: [ ^ self at: aMessage selector allButLast put: aMessage
arguments first ] ].
        ^ super doesNotUnderstand: aMessage

at: aSymbol ifAbsentPut: aValue
        ^ self values at: aSymbol ifAbsentPut: aValue

at: aSymbol put: aValue
        self values at: aSymbol put: aValue

values
        ^ values ifNil: [ values := Dictionary new ]





--
View this message in context: http://forum.world.st/Dictionary-whose-values-are-dictionaries-tp4948453p4948484.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.