0

I have a set of events - let's say [event1, event2, .., eventN] and set of event handlers [handler1, handler2, .., handlerK] and each handler could be assigned to several events. For example - Handler6 assigned to Event1, Event2, Event5

But my tipycal request is opposite - I need all handlers for selected event.

Is there any kind of data structure which could store this data correspondence in memory and retrieve data effectively (not worse than O(log(n)))

silent_coder
  • 6,222
  • 14
  • 47
  • 91
  • You might reduce the original mapping to a Stream of tuples, and then recollect them to create the inverted map, using the technique described at http://stackoverflow.com/questions/33086686/java-8-stream-collect-and-group-by-objects-that-map-to-multiple-keys – Hank D Apr 29 '16 at 16:50

1 Answers1

0

I think what you have to do is something like a many to many relationship. Each event will have a list of handlers and for each handlers a list of events.

You can also try to use Do we have a MultiBiMap ? or MultiKeyMap from Apache Guava https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/map/MultiKeyMap.html

Community
  • 1
  • 1
Jaumzera
  • 2,305
  • 1
  • 30
  • 44