Example #1
0
        /// <summary>
        /// дерево с 10 ветвями и long значением.
        /// </summary>
        /// <returns></returns>
        private static PType PTypeTree()
        {
            var tpBtree = new PTypeRecord();

            tpBtree = new PTypeRecord(
                new NamedType("zero", new PTypeUnion()),
                new NamedType("one", new PTypeUnion()),
                new NamedType("two", new PTypeUnion()),
                new NamedType("three", new PTypeUnion()),
                new NamedType("four", new PTypeUnion()),
                new NamedType("five", new PTypeUnion()),
                new NamedType("six", new PTypeUnion()),
                new NamedType("seven", new PTypeUnion()),
                new NamedType("eight", new PTypeUnion()),
                new NamedType("nine", new PTypeUnion()),
                new NamedType("value", new PType(PTypeEnumeration.longinteger)));
            for (int i = 0; i < 10; i++)
            {
                ((PTypeUnion)tpBtree.Fields[i].Type).Variants = new[]
                {
                    new NamedType("empty", new PType(PTypeEnumeration.none)),
                    new NamedType("next", tpBtree)
                }
            }
            ;

            return(tpBtree);
        }
Example #2
0
        // ===============================================
        // ============== Методы доступа =================
        // ===============================================

        // ========== Для записей =========
        public PaEntry Field(int index)
        {
            if (tp.Vid != PTypeEnumeration.record)
            {
                throw new Exception("Err in TPath formula: Field can't be applied to structure of vid " + tp.Vid);
            }
            PTypeRecord mtr = (PTypeRecord)tp;

            if (index >= mtr.Fields.Length)
            {
                throw new Exception("Err in TPath formula: index of Field is too large " + index);
            }

            long pos = this.offset;

            for (int i = 0; i < index; i++)
            {
                PType t = mtr.Fields[i].Type;
                if (t.HasNoTail)
                {
                    pos += t.HeadSize;
                }
                else
                {
                    pos = Skip(t, pos);
                }
            }
            return(new PaEntry(mtr.Fields[index].Type, pos, cell));
        }
Example #3
0
        public static void Main301()
        {
            Console.WriteLine("Start Main301");

            // ============ Типы структур и значения с труктур в объектном представлении ===========
            // Создадим типы записи и последовательности записей
            PType tp1 = new PTypeRecord(
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("age", new PType(PTypeEnumeration.integer)));
            PType tp2 = new PTypeSequence(tp1);

            // Создадим структурные значения этих типов в объектном представлении
            object val1 = new object[] { "Иванов", 22 };
            object val2 = new object[]
            {
                new object[] { "Иванов", 22 },
                new object[] { "Петров", 33 },
                new object[] { "Сидоров", 44 }
            };

            // Визуализация структур в объектном представлении
            Console.WriteLine(tp1.Interpret(val1));
            Console.WriteLine(tp2.Interpret(val2));

            // ============== Сериализация/Десериализация =============
            // Сериализация выполняет отображение структуры на поток символов (текстовая сериализация) или
            // поток байтов (бинарная сериализация). Десериализация выполняет обратное преобразование.
            Stream stream = new MemoryStream();
            // сериализация делается через текстовый райтер
            TextWriter tw = new StreamWriter(stream);

            TextFlow.Serialize(tw, val2, tp2);
            tw.Flush();
            // посмотрим что записалось
            stream.Position = 0L;
            TextReader tr  = new StreamReader(stream);
            string     sss = tr.ReadToEnd();

            Console.WriteLine("Накопилось в стриме: " + sss);

            // десериализаця делатеся через текстовый ридер
            stream.Position = 0L;
            object val = TextFlow.Deserialize(tr, tp2);

            // Теперь надо посмотреть что в объекте
            Console.WriteLine("После цикла сериализация/десериализация: " + tp2.Interpret(val));

            // Бинарная сериализация
            // bool - 1 байт
            // byte - 1 байт
            // int - 4 байта
            // long, double - 8 байтов
            // строка - набор байтов определяемый BinaryWriter.Write((string)s)
            // запись - подряд стоящие сериализации полей записи
            // последовательность - long длина последовательности, подряд стоящие развертки элементов
            //
            // Бинарная сериализация совместима с BinaryWriter и BinaryReader

            // выполняется точно также, как текстовая сериализация (пример сделаю позже)
        }
Example #4
0
        public RDFGraph(string path)
        {
            Path = path;
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            PType tp_triple = new PTypeRecord(
                new NamedType("subj", new PType(PTypeEnumeration.integer)),
                new NamedType("pred", new PType(PTypeEnumeration.integer)),
                new NamedType("obj", ObjectVariantsPolarType.ObjectVariantPolarType));

            table    = new TableView(path + "triples", tp_triple);
            ps_index = new IndexCascadingDynamic <int>(path + "ps_index",
                                                       (IBearingTableImmutable)table,
                                                       ob => (int)((object[])((object[])ob)[1])[1],
                                                       ob => (int)((object[])((object[])ob)[1])[0],
                                                       i => i);
            po_index = new IndexCascadingDynamic <ObjectVariants>(path + "po_index",
                                                                  (IBearingTableImmutable)table,
                                                                  ob => (int)((object[])((object[])ob)[1])[1],
                                                                  ob => ((object[])((object[])ob)[1])[2].ToOVariant(NodeGenerator),
                                                                  ov => ov.GetHashCode());
            textObjectIndex =
                new TextObjectIndex((ulong)(table.TableCell.IsEmpty ? 10 : table.TableCell.Root.Count() / 3 + 1),
                                    this);
            OnAddPortion += po_index.index_arr.FillPortion;
            OnAddPortion += ps_index.index_arr.FillPortion;
            OnAddPortion += textObjectIndex.FillPortion;
            NodeGenerator = NodeGeneratorInt.Create(new NameTableDictionaryRam(path)); //new NametableLinearBuffered(path));
            _ng           = NodeGenerator as NodeGeneratorInt;
            ((NameTableDictionaryRam)_ng.coding_table).Expand((int)10000 / 3 + 1, Enumerable.Repeat(SpecialTypesClass.RdfType, 1));

            Start();
        }
