java - A Collection that associates keys to values, and where both a key and a value can be obtained by index -
by indexed mean keys , values can accessed via index representing order in inserted collection.
i need collection behaves map<k, v>
, list<k>
(read-only) , list<v>
(also read-only). naive implementation wrap hashmap<k, v>
, 2 arraylist
, leads massive data redundancy , poor perfomance. thought linkedhashmap<k, v>
, work lot better in case, getbyindex
operations not perform well, because require navigating internal linked nodes, small quantities of data acceptable, i'm not sure how list used client code.
in short, there suits requirements better alternative?
edit: if had pointer arithmetics , low level functions memcpy , runtime sizeof operator resolving sizes of k , v, maybe come efficient implementation. there equivalents of in java?
i can suggest few indirect ways.
- you can create
hashmap < integer,hashmap< k,v > >
. can insert in map keeping order key , can put key-value pair hashmap value. - you can have single
arraylist<k>
,hashmap<k,v>
. each entry map can insert key in array list. - you can use (as have said in question itself)
linkedhashmap
, caniterator
or can usefor each enhanced loop
iteration. way of iterating efficient , each step of iteration entire list not iterated. can iterate , not random indexed entry.
Comments
Post a Comment