예제 #1
0
        private void Add(KdTreeNode <T> parent, T childValue)
        {
            int functionIndex = GetNodeLevel(parent) % comparers.Count;

            if (this.comparers[functionIndex](parent.Point, childValue) >= 0)
            {
                if (parent.LeftChild != null)
                {
                    Add(parent.LeftChild, childValue);
                }
                else
                {
                    //int nodeLevel = 1 + GetNodeLevel(parent);

                    parent.LeftChild = new KdTreeNode <T>(childValue);
                }
            }
            else
            {
                if (parent.RigthChild != null)
                {
                    Add(parent.RigthChild, childValue);
                }
                else
                {
                    //int nodeLevel = 1 + GetNodeLevel(parent);

                    parent.RigthChild = new KdTreeNode <T>(childValue);
                }
            }
        }
예제 #2
0
 public int GetNodeLevel(KdTreeNode <T> node)
 {
     if (object.Equals(null, node.Parent))
     {
         return(0);
     }
     else
     {
         return(GetNodeLevel(node.Parent) + 1);
     }
 }
예제 #3
0
        public KdTree(T[] values, List <Func <T, T, int> > comparers)
        {
            if (values.Equals(null) || comparers.Equals(null))
            {
                return;
            }

            this.Root = new KdTreeNode <T>(values[0]);

            this.comparers = comparers;

            for (int i = 1; i < values.Length; i++)
            {
                Insert(values[i]);
            }
        }