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.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.