OrderedCollections.jl
OrderedCollections.jl copied to clipboard
keys and getindex of OrderedSet
My understanding of a set is a collection of keys without values. Therefore, I would expect OrderedSet
to have keys
as elements and their positions in the set as values or indices. This interpretation agrees with the description of Base.getindex
: "Retrieve the value(s) stored at the given key or index within a collection."
The current implementation of getindex(ordered_set, i)
returns the i
th element in ordered_set
which is opposite to this interpretation. I agree that it's useful to get the element at a given position, but it's more intuitive to use ordered_set[i]
instead. Similarly, the current implementation of keys(ordered_set)
returns 1:length(ordered_set)
instead of collect(ordered_set)
.
Just realized that Julia actually converts ordered_set[i]
to getindex(ordered_set, i)
. Nevertheless, is there an efficient way to get the index of an element in an OrderedSet
?
Note that OrderSet is part of OrderedCollections, which is not this repository (DataStructures) but is adjacent. So I am closing this issue and requesting that you reopen it in OrderedCollections if you wish.
ordered_set[i]
is currently deprecated: https://github.com/JuliaCollections/OrderedCollections.jl/blob/6497eb58bdc7898db7e2fd1f9685f4218e55c62d/src/ordered_set.jl#L84-L91
Personally I think getting rid of it is the right answer, but I know there have been voices to the contrary.