[HN Gopher] Appending to an std:string character-by-character: h...
___________________________________________________________________
Appending to an std:string character-by-character: how does the
capacity grow?
Author : greghn
Score : 16 points
Date : 2023-10-26 16:34 UTC (6 hours ago)
(HTM) web link (lemire.me)
(TXT) w3m dump (lemire.me)
| pacaro wrote:
| This is, of course, the same mechanism that allows appending to
| an ArrayList in Java to be O (1), or at least amortized too such
| kadoban wrote:
| Interestingly, the C++ standard doesn't specify a cost for
| this, or an implementation. So there could be some C++
| implementation out there somewhere that just copies the whole
| string on each append.
|
| This is in contrast to std::vector, where the cost of adding
| one element to the end _is_ specified to be amortized O(1).
| foota wrote:
| Are there reasonable string implementations lacking 0(1)
| amortized append runtime?
___________________________________________________________________
(page generated 2023-10-26 23:00 UTC)