Esempio n. 1
0
        /// <summary>
        /// 添加节点的递归方法
        /// </summary>
        /// <param name="inputValue">输入的值</param>
        /// <returns></returns>
        private bool insertLoopMethod(IDimensionValueBean inputValue)
        {
            //当前递归节点
            KDTreeNode currentNode = rootNode;
            //当前节点的父节点
            KDTreeNode parentNode = null;
            //临时节点
            KDTreeNode tempNode = null;
            //父节点的索引
            int tempDimensionIndex = -1;

            //当前节点应当使用的索引
            int tempNowIndex = -1;

            //表征节点前进方向是否是向左节点
            bool ifIsLeftTag = true;

            double tempParentValue  = 0.0d;
            double tempCurrentValue = 0.0d;

            CompareResultEnum tempCompareResult;

            //递归寻找添加位点
            while (true)
            {
                //当前递归层级节点变为父节点
                parentNode = currentNode;
                //获得父节点的索引
                tempDimensionIndex = parentNode.NowDimisionIndex;
                //获得父节点的值
                tempParentValue = parentNode.ThisDataValue.
                                  GetValueAtDimensionIndex(tempDimensionIndex);
                //获取此节点的值
                tempCurrentValue = inputValue.
                                   GetValueAtDimensionIndex(tempDimensionIndex);
                //比较节点值
                tempCompareResult = UtilityMethod.
                                    CompareDoulbe(tempCurrentValue, tempParentValue);
                //按相等策略调整
                tempCompareResult = equalStrategy(tempCompareResult);

                //小于:左子树方向
                if (tempCompareResult == CompareResultEnum.Less)
                {
                    ifIsLeftTag = true;
                }
                //其它右子树方向
                else
                {
                    ifIsLeftTag = false;
                }

                //获取父节点相应位置处的子节点
                currentNode = parentNode.GetChildNode(ifIsLeftTag);
                //获得子节点的索引
                tempNowIndex = GetUseDimensionInde(tempDimensionIndex);
                if (null == currentNode)
                {
                    tempNode = new KDTreeNode(inputValue, tempNowIndex);
                    parentNode.SetChildNode(ifIsLeftTag, tempNode);
                    break;
                }

                //若多维值相同
                if (UtilityMethod.IfDDimensionIsEqula(currentNode.ThisDataValue, inputValue))
                {
                    //若需要替换或当前节点是已删除状态
                    if (ifEqualValueReplace || currentNode.IsDeleteTag)
                    {
                        currentNode.ThisDataValue = inputValue;
                        currentNode.IsDeleteTag   = false;
                    }
                    break;
                }
            }
            nodeCount++;
            return(true);
        }
Esempio n. 2
0
 /// <summary>
 /// 比较输入多维数据是否与此节点数据相同
 /// </summary>
 /// <param name="inputValue">输入的多维数据</param>
 /// <returns>是否相同</returns>
 internal bool IfEqula(IDimensionValueBean inputValue)
 {
     return(UtilityMethod.IfDDimensionIsEqula(this.thisDataValue, inputValue));
 }