I am currently working with a JavaScript map structure that is sorted based on time, storing object states.
Map(key:time(inMilli), value: {object attributes})
My goal is to efficiently retrieve a collection of all values within a specific start and end time range from the map without having to iterate over the entire map.
//here is my current approach. However, I would like to avoid comparing against the entire map of times
let map = dataService.getTimeData()//returns map of all objects
let updates = getRange(someTime, someTime);
function getRange(start, stop){
let foundValues = [];
//if start is equal to or after end time
if(start >= stop) return [start];
//search the map for values within the given range
for([key,value] of map){
if(key > start && key < stop) foundValues.push(key)
}
return foundValues;
}