Yes, except that the amount of over-allocation is proportional to the current size of the array, rather than being some fixed amount. This turns out to be important to achieve amortized constant time for push!
. This is the same behavior of pretty much any other dynamic array type (like std::vector
in C++).
This seems like unnecessary complexity. Try just using push!
or append!
first and see if that is sufficient.