Skip to content

Commit

Permalink
perl
Browse files Browse the repository at this point in the history
  • Loading branch information
irr committed Oct 22, 2015
1 parent a980234 commit 611eab1
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions redis/test-geohash.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use Modern::Perl;
use Data::Dumper;

use Inline C => <<'END_C', LIBS => '-lrgeohash';
#include <stdint.h>
#include <string.h>
#include "rgeohash.h"
void geohash_sv(double longitude, double latitude, SV* res) {
char hash[12];
geohash(longitude, latitude, hash);
sv_setpvn(res, hash, strlen(hash));
}
unsigned long geohash64_sv(double longitude, double latitude) {
return (unsigned long)geohash64(longitude, latitude);
}
void geohash_decode_sv(unsigned long bits, SV* longitude, SV* latitude) {
double lon, lat;
geohash_decode(bits, &lon, &lat);
sv_setnv(longitude, lon);
sv_setnv(latitude, lat);
}
unsigned long geohash_decode64_sv(char* buf) {
return (unsigned long) geohash_decode64(buf);
}
END_C

my ($hash, $hash64, $longitude, $latitude, $hash64_sv);

geohash_sv(-46.691657, -23.570018, $hash);

$hash64 = geohash64_sv(-46.691657, -23.570018);

geohash_decode_sv($hash64 + 0, $longitude, $latitude);

$hash64_sv = geohash_decode64_sv($hash);

say(Dumper([$hash, $hash64, $longitude, $latitude, $hash64_sv],
[qw(hash hash64 longitude latitude hash64_sv)]));

0 comments on commit 611eab1

Please sign in to comment.