Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43353 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81492 invoked from network); 15 Mar 2009 18:09:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2009 18:09:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.158 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.218.158 mail-bw0-f158.google.com Received: from [209.85.218.158] ([209.85.218.158:42853] helo=mail-bw0-f158.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 49/C1-06903-C444DB94 for ; Sun, 15 Mar 2009 13:09:17 -0500 Received: by bwz2 with SMTP id 2so864770bwz.23 for ; Sun, 15 Mar 2009 11:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=KAul9NQzUkJ1qgOx1I2pqJYlOd8Iu/k3pbwiVb/zozg=; b=JIAP6lMZ2FEtl289OrZTV27hU8fizym8sRlI930mendGNsS8Z7U/rTr5ckeIdqbGD5 iOAdIuCkSFzyg4WVh9Z3bhzIhfPfg5tbGbsTXXbXqr8tNxSWKhVuoVf5m680+WNv+Ivh vJy9GvRpMdWkhDcQCvaaDjNyRivr1K4qIAZRc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=THvdDgJ5odyMP2mVja8f3lntuB6SH9gTJFhh0UhZzq+KekBpHl7q+j4ZwlhlVn6OmG 0jB7zJfdCRUPeylKzn5EkodC9UQuIoQJlJ3KNgXoM2sr5Qk2v5m8upsN3VdDI8bbReil GFIlKZ0cCE1kVAEGXVQu47PYyYz8jzkFz6kAM= MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.86.57.9 with SMTP id f9mr2143517fga.38.1237140550679; Sun, 15 Mar 2009 11:09:10 -0700 (PDT) In-Reply-To: References: Date: Sun, 15 Mar 2009 19:09:10 +0100 X-Google-Sender-Auth: 1601d47a33873f63 Message-ID: To: Ben Smithers Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] SplStack Implementation From: webmaster@colder.ch (Etienne Kneuss) Hello, On Sun, Mar 15, 2009 at 2:19 PM, Ben Smithers wrote: > Firstly, apologies if this is not the correct place to ask such a question - > I was directed here from a forum. > > I recently discovered the datastructures found in the Standard PHP Library. > I noticed that SplStack is implemented using a doubly-linked list and > wondered why. Given that a stack is LIFO store and the only operations > really needed are push and pop, why would next and previous pointers be > required on each item? There's no requirement to allow iteration over a > stack. > > It would seem to me that a stack should require a linear linked list and a > pointer to the top of the stack - which would have roughly half the memory > overhead of a doubly-linked list (half the number of pointers). > > Do i just have no idea what i'm talking about or have i missed something > obvious? You're right, a stack can be implemented in a simpler way that would reduce slightly the memory usage. However, storing one additional pointer per doubly linkedlist (DLL) node and managing it is totally irrelevant when placed in context of PHP code. If you look at the code, you'll see that the additionnal code to make a DLL work as a stack is very small, and that's why it was implemented like that. One could implement a stack and a queue using a single linked list, but that would mean code duplication which ends up to be not worth the irrelevant speed/memory improvement. If SPLinkedList is implemented once, we might consider move SplStack and SplQueue to use that new implementation, but I believe there are other priorities for SPL right now, such as documentation. Regards, > > Thanks in advance, > > Ben > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal