making vector push-front improved to O(1) / 8192
Last question, on StackOverflow.com about speeding vector.push_back and push_front was said to have it's place here. So here it is :
Well well well, looks like, after work, my regenerating reserve vector may not be so bad after all ? (in question "44326712/speeding-vector-push-back", I presented a vector with a regenerating reserve, faster at push_back when reserve cant be predicted).
Deque may be cool, but faster is the vector.
So I ameliorated my Vector, with two reserves : one before the begin and another after the end, thus, enabling push_front in a vector very quickly (push_back is still better than normal vector).
With a RESA of 8192, and 1000 push_front, I had this results (computer is a Lenovo Think Center):
duration old push_front == 199 ticks ("insert (v.begin () , s)")
duration new push_front == 5 ticks
And here is the Code of my Vector :
#ifndef __VECTOR2_HPP
#define __VECTOR2_HPP
#include <vector>
#include <iostream>
#include "Concept.hpp"
#include <exception>
#include <algorithm>
template <typename T>
class Vector : public std::vector<T> {
public :
class Error : public std::exception {
public :
Error (std::string val = "") throw () : val_ (val) {}
~Error () throw () {}
const char* what () throw () {
std::string s ("Vector Error :");
s += val_;
return s.c_str();
}
private :
std::string val_;
};
typename std::vector<T>::iterator begin () {
typename std::vector<T>::iterator i (std::vector<T>::begin ());
i += lresa_;
return i;
}
typename std::vector<T>::iterator end () {
typename std::vector<T>::iterator i (std::vector<T>::end ());
i -= rresa_;
return i;
}
typename std::vector<T>::const_iterator begin () const {
typename std::vector<T>::const_iterator i (std::vector<T>::begin ());
i += lresa_;
return i;
}
typename std::vector<T>::const_iterator end () const {
typename std::vector<T>::const_iterator i (std::vector<T>::end ());
i -= rresa_;
return i;
}
typename std::vector<T>::reverse_iterator rbegin () {
typename std::vector<T>::reverse_iterator i (std::vector<T>::rbegin ());
i += rresa_;
return i;
}
typename std::vector<T>::reverse_iterator rend () {
typename std::vector<T>::reverse_iterator i (std::vector<T>::rend ());
i -= lresa_;
return i;
}
typename std::vector<T>::const_reverse_iterator rbegin () const {
typename std::vector<T>::const_reverse_iterator i (std::vector<T>::rbegin ());
i += rresa_;
return i;
}
typename std::vector<T>::const_reverse_iterator rend () const {
typename std::vector<T>::const_reverse_iterator i (std::vector<T>::rend ());
i -= lresa_;
return i;
}
Vector () : std::vector<T> (2*(size_t) Concept::RESA, T()), lresa_ ((size_t) Concept::RESA), rresa_ ((size_t) Concept::RESA) {
}
size_t size () const {
size_t s (std::vector<T>::size ());
s -= lresa_;
s -= rresa_;
return s;
}
Vector (int n, T t0) : std::vector<T> (n + 2*(size_t) Concept::RESA, t0), lresa_ ((size_t) Concept::RESA), rresa_ ((size_t) Concept::RESA) {
}
Vector (const Vector& v) : std::vector<T> (v), lresa_ (v.lresa_), rresa_ (v.rresa_) {
}
bool operator == (const Vector& v) const {
return std::equal (begin (), end (), v.begin ());
}
bool operator != (const Vector& v) const {
return !operator == (v);
}
T& operator (const size_t &s) {
return std::vector<T>::operator (s+lresa_);
}
void push_front (const T& t) {
if (!lresa_) {
std::vector<T>::insert (std::vector<T>::begin (), (size_t) Concept::RESA, t);
lresa_ = (size_t) Concept::RESA;
}
typename std::vector<T>::iterator i (std::vector<T>::begin ());
i += lresa_ -1;
*i = t;
--lresa_;
}
void push_back (const T& t) {
if (!rresa_) {
std::vector<T>::insert (std::vector<T>::end (), (size_t) Concept::RESA, t);
rresa_ = (size_t) Concept::RESA;
}
typename std::vector<T>::iterator i (std::vector<T>::end ());
i -= rresa_;
*i = t;
--rresa_;
}
//can be optimized,but that s not the topic
Vector& operator = (const Vector& v) {
std::vector<T>::operator = (v);
lresa_ = v.lresa_;
rresa_ = v.rresa_;
return *this;
}
//intelligent resize to do
//at the moment just stupid
void resize (size_t n) {
std::vector<T>::resize (n + lresa_ + rresa_);
}
private :
size_t lresa_;
size_t rresa_;
};
#endif
What do you think about it ?
c++ c++11
New contributor
add a comment |
Last question, on StackOverflow.com about speeding vector.push_back and push_front was said to have it's place here. So here it is :
Well well well, looks like, after work, my regenerating reserve vector may not be so bad after all ? (in question "44326712/speeding-vector-push-back", I presented a vector with a regenerating reserve, faster at push_back when reserve cant be predicted).
Deque may be cool, but faster is the vector.
So I ameliorated my Vector, with two reserves : one before the begin and another after the end, thus, enabling push_front in a vector very quickly (push_back is still better than normal vector).
With a RESA of 8192, and 1000 push_front, I had this results (computer is a Lenovo Think Center):
duration old push_front == 199 ticks ("insert (v.begin () , s)")
duration new push_front == 5 ticks
And here is the Code of my Vector :
#ifndef __VECTOR2_HPP
#define __VECTOR2_HPP
#include <vector>
#include <iostream>
#include "Concept.hpp"
#include <exception>
#include <algorithm>
template <typename T>
class Vector : public std::vector<T> {
public :
class Error : public std::exception {
public :
Error (std::string val = "") throw () : val_ (val) {}
~Error () throw () {}
const char* what () throw () {
std::string s ("Vector Error :");
s += val_;
return s.c_str();
}
private :
std::string val_;
};
typename std::vector<T>::iterator begin () {
typename std::vector<T>::iterator i (std::vector<T>::begin ());
i += lresa_;
return i;
}
typename std::vector<T>::iterator end () {
typename std::vector<T>::iterator i (std::vector<T>::end ());
i -= rresa_;
return i;
}
typename std::vector<T>::const_iterator begin () const {
typename std::vector<T>::const_iterator i (std::vector<T>::begin ());
i += lresa_;
return i;
}
typename std::vector<T>::const_iterator end () const {
typename std::vector<T>::const_iterator i (std::vector<T>::end ());
i -= rresa_;
return i;
}
typename std::vector<T>::reverse_iterator rbegin () {
typename std::vector<T>::reverse_iterator i (std::vector<T>::rbegin ());
i += rresa_;
return i;
}
typename std::vector<T>::reverse_iterator rend () {
typename std::vector<T>::reverse_iterator i (std::vector<T>::rend ());
i -= lresa_;
return i;
}
typename std::vector<T>::const_reverse_iterator rbegin () const {
typename std::vector<T>::const_reverse_iterator i (std::vector<T>::rbegin ());
i += rresa_;
return i;
}
typename std::vector<T>::const_reverse_iterator rend () const {
typename std::vector<T>::const_reverse_iterator i (std::vector<T>::rend ());
i -= lresa_;
return i;
}
Vector () : std::vector<T> (2*(size_t) Concept::RESA, T()), lresa_ ((size_t) Concept::RESA), rresa_ ((size_t) Concept::RESA) {
}
size_t size () const {
size_t s (std::vector<T>::size ());
s -= lresa_;
s -= rresa_;
return s;
}
Vector (int n, T t0) : std::vector<T> (n + 2*(size_t) Concept::RESA, t0), lresa_ ((size_t) Concept::RESA), rresa_ ((size_t) Concept::RESA) {
}
Vector (const Vector& v) : std::vector<T> (v), lresa_ (v.lresa_), rresa_ (v.rresa_) {
}
bool operator == (const Vector& v) const {
return std::equal (begin (), end (), v.begin ());
}
bool operator != (const Vector& v) const {
return !operator == (v);
}
T& operator (const size_t &s) {
return std::vector<T>::operator (s+lresa_);
}
void push_front (const T& t) {
if (!lresa_) {
std::vector<T>::insert (std::vector<T>::begin (), (size_t) Concept::RESA, t);
lresa_ = (size_t) Concept::RESA;
}
typename std::vector<T>::iterator i (std::vector<T>::begin ());
i += lresa_ -1;
*i = t;
--lresa_;
}
void push_back (const T& t) {
if (!rresa_) {
std::vector<T>::insert (std::vector<T>::end (), (size_t) Concept::RESA, t);
rresa_ = (size_t) Concept::RESA;
}
typename std::vector<T>::iterator i (std::vector<T>::end ());
i -= rresa_;
*i = t;
--rresa_;
}
//can be optimized,but that s not the topic
Vector& operator = (const Vector& v) {
std::vector<T>::operator = (v);
lresa_ = v.lresa_;
rresa_ = v.rresa_;
return *this;
}
//intelligent resize to do
//at the moment just stupid
void resize (size_t n) {
std::vector<T>::resize (n + lresa_ + rresa_);
}
private :
size_t lresa_;
size_t rresa_;
};
#endif
What do you think about it ?
c++ c++11
New contributor
2
It cannot be O(1) as you sometime need to grow the vector and move items.. Maybe amortized O(1)?
– Phil1970
1 hour ago
1
Folks: Be nice to one another and to everyone else. Make critique not about the person, but about the code.
– Vogel612♦
59 mins ago
this Vector insert begin at O(1) / some constant
– Saint-Martin
55 mins ago
add a comment |
Last question, on StackOverflow.com about speeding vector.push_back and push_front was said to have it's place here. So here it is :
Well well well, looks like, after work, my regenerating reserve vector may not be so bad after all ? (in question "44326712/speeding-vector-push-back", I presented a vector with a regenerating reserve, faster at push_back when reserve cant be predicted).
Deque may be cool, but faster is the vector.
So I ameliorated my Vector, with two reserves : one before the begin and another after the end, thus, enabling push_front in a vector very quickly (push_back is still better than normal vector).
With a RESA of 8192, and 1000 push_front, I had this results (computer is a Lenovo Think Center):
duration old push_front == 199 ticks ("insert (v.begin () , s)")
duration new push_front == 5 ticks
And here is the Code of my Vector :
#ifndef __VECTOR2_HPP
#define __VECTOR2_HPP
#include <vector>
#include <iostream>
#include "Concept.hpp"
#include <exception>
#include <algorithm>
template <typename T>
class Vector : public std::vector<T> {
public :
class Error : public std::exception {
public :
Error (std::string val = "") throw () : val_ (val) {}
~Error () throw () {}
const char* what () throw () {
std::string s ("Vector Error :");
s += val_;
return s.c_str();
}
private :
std::string val_;
};
typename std::vector<T>::iterator begin () {
typename std::vector<T>::iterator i (std::vector<T>::begin ());
i += lresa_;
return i;
}
typename std::vector<T>::iterator end () {
typename std::vector<T>::iterator i (std::vector<T>::end ());
i -= rresa_;
return i;
}
typename std::vector<T>::const_iterator begin () const {
typename std::vector<T>::const_iterator i (std::vector<T>::begin ());
i += lresa_;
return i;
}
typename std::vector<T>::const_iterator end () const {
typename std::vector<T>::const_iterator i (std::vector<T>::end ());
i -= rresa_;
return i;
}
typename std::vector<T>::reverse_iterator rbegin () {
typename std::vector<T>::reverse_iterator i (std::vector<T>::rbegin ());
i += rresa_;
return i;
}
typename std::vector<T>::reverse_iterator rend () {
typename std::vector<T>::reverse_iterator i (std::vector<T>::rend ());
i -= lresa_;
return i;
}
typename std::vector<T>::const_reverse_iterator rbegin () const {
typename std::vector<T>::const_reverse_iterator i (std::vector<T>::rbegin ());
i += rresa_;
return i;
}
typename std::vector<T>::const_reverse_iterator rend () const {
typename std::vector<T>::const_reverse_iterator i (std::vector<T>::rend ());
i -= lresa_;
return i;
}
Vector () : std::vector<T> (2*(size_t) Concept::RESA, T()), lresa_ ((size_t) Concept::RESA), rresa_ ((size_t) Concept::RESA) {
}
size_t size () const {
size_t s (std::vector<T>::size ());
s -= lresa_;
s -= rresa_;
return s;
}
Vector (int n, T t0) : std::vector<T> (n + 2*(size_t) Concept::RESA, t0), lresa_ ((size_t) Concept::RESA), rresa_ ((size_t) Concept::RESA) {
}
Vector (const Vector& v) : std::vector<T> (v), lresa_ (v.lresa_), rresa_ (v.rresa_) {
}
bool operator == (const Vector& v) const {
return std::equal (begin (), end (), v.begin ());
}
bool operator != (const Vector& v) const {
return !operator == (v);
}
T& operator (const size_t &s) {
return std::vector<T>::operator (s+lresa_);
}
void push_front (const T& t) {
if (!lresa_) {
std::vector<T>::insert (std::vector<T>::begin (), (size_t) Concept::RESA, t);
lresa_ = (size_t) Concept::RESA;
}
typename std::vector<T>::iterator i (std::vector<T>::begin ());
i += lresa_ -1;
*i = t;
--lresa_;
}
void push_back (const T& t) {
if (!rresa_) {
std::vector<T>::insert (std::vector<T>::end (), (size_t) Concept::RESA, t);
rresa_ = (size_t) Concept::RESA;
}
typename std::vector<T>::iterator i (std::vector<T>::end ());
i -= rresa_;
*i = t;
--rresa_;
}
//can be optimized,but that s not the topic
Vector& operator = (const Vector& v) {
std::vector<T>::operator = (v);
lresa_ = v.lresa_;
rresa_ = v.rresa_;
return *this;
}
//intelligent resize to do
//at the moment just stupid
void resize (size_t n) {
std::vector<T>::resize (n + lresa_ + rresa_);
}
private :
size_t lresa_;
size_t rresa_;
};
#endif
What do you think about it ?
c++ c++11
New contributor
Last question, on StackOverflow.com about speeding vector.push_back and push_front was said to have it's place here. So here it is :
Well well well, looks like, after work, my regenerating reserve vector may not be so bad after all ? (in question "44326712/speeding-vector-push-back", I presented a vector with a regenerating reserve, faster at push_back when reserve cant be predicted).
Deque may be cool, but faster is the vector.
So I ameliorated my Vector, with two reserves : one before the begin and another after the end, thus, enabling push_front in a vector very quickly (push_back is still better than normal vector).
With a RESA of 8192, and 1000 push_front, I had this results (computer is a Lenovo Think Center):
duration old push_front == 199 ticks ("insert (v.begin () , s)")
duration new push_front == 5 ticks
And here is the Code of my Vector :
#ifndef __VECTOR2_HPP
#define __VECTOR2_HPP
#include <vector>
#include <iostream>
#include "Concept.hpp"
#include <exception>
#include <algorithm>
template <typename T>
class Vector : public std::vector<T> {
public :
class Error : public std::exception {
public :
Error (std::string val = "") throw () : val_ (val) {}
~Error () throw () {}
const char* what () throw () {
std::string s ("Vector Error :");
s += val_;
return s.c_str();
}
private :
std::string val_;
};
typename std::vector<T>::iterator begin () {
typename std::vector<T>::iterator i (std::vector<T>::begin ());
i += lresa_;
return i;
}
typename std::vector<T>::iterator end () {
typename std::vector<T>::iterator i (std::vector<T>::end ());
i -= rresa_;
return i;
}
typename std::vector<T>::const_iterator begin () const {
typename std::vector<T>::const_iterator i (std::vector<T>::begin ());
i += lresa_;
return i;
}
typename std::vector<T>::const_iterator end () const {
typename std::vector<T>::const_iterator i (std::vector<T>::end ());
i -= rresa_;
return i;
}
typename std::vector<T>::reverse_iterator rbegin () {
typename std::vector<T>::reverse_iterator i (std::vector<T>::rbegin ());
i += rresa_;
return i;
}
typename std::vector<T>::reverse_iterator rend () {
typename std::vector<T>::reverse_iterator i (std::vector<T>::rend ());
i -= lresa_;
return i;
}
typename std::vector<T>::const_reverse_iterator rbegin () const {
typename std::vector<T>::const_reverse_iterator i (std::vector<T>::rbegin ());
i += rresa_;
return i;
}
typename std::vector<T>::const_reverse_iterator rend () const {
typename std::vector<T>::const_reverse_iterator i (std::vector<T>::rend ());
i -= lresa_;
return i;
}
Vector () : std::vector<T> (2*(size_t) Concept::RESA, T()), lresa_ ((size_t) Concept::RESA), rresa_ ((size_t) Concept::RESA) {
}
size_t size () const {
size_t s (std::vector<T>::size ());
s -= lresa_;
s -= rresa_;
return s;
}
Vector (int n, T t0) : std::vector<T> (n + 2*(size_t) Concept::RESA, t0), lresa_ ((size_t) Concept::RESA), rresa_ ((size_t) Concept::RESA) {
}
Vector (const Vector& v) : std::vector<T> (v), lresa_ (v.lresa_), rresa_ (v.rresa_) {
}
bool operator == (const Vector& v) const {
return std::equal (begin (), end (), v.begin ());
}
bool operator != (const Vector& v) const {
return !operator == (v);
}
T& operator (const size_t &s) {
return std::vector<T>::operator (s+lresa_);
}
void push_front (const T& t) {
if (!lresa_) {
std::vector<T>::insert (std::vector<T>::begin (), (size_t) Concept::RESA, t);
lresa_ = (size_t) Concept::RESA;
}
typename std::vector<T>::iterator i (std::vector<T>::begin ());
i += lresa_ -1;
*i = t;
--lresa_;
}
void push_back (const T& t) {
if (!rresa_) {
std::vector<T>::insert (std::vector<T>::end (), (size_t) Concept::RESA, t);
rresa_ = (size_t) Concept::RESA;
}
typename std::vector<T>::iterator i (std::vector<T>::end ());
i -= rresa_;
*i = t;
--rresa_;
}
//can be optimized,but that s not the topic
Vector& operator = (const Vector& v) {
std::vector<T>::operator = (v);
lresa_ = v.lresa_;
rresa_ = v.rresa_;
return *this;
}
//intelligent resize to do
//at the moment just stupid
void resize (size_t n) {
std::vector<T>::resize (n + lresa_ + rresa_);
}
private :
size_t lresa_;
size_t rresa_;
};
#endif
What do you think about it ?
c++ c++11
c++ c++11
New contributor
New contributor
edited 14 mins ago
Saint-Martin
New contributor
asked 1 hour ago
Saint-MartinSaint-Martin
13
13
New contributor
New contributor
2
It cannot be O(1) as you sometime need to grow the vector and move items.. Maybe amortized O(1)?
– Phil1970
1 hour ago
1
Folks: Be nice to one another and to everyone else. Make critique not about the person, but about the code.
– Vogel612♦
59 mins ago
this Vector insert begin at O(1) / some constant
– Saint-Martin
55 mins ago
add a comment |
2
It cannot be O(1) as you sometime need to grow the vector and move items.. Maybe amortized O(1)?
– Phil1970
1 hour ago
1
Folks: Be nice to one another and to everyone else. Make critique not about the person, but about the code.
– Vogel612♦
59 mins ago
this Vector insert begin at O(1) / some constant
– Saint-Martin
55 mins ago
2
2
It cannot be O(1) as you sometime need to grow the vector and move items.. Maybe amortized O(1)?
– Phil1970
1 hour ago
It cannot be O(1) as you sometime need to grow the vector and move items.. Maybe amortized O(1)?
– Phil1970
1 hour ago
1
1
Folks: Be nice to one another and to everyone else. Make critique not about the person, but about the code.
– Vogel612♦
59 mins ago
Folks: Be nice to one another and to everyone else. Make critique not about the person, but about the code.
– Vogel612♦
59 mins ago
this Vector insert begin at O(1) / some constant
– Saint-Martin
55 mins ago
this Vector insert begin at O(1) / some constant
– Saint-Martin
55 mins ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Saint-Martin is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211398%2fmaking-vector-push-front-improved-to-o1-8192%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Saint-Martin is a new contributor. Be nice, and check out our Code of Conduct.
Saint-Martin is a new contributor. Be nice, and check out our Code of Conduct.
Saint-Martin is a new contributor. Be nice, and check out our Code of Conduct.
Saint-Martin is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211398%2fmaking-vector-push-front-improved-to-o1-8192%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
It cannot be O(1) as you sometime need to grow the vector and move items.. Maybe amortized O(1)?
– Phil1970
1 hour ago
1
Folks: Be nice to one another and to everyone else. Make critique not about the person, but about the code.
– Vogel612♦
59 mins ago
this Vector insert begin at O(1) / some constant
– Saint-Martin
55 mins ago