[PEPr] Comment on Structures::Structures_Linked_List
| From: | David Soria Parra | Date: | Thu, 14 Sep 2006 17:59:48 +0000 |
| Subject: | [PEPr] Comment on Structures::Structures_Linked_List | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-43938@lists.php.net to get a copy of this message | ||
David Soria Parra (http://pear.php.net/user/dsp) has commented on the proposal for
Structures::Structures_Linked_List.
Comment:
Not tested the code right now on my machine but I looked into the code and
have a few suggestions. First of all I think a kind of sort whould be
nice. I think a callback mechanism is quite usual for linked lists.
function callback(My_Structures_Linked_List_Node $a,
My_Structures_Linked_List_Node $b) {
if ($a->data > $b->data) {
return 1;
} else if ($a->data == $b->data) {
return 0;
} else {
return -1;
}
}
The list check if the callback returns -1 while inserting and appends
either before or after the current node depending on the settings
(STRUCTURES_LINKED_LIST_ADD_BEFORE, STRUCTURES_LINKED_LIST_ADD_AFTER).
This could be usefull to implement a priority queue using the linked list.
An ADD_APEND option is not needed any longer, because it can be handled
using an callback that only returns -1-
Also you should use type hinting if you the package allready depends on
PHP 5 (but i'm not sure if that corresponde with the pear coding styles).
So:
public function addNode(Structures_Linked_List_Node $new_node)
Nice approch
greets
Proposal information:
http://pear.php.net/pepr/pepr-proposal-show.php?id=444
--
Sent by PEPr, the automatic proposal system at http://pear.php.net