I am currently working on the Haskell API. The latter provides some functions that currently take a list of lists as input, i.e. [(String,[(String, Double)])] .
For visualization purposes, here is an example of the list of lists mentioned above:
[ ("A", [ ("I1", 1), ("I2", 2), ] ), ("B", [ ("I1", 3), ] ) ]
I have defined some private helper functions. One helper function will look for specific records in this list ( Data.List.find = O(n) ); another will make intersections; and another function converts the list above to the following:
[ ("I1", [ ("A", 1), ("B", 3), ] ), ("I2", [ ("A", 2), ] ) ]
The conversion function uses Data.Map because it offers some functions that simplify the process, such as Data.Map.unionWith and Data.Map.insertWith . Well, since the conversion functions had to be called Data.Map.fromList and Data.Map.toList , I thought it would be nice to have a map map instead of a list of lists from the very beginning. And so I changed my input pattern to fit the card requirements card.
Again, for visualization purposes, here is a list at the top like a map of cards:
Map.fromList [ ("A", Map.fromList [ ("I1", 1), ("I2", 2), ] ), ("B", Map.fromList [ ("I1", 3), ] ) ]
Thanks to this step, my code lost several lines, and thanks to Data.Map.lookup , finding what I want now only requires O(log n) .
However, I am now asking myself, is this really a good solution? Is map card a way to go? Or should the conversion function work with Data.Map.fromList and Data.Map.toList , and the rest should work with a list of lists? Or better yet, is there a data structure that is more suitable for this kind of work?
I look forward to your answers.