Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:29380 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82357 invoked by uid 1010); 9 May 2007 17:43:06 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 82342 invoked from network); 9 May 2007 17:43:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 May 2007 17:43:06 -0000 Authentication-Results: pb1.pair.com header.from=brianm@dealnews.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=brianm@dealnews.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain dealnews.com designates 129.41.69.185 as permitted sender) X-PHP-List-Original-Sender: brianm@dealnews.com X-Host-Fingerprint: 129.41.69.185 smtp.dealnews.com Linux 2.5 (sometimes 2.4) (4) Received: from [129.41.69.185] ([129.41.69.185:53917] helo=smtp.dealnews.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/90-60325-82802464 for ; Wed, 09 May 2007 13:43:06 -0400 Received: (qmail 9925 invoked from network); 9 May 2007 13:43:02 -0400 Received: from unknown (HELO mail.dealnews.com) (10.1.1.7) by -H with (DHE-RSA-AES256-SHA encrypted) SMTP; 9 May 2007 13:43:02 -0400 Received: (qmail 27042 invoked from network); 9 May 2007 13:43:01 -0400 Received: from unknown (HELO ?10.1.6.4?) (brianm@75.91.28.233) by -H with ESMTPA; 9 May 2007 13:43:01 -0400 Message-ID: <464207FC.2040403@dealnews.com> Date: Wed, 09 May 2007 12:42:20 -0500 User-Agent: Thunderbird 2.0.0.0 (Macintosh/20070326) MIME-Version: 1.0 To: maurice@phorum.org CC: Michael Walter , internals@lists.php.net References: <4641D92C.4050208@dealnews.com> <10845a340705090743v6aba7896y45b9f7d60a4e77ba@mail.gmail.com> <4641E3DD.8040807@phorum.org> <877e9a170705090913i320359cag81b0a3bf203e2c86@mail.gmail.com> <464202D9.8080509@phorum.org> In-Reply-To: <464202D9.8080509@phorum.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Tree sort in C From: brianm@dealnews.com (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 down. Actually, this does not work. It uses string sorting to sort the nodes in the $keys array. This means the nodes at a given level are now out of order compared to the original order of the input array Try this for making a node list: for($x=1;$x<=40;$x++){ $parent = rand(0,$x-1); $nodes[$x] = array( "id" => $x, "parent_id" => $parent, "title" => "item $x" ); } You will see that the order of the nodes within a level is string sorted. That is not desired. The order of the children should not change from the order they appeared in the input array. In this case, numeric, but with our function, the order is preserved. So, you could sort the array by ANY thing you wanted before calling the tree sort function and the nodes at any given level will be in that order. And as Maurice said, the memory overhead is still there. -- Brian Moon Senior Developer ------------------------------ http://dealnews.com/ It's good to be cheap =)