Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/OrderedCollections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module OrderedCollections
searchsortedfirst, searchsortedlast, in,
filter, filter!, ValueIterator, eachindex, keytype,
valtype, lastindex, nextind,
copymutable, emptymutable, dict_with_eltype
copymutable, emptymutable, dict_with_eltype,
deleteat!

export OrderedDict, OrderedSet, LittleDict
export freeze
Expand Down
27 changes: 27 additions & 0 deletions src/ordered_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,33 @@ function delete!(h::OrderedDict, key)
return h
end

function deleteat!(od::OrderedDict, i::Integer, rehash=true)
key = od.keys[i]
index = OrderedCollections.ht_keyindex(od, key, false)
@inbounds ki = od.slots[index]
@inbounds od.slots[index] = -ki
ccall(:jl_arrayunset, Cvoid, (Any, UInt), od.keys, ki-1)
ccall(:jl_arrayunset, Cvoid, (Any, UInt), od.vals, ki-1)
od.ndel += 1
od.dirty = true
rehash && OrderedCollections.rehash!(od)
end

function deleteat!(od::OrderedDict,
inds::Union{AbstractUnitRange{<:Integer}, AbstractVector{<:Integer}})
for i in inds
deleteat!(od, i, false)
end
OrderedCollections.rehash!(od)
end

function deleteat!(od::OrderedDict, inds::AbstractVector{<:Bool})
for (i,b) in enumerate(inds)
b && deleteat!(od, i, false)
end
OrderedCollections.rehash!(od)
end

function iterate(t::OrderedDict)
t.ndel > 0 && rehash!(t)
length(t.keys) < 1 && return nothing
Expand Down