Re: [PATCH 04/16] Add embedded list interface (header only)

Поиск
Список
Период
Сортировка
От Marko Kreen
Тема Re: [PATCH 04/16] Add embedded list interface (header only)
Дата
Msg-id CACMqXCJwjRAxhOZ6UP0yKzLmEbjCFQ9r2C93FwgzcG-0Bk76YQ@mail.gmail.com
обсуждение исходный текст
Ответ на [PATCH 04/16] Add embedded list interface (header only)  (Andres Freund <andres@2ndquadrant.com>)
Ответы Re: [PATCH 04/16] Add embedded list interface (header only)  (Andres Freund <andres@2ndquadrant.com>)
Список pgsql-hackers
On Wed, Jun 13, 2012 at 2:28 PM, Andres Freund <andres@2ndquadrant.com> wrote:
> +/*
> + * removes a node from a list
> + * Attention: O(n)
> + */
> +static inline void ilist_s_remove(ilist_s_head *head,
> +                                  ilist_s_node *node)
> +{
> +       ilist_s_node *last = &head->head;
> +       ilist_s_node *cur;
> +#ifndef NDEBUG
> +       bool found = false;
> +#endif
> +       while ((cur = last->next))
> +       {
> +               if (cur == node)
> +               {
> +                       last->next = cur->next;
> +#ifndef NDEBUG
> +                       found = true;
> +#endif
> +                       break;
> +               }
> +               last = cur;
> +       }
> +       assert(found);
> +}

This looks weird.

In cyclic list removal is:
 node->prev->next = node->next; node->next->prev = node->prev;

And thats it.

--
marko


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: [PATCH 04/16] Add embedded list interface (header only)
Следующее
От: Andres Freund
Дата:
Сообщение: Re: [PATCH 04/16] Add embedded list interface (header only)