Is there a data structure for this type of list/map?

Posted by Nick on Programmers See other posts from Programmers or by Nick
Published on 2013-10-03T19:08:07Z Indexed on 2014/06/01 3:49 UTC
Read the original article Hit count: 182

Filed under:
|

Perhaps there's a name for what I want, but I'm not aware of it. I need something similar to a LinkedHashMap in Java, but where it returns the 'previous' value if there's no value at the specified key.

That is, I have a list of objects stored by an integer key (which is in units of time in my case):

; key->value
10->A
15->B
20->C

So, if I were to query for a value for key 0-9, it would return null. The special part is if I queried for something 10 <= i <= 14 it would return A. Or, for i >= 20, it would return C.

Is there a data structure for this?

© Programmers or respective owner

Related posts about java

Related posts about data-structures