Re: ilist.h is not useful as-is

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: ilist.h is not useful as-is
Дата
Msg-id 25058.1374680960@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: ilist.h is not useful as-is  (Andres Freund <andres@2ndquadrant.com>)
Ответы Re: ilist.h is not useful as-is  (Andres Freund <andres@2ndquadrant.com>)
Список pgsql-hackers
Andres Freund <andres@2ndquadrant.com> writes:
> On 2013-07-24 11:26:00 -0400, Tom Lane wrote:
>> So I'm going to end up hand-implementing the same kind of manipulation
>> we frequently use with traditional Lists, namely keep a second variable
>> that's the preceding list element (not the next one) so I can unlink and
>> delete the target element when I find it.  ilist.h is not offering me
>> any useful support at all for this scenario.  Seems like we're missing
>> a bet here.

> Hm. Yes. This should be added. I didn't need it so far, but I definitely
> can see usecases.
> slist_delete_current(slist_mutable_iter *)?
> I am willing to cough up a patch if you want.

Please.

> This will require another member variable in slist_mutable_iter which
> obviously will need to be maintained, but that seems fine to me since it
> will reduce the cost of actually deleting noticeably.

I think that's all right.  Conceivably we could introduce two forms of
iterator depending on whether you want to delete or not, but that seems
like overkill to me.

In fact, now that I think about it, the distinction between slist_iter
and slist_mutable_iter is really misstated in the comments, isn't it?
The *only* action on the list that's unsafe with an active slist_iter
is to delete the current element (and then continue iterating).
If the value of slist_mutable_iter is to support deletion of the current
element, then it seems obvious that it should support doing so
efficiently, ie it should carry both prev and next.  Also, if it's
carrying both of those, then use of slist_mutable_iter really doesn't
allow any action other than deleting the current element --- adding
new nodes "ahead" of the current element isn't safe.
        regards, tom lane



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

Предыдущее
От: Vik Fearing
Дата:
Сообщение: Re: [GENERAL] Insert result does not match record count
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: ilist.h is not useful as-is