SPVM::Hash - Hash Data Structure
use Hash; # Create hash my $book = Hash->new; 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); my $id = (int)$book->get_int("id"); my $key = (string)$book->get_string("name"); my $price = (double)$book->get_double("price");
Hash is Hash Data Structure. This is generally called associative array.
Hash
The hash function is siphash-1-3.
siphash-1-3
Cloneable
static method new : Hash ($key_values = undef : object[]);
Create a new Hash object with key value pairs.
my $book = Hash->new; my $book = Hash->new({}); my $book = Hash->new({id => 4, name => "Perl"});
count : int ()
Counts keys in the hash.
copy : Hash ()
Copies hash.
This is not deep copy. Address of keys and values is copied into new hash.
method clone : Hash ();
The alias for the "copy".
delete : object ($key : string)
Deletes a key value pair. Deleted value is returned.
exists : int ($key : string)
Specify the key and check if the value exists. If exists, return 1, otherwise 0.
keys : string[] ()
Gets keys. This method do not copy the strings.
values : object[] ()
Gets values.
get : object ($key : string)
Gets a value.
get_byte : int ($key : string)
Gets the value with a $key from a Byte object.
get_short : int ($key : string)
Gets the value with a $key from a Short object.
get_int : int ($key : string)
Gets the value with a $key from a Int object.
get_long : long ($key : string)
Gets the value with a $key from a Long object.
get_float : float ($key : string)
Gets the value with a $key from a Float object.
get_double : double ($key : string)
Gets the value with a $key from a Double object.
set : void ($key : string, $val : object)
Sets the object $value with the $key.
set_byte : void ($key : string, $value : int)
Sets the byte $value with the $key. the $value is converted to Byte object.
byte
set_short : void ($key : string, $value : int)
Sets the short $value with the $key. the $value is converted to Short object.
short
set_int : void ($key : string, $value : int)
Sets the int $value with the $key. the $value is converted to Int object.
int
set_long : void ($key : string, $value : long)
Sets the long $value with the $key. the $value is converted to Long object.
long
set_float : void ($key : string, $value : float)
Sets the float $value with the $key. the $value is converted to Float object.
float
set_double : void ($key : string, $value : double)
Sets the double $value with the $key. the $value is converted to Double object.
double
set_string : void ($key : string, $value : string)
Sets the string $value with the $key.
method to_array : object[] ($sort = 0 : int);
Converts the hash to an array.
If $sort is a true value, the keys are sorted by the asc order.
method delete_or_default_byte : int ($key : string, $default : int) {
If the $key exists, the value is deleted and returned with the type cast to byte type.
If not, the $default value with the type cast to byte type is returned.
method delete_or_default_short : int ($key : string, $default : int) {
If the $key exists, the value is deleted and returned with the type cast to short type.
If not, the $default value with the type cast to short type is returned.
method delete_or_default_int : int ($key : string, $default : int) {
If the $key exists, the value is deleted and returned with the type cast to int type.
If not, the $default value is returned.
method delete_or_default_long : long ($key : string, $default : long) {
If the $key exists, the value is deleted and returned with the type cast to long type.
method delete_or_default_float : float ($key : string, $default : float) {
If the $key exists, the value is deleted and returned with the type cast to float type.
method delete_or_default_double : double ($key : string, $default : double) {
If the $key exists, the value is deleted and returned with the type cast to double type.
method delete_or_default_string : string ($key : string, $default : string) {
If the $key exists, the value is deleted and returned with the type cast to string type.
string
method delete_or_default : object ($key : string, $default : object) {
If the $key exists, the value is deleted and returned.
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.