Dictionary of dictionaries 
Author Message
 Dictionary of dictionaries

I am trying to write code for a dictionary of addresses as keys with names
of the occupants as elements, I also want to have the occupant elements as
keys for a dictionary associated with another element.

The trouble I have is in writing the code to allow the elements in the first
to become the keys in the second.

I also want to write a method that will add a new occupant to the first
dictionary with a default value assigned in the second dictionary.

If you can understand what I am after and have any ideas I would be
grateful.



Wed, 18 Jun 1902 08:00:00 GMT  
 Dictionary of dictionaries
Quote:

>I am trying to write code for a dictionary of addresses as keys with names
>of the occupants as elements, I also want to have the occupant elements as
>keys for a dictionary associated with another element.

>The trouble I have is in writing the code to allow the elements in the
first
>to become the keys in the second.

>I also want to write a method that will add a new occupant to the first
>dictionary with a default value assigned in the second dictionary.

>If you can understand what I am after and have any ideas I would be
>grateful.

1) Write a DictionaryOfDictionary class as a subclass of Dictionary.
    Then override the #at:put: method to check the value. If it is an item,
then convert it to a Dictionary and store that instead.
    You can also write additional methods to access the second dictionaries
values as well, e.g., #at:#at:
2) Add some additional methods to the Dictionary class that will do this for
you. Bad practice. Not recommended.
3) Move these manipulations to the "client" method where you just do the
work externally from the Dictionary.
4) Create a new DictionaryOfNamesAndAddressesAndOccupants class as subclass
of Object, and manage the relationships using basic Dictionaries.

BTW, it is not perfectly clear what you are trying to do. Do you really need
two nested Dictionaries?
Or are you thinking about two separate Dictionaries which are coupled in
some way?
If the former, think about (1). If the latter, you'll have to use (3) or (4)



Wed, 18 Jun 1902 08:00:00 GMT  
 Dictionary of dictionaries
Hi Stevo,

The way I'd do it is to create an Occupant class, containing all the
attributes you require to store; then create an Address class, holding all
the address attributes.  Next, associate each Occupant instance with the
appropriate instance of Address.  You can now build your dictionary with any
attribute of the Occupant,(or Address), class as a key and the Occupant, (or
Address), as the value.  You can then access the Address, (or Occupant),
instance via the appropriate accessor.

HTH,
Gary

Quote:

>I am trying to write code for a dictionary of addresses as keys with names
>of the occupants as elements, I also want to have the occupant elements as
>keys for a dictionary associated with another element.

>The trouble I have is in writing the code to allow the elements in the
first
>to become the keys in the second.

>I also want to write a method that will add a new occupant to the first
>dictionary with a default value assigned in the second dictionary.

>If you can understand what I am after and have any ideas I would be
>grateful.



Wed, 18 Jun 1902 08:00:00 GMT  
 Dictionary of dictionaries

Quote:

> I am trying to write code for a dictionary of addresses as keys with names
> of the occupants as elements, I also want to have the occupant elements as
> keys for a dictionary associated with another element.

> The trouble I have is in writing the code to allow the elements in the first
> to become the keys in the second.

> I also want to write a method that will add a new occupant to the first
> dictionary with a default value assigned in the second dictionary.

> If you can understand what I am after and have any ideas I would be
> grateful.

I also agree that it sounds like you're focusing too much on the implementation,
and not enough on the interface:

What do you actually want?
If this datastorage object were a black box, what methods would you want to have
to store and retrieve information?

Once we know the answers to the questions, we can think about ways to implement
them: Dictionaries? arrays? etc.

Just my opinion,
Robb



Wed, 18 Jun 1902 08:00:00 GMT  
 Dictionary of dictionaries

Quote:


> > I am trying to write code for a dictionary of addresses as keys with names
> > of the occupants as elements, I also want to have the occupant elements as
> > keys for a dictionary associated with another element.

> > The trouble I have is in writing the code to allow the elements in the first
> > to become the keys in the second.

> > I also want to write a method that will add a new occupant to the first
> > dictionary with a default value assigned in the second dictionary.

> > If you can understand what I am after and have any ideas I would be
> > grateful.

> I also agree that it sounds like you're focusing too much on the implementation,
> and not enough on the interface:

> What do you actually want?
> If this datastorage object were a black box, what methods would you want to have
> to store and retrieve information?

> Once we know the answers to the questions, we can think about ways to implement
> them: Dictionaries? arrays? etc.

Yes, yes. Please just post the spec. You might be surprised at how many different
solutions the group can come up with and often it serves as a vehicle for us to
learn from one another. I mean... look at how long the "doubling the contents of an
array" went on!

--
Travis Griggs (a.k.a. Lord of the Fries)
Key Technology

Member, Fraven Skreiggs Software Collective
 - C for Sinking
 - Java for Drinking
 - Smalltalk for Thinking
 ...and Power to the Penguin!



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. losrt -dictionary and dictionary sorting...

2. Dictionary to string and back to dictionary??

3. Accessing Dictionary values from within the Dictionary

4. Convert All Files of old Dictionary to New Dictionary (Newbie French...)

5. Pool Dictionary

6. Pool Dictionaries and Array declarations

7. Copying A Dictionary Object

8. best way to refactor dictionary lookup problem

9. Searching dictionaries for large integer values

10. Flipper an Dictionaries

11. Cannot remove entry from Pool Dictionaries

12. Comparing Dictionaries

 

 
Powered by phpBB® Forum Software