public IntervalNode() { intervals = new OrderedDictionary <Interval <T, D>, List <Interval <T, D> > >(); center = default(D); leftNode = null; rightNode = null; }
public IntervalNode(List <Interval <T, D> > intervalList) { intervals = new OrderedDictionary <Interval <T, D>, List <Interval <T, D> > >(); var endpoints = new OrderedSet <D>(); foreach (var interval in intervalList) { endpoints.Add(interval.Start); endpoints.Add(interval.End); } Nullable <D> median = GetMedian(endpoints); center = median.GetValueOrDefault(); List <Interval <T, D> > left = new List <Interval <T, D> >(); List <Interval <T, D> > right = new List <Interval <T, D> >(); foreach (Interval <T, D> interval in intervalList) { if (interval.End.CompareTo(center) < 0) { left.Add(interval); } else if (interval.Start.CompareTo(center) > 0) { right.Add(interval); } else { List <Interval <T, D> > posting; if (!intervals.TryGetValue(interval, out posting)) { posting = new List <Interval <T, D> >(); intervals.Add(interval, posting); } posting.Add(interval); } } if (left.Count > 0) { leftNode = new IntervalNode <T, D>(left); } if (right.Count > 0) { rightNode = new IntervalNode <T, D>(right); } }