Use a TreeMap. A range query can be done using the methods lowerEntry
and higherEntry
, higherKey
and lowerKey
. Find the first key smaller than the left end of the range, the first key bigger than the right one and return everything between them.
What's a good java-friendly in-memory map supporting range queries?
-
24-03-2022 - |
Question
I'm looking for an in-memory map with java-friendly APIs (not necessarily java) that supports range queries. Our design doesn't yet call for it to be distributed.
Any suggestions? Thanks!
La solution
Autres conseils
Depending on how flexible you need things to be and how extensible, etc., you could consider using an in-memory database; that would give you far more capability than you've mentioned here, and is probably only interesting if you think you might have a use for a lot more one day. You would be expending a lot of complexity, and possibly space, for something that would be extremely flexible. But you should be aware that several (free) java databases offer in-memory configurations, including Derby (released with Java).
Is an interval tree maybe what you're looking for?