Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
emin opened this issue Jan 24, 2018 · 3 comments
Closed

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

emin opened this issue Jan 24, 2018 · 3 comments

Comments

@emin
Copy link

emin commented Jan 24, 2018

` 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
Copy link
Owner

BlueRaja commented Jan 24, 2018

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
Copy link
Author

emin commented Jan 24, 2018

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
Copy link
Owner

BlueRaja commented Jan 24, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants