Name
SPVM::Hash - Hash Data Structure
Usage
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");
Description
Hash
is Hash Data Structure. This is generally called associative array.
The hash function is siphash-1-3
.
Interfaces
Class Methods
new
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"});
Instance Methods
count
count : int ()
Counts keys in the hash.
copy
copy : Hash ()
Copies hash.
This is not deep copy. Address of keys and values is copied into new hash.
clone
method clone : Hash ();
The alias for the "copy".
delete
delete : object ($key : string)
Deletes a key value pair. Deleted value is returned.
exists
exists : int ($key : string)
Specify the key and check if the value exists. If exists, return 1, otherwise 0.
keys
keys : string[] ()
Gets keys. This method do not copy the strings.
values
values : object[] ()
Gets values.
get
get : object ($key : string)
Gets a value.
get_byte
get_byte : int ($key : string)
Gets the value with a $key from a Byte object.
get_short
get_short : int ($key : string)
Gets the value with a $key from a Short object.
get_int
get_int : int ($key : string)
Gets the value with a $key from a Int object.
get_long
get_long : long ($key : string)
Gets the value with a $key from a Long object.
get_float
get_float : float ($key : string)
Gets the value with a $key from a Float object.
get_double
get_double : double ($key : string)
Gets the value with a $key from a Double object.
set
set : void ($key : string, $val : object)
Sets the object $value with the $key.
set_byte
set_byte : void ($key : string, $value : int)
Sets the byte
$value with the $key. the $value is converted to Byte object.
set_short
set_short : void ($key : string, $value : int)
Sets the short
$value with the $key. the $value is converted to Short object.
set_int
set_int : void ($key : string, $value : int)
Sets the int
$value with the $key. the $value is converted to Int object.
set_long
set_long : void ($key : string, $value : long)
Sets the long
$value with the $key. the $value is converted to Long object.
set_float
set_float : void ($key : string, $value : float)
Sets the float
$value with the $key. the $value is converted to Float object.
set_double
set_double : void ($key : string, $value : double)
Sets the double
$value with the $key. the $value is converted to Double object.
set_string
set_string : void ($key : string, $value : string)
Sets the string $value with the $key.
to_array
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.
delete_or_default_byte
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.
delete_or_default_short
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.
delete_or_default_int
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.
delete_or_default_long
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.
If not, the $default value is returned.
delete_or_default_float
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.
If not, the $default value is returned.
delete_or_default_double
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.
If not, the $default value is returned.
delete_or_default_string
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.
If not, the $default value is returned.
delete_or_default
method delete_or_default : object ($key : string, $default : object) {
If the $key exists, the value is deleted and returned.
If not, the $default value is returned.