in reply to Bidirectional lookup algorithm? (Updated: further info.)

Since your strings and integers are unique - why don't you use a hash for strings and an array for integers

#!/usr/bin/perl -l my %str2int; my @int2str; $i=0; for ('aaaa'..'zzzz') { $str2int{ $_ } = ++$i; $int2str[$i] = $_; }

and look up the strings by index into the array, and the integers by key into the hash?

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: Bidirectional lookup algorithm? (Updated: further info.)
by Laurent_R (Canon) on Jan 05, 2015 at 19:00 UTC
    The integers are 64-bits. I do not know what they really look like, but there is clear danger of ending up with a sparse array growing to be much much larger than the hash.

      Right you are.

      qwurx [shmem] ~/comp/perl/tmp > perl -le '@a = 2**64; for(1..29){$a[2* +*$_]=$_}print `ps -o vsz= -p $$`' Out of memory!

      Having 8 GB RAM. 2**28 doesn't die.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'