I need an ordered data structure with an O (1) indexOf operation. I store object pointers in a data structure. Any ideas? Some kind of LinkedHashMap?
See what "indexOf" means: List.indexOf(Object)
List.indexOf(Object)
This question is ambiguous to begin with.
indexOf(..)
, - , Object .
Object
HashMap<Object, List<Integer>>
, , , , , .
, SortedMap, TreeMap . log(n) , , ( ).
SortedMap
TreeMap
log(n)
, O (log n) insert indexOf.
insert
indexOf
List<Object> , , HashMap<Object, Integer> , O (1) indexOf O ( n) insert.
List<Object>
HashMap<Object, Integer>
I did not think deeply about this, but I do not think that it is possible to get an O (1) insert and an O (log n) indexOf.
try using PriorityQueue instead to make it ...
Save the object as a key and value in a HashMap. I assume that you want to get the object in the end.