Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Bidirectional lookup algorithm? (Updated: further info.)

by shmem (Chancellor)
on Jan 05, 2015 at 18:02 UTC ( [id://1112214]=note: print w/replies, xml ) Need Help??


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'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1112214]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2025-07-12 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.