Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
A counter example is trees & tries. These are immensely useful structures for many purposes, and there are quite a few flavours of both on CPAN. But, for the most part, they are almost useless for anything but experimentation and the most trivial of applications. They are, mostly, based upon using hashes to construct the trees, with the result that the are slow, clumsy and hugely memory hungry.
I'm guessing that you mean that tries are implemented with hashes. I can't image trees implemented with arrays being that much more memory hungary than arrays alone. Sure, operations on trees will be slower than similar operations on arrays, but that's mostly comparing perl vs. C.
#!/usr/bin/perl -w use strict; use Data::Dumper; my $MAX = 10000; my $tree = make_tree($MAX/2,undef,undef); for(my $x=1;$x<$MAX;$x++) { $tree = insert(int(rand($MAX)), $tree); } print "sum = ", sum_tree($tree), "\n"; #print Dumper $tree; sub sum_tree { my $tree = shift; return 0 if not defined($tree); return node($tree) + sum_tree(right($tree)) + sum_tree(left($tree) +); } sub insert { (my $elem, my $tree) = @_; if(not defined($tree)){ return make_tree($elem, undef, undef); } my $curr = node($tree); if( $elem == $curr) { return $tree; } elsif($elem < $curr) { return make_tree($curr, insert($elem,left($tree)), right($tree)); } elsif($elem > $curr) { return make_tree($curr, left($tree), insert($elem,right($tree))); } } sub make_tree { [$_[0], $_[1], $_[2]] } sub node { $_[0]->[0] } sub left { $_[0]->[1] } sub right { $_[0]->[2] }

In reply to Re^3: Performance, Abstraction and HOP by Anonymous Monk
in thread Performance, Abstraction and HOP by pg

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (9)
    As of 2018-06-18 14:03 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (110 votes). Check out past polls.