Perl-Sensitive Sunglasses | |
PerlMonks |
Re: “A meeting at the Liquor-Vodka Factory”, or… same ARRAY questions again?!!by Mabooka-Mabooka (Sexton) |
on Sep 05, 2005 at 20:26 UTC ( [id://489285]=note: print w/replies, xml ) | Need Help?? |
Gentlemen,
1st of all - huge thank you to everybody. It’s as always a pleasure to be here and have your questions answered. I *love* this community of wise, intelligent and professional hackers:-), (-- although I am not too much into Perl:-)- (sorry)).. A few general remarks:
2. Thanks a lot for the two _binary search_ answers. Both seem to work, I’ll do some corner-case and performance testing and compare them to hash implementation as well, -- and probably post the results here (if nobody minds).
this is just a “style” thing, easier to remember (int in arr, not arr in int), plus - easier to test together with other impl-s by the same driver; B) Changed
to: (Otherwise, for an array of 5 elements, it’d return an index = 2.5 ;-...)).
3. Re: using <code> v.s <pre>:
4. ($#array + 1) vs. scalar(@array) :
5. Using a hash vs. Binary search.
Enough said about ## 1 & 2; let me explain the 3d one: ... Imagine an application that updates an array rarely and looks up often. Say you have 10,000,000 customers / books / whatever that get added / published only once a minute, but information is requested 1000 per second. So, re-building the hash for lookup 1000 times a second is clearly not an option. Right? A solution to that might be (I’ll think in some pseudo-language now): Well, if you know for sure that push and pop is *all* that you do, that might be possible. However, creating a generic class like this might be really tricky.
This only means that the hash approach only works if
In Section
Seekers of Perl Wisdom
|
|