From: <ny...@us...> - 2007-02-07 15:50:54
|
Revision: 307 http://svn.sourceforge.net/pmplib/?rev=307&view=rev Author: nyaochi Date: 2007-02-07 07:50:54 -0800 (Wed, 07 Feb 2007) Log Message: ----------- Append a new element at the bottom of the tail (linked list pointed by an AVL tree node), rather than at the beginning of the tail. I'm not sure the specification about the ordering of elements in a tail at this moment, but this can solve the problem where tracks in a playlist are arranged in reversed order. This is not a perfect solution; I need to investigate the ordering later. Modified Paths: -------------- trunk/pmplib/lib/pmp_iriverplus3/idx.c Modified: trunk/pmplib/lib/pmp_iriverplus3/idx.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/idx.c 2007-02-07 14:11:15 UTC (rev 306) +++ trunk/pmplib/lib/pmp_iriverplus3/idx.c 2007-02-07 15:50:54 UTC (rev 307) @@ -886,12 +886,24 @@ } else { /* The same here. We must obtain the pointer to the node after avltail_new() call. */ - uint32_t offset_tail = avltail_new(idx->avl); + uint32_t offset_newelem = avltail_new(idx->avl); avlnode_t* node = avlnode(idx->avl, offset); - avltail_t* tail = (avltail_t*)avlnode(idx->avl, offset_tail); - tail->data = entry->offset; - tail->next = node->tail; - node->tail = offset_tail; + avltail_t* newelem = (avltail_t*)avlnode(idx->avl, offset_newelem); + if (node->tail) { + /* Append to the end of the linked list. */ + avltail_t* elem = (avltail_t*)avlnode(idx->avl, node->tail); + while (elem->next) { + elem = (avltail_t*)avlnode(idx->avl, elem->next); + } + elem->next = offset_newelem; + newelem->data = entry->offset; + newelem->next = 0; + } else { + /* The first element in the linked list. */ + node->tail = offset_newelem; + newelem->data = entry->offset; + newelem->next = 0; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |