sisl / ExprOptimization.jl

Algorithms for optimization of Julia expressions
Other
44 stars 11 forks source link

Return of enqueue!() are always -1 #28

Closed kai-wow closed 1 year ago

kai-wow commented 1 year ago

There may be a little mistake in contrib/BoundedPriorityQueues.jl file when you define the function DataStructures.enqueue!, which results in return value of -1 all the time.

function DataStructures.enqueue!(q::BoundedPriorityQueue{K,V}, k::K, v::V;
    make_copy::Bool=false) where {K,V}
    haskey(q.pq, k) && return -1 #keys must be unique, return -1 if collision
    if make_copy
        k = deepcopy(k)
    end
    n = length(q.pq)
    enqueue!(q.pq, k, v)
    n_add = n - length(q.pq) #number of items added
    while length(q.pq) > q.N
        dequeue!(q.pq)
    end
    n_add
end

I guess the mistake is made in line 59:

n_add = n - length(q.pq) #number of items added

and it should be

n_add = length(q.pq) - n #number of items added
rcnlee commented 1 year ago

Hi @kai-wow , yes I agree that looks like a bug. Can you please submit a PR to fix? Thanks!