Edit report at http://bugs.php.net/bug.php?id=48358&edit=1

 ID:                 48358
 Comment by:         omercan at gmail dot com
 Reported by:        dannel at aaronexodus dot com
 Summary:            SplDoublyLinkedList needs an insertAfterIterator()
                     method or something similar
 Status:             Assigned
 Type:               Feature/Change Request
 Package:            SPL related
 PHP Version:        5.3.0RC2
 Assigned To:        colder
 Block user comment: N
 Private report:     N

 New Comment:

O(n) complexity should be expected from a list data structure along with
no array access. The drawback of lists is they lack direct access to the
elements by their position. Well, that's not the case with
SplDoublyLinkedList because there's array access. So, it's a different
implementation as far as it seems.



In my opinion, the problem with SplDoublyLinkedList is that the main
operations are left to be implemented in the user land, which require
iterating over the list in each. This class can be much more valuable if
the following operations are included:



clear() -> clear all elements



remove($value) -> return number of removals b/c $value can be more than
1



sort(Closure $predicate) -> sort without keeping key association



swap($list) -> swap with another list or a Traversable instance



unique() -> return the unique values in the list, possibly in a new list


Previous Comments:
------------------------------------------------------------------------
[2010-05-22 13:46:01] 1000235409 at smail dot shnu dot edn dot cn

i have encountered the same problem today, after this was modified for 1
year...



but i have a solution to solve this problem. write anohter class with a
lots of 

spldoublylinkedlists inside it. however, complex algorithm may be
used...

------------------------------------------------------------------------
[2009-05-21 17:02:15] dannel at aaronexodus dot com

Description:
------------
The SplDoublyLinkedList is great, but it lacks a way to insert a node
somewhere in the middle of the list.



One could technically extend the class and provide that functionality,
but due to the fact that there seem to be [documented] data members in
SplDoublyLinkedList, the only way to do it would be to find the
reference node, insert the new node, and move all of the following nodes
up one slot in the list, resulting in O(n) performance for an insert.



I propose adding an insertAfterIterator() method which would place the
new node after the current node the iterator points to.



Another option could be an insertAfterArrayKey() method which would act
similarly, but would find the reference node via a given array key,
which might be a little more straightforward to use in code.



Each should probably have an insertBefore*() counterpart as well.



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=48358&edit=1

Reply via email to