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.

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.

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.