Example #5
0
        public static void Main()
        {
            Console.WriteLine("Start Experiments.");

            string path = "../../";

            // Файл
            FileStream fs = new FileStream(path + "tn.jpg", FileMode.Open, FileAccess.Read);

            PType tp_complex = new PTypeRecord(
                new NamedType("f1", new PType(PTypeEnumeration.integer)),
                new NamedType("f2", new PTypeSequence(new PType(PTypeEnumeration.@byte))));
            PxCell xcell = new PxCell(tp_complex, path + "xcell.bin", false);

            // Способ внедрения файла
            xcell.Clear();
            Write(xcell, fs);

            //object obval = xcell.Root.Get();
            //Console.WriteLine(tp_complex.Interpret(obval));

            PxEntry xentry = xcell.Root.Field(1);
            long llen = xentry.Count();
            PxEntry zelement = xentry.Element(0);
            Stream stream = xcell.BasicStream;
            long offset = zelement.offset;
            Console.WriteLine("{0} {1}", llen, offset);

            // Файл записи
            FileStream fsout = new FileStream(path + "tn_out.jpg", FileMode.Create, FileAccess.Write);

            stream.Position = offset;
            stream.CopyTo(fsout);
            fsout.Close();
        }
Example #6
0
        internal object ScanObject(PType typ)
        {
            switch (typ.Vid)
            {
            case PTypeEnumeration.none: return(null);

            case PTypeEnumeration.boolean: return(br.ReadByte());

            case PTypeEnumeration.integer: return(br.ReadInt32());

            case PTypeEnumeration.longinteger: return(br.ReadInt64());

            case PTypeEnumeration.real: return(br.ReadDouble());

            case PTypeEnumeration.@byte: return(br.ReadByte());

            case PTypeEnumeration.sstring:
            {
                //int len = br.ReadInt32();
                //char[] chrs = br.ReadChars(len);
                //return new string(chrs);
                return(br.ReadString());
            }

            case PTypeEnumeration.record:
            {
                PTypeRecord r_tp   = (PTypeRecord)typ;
                object[]    fields = new object[r_tp.Fields.Length];
                for (int i = 0; i < r_tp.Fields.Length; i++)
                {
                    fields[i] = ScanObject(r_tp.Fields[i].Type);
                }
                return(fields);
            }

            case PTypeEnumeration.sequence:
            {
                PTypeSequence mts  = (PTypeSequence)typ;
                PType         tel  = mts.ElementType;
                long          llen = br.ReadInt64();
                object[]      els  = new object[llen];
                for (long ii = 0; ii < llen; ii++)
                {
                    els[ii] = ScanObject(tel);
                }
                return(els);
            }

            case PTypeEnumeration.union:
            {
                PTypeUnion mtu = (PTypeUnion)typ;
                int        v   = br.ReadByte();
                PType      mt  = mtu.Variants[v].Type;
                return(new object[] { v, ScanObject(mt) });
            }

            default: throw new Exception("Err in TPath ScanObject(): type is not implemented " + typ.Vid);
            }
        }
Example #7
0
        public static void Main1(string[] args)
        {
            PType tp_person = new PTypeRecord(
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("age", new PType(PTypeEnumeration.integer)),
                new NamedType("reside", new PType(PTypeEnumeration.integer)));
            PType tp_city = new PTypeRecord(
                new NamedType("name", new PType(PTypeEnumeration.sstring)));
            string path = @"..\..\..\Databases\";

            Console.WriteLine("Start");
            //создание или открытие базы данных
            Database db = new Database(path + @"po_db\");

            // Фаза 1: добавление коллекций
            //db.CreateCollection("persons", tp_person);
            //db.CreateCollection("cities", tp_city);

            //Фаза 1
            Collection persons = db.Collection("persons");
            Collection cities  = db.Collection("cities");

            //var c1 = cities.CreateElement(new object[] { "Новосибирск" });
            //var c2 = cities.CreateElement(new object[] { "Бердск" });
            //var p1 = persons.CreateElement(new object[] { "Иванов", 33, -1 });
            //var p2 = persons.CreateElement(new object[] { "Петров", 34, c1.Id });
            //var p3 = persons.CreateElement(new object[] { "Сидоров", 35, c2.Id });

            //var c3 = cities.CreateElement(new object[] { "Искитим" });
            //var p1 = persons.Element(0);
            //persons.UpdateElement(p1, new object[] { "Иванов Иван Иванович", 33, c3.Id });

            //Фаза 2
            foreach (var element in db.Collection("persons").Elements())
            {
                var v = element.Get();
                Console.WriteLine("Element: {0}", tp_person.Interpret(v));
            }

            //// Другой способ
            //Person pers = persons.Element<Person>(1);
            //Console.WriteLine("{0} {1}", pers.Name, pers.Age);
            //City cty = cities.Element<City>(1);
            //Console.WriteLine("{0} ", cty.Name);

            Person pers = persons.Element <Person>(1);

            Console.WriteLine("Element: {0}", tp_person.Interpret(pers.Get()));
            Console.WriteLine("{0} {1}", pers.Name, pers.Age);
            City cty = pers.City;

            Console.WriteLine("{0} ", cty.Name);

            //// Изменение
            //pers.Age = 35;
            //pers.Name = "Петренко";

            Console.WriteLine("ok.");
        }
Example #8
0
        //START_SOURCE_CODE
        public void Run()
        {
            Console.WriteLine("Start Task03_PolarDB");
            dbpath = System.IO.Path.GetTempPath();
            PType  tp   = new PType(PTypeEnumeration.sstring);
            PaCell cell = new PaCell(tp, dbpath + "test.pac", false);

            cell.Clear();
            cell.Fill("Привет из ячейки базы данных!");
            Console.WriteLine("Содержимое ячейки: {0}", cell.Root.Get());

            PType tp_rec = new PTypeRecord(
                new NamedType("имя", new PType(PTypeEnumeration.sstring)),
                new NamedType("возраст", new PType(PTypeEnumeration.integer)),
                new NamedType("мужчина", new PType(PTypeEnumeration.boolean)));
            object rec_value = new object[] { "Пупкин", 22, true };
            PaCell cell_rec  = new PaCell(tp_rec, dbpath + "test_rec.pac", false);

            cell_rec.Clear();
            cell_rec.Fill(rec_value);
            object from_rec = cell_rec.Root.Get();

            Console.WriteLine(tp_rec.Interpret(from_rec));

            PType  tp_seq    = new PTypeSequence(tp_rec);
            object seq_value = new object[]
            {
                new object[] { "Иванов", 24, true },
                new object[] { "Петрова", 18, false },
                new object[] { "Пупкин", 22, true }
            };
            PaCell cell_seq = new PaCell(tp_seq, dbpath + "test_seq.pac", false);

            cell_seq.Clear();
            cell_seq.Fill(seq_value);
            object from_seq = cell_seq.Root.Get();

            Console.WriteLine(tp_seq.Interpret(from_seq));

            cell_seq.Root.AppendElement(new object[] { "Сидоров", 23, true });
            Console.WriteLine(tp_seq.Interpret(cell_seq.Root.Get()));

            long v0 = cell_seq.Root.Count();
            var  v1 = cell_seq.Root.Element(2).Field(0).Get();
            var  v2 = cell_seq.Root.Element(3).Field(1).Get();

            Console.WriteLine($"{v0} {v1} {v2}");

            cell_seq.Root.Element(1).Field(1).Set(19);
            cell_seq.Root.Element(1).Field(2).Set(true);
            Console.WriteLine(tp_seq.Interpret(cell_seq.Root.Get()));
            cell_seq.Flush();
            cell_seq.Close();
            cell_rec.Flush();
            cell_rec.Close();
            cell.Flush();
            cell.Close();
        }
Example #9
0
        public static void Main1(string[] args)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            PType tp_rec = new PTypeRecord(
                new NamedType("id", new PType(PTypeEnumeration.integer)),
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("age", new PType(PTypeEnumeration.integer)));
            PaCell cell    = new PaCell(new PTypeSequence(tp_rec), path + "people.pac", false);
            PType  tp_pair = new PTypeRecord(
                new NamedType("id", new PType(PTypeEnumeration.integer)),
                new NamedType("offset", new PType(PTypeEnumeration.longinteger)));
            PaCell cell_index = new PaCell(new PTypeSequence(tp_pair), path + "people_index.pac", false);

            int    npersons = 1_000_000;
            Random rnd      = new Random();

            Console.WriteLine("Start Task04: Main1");

            // Загрузка данных
            sw.Restart();
            cell.Clear();
            cell.Fill(new object[0]);
            cell_index.Clear();
            cell_index.Fill(new object[0]);
            for (int i = 0; i < npersons; i++)
            {
                int  code   = npersons - i;
                long offset = cell.Root.AppendElement(new object[] { code, "=" + code + "=", rnd.Next(120) });
                cell_index.Root.AppendElement(new object[] { code, offset });
            }
            cell.Flush();
            cell_index.Flush();
            cell_index.Root.SortByKey <int>(pair => (int)((object[])pair)[0]);
            sw.Stop();
            Console.WriteLine($"load {npersons} records. duration {sw.ElapsedMilliseconds}");

            // Поиск
            int key    = npersons * 2 / 3;
            int ntests = 10000;

            sw.Restart();
            PaEntry entry = cell.Root.Element(0);

            for (int j = 0; j < ntests; j++)
            {
                key = rnd.Next(npersons);
                PaEntry en      = cell_index.Root.BinarySearchFirst(ent => ((int)((object[])ent.Get())[0]).CompareTo(key));
                object  operson = entry.SetOffset((long)((object[])en.Get())[1]).Get();
                //Console.WriteLine($"val={tp_rec.Interpret(operson)}");
            }
            sw.Stop();
            Console.WriteLine($"getByKey {ntests} times. duration {sw.ElapsedMilliseconds}");
        }
