Java: how to index elements having an appropriate spacing?

Suppose I have several objects with a start value and an end value comparable with some comparator.

What collection can I use to create an index of objects, so given the arbitrary value of V, I can find all the objects where V is between the start and end values?

I'm at a dead end.

+4
source share
2 answers

See http://en.wikipedia.org/wiki/Interval_tree . You should probably ignore the complex construction of the “centered tree” that first appears there, and instead look at the “extended tree” instead, which is the standard way to do this.

+5
source

In some circumstances, a relational database , possibly with a temporal , may be a suitable alternative.

+1
source

Source: https://habr.com/ru/post/1345920/


All Articles