Some new list.c primitives

Поиск
Список
Период
Сортировка
Искать

Some new list.c primitives

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Neil (or anyone else with an opinion),

I'm finding several uses in the planner for some new List primitives
defined as below.  I'd like to push these into list.c, but before that,
has anyone got any serious objections?  How about suggestions for better
names?
		regards, tom lane



/** list_add adds the datum to the list if it's not already a member* (membership is determined by equal()).*/
static List *
list_add(List *list, void *datum)
{   if (list_member(list, datum))       return list;   else       return lappend(list, datum);
}

/** list_add_all does list_add for each element of list2.  This is effectively* the same as list_union(), except that list1 is modified in-place rather* than being copied.*/
static List *
list_add_all(List *list1, List *list2)
{   ListCell   *cell;
   foreach(cell, list2)   {       if (!list_member(list1, lfirst(cell)))           list1 = lappend(list1, lfirst(cell));   }
   return list1;
}

Re: Some new list.c primitives

От:
Gavin Sherry <swm@linuxworld.com.au>
Дата:
On Wed, 27 Jul 2005, Tom Lane wrote:

> Neil (or anyone else with an opinion),
>
> I'm finding several uses in the planner for some new List primitives
> defined as below.  I'd like to push these into list.c, but before that,
> has anyone got any serious objections?  How about suggestions for better
> names?

list_add() doesn't really describe what it does. I was thinking either
list_cond_add() or list_merge().

I think list_add_all is also ambiguous. What about list_merge_all() or,
even, list_merge_list()?

Gavin

Re: Some new list.c primitives

От:
David Fetter <david@fetter.org>
Дата:
On Wed, Jul 27, 2005 at 06:01:21PM -0400, Tom Lane wrote:
> Neil (or anyone else with an opinion),
> 
> I'm finding several uses in the planner for some new List primitives
> defined as below.  I'd like to push these into list.c, but before that,
> has anyone got any serious objections?  How about suggestions for better
> names?
> 
> 			regards, tom lane
> 
> 
> 
> /*
>  * list_add adds the datum to the list if it's not already a member
>  * (membership is determined by equal()).
>  */
> static List *
> list_add(List *list, void *datum)
> {
>     if (list_member(list, datum))
>         return list;
>     else
>         return lappend(list, datum);
> }

How about list_push for both of these?  This opens the door for
possible future functionality like list_pop, list_shift,
list_unshift...

Just my uneducated $.02.

Cheers,
D
-- 
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Re: Some new list.c primitives

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
David Fetter  writes:
> How about list_push for both of these?

list_push to me would connote the functionality of lappend, ie,
unconditionally add the item to the list.
		regards, tom lane

Re: Some new list.c primitives

От:
Neil Conway <neilc@samurai.com>
Дата:
Gavin Sherry wrote:
> list_add() doesn't really describe what it does.

I agree -- the functionality itself is fine, of course, but it would be 
nice to have a better name.

> I was thinking either list_cond_add() or list_merge().

What about list_append_distinct()? (And list_append_all_distinct() for 
the "merge two lists" case.)

-Neil

Re: Some new list.c primitives

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Neil Conway  writes:
> I agree -- the functionality itself is fine, of course, but it would be 
> nice to have a better name.

Those were just the first names that came to mind, and of course the
reason I asked is that I felt they could be improved upon...

>> I was thinking either list_cond_add() or list_merge().

> What about list_append_distinct()? (And list_append_all_distinct() for 
> the "merge two lists" case.)

How about list_append_distinct and list_concat_distinct?
		regards, tom lane

Re: Some new list.c primitives

От:
Neil Conway <neilc@samurai.com>
Дата:
Tom Lane wrote:
> How about list_append_distinct and list_concat_distinct?

Those names are fine with me.

-Neil

Re: Some new list.c primitives

От:
Thomas Swan <thomas.swan@gmail.com>
Дата:
On 7/28/05, Neil Conway <neilc@samurai.com> wrote:
Tom Lane wrote:
> How about list_append_distinct and list_concat_distinct?

Those names are fine with me.

list_append_unique and list_concat_unique might be a little clearer, unless you want to retain the sqlism of distinct.

Re: Some new list.c primitives

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Thomas Swan  writes:
> On 7/28/05, Neil Conway  wrote:
>> Tom Lane wrote:
>>> How about list_append_distinct and list_concat_distinct?

>> Those names are fine with me.

> list_append_unique and list_concat_unique might be a little clearer, unless
> you want to retain the sqlism of distinct.

I like those too --- sold, unless anyone objects?
		regards, tom lane

FAQ