Exemplo n.º 1
0
 public IntervalNode()
 {
     intervals = new Dictionary <Interval <D>, List <T> >();
     center    = default(D);
     leftNode  = null;
     rightNode = null;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Instantiate and Build an interval tree with a preset list of stubedIntervals
 /// </summary>
 /// <param name="intervalList">The list of stubedIntervals to use</param>
 public IntervalTree(IList <T> intervalList)
 {
     this.head         = new IntervalNode <T, D>(intervalList);
     this.intervalList = intervalList;
     this.inSync       = true;
     this.size         = intervalList.Count;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Instantiate a new interval tree with no stubedIntervals
 /// </summary>
 public IntervalTree()
 {
     this.head         = new IntervalNode <T, D>();
     this.intervalList = new List <T>();
     this.inSync       = true;
     this.size         = 0;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Build the interval tree to reflect the list of stubedIntervals.
 /// Will not run if this is currently in sync
 /// </summary>
 /// </summary>
 public void Build()
 {
     if (!inSync)
     {
         head   = new IntervalNode <T, D>(intervalList);
         inSync = true;
         size   = intervalList.Count;
     }
 }
Exemplo n.º 5
0
        private String NodeString(IntervalNode <T, D> node, int level)
        {
            if (node == null)
            {
                return("");
            }

            var sb = new StringBuilder();

            for (int i = 0; i < level; i++)
            {
                sb.Append("\t");
            }
            sb.Append(node + "\n");
            sb.Append(NodeString(node.Left, level + 1));
            sb.Append(NodeString(node.Right, level + 1));
            return(sb.ToString());
        }
Exemplo n.º 6
0
        public IntervalNode(IEnumerable <T> intervalDataList)
        {
            intervals = new Dictionary <Interval <D>, List <T> >();

            var endpoints = new List <D>();

            foreach (var intervalData in intervalDataList)
            {
                endpoints.Add(intervalData.Interval.Start);
                endpoints.Add(intervalData.Interval.End);
            }
            endpoints.Sort();

            Nullable <D> median = GetMedian(endpoints);

            center = median.GetValueOrDefault();

            var left  = new List <T>();
            var right = new List <T>();

            foreach (var intervalData in intervalDataList)
            {
                if (intervalData.Interval.End.CompareTo(center) < 0)
                {
                    left.Add(intervalData);
                }
                else if (intervalData.Interval.Start.CompareTo(center) > 0)
                {
                    right.Add(intervalData);
                }
                else
                {
                    List <T> list;
                    if (!intervals.TryGetValue(intervalData.Interval, out list))
                    {
                        intervals.Add(intervalData.Interval, new List <T>());
                    }
                    if (totalInterval == null)
                    {
                        totalInterval = intervalData.Interval;
                    }
                    else
                    {
                        if (totalInterval.Start.CompareTo(intervalData.Interval.Start) > 0)
                        {
                            totalInterval.Start = intervalData.Interval.Start;
                        }
                        if (totalInterval.End.CompareTo(intervalData.Interval.End) < 0)
                        {
                            totalInterval.End = intervalData.Interval.End;
                        }
                    }
                    intervals[intervalData.Interval].Add(intervalData);
                }
            }

            if (left.Count > 0)
            {
                leftNode = new IntervalNode <T, D>(left);
            }
            if (right.Count > 0)
            {
                rightNode = new IntervalNode <T, D>(right);
            }
        }