Пример #1
0
 public SplitResult(Range <T> range, SplitResultRange type)
 {
     this.Range = range;
     this.Type  = type;
 }
Пример #2
0
        private static bool SplitOrdered(Range <T> lower, Range <T> higher,
                                         SplitResultRange lowerRangeName, SplitResultRange higherRangeName,
                                         out SplitResult before, out SplitResult intersection, out SplitResult after)
        {
            // 7 Possible results
            //   1) Disjoint             (a.h < b.l)   => (a.l to a.h) + (b.l to b.h)                            -- A_X_B
            //
            //   (a.l < b.l)
            //    2) Overlap             (a.h < b.h)   => (a.l to b.l - 1) + (b.l to a.l) + (a.l + 1 to b.h)     -- A_AB_B
            //    3) SuperSet            (a.h > b.h)   => (a.l to b.l - 1) + (b.l to b.h) + (b.h + 1 to a.h)     -- A_AB_A
            //    4) SuperSetToEnd       (a.h = b.h)   => (a.l to b.l - 1) + (b.l to b.h)                        -- A_AB_X
            //
            //   (a.l = b.l)
            //    5) SubSetFromStart     (a.h < b.h)   => (a.l to a.h)     + (a.h + 1 to b.h)                    -- X_AB_B
            //    6) SuperSetFromStart   (a.h > b.h)   => (a.l to b.h)     + (b.h + 1 to a.h)                    -- X_AB_A
            //    7) Union               (a.h = b.h)   => (a.l to b.h)                                           -- X_AB_X

            // [1] (a.h < b.l) | Disjoint => A_B
            if (lower.high.Precedes(higher.low))
            {
                before = new SplitResult(lower, lowerRangeName);

                intersection = SplitResult.Neither;

                after = new SplitResult(lower, higherRangeName);

                return(false);
            }
            else
            {
                // BEFORE -> [A|X] => when a.l != b.l, (a.l to b.l - 1)
                if (lower.low.Equals(higher.low))
                {
                    before = SplitResult.Neither;
                }
                else
                {
                    before = new SplitResult(lower.low, higher.low.Previous, lowerRangeName);
                }

                // INTERSECTION -> AB => (b.l to MIN(a.h, b.h))
                T ab_high = Min(lower.high, higher.high);

                intersection = new SplitResult(higher.low, ab_high, SplitResultRange.AB);

                // AFTER -> [A|B|X] => when a.h != b.h, (ab.h + 1 to MAX(a.h, b.h))
                if (lower.high.Follows(higher.high))
                {
                    after = new SplitResult(ab_high.Next, lower.high, lowerRangeName);
                }
                else if (higher.high.Follows(lower.high))
                {
                    after = new SplitResult(ab_high.Next, higher.high, higherRangeName);
                }
                else
                {
                    after = SplitResult.Neither;
                }

                return(true);
            }
        }
Пример #3
0
 public SplitResult(T low, T high, SplitResultRange type)
 {
     this.Range = new Range <T>(low, high);
     this.Type  = type;
 }