Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: A memory efficient hash, trading off speed - does it already exist?

by Aristotle (Chancellor)
on Feb 06, 2003 at 11:57 UTC ( #233112=note: print w/replies, xml ) Need Help??


in reply to Re: Re: A memory efficient hash, trading off speed - does it already exist?
in thread A memory efficient hash, trading off speed - does it already exist?

If anything, you should probably switch to a structure like
$hash{"Keyword\0Symbol_1"} = $Weighting[1]; $hash{"Keyword\0Symbol_2"} = $Weighting[2];

That way you still get full hash lookup performance on the entire (two dimensional) key. And you avoid creating whole legions of hashes. That should pretty much fix 90% of your problem. And such a flat hash is trivial to tie to a DBM file.

Don't knock DBMs without benchmarking them. DBM files are specifically laid out to allow for rapid retrieval - paging just indiscriminately swaps out whatever seems least necessary, including other parts of the system besides the data. Drawing any conclusions about one based on the other borders on ridiculous.

Makeshifts last the longest.

  • Comment on Re^3: A memory efficient hash, trading off speed - does it already exist?
  • Download Code

Replies are listed 'Best First'.
Re: Re^3: A memory efficient hash, trading off speed - does it already exist?
by JPaul (Hermit) on Feb 06, 2003 at 17:57 UTC
    This requires I know what the following symbol is.
    The point of the hash is to look up potential following symbols of the keyword, unless there's someway to glob hash keys without going through them to compile a list, it's not going to work at all.

    JP,
    -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

      Then keep a key with a list of symbols.
      $hash{"Keyword"} = "Symbol_1\0Symbol_2\0Symbol_3"; my $key = "Keyword"; for my $symbol (split /\0/, $hash{$key}, -1) { my $weight = $hash{"$key\0$symbol"}; # ... }

      Makeshifts last the longest.

        So where is the advantage of that over what I chose to use?
        $hash{"Keyword"} = "Symbol_1 \x255 5 \O Symbol_2 \x255 4";
        I use a single hash (As opposed to two - the lookup hash and the one with values), and when I'm doing accesses I throw it into a temporary hash for quicker lookups on multiple hits to the same keyword.

        JP,
        -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2023-09-23 18:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?