FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor


 
 
LinkBack Thread Tools
 
Old 04-21-2008, 05:46 AM
Sebastian Nowicki
 
Default alpm_list_last

I noticed that alpm_list_last simply returns a pointer to the previous
node. Is this expected behavior? My interpretation of "last" would be
to return the absolute last node, as the comment suggests. In my
opinion the function as it is now should be called alpm_list_prev.

From alpm_list.c:
> alpm_list_t SYMEXPORT *alpm_list_last(const alpm_list_t *list)
> {
> if(list) {
> return(list->prev);
> } else {
> return(NULL);
> }
> }

--
Sebastian Nowicki







_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 04-21-2008, 06:04 AM
Xavier
 
Default alpm_list_last

Sebastian Nowicki wrote:
> I noticed that alpm_list_last simply returns a pointer to the previous
> node. Is this expected behavior? My interpretation of "last" would be
> to return the absolute last node, as the comment suggests. In my
> opinion the function as it is now should be called alpm_list_prev.
>
> From alpm_list.c:
>> alpm_list_t SYMEXPORT *alpm_list_last(const alpm_list_t *list)
>> {
>> if(list) {
>> return(list->prev);
>> } else {
>> return(NULL);
>> }
>> }
>

That's because a alpm_list_t element is not really a list, but a list node.
So when you use a list in alpm (with alpm_list_t *list), it's actually
just the head node that you manipulate.
And head->prev == tail.

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 04-21-2008, 06:33 AM
Sebastian Nowicki
 
Default alpm_list_last

On 21/04/2008, at 2:04 PM, Xavier wrote:
> Sebastian Nowicki wrote:
>> I noticed that alpm_list_last simply returns a pointer to the
>> previous
>> node. Is this expected behavior? My interpretation of "last" would be
>> to return the absolute last node, as the comment suggests. In my
>> opinion the function as it is now should be called alpm_list_prev.
>>
>> From alpm_list.c:
>>> alpm_list_t SYMEXPORT *alpm_list_last(const alpm_list_t *list)
>>> {
>>> if(list) {
>>> return(list->prev);
>>> } else {
>>> return(NULL);
>>> }
>>> }
>>
>
> That's because a alpm_list_t element is not really a list, but a
> list node.
> So when you use a list in alpm (with alpm_list_t *list), it's actually
> just the head node that you manipulate.
> And head->prev == tail.
>
> _______________________________________________
> pacman-dev mailing list
> pacman-dev@archlinux.org
> http://archlinux.org/mailman/listinfo/pacman-dev


Ok, but there's also alpm_list_first and alpm_list_next. According to
your description alpm_list_first should be the same as alpm_list_next,
unless I misunderstood you. Since alpm_list_t is a node in a double
linked list, it is possible to be somewhere in the middle of a list.
Using alpm_list_last somewhere in a progrem, I would expect to go to
the absolute last node within the list in general. The doxygen comment
seems to suggest this as well, as it talks about a list in general,
and not the node (alpm_list_t). It just seems a bit confusing/
misleading to me, and possibly others looking at the documentation.

--
Sebastian Nowicki







_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 04-21-2008, 07:20 AM
Xavier
 
Default alpm_list_last

On Mon, Apr 21, 2008 at 8:33 AM, Sebastian Nowicki <sebnow@gmail.com> wrote:
>
> Ok, but there's also alpm_list_first and alpm_list_next. According to
> your description alpm_list_first should be the same as alpm_list_next,
> unless I misunderstood you.

You misunderstood.
What I was saying is illustrated by the implementation of
alpm_list_first, that is :
alpm_list_first(list) == list.

Because a list is just the head node.

> Since alpm_list_t is a node in a double
> linked list, it is possible to be somewhere in the middle of a list.

It's a convention to use the head node when manipulating a list.
Otherwise, how would you know where the head is?
Besides, you must have this propriety : list->prev == tail
If you use a node in the middle of a list, this is simply not true.

> Using alpm_list_last somewhere in a progrem, I would expect to go to
> the absolute last node within the list in general. The doxygen comment
> seems to suggest this as well, as it talks about a list in general,
> and not the node (alpm_list_t). It just seems a bit confusing/
> misleading to me, and possibly others looking at the documentation.
>

That's because most functions are made to work with list (== head
nodes), and not a middle node.
It's very simple really, I have the feeling that I make it look more
complicated than it really is.

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 04-21-2008, 09:23 AM
Sebastian Nowicki
 
Default alpm_list_last

On 21/04/2008, at 3:20 PM, Xavier wrote:
> On Mon, Apr 21, 2008 at 8:33 AM, Sebastian Nowicki
> <sebnow@gmail.com> wrote:
>>
>> Ok, but there's also alpm_list_first and alpm_list_next. According to
>> your description alpm_list_first should be the same as
>> alpm_list_next,
>> unless I misunderstood you.
>
> You misunderstood.
> What I was saying is illustrated by the implementation of
> alpm_list_first, that is :
> alpm_list_first(list) == list.
>
> Because a list is just the head node.
>
>> Since alpm_list_t is a node in a double
>> linked list, it is possible to be somewhere in the middle of a list.
>
> It's a convention to use the head node when manipulating a list.
> Otherwise, how would you know where the head is?
> Besides, you must have this propriety : list->prev == tail
> If you use a node in the middle of a list, this is simply not true.
>
>> Using alpm_list_last somewhere in a progrem, I would expect to go to
>> the absolute last node within the list in general. The doxygen
>> comment
>> seems to suggest this as well, as it talks about a list in general,
>> and not the node (alpm_list_t). It just seems a bit confusing/
>> misleading to me, and possibly others looking at the documentation.
>>
>
> That's because most functions are made to work with list (== head
> nodes), and not a middle node.
> It's very simple really, I have the feeling that I make it look more
> complicated than it really is.
>
> _______________________________________________
> pacman-dev mailing list
> pacman-dev@archlinux.org
> http://archlinux.org/mailman/listinfo/pacman-dev

It makes sense now. I didn't realise that it was a circular list
(might be worth mentioning).

--
Sebastian Nowicki


--
Sebastian Nowicki







_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 04-21-2008, 09:52 AM
Xavier
 
Default alpm_list_last

On Mon, Apr 21, 2008 at 11:23 AM, Sebastian Nowicki <sebnow@gmail.com> wrote:
>
> It makes sense now. I didn't realise that it was a circular list
> (might be worth mentioning).
>

Ah right, I should have just said that. Maybe I didn't because I
wasn't sure if it's really a typical circular list.
It's a double linked list, which is circular when going backward with
->prev pointer, but not when going forward with ->next pointer.
Because for walking through a list, we always do something like :
for(i = dblist; i; i = i->next) {
...
}

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 

Thread Tools




All times are GMT. The time now is 05:07 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org