Re: Some new list.c primitives

Lists: pgsql-hackers
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Some new list.c primitives
Date: 2005-07-27 22:01:21
Message-ID: 11663.1122501681@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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;
}


From: Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Neil Conway <neilc(at)samurai(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Some new list.c primitives
Date: 2005-07-28 00:06:46
Message-ID: Pine.LNX.4.58.0507281002130.32074@linuxworld.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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


From: David Fetter <david(at)fetter(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Neil Conway <neilc(at)samurai(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Some new list.c primitives
Date: 2005-07-28 00:25:32
Message-ID: 20050728002532.GD6635@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Fetter <david(at)fetter(dot)org>
Cc: Neil Conway <neilc(at)samurai(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Some new list.c primitives
Date: 2005-07-28 00:32:00
Message-ID: 13519.1122510720@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Fetter <david(at)fetter(dot)org> 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


From: Neil Conway <neilc(at)samurai(dot)com>
To: Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Some new list.c primitives
Date: 2005-07-28 01:40:52
Message-ID: 42E837A4.4050006@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Some new list.c primitives
Date: 2005-07-28 02:55:50
Message-ID: 14418.1122519350@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Neil Conway <neilc(at)samurai(dot)com> 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


From: Neil Conway <neilc(at)samurai(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Some new list.c primitives
Date: 2005-07-28 05:12:49
Message-ID: 42E86951.1060905@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> How about list_append_distinct and list_concat_distinct?

Those names are fine with me.

-Neil


From: Thomas Swan <thomas(dot)swan(at)gmail(dot)com>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Some new list.c primitives
Date: 2005-07-28 17:50:05
Message-ID: abb19e6c050728105067790f8d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 7/28/05, Neil Conway <neilc(at)samurai(dot)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.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Swan <thomas(dot)swan(at)gmail(dot)com>
Cc: Neil Conway <neilc(at)samurai(dot)com>, Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Some new list.c primitives
Date: 2005-07-28 18:42:50
Message-ID: 26018.1122576170@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thomas Swan <thomas(dot)swan(at)gmail(dot)com> writes:
> On 7/28/05, Neil Conway <neilc(at)samurai(dot)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.

I like those too --- sold, unless anyone objects?

regards, tom lane