I wonder if this has to do with the fact that heappush! assumes heap-order, 
but isn't taking into account my Reverse ordering in ord?

-Jacob


On Thursday, April 10, 2014 12:51:19 PM UTC-4, Jacob Quinn wrote:
>
> I thought this would work, but it seems that when I insert items in 
> ascending order (and the heap is supposed to be descending), my "heap" is 
> getting messed up. Is something wrong with my `ord` function?
>
> In  [448]: matches = (String,Float64)[]
>
> Out [448]: 0-element Array{(String,Float64),1}
>
> In  [449]: o = ord((x,y)->isless(x[2],y[2]),identity,true)
>
> Out [449]: ReverseOrdering{Lt}(Lt((anonymous function)))
>
> In  [450]: heappush!(matches,("Jeff",0.4),o)
>
> Out [450]: 1-element Array{(String,Float64),1}:
>  ("Jeff",0.4)
>
> In  [451]: heappush!(matches,("Jerry",0.5),o)
>
> Out [451]: 2-element Array{(String,Float64),1}:
>  ("Jerry",0.5)
>  ("Jeff",0.4) 
>
> In  [452]: heappush!(matches,("Jim",0.6),o)
>
> Out [452]: 3-element Array{(String,Float64),1}:
>  ("Jim",0.6)  
>  ("Jeff",0.4) 
>  ("Jerry",0.5)
>
> In  [453]: heappush!(matches,("Jacob",0.7),o)
>
> Out [453]: 4-element Array{(String,Float64),1}:
>  ("Jacob",0.7)
>  ("Jim",0.6)  
>  ("Jerry",0.5)
>  ("Jeff",0.4) 
>
> In  [454]: heappush!(matches,("Mike",0.8),o)
>
> Out [454]: 5-element Array{(String,Float64),1}:
>  ("Mike",0.8) 
>  ("Jacob",0.7)
>  ("Jerry",0.5)
>  ("Jeff",0.4) 
>  ("Jim",0.6)  
>
> In  [455]: heappush!(matches,("John",0.9),o)
>
> Out [455]: 6-element Array{(String,Float64),1}:
>  ("John",0.9) 
>  ("Jacob",0.7)
>  ("Mike",0.8) 
>  ("Jeff",0.4) 
>  ("Jim",0.6)  
>  ("Jerry",0.5)
>
>
>
>

Reply via email to