예제 #1
0
        public override Split <FingerTree <T, M>, T, M> Split(Func <M, bool> p, M a)
        {
            var fdm = _m.BinaryOperator(a, _leftDigits.Measure());

            if (p(fdm))
            {
                var lsplit = _leftDigits.Split(p, a);
                return(new Split <FingerTree <T, M>, T, M>(FromSequence(lsplit.Left.Digits, _m), lsplit.SplitItem, Create(lsplit.Right.Digits, _fingerTree, _rightDigits)));
            }

            var ftm = _m.BinaryOperator(fdm, _fingerTree.Measure());

            if (p(ftm))
            {
                var ms  = _fingerTree.Split(p, fdm);
                var ml  = ms.Left;
                var mi  = ms.SplitItem;
                var sml = (new Digit <T, M>(_m, mi.Nodes)).Split(p, _m.BinaryOperator(fdm, ml.Measure()));
                var fi  = sml.SplitItem;
                var flt = CreateR(_leftDigits, ml, sml.Left.Digits);
                var frt = Create(sml.Right.Digits, ms.Right, _rightDigits);

                return(new Split <FingerTree <T, M>, T, M>(flt, fi, frt));
            }

            var rsplit = _rightDigits.Split(p, ftm);

            return(new Split <FingerTree <T, M>, T, M>(CreateR(_leftDigits, _fingerTree, rsplit.Left.Digits), rsplit.SplitItem, FromSequence(rsplit.Right.Digits, _m)));
        }
예제 #2
0
            public V Measure()
            {
                var result = M.Zero;

                foreach (U u in Digits)
                {
                    result = M.BinaryOperator(result, u.Measure());
                }

                return(result);
            }
예제 #3
0
            public Node(Monoid <V> m, U u1, U u2)
            {
                ConcreteMonoid = m;
                Nodes.Add(u1);
                Nodes.Add(u2);

                PreCalcMeasure = ConcreteMonoid.BinaryOperator(u1.Measure(), u2.Measure());
            }
예제 #4
0
        public DeepFingerTree(Monoid <M> m, Digit <T, M> f, FingerTree <Node <T, M>, M> ft, Digit <T, M> b)
        {
            if (f.Digits.Count > 0)
            {
                _m = m;

                _leftDigits  = f;
                _fingerTree  = ft;
                _rightDigits = b;

                PreCalcMeasure = _m.Zero;
                PreCalcMeasure = _m.BinaryOperator(PreCalcMeasure, f.Measure());
                PreCalcMeasure = _m.BinaryOperator(PreCalcMeasure, ft.Measure());
                PreCalcMeasure = _m.BinaryOperator(PreCalcMeasure, b.Measure());
            }
            else
            {
                throw new Exception("oops");
            }
        }
예제 #5
0
            public Node(Monoid <V> m, List <U> uu)
            {
                ConcreteMonoid = m;
                Nodes          = uu;

                PreCalcMeasure = ConcreteMonoid.Zero;
                foreach (var u in Nodes)
                {
                    PreCalcMeasure = ConcreteMonoid.BinaryOperator(PreCalcMeasure, u.Measure());
                }
            }
예제 #6
0
            public Node(Monoid <V> m, U u1, U u2, U u3)
            {
                ConcreteMonoid = m;
                Nodes.Add(u1);
                Nodes.Add(u2);
                Nodes.Add(u3);

                PreCalcMeasure = ConcreteMonoid.Zero;
                foreach (var u in Nodes)
                {
                    PreCalcMeasure = ConcreteMonoid.BinaryOperator(PreCalcMeasure, u.Measure());
                }
            }