Hi Joe,
Joe Gottman said:
Giovanni Azua wrote:
I think that we have a philosophical difference here. You think
that an ArrayDeque should ONLY be used as a queue. I think that it
[snip]
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.
should be usable as a queue, and for whatever other uses a coder
desires, as long as those uses don't make it less efficient when
used as a Queue. Note that an ArrayList can be used as either a
List
or a Queue, even though it is has linear complexity on its get()
method.
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)
As it is currently implemented, ArrayDeque could be given a
constant-complexity get() method.
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.