Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Why doesn't ArrayDeque implement the List interface?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Giovanni Azua, post: 3815199"] Hi Joe, Well not exactly. I think that any implementation, in this case an ArrayDeque should be used as whatever interface(s) it implements, no more but no less. If you have very specific needs and in very rare cases you could resort to extending the closest match in the Collections API and creating an ad hoc implementation that fits your needs e.g. if you needed something like a "CircularPriorityQueue" then you would extend PriorityQueue (or preferably use the Decorator Pattern) and add the circularity feature. Dequeue main use-case is to manipulate and retrieve elements from the ends and that's O(c) complexity, not linear. If you try using a helicopter as a blender then you are getting into troubles no one could have ever predicted like ending up in a very inefficient usage. I disagree, ArrayList should be only used as what its official contract offers i.e. its implemented interfaces. ArrayList only offers to customers the List and RandomAccess contracts. As you know you are free to leave the contracts and get into slightly hacking arena but then you will be on your own like now. ArrayList does not offer fast search per se, it is not built for that purpose. If you need fast retrieval you should use e.g. - TreeSet O(log N) - TreeMap O(log N) I think this is not possible without implementing the ArrayDeque to internally manipulate a redundant data structure optimized for searching. But then it would not be an ArrayDeque anymore but something else. What I would myself do in this case is: 1) create a new interface e.g. LogNSearchDeque extends Deque and adds a method search(Element anElement) 2) introduce new class LogNSearchArrayDeque that implements #1 and extends ArrayDeque. This implementation could e.g. aggregate and delegate to a redundant collection optimized for search like the ones above or do it yourself using a sorted ArrayList and Collections.binarySearch: [URL]http://java.sun.com/javase/6/docs/api/java/util/Collections.html#binarySearch(java.util.List,%20T,%20java.util.Comparator)[/URL] I checked the deque class in std and it does not offer a fast search get method. I can only see the access "operator[]" and "at" methods where you should provide the position index: [URL]http://www.cplusplus.com/reference/stl/deque/[/URL] [URL]http://www.cplusplus.com/reference/stl/deque/at.html[/URL] Since ArrayDeque lacks a get(i) you can easily do: Deque<String> myDeque = new ArrayDeque<String>(); // ... insert elements // get the i-th element int i = 3; String myThirdElement = myDeque.toArray(new String[0])[i]; HTH, Best regards, Giovanni[/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Why doesn't ArrayDeque implement the List interface?
Top