Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi all,

I've have to implement some perl code from perl to c. I'm nearly thee, but I'm wondering if there is a stanard hash library from C. If not, any resources on how to implement hashes in C?

Cheers.

Replies are listed 'Best First'.
Re: Perl to C
by Aristotle (Chancellor) on Nov 15, 2005 at 20:14 UTC

    Take a look at libghthash. Also, both the GNU and the FreeBSD libc contain hashing functions – check hcreate(3), hsearch(3) and hdestroy(3). (Not sure how widely these are available on other systems; I never had to look.)

    Makeshifts last the longest.

      According to the man pages on my machine, search.h (containing hcreate and co.) goes back to System V Interface Description, and is described in POSIX 1003.1-2001.

      So they should be pretty widely available.

Re: Perl to C
by jeffa (Bishop) on Nov 15, 2005 at 20:09 UTC
Re: Perl to C
by cbrandtbuffalo (Deacon) on Nov 16, 2005 at 19:06 UTC
    I've recently been reading The Practice of Programming and it describes basic approaches to hashes in C. If you have to implement it from scratch, all the details are there along with explanations. Probably worth picking up if this is your first go at it.