File Coverage

lib/Crypt/Komihash.xs
Criterion Covered Total %
statement 3 13 23.0
branch 0 2 0.0
condition n/a
subroutine n/a
pod n/a
total 3 15 20.0


line stmt bran cond sub pod time code
1             #include "EXTERN.h"
2             #include "perl.h"
3             #include "XSUB.h"
4             #include
5             #include
6             #include
7             #include "komihash.h"
8             #include "rdtsc_rand.h"
9              
10             // Global seeds used for komirand
11             uint64_t SEED1;
12             uint64_t SEED2;
13              
14             bool has_been_seeded = false;
15              
16             // External function allow setting the seeds
17 0           static void komirand_seed(uint64_t seed1, uint64_t seed2) {
18 0           SEED1 = seed1;
19 0           SEED2 = seed2;
20              
21             //printf("SEED: %llu / %llu\n", seed1, seed2);
22              
23 0           has_been_seeded = true;
24 0           }
25              
26 0           static uint64_t komirand64() {
27 0 0         if (!has_been_seeded) {
28 0           komirand_seed(rdtsc_rand64(), rdtsc_rand64());
29             }
30              
31 0           uint64_t ret = komirand(&SEED1, &SEED2);
32              
33 0           return ret;
34             }
35              
36             // XS binding
37             MODULE = Crypt::Komihash PACKAGE = Crypt::Komihash
38              
39             UV komihash(SV *input, UV seednum = 0)
40             CODE:
41 54           STRLEN len = 0;
42             // Take the bytes in input, put the length in len, and get a pointer to the bytes
43             // We use SvPVbyte instead of SvPV to handle unicode correctly
44 54           char *buf = SvPVbyte(input, len);
45              
46 54           RETVAL = (UV)komihash(buf, len, seednum);
47             OUTPUT:
48             RETVAL
49              
50             UV komirand64()
51              
52             void komirand_seed(UV seed1, UV seed2)
53              
54             UV rdtsc_rand64()
55              
56             UV get_rdtsc()