Skip to content

Commit

Permalink
refactor MutableLinkedList
Browse files Browse the repository at this point in the history
  • Loading branch information
laborg committed Oct 13, 2023
1 parent 85c25c3 commit b4e6baa
Show file tree
Hide file tree
Showing 4 changed files with 562 additions and 165 deletions.
9 changes: 7 additions & 2 deletions docs/src/mutable_linked_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Usage:
l = MutableLinkedList{T}() # initialize an empty list of type T
l = MutableLinkedList{T}(elts...) # initialize a list with elements of type T
isempty(l) # test whether list is empty
empty!(l) # empties the list
length(l) # get the number of elements in list
collect(l) # return a vector consisting of list elements
eltype(l) # return type of list
Expand All @@ -18,19 +19,23 @@ last(l) # return value of last element of list
l1 == l2 # test lists for equality
map(f, l) # return list with f applied to elements
filter(f, l) # return list of elements where f(el) == true
filter!(f, l) # mutating version of `filter(f,l)`
reverse(l) # return reversed list
reverse!(l) # reverse the list in place
copy(l) # return a copy of list
getindex(l, idx) || l[idx] # get value at index
getindex(l, range) || l[range] # get values within range a:b
setindex!(l, data, idx) # set value at index to data
append!(l1, l2) # attach l2 at the end of l1
append!(l, elts...) # attach elements at end of list
append!(l, collections...) # all elements of all collections to l
prepend(l, collections...) # add all elements of all collections in front of l
delete!(l, idx) # delete element at index
delete!(l, range) # delete elements within range a:b
push!(l, data) # add element to end of list
pushfirst!(l, data) # add element to beginning of list
pop!(l) # remove element from end of list
popfirst!(l) # remove element from beginning of list
splice!(l,idx,ins) # remove element given as `idx` and insert elements of `ins` instead. idx is either an Int or a UnitRange

```

`MutableLinkedList` implements the Iterator interface, iterating over the list
Expand Down
12 changes: 12 additions & 0 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ Base.@deprecate_binding IntDisjointSets IntDisjointSet
@deprecate insert!(m::SortedDict, k, d) push_return_semitoken!(m::SortedDict, k=>d)
@deprecate insert!(m::SortedMultiDict, k, d) (push_return_semitoken!(m::SortedMultiDict, k=>d))[2]

function Base.delete!(l::MutableLinkedList, idx)
Expr(:meta, :noinline)
Base.depwarn("`delete!(l::MutableLinkedList,idx::Int)` is deprecated, use `deleteat!(l,idx)` instead.", :delete!)
deleteat!(l,idx)
end

function Base.delete!(l::MutableLinkedList, r::UnitRange)
Expr(:meta, :noinline)
Base.depwarn("`delete!(l::MutableLinkedList,r::UnitRange)` is deprecated, use `deleteat!(l,idx)` instead.", :delete!)
deleteat!(l,r)
end

function Base.peek(q::PriorityQueue)
Expr(:meta, :noinline)
Base.depwarn("`peek(q::PriorityQueue)` is deprecated, use `first(q)` instead.", :peek)
Expand Down
Loading

0 comments on commit b4e6baa

Please sign in to comment.