Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hash lookup in the type of hash structure used in perl is O(1). Its basically the time to calculate the hash value of the key, which is not dependent on the size of the hash, followed by the application of a bitmask to obtain an index into an array of linked lists, which are normally very short, followed by a key comparison on each element in the LL until the actual key is found or the end of the LL is reached. Under non pathological circumstances the LL should hold 0 or 1 elements. The end result is that the lookup time (memory swapping aside) is O(1) and thus independent of the number of keys in the hash.

Its true that under pathological cirumstances you could end up with a bucket with a million keys in it, but Perl has a number of heuristics to prevent this happening in practice. Building the hash is more expensive because Perl cannot know the final size required and must always have a power of two number of buckets, so while growing the hash array needs to be expanded and the keys remapped which costs time. But its purely on storage. Once built a perl hash should behave in O(1) time, or rather time proportional to the length of the key being looked up.

---
demerphq


In reply to Re^5: How to remove duplicates from a large set of keys by demerphq
in thread How to remove duplicates from a large set of keys by nite_man

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2021-07-24 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?