Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

PerlApi: hashes

by BrowserUk (Patriarch)
on Aug 12, 2015 at 02:12 UTC ( [id://1138255]=perlquestion: print w/replies, xml ) Need Help??

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

in Re: Perl Hashes in C?, I construct a hash using the perlapi from Inline::C.

Two of the apis, hv_fetch() and hv_store() optionally take a numeric hash value which if supplied is used directly rather than the key string and length being (re)hashed.

I assume that idea is that once you've hashed a key once, it saves rehashing it; but the fly in that ointment is that there does not seem to be any api to obtain the hash value?

Also, there does not appear to be an equivalent option to supply the hash value to hv_exists()?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re: PerlApi: hashes
by Anonymous Monk on Aug 12, 2015 at 02:32 UTC
        HeHASH Returns the computed hash stored in the hash entry. U32 HeHASH(HE* he)

        Which is fine ... Er, actually, it is terminally stupid.

        In order to obtain the HE* for a key, I first need to look it up; and in order to lookup the key, I need to calculate the hash value!

        Reminds me of the old joke: Anti-thirst pills; take two in a glass of water.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.
        I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
      hv_exists_ent()

      But if I supply the hash value, why does it need the keysv?

      If all I have is the string and its length (the normal case), it means I have to construct an SvPV which is surely more computationally and time costly than simply recalculating the hash; as it requires a several memory allocations.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
      I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found