From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18498 invoked by alias); 1 Mar 2010 18:01:04 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27763 Received: (qmail 9860 invoked from network); 1 Mar 2010 18:01:02 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VERIFIED autolearn=ham version=3.2.5 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 74.125.82.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=ptgAv6+EDWBmX8vHacah4hA0L4eWdQ++1px/emw6zjc=; b=v6O8eIavDrrvRR/ixxvzGNCUdIXR1RXvCJqPiQ4svlQMsiZd3nnHTQUy14qgId5r9b YGDhL0TKXUj9E9Qz5LCPhjDTCmnEwEDWNRlPg+okPUEv7ZMK6AQd6jLk8CE2Lo9WvNWq 49QNlQ+5Gr+5BRUnOan5+solf4B/lRNMnRbMs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=oR/MT4yCWn/SR+4mMdyEZzMMca+7TkQopS5O7gEYxerIg3SLRrA/ObQwbUpr4t5bE3 ae24ihkEj5F3Mong3mwT3UtFC8XDBY1Z0Wq/yI9/wUjfsW536mQVzkMIZeQ309/t3oi5 rGgwClWo6Mv2RYY69IvyX649Rl2rJ0DdObq7Q= MIME-Version: 1.0 In-Reply-To: <201002281206.53953.arvidjaar@gmail.com> References: <22a0ef081002271433u713e1923lb04c7d1bf369d3d0@mail.gmail.com> <201002281206.53953.arvidjaar@gmail.com> Date: Mon, 1 Mar 2010 13:00:56 -0500 Message-ID: <22a0ef081003011000o36e85e27id29136a793347f8c@mail.gmail.com> Subject: Re: LinkList implementation From: Michael Hwang To: Andrey Borzenkov Cc: zsh-workers@zsh.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sun, Feb 28, 2010 at 4:06 AM, Andrey Borzenkov wro= te: > On Sunday 28 of February 2010 01:33:24 Michael Hwang wrote: >> In the process of writing a new builtin, I discovered an oddity of >> zsh's implementation of LinkList, which is a doubly linked list. >> >> LinkList alist =3D newlinklist(); >> LinkNode node; >> for (node =3D lastnode(alist); node; decnode(alist)) { >> =A0 =A0 =A0((SomeStructPointer) getdata(node))->someField; >> } >> > BTW decnode applies to node, not list - it should be decnode(node) Right, that's another typo on my part. >> Since no nodes have been added to the LinkList, one would expect the >> body of the loop to not run at all. > > Well, you have to accept that and use another termination condition, > like e.g. in zle_hist.c:isearch_newpos(): > > =A0 =A0 =A0 =A0for (node =3D lastnode(matchlist); > =A0 =A0 =A0 =A0 =A0 =A0 node !=3D (LinkNode)matchlist; decnode(node)) { > > For the sake of purity this actually should be > =A0 =A0 =A0 =A0 =A0 =A0 node !=3D &matchlist->node > > The games linklist.c plays are really daunting ... but to change it now > you have to carefully go through all of code to adjust snippets like > above. I solved my problem by simply reversing the direction I added on to the LinkList, and therefore the direction I walked through it. I'll see if I can't make the LinkList implementation simpler and more intuitive. These "gotcha!"'s are a bit annoying. Michael Hwang