I'm trying to find the correct data structure for this use case, but apparently do not have the correct terminology for searching.
I have many copies of the following structure:
struct Item {
var start: Int
var end: Int
var type: Int
}
The ranges represented in Item
are non-overlapping and contiguous.
I need to be able to:
- Query which
Item
is present at a givenInt
index - Walk forwards/backwards from the located
Item
The collection of Item
s will be updated regularly, either as a complete re-build or by appending to the end. Mid-collection inserts will likely be rare enough to warrant a rebuild from scratch.
Can anyone please point me to a suitable structure or at perhaps the correct terminology for me to continue researching myself?