Ejemplo n.º 1
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>());
        }
Ejemplo n.º 2
0
        // подсчитывает число "нулевых" элементов слева направо
        private static long BinaryCountRight(PaEntry elementFrom, long number, Func <PaEntry, int> elementDepth)
        {
            if (number <= 0)
            {
                return(0);
            }
            if (number == 1)
            {
                if (elementDepth(elementFrom) == 0)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            long    half         = number / 2;
            var     size         = elementFrom.Type.HeadSize;
            PaEntry middle       = new PaEntry(elementFrom.Type, elementFrom.offset + half * size, elementFrom.cell);
            var     middle_depth = elementDepth(middle);

            if (middle_depth == 0)
            {
                middle.offset += size; // Начальный элемент будет следующий
                return(half + 1 + BinaryCountRight(middle, number - half - 1, elementDepth));
            }
            else if (middle_depth > 0)
            {
                return(BinaryCountRight(elementFrom, half, elementDepth));
            }
            else // if (middle_depth < 0)
            {
                throw new Exception("Assert Err: 2984");
            }
        }
Ejemplo 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);
        }
Ejemplo n.º 4
0
        public IEnumerable <PaEntry> Elements(long start, long number)
        {
            if (tp.Vid != PTypeEnumeration.sequence)
            {
                throw new Exception("Err in TPath formula: Elements() can't be applyed to structure of vid " + tp.Vid);
            }
            if (number > 0)
            {
                PTypeSequence mts     = (PTypeSequence)tp;
                PType         t       = mts.ElementType;
                PaEntry       element = this.Element(start);
                if (t.HasNoTail)
                {
                    int size = t.HeadSize;
                    for (long ii = 0; ii < number; ii++)
                    {
                        yield return(element);

                        element.offset += size;
                    }
                }
                else
                {
                    long off = element.offset;
                    for (long ii = 0; ii < number; ii++)
                    {
                        element.offset = off;
                        if (ii < number - 1)
                        {
                            off = element.Skip(t, off);
                        }
                        yield return(element);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public static bool IsNullOrEmpty(PaEntry ent)
 {
     return(ent == null || ent.offset == Int64.MinValue);
 }
Ejemplo n.º 6
0
 public PaCell(PType typ, string filePath, bool readOnly = true)
     : base(typ, false, filePath, readOnly)
 {
     rt = new PaEntry(typ, this.dataStart, this);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Новый вариан конструктора - на основе потока
 /// </summary>
 /// <param name="typ"></param>
 /// <param name="stream"></param>
 /// <param name="readOnly"></param>
 public PaCell(PType typ, System.IO.Stream stream, bool readOnly = true) : base(typ, false, stream, readOnly)
 {
     rt = new PaEntry(typ, this.dataStart, this);
 }