blib/lib/SPVM/QList.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 package SPVM::QList;
2  
3 1;
4  
5 =head1 Name
6  
7 SPVM::QList - List with O(1) deque
8  
9 =head1 Usage
10
11 use QList;
12
13 # Create an object list
14 my $list = QList->new;
15 my $list = QList->new([(object)Byte->new(1), Int->new(2), Long->new(3)]);
16  
17 # Create a Int list
18 my $list = QList->new([Int->new(1), Int->new(2), Int->new(3)]);
19
20 # Create an object list with length
21 my $list = QList->new_len([], 3);
22  
23 # Create a Int list with length
24 my $list = QList->new_len(new Int[0], 3);
25  
26 # Get list length
27 my $length = $list->length;
28
29 # Push object value
30 $list->push(Int->new(3));
31  
32 # Pop object value.
33 my $element = $list->pop;
34  
35 # Unshift object value.
36 $list->unshift(Int->new(3));
37
38 # Shift object value.
39 my $element = $list->shift;
40
41 # Set object value.
42 $list->set(2, Int->new(3));
43
44 # Get object value.
45 my $element = $list->get(2);
46  
47 # Insert object value
48 $list->insert(1, Int->new(3));
49  
50 # Remove object value
51 my $element = $list->remove(1);
52  
53 # Convert QList to object array.
54 my $int_array = $list->to_array;
55  
56 # Convert QList to Int array.
57 my $int_array = (Int[])$list->to_array;
58  
59 =head1 Description
60  
61 QList class in L<SPVM> is L<List|SPVM::List> class with O(1) deque
62  
63 =head1 Details
64  
65 =head2 O(1) deque
66  
67 L</"shift"> method is O(1) instead of L<List|SPVM::List> class.
68  
69 =head1 Super Class
70  
71 L<List|SPVM::List>
72  
73 =head1 Class methods
74  
75 =head2 new
76  
77 C<static method new : L<QList|SPVM::QList> ($array : object[] = undef, $capacity : int = -1);>
78  
79 =head2 new_len
80  
81 C<static method new_len : L<QList|SPVM::QList> ($proto_array : object[], $length : int, $capacity : int = -1);>
82  
83 =head1 Instance methods
84  
85 =head2 get
86  
87 C<method get : element ($index : int);>
88  
89 Same as L<List#get|SPVM::List/"get"> method.
90  
91 =head2 set
92  
93 C<method set : void ($index : int, $element : object);>
94  
95 Same as L<List#set|SPVM::List/"set"> method.
96  
97 =head2 shift
98  
99 C<method shift : element ();>
100  
101 Same as L<List#shift|SPVM::List/"shift"> method.
102  
103 =head2 to_array
104  
105 C<method to_array : element[] ();>
106  
107 Same as L<List#to_array|SPVM::List/"to_array"> method.
108  
109 =head2 unshift
110  
111 C<method unshift : void ($element : object);>
112  
113 Same as L<List#unshift|SPVM::List/"unshift"> method.
114  
115 =head2 clone
116  
117 C<method clone : L<QList|SPVM::QList> ();>
118  
119 Same as L<List#clone|SPVM::List/"clone"> method.
120  
121 =head2 get_array
122  
123 C<method get_array : element[] ();>
124  
125 Always throw an exception.
126  
127 Exceptions:
128  
129 Cannot get the internal array in QList object.
130  
131 =head1 Copyright & License
132  
133 Copyright (c) 2023 Yuki Kimoto
134  
135 MIT License