-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
make KeyIterator and ValueIterator more array-like #10092
Comments
The problem is that this indexing would be O(n). |
I feel that the |
Would be addressed by the ordered dictionary design that PyPy recently adopted: http://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html Julia Dev discussion: |
In the case of dictionaries, these iterators can't be infinite... |
Of course, but I feel that there is a component of API predictability. If I get an |
Should we have a kind of an iterator class hierarchy like C++? |
Although we might ultimately want ordered dictionaries, I don't think it's good to set the expectation that a type like KeyIterator should implement indexing. For many data structures you can only efficiently iterate the keys, and not index them. |
I think there are really two distinct things here: being able to index these objects, and getting I think broadcast should perhaps be the higher priority. While indexing is missing functionality that would require data structure changes to be efficient, broadcast currently behaves in an unexpected way. For instance, julia> a = Dict(1=>2, 2=>2)
Dict{Int64,Int64} with 2 entries:
2 => 2
1 => 2
julia> all(collect(values(a)) .== 2)
true
julia> all(values(a) .== 2)
false |
Also #18618 |
When have
d = Dict(:foo => 12.34, "bar" => 567)
and you writekeys(d)
you get aBase.KeyIterator
object, which is fast and cheap to construct from the dictionaryd
. You can writecollect(keys(d))
to get an array of keys, but you have to do this unfortunately often. It would be a good self-contained project to add more array-like behaviors toKeyIterator
and the correspondingValueIterator
types so that things likekeys(d)[1]
andvalues(d)[end]
work as expected.The text was updated successfully, but these errors were encountered: