コード例 #1
0
        public Split <T, Digit <T, M>, M> Split(MeasurePredicate <M> predicate, M acc)
        {
            return(Match(one => new Split <T, Digit <T, M>, M>(null, one.V, null),
                         two =>
            {
                M value = _m.Append(acc, _m.Measure(two.V1));
                if (predicate(value))
                {
                    return new Split <T, Digit <T, M>, M>(null, two.V1, _mk.One(two.V2));
                }

                return new Split <T, Digit <T, M>, M>(_mk.One(two.V1), two.V2, null);
            },
                         three =>
            {
                M value = _m.Append(acc, _m.Measure(three.V1));
                if (predicate(value))
                {
                    return new Split <T, Digit <T, M>, M>(null, three.V1, _mk.Two(three.V2, three.V3));
                }
                value = _m.Append(value, _m.Measure(three.V2));
                if (predicate(value))
                {
                    return new Split <T, Digit <T, M>, M>(_mk.One(three.V1), three.V2, _mk.One(three.V3));
                }

                throw new InvalidOperationException("Should not have split prefix if not in the middle");
            },
                         four =>
            {
                M value = _m.Append(acc, _m.Measure(four.V1));
                if (predicate(value))
                {
                    return new Split <T, Digit <T, M>, M>(null, four.V1, _mk.Three(four.V2, four.V3, four.V4));
                }
                value = _m.Append(value, _m.Measure(four.V2));
                if (predicate(value))
                {
                    return new Split <T, Digit <T, M>, M>(_mk.One(four.V1), four.V2, _mk.Two(four.V3, four.V4));
                }
                value = _m.Append(value, _m.Measure(four.V3));
                if (predicate(value))
                {
                    return new Split <T, Digit <T, M>, M>(_mk.Two(four.V1, four.V2), four.V3, _mk.One(four.V4));
                }

                throw new InvalidOperationException("Should not have split prefix if not in the middle");
            }));
        }
コード例 #2
0
 public override FingerTree <T, M> AddLeft(T a)
 {
     return(_mk.Deep(_mk.One(a), new Empty <Node <T, M>, M>(Measured.Node), _mk.One(_item)));
 }