示例#1
0
        public static int GetAlpha(IntNode node, int entry)
        {
            if (entry == 0)
                return 0;

            int branchFactor = node.Children.Count;
            int sum = 0;
            for (int i = 0; i <= node.Children[0].Height; i++)
                sum += (int)Math.Pow(branchFactor, i);
            return sum * entry;
        }
示例#2
0
        /// <summary>
        /// Make an IndexBucket and calculate the pointer for each entry.
        /// </summary>
        /// <param name="node">The node to make the bucket of</param>
        /// <param name="start">Index of entry of this node to be used to
        /// start this bucket.</param>
        /// <param name="offset"></param>
        /// <param name="rep"></param>
        /// <returns></returns>
        public static IndexBucket MakeIndexBucket(IntNode node, int start,
            int offset, int rep)
        {
            IndexBucket bucket =  new IndexBucket();
            int entry = 0;
            for (int i = start; i < node.Children.Count; i++)
            {
                int index = GetAlpha(node, entry);
                if (rep > 0)
                    index += entry;
                if (rep > 1)
                    index += GetBeta(node.Children.Count, rep, entry);
                index += (offset + 1);

                bucket.AddEntry(new IndexEntry(node.Children[i].Bounds,
                    index));

                entry++;
            }

            return bucket;
        }
示例#3
0
        private void BuildTree(List<Point> records, Orthotope bounds,
            int branchFactor)
        {
            int dimensions = records[0].Dimensions;
            int height = ApproxTreeHeight(records.Count, branchFactor);

            //Assign partitions to each dimension.
            int[] dimensionPartitions = GetPartitionPerDimension(
                GetPartitionPowerFactor(dimensions, height),
                branchFactor);
            //Get cell width for each dimension
            double[] cellWidths = GetPartitionWidth(bounds, dimensionPartitions);
            //Make Leaves
            List<Node> leaves = MakeLeaves(bounds, dimensionPartitions,
                cellWidths);

            //Build the tree bottom up from leaves.
            List<Node> nodes = leaves;
            while (true)
            {
                if (nodes.Count == 1)
                {
                    root = nodes[0];
                    break;
                }
                List<Node> newNodes = new List<Node>();
                for (int i = 0; i < (int)(nodes.Count / branchFactor); i++)
                {
                    IntNode node = new IntNode(
                        nodes.GetRange(i * branchFactor, branchFactor));
                    newNodes.Add(node);
                }
                nodes = newNodes;
            }
        }