[Feature Request] Add a deque struct to the stdlib #2659
Labels
enhancement
New feature or request
help wanted
Extra attention is needed
mojo-repo
Tag all issues with this label
Review Mojo's priorities
What is your request?
Add a Deque struct to the stdlib, similar to python's deque: https://docs.python.org/3/library/collections.html#collections.deque
What is your motivation for this change?
While it's a very useful collection to have in general, in the context of the standard library it offers some new possibilities.
There are multiple places in the stdlib where we want to "consume" objects in a list in order. Doing so currently means either
List.pop(0)
, while safe, this is very inneficient as all elements must be moved at every pop()move_pointee
. While this is efficient, this is quite unsafe.Moving a list pointer into a deque would allow us to call
deque.popleft()
at very little cost. Thus consuming the elements in order.Any other details?
The two places where we currently have this issue in the stdlib are
List.extends()
andDict.fromkeys()
The text was updated successfully, but these errors were encountered: