If I were to add an isLeaf member function, I would have the cpu overhead of a function call every time I wanted to use that. I may switch it to 1/0, but doesn't that get rounded up to a 64-bit integer?
You have a simple space/time tradeoff to make, and you've indicated that the problem is space. If the overhead isn't significant for a slot in the object to hold a boolean to indicate whether the object is a leaf, then do it. But if you're still tight on space, trade that boolean for a function call. Sure, a function call takes "more CPU", but do you know whether that additional time is significant (or even measurable)? I'll bet that the overhead of
package Node;
sub isLeaf { 0 }
package Leaf;
isLeaf { 1 }
is barely measurable, and may be more than canceled out by not having to grow (at setup time) or access (at use time)the anonymous arrays that underly your objects.
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.