119 points · by luu · 12y ago · 24 comments
Kind of: Set returns a new Vector with a changed state (the specified element overwritten).
But yes, this implement is very sparse: there's no way to add and remove elements in the middle, no way to even tell how many elements are in the list: https://news.ycombinator.com/item?id=8592178
Perhaps omitting them hides some different optimisation choices (i.e. they would be more expensive)
Maybe it's just a proof of concept?
If Lookup and Set take an index (int i), and you can't tell how many items there are in the vector, what happens when you specify an index way past the end to one of those?
That would be great.
If you want a blackbox object that has Lookup(), Add() and Set() but with no guarantees about the underlying algorithm, you should probably avoid calling it a vector...
"Vector" here is an interface.
The equivalent, e.g. "interface ILinkedListVector" is considered bad practice, i.e. you do want an interface to be a back box and not leak implementation details. if it has the right operations, "Vector" (actually more like "IVector<T>") is an acceptable interface name.
Would a data structure stored in an array but not supporting the correct interface be a "vector" because the secret implementation is an array?
If you are not doing math on pointer, it should not matter.
The opinion that vector must equal array is presumably because people have used mutable vectors in e.g Java or C++ and assumed the underlying data structure is the same in other contexts.
A mutable List is very natural to implement array based, but an immutable List is usually not. It's the same thing.