Repository navigation
len, is_empty, capacity should all take constant-time #149
Replies: 4 comments
|
What is the guideline for when this isn't the case? Add an extra couple of bytes to store the length, or use a name like For reference I have a crate that currently implements an |
|
|
|
I think it's more important that |
|
Note, for linked lists (which are niche data structures), the tradeoff between constant time slice and constant time len is complicated. To make it less complicated, specifying len as being amortized constant time makes sense. |
Uh oh!
There was an error while loading. Please reload this page.
This is the case in all libstd collections and I think that it's reasonable to put this in the guidelines. Although it's stated that
is_emptymay be faster thanlen == 0, it should be clarified thatlenshould always take constant time to execute regardless. Users should expect that even for collections likeLinkedListandHashMap, checking the length is constant-time.All reactions