-
Notifications
You must be signed in to change notification settings - Fork 5
2015 003e Vector
John Reppy edited this page Jul 9, 2023
·
2 revisions
structure Vector : VECTORWe propose three new functions for the Vector module.
This page is part of proposal 2015-003.
val toList : 'a vector -> 'a list
val append : 'a vector * 'a -> 'a vector
val prepend : 'a * 'a vector -> 'a vectortoList vec
returns the list of the elements in the vector `vec`.
append (vec, x)
returns the vector formed by adding the element `x` to the end of the vector `vec`. Will raise the `Size` exception if the resulting vector would exceed `maxLen` elements.
prepend (x, vec)
returns the vector formed by adding the element `x` to the beginning of the vector `vec`. Will raise the `Size` exception if the resulting vector would exceed `maxLen` elements.
The toList operation complements the existing fromList and can be implemented more
efficiently than by using List.tabulate. Adding it helps reduce the friction of
converting between the different sequence types.
The append and prepend operations provide a convinent (and slightly more efficient)
way to grow a vector by one element, although they are still O(n) operations.
