-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] Add Linked List #3942
base: nightly
Are you sure you want to change the base?
[stdlib] Add Linked List #3942
Conversation
5b54853
to
557b07c
Compare
# c = c[].next | ||
return current | ||
|
||
fn __getitem__[I: Indexer](ref self, read idx: I) raises -> ref [self] T: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was decided a while ago to just use Int
here and let the implicit conversion do the work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following what List
does. If we want to establish that as a convention, I think that it probably should go in the stdlib docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see now it was recently changed back to this way. That's fine I preferred it anyways
Returns: | ||
Whether the list is empty or not. | ||
""" | ||
return self._head == Self.PointerT() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use return not self._head
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had "check head for null" in my head when writing this. I'll remove the comparison.
557b07c
to
9743f28
Compare
Adds a `LinkedList` type which implements most of the API surface of `List` (also grabbing the tests). This should help with filling in basic data structures in the stdlib. Signed-off-by: Owen Hilyard <[email protected]>
9743f28
to
e46ebca
Compare
Move to draft due to existing linked list. I'll circle around after I've merged the two implementations. |
Adds a
LinkedList
type which implements most of the API surface ofList
(also grabbing the tests). This should help with filling in basic data structures in the stdlib.No iterator because I ran into some nasty issues with origins and I'm not sure how far I can push casting them before I get to UB.
There's also an instance of
list.__getitem__(0).__getitem__(1).value = "Mojo"
in test_linked_list.mojo since I couldn't find another way to avoid the copy. If someone has a solution please let me know.