예제 #1
0
파일: DisInterval.cs 프로젝트: weeble/mono
        public override bool LessEqual(DisInterval that)
        {
            bool result;

            if (this.TryTrivialLessEqual(that, out result))
            {
                return(result);
            }

            if (!join_interval.LessEqual(that.join_interval))
            {
                return(false);
            }

            return(intervals.AsEnumerable().All(inv => that.intervals.Any(inv.LessEqual)));
        }
예제 #2
0
파일: DisInterval.cs 프로젝트: weeble/mono
        public static Sequence <Interval> Normalize(Sequence <Interval> intervals, out bool isBottom)
        {
            if (intervals.Length() == 0)
            {
                isBottom = false;
                return(intervals);
            }

            Comparison <Interval> comparison =
                (a, b) => a.Equals(b) ? 0 : a.UpperBound <= b.UpperBound ? -1 : 1;

            var intervalList = new List <Interval> (intervals.AsEnumerable());

            intervalList.Sort(comparison);

            var list = Sequence <Interval> .Empty;

            var      bottomCnt = 0;
            Interval last      = null;

            foreach (var t in intervalList)
            {
                var cur = t;

                if (cur.IsBottom)
                {
                    bottomCnt++;
                }
                else if (cur.IsTop)
                {
                    isBottom = false;
                    return(Sequence <Interval> .Empty);
                }
                else if (!cur.Equals(last))
                {
                    if (last != null)
                    {
                        while (list != null)
                        {
                            last = list.Head;
                            if (Interval.AreConsecutiveIntegers(last, cur))
                            {
                                list = list.Tail;
                                cur  = last.Join(cur);
                            }
                            else if (last.LessEqual(cur))
                            {
                                list = list.Tail;
                            }
                            else if (last.OverlapsWith(cur))
                            {
                                list = list.Tail;
                                cur  = cur.Join(last);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    last = cur;
                    list = list.Cons(cur);
                }
            }

            isBottom = bottomCnt == intervals.Length();
            return(list.Reverse());
        }