Exemplo n.º 1
0
        public PaEntry BinarySearchFirst(Func <PaEntry, int> elementDepth)
        {
            PaEntry sequ = this;
            var     typ  = sequ.Type;

            if (typ.Vid != PTypeEnumeration.sequence)
            {
                throw new Exception("Function BinarySearchFirst can't be applied to the type with vid=" + typ.Vid);
            }
            PTypeSequence mts = (PTypeSequence)sequ.Type;
            PType         tel = mts.ElementType;

            if (!tel.HasNoTail)
            {
                throw new Exception("Function BinarySearchFirst can't be applied to elements with vid=" + tel.Vid);
            }
            long llen = sequ.Count();

            if (llen == 0)
            {
                sequ.offset = Int64.MinValue; return(sequ);
            }
            var first_el    = sequ.Element(0);
            var first_depth = elementDepth(first_el);

            if (first_depth == 0)
            {
                return(first_el);
            }
            PaEntry found = BinarySearchFirst(first_el, llen, elementDepth);

            //if (found.offset == long.MinValue) throw new Exception("Zero element did't foound by FindZero()");
            return(found);
        }
Exemplo n.º 2
0
        public IEnumerable <PaEntry> BinarySearchAll(long start, long numb, Func <PaEntry, int> elementDepth)
        {
            PaEntry sequ = this;
            var     typ  = sequ.Type;

            if (typ.Vid != PTypeEnumeration.sequence)
            {
                throw new Exception("Function BinarySearchAll can't be applied to the type with vid=" + typ.Vid);
            }
            PTypeSequence mts  = (PTypeSequence)sequ.Type;
            PType         tel  = mts.ElementType;
            long          llen = System.Math.Min(numb, sequ.Count() - start);

            if (llen > 0)
            {
                var elementFrom = sequ.Element(start);
                //foreach (var pe in BinarySearchInside(elementFrom, llen, elementDepth)) yield return pe;
                return(BinarySearchInside(elementFrom, llen, elementDepth));
            }
            return(Enumerable.Empty <PaEntry>());
        }
Exemplo n.º 3
0
        public PaEntry BinarySearchFirst(long start, long number, Func <PaEntry, int> elementDepth)
        {
            PaEntry sequ = this;

            if (this.Type.Vid != PTypeEnumeration.sequence)
            {
                throw new Exception("Function BinarySearchFirst can't be applied to this type");
            }
            PTypeSequence mts = (PTypeSequence)sequ.Type;
            PType         tel = mts.ElementType;

            if (!tel.HasNoTail)
            {
                throw new Exception("Function BinarySearchFirst can't be applied to elements with vid=" + tel.Vid);
            }
            long llen = sequ.Count();

            if (llen == 0 || number == 0)
            {
                return(PaEntry.Empty);
            }
            if (start < 0 || number < 0 || start + number > llen)
            {
                throw new IndexOutOfRangeException();
            }
            var first_el    = sequ.Element(start);
            var first_depth = elementDepth(first_el);

            if (first_depth == 0)
            {
                return(first_el);
            }
            PaEntry found = BinarySearchFirst(first_el, number, elementDepth);

            return(found);
        }