Dictionary whose values are dictionaries
Hi I'm looking for an implementation of dictionary whose value is also a dictionary. Stef
On sam. 27 mai 2017 at 20:29, Stephane Ducasse <stepharo.self@gmail.com> 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
On sam. 27 mai 2017 at 20:35, Cyril Ferlicot <cyril.ferlicot@gmail.com> wrote:
On sam. 27 mai 2017 at 20:29, Stephane Ducasse <stepharo.self@gmail.com> 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
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:pharo-users-bounces@lists.pharo.org] On Behalf Of Cyril Ferlicot Sent: 27 May 2017 19:42 To: Any question about pharo is welcome <pharo-users@lists.pharo.org> Subject: Re: [Pharo-users] Dictionary whose values are dictionaries On sam. 27 mai 2017 at 20:35, Cyril Ferlicot <cyril.ferlicot@gmail.com <mailto:cyril.ferlicot@gmail.com> > wrote: On sam. 27 mai 2017 at 20:29, Stephane Ducasse <stepharo.self@gmail.com <mailto:stepharo.self@gmail.com> > 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
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 <peter@pbkresearch.co.uk> 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:pharo-users-bounces@lists.pharo.org] *On Behalf Of *Cyril Ferlicot *Sent:* 27 May 2017 19:42 *To:* Any question about pharo is welcome <pharo-users@lists.pharo.org> *Subject:* Re: [Pharo-users] Dictionary whose values are dictionaries
On sam. 27 mai 2017 at 20:35, Cyril Ferlicot <cyril.ferlicot@gmail.com> wrote:
On sam. 27 mai 2017 at 20:29, Stephane Ducasse <stepharo.self@gmail.com> 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
Thanks cyril I was looking at it. On Sat, May 27, 2017 at 8:42 PM, Cyril Ferlicot <cyril.ferlicot@gmail.com> wrote:
On sam. 27 mai 2017 at 20:35, Cyril Ferlicot <cyril.ferlicot@gmail.com> wrote:
On sam. 27 mai 2017 at 20:29, Stephane Ducasse <stepharo.self@gmail.com> 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
hi, i'm using a multi-valued dictionary https://github.com/vonbecmann/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 <stepharo.self@gmail.com> 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.
You could just use a regular Dictionary, but with association keys: dict at: outerKey -> innerKey put: innerValue
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-tp4948453p494... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
participants (7)
-
Bernardo Ezequiel Contreras -
Cyril Ferlicot -
monty -
PBKResearch -
phil@highoctane.be -
Stan Silver -
Stephane Ducasse