Reputation: 329
I was wondering whether is there a data structure that offers constant effort (O(1)) for both insertion/removal from/to both ends, as for example a LinkedList offers, and retrieval from a random index, as for example a HashMap offers.
Or maybe if I can achieve something similar somehow with a combination of data structures.
Upvotes: 3
Views: 379
Reputation: 807
A hashmap is the fastest data structure i think
remove: O(1) size: O(1) values: O(n) (on traversal through iterator)
Upvotes: 1
Reputation: 200206
It seems like ArrayDeque
fits all your requirements. Quoting its Javadoc:
Most ArrayDeque operations run in amortized constant time.
Upvotes: 3