I have parent and child mappings in a relational database as shown below,
relationship_id | parent_id | child_id
1 | 100009 | 600009
2 | 100009 | 600010
3 | 600010 | 100008
to optimize performance, I like to keep all these mappings in memory. Here the child will have more than one parent, and the parent will have more than 2 children. I think I should use the Chart data structure.
Filling in memory is a one-time job. My concern is that when I ask to list all the children (not just the immediate child), he should return them as soon as possible. Adding and removing is rare. What data structure and algorithm should I use?
Tried MultiHashMap to achieve search time O(1), but has more redundancy.
source
share