BlueRaja / High-Speed-Priority-Queue-for-C-Sharp

A C# priority queue optimized for pathfinding applications
MIT License
1.15k stars 169 forks source link

Doesn't work with big numbers (probably long!) #40

Closed emin closed 6 years ago

emin commented 6 years ago

` SimplePriorityQueue priorityQueue = new SimplePriorityQueue();

    //Now, let's add them all to the queue (in some arbitrary order)!
    priorityQueue.Enqueue("2 - Jason", 1516779438070);
    priorityQueue.Enqueue("1 - Joseph", 1516779438069);
    priorityQueue.Enqueue("3 - Tyler", 1516779441371); 

    //Change one of the string's priority to 2.  Since this string is already in the priority queue, we call UpdatePriority() to do this

    //Finally, we'll dequeue all the strings and print them out
    while(priorityQueue.Count != 0)
    {
        string nextUser = priorityQueue.Dequeue();
        Debug.Log(nextUser);
    }

`

I tried to change the numbers from example, and you dequeue them in order you queue them like normal queue, It's expected that you should dequeue them as 1, 2, 3.

I don't know it's related to the numbers being big (not support long etc). Or maybe I tried to use it wrong way. I should be able to use it with these numbers because they're timestamp values and I want to order the queue with them

Thanks

BlueRaja commented 6 years ago

It's because priority values are floats, which have a precision of 23 bits (about 7 digits). ~Try using GenericPriorityQueue which supports a generic priority value (but is slightly slower than FastPriorityQueue)~

I have an idea for the future on how to fix this, but I haven't found time to implement it yet.

[Edit] Oh, I just noticed you're using SimplePriorityQueue, not FastPriorityQueue. SimplePriorityQueue already supports a generic priority type. Try declaring it SimplePriorityQueue<string, long> instead.

emin commented 6 years ago

Oh, I didn't know that. I was using SimplePriorityQueue and it doesn't say that limitation on Wiki page or any other place I looked for, maybe you should consider to add that to let people know beforehand. Thanks for the help.

BlueRaja commented 6 years ago

It's mentioned in the XML documentation which should pop up when you use the class in Visual Studio