There is an ongoing outage on the primary CPAN mirror. It is possible to work around the issue by using MetaCPAN as a mirror.

Name

SPVM::QList - List with O(1) deque

Usage

use QList;

# Create an object list
my $list = QList->new;
my $list = QList->new([(object)Byte->new(1), Int->new(2), Long->new(3)]);

# Create a Int list
my $list = QList->new([Int->new(1), Int->new(2), Int->new(3)]);

# Create an object list with length
my $list = QList->new_len([], 3);

# Create a Int list with length
my $list = QList->new_len(new Int[0], 3);

# Get list length
my $length = $list->length;

# Push object value
$list->push(Int->new(3));

# Pop object value.
my $element = $list->pop;

# Unshift object value.
$list->unshift(Int->new(3));

# Shift object value.
my $element = $list->shift;

# Set object value.
$list->set(2, Int->new(3));

# Get object value.
my $element = $list->get(2);

# Insert object value
$list->insert(1, Int->new(3));

# Remove object value
my $element = $list->remove(1);

# Convert QList to object array.
my $int_array = $list->to_array;

# Convert QList to Int array.
my $int_array = (Int[])$list->to_array;

Description

QList class in SPVM is List class with O(1) deque

Details

O(1) deque

"shift" method is O(1) instead of List class.

Super Class

List

Class methods

new

static method new : QList ($array : object[] = undef, $capacity : int = -1);

new_len

static method new_len : QList ($proto_array : object[], $length : int, $capacity : int = -1);

Instance methods

get

method get : element ($index : int);

Same as List#get method.

set

method set : void ($index : int, $element : object);

Same as List#set method.

shift

method shift : element ();

Same as List#shift method.

to_array

method to_array : object[] ();

Same as List#to_array method.

unshift

method unshift : void ($element : object);

Same as List#unshift method.

clone

method clone : QList ();

Same as List#clone method.

get_array_unsafe

method get_array_unsafe : object[] ();

Always throw an exception.

Exceptions:

Cannot get the internal array in QList object.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License