SPVM::Array(3)

πŸ“¦ version 0.990125, in alpine 3.24

πŸ’– NAME πŸ’–

SPVM::Array β€” Array Utilities

ok so this is a page from User Contributed Perl Documentation (that's the manual name right there, bestie, consider it folded in πŸŽ€), and it's all about SPVM::Array, the module that hands you a whole lil toolkit for messing with arrays. Slay.


✨ USAGE ✨

Bestie, just use Array; and you're in. Here's the whole vibe menu, verbatim, no cap:

use Array;

# Copy a byte array
{
  my $array = [(byte)1, 2, 3];
  my $array_copy = Array->copy_byte($array);
}

# Copy a short array
{
  my $array = [(short)1, 2, 3];
  my $array_copy = Array->copy_short($array);
}

# Copy a int array
{
  my $array = [1, 2, 3];
  my $array_copy = Array->copy_int($array);
}

# Copy a long array
{
  my $array = [(long)1, 2, 3];
  my $array_copy = Array->copy_long($array);
}

# Copy a float array
{
  my $array = [1.5f, 2.5f, 3.5f];
  my $array_copy = Array->copy_float($array);
}

# Copy a double array
{
  my $array = [1.5, 2.5, 3.5];
  my $array_copy = Array->copy_double($array);
}

# Copy a string array
{
  my $array = ["abc", "def", "ghi"]
  my $array_copy = Array->copy_string($array);
}

# Check if the two byte arrays equal
{
  my $array1 = [(byte)1, 2];
  my $array2 = [(byte)1, 2];
  my $ret = Array->equals_byte($array1, $array2);
}

# Check if the two short arrays equal
{
  my $array1 = [(short)1, 2];
  my $array2 = [(short)1, 2];
  my $ret = Array->equals_short($array1, $array2);
}

# Check if the two int arrays equal
{
  my $array1 = [(int)1, 2];
  my $array2 = [(int)1, 2];
  my $ret = Array->equals_int($array1, $array2);
}

# Check if the two long arrays equal
{
  my $array1 = [(long)1, 2];
  my $array2 = [(long)1, 2];
  my $ret = Array->equals_long($array1, $array2);
}

# Check if the two float arrays equal
{
  my $array1 = [(float)1, 2];
  my $array2 = [(float)1, 2];
  my $ret = Array->equals_float($array1, $array2);
}

# Check if the two double arrays equal
{
  my $array1 = [(double)1, 2];
  my $array2 = [(double)1, 2];
  my $ret = Array->equals_double($array1, $array2);
}

# Check if the two string arrays equal
{
  my $array1 = ["abc", "def"];
  my $array2 = ["abc", "def"];
  my $ret = Array->equals_string($array1, $array2);
}

# Copy object array
my $array = [(object)Int->new(1), Int->new(2), Int->new(3)];
my $array_copy = Array->copy_object($array, method : object ($obj : object) {
  my $int_obj = (Int)$obj;
  my $new_int_obj = Int->new($int_obj->value);
  return $new_int_obj;
});

(Yes, the <pink>string</pink> copy block up there is missing a semicolon before the next line β€” that's literally how it is in the original, I'm not touching it πŸ™ˆ. Also peep the equals_short, equals_int, equals_long, equals_double and equals_string calls β€” those methods live in the later parts of this page, ok? We're on part 1. Patience, bestie πŸ’…)


🌸 DESCRIPTION 🌸

"Array" provides array utilities. That's it, that's the whole description. Short and iconic.


πŸ‘‘ CLASS METHODS πŸ‘‘

All of these are static methods, so you call 'em on the class itself like Array->whatever(...). Let's go, one by one πŸ¦‹


copy_byte

static method copy_byte : byte[] ($array : byte[], $offset : int = 0, $length : int = -1);

Makes a brand-new "byte" array sized $length, and copies the elements from $offset up to the position proceeded by $length into that fresh baby array.

If $length is less than 0, then it's the length of $array minus $offset. (So you get everything from $offset to the end. Convenient ✨)

Exceptions:

  • $array must be defined. Otherwise an exception is thrown. 😭
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

copy_double

static method copy_double : double[] ($array : double[], $offset : int = 0, $length : int = -1);

Makes a new "double" array with $length, and copies the elements from $offset to the position proceeded by $length into the created array. Same drill as its byte sibling, just double-flavoured πŸ’œ

If $length is less than 0, it is the length of $array minus $offset.

If the array is not defined, return undef.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown. (Yeah, this one says both "return undef" and "an exception is thrown" for the undefined case β€” I'm just the messenger, don't come for me πŸ’€)
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

copy_float

static method copy_float : float[] ($array : float[], $offset : int = 0, $length : int = -1);

Creates a new "float" array with $length, copies elements from $offset to the position proceeded by $length over into it. Float gang rise 🌈

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

copy_int

static method copy_int : int[] ($array : int[], $offset : int = 0, $length : int = -1);

New "int" array of size $length, elements from $offset to the position proceeded by $length get copied in. The classic, the main character of arrays tbh πŸ‘‘

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

copy_long

static method copy_long : long[] ($array : long[], $offset : int = 0, $length : int = -1);

Builds a new "long" array with $length and copies the elements from $offset to the position proceeded by $length into the created array. Big numbers, big energy πŸ”₯

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

copy_object

static method copy_object : object[] ($array : object[], $cloner : Cloner = undef, $offset : int = 0, $legnth : int = -1);

(Yes bestie, it really does say $legnth in the signature. Typo's canon now πŸ’€)

Creates a new object array with $length, and clones the elements of the object array from $offset to the position proceeded by $length into the created array.

Each element is cloned by Cloner.

If the cloner is not defined, the address of each element is copied. (so like, shallow. same objects, new array. iykyk)

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

copy_object_address

static method copy_object_address : object[] ($array : object[], $offset : int = 0, $legnth : int = -1);

This one's just an alias for the following code using "copy_object":

my $ret = &copy_object($array, undef, $offset, $length);

(Another $legnth in the signature, another $length in the body. We don't ask questions, we just copy the addresses 🫢)


copy_short

static method copy_short : short[] ($array : short[], $offset : int = 0, $length : int = -1);

Creates a new "short" array with $length, and copies the elements from $offset to the position proceeded by $length into the created array. Smol ints, huge heart πŸ“

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

copy_string

static method copy_string : string[] ($array : string[], $offset : int = 0, $length : int = -1);

Makes a new "string" array with $length, and copies the elements of the "string" array using the "copy" operator, from $offset to the position proceeded by $length, into the created array. Actual deep-ish string copying, we love to see it ✨

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

copy_string_address

static method copy_string_address : string[] ($array : string[], $offset : int = 0, $length : int = -1);

Creates a new "string" array with $length, and copies the addresses of the elements of the "string" array from $offset to the position proceeded by $length into the created array.

So like, copy_string copies the strings, this one copies the addresses. Different vibe, both valid πŸ’…

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

dump_unsigned_byte

static method dump_unsigned_byte : string ($array : byte[]);

Same as the following code using the dump operator operator, except the elements are displayed as unsigned 8-bit integer:

my $ret = dump $array;

dump_unsigned_int

static method dump_unsigned_int : string ($array : int[]);

Same as the following code using the dump operator operator, but the elements are displayed as unsigned 32-bit integer:

my $ret = dump $array;

dump_unsigned_long

static method dump_unsigned_long : string ($array : long[]);

Same as the following code using the dump operator operator, but the elements are displayed as unsigned 64-bit integer:

my $ret = dump $array;

dump_unsigned_short

static method dump_unsigned_short : string ($array : short[]);

Same as the following code using the dump operator operator, but the elements are displayed as unsigned 16-bit integer:

my $ret = dump $array;

equals_byte

static method equals_byte : int ($array1 : byte[], $array2 : byte[]);

The equality vibe check, byte edition. Here's exactly how it decides:

  • If $array1 is not defined and $array2 is not defined, returns 1.
  • If $array1 is defined and $array2 is not defined, returns 0.
  • If $array1 is not defined, $array2 is defined, returns 0.
  • If $array1 is defined and $array2 is defined and the all elements of $array1 are equal to all elements of $array2, returns 1.
  • Otherwise return 0.

equals_double

static method equals_double : int ($array1 : double[], $array2 : double[]);

Same rules, double flavour:

  • If $array1 is not defined and $array2 is not defined, returns 1.
  • If $array1 is defined and $array2 is not defined, returns 0.
  • If $array1 is not defined, $array2 is defined, returns 0.
  • If $array1 is defined and $array2 is defined and the all elements of $array1 are equal to all elements of $array2, returns 1.
  • Otherwise return 0.

equals_float

static method equals_float : int ($array1 : float[], $array2 : float[]);

Same rules again, float flavoured:

  • If $array1 is not defined and $array2 is not defined, returns 1.
  • If $array1 is defined and $array2 is not defined, returns 0.
  • If $array1 is not defined, $array2 is defined, returns 0.
  • If $array1 is defined and $array2 is defined and the all elements of $array1 are equal to all elements of $array2, returns 1.
  • Otherwise return 0.

and that's where part 1 wraps β€” there's more coming, so don't go anywhere 🧚

equals_int ✨

static method equals_int : int ($array1 : int[], $array2 : int[]);

Bestie, this is your "are these two int arrays literally the same array" vibe check. It returns 1 or 0, and the rules go like this:

  • If $array1 is not defined and $array2 is not defined β†’ returns 1 (both nothing? iconic, they match πŸ’…).
  • If $array1 is defined and $array2 is not defined β†’ returns 0.
  • If $array1 is not defined and $array2 is defined β†’ returns 0.
  • If $array1 is defined and $array2 is defined and all elements of $array1 are equal to all elements of $array2 β†’ returns 1.
  • Otherwise β†’ return 0.

equals_long ✨

static method equals_long : int ($array1 : long[], $array2 : long[]);

Same energy as equals_int but for long. The whole rundown, one more time, because consistency ate:

  • If $array1 is not defined and $array2 is not defined β†’ returns 1.
  • If $array1 is defined and $array2 is not defined β†’ returns 0.
  • If $array1 is not defined and $array2 is defined β†’ returns 0.
  • If $array1 is defined and $array2 is defined and all elements of $array1 are equal to all elements of $array2 β†’ returns 1.
  • Otherwise β†’ return 0.

equals_object ✨

static method static method equals_object : int ($array1 : object[], $array2 : object[], $equality_checker : EqualityChecker);

(Yes, the doubled static method static method is exactly what's written up there β€” do not come for me, I'm just the messenger 🫢)

So this one compares two object[] arrays, but you get to bring your own judge:

  • If $array1 is not defined and $array2 is not defined β†’ returns 1.
  • If $array1 is defined and $array2 is not defined β†’ returns 0.
  • If $array1 is not defined and $array2 is defined β†’ returns 0.
  • If $array1 is defined and $array2 is defined and all elements of $array1 are equal to all elements of $array2 using the equality checker β†’ returns 1.
If the equality checker is not defined, the address is used to check the equality. (aka we're comparing vibes by memory location, not by contents β€” know the difference, bestie 😭)
  • Otherwise β†’ return 0.

equals_object_address ✨

static method equals_object_address : int ($array1 : object[], $array2 : object[]);

A lil alias, no cap. It's shorthand for this exact code using equals_object:

my $ret = &equals_object($array1, $array2, undef);

equals_short ✨

static method equals_short : int ($array1 : short[], $array2 : short[]);

short arrays, same drill, still slaying:

  • If $array1 is not defined and $array2 is not defined β†’ returns 1.
  • If $array1 is defined and $array2 is not defined β†’ returns 0.
  • If $array1 is not defined and $array2 is defined β†’ returns 0.
  • If $array1 is defined and $array2 is defined and all elements of $array1 are equal to all elements of $array2 β†’ returns 1.
  • Otherwise β†’ return 0.

equals_string ✨

static method equals_string : int ($array1 : string[], $array2 : string[]);

Two string[] arrays walk into a comparison… and this time the elements are compared using the eq operator (string comparison, not address, we're classy πŸ’…):

  • If $array1 is not defined and $array2 is not defined β†’ returns 1.
  • If $array1 is defined and $array2 is not defined β†’ returns 0.
  • If $array1 is not defined and $array2 is defined β†’ returns 0.
  • If $array1 is defined and $array2 is defined and all elements of $array1 are equal to all elements of $array2 using the "eq" operator β†’ returns 1.
  • Otherwise β†’ return 0.

equals_string_address ✨

static method equals_string_address : int ($array1 : string[], $array2 : string[]);

Another alias bestie β€” this is shorthand for the following code using equals_object_address:

my $ret = &equals_object_address($array1, $array2);

πŸŽ€ memcpy era πŸŽ€

Heads up before we dive in: for every single one of these copy functions, if the range of the elements of $source array and the range of the elements of $dest array overlap, the result is not guaranteed. Overlapping copies are giving undefined behaviour, and we do not do that here. 🚩

memcpy_byte 🌈

static method memcpy_byte : void ($dest : byte[], $dest_offset : int, $source : byte[], $source_offset : int, $length : int);

Copy the range of the elements of $source byte array into the range of the elements of $dest byte array.

  • The range of the elements of $source array is from $offset to the position proceeded by $length of the source.
  • The range of the elements of $dest array is from $dest_offset to $dest_offset + $length.
  • If those two ranges overlap β†’ result not guaranteed, periodt.

Exceptions (aka the ways this will yell at you 😭):

  • $dest must be defined. Otherwise an exception is thrown.
  • $source must be defined. Otherwise an exception is thrown.
  • $length must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $source_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset + $length must be less than or equal to the length of $dest. Otherwise an exception is thrown.
  • $source_offset + $length must be less than or equal to the length of $source. Otherwise an exception is thrown.

memcpy_double 🌈

static method memcpy_double : void ($dest : double[], $dest_offset : int, $source : double[], $source_offset : int, $length : int);

Copy the range of the elements of $source double array into the range of the elements of $dest double array.

  • The range of the elements of $source array is from $offset to the position proceeded by $length of the source.
  • The range of the elements of $dest array is from $dest_offset to $dest_offset + $length.
  • Overlapping ranges? Not guaranteed. Don't test it. πŸ™ˆ

Exceptions:

  • $dest must be defined. Otherwise an exception is thrown.
  • $source must be defined. Otherwise an exception is thrown.
  • $length must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $source_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset + $length must be less than or equal to the length of $dest. Otherwise an exception is thrown.
  • $source_offset + $length must be less than or equal to the length of $source. Otherwise an exception is thrown.

memcpy_float 🌈

static method memcpy_float : void ($dest : float[], $dest_offset : int, $source : float[], $source_offset : int, $length : int);

Copy the range of the elements of $source float array into the range of the elements of $dest float array.

  • The range of the elements of $source array is from $offset to the position proceeded by $length of the source.
  • The range of the elements of $dest array is from $dest_offset to $dest_offset + $length.
  • Overlap of those ranges β†’ result is not guaranteed, so keep them separated bestie πŸ’€

Exceptions:

  • $dest must be defined. Otherwise an exception is thrown.
  • $source must be defined. Otherwise an exception is thrown.
  • $length must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $source_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset + $length must be less than or equal to the length of $dest. Otherwise an exception is thrown.
  • $source_offset + $length must be less than or equal to the length of $source. Otherwise an exception is thrown.

memcpy_int 🌈

static method memcpy_int : void ($dest : int[], $dest_offset : int, $source : int[], $source_offset : int, $length : int);

Copy the range of the elements of $source int array into the range of the elements of $dest int array. The classic, the icon, the main character of copying.

  • The range of the elements of $source array is from $offset to the position proceeded by $length of the source.
  • The range of the elements of $dest array is from $dest_offset to $dest_offset + $length.
  • If the two ranges overlap, the result is not guaranteed. Not me warning you twice πŸ”₯

Exceptions:

  • $dest must be defined. Otherwise an exception is thrown.
  • $source must be defined. Otherwise an exception is thrown.
  • $length must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $source_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset + $length must be less than or equal to the length of $dest. Otherwise an exception is thrown.
  • $source_offset + $length must be less than or equal to the length of $source. Otherwise an exception is thrown.

memcpy_long 🌈

static method memcpy_long : void ($dest : long[], $dest_offset : int, $source : long[], $source_offset : int, $length : int);

Copy the range of the elements of $source long array into the range of the elements of $dest long array. Big numbers, same procedure.

  • The range of the elements of $source array is from $offset to the position proceeded by $length of the source.
  • The range of the elements of $dest array is from $dest_offset to $dest_offset + $length.
  • Overlapping ranges β†’ result not guaranteed, iykyk πŸ¦‹

Exceptions:

  • $dest must be defined. Otherwise an exception is thrown.
  • $source must be defined. Otherwise an exception is thrown.
  • $length must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $source_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset + $length must be less than or equal to the length of $dest. Otherwise an exception is thrown.
  • $source_offset + $length must be less than or equal to the length of $source. Otherwise an exception is thrown.

memcpy_object_address 🌈

static method memcpy_object_address : void ($dest : object[], $dest_offset : int, $source : object[], $source_offset : int, $length : int);

Copy the range of the elements of $source object array into the range of the elements of $dest object array. And here's the tea: each address is copied β€” we're moving pointers around, not deep-copying whole objects, okay? πŸ’…

  • The range of the elements of $source array is from $offset to the position proceeded by $length of the source.
  • The range of the elements of $dest array is from $dest_offset to $dest_offset + $length.
  • If the range of the elements of $source array and the range of the elements of $dest array overlap, the result is not guaranteed. πŸ™…

Exceptions:

  • $dest must be defined. Otherwise an exception is thrown.
  • $source must be defined. Otherwise an exception is thrown.
  • $length must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $source_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset + $length must be less than or equal to the length of $dest. Otherwise an exception is thrown.
  • $source_offset + $length must be less than or equal to the length of $source. Otherwise an exception is thrown.

memcpy_short 🌈

static method memcpy_short : void ($dest : short[], $dest_offset : int, $source : short[], $source_offset : int, $length : int);

Copy the range of the elements of $source short array into the range of the elements of $dest short array.

  • The range of the elements of $source array is from $offset to the position proceeded by $length of the source.
  • The range of the elements of $dest array is from $dest_offset to $dest_offset + $length.
  • If the range of the elements of $source array and the range of the elements of $dest array overlap, the result is not guaranteed. (Overlap is cancelled, sorry babe 🫢)

Exceptions:

Exceptions are lowkey strict here β€” she will throw if you break these, so pay attention bestie 😀:

  • $dest must be defined. Otherwise an exception is thrown.
  • $source must be defined. Otherwise an exception is thrown.
  • $length must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $source_offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $dest_offset + $length must be less than or equal to the length of $dest. Otherwise an exception is thrown.
  • $source_offset + $length must be less than or equal to the length of $source. Otherwise an exception is thrown.

memcpy_string_address</p>

static method memcpy_string_address : void ($dest : string[], $dest_offset : int, $source : string[], $source_offset : int, $length : int);

The alias for memcpy_object_address. That's it, that's the whole vibe πŸ’….


memmove_byte</p>

static method memmove_byte : void ($dest : byte[], $dest_offset : int, $source : byte[], $source_offset : int, $length : int);

The same as memcpy_byte, but even if the range of the source and the range of the destination overlap, the result is guaranteed. So like, overlapping is fine here, no cap 🫢.


memmove_double</p>

static method memmove_double : void ($dest : double[], $dest_offset : int, $source : double[], $source_offset : int, $length : int);

The same as memcpy_double, but even if the range of the source and the range of the destination overlap, the result is guaranteed. Overlap? She ate and left no crumbs ✨.


memmove_float</p>

static method memmove_float : void ($dest : float[], $dest_offset : int, $source : float[], $source_offset : int, $length : int);

The same as memcpy_float, but even if the range of the source and the range of the destination overlap, the result is guaranteed. Overlapping ranges could never πŸ’….


memmove_int</p>

static method memmove_int : void ($dest : int[], $dest_offset : int, $source : int[], $source_offset : int, $length : int);

The same as memcpy_int, but even if the range of the source and the range of the destination overlap, the result is guaranteed. Yes bestie, even then πŸ¦‹.


memmove_long</p>

static method memmove_long : void ($dest : long[], $dest_offset : int, $source : long[], $source_offset : int, $length : int);

The same as memcpy_long, but even if the range of the source and the range of the destination overlap, the result is guaranteed. Overlap handled, periodt 🌸.


memmove_object_address</p>

static method memmove_object_address : void ($dest : object[], $dest_offset : int, $source : object[], $source_offset : int, $length : int);

The same as memcpy_object_address, but even if the range of the source and the range of the destination overlap, the result is guaranteed. She's giving safe-overlap main character energy πŸ‘‘.


memmove_short</p>

static method memmove_short : void ($dest : short[], $dest_offset : int, $source : short[], $source_offset : int, $length : int);

The same as memcpy_short, but even if the range of the source and the range of the destination overlap, the result is guaranteed. No accidental self-destruction here, ngl πŸ’€.


memmove_string_address</p>

static method memmove_string_address : void ($dest : string[], $dest_offset : int, $source : string[], $source_offset : int, $length : int);

The same as the following code using memmove_object_address:

&memmove_object_address($dest, $dest_offset, $source, $source_offset, $length);

memset_byte</p>

static method memset_byte : void ($array : byte[], $element : int, $offset : int = 0, $length : int = -1);

Set the range of the elements of the byte array to $element. πŸ“

The range of the elements of $array is from $offset to the position proceeded by $length.

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

memset_double</p>

static method memset_double : void ($array : double[], $element : double, $offset : int = 0, $length : int = -1);

Set the range of the elements of the double array to $element. πŸ’–

The range of the elements of $array is from $offset to the position proceeded by $length.

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

memset_float</p>

static method memset_float : void ($array : float[], $element : float, $offset : int = 0, $length : int = -1);

Set the range of the elements of the float array to $element. 🧚

The range of the elements of $array is from $offset to the position proceeded by $length.

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

memset_int</p>

static method memset_int : void ($array : int[], $element : int, $offset : int = 0, $length : int = -1);

Set the range of the elements of the int array to $element. ⭐

The range of the elements of $array is from $offset to the position proceeded by $length.

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

memset_long</p>

static method memset_long : void ($array : long[], $element : long, $offset : int = 0, $length : int = -1);

Set the range of the elements of the long array to $element. 🌈

The range of the elements of $array is from $offset to the position proceeded by $length.

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

memset_object</p>

static method memset_object : void ($array : object[], $element : object, $offset : int = 0, $length : int = -1);

Set the range of the elements of the object $array to $element. πŸ”₯

The range of the elements of $array is from $offset to the position proceeded by $length.

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

memset_short</p>

static method memset_short : void ($array : short[], $element : int, $offset : int = 0, $length : int = -1);

Set the range of the elements of the short $array to $element. πŸŽ€

The range of the elements of $array is from $offset to the position proceeded by $length.

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

memset_string</p>

static method memset_string : void ($array : string[], $element : string, $offset : int = 0, $length : int = -1);

The alias for the following code using memset_object:

&memset_object($dest, $element, $dest_offset, $length);

merge_byte</p>

static method merge_byte : byte[] ($array1 : byte[], $array2 : byte[]);

Creates a new array by merging the array $array1 and the array $array2, and returns it. It's giving combined-array realness ✨.

Exceptions:

  • $array1 must be defined. Otherwise an exception is thrown.
  • $array2 must be defined. Otherwise an exception is thrown.

merge_short</p>

static method merge_short : short[] ($array1 : short[], $array2 : short[]);

Creates a new array by merging the array $array1 and the array $array2, and returns it. Two arrays walk in, one iconic new array walks out πŸ’….

Exceptions:

  • $array1 must be defined. Otherwise an exception is thrown.
  • $array2 must be defined. Otherwise an exception is thrown.

merge_int</p>

static method merge_int : int[] ($array1 : int[], $array2 : int[]);

Creates a new array by merging the array $array1 and the array $array2, and returns it. Merged and returned, fr fr 🫢.

Exceptions:

  • $array1 must be defined. Otherwise an exception is thrown.
  • $array2 must be defined. Otherwise an exception is thrown.

merge_long</p>

static method merge_long : long[] ($array1 : long[], $array2 : long[]);

Creates a new array by merging the array $array1 and the array $array2, and returns it. She merged, she returned, she slayed πŸ‘‘.

Exceptions:

  • $array1 must be defined. Otherwise an exception is thrown.
  • $array2 must be defined. Otherwise an exception is thrown.

merge_float</p>

static method merge_float : float[] ($array1 : float[], $array2 : float[]);

Creates a new array by merging the array $array1 and the array $array2, and returns it. New array just dropped 🌸.

Exceptions:

  • $array1 must be defined. Otherwise an exception is thrown.
  • $array2 must be defined. Otherwise an exception is thrown.

merge_double</p>

static method merge_double : double[] ($array1 : double[], $array2 : double[]);

Creates a new array by merging the array $array1 and the array $array2, and returns it. Merging is her whole personality here πŸ’–.

Exceptions:

  • $array1 must be defined. Otherwise an exception is thrown.
  • $array2 must be defined. Otherwise an exception is thrown.

merge_string</p>

static method merge_string : string[] ($array1 : string[], $array2 : string[]);

Creates a new array by merging the array $array1 and the array $array2, and returns it. Strings combined, no notes πŸŽ€.

Exceptions:

  • $array1 must be defined. Otherwise an exception is thrown.
  • $array2 must be defined. Otherwise an exception is thrown.

merge_object</p>

static method merge_object : object[] ($array1 : object[], $array2 : object[]);

Creates a new array by merging the array $array1 and the array $array2, and returns it. Objects assembled, result returned, iconic behaviour πŸ”₯.

Exceptions:

  • $array1 must be defined. Otherwise an exception is thrown.
  • $array2 must be defined. Otherwise an exception is thrown.

new_proto</p>

static method new_proto : object[] ($proto_array : object[], $length : int);

Create a new object array as the same type as $proto_array with $length. Same type, new length, new array β€” it's giving prototype energy πŸ¦‹.

Exceptions:

  • $prototype array must be defined. Otherwise an exception is thrown.
  • $length must be greater than or equal to 0. Otherwise an exception is thrown.

new_proto_any</p>

static method new_proto_any : object ($proto_array : object, $length : int);

Same as the new_proto method, except you can hand it $proto_array of the numeric-array or multi-numeric-array type, and the return type comes back different. Slay. πŸ’…

πŸŒ€ shuffle_object

"static method shuffle_object : void ($array : object[], $seed_ref : int*);"

Shuffles the array $array in place, given the reference to a seed $seed_ref. Iconic, chaotic, randomized, exactly what you want. 🎲

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.

πŸ” repeat_string

"static method repeat_string : string[] ($strings : string[], $count : int);"

Makes a brand-new array that repeats the string $strings $count times, and returns it. It's giving "copy-paste but make it classy". ✨

Exceptions:

  • $strings must be defined. Otherwise an exception is thrown.
  • $count must be greater than or equal to 0. Otherwise an exception is thrown.

🫢 copy_object_with_proto

"static method copy_object_with_proto : object[] ($array : object[], $proto : object[], $cloner : Cloner = undef, $offset : int = 0, $length : int = -1);"

The same as "copy_object", but you can pass in the prototype array $proto for the copied array. Bestie behavior fr fr. πŸ’–

🫢 copy_object_address_with_proto

"static method copy_object_address_with_proto : object[] ($array : object[], $proto : object[], $offset : int = 0, $length : int = -1);"

The same as "copy_object_address", but you can pass in the prototype array $proto for the copied array. Yes, it's the address-flavored twin, and yes, she ate. πŸ”₯


πŸ¦‹ to_object_array_byte

"static method to_object_array_byte : Byte[] ($array : byte[]);"

Creates a new Byte array with the same length as the byte array $array, copies the elements in $array into it, and returns it. Glow-up transformation, no cap. 🧚

Exceptions:

  • The array $array must be defined. Otherwise, an exception is thrown.

πŸ¦‹ to_object_array_short

"static method to_object_array_short : Short[] ($array : short[]);"

Creates a new Short array with the same length as the short array $array, copies the elements in $array into it, and returns it. Same energy, different width. πŸ’œ

Exceptions:

  • The array $array must be defined. Otherwise, an exception is thrown.

πŸ¦‹ to_object_array_int

"static method to_object_array_int : Int[] ($array : int[]);"

Creates a new Int array with the same length as the int array $array, copies the elements in $array into it, and returns it. Main character conversion arc. πŸ‘‘

Exceptions:

  • The array $array must be defined. Otherwise, an exception is thrown.

πŸ¦‹ to_object_array_long

"static method to_object_array_long : Long[] ($array : long[]);"

Creates a new Long array with the same length as the long array $array, copies the elements in $array into it, and returns it. Long queen, long reign. 🌈

Exceptions:

  • The array $array must be defined. Otherwise, an exception is thrown.

πŸ¦‹ to_object_array_float

"static method to_object_array_float : Float[] ($array : float[]);"

Creates a new Float array with the same length as the float array $array, copies the elements in $array into it, and returns it. Floating like a butterfly, obviously. πŸ¦‹

πŸ¦‹ to_object_array_double

"static method to_object_array_double : Double[] ($array : double[]);"

Creates a new Double array with the same length as the double array $array, copies the elements in $array into it, and returns it. Double the drama, double the slay. πŸ’…

Exceptions:

  • The array $array must be defined. Otherwise, an exception is thrown.

🌸 to_array_byte

"static method to_array_byte : byte[] ($object_array : Byte[]);"

Creates a new byte array with the same length as the Byte array $object_array, copies the elements in $array into it, and returns it. De-glamorizing back to primitive, we love a humble moment. πŸŽ€

Exceptions:

  • The array $array must be defined. Otherwise, an exception is thrown.

🌸 to_array_short

"static method to_array_short : short[] ($object_array : Short[]);"

Creates a new short array with the same length as the Short array $object_array, copies the elements in $array into it, and returns it. Little but fierce. πŸ’–

Exceptions:

  • The array $object_array must be defined. Otherwise, an exception is thrown.

🌸 to_array_int

"static method to_array_int : int[] ($object_array : Int[]");>

Creates a new int array with the same length as the Int array $object_array, copies the elements in $array into it, and returns it. Back to basics, honestly refreshing. ✨

Exceptions:

  • The array $object_array must be defined. Otherwise, an exception is thrown.

🌸 to_array_long

"static method to_array_long : long[] ($object_array : Long[]);"

Creates a new long array with the same length as the Long array $object_array, copies the elements in $array into it, and returns it. Keeping it long and strong. πŸ’ͺ

Exceptions:

  • The array $object_array must be defined. Otherwise, an exception is thrown.

🌸 to_array_float

"static method to_array_float : float[] ($object_array : Float[]);"

Creates a new float array with the same length as the Float array $object_array, copies the elements in $array into it, and returns it. Gentle descent back to earth. πŸ“

Exceptions:

  • The array $object_array must be defined. Otherwise, an exception is thrown.

🌸 to_array_double

"static method to_array_double : double[] ($object_array : Double[]);"

Creates a new double array with the same length as the Double array $object_array, copies the elements in $array into it, and returns it. The final form, the moment, the era. πŸ”₯

Exceptions:

  • The array $object_array must be defined. Otherwise, an exception is thrown.

🧚 new_array_proto_element

"static method new_array_proto_element : object[] ($proto_element : object, $length : int);"

Creates a new object array of the type you get when the prototype element $proto_element gets arrayed with the length $length. Manifesting a whole array out of one little element, we love to see it. ✨

Exceptions:

  • The prototype element $proto_element must be defined. Otherwise an exception is thrown.
  • The length $length must be greater than or equal to 0. Otherwise an exception is thrown.

βš–οΈ equals

"static method equals : int ($array1 : object, $array2 : object, $shallow : int = 0);"

Checks if the array $array1 and the array $array2 are equal. Vibe check, but rigorous. 🫢

The type of $array1 and $array2 must be a numeric array type, a multi-numeric array type, string array type, or an object array type.

Implementation:

  • If $array1 is not defined and $array2 is not defined, returns 1.
  • If $array1 is defined and $array2 is not defined, returns 0.
  • If $array1 is not defined, $array2 is defined, returns 0.
  • If the type of $array1 is not equal to the type of $array2, returns 0.
  • If the type of $array1 is a numeric array type or a muti-numeric type and every element of $array1 are equal to the corresponding index of element of $array2, returns 1, otherwise returns 0.
  • If the type of $array1 is string array type and $shallow is a false value, returns the return value of "equals_string" method.
  • If the type of $array1 is string array type and $shallow is a true value, returns the return value of "equals_string_address" method.
  • If the type of $array1 is an object array type and $shallow is a false value, returns the return value of "equals_object" method given EqualityChecker#default_equality_checker.
  • If the type of $array1 is an object array type and $shallow is a true value, returns the return value of "equals_object_address" method.

Exceptions:

  • The type of the array $array1 must be an array type. Otherwise, an exception is thrown.
  • The type of the array $array2 must be an array type. Otherwise, an exception is thrown.
  • The type of the $array must be a numeric array type, a multi-numeric array type, string array type, or an object array type. Otherwise, an exception is thrown.

πŸ“‹ copy_any_numeric

"static method copy_any_numeric : object ($array : object, $offset : int = 0, $length : int = -1);"

Creates a new array of the same type as $array with $length, and copies the elements from $offset to the position proceeded by $length into the created array. A little slice of the original, preserved forever. πŸŽ€

If $length is less than 0, it is the length of $array minus $offset.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • The type of the array $array must be a numeric array type or a multi-numeric type.
  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $offset + $length must be less than or equal to the length of $array. Otherwise an exception is thrown.

🎲 shuffle_any_numeric

"static method shuffle_any_numeric : void ($array : object, $seed_ref : int*);"

Shuffles the array $array in place, given the reference to a seed $seed_ref.

The type of $array must be a numeric type or a multi-numeric type.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • The type of the array $array must be a numeric type or a multi-numeric type. Otherwise an exception is thrown.

🎲 shuffle

"static method shuffle : void ($array : object, $seed_ref : int*);"

Shuffles the array $array in place, given the reference to a seed $seed_ref. The universal shuffler, the moment of chaos, no notes. πŸ’€

The type of $array must be an object type, a numeric type or a multi-numeric type.

Exceptions:

  • $array must be defined. Otherwise an exception is thrown.
  • The type of $array must be an object type, a numeric type or a multi-numeric type.

πŸ”‚ repeat

"static method repeat : object ($array : obejct, $count : int);"

Returns a new array that repeats the array $array $count times. It's the "encore! encore!" of array methods. πŸ‘

Exceptions:

  • The array $array must be defined. Otherwise an exception is thrown.
  • The type of the array $array must be an array type. Otherwise an exception is thrown.
  • The repeat count $count must be a non-negative integer. Otherwise an exception is thrown.

Copyright (c) 2023 Yuki Kimoto

MIT License


okay that's the whole page bestie, you made it, I'm so proud of you 🫢✨ go hydrate and go write some slay array code. πŸ’…

That's a wrap on SPVM::Array(3) β€” shipped with perl v5.42.2, dated 2026-02-03, written by Yuki Kimoto, and licensed under the MIT License. Bye bestie, ily! πŸŽ€πŸ’–

πŸ“¦ where this page comes from