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
$name
= (string)
$book
->get_string(
"name"
);
my
$price
= (double)
$book
->get_double(
"price"
);
Description
Hash is Hash Data Structure. This is generally called associative array.
Class Methods
new
static method new : Hash (
$key_values
: 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
()
Count keys.
copy
copy : Hash ()
Copy hash.
This is not deep copy. Address of keys and values is copied into new hash.
delete
delete
: object (
$key
: string)
Delete 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[] ()
Get keys. This method do not copy the strings.
values
values
: object[] ()
Get values.
get
get : object (
$key
: string)
Get a value.
get_byte
get_byte : byte (
$name
: string)
Get value with a key. the value is converted to byte type.
get_short
get_short : short (
$name
: string)
Get value with a key. the value is converted to short type.
get_int
get_int :
int
(
$name
: string)
Get value with a key. the value is converted to int type.
get_long
get_long : long (
$name
: string)
Get value with a key. the value is converted to long type.
get_float
get_float : float (
$name
: string)
Get value with a key. the value is converted to float type.
get_double
get_double : double (
$name
: string)
Get value with a key. the value is converted to double type.
set
set : void (
$key
: string,
$val
: object)
Set key value pair.
set_byte
set_byte : void (
$name
: string,
$value
: byte)
Set key and value pair. byte value is converted to Byte object.
set_short
set_short : void (
$name
: string,
$value
: short)
Set key and value pair. short value is converted to Short object.
set_int
set_int : void (
$name
: string,
$value
:
int
)
Set key and value pair. int value is converted to Int object.
set_long
set_long : void (
$name
: string,
$value
: long)
Set key and value pair. long value is converted to Long object.
set_float
set_float : void (
$name
: string,
$value
: float)
Set key and value pair. float value is converted to Float object.
set_double
set_double : void (
$name
: string,
$value
: double)
Set key and value pair. double value is converted to Double object.
set_string
set_string : void (
$name
: string,
$value
: string)
Set key and value pair with string value.