SPVM::LongList(3)

πŸ“¦ version 0.990125, in alpine 3.24

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 array stored in a LongList object always starts at index 0.
  • The elements in the range that is greater than or equal to the length field and less than the capacity field are filled with 0.

🌈 Interfaces 🌈

This class is in its interface era:

  • Cloneable
  • Countable

πŸ‘‘ 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:

  • $length must be greater than or equal to 0. 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 $array must 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:

  • $index must be greater than or equal to 0. Otherwise an exception is thrown.
  • $index must 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:

  • $index must be greater than or equal to 0. Otherwise an exception is thrown.
  • $index must 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 $list must be greater than 0. 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:

  • $index must be greater than or equal to 0. Otherwise an exception is thrown.
  • $index must 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 splice method 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:

  • $offset must be greater than or equal to 0. Otherwise an exception is thrown.
  • $remove_length must be greater than or equal to 0. Otherwise an exception is thrown.
  • The sum of $offset and 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_capacity must be greater than or equal to 0. Otherwise an exception is thrown.

🌈 resize

method resize : void ($new_length : int);

Resizes the list with $new_length.

Exceptions:

  • $new_length must be greater than or equal to 0. 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:

  • $index must be greater than or equal to 0. Otherwise an exception is thrown.
  • $index must 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 $list must be greater than 0. 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 $elements must be defined.
  • Exceptions thrown by the push method could be thrown.

🌸 unshift_

method unshift_ : void ($elements : long[]);

Inserts the elements $elements at the beginning of the list.

Exceptions:

  • The elements $elements must be defined.
  • Exceptions thrown by the unshift method could be thrown.

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