in reply to Re: Bidirectional lookup algorithm? (Solution.)
in thread Bidirectional lookup algorithm? (Updated: further info.)
That line below your signature is somewhat enigmatic:
The code present a class:BiMap, which supports the following methods: 7 ) { strncpy( (char*)( iHash script for RAD and testing), and a brief description. , CLEAN_AFTER_BUILD =used, newSize ); for( i = 0; i = pair; bm--1
I've tried setting up a bidirectional hash using XS code. It makes both key and values into keys and misuses the IV slot of SV of a hash entry to store the pointer to the crossover hash key.
However, the benchmarks are disappointing:
use blib; use Hash::Bidirectional; use Benchmark qw(cmpthese); use Devel::Size qw(total_size); use strict; use warnings; my $hn = {}; my $hb = bless {}, 'Hash::Bidirectional'; my $i = 0; for ( 'aaaaz' .. 'zzzzz') { $i++; $hn->{$_} = $i; # - normal hash $hn->{$i} = $_; # / $hb->pair($_,$i); # - bidirectional hash } print "size normal hash: ", total_size($hn),"\n"; print "size bi_dir hash: ", total_size($hb),"\n"; cmpthese( 10000000, { normal => sub { $hn->{$hn->{shmem}} }, bi_dir => sub { $hb->get($hb->get('shmem')) }, }); __END__ size normal hash: 3025679168 size bi_dir hash: 2360323536 Rate bi_dir normal bi_dir 2801120/s -- -62% normal 7407407/s 164% --
Improvement of 22% in memory and more than double time for lookup? Why? Is it due to method call/XS overhead? XS code below.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Bidirectional lookup algorithm? (poor XS solution)
by BrowserUk (Patriarch) on Jan 11, 2015 at 21:48 UTC | |
by Anonymous Monk on Jan 11, 2015 at 23:00 UTC | |
by BrowserUk (Patriarch) on Jan 12, 2015 at 00:22 UTC |