-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Request #48358 insertBeforeOffset() and insertAfterOffset() methods for ... #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…or SplDoublyLinkedList Adds new methods to insert a node in the middle of the dll object
…plDoublyLinkedList Modify code to use correct /* */ commenting and ensure that all indents are tabs rather than spaces
…plDoublyLinkedList Additional tests for function argument validation
Previous discussion on this: https://bugs.php.net/bug.php?id=48358 I agree that doubly linked lists need this ability to add elements in their inner content. The implementation seems OK (+- whitespaces). I however have some concern that with that patch, they interface of DLL becomes (even more) odd: To modify the content, you have: offsetSet, offsetUnset, and insertAfterOffset, insertBeforeOffset |
What are you suggesting: that they should be offsetInsertBefore() and offsetInsertAfter()? |
Well, I'm not sure, since offset* comes from ArrayAccess. But I would rather have some general-purpose discussion about interfaces of collections rather than adding one method at a time that we will not be able to rename in the future. |
I honestly fear that we are not reaching a conclusion on how to name the interfaces (and particularly as we cannot rename existing methods). Nevertheless I do think a linkedlist must have these methods similar methods to add elements to after an arbitrary poisiton. |
After an discussion with @colder, I think the best way to go is dropping insertAfter and adding a
similar to Javas API. It behaves like insertBefore. The insertAfter can be easily written as a userland function using the add method. This way we keep things simple and our interface is similar to the Java LinkedList and C# LinkedList EDIT: NInja edit. Java add behaves like insertBefore not insertAfter.. |
👍 since |
The only argument I can think of for having both before and after versions is for after with an index of the last entry, effectively pushing a new value; but as push() is already available, this functionality is already available anyway. |
…plDoublyLinkedList Removed DLL insertAfterOffset() method; and renamed insertBeforeOffset() as add() Modified add() to handle a push if specified index = count of elements already in the DLL, while still adding before the specified index otherwise Adjusted tests accordingly to reflect the changes
Changes duly made as suggested to provide a single add() method |
This suggestion might be a bit iffy, but I'd quite like a |
I think if you want to push to the linked list, you would use push. It makes much more sense and is more readable than add(null, $value) |
I dont think we should handle NULL special. Anyway the patch looks good to me and if there are no objections I will merge it before beta1. |
Sounds good to me. 🐹 |
SEPARATE_ARG_IF_REF(value); | ||
|
||
intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC); | ||
index = (int)spl_offset_convert_to_long(zindex TSRMLS_CC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this have an (int) cast? index is declared as long, so the types should match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly for the same reason that I wasn't certain why offsetUnset() also casts to int, while other methods like offsetExists() and offsetGet() don't: I wasn't sure if I was missing something elsewhere in the code, and preferred to err on the side of caution.... or is offsetUnset() also wrong in this cast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems wrong to me, I will fix offsetunset.
EDIT: Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I'll happily change add() and push again
Don't cast index to an int, leave it as a long
I squashed the branch to one commit and removed the newline changes and pushed it as 4257469. Thanks for the pull request. |
...SplDoublyLinkedList
Adds new methods to insert a node in the middle of the dll object