Example #10
0
        private static void Test_Mag_Store()
        {
            string path = "mag_data/";

            Console.WriteLine("Start mag Store test");
            PType tp_ov = new PTypeUnion(
                new NamedType("dummy", new PType(PTypeEnumeration.none)),
                new NamedType("iri", new PType(PTypeEnumeration.integer)),
                new NamedType("str", new PType(PTypeEnumeration.sstring)));
            // Тип триплепта
            PType tp_triple = new PTypeRecord(
                //new NamedType("id", new PType(PTypeEnumeration.integer)), // Возможно, это временное решение
                new NamedType("subj", new PType(PTypeEnumeration.integer)),
                new NamedType("pred", new PType(PTypeEnumeration.integer)),
                new NamedType("obj", tp_ov));

            using (var table = File.Open(path + "triples.pac", FileMode.OpenOrCreate))
                using (var index1 = File.Open(path + "index1.pac", FileMode.OpenOrCreate))
                    using (var index2 = File.Open(path + "index2.pac", FileMode.OpenOrCreate))
                    {
                        Mag_Store store    = new Mag_Store(table, index1, index2);
                        int       nrecords = 1_000_000;
                        T.Restart();
                        // codes: 0 - <type>, 1 - <person>, 2 - <name>, 3... persons
                        var flow = Enumerable.Range(0, nrecords).SelectMany(i => new object[]
                        {
                            // субъект, предикат, объект
                            new object[] { i + 3, 0, new object[] { 1, 1 } },
                            new object[] { i + 3, 2, new object[] { 2, "Pupkin" + i } },
                        }).ToArray();
                        store.Load(flow);
                        T.Stop();
                        Console.WriteLine($"Load of {nrecords * 2} triples ok. Duration={T.ElapsedMilliseconds}");

                        var query = store.GetTriplesBySubject(nrecords * 2 / 3).ToArray();
                        //Console.WriteLine(query.Count());
                        foreach (var q in query)
                        {
                            Console.WriteLine(tp_triple.Interpret(q));
                        }

                        int    nprobes = 1000;
                        Random rnd     = new Random();
                        T.Restart();
                        for (int i = 0; i < nprobes; i++)
                        {
                            int code = rnd.Next(nrecords);
                            store.GetTriplesBySubject(code).Count();
                        }
                        T.Stop();
                        Console.WriteLine($"GetTriplesBySubject {nprobes} times. Duration={T.ElapsedMilliseconds}");
                    }
        }
Example #11
0
        public Nametable32(Func <Stream> stream_gen)
        {
            PType tp_elem = new PTypeRecord(
                new NamedType("code", new PType(PTypeEnumeration.integer)),
                new NamedType("str", new PType(PTypeEnumeration.sstring)));

            cod_str   = new UniversalSequenceBase(tp_elem, stream_gen());
            offsets   = new UniversalSequenceBase(new PType(PTypeEnumeration.longinteger), stream_gen());
            index_str = new IndexKey32CompImmutable(stream_gen, cod_str, ob => true,
                                                    ob => Hashfunctions.HashRot13((string)((object[])ob)[1]), null);
            dyna_index = new Dictionary <string, int>();
        }
Example #12
0
        public static void Main400()
        {
            Console.WriteLine("Start Main400");

            PType tp = new PTypeRecord(
                new NamedType("id", new PType(PTypeEnumeration.integer)),
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("age", new PType(PTypeEnumeration.integer)));
            object val1 = new object[] { 123, "Ivan", 21 };
            var    s    = tp.Interpret(val1);

            Console.WriteLine(s);
        }
Example #13
0
 // Техническая процедура Пропускает поле, выдает адрес, следующий за ним. Указатель никуда не установлен
 private long Skip(PType tp, long off)
 {
     if (tp.HasNoTail)
     {
         return(off + tp.HeadSize);
     }
     if (tp.Vid == PTypeEnumeration.sstring)
     {
         long offout;
         cell.ReadString(off, out offout);
         return(offout);
     }
     if (tp.Vid == PTypeEnumeration.record)
     {
         long        field_offset = off;
         PTypeRecord mtr          = (PTypeRecord)tp;
         foreach (var pa in mtr.Fields)
         {
             field_offset = Skip(pa.Type, field_offset);
         }
         return(field_offset);
     }
     if (tp.Vid == PTypeEnumeration.sequence)
     {
         PTypeSequence mts  = (PTypeSequence)tp;
         PType         tel  = mts.ElementType;
         long          llen = cell.ReadLong(off);
         if (tel.HasNoTail)
         {
             return(off + 8 + llen * tel.HeadSize);
         }
         long element_offset = off + 8;
         for (long ii = 0; ii < llen; ii++)
         {
             element_offset = Skip(tel, element_offset);
         }
         return(element_offset);
     }
     if (tp.Vid == PTypeEnumeration.union)
     {
         PTypeUnion mtu = (PTypeUnion)tp;
         int        v   = cell.ReadByte(off);
         if (v < 0 || v >= mtu.Variants.Length)
         {
             throw new Exception("Err in Skip (TPath-formula): wrong variant for union " + v);
         }
         PType mt = mtu.Variants[v].Type;
         return(Skip(mt, off + 1));
     }
     throw new Exception("Assert err: 2874");
 }
Example #14
0
        public EntitiesWideTable(string path, DiapasonScanner <string>[] scanners)
        {
            this.path     = path;
            this.scanners = scanners;
            PType DiaRec = new PTypeRecord(
                new NamedType("start", new PType(PTypeEnumeration.longinteger)),
                new NamedType("number", new PType(PTypeEnumeration.longinteger)));
            PType tp = new PTypeSequence(new PTypeRecord(
                                             new NamedType("entity", new PType(PTypeEnumeration.sstring)),
                                             new NamedType("spo", DiaRec),
                                             new NamedType("spo_op", DiaRec),
                                             new NamedType("spd", DiaRec)));

            ewtable = new PaCell(tp, path + "ewtable.pac", false);
        }
Example #15
0
        public EntitiesWideTable(string path, int count)
        {
            //  this.path = path;

            PType DiaRec = new PTypeRecord(
                new NamedType("start", new PType(PTypeEnumeration.longinteger)),
                new NamedType("number", new PType(PTypeEnumeration.longinteger)));
            PType tp = new PTypeSequence(new PTypeRecord(
                                             new NamedType("entity", new PType(PTypeEnumeration.integer)),
                                             new NamedType("spo", DiaRec),   //TODO use count
                                             new NamedType("spo_op", DiaRec),
                                             new NamedType("spd", DiaRec)));

            ewtable = new PaCell(tp, path + "ewtable.pac", false);
        }
        public void Open(bool readOnlyMode)
        {
            doublesCell = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.real)), dataCellPath + "/doublesLiterals.pac", readOnlyMode);
            var pTypeString      = new PType(PTypeEnumeration.sstring);
            var pTypeStringsPair = new PTypeRecord(new NamedType("value", pTypeString),
                                                   new NamedType("add info", pTypeString));

            stringsCell      = new PaCell(new PTypeSequence(pTypeStringsPair), dataCellPath + "/stringsLiterals.pac", readOnlyMode);
            boolsCell        = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.boolean)), dataCellPath + "/booleansLiterals.pac", readOnlyMode);
            typedObjectsCell = new PaCell(new PTypeSequence(pTypeStringsPair), dataCellPath + "/typedObjectsLiterals.pac", readOnlyMode);
            stringsArhive    = new Archive(dataCellPath + "/strings archive");
            var ptypeCode = new PTypeSequence(new PType(PTypeEnumeration.@byte));

            StringsArchedCell = new PaCell(new PTypeSequence(new PTypeRecord(new NamedType("string code", ptypeCode), new NamedType("lang code", ptypeCode))), dataCellPath + "/strings archive/binary data", false);
        }
        public IndexCascadingImmutable(string pathName, IBearingTableImmutable table, Func <object, int> key1Producer, Func <object, Tkey> key2Producer, Func <Tkey, int> half2Producer)
        {
            PType tp_record = new PTypeRecord(
                new NamedType("offset", new PType(PTypeEnumeration.longinteger)),
                new NamedType("key1", new PType(PTypeEnumeration.integer)),
                new NamedType("keyhkey2", new PType(PTypeEnumeration.integer)));

            index_cell = new PaCell(new PTypeSequence(tp_record),
                                    pathName + "_2.pac", false);
            groups_index = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.integer)),
                                      pathName + "_g.pac", false);

            Table         = table;
            Key1Producer  = key1Producer;
            Key2Producer  = key2Producer;
            Half2Producer = half2Producer;
        }
Example #18
0
        public static void Main2()
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            string path = "../../../Databases/";
            int NumberOfRecords = 1000000;
            Random rnd = new Random();
            Console.WriteLine("Start Universal Index. Main2()");

            PType tp_table_element = new PTypeRecord(
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("age", new PType(PTypeEnumeration.integer)));
            IBearingTable table = new TableView(path + "table", tp_table_element);
            sw.Restart();
            bool tobuild = true;
            if (tobuild)
            {
                table.Fill(Enumerable.Range(0, NumberOfRecords).Select(i =>
                    (object)(new object[] { i.ToString(), i == NumberOfRecords / 2 ? -1 : i })));
                sw.Stop();
                Console.WriteLine("Load Table of {0} elements ok. Duration {1}", NumberOfRecords, sw.ElapsedMilliseconds);
            }
            IIndexImmutable<string> s_index = new IndexViewImmutable<string>(path + "s_index")
            {
                Table = table,
                KeyProducer = va => (string)((object[])(((object[])va)[1]))[0]
            };
            if (tobuild)
            {
                sw.Restart();
                s_index.Build();
                sw.Stop();
                Console.WriteLine("s_index Build ok. Duration {0}", sw.ElapsedMilliseconds);
            }
            sw.Restart();
            int cnt = 0;
            for (int i = 0; i < 1000; i++)
            {
                int c = s_index.GetAllByKey(rnd.Next(NumberOfRecords * 3 / 2 - 1).ToString()).Count();
                if (c > 1) Console.WriteLine("Unexpected Error: {0}", c);
                cnt += c;
            }
            sw.Stop();
            Console.WriteLine("1000 GetAllByKey ok. Duration={0} cnt={1}", sw.ElapsedMilliseconds, cnt);
        }
