News for hackers. Stuff that matters.
Re:Appending to an std:string character-by-character: how do... by foota on Thursday October 26, 2023 @06:52PM (#38032679)
Are there reasonable string implementations lacking 0(1) amortized append runtime?
Re:Appending to an std:string character-by-character: how do... by sltkr on Thursday October 26, 2023 @07:28PM (#38032964)
No, because appending with push_back() which strings must also support is required to have O(1) amortized time.

See my comment here for details: https://news.ycombinator.com/item?id=38032949

Re:Appending to an std:string character-by-character: how do... by kadoban on Thursday October 26, 2023 @07:04PM (#38032775)
Depends what you mean by reasonable I suppose. If you just implement it naively, either by growing by 1 or a constant amount each time, it'll be O(n) amortized.

I'd call those potentially reasonable, in that it works and it doesn't break the standard. I probably wouldn't be mad if a student did that impl, but I'd mention it.

I would be surprised if a well-supported, non-toy implementation without strange constraints (eg not for embedded and not trying to optimize solely for size or simplicity or something) did something other than amortized O(1).

Re:Appending to an std:string character-by-character: how do... by not2b on Friday October 27, 2023 @01:39AM (#38035068)
No, but there was an unreasonable one. Microsoft Foundation Classes, which preceded the STL. Originally, Their CString class extended the capacity in such a way that appending one character at a time had quadratic cost.
Re:Appending to an std:string character-by-character: how do... by rurban on Friday October 27, 2023 @04:14AM (#38035956)
It was just using the naive approach (grow by the exact size), the same idea as Google is now proposing. https://news.ycombinator.com/item?id=38033206