Skip to content
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

Add iteration support for more containers #448

Merged
merged 14 commits into from
Jul 22, 2024

Conversation

PraneethJain
Copy link
Contributor

https://github.com/PraneethJain/libcxxwrap-julia#iterators

Added iterators for

  • StdDeque
  • StdSet
  • StdUnorderedSet
  • StdMultiset
  • StdUnorderedMultiset
  • StdList
  • StdForwardList

Base code from #433

Also added pretty printing for StdList and StdForwardList, since they do not have a parent Abstract Type in Julia

Copy link
Collaborator

@barche barche left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, I left some inline comments.

function Base.show(io::IO, ::MIME"text/plain", container::StdForwardList)
print(io, "StdForwardList[")

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would rather go for something like:

StdForwardList{<element type>} with X elements:
  2
  3
  1

similar to the way Julia Sets are printed. The [] syntax risks confusion with arrays.

Copy link
Contributor Author

@PraneethJain PraneethJain Jul 22, 2024

Choose a reason for hiding this comment

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

For a forward list, printing the length will require iterating over the entire list, so I have omitted the number of elements and now gone for this:

StdForwardList{Int64}:
  2
  3
  1

Base.iterate(v::StdList, state::StdListIterator) = (state != iteratorend(v)) ? _list_iteration_tuple(v, iterator_next(state)) : nothing

function Base.show(io::IO, ::MIME"text/plain", container::StdList)
print(io, "StdList[")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, it is now displayed like this

StdList{Int64} with 3 elements:
  2
  3
  1

Base.pushfirst!(v::StdDeque, x) = push_front!(v, x)
Base.push!(v::StdDeque, x) = isempty(v) ? push_front!(v, x) : push_back!(v, x)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The push methods for StdDeque also need to return the container, as is done for the other types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@barche barche merged commit 17e1d59 into JuliaInterop:main Jul 22, 2024
5 of 11 checks passed
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.

2 participants