Example #19
0
        static void Main201()
        {
            Console.WriteLine("Start Program201");
            // Определение поляровских типов
            PType tp_rec = new PTypeRecord(
                new NamedType("имя", new PType(PTypeEnumeration.sstring)),
                new NamedType("возраст", new PType(PTypeEnumeration.integer)),
                new NamedType("мужчина", new PType(PTypeEnumeration.boolean)));
            PType tp_seq = new PTypeSequence(tp_rec);
            // Задание поляровского объекта и его визуализация
            object seq_value = new object[]
            {
                new object[] { "Иванов", 24, true },
                new object[] { "Петрова", 18, false },
                new object[] { "Пупкин", 22, true }
            };

            Console.WriteLine(tp_seq.Interpret(seq_value));

            // Текстовая сериализация
            // Создадим поток байтов. Это мог бы быть файл, но сделали в памяти
            MemoryStream mstream = new MemoryStream();
            // Поработаем через текстовый интерфейс
            TextWriter tw = new StreamWriter(mstream);

            TextFlow.Serialize(tw, seq_value, tp_seq);
            tw.Flush();
            // Прочитаем то что записали
            TextReader tr = new StreamReader(mstream);

            mstream.Position = 0L;
            string instream = tr.ReadToEnd();

            Console.WriteLine($"======== instream={instream}");
            Console.WriteLine();

            // Теперь десериализуем
            object db = null;

            mstream.Position = 0L;
            db = TextFlow.Deserialize(tr, tp_seq);
            // проинтерпретируем объект и посмотрим
            Console.WriteLine(tp_seq.Interpret(db));
            Console.WriteLine();
        }
Example #20
0
        private static BTree TestToBTree(IEnumerable <object[]> query, PTypeRecord ptElement, string path,
                                         Func <object, PxEntry, int> edepth)
        {
            var tt0           = DateTime.Now;
            var treeFromQuery = query.ToBTree(ptElement, path + "TreeFromQuery.pxc", edepth, o => ((object[])o)[0], false);

            Console.WriteLine("tree from query createtd,duration={0}", (DateTime.Now - tt0).Ticks / 10000L);
            tt0 = DateTime.Now;

            // Иcпытание на "предельные" характеристики по скорости ввода данных. Данные сортируются, а потом выстраивается в
            // оперативной памяти структурный объект, соответствующий синтаксису и семантике введенного бинарного дерева.
            // Потом объект вводится в ячейку и испытывается.
            // На моем домашнем компьютере - 130 мс.
            TestSearch(treeFromQuery, "Марчук Александр Гурьевич");
            Console.WriteLine("======TestSearch ok. duration=" + (DateTime.Now - tt0).Ticks / 10000L);
            Console.WriteLine();
            return(treeFromQuery);
        }
Example #21
0
        public NameTableUniversal(string path)
        {
            this.path = path;
            PType tp_tabelement = new PTypeRecord(
                new NamedType("code", new PType(PTypeEnumeration.integer)),
                new NamedType("str", new PType(PTypeEnumeration.sstring)));

            this.table = new TableView(path + "cstable", tp_tabelement);
            //next_code = (int)table.Count();
            offset_array = new IndexViewImmutable <int>(path + "offsets")
            {
                Table       = this.table,
                KeyProducer = pair => (int)((object[])(((object[])pair)[1]))[0],
                Tosort      = false
            };
            offsets = new IndexDynamic <int, IndexViewImmutable <int> >(true)
            {
                Table = this.table,
                //KeyProducer = pair => (int)((object[])pair)[0],
                KeyProducer = pair => (int)((object[])(((object[])pair)[1]))[0],
                IndexArray  = offset_array
            };
            table.RegisterIndex(offsets);
            s_index_array_path = path + "s_index";

            s_index_array = new IndexHalfkeyImmutable <string>(s_index_array_path)
            {
                Table        = table,
                KeyProducer  = pair => (string)((object[])(((object[])pair)[1]))[1],
                HalfProducer = key => key.GetHashCode()
            };
            s_index_array.Scale = new ScaleCell(path + "dyna_index_str_half")
            {
                IndexCell = s_index_array.IndexCell
            };
            //s_index_array.Scale = new ScaleMemory() { IndexCell = s_index_array.IndexCell };
            s_index = new IndexDynamic <string, IndexHalfkeyImmutable <string> >(true)
            {
                Table       = table,
                KeyProducer = pair => (string)((object[])(((object[])pair)[1]))[1],
                IndexArray  = s_index_array
            };
            table.RegisterIndex(s_index);
        }
Example #22
0
        public static void Main21()
        {
            Console.WriteLine("Start Program21KeyValueExp");
            Random rnd = new Random();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            string        path      = dbpath + "Databases/";
            int           cnt       = 0;
            Func <Stream> genStream = () => File.Open(path + "data" + (cnt++) + ".bin",
                                                      FileMode.OpenOrCreate, FileAccess.ReadWrite);
            PType tp_person = new PTypeRecord(
                new NamedType("id", new PType(PTypeEnumeration.integer)),
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("age", new PType(PTypeEnumeration.real)));
            KVStorage32 storage = new KVStorage32(tp_person, genStream);

            sw.Restart();
            int npersons = 1_000_000;

            storage.Build(Enumerable.Range(0, npersons)
                          .Select(i => new object[] { npersons - i - 1, "Pupkin " + (npersons - i - 1), 33.0 }));
            sw.Stop();
            Console.WriteLine($"load duration={sw.ElapsedMilliseconds}");

            int key = npersons * 2 / 3;
            var qq  = storage.GetAllByKey(key);

            foreach (object q in qq)
            {
                Console.WriteLine(tp_person.Interpret(q));
            }

            int nprobe = 10_000;
            int total  = 0;

            sw.Restart();
            for (int i = 0; i < nprobe; i++)
            {
                int ke = rnd.Next(npersons);
                total += storage.GetAllByKey(key).Count();
            }
            sw.Stop();
            Console.WriteLine($"{nprobe} probes ok. duration={sw.ElapsedMilliseconds}");
        }
Example #23
0
        public GroupedEntities(string path)
        {
            this.path = path;
            PType tDiapason = new PTypeRecord(
                new NamedType("start", new PType(PTypeEnumeration.longinteger)),
                new NamedType("number", new PType(PTypeEnumeration.longinteger)));
            PType tDiapLinks = new PTypeRecord(
                new NamedType("all", tDiapason),
                new NamedType("predList", new PTypeSequence(new PTypeRecord(
                                                                new NamedType("pred", new PType(PTypeEnumeration.integer)),
                                                                new NamedType("diap", tDiapason)))));

            this.tGETable = new PTypeSequence(new PTypeRecord(
                                                  new NamedType("entity", new PType(PTypeEnumeration.integer)),
                                                  new NamedType("spo", tDiapLinks),
                                                  new NamedType("spo_op", tDiapLinks),
                                                  new NamedType("spd", tDiapLinks)));
            this.getable = new PaCell(tGETable, path + "getable.pac", false);
        }
Example #24
0
        public Nametable32(Func <Stream> stream_gen)
        {
            PType tp_elem = new PTypeRecord(
                new NamedType("code", new PType(PTypeEnumeration.integer)),
                new NamedType("str", new PType(PTypeEnumeration.sstring)));

            table       = new UniversalSequenceBase(tp_elem, stream_gen());
            str_offsets = new UniversalSequence <long>(new PType(PTypeEnumeration.longinteger), stream_gen());
            Comparer <object> comp_str = Comparer <object> .Create(new Comparison <object>((object a, object b) =>
            {
                var aa = (string)((object[])a)[1];
                var bb = (string)((object[])b)[1];
                return(aa.CompareTo(bb));
            }));

            name_index = new IndexKey32CompImm(stream_gen, table,
                                               ob => Hashfunctions.HashRot13((string)((object[])ob)[1]), comp_str);
            dyna_index = new Dictionary <string, int>();
        }
Example #25
0
        public NametableTry(string path)
        {
            PType tp_person = new PTypeRecord(
                new NamedType("code", new PType(PTypeEnumeration.integer)),
                new NamedType("name", new PType(PTypeEnumeration.sstring)));

            tab_person = new TableView(path + "nametable", tp_person);
            // Индексы: Персона
            Func <object, int> person_code_keyproducer = v => (int)((object[])((object[])v)[1])[0];

            ind_arr_person = new IndexKeyImmutable <int>(path + "code_ind")
            {
                Table       = tab_person,
                KeyProducer = person_code_keyproducer,
                Scale       = null
            };
            ind_arr_person.Scale = new ScaleCell(path + "code_ind")
            {
                IndexCell = ind_arr_person.IndexCell
            };
            index_person = new IndexDynamic <int, IndexKeyImmutable <int> >(true)
            {
                Table       = tab_person,
                IndexArray  = ind_arr_person,
                KeyProducer = person_code_keyproducer
            };
            Func <object, string> name_keyproducer = v => (string)((object[])((object[])v)[1])[1];

            ind_arr_person_name = new IndexViewImmutable <string>(path + "name_ind")
            {
                Table       = tab_person,
                KeyProducer = name_keyproducer,
                Scale       = null
            };
            index_person_name = new IndexDynamic <string, IndexViewImmutable <string> >(false)
            {
                Table       = tab_person,
                IndexArray  = ind_arr_person_name,
                KeyProducer = name_keyproducer
            };
            tab_person.RegisterIndex(index_person);
            tab_person.RegisterIndex(index_person_name);
        }
Example #26
0
        // ========== Для записей =========
        public PxEntry Field(int ind)
        {
            if (this.typ.Vid != PTypeEnumeration.record)
            {
                throw new Exception("Err: Field() need record");
            }
            PTypeRecord mtr = (PTypeRecord)this.typ;

            if (ind < 0 || ind >= mtr.Fields.Length)
            {
                throw new Exception("Wrong index in Field()");
            }
            var shift = mtr.Fields.Take(ind).Select(pair => pair.Type.HeadSize).Sum(); // .Where((f, i) => i < ind)

            return(new PxEntry(
                       mtr.Fields[ind].Type,
                       this.offset + shift,
                       this.fis));
        }
        /// <summary>
        ///  Тип
        /// BTree<T> = empty^none,
        /// pair^{element: T, less: BTree<T>, more: BTree<T>};
        /// </summary>
        /// <param name="tpElement"></param>
        /// <returns></returns>
        private static PType PTypeTree(PType tpElement)
        {
            var tpBtree = new PTypeRecord();

            tpBtree = new PTypeRecord(
                new NamedType("element", tpElement),
                new NamedType("next", new PTypeUnion()));

            ((PTypeUnion)tpBtree.Fields[1].Type).Variants = new[]
            {
                new NamedType("empty", new PType(PTypeEnumeration.none)),
                new NamedType("pair", new PTypeRecord(
                                  new NamedType("less", tpBtree),
                                  new NamedType("more", tpBtree),
                                  //1 - слева больше, -1 - справа больше.
                                  new NamedType("balance", new PType(PTypeEnumeration.integer))))
            };

            return(tpBtree);
        }
Example #28
0
 private void BuildCollectionStructure()
 {
     foreach (XElement frecord in fschema.Elements())
     {
         NamedType[] nt_arr = frecord.Elements()
                              .Where(el => el.Name == "field" || el.Name == "direct")
                              .Select(el =>
         {
             PType tpe = null;
             if (el.Name == "direct")
             {
                 tpe = new PType(PTypeEnumeration.integer);
             }
             else if (el.Name == "field")
             {
                 string el_type = el.Attribute("datatype").Value;
                 if (el_type == "string")
                 {
                     tpe = new PType(PTypeEnumeration.sstring);
                 }
                 else if (el_type == "int")
                 {
                     tpe = new PType(PTypeEnumeration.integer);
                 }
             }
             return(new NamedType(el.Attribute("prop").Value, tpe));
         })
                              .ToArray();
         PType  tp   = new PTypeRecord(nt_arr);
         string type = frecord.Attribute("type").Value;
         db.CreateCollection(type, tp);
         // Заведем индексы
         foreach (XElement el in frecord.Elements("direct"))
         { // есть type и есть:
             string column           = el.Attribute("prop").Value;
             string totype           = el.Element("record").Attribute("type").Value;
             string name_combination = type + "(" + column + ")" + totype;
             db.CreateCollection(name_combination, new PType(PTypeEnumeration.longinteger));
         }
     }
 }
Example #29
0
        public NameTableUniversal(string path)
        {
            this.path = path;
            PType tp_tabelement = new PTypeRecord(
                new NamedType("code", new PType(PTypeEnumeration.integer)),
                new NamedType("str", new PType(PTypeEnumeration.sstring)));
            this.table = new TableView(path + "cstable", tp_tabelement);
            //next_code = (int)table.Count();
            offset_array = new IndexViewImmutable<int>(path + "offsets")
            {
                Table = this.table,
                KeyProducer = pair => (int)((object[])(((object[])pair)[1]))[0],
                tosort = false
            };
            offsets = new IndexDynamic<int, IndexViewImmutable<int>>(true)
            {
                Table = this.table,
                //KeyProducer = pair => (int)((object[])pair)[0],
                KeyProducer = pair => (int)((object[])(((object[])pair)[1]))[0],
                IndexArray = offset_array
            };
            table.RegisterIndex(offsets);
            s_index_array_path = path + "s_index";

            s_index_array = new IndexHalfkeyImmutable<string>(s_index_array_path)
            {
                Table = table,
                KeyProducer = pair => (string)((object[])(((object[])pair)[1]))[1],
                HalfProducer = key => key.GetHashModifiedBernstein()
            };
            s_index_array.Scale = new ScaleCell(path + "dyna_index_str_half") { IndexCell = s_index_array.IndexCell };
            //s_index_array.Scale = new ScaleMemory() { IndexCell = s_index_array.IndexCell };
            s_index = new IndexDynamic<string, IndexHalfkeyImmutable<string>>(true)
            {
                Table = table,
                KeyProducer = pair => (string)((object[])(((object[])pair)[1]))[1],
                IndexArray = s_index_array
            };
            table.RegisterIndex(s_index);
        }
Example #30
0
        private static void TestTreeOfInt(IEnumerable <object[]> query, string path)
        {
            PType treePType = new PTypeRecord(new NamedType("id_hash", new PType(PTypeEnumeration.integer)),
                                              new NamedType("indexes", new PTypeSequence(new PType(PTypeEnumeration.longinteger))));
            long sample = 0;
            var  tt0    = DateTime.Now;

            var tree = query.Select(q => (string)q[0])
                       .GroupBy(q => q.GetHashCode())
                       .Select(g => new object[] { g.Key, g.Select(q => sample as object).ToArray() })
                       .ToBTree(treePType, path + "treeOfInt",
                                (o, entry) => (int)((object[])o)[0] - (int)entry.Field(0).Get(),
                                o => (int)((object[])o)[0], false);

            Console.WriteLine("create tree of int long pairs ok " + (DateTime.Now - tt0).TotalMilliseconds);
            var testIdHash = query.First()[0].GetHashCode();//"w20070417_5_8436".GetHashCode();

            tt0 = DateTime.Now;
            var finded = tree.BinarySearch(entry => testIdHash - (int)entry.Field(0).Get());

            Console.WriteLine(finded.Field(0).Get() + " finded, duration=" + (DateTime.Now - tt0).TotalMilliseconds + "ms");
            Console.WriteLine();
            tree.Close();
        }
Example #31
0
        public static void Test()
        {
            PType tp_point = new PTypeRecord(
                new NamedType("x", new PType(PTypeEnumeration.real)),
                new NamedType("y", new PType(PTypeEnumeration.real)));
            PType tp_figure = new PTypeUnion(
                new NamedType("nothing", new PType(PTypeEnumeration.none)),
                new NamedType("point", tp_point),
                new NamedType("polygon", new PTypeSequence(tp_point)),
                new NamedType("circle", new PTypeRecord(
                                  new NamedType("center", tp_point),
                                  new NamedType("radius", new PType(PTypeEnumeration.real)))));
            PType  tp_sequ = new PTypeSequence(tp_figure);
            object sequ    = new object[]
            {
                new object[] { 1, new object[] { 3.5, 7.8 } },
                new object[] { 2, new object[] {
                                   new object[] { 0.0, 0.0 }, new object[] { 1.0, 0.0 }, new object[] { 1.0, 1.0 }, new object[] { 0.0, 1.0 }
                               } },
                new object[] { 3, new object[] { new object[] { 5.0, 5.0 }, 4.99 } }
            };

            // Выполним текстовую сериализацию
            TextFlow.Serialize(Console.Out, sequ, tp_sequ);
            Console.WriteLine();
            // Создадим Stream, сделаем бинарную сериализацию, будем считать, что это файл
            Stream stream = new MemoryStream();

            ByteFlow.Serialize(new BinaryWriter(stream), sequ, tp_sequ);
            // Десериализуем стрим (бинарный файл)
            stream.Position = 0L;
            object sequ_1 = ByteFlow.Deserialize(new BinaryReader(stream), tp_sequ);

            // Проверим полученное значение
            Console.WriteLine(tp_sequ.Interpret(sequ_1));
        }
Example #32
0
 public Stan3TabsInt(string path)
 {
     PType tp_person = new PTypeRecord(
         new NamedType("code", new PType(PTypeEnumeration.integer)),
         new NamedType("name", new PType(PTypeEnumeration.sstring)),
         new NamedType("age", new PType(PTypeEnumeration.integer)));
     PType tp_photo_doc = new PTypeRecord(
         new NamedType("code", new PType(PTypeEnumeration.integer)),
         new NamedType("name", new PType(PTypeEnumeration.sstring)));
     PType tp_reflection = new PTypeRecord(
         new NamedType("code", new PType(PTypeEnumeration.integer)), // Может не быть
         new NamedType("reflected", new PType(PTypeEnumeration.integer)), // ссылки на коды
         new NamedType("in_doc", new PType(PTypeEnumeration.integer)));
     tab_person = new TableView(path + "person", tp_person);
     tab_photo_doc = new TableView(path + "photo_doc", tp_photo_doc);
     tab_reflection = new TableView(path + "reflection", tp_reflection);
     // Индексы: Персона
     Func<object, int> person_code_keyproducer = v => (int)((object[])((object[])v)[1])[0];
     ind_arr_person = new IndexKeyImmutable<int>(path + "person_ind")
     {
         Table = tab_person,
         KeyProducer = person_code_keyproducer,
         Scale = null
     };
     //ind_arr_person.Scale = new ScaleCell(path + "person_ind") { IndexCell = ind_arr_person.IndexCell };
     //ind_arr_person.Scale.Build();
     index_person = new IndexDynamic<int, IndexKeyImmutable<int>>(true)
     {
         Table = tab_person,
         IndexArray = ind_arr_person,
         KeyProducer = person_code_keyproducer
     };
     // Индексы - документ
     Func<object, int> photo_doc_code_keyproducer = v => (int)((object[])((object[])v)[1])[0];
     ind_arr_photo_doc = new IndexKeyImmutable<int>(path + "photo_doc_ind")
     {
         Table = tab_photo_doc,
         KeyProducer = photo_doc_code_keyproducer,
         Scale = null
     };
     //ind_arr_photo_doc.Scale = new ScaleCell(path + "photo_doc_ind") { IndexCell = ind_arr_photo_doc.IndexCell };
     //ind_arr_photo_doc.Scale.Build();
     index_photo_doc = new IndexDynamic<int, IndexKeyImmutable<int>>(true)
     {
         Table = tab_photo_doc,
         IndexArray = ind_arr_photo_doc,
         KeyProducer = photo_doc_code_keyproducer
     };
     // Индекс - reflection-reflected
     Func<object, int> reflected_keyproducer = v => (int)((object[])((object[])v)[1])[1];
     ind_arr_reflected = new IndexKeyImmutable<int>(path + "reflected_ind")
     {
         Table = tab_reflection,
         KeyProducer = reflected_keyproducer,
         Scale = null
     };
     //ind_arr_reflected.Scale = new ScaleCell(path + "reflected_ind") { IndexCell = ind_arr_reflected.IndexCell };
     //ind_arr_reflected.Scale.Build();
     index_reflected = new IndexDynamic<int, IndexKeyImmutable<int>>(false)
     {
         Table = tab_reflection,
         IndexArray = ind_arr_reflected,
         KeyProducer = reflected_keyproducer
     };
     // Индекс - reflection-in_doc
     Func<object, int> in_doc_keyproducer = v => (int)((object[])((object[])v)[1])[2];
     ind_arr_in_doc = new IndexKeyImmutable<int>(path + "in_doc_ind")
     {
         Table = tab_reflection,
         KeyProducer = in_doc_keyproducer,
         Scale = null
     };
     //ind_arr_in_doc.Scale = new ScaleCell(path + "in_doc_ind") { IndexCell = ind_arr_in_doc.IndexCell };
     //ind_arr_in_doc.Scale.Build();
     index_in_doc = new IndexDynamic<int, IndexKeyImmutable<int>>(false)
     {
         Table = tab_reflection,
         IndexArray = ind_arr_in_doc,
         KeyProducer = in_doc_keyproducer
     };
     Func<object, string> name_keyproducer = v => (string)((object[])((object[])v)[1])[1];
     ind_arr_person_name = new IndexViewImmutable<string>(path + "personname_ind")
     {
         Table = tab_person,
         KeyProducer = name_keyproducer,
         Scale = null
     };
     //ind_arr_person_name.Scale = new ScaleCell(path + "personname_ind") {IndexCell = ind_arr_in_doc.IndexCell};
     //ind_arr_person_name.Scale.Build();
     index_person_name = new IndexDynamic<string, IndexViewImmutable<string>>(false)
     {
         Table = tab_person,
         IndexArray = ind_arr_person_name,
         KeyProducer = name_keyproducer
     };
     tab_person.RegisterIndex(index_person);
     tab_person.RegisterIndex(index_person_name);
     tab_photo_doc.RegisterIndex(index_photo_doc);
     tab_reflection.RegisterIndex(index_reflected);
     tab_reflection.RegisterIndex(index_in_doc);
 }
Example #33
0
        public static void Main7()
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            string path = "../../../Databases/";
            int NumberOfRecords = 100000000;
            Random rnd = new Random();
            Console.WriteLine("Start Universal Index. Main7()");

            PType tp_table_element = new PTypeRecord(
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("age", new PType(PTypeEnumeration.integer)));
            TableView table = new TableView(path + "table", tp_table_element);
            sw.Restart();
            bool tobuild = false;
            if (tobuild)
            {
                table.Fill(Enumerable.Range(0, NumberOfRecords).Select(i =>
                    (object)(new object[] { i.ToString(), i == NumberOfRecords / 2 ? -1 : i })));
                sw.Stop();
                Console.WriteLine("Load Table of {0} elements ok. Duration {1}", NumberOfRecords, sw.ElapsedMilliseconds);
            }
            else table.Warmup();
            sw.Restart();
            // Делаем индекс
            var ha = new IndexHalfkeyImmutable<string>(path + "dyna_index_str_half")
            {
                Table = table,
                KeyProducer = va => (string)((object[])(((object[])va)[1]))[0],
                HalfProducer = k => k.GetHashCode()
            };
            ha.Scale = new ScaleCell(path + "dyna_index_str_half") { IndexCell = ha.IndexCell };
            bool tobuild_h_index = false;
            if (tobuild_h_index)
            {
                ha.Build();
            }
            else
            {
                ha.Warmup();
                //ha.BuildScale();
            }
            IndexDynamic<string, IndexHalfkeyImmutable<string>> h_index = new IndexDynamic<string, IndexHalfkeyImmutable<string>>(true)
            {
                Table = table,
                KeyProducer = va => (string)((object[])(((object[])va)[1]))[0],
                IndexArray = ha
            };
            Console.WriteLine("h_index Build ok. Duration {0}", sw.ElapsedMilliseconds);
            sw.Restart();
            int cnt = 0;
            for (int i = 0; i < 1000; i++)
            {
                int c = h_index.GetAllByKey(rnd.Next(NumberOfRecords * 3 / 2 - 1).ToString()).Count();
                if (c > 1) Console.WriteLine("Unexpected Error: {0}", c);
                cnt += c;
            }
            sw.Stop();
            Console.WriteLine("1000 GetAllByKey ok. Duration={0} cnt={1}", sw.ElapsedMilliseconds, cnt);
        }