SPVM::LongList(3)
okay bestie, welcome to the SPVM::LongList(3) page β yes, itβs User Contributed Perl Documentation, and we are about to get into dynamic long arrays. no cap, this class is all about dynamic long arrays and making them look effortless. π
π Name π
SPVM::LongList β Dynamic long Arrays. Thatβs the name, thatβs the vibe: dynamic long arrays, periodt. β¨
π¦ Description π¦
The LongList class in SPVM has methods to manipulate dynamic long arrays. Itβs giving βlist, but make it long-typedβ and honestly? iconic. π
π Usage π
Hereβs the group-chat cheat sheet, bestie β exact code, no edits:
use LongList;
# Create a long list
my $list = LongList->new;
my $list = LongList->new([(long)1, 2, 3]);
# Create a long list with array length
my $list = LongList->new_len(10);
# Get list length
my $length = $list->length;
# Push value
$list->push((long)3);
# Pop value.
my $element = $list->pop;
# Unshift value.
$list->unshift((long)3);
# Shift value.
my $element = $list->shift;
# Set value.
$list->set(2, (long)3);
# Get value.
my $element = $list->get(2);
# Insert value
$list->insert(1, 3);
# Remove value
my $element = $list->remove(1);
# Convert list to array.
my $array = $list->to_array;
thatβs the whole tour: create, get the length, push/pop, unshift/shift, set/get, insert/remove, and convert to an array. slay. π₯
π Details π
π§ Internal Data Structure π§
Two things to keep in your notes app, fr fr:
- The
arraystored in aLongListobject always starts at index0. - The elements in the range that is greater than or equal to the
lengthfield and less than thecapacityfield are filled with0.
π Interfaces π
This class is in its interface era:
CloneableCountable
π Fields π
These are the fields, and yes, theyβre all important:
πΈ capacity
has capacity : virtual ro int;
The capacity. This is the length of the internally reserved elements to extend the length of the list.
π¦ length
has length : virtual ro int;
The length of the list.
π array
has array : long[];
The internal array stored in the LongList object.
β¨ Class Methods β¨
okay, class methods time. these are the constructor-ish icons:
π new
static method new : LongList ($array : long[] = undef, $capacity : int = -1);
Creates a new LongList object using new_len. The signature takes $array : long[] = undef and $capacity : int = -1; the passed length to new_len is the length of the array. If the array is undef, the length is 0.
The elements of the array are copied to the elements of the created array.
Examples:
my $list = LongList->new;
my $list = LongList->new([(long)1, 2, 3]);
π« new_len
static method new_len : LongList ($length : int, $capacity : int = -1);
Creates a new LongList object with $length and $capacity.
If $capacity is less than 0, the capacity is set to the default value.
If $length is greater than $capacity, $capacity is set to $length.
Exceptions:
$lengthmust be greater than or equal to0. Otherwise an exception is thrown.
π§ new_ref
static method new_ref : LongList ($array : long[]);
Creates a new LongList object, sets the array field to the array $array, and returns the new object.
Exceptions:
- The array
$arraymust be defined. Otherwise an exception is thrown.
π Instance Methods π
now the main character section: instance methods. every one of them gets its moment. π
π₯ get
method get : long ($index : int);
Gets the element at the position of $index.
If $index is a negative value, $index is set to length plus $index.
Exceptions:
$indexmust be greater than or equal to0. Otherwise an exception is thrown.$indexmust be less than the length of$list. Otherwise an exception is thrown.
β¨ insert
method insert : void ($index : int, $element : long);
Inserts an $element to the position of $index.
Exceptions:
$indexmust be greater than or equal to0. Otherwise an exception is thrown.$indexmust be less than or equal to the length of$list. Otherwise an exception is thrown.
π pop
method pop : long ();
Removes the last element and returns it.
Exceptions:
- The length of
$listmust be greater than0. Otherwise an exception is thrown.
πΈ push
method push : void ($element : long);
Adds an $element after the end of the list.
π¦ remove
method remove : long ($index : int);
Removes the element at the position of $index and returns it.
Exceptions:
$indexmust be greater than or equal to0. Otherwise an exception is thrown.$indexmust be less than the length of$list. Otherwise an exception is thrown.
π replace
method replace : void ($offset : int, $remove_length : int, $replace : long[] = undef);
Same as the splice method, but the return value is not returned.
Exceptions:
- Exceptions thrown by the
splicemethod could be thrown.
β splice
method splice : long[] ($offset : int, $remove_length : int, $replace : long[] = undef);
Replaces the elements of the range specified by $offset and $length with the $replace array, and returns removed elements creating a new array.
If $replace is not defined, the replacement is not performed.
Exceptions:
$offsetmust be greater than or equal to0. Otherwise an exception is thrown.$remove_lengthmust be greater than or equal to0. Otherwise an exception is thrown.- The sum of
$offsetand the removing length must be less than or equal to the length of$list. Otherwise an exception is thrown.
π«Ά reserve
method reserve : void ($new_capacity : int);
Reserves the elements with $new_capacity.
If $new_capacity is greater than the capacity of the list, the capacity of the list is extended to $new_capacity.
Exceptions:
$new_capacitymust be greater than or equal to0. Otherwise an exception is thrown.
π resize
method resize : void ($new_length : int);
Resizes the list with $new_length.
Exceptions:
$new_lengthmust be greater than or equal to0. Otherwise an exception is thrown.
π« set
method set : void ($index : int, $element : long);
Sets $element at the position of $index.
If $index is a negative value, $index is set to length plus $index.
Exceptions:
$indexmust be greater than or equal to0. Otherwise an exception is thrown.$indexmust be less than the length of$list. Otherwise an exception is thrown.
π§ shift
method shift : long ();
Removes the first element and returns it.
Exceptions:
- The length of
$listmust be greater than0. Otherwise an exception is thrown.
π to_array
method to_array : long[] ();
Creates a new array with the length of the list and copies all elements of the list into the new array, and returns it.
π¦ get_array
method get_array : long[] ();
Returns the internal array.
π unshift
method unshift : void ($element : long);
Inserts an $element at the beginning of the list.
π clone
method clone : LongList ();
Clones this instance and returns it.
π₯ push_
method push_ : void ($elements : long[]);
Adds the elements $elements after the end of this list.
This method calls the push method internally.
Exceptions:
- The elements
$elementsmust be defined. - Exceptions thrown by the
pushmethod could be thrown.
πΈ unshift_
method unshift_ : void ($elements : long[]);
Inserts the elements $elements at the beginning of the list.
Exceptions:
- The elements
$elementsmust be defined. - Exceptions thrown by the
unshiftmethod could be thrown.
π Copyright & License π
Copyright (c) 2023 Yuki Kimoto
MIT License
xoxo bestie π β this page is from perl v5.42.2, dated 2026-02-03, signing off as the SPVM::LongList(3) manual page. bye and slay! π«Ά
π¦ where this page comes from
- alpine 3.24: spvm-doc 0.990125-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms