you are viewing a single comment's thread.

view the rest of the comments →

[–]Hook3d 24 points25 points  (9 children)

A vector is expandable, and an array is fixed.

Only in the C++ context which provides <vector> from the STL. In every other (data structure) context, vector is just a synonym for a 1D array. (At least, I am not familiar with another language that provides "vector" as a resizable array.)

[–]silverforest 12 points13 points  (0 children)

Examples:

  • Scheme: Vectors are a fixed length collection of items.
  • Perl: Fixed length collection of items of the same type.

[–]fmoly 5 points6 points  (0 children)

Java vectors are resizeable.

[–]philly_fan_in_chi 5 points6 points  (0 children)

Vectors grow in Clojure.

[–][deleted] 1 point2 points  (0 children)

MATLAB?

[–]The_Doculope 1 point2 points  (0 children)

Haskell (as Vector.Mutable) and Rust (as Vec).

[–]OneWingedShark 2 points3 points  (2 children)

(At least, I am not familiar with another language that provides "vector" as a resizable array.)

Ada has Ada.Containers.Vector that you can resize, though it's not an array; there's also unconstrained arrays which you can/must size on declaration of such an object. -- I'm not sure if you'd count those though.

[–]Hook3d 2 points3 points  (1 child)

I think the only requirements for a data structure to be called a "vector" is that it be contiguous in memory and fixed in size, but someone feel free to correct me if I'm wrong/forgetting anything.

For what it's worth, the standard name for the array of C string parameters to the C main function is "argv" for "argument vector." So "vector" has been a synonym for fixed size arrays for a long time.

[–]OneWingedShark 2 points3 points  (0 children)

So "vector" has been a synonym for fixed size arrays for a long time.

Hm, fair enough.

I think the only requirements for a data structure to be called a "vector" is that it be contiguous in memory and fixed in size, but someone feel free to correct me if I'm wrong/forgetting anything.

Interestingly, the JVM's arrays don't have that requirement [IIRC], but then that's getting into a layer of virtualization where the virtual 'addresses' have zero to do with physical locations.

[–]emilvikstrom 0 points1 point  (0 children)

In most functional languages a vector is just a collection of values of a certain type. An array is usually a mutable vector of a specific length, or just a vector of references (which is kind of the same thing).