Fast immutable vectors in C#
julesjacobs.github.io
julesjacobs.github.io
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...
Would a data structure stored in an array but not supporting the correct interface be a "vector" because the secret implementation is an array?
"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.
If you are not doing math on pointer, it should not matter.
Im not gone explain to you why it work, but see paper [1].
Its not about the clojure vector, but basiclly the same and he explains performance and he it is quite fast for lookup. Adding is also quite fast, both for immutable and the mutable case.
[1] http://infoscience.epfl.ch/record/169879/files/RMTrees.pdf
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.