Is there a module that implements an efficient array type in Erlang?
- by dsmith
I have been looking for an array type with the following characteristics in Erlang.
append(vector(), term()) O(1)
nth(Idx, vector()) O(1)
set(Idx, vector(), term()) O(1)
insert(Idx, vector(), term()) O(N)
remove(Idx, vector()) O(N)
I normally use a tuple for this purpose, but the performance characteristics are not what I would want for large N. My testing shows the following performance characteristics...
erlang:append_element/2 O(N).
erlang:setelement/3 O(N).
I have started on a module based on the clojure.lang.PersistentVector implementation, but if it's already been done I won't reinvent the wheel.