Re: PEAR Algorithms/Containers
| From: | Richard Lynch | Date: | Thu, 18 May 2006 23:10:27 +0000 |
| Subject: | Re: PEAR Algorithms/Containers | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-236451@lists.php.net to get a copy of this message | ||
On Thu, May 18, 2006 8:57 am, tedd wrote:
> However, binary-trees are for searching and I use MySQL for that. I
> don't know specifically how MySQL preforms searches. I had hoped that
> somewhere one could set a bit and change the algorithms, but I
> haven't been able to find any references that allow that.
You really would need to discuss this at length on a MySQL forum/list,
but basically, the first thing you have to look at is the indeces, if
any, on the tables in question.
If you have an index, it could be a B-tree, or a hash, or any other
number of low-level indexed structures which more-or-less imply the
algorithm to be used in a search/sort.
The second thing to examine is MySQL's estimate of the number and
distribution of records to be loaded/examined/returned.
If the result set to be loaded/examine/returned is relatively high
number and widely distributed over hard drive "pages" then MySQL
"knows" it has to do a full table scan anyway, and goes ahead and does
that, I think.
All of the above is a gross over-simplification of something that
MySQL has put a zillion man-hours into solving -- which is why a
database is so GOOD at this sort of thing.
Of course, one doesn't always have a choice...
For example, one might be faced with a dog-slow crappy Google adwords
API feed that can only return keyword traffic estimates for specific
bids, and then one would be forced to hit that dog-slow crappy Google
adwords API feed in a binary search algorithm just to have any hope at
all of completing one's task in some reasonable time-frame... Not
that I've ever faced this problem, oh no. :-(
To me, the added complexity of a class to handle something as simple
as binary search, hash-search, or even a B-tree or order N, is just
overhead and complexity of integration that I don't need.
When I need that kind of algorithm, I do not find it difficult nor
tedious to just code it from scratch.
But I can see where others would find it a real boon, so I suspect it
would be quite useful for many to find in PEAR or some reasonable PHP
code library.
What might be MORE useful, perhaps, would be an extension in C to add
some of these algorithms to the language somehow -- Since that would
maybe include a performance boost in the algorithm itself, assuming
you could get the data/structures into and out of the C code in some
reasonable way.
YMMV
--
Like Music?
http://l-i-e.com/artists.htm