SPVM::QList − List with O(1) deque
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;
QList class in SPVM is List class with O(1) deque
"shift" method is O(1) instead of List class.
List
"static method new : QList ($array : object[] = undef, $capacity : int = −1);"
"static method new_len : QList ($proto_array : object[], $length : int, $capacity : int = −1);"
"method get : element ($index : int);"
Same as List#get method.
"method set : void ($index : int, $element : object);"
Same as List#set method.
"method shift : element ();"
Same as List#shift method.
"method to_array : element[] ();"
Same as List#to_array method.
"method unshift : void ($element : object);"
Same as List#unshift method.
"method clone : QList ();"
Same as List#clone method.
"method get_array : element[] ();"
Always throw an exception.
Exceptions:
Cannot get the internal array in QList object.
Copyright (c) 2023 Yuki Kimoto
MIT License