Пример #1
0
        /// <summary>
        /// Collects all values in the specific range of the subtree rooted at the specified node.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="node">The root of the subtree to search within.</param>
        /// <param name="dimension">The dimension of which the specified node belongs to.</param>
        /// <param name="matchingItems">The items which are found to be in the specified range are placed in this list.</param>
        private void CollectAllInRange(MultiDimensionalRange <T> range, Node node, int dimension, List <T> matchingItems)
        {
            if (node == null)
            {
                return;
            }

            int minRangeComparison = range.CompareTo(node.Min, dimension);
            int maxRangeComparison = range.CompareTo(node.Max, dimension);

            if (minRangeComparison == 0 && maxRangeComparison == 0)
            {
                // The node's range is fully contained within the search range.

                if (dimension == this.DimensionCount - 1)
                {
                    // This is the last dimension so collect all of the values in this subtree.
                    CollectAllValues(node, matchingItems);
                }
                else
                {
                    // Continue searching in the next dimension.
                    CollectAllInRange(range, node.NextDimensionRoot, dimension + 1, matchingItems);
                }
            }
            else if (minRangeComparison <= 0 || minRangeComparison >= 0)
            {
                // The node's range intersects the search range so continue searching all of the children.
                CollectAllInRange(range, node.LeftChild, dimension, matchingItems);
                CollectAllInRange(range, node.RightChild, dimension, matchingItems);
            }
        }
Пример #2
0
        /// <summary>
        /// Gets all items in the specified range.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <returns>The items in the specified range.</returns>
        public List <T> GetAllInRange(MultiDimensionalRange <T> range)
        {
            List <T> matchingItems = new List <T>();

            CollectAllInRange(range, m_root, 0, matchingItems);
            return(matchingItems);
        }