in reply to Fast string hash in portable perl?

I believe if you're hell-bent on pure Perl, there is no faster thing than the CRC32 for "sufficiently good" hashing. Enough work has gone into CRC32 to make it fast, as it has been in use for a long time. Oh - there even is a module for it - CRC32

But why not simply use Digest::MD5 ? I think it's core nowadays, and there even is a (slow) pure Perl version available ...

Update:Added link to the CRC32 module

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Replies are listed 'Best First'.
Re: Re: Fast string hash in portable perl?
by BrowserUk (Patriarch) on Dec 19, 2003 at 19:45 UTC

    CRC32 is not a good choice for hashing strings for lookup purposes. There are too many collosion hotspots. And MD5 isn't a 32-bit value.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!

      Not 32 bit? Then just run the B::hash on the MD5! Just kidding folks, just kidding!

      You are exactly right on CRC32. I can't think of any case where CRC32 is really a good choice.

        CRC32 may be a great choice if you use it as the quick test for changes and then use a less collision prone (more time/cpu intensive) hash generator for a secondary test. Kind of what rsync does to speed up the block level checking.


        -Waswas
Re: Re: Fast string hash in portable perl?
by dragonchild (Archbishop) on Dec 19, 2003 at 19:55 UTC
    PurePerl generally means things that don't require a a C compiler to install, so that Win32 can easily use it. CRC32 has an XS component.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      How is that an issue?
        XS requires a C compiler. Hence, most Win32 users (and many Unix users, believe it or not) cannot use modules that have an XS component directly from CPAN.

        I'm facing this issue right now at work trying to get a clean system up for a webserver in a DMZ. My dev box has all the tools, so I built a bunch of stuff. Now, trying to get those same items over into the clean box without accidentally polluting it isn't so easy.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.