Skip to content

Commit

Permalink
add deleteat! for OrderedDict
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Jul 27, 2023
1 parent c3687a8 commit 01c338d
Showing 1 changed file with 27 additions and 0 deletions.
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

0 comments on commit 01c338d

Please sign in to comment.