Pergunta

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!

Foi útil?

Solução

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.

Outras dicas

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?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top