How would you solve this problem? (At the beginning it seemed simple, then I found it to be puzzling).
- You have a class called Executor. Suppose you have many instance of it and they do different things upon call of a method do(Argument).
- Argument has 2 different parameters and they are A* pa, B* pb (one of which can be null)
- Now, I want a class Manager that receives Argument istances and forwards them to the appropriate instance of Executor (let's call this method Filter). This is done after, some time before, each Executor called the Manager.subscribe(A* pa, B* pb) method to say to wich one of these is interested. Note that: if pa or (not both) pb are NULL, means ANY (I mean if pa is NULL, only pb is checked). Of course there must not be more than one Executor.
- The implementation must be FAST, the ideal should be a vector, or something close like an hash map... BUT THE COMPARISON HAS TO BE MADE ON THE CONTENTS OF pa and pb, not their value as pointers.
- Finally,it must be possible that subscription can be cancelled by an executor (without waiting too long). Anyway I want that Filter, subscribe and cancelSubscription are very fast.
I've been thinking of many arrangements, with hash maps, lists and multimaps... But all of them lack speed or easyness, or something else. What would you do?