Given 2 objects / classes:
- A class for a cargo ship. It has a small set of attributes, say current location, size, number of crew and some other things. Most important, it has an attribute for the id which is unique and the class is hashable.
- A class for a harbor. Again a small list of attributes like location and the unique identifier. This class is hashable as well.
Now you could ask interesting questions like:
- For each cargo ship what is the nearest harbor together with its distance.
- For each harbor give me a list of all cargo ships within a 100 km radius.
- Give me for each cargo ship a list of all harbors visited last year (you probably need some extra info for this question, but this detail we omit for now as it is about the results).
Next let’s assume classes are immutable. All classes are in computer memory too.
Now my question is how to store the results of given questions in memory? Should I for each question only keep the relations between the id’s (which each cargo ship and harbor has) or can I keep the entire classes which should work because they are hashable?
A small example for question 2:
When I only keep id’s it could look like this:
{5235: [735235, 25245, 954646],
3232: [112, 34345, 65354, 45454]}
Or should it be like this:
{(an entire harbor class): [(an entire ship class), (an entire ship class) , (an entire ship class)],
(an entire harbor class): [(an entire ship class), (an entire ship class), (an entire ship class), (an entire ship class)]}
(While writing this I came up with another question, should the unique identifier be an attribute of the class, I mean every question you ask has strictly nothing to do with the identifier)