Re: [PHP-DEV] Tree sort in C

2007-05-11 Thread Pierre
HI Maurice, On 5/10/07, Maurice Makaay <[EMAIL PROTECTED]> wrote: > That is very peculiar... it should never be slower than an > implementation in PHP - unless your algorithm isn't optimal. > The timing for large numbers of nodes got slower due to a linear lookup (as explained in a previous mes

Re: [PHP-DEV] Tree sort in C

2007-05-10 Thread Richard Lynch
On Wed, May 9, 2007 1:00 pm, Brian Moon wrote: > Richard Lynch wrote: >> Seems like you could just make it a custom extension and see if >> people >> use it a lot... >> >> Even if you just had every phorum user asking for it, that would >> drive >> a lot of interest, no? > > Well, making a custom

Re: [PHP-DEV] Tree sort in C

2007-05-10 Thread Maurice Makaay
Hi, That is very peculiar... it should never be slower than an implementation in PHP - unless your algorithm isn't optimal. The timing for large numbers of nodes got slower due to a linear lookup (as explained in a previous message too). I implemented a hash table lookup as a replacement. Th

Re: [PHP-DEV] Tree sort in C

2007-05-10 Thread Richard Quadling
On 09/05/07, Brian Moon <[EMAIL PROTECTED]> wrote: Derick Rethans wrote: > On Wed, 9 May 2007, Maurice Makaay wrote: > >> At a really >> large number of nodes, the extension becomes slower, but the memory stays low. > > That is very peculiar... it should never be slower than an > implementation

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Maurice Makaay
Hi, That is very peculiar... it should never be slower than an implementation in PHP - unless your algorithm isn't optimal. Depends on your definition of "optimal". In setting up the structures, I have a linear search going to find the node for a parent. That's why it gets slower for (very)

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Sebastian Bergmann
Brian Moon schrieb: > Well, making a custom Phorum extension is a whole other discussion for > our team to have. If we went down that road, we would do more than just > this function. An extension that provides efficient graph / tree algorithms (the latter are just a special case of the former)

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Brian Moon
Maurice Makaay wrote: Hi, A quick sketch of an idea that should work: Yes, that would work. The problem though, is that there's still accumulation of data going on, before the actual sorting can take place. Remember that the main reason for writing the C-extension was to get the memory usage

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Brian Moon
Richard Lynch wrote: Seems like you could just make it a custom extension and see if people use it a lot... Even if you just had every phorum user asking for it, that would drive a lot of interest, no? Well, making a custom Phorum extension is a whole other discussion for our team to have. I

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Richard Lynch
On Wed, May 9, 2007 9:22 am, Brian Moon wrote: > A common issue in lots of applications is tree sorting with unlimited > depth. Phorum has used a recursive function since 1999 to solve this > problem. However, at MySQL Conference this year, we finally wrote a > non Seems like you could just make

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Brian Moon
Derick Rethans wrote: On Wed, 9 May 2007, Maurice Makaay wrote: At a really large number of nodes, the extension becomes slower, but the memory stays low. That is very peculiar... it should never be slower than an implementation in PHP - unless your algorithm isn't optimal. Me too. But, f

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Derick Rethans
On Wed, 9 May 2007, Maurice Makaay wrote: > At a really > large number of nodes, the extension becomes slower, but the memory stays low. That is very peculiar... it should never be slower than an implementation in PHP - unless your algorithm isn't optimal. regards, Derick -- PHP Internals - P

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Maurice Makaay
Hi, A quick sketch of an idea that should work: Yes, that would work. The problem though, is that there's still accumulation of data going on, before the actual sorting can take place. Remember that the main reason for writing the C-extension was to get the memory usage down. Here's some ben

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Michael Walter
Hi, A quick sketch of an idea that should work: 1, 'parent_id'=>0), array('id'=>2, 'parent_id'=>1), array('id'=>3, 'parent_id'=>1), array('id'=>4, 'parent_id'=>2) ); // create column data $keys=$indents=$index=array(); $i=0; foreach($nodes as $node) { $id=$node['id']; $pid=

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Maurice Makaay
Hello, Take a look at http://www.php.net/manual/en/function.array-multisort.php#68689 / http://rquadling.php1h.com/array_multisort_column.php Could you please explain how you think that multisort array would help in doing a tree sort? AFAIK, tree sorting is not a simple sort algorithm where yo

Re: [PHP-DEV] Tree sort in C

2007-05-09 Thread Richard Quadling
On 09/05/07, Brian Moon <[EMAIL PROTECTED]> wrote: A common issue in lots of applications is tree sorting with unlimited depth. Phorum has used a recursive function since 1999 to solve this problem. However, at MySQL Conference this year, we finally wrote a non recursive function for it and ach