I think that these two classes should remain separated. Maybe the documentation should include two well defined usage cases in order to make easier to programmers choose which class to pick .
Hi @rtheunissen , mainly because it's very interesting to keep the advantages of both data structures.
If the programmer knows in advance that the container won't be resized, or that the resize will be done only due to append operations (and NOT prepend ops)... then it should be crystal clear that Vector is the correct choice (over Deque or even over the native PHP "array").
There is no need to justify the Deque existence because it's more flexible than Vector, but maybe the programmers should know at which price. It's a good thing to allow the programmers to exploit this "forgotten" knowledge and optimize their programs.
@castarco I completely agree that it's ideal to keep the advantages of both structures, but I believe that the overhead of having two structures that are practically identical outweighs those benefits.
The minor differences between them are that a Vector is very slightly faster to access and modify at the end of the sequence (but has the same complexity as Deque), and the growth factor is 1.5 vs Deque's 2.0. But a Deque has a significant advantage offering O(1) ops at the front of the sequence. That to me is enough to make Deque the default, thereby making Vector practically redundant.
Keep in mind that this is with the introduction of Tuple (think SplFixedArray but better), which would consume some of the use cases where you might have used Vector. This would be where growth is not expected, or in read-only contexts.
rtheunissen commentedAug 30, 2016
•
edited
The differences between
Deque
andVector
might be considered small enough to consider removingVector
andSequence
, and renameDeque
to Sequence.Advantages of
Deque
:Advantages of
Vector
:Sequence
is also the only interface belowCollection
.The important question is: is it clear enough when you would use one over the other?
The text was updated successfully, but these errors were encountered: