Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Consider replacing Vector and Deque with Sequence as a class (not an interface) #45
The differences between
The important question is: is it clear enough when you would use one over the other?
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.