vector#
- swordfish.vector(data: Any = None, *, type: DataType = None) Vector#
- swordfish.vector(*, type: DataType = None, size: int = 0, capacity: int = 1, default: Any = None) Vector
Creates a Swordfish Vector from a Python object or initializes one with specified type, size, capacity, and default value.
There are two modes of initialization:
If
datais provided, it converts the given Python object into a Vector of the specifiedtype.If
datais not provided, a new Vector is created with the specifiedtype,size,capacity, anddefaultvalue.
- Parameters:
data (Any, optional) – The input data to initialize the Vector. Defaults to None.
type (DataType, optional) – The data type for the Vector. Defaults to None.
size (int, optional) – The number of elements in the Vector (used when
datais None). Defaults to 0.capacity (int, optional) – The initial capacity of the Vector (used when
datais None). Defaults to 1.default (Any, optional) – The value used to fill the Vector (used when
datais None). Defaults to None.
- Returns:
A Swordfish Vector initialized based on the provided arguments.
- Return type:
Examples
- Creating a Vector from existing data:
>>> import swordfish as sf >>> x = sf.vector([1, 2, 3]) >>> x Vector([1,2,3], type=LONG)
- Creating an empty Vector with specific type, size, capacity, and default value:
>>> y = sf.vector(type="INT", size=3, capacity=5, default=0) >>> y Vector([0,0,0], type=INT)