Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: LinkList implementation
- X-seq: zsh-workers 27763
- From: Michael Hwang <michael.a.hwang@xxxxxxxxx>
- To: Andrey Borzenkov <arvidjaar@xxxxxxxxx>
- Subject: Re: LinkList implementation
- Date: Mon, 1 Mar 2010 13:00:56 -0500
- Cc: zsh-workers@xxxxxxx
- 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=
- In-reply-to: <201002281206.53953.arvidjaar@xxxxxxxxx>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <22a0ef081002271433u713e1923lb04c7d1bf369d3d0@xxxxxxxxxxxxxx> <201002281206.53953.arvidjaar@xxxxxxxxx>
On Sun, Feb 28, 2010 at 4:06 AM, Andrey Borzenkov <arvidjaar@xxxxxxxxx> wrote:
> 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 = newlinklist();
>> LinkNode node;
>> for (node = lastnode(alist); node; decnode(alist)) {
>> ((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():
>
> for (node = lastnode(matchlist);
> node != (LinkNode)matchlist; decnode(node)) {
>
> For the sake of purity this actually should be
> node != &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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author