-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeys.xs
46 lines (35 loc) · 1.07 KB
/
Keys.xs
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
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "INLINE.h"
AV* ckeys (AV* hashes) {
int num_to_merge, i;
HE *hash_entry;
SV *sv_key, *hash_ref, *merge_ref;
HV *merger, *hash;
AV* hkeys = newAV();
merger = newHV();
num_to_merge = av_len(hashes) + 1;
for (i = 0; i < num_to_merge; i++) {
hash_ref = av_shift(hashes);
if (SvTYPE(SvRV(hash_ref)) != SVt_PVHV) croak("Index is not a hash reference %d", i);
hash = (HV*)SvRV(hash_ref);
(void) hv_iterinit(hash);
while ((hash_entry = hv_iternext(hash))) {
sv_key = hv_iterkeysv(hash_entry);
hv_store_ent(merger, sv_key, newSViv(1), 0);
}
}
(void) hv_iterinit(merger);
while ((hash_entry = hv_iternext(merger))) {
sv_key = hv_iterkeysv(hash_entry);
av_push(hkeys, newSVpvf("%s", SvPV(sv_key, PL_na)));
}
sortsv(AvARRAY(hkeys), av_len(hkeys)+1, Perl_sv_cmp_locale);
return hkeys;
}
MODULE = Combine::Keys PACKAGE = Combine::Keys
PROTOTYPES: DISABLE
AV *
ckeys (hashes)
AV * hashes