-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hashes.xsh
53 lines (43 loc) · 1.43 KB
/
Hashes.xsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
MODULE = XSamples PACKAGE = XSamples::Hashes
SV* create_and_store_key_value_in_hash(SV* key, SV* value)
CODE:
HV* hash = newHV();
hv_store_ent(hash, key, SvREFCNT_inc(value), 0);
RETVAL = newRV_noinc((SV*)hash);
OUTPUT: RETVAL
void add_key_value_to_hash(HV* hash, SV* key, SV* value)
CODE:
hv_store_ent(hash, key, SvREFCNT_inc(value), 0);
SV* delete_and_return_key_from_hash(HV* hash, SV* key)
CODE:
RETVAL = SvREFCNT_inc(hv_delete_ent(hash, key, 0, 0));
OUTPUT: RETVAL
void delete_and_discard_key_from_hash(HV* hash, SV* key)
CODE:
hv_delete_ent(hash, key, G_DISCARD, 0);
SV* key_exists_in_hash(HV* hash, SV* key)
CODE:
SV* returnvalue = newSViv((int) hv_exists_ent(hash, key, 0));
RETVAL = returnvalue;
OUTPUT: RETVAL
SV* get_value_for_key_in_hash(HV* hash, SV* key)
CODE:
HE* hashentry = hv_fetch_ent(hash, key, NULL, 0);
RETVAL = SvREFCNT_inc(HeVAL(hashentry)); /** Get the value of the hashentry **/
OUTPUT: RETVAL
SV* get_number_of_keys_in_hash(HV* hash)
CODE:
SV* number_of_keys = newSViv(HvUSEDKEYS(hash));
RETVAL = SvREFCNT_inc(number_of_keys);
OUTPUT: RETVAL
SV* get_list_of_keys(HV* hash)
CODE:
AV* keys = newAV();
SV* sv; char* key; I32 klen; /** Used in the loop **/
hv_iterinit(hash);
while((sv = hv_iternextsv(hash, &key, &klen)))
av_push(keys, newSVpv(key, klen));
/** AV*'s and HV*'s are actually SV*'s **/
/** The more you know... **/
RETVAL = newRV_noinc((SV*) keys);
OUTPUT: RETVAL