codeandcats / KdTree

A fast, generic, multi-dimensional Binary Search Tree written in C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow for duplicate coordinates

codeandcats opened this issue · comments

commented

Currently the tree will not allow you to add multiple data points with the same coordinates.
Though, I don't think there's any technical requirement for not allowing duplicate coordinates.

commented

I'm thinking of adding a DuplicateBehavior property that is an enum with the following possible values:

  • Skip (Silently ignores requests to add a duplicate coord and returns False)
  • Error (Throws an exception if requested to add a duplicate coord)
  • Allow (Allows adding duplicate coordinates)
  • Update (Updates the existing node at coord with new value)

This would be added in a minor update with a default behavior of Skip for backwards compatibility.

Then in a major update I would update the default behavior to be Allow since I believe most cases would not care about multiple points at the same coordinate.

commented

I've decided not to allow duplicates for now.

However, as of version 1.2.0 I've added an overloaded constructor for the KdTree which takes an AddDuplicateBehavior enum which specifies how to handle attempts to add nodes with coordinates that already exist. There are three options:

  • Skip (Current and Default behavior. Silently ignores request to add duplicate node and returns false)
  • Error (Throws a DuplicateNodeError exception when attempting to add duplicate node)
  • Update (Updates the existing node at coord with value of new node you're trying to add)