Skip to content

WIP: Update deque #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

mattytrentini
Copy link
Contributor

MicroPython's built-in deque lacks many features but is implemented in C so is very lean and fast.
The micropython-lib version is implemented in Python and has more features - but should have even more. This is a start toward achieving feature-parity with CPython's deque.

@mattytrentini
Copy link
Contributor Author

This could possibly be merged as-is (I had to extend deque to supporting porting the progress library to MicroPython) but I'm going to try and add all the other features of deque as well as use as much as possible of the CPython test cases.

def pop(self):
return self.q.pop()

def append(self, a):
self.q.append(a)
if self.__maxlen is not None and len(self.q) > self.__maxlen:
self.popleft()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do this bit before appending, to use less memory for the list

@BrianPugh
Copy link
Contributor

chiming in that this helped make some of my cpython code be micropython-compatible.

@mattytrentini
Copy link
Contributor Author

Note that the built-in deque has had some substantial improvements, see:

micropython/micropython@7dff38f

There is little reason to use this Python version now - which is great!

@dpgeorge
Copy link
Member

Now that the core collections.deque class is more fully implemented, I think we should just remove the deque implementation here. That will prevent any confusion, everyone will just use the built-in version.

@mattytrentini
Copy link
Contributor Author

I agree; the differences are minimal, so I'll close this. Fantastic to see the built-in deque improved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants