The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

SPVM::R::NDArray::StringBuffer - N-Dimensional Array of StringBuffer Type.

Description

R::NDArray::StringBuffer class in SPVM represents n-dimensional array of StringBuffer type.

Usage

  use R::NDArray::StringBuffer;
  
  my $data = [
    StringBuffer->new("a"),
    StringBuffer->new("b"),
    StringBuffer->new("c"),
    StringBuffer->new("d"),
    StringBuffer->new("e"),
    StringBuffer->new("f")
  ];
  
  my $ndarray = R::NDArray::String->new({data => $data, dim => [3, 2]});

Super Class

R::NDArray

Field

data

method data : StringBuffer[] ();

Same as R::NDArray#data method, but the return type is different.

Class Methods

new

static method new : R::NDArray::StringBuffer ($options : object[] = undef);

Creates a new R::NDArray::StringBuffer given the options $options and returns it.

This method calls R::NDArray#init method given the options $options.

Instance Methods

create_default_data

method create_default_data : StringBuffer[] ($length : int = 0);

Creates a default data given the length $length and returns it.

The default data is created by the following code.

  my $default_data = new StringBuffer[$length];

Exceptions:

The length $length must be more than or equal to 0. Otherwise an exception is thrown.

elem_to_string

method elem_to_string : string ($data : StringBuffer[], $data_index : int);

The string is created by the following code.

Converts an element $data at index $data_index to a string and returns it.

  my $string = (string)undef;
  if ($data->[$data_index]) {
    $string = $data->[$data_index]->to_string;
  }

elem_assign

method elem_assign : void ($dist_data : StringBuffer[], $dist_data_index : int, $src_data : StringBuffer[], $src_data_index : int);

Assigns the element $src_data at index $src_data_index to the element $dist_data at index $dist_data_index.

elem_clone

method elem_clone : void ($dist_data : StringBuffer[], $dist_data_index : int, $src_data : StringBuffer[], $src_data_index : int);

Clones the element $src_data at index $src_data_indext to the element $dist_data at index $dist_data_index.

The clone is created by the following code.

  $dist_data->[$dist_data_index] = (StringBuffer)undef;
  if ($src_data->[$src_data_index]) {
    $dist_data->[$dist_data_index] = StringBuffer->new($src_data->[$src_data_index]->to_string);
  }

elem_cmp

method elem_cmp : int ($a_data : StringBuffer[], $a_data_index : int, $b_data : StringBuffer[], $b_data_index : int);

Compares the element $a_data at index $a_data_index and the element $b_data at index $b_data_index using the following comparison code and returns the result.

  my $a_string = (string)undef;
  if ($a_data->[$a_data_index]) {
    $a_string = $a_data->[$a_data_index]->to_string;
  }
  
  my $b_string = (string)undef;
  if ($b_data->[$b_data_index]) {
    $b_string = $b_data->[$b_data_index]->to_string;
  }
  
  my $cmp = $a_string cmp $b_string;

elem_is_na

method elem_is_na : int ($data : object, $data_index : int);

Checks if an element represets NA.

If the element $data at index $data_index is not defined, returns 1, otherwise returns 0.

clone

method clone : R::NDArray::StringBuffer ($shallow : int = 0);

Same as R::NDArray#clone method, but the return type is different.

slice

method slice : R::NDArray::StringBuffer ($indexes_product : R::NDArray::Int[]);

Same as R::NDArray#slice method, but the return type is different.

See Also

Copyright & License

Copyright (c) 2024 Yuki Kimoto

MIT License