Skip to content

Commit

Permalink
Move in!() outside of push!()
Browse files Browse the repository at this point in the history
  • Loading branch information
gkronber committed Aug 24, 2024
1 parent f74d552 commit a3ebcb6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/EGraphs/uniquequeue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ end
UniqueQueue{T}() where {T} = UniqueQueue{T}(Set{T}(), T[])

function Base.push!(uq::UniqueQueue{T}, x::T) where {T}
# checks if x is contained in s and adds x if it is not, using a single hash call and lookup
# available from Julia 1.11
function in!(x::T, s::Set)
idx, sh = Base.ht_keyindex2_shorthash!(s.dict, x)
idx > 0 && return true
Base._setindex!(s.dict, nothing, x, -idx, sh)

false
end

if !in!(x, uq.set)
push!(uq.vec, x)
end
Expand All @@ -39,4 +29,16 @@ function Base.pop!(uq::UniqueQueue{T}) where {T}
v
end

Base.isempty(uq::UniqueQueue) = isempty(uq.vec)
Base.isempty(uq::UniqueQueue) = isempty(uq.vec)

# Helper for push!()
# checks if x is contained in s and adds x if it is not, using a single hash call and lookup
# available from Julia 1.11
function in!(x::T, s::Set{T}) where {T}
idx, sh = Base.ht_keyindex2_shorthash!(s.dict, x)
idx > 0 && return true
Base._setindex!(s.dict, nothing, x, -idx, sh)

false
end

0 comments on commit a3ebcb6

Please sign in to comment.