I have lots of instances two classes Children and Animal which have a many-to-many entity relationship.
I want to have a data structure such that given a Children I can get a list of Animal that are mapped to it and vice versa. For any given Animal I can get a list of Children that are mapped to it.
I need this data structure to be concurrent such that it can be accessed by any thread.
So given an example mapping:
Child1 -> Animal1 Child1 -> Animal2 Child1 -> Animal3 Child2 -> Animal2 Child2 -> Animal3 Child3 -> Animal3 Querying for Child1 I wish to get a returned list: [ Animal1, Animal2, Animal2 ].
Querying forAnimal2 I wish to get a returned list: [ Child2, Child3 ].
The only way I could think to do this was using a dictionary and a list for each item in this dictionary (both Animals and Children) but I would then also have to deal with locking an synchronization of the lists which is troublesome.