Hot take: using `+` as the "concatenation operator" is evil. `+` should form an abelian group. `*` is obviously the natural choice for concatenation, as it only needs to form a monoid.
Push can't be amortized O(1) if you use an array representation. If you don't, other operations will be slowish, but you can possibly make everything O(log n).
-
-
Yes it can? Assuming the standard array representation used by say, C++ or Rust
-
Sorry I was figuring it wrong. It's possible just expensive in storage and in worst-case individual op.
-
true, but it's generally how mutable strings are implemented in langs like C++/Rust.
-
If you're doing any serious text processing, you're probably better off switching to ropes :shrug:
-
and if you're doing anything that requires a bunch of strings, require fast comparison and a lot of the strings are repeated, you're better off switching to an identifier-style system.
-
array based strings are just a nice middle ground which aren't especially good for anything in particular, but also aren't especially bad for anything in particular
End of conversation
New conversation -
-
-
But all this (eg exponential allocation strategy) requires wasting lots of space in typical cases.
-
that's exactly how Rust and C++ work tho
-
Yes, and that's why Firefox and Chrome use 10+ GB... ;-)
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.