Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

RE: RE: RE: My views on pseudohashes

by Adam (Vicar)
on Jun 24, 2000 at 03:17 UTC ( #19681=note: print w/ replies, xml ) Need Help??


in reply to RE: RE: My views on pseudohashes
in thread My views on pseudohashes

That's pretty cool. I wonder what it's good for.


Comment on RE: RE: RE: My views on pseudohashes
RE: RE: RE: RE: My views on pseudohashes
by Zoogie (Curate) on Jun 24, 2000 at 04:40 UTC
    This is just a guess (perhaps somebody who's more experienced with Perl compiler optimizations can help out here). Since accessing array elements tends to be faster than accessing hash elements, if the Perl compiler resolves the pseudo-hash keys to the array indexes at compile-time, it makes building structures with named elements more efficient at run-time than simply using hashes.

    The perlref page notes that the compiler does something to this effect for using named fields in objects. I'm not at all familiar with objects in Perl, so I can't really elaborate on that.

    - Zoogie

      Array access is faster than hash access. Yes, with a good hashing algorithm, access is O(1), but it'll never be as fast as array index access. You still have to pay the overhead of the hashing algorithm. There's also the increased memory requirement.

      Of course, with arrays you either use numbers for indexes or constants. That's a bit of trouble to go to either way, and with constants you still have some memory overhead.

      Let's not forget autovivification of hash keys. That could bite you when you least expect it.

      The pseudo-hash tries to solve all of those. Yes, it's a little more complex than your average array, but you can access it either way, and it's faster than a hash, doesn't autovivify keys, and it allows you to refer to values by name instead of by index.

      See perlref for more information, as well as the documentation for fields.pm. (I learned about them from Object Oriented Perl, a fine book.)

        chromatic not only learned from Object Oriented Perl, he wrote the book. Well, a review, at any rate. chromatics prolific review list can be found on SlashDot, here.

        (he's actually very modest, and never would have mentioned this himself)

        --Chris

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2014-11-25 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (148 votes), past polls