On Tue, Dec 27, 2011 at 12:02 AM, wang qin <scpl0...@gmail.com> wrote:
> Dear,
>
> This is the double circle queue. But the operations are not enqueue
> the circle queue.
> Below is the standard operations:
>
>        if (!base->server_head) {
>                ns->next = ns->prev = ns;
>                base->server_head = ns;
>        } else {
>                ns->next = base->server_head->next;
>                ns->prev = base->server_head;
>                base->server_head->next = ns;
>                if (base->server_head->prev == base->server_head) {
>                        base->server_head->prev = ns;
>                }else{
>                      base->server_head->next->next-prev = ns;
>                }
>        }

Ah, now I get what you were trying to say.  But there's an even
simpler implementation:


        if (!base->server_head) {
                ns->next = ns->prev = ns;
                base->server_head = ns;
        } else {
                ns->next = base->server_head->next;
                ns->prev = base->server_head;
                base->server_head->next = ns;
                ns->next->prev = ns;
        }

I'm adding this to patches-2.0 for the next release (commit
d6094b160f63fa6c6279), and marking that the whole  data structure
should probably turn into a CIRCLEQ in 2.1.

yrs,
-- 
Nick
***********************************************************************
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-users    in the body.

Reply via email to