SPVM::Hash - Hash (Associative Array)
The Hash class of SPVM has methods to manipulate hashes(associative arrays).
use Hash; my $book = Hash->new; my $book = Hash->new({id => 4, name => "Perl", price => 3000.0}); $book->set_int(id => 4); $book->set_string(name => "Perl"); $book->set_double(price => 3000.0); $book->set(point => Point->new(1, 2)); my $id = $book->get_int("id"); my $name = $book->get_string("name"); my $price = $book->get_double("price"); my $point = (Point)$book->get("point");
The hash function is siphash-1-3.
siphash-1-3
Cloneable
has keys_length : ro int;
The length of the keys in the hash.
static method new : Hash ($key_values : object[] = undef);
Creates a new Hash object given key-value pairs $key_values.
Examples:
my $book = Hash->new; my $book = Hash->new({}); my $book = Hash->new({id => 4, name => "Perl"});
method copy : Hash ();
Creates a new Hash object, and copies the keys and values of the current hash to the new hash, and returns it.
This is not deep copy. The keys are got by the "keys" method. The values are got by the "get" method.
method clone : Hash ();
The alias for the "copy" method.
method delete : object ($key : string);
Deletes the key and value given by the key $key.
The deleted value is returned.
Exceptions:
$key must be defined. Otherwise an exception is thrown.
method exists : int ($key : string);
Checks if the value specified by the key $key exists. If it exists, returns 1. Otherwise returns 0.
method keys : string[] ();
Gets the keys in the hash. This method does not copy the strings.
method values : object[] ();
Gets all the values in the hash.
method get : object ($key : string);
Gets a value specifed by the key $key, and returns it.
method get_byte : int ($key : string);
Gets the value specifed by the key $key using the "get" method, and casts it to the byte type, and casts it to the int type, and returns it.
The type of the value for the key must be the Byte class. Otherwise an exception is thrown.
method get_short : int ($key : string);
Gets the value specifed by the key $key using the "get" method, and casts it to the short type, and casts it to the int type, and returns it.
The type of the value for the key must be the Short class. Otherwise an exception is thrown.
method get_int : int ($key : string);
Gets the value specifed by the key $key using the "get" method, and casts it to the int type, and returns it.
The type of the value for the key must be the Int class. Otherwise an exception is thrown.
method get_long : long ($key : string);
Gets the value specifed by the key $key using the "get" method, and casts it to the long type, and returns it.
The type of the value for the key must be the Long class. Otherwise an exception is thrown.
method get_float : float ($key : string);
Gets the value specifed by the key $key using the "get" method, and casts it to the float type, and returns it.
The type of the value for the key must be the Float class. Otherwise an exception is thrown.
method get_double : double ($key : string);
Gets the value specifed by the key $key using the "get" method, and casts it to the double type, and returns it.
The type of the value for the key must be the Double class. Otherwise an exception is thrown.
method get_string : string ($key : string)
Gets the value specifed by the key $key using the "get" method, and casts it to the string type, and returns it.
The type of the value for the key must be the string type. Otherwise an exception is thrown.
method set : void ($key : string, $value : object);
Sets $value to the hash by the key $key.
method set_byte : void ($key : string, $value : int);
The value $value is converted to a Byte object, and sets it to the hash by the key $key using the "set" method.
method set_short : void ($key : string, $value : int);
The value $value is converted to a Short object, and sets it to the hash by the key $key using the "set" method.
method set_int : void ($key : string, $value : int);
The value $value is converted to an Int object, and sets it to the hash by the key $key using the "set" method.
method set_long : void ($key : string, $value : long);
The value $value is converted to a Long object, and sets it to the hash by the key $key using the "set" method.
method set_float : void ($key : string, $value : float);
The value $value is converted to a Float object, and sets it to the hash by the key $key using the "set" method.
method set_double : void ($key : string, $value : double);
The value $value is converted to a Double object, and sets it to the hash by the key $key using the "set" method.
method set_string : void ($key : string, $value : string);
Sets the string $value to the hash by the key $key using the "set" method.
method to_array : object[] ($sort : int = 0);
Converts all the key-value pairs in the hash to an array, and returns it.
If the option $sort is a positive value, the keys are sorted by ascendant order.
If the option $sort is a negative value, the keys are sorted by decendant order.
method get_or_default_byte : int ($key : string, $default : int;
If the value specified by the key $key exists, this method calls the "get_byte" method , and returns the return value of the the "get_byte" method.
If the value specified by the key $key does not exists, returns the default value $default.
method get_or_default_short : int ($key : string, $default : int;
If the value specified by the key $key exists, this method calls the "get_short" method , and returns the return value of the the "get_short" method.
method get_or_default_int : int ($key : string, $default : int;
If the value specified by the key $key exists, this method calls the "get_int" method , and returns the return value of the the "get_int" method.
method get_or_default_long : long ($key : string, $default : long;
If the value specified by the key $key exists, this method calls the "get_long" method , and returns the return value of the the "get_long" method.
method get_or_default_float : float ($key : string, $default : float;
If the value specified by the key $key exists, this method calls the "get_float" method , and returns the return value of the the "get_float" method.
method get_or_default_double : double ($key : string, $default : double;
If the value specified by the key $key exists, this method calls the "get_double" method , and returns the return value of the the "get_double" method.
method get_or_default_string : string ($key : string, $default : string;
If the value specified by the key $key exists, this method calls the "get_string" method , and returns the return value of the the "get_string" method.
method get_or_default : object ($key : string, $default : object;
If the value specified by the key $key exists, this method calls the "get" method , and returns the return value of the the "get" method.
method delete_or_default_byte : int ($key : string, $default : int;
If the value specified by the key $key exists, this method calls the "get_byte" method and the "delete" method, and returns the return value of the the "get_byte" method.
method delete_or_default_short : int ($key : string, $default : int;
If the value specified by the key $key exists, this method calls the "get_short" method and the "delete" method, and returns the return value of the the "get_short" method.
method delete_or_default_int : int ($key : string, $default : int;
If the value specified by the key $key exists, this method calls the "get_int" method and the "delete" method, and returns the return value of the the "get_int" method.
method delete_or_default_long : long ($key : string, $default : long;
If the value specified by the key $key exists, this method calls the "get_long" method and the "delete" method, and returns the return value of the the "get_long" method.
method delete_or_default_float : float ($key : string, $default : float;
If the value specified by the key $key exists, this method calls the "get_float" method and the "delete" method, and returns the return value of the the "get_float" method.
method delete_or_default_double : double ($key : string, $default : double;
If the value specified by the key $key exists, this method calls the "get_double" method and the "delete" method, and returns the return value of the the "get_double" method.
method delete_or_default_string : string ($key : string, $default : string;
If the value specified by the key $key exists, this method calls the "get_string" method and the "delete" method, and returns the return value of the the "get_string" method.
method delete_or_default : object ($key : string, $default : object;
If the value specified by the key $key exists, this method calls the "get" method and the "delete" method, and returns the return value of the the "get" method.
Copyright (c) 2023 Yuki Kimoto
MIT License
To install SPVM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SPVM
CPAN shell
perl -MCPAN -e shell install SPVM
For more information on module installation, please visit the detailed CPAN module installation guide.