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

Inserted values are ignored if inserted with the same key #5

Closed
ForNeVeR opened this issue Mar 6, 2016 · 3 comments
Closed

Inserted values are ignored if inserted with the same key #5

ForNeVeR opened this issue Mar 6, 2016 · 3 comments

Comments

@ForNeVeR
Copy link

ForNeVeR commented Mar 6, 2016

KdTree seems to always be ignoring the new values if there's an old value stored with the same key. Here's an example:

using System;
using KdTree;
using KdTree.Math;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var tree = new KdTree<float, int>(2, new FloatMath());
            var coords = new[] { 0.0f, 0.0f };
            tree.Add(coords, 100);
            tree.Add(coords, 200);

            var z = tree.FindValueAt(coords);
            Console.Write(z); // => 100, but I'd expect 200
        }
    }
}

It would be better to either replace the existing value or throw an exception. I think that the library should never silently ignore the user value.

Maybe the problem will be solved as part of #4.

@codeandcats
Copy link
Owner

You can determine whether it was added or not via the result of Add. Add returns True if it was added and False it it wasn't.

That said, I hear what you're saying. Returning a boolean to indicate success it not my preferred style and generally I would raise an exception. If I were redesigning it today I would simply allow for duplicates - I don't see why there couldn't be multiple nodes at the same coordinate, hence why I added issue #4. I will update #4 with how I was thinking of handling it. Feel free to share your opinion.

@codeandcats
Copy link
Owner

Closing as #4 covers this.

@ForNeVeR
Copy link
Author

ForNeVeR commented Mar 6, 2016

Add returns True if it was added and False it it wasn't.

Oh, my bad - I haven't checked the type of Add method. Now it makes sense, I don't think that's such a big issue. Thank you.

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