If you want to be particularly strict about this specific set of operations independently of association, performance, or anything else, I can't think of any standard term. (Also it should probably be a trait, not a data structure.)
There are probably still better names than Foo
though. Maybe a Tail
, that can truncate
, append
, Index
, and len
. Or a Clip
that can chop
, len
, Index
, and push
. Though I guess at a stretch you could fuse
, front
, offset
, and ordinal
.
More seriously, data structures are normally named for their structure, in memory or conceptually (like trees), more than the set of supported operations. But if what matters is a set of operations, you still generally want the data structure that is best for that set of operations. The data structure that is best for the given set of operations is an vector/dynamic array/etc. As a side-effect, I think most people are going to associate that limited set of operations with a vector/dynamic array/etc.
Thus, I suggest FooVec
is still somewhat better than Foo
. Or maybe something even more use-case specific like @RustyJoeM suggested.
Amortized O(1)
when doubling capacity each reallocation
Not a proof, but maybe this will help your [uh, I can only reply to one person at a time, but y'all understand] intuition.
If you have the excess capacity, pushing is O(1)
. If you don't, # of relocations is the size of your current capacity. Here's the pattern when you double capacity every time:
push # |
relocations |
total relocations |
2 |
1 |
1 |
3 |
2 |
3 |
4 |
0 |
3 |
5 |
4 |
7 |
6 |
0 |
7 |
7 |
0 |
7 |
8 |
0 |
7 |
9 |
8 |
15 |
10 |
0 |
15 |
... |
0 |
15 |
16 |
0 |
15 |
17 |
16 |
31 |
... |
0 |
31 |
32 |
0 |
31 |
Note how when you've pushed 2
n
items, you've relocated 2
n
-1
items. And at 2
n
+1
pushes, you're still within a constant factor (2
). Hence, amortized O(1)
.