Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 19, 2010 [Issue 4348] New: std.container.SList append | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=4348 Summary: std.container.SList append Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2010-06-19 12:52:03 PDT --- This shows how you can append to a std.container.SList: import std.container: SList; void main() { auto l = SList!int(1, 2); l.insertAfter(l[], 3); } But the standard D syntax too can be supported, despite it's O(n): import std.container: SList; void main() { auto l = SList!int(1, 2); l ~= 3; } (The member function "insertFront" might be named "prepend", that is shorter , equally readable and contains no upper case letters). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 19, 2010 [Issue 4348] std.container.SList append | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4348 Andrei Alexandrescu <andrei@metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrei@metalanguage.com --- Comment #1 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-06-19 14:51:02 PDT --- ~= is only for containers that can implement it in time independent of the size of the container. Writing s.insertAfter(s[], value) hints the user that the cost is higher (i.e. proportional to the length of s[]). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 19, 2010 [Issue 4348] std.container.SList append | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4348 --- Comment #2 from bearophile_hugs@eml.cc 2010-06-19 15:20:42 PDT --- Answer to Comment 1: thank you for your answer, I didn't know about this rule. In arrays the append can require a full array copy, so it can be O(n), but it's (hopefully) O(1) on amortized time. If this rule is present and well established then you can close this bug report (the suggestion about the "prepend" name is for you, but you can ignore it if you don't like it). Another possibility is to find a compromise: instead of writing something hairy like: s.insertAfter(s[], value) You can use: s.linearAppend(value) That is less noisy and equally clear in its complexity :-) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 20, 2010 [Issue 4348] std.container.SList append | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4348 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |WONTFIX -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation