| 1 | package SPVM::Immutable::DoubleList; | ||
| 2 | |||
| 3 | 1; | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | SPVM::Immutable::DoubleList - Immutable double Array | ||
| 8 | |||
| 9 | =head1 Description | ||
| 10 | |||
| 11 | The Immutable::DoubleList class has methods to manipulate an immutable double array. | ||
| 12 | |||
| 13 | =head1 Usage | ||
| 14 | |||
| 15 | use Immutable::DoubleList; | ||
| 16 | |||
| 17 | # Create a double list | ||
| 18 | my $list = Immutable::DoubleList->new; | ||
| 19 | my $list = Immutable::DoubleList->new([(double)1, 2, 3]); | ||
| 20 | |||
| 21 | # Create a double list with array length | ||
| 22 | my $list = Immutable::DoubleList->new_len(10); | ||
| 23 | |||
| 24 | # Get list length | ||
| 25 | my $length = $list->length; | ||
| 26 | |||
| 27 | # Get value. | ||
| 28 | my $element = $list->get(2); | ||
| 29 | |||
| 30 | # Convert list to array. | ||
| 31 | my $array = $list->to_array; | ||
| 32 | |||
| 33 | =head1 Fields | ||
| 34 | |||
| 35 | =head2 length | ||
| 36 | |||
| 37 | has length : ro int; | ||
| 38 | |||
| 39 | Gets the C<length> field. | ||
| 40 | |||
| 41 | This field is the length of the elements of the list. | ||
| 42 | |||
| 43 | =head1 Class Methods | ||
| 44 | |||
| 45 | =head2 new | ||
| 46 | |||
| 47 | C<static method new : L<Immutable::DoubleList|SPVM::Immutable::DoubleList> ($array : double[] = undef);> | ||
| 48 | |||
| 49 | Create a new L<Immutable::DoubleList|SPVM::Immutable::DoubleList> object using L</"new_len">. | ||
| 50 | |||
| 51 | The passed length to L</"new_len"> is the length of the array. If the array is undef, the length is 0. | ||
| 52 | |||
| 53 | The elements of the array are copied to the elements of the the created array. | ||
| 54 | |||
| 55 | Examples: | ||
| 56 | |||
| 57 | my $list = Immutable::DoubleList->new; | ||
| 58 | my $list = Immutable::DoubleList->new([(double)1, 2, 3]); | ||
| 59 | |||
| 60 | =head2 new_len | ||
| 61 | |||
| 62 | C<static method new_len : L<Immutable::DoubleList|SPVM::Immutable::DoubleList> ($length : int);> | ||
| 63 | |||
| 64 | Creates a new L<Immutable::DoubleList|SPVM::Immutable::DoubleList> object with $length and $capacity. | ||
| 65 | |||
| 66 | Exceptions: | ||
| 67 | |||
| 68 | $length must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 69 | |||
| 70 | =head1 Instance Methods | ||
| 71 | |||
| 72 | =head2 get | ||
| 73 | |||
| 74 | C<method get : double ($index : int);> | ||
| 75 | |||
| 76 | Gets the element of the position of $index. | ||
| 77 | |||
| 78 | If $index is a netative value, $index is set to L</"length"> plus $index. | ||
| 79 | |||
| 80 | Exceptions: | ||
| 81 | |||
| 82 | $index must be greater than or equal to 0. Otherwise an exception is thrown. | ||
| 83 | |||
| 84 | $index must be less than the length of $list. | ||
| 85 | |||
| 86 | =head2 to_array | ||
| 87 | |||
| 88 | C<method to_array : double[] ();> | ||
| 89 | |||
| 90 | Converts the list to an array. | ||
| 91 | |||
| 92 | =head1 Copyright & License | ||
| 93 | |||
| 94 | Copyright (c) 2023 Yuki Kimoto | ||
| 95 | |||
| 96 | MIT License |