pop! conflate two different meanings (adding/removing elements to unordered/sorted collections vs. adding elements to the end of
Deques, etc). These meanings should be split into different functions in Julia 2.0.
DataStructures.jl implements a number of data structures, including
CircularDeque, which are meant to be more performant implementations of stacks and queues (and deques) than just using
CircularDeque all use the same functions as base (
Queue has never been moved over to that interface, and still uses
We’re having a discussion in
DataStructures.jl around moving
Queue to the standard interface.
Currently, we have the following:
|Queue, PriorityQueue (current)|
|Queue, PriorityQueue (DS proposal A)|
|Queue, PriorityQueue (DS proposal B)|
◯ = not implemented, but could/should be
From this, we can see that
pop! have two different meanings.
- For unordered and sorted collections, they simply mean to add or remove elements from the collection.
- For every other collection listed, they (necessarily) mean to add or remove elements from the end of the collection, and they carry their traditional meaning.
There are two proposals for the
“DS Proposal A” above suggests that
Queue should be treated like
SortedDict/SortedSet, (and perhaps
Stack), since there’s only one way to add things to the collection.
“DS Proposal B” above suggests that
Queue should be treated like a
CircularDeque, (and perhaps
Stack), since there’s a distinction as to whether things are added to the front or back of the collection.
Both are valid perspectives, and this suggests that the fact that
pop! are used for adding/removing elements from unordered and sorted collections should be revisited.
For Julia 2.0,
push! should be deprecated for
SortedDict/SortedSets), and a separate function for adding/removing elements into unordered or sorted collections should be implemented. Possibilities include:
add!(s, elem) # this was the name in Julia 0.1!
delete!, see item #1 under Notes.
Switch to https://github.com/andyferris/Dictionaries.jl as the main dictionary interface. This would be a much larger discussion, but has the benefit here that
pop! would not be defined on unordered collections.
delete!(s, elem)already exists; it returns the updated collection, as opposed to
pop!(currently), which returns the removed element:
julia> s = Set([1,2,3]) Set([2, 3, 1]) julia> pop!(s) 2 julia> pop!(s,3) 3 julia> delete!(s, 1) Set(Int64)
Original discussion/PR where
pop! were originally defined on