Exemplo n.º 1
0
        /// <summary>
        /// Find the KD-tree node whose key is identical to the specified key.
        /// This uses the algorithm translated from 352.srch.c of Connet and Baeza-Yates.
        /// </summary>
        /// <param name="key">The key identifying the node to search for</param>
        /// <returns>An object that is the node with a matching key, or null if no key was found.</returns>
        /// <exception cref="KeySizeException"> if key.length mismatches the dimension of the tree (K)</exception>
        public object Search(double[] key)
        {
            if (key.Length != _k)
            {
                throw new KeySizeException();
            }

            KdNode kd = KdNode.Search(new HPoint(key), _root, _k);

            return(kd == null ? null : kd.V);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes a node from the KD-tree.  Instead of actually deleting the node and
        /// rebuilding the tree, it marks the node as deleted.  Hence, it is up to the
        /// caller to rebuild the tree as needed for efficiency.
        /// </summary>
        /// <param name="key">The key to use to identify the node to delete</param>
        /// <exception cref="KeySizeException"> if key.length mismatches the dimension of the tree (K)</exception>
        /// <exception cref="KeyMissingException"> if the key was not found in the tree</exception>
        public void Delete(double[] key)
        {
            if (key.Length != _k)
            {
                throw new KeySizeException();
            }

            KdNode t = KdNode.Search(new HPoint(key), _root, _k);

            if (t == null)
            {
                throw new KeyMissingException();
            }

            t.IsDeleted = true;

            _count--;
        }