Exemple #1
0
        internal KVSequencePortion(DataNode dn,
                                   long offset_in_mainstream_for_seq, long offset_for_keys, long offset_for_offsets, long offset_for_dic1, long offset_for_dic2, PType tp_element)
        {
            this.dn                 = dn;
            this.offset_for_seq     = offset_in_mainstream_for_seq;
            this.offset_for_keys    = offset_for_keys;
            this.offset_for_offsets = offset_for_offsets;
            this.offset_for_dic1    = offset_for_dic1;
            this.offset_for_dic2    = offset_for_dic2;
            this.tp_element         = tp_element;
            PType tp_sequ = new PTypeSequence(new PTypeRecord(
                                                  new NamedType("key", new PType(PTypeEnumeration.integer)),
                                                  new NamedType("value", tp_element)));
            // Создадим базу данных, состоящую из последовательности и двух индексных массивов: массива ключей и массива офсетов
            PagedStream stream1 = new PagedStream(dn.fob, dn.main_stream, offset_in_mainstream_for_seq);

            keyvalue_seq = new PaCell(tp_sequ, stream1, false);
            PagedStream stream2 = new PagedStream(dn.fob, dn.main_stream, offset_for_keys);

            keys = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.integer)), stream2, false);
            //keys_arr = keys.IsEmpty ? new int[0] : keys.Root.ElementValues().Cast<int>().ToArray();
            PagedStream stream3 = new PagedStream(dn.fob, dn.main_stream, offset_for_offsets);

            offsets = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.longinteger)), stream3, false);
        }
Exemple #2
0
 public TableView(string path_name, PType e_type)
 {
     tp_rec = new PTypeRecord(
         new NamedType("deleted", new PType(PTypeEnumeration.boolean)),
         new NamedType("evalue", e_type));
     table_cell = new PaCell(new PTypeSequence(tp_rec), path_name + ".pac", false);
 }
Exemple #3
0
        //// Идея хорошая, но надо менять схему реализации
        //private GroupedEntities getable;
        //private Dictionary<string, object[]> geHash;

        public TripleStore(string path)
        {
            this.path = path;
            InitTypes();

            otriples    = new PaCell(tp_otriple_seq, path + "otriples.pac", false);
            otriples_op = new PaCell(tp_otriple_seq, path + "otriples_op.pac", false);
            dtriples    = new PaCell(tp_dtriple_seq, path + "dtriples.pac", false);
            dtriples_sp = new PaCell(tp_dtriple_spf, path + "dtriples_spf.pac", false);
            oscale      = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.integer)), path + "oscale.pac", false);
            if (!oscale.IsEmpty)
            {
                CalculateRange();
            }
            if (!otriples.IsEmpty)
            {
                OpenCreateIndexes();
            }
            ewt = new EntitiesWideTable(path, new[]
            {
                new DiapasonScanner <string>(otriples, ent => (string)((object[])ent.Get())[0]),
                new DiapasonScanner <string>(otriples_op, ent => (string)((object[])ent.Get())[2]),
                new DiapasonScanner <string>(dtriples_sp, ent => (string)((object[])ent.Get())[0])
            });
            ewtHash = new EntitiesMemoryHashTable(ewt);
            ewtHash.Load();


            //getable = new GroupedEntities(path); // Это хорошая идея, но нужно менять схему реализации
            //getable.CheckGroupedEntities();
            //geHash = getable.GroupedEntitiesHash();
        }
Exemple #4
0
 public NameTableInt(string path)
 {
     this.path    = path;
     this.nc_cell = new PaCell(new PTypeSequence(new PTypeRecord(
                                                     new NamedType("code", new PType(PTypeEnumeration.integer)),
                                                     new NamedType("name", new PType(PTypeEnumeration.sstring))
                                                     )),
                               path + "_nc.pac", false);
     if (nc_cell.IsEmpty)
     {
         nc_cell.Fill(new object[0]);
     }
     //PaEntry nc_entry =
     this.n_index = new DynaIndex <string>(path, "_n", off =>
     {
         PaEntry ent = nc_cell.Root.Element(0); // это возможно только если есть элемент, надо проверить
         ent.offset  = (long)off;
         return((string)ent.Field(1).Get());
     });
     this.c_index = new DynaIndex <int>(path, "_c", off =>
     {
         PaEntry ent = nc_cell.Root.Element(0); // это возможно только если есть элемент, надо проверить
         ent.offset  = (long)off;
         return((int)ent.Field(0).Get());
     });
     // Кодирование будет - номер записи, в которую попал идентификатор
     next_code = (int)n_index.Count();
     // Количество записей должно совпадать
     if (n_index.Count() != c_index.Count())
     {
         throw new Exception("Assert error: 9434");
     }
 }
        public virtual void ReCreate(KeyValuePair <int, int>[] edges)
        {
            Dictionary <int, HashSet <int> > direct;
            var roots = ReCreateDirectAndRoots(edges, out direct);

            maxChildrenCount = direct.Max(pair => pair.Value.Count);

            height = direct.Any() ? roots.Max(i => GetTreeHeight(i)) : 0;//edges.Count();

            if (roots.Count > maxChildrenCount)
            {
                maxChildrenCount = roots.Count;
            }

            codingIndex.IndexArray.Table.Clear();
            for (int i = 1; i < roots.Count + 1; i++)
            {
                CreateCoding(roots[i - 1], i, direct);
            }

            PType treePType = Enumerable.Range(0, height).
                              Aggregate(new PType(PTypeEnumeration.integer),
                                        (PType res, int level) =>
                                        new PTypeRecord(new NamedType("value", new PType(PTypeEnumeration.integer)),
                                                        new NamedType("children", new PTypeSequence(res))));

            paCell = new PaCell(treePType, "../../tree.pa", false);
            ReCreate(direct);

            direct.Clear();
        }
        protected object Read(PaCell fromCell, long offset)
        {
            var paEntry = fromCell.Root.Element(0);

            paEntry.offset = offset;
            return(paEntry.Get());
        }
Exemple #7
0
        // Использовать надо следующим образом:

        public static void Test()
        {
            PType objectTriplets = new PTypeSequence(new PTypeRecord(
                                                         new NamedType("deleted", new PType(PTypeEnumeration.boolean)),
                                                         new NamedType("s", new PType(PTypeEnumeration.sstring)),
                                                         new NamedType("p", new PType(PTypeEnumeration.sstring)),
                                                         new NamedType("o", new PType(PTypeEnumeration.sstring))
                                                         ));
            // инициализация таблицы
            var directCell = new PaCell(objectTriplets, "path", false);

            // Более компактный способ заполнения ячейки
            directCell.Clear();
            directCell.Fill(new object[0]);
            //foreach (var element in elements) // Закомментарил из-за отсутствия перечислителя elements
            {
                directCell.Root.AppendElement(new object[] { false, "subject", "predicate", "object" });
            }
            directCell.Flush();
            // Создание индекса
            FixedIndex <SubjPred> sp_index = new FixedIndex <SubjPred>("..sp", directCell.Root, entry =>
            {
                return(new SubjPred()
                {
                    subj = (string)entry.Field(1).Get(), pred = (string)entry.Field(1).Get()
                });
            });
        }
Exemple #8
0
 public TableView(System.IO.Stream stream, PType e_type)
 {
     tp_rec = new PTypeRecord(
         new NamedType("deleted", new PType(PTypeEnumeration.boolean)),
         new NamedType("evalue", e_type));
     table_cell = new PaCell(new PTypeSequence(tp_rec), stream, false);
 }
Exemple #9
0
        //// Идея хорошая, но надо менять схему реализации
        //private GroupedEntities getable;
        //private Dictionary<int, object[]> geHash;

        public TripleStoreInt(string path)
        {
            this.path = path;
            InitTypes();
            otriples    = new PaCell(tp_otriple_seq, path + "otriples.pac", false);
            otriples_op = new PaCell(tp_otriple_seq, path + "otriples_op.pac", false);
            dtriples    = new PaCell(tp_dtriple_seq, path + "dtriples.pac", false);
            dtriples_sp = new PaCell(tp_dtriple_spf, path + "dtriples_spf.pac", false);

            scale = new ScaleCell(path);
            if (!otriples.IsEmpty)
            {
                OpenCreateIndexes();
            }
            ewt = new EntitiesWideTable(path, new DiapasonScanner <int>[]
            {
                new DiapasonScanner <int>(otriples, ent => (int)((object[])ent.Get())[0]),
                new DiapasonScanner <int>(otriples_op, ent => (int)((object[])ent.Get())[2]),
                new DiapasonScanner <int>(dtriples_sp, ent => (int)((object[])ent.Get())[0])
            });
            ewtHash = new EntitiesMemoryHashTable(ewt);
            ewtHash.Load();

            //getable = new GroupedEntities(path); // Это хорошая идея, но нужно менять схему реализации
            //getable.CheckGroupedEntities();
            //geHash = getable.GroupedEntitiesHash();
        }
        public void Load(int tripletsCountLimit, params string[] filesPaths)
        {
            directCell.Close();
            dataCell.Close();

            File.Delete(dataCellPath);
            File.Delete(directCellPath);

            directCell = new PaCell(ptDirects, directCellPath, false);
            dataCell   = new PaCell(ptData, dataCellPath, false);

            var directSerialFlow = (ISerialFlow)directCell;
            var dataSerialFlow   = (ISerialFlow)dataCell;

            directSerialFlow.StartSerialFlow();
            dataSerialFlow.StartSerialFlow();
            directSerialFlow.S();
            dataSerialFlow.S();
            ReaderRDF.ReaderRDF.ReadFiles(tripletsCountLimit, filesPaths, (id, property, value, isObj, lang) =>
            {
                if (isObj)
                {
                    directSerialFlow.V(new object[] { id, property, value });
                }
                else
                {
                    dataSerialFlow.V(new object[] { id, property, value, lang ?? "" });
                }
            });
            directSerialFlow.Se();
            dataSerialFlow.Se();
            directSerialFlow.EndSerialFlow();
            dataSerialFlow.EndSerialFlow();
        }
Exemple #11
0
        private void PrepareArrays()
        {
            // Создание и упорядочивание дополнительных структур

            otriples_op.Close();
            otriples.Close();
            if (File.Exists(otriplets_op_filePath + "tmp"))
            {
                File.Delete(otriplets_op_filePath + "tmp");
            }
            File.Copy(otriples_filePath + "tmp", otriplets_op_filePath + "tmp");
            otriples_op = new PaCell(tp_otriple_seq, otriplets_op_filePath + "tmp", false);
            otriples    = new PaCell(tp_otriple_seq, otriples_filePath + "tmp", false);
            //otriples_op.Clear();
            //otriples_op.Fill(new object[0]);
            //foreach (object v in otriples.Root.ElementValues()) otriples_op.Root.AppendElement(v);
            //otriples_op.Flush();

            //foreach (PaEntry entry in dtriples.Root.Elements())
            //{
            //    int s = (int)entry.Field(0).Get();
            //    int p = (int)entry.Field(1).Get();
            //    dtriples_sp.Root.AppendElement(new object[] { s, p, entry.offset });
            //}
            //       dataCell.Root.Scan((off, pobj) =>
            //{
            //    object[] tri = (object[])pobj;
            //    int s = (int)tri[0];
            //    int p = (int)tri[1];
            //    dtriples_sp.Root.AppendElement(new object[] { s, p, off });
            //    return true;
            //});
            //dtriples_sp.Flush();
        }
        public void MakeIndexed()
        {
            // Подготовим индексы для заполнения
            n_index.Close();
            c_index.Close();
            n_index = new PaCell(tp_ind, niCell, false);
            n_index.Clear();
            n_index.Fill(new object[0]);
            c_index = new PaCell(tp_ind, ciCell, false);
            c_index.Clear();
            c_index.Fill(new object[0]);
            foreach (PaEntry ent in nc_cell.Root.Elements())
            {
                long off = ent.offset;
                n_index.Root.AppendElement(off);
                c_index.Root.AppendElement(off);
            }
            n_index.Flush();
            c_index.Flush();

            // Индекс n_index отсортирован по построению. Надо сортировать c_index
            PaEntry nc_entry = nc_cell.Root.Element(0);

            c_index.Root.SortByKey(obj =>
            {
                nc_entry.offset = (long)obj;
                return(nc_entry.Field(0).Get());
            });
            Open(true);
        }
Exemple #13
0
 /// <summary>
 /// Индекс конструируется для последовательности записей, расположенной в ячейке свободного формата
 /// </summary>
 /// <param name="indexName">имя индекса вместе с путем в файловой системе</param>
 /// <param name="table">Таблица</param>
 /// <param name="i_field">номер индексируемой записи</param>
 public FreeIndex(string indexName, PaEntry table, int i_field)
 {
     this.table   = table;
     this.i_field = i_field;
     index_cell   = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.longinteger)), indexName + ".pac", false);
     columnType   = ((PTypeRecord)((PTypeSequence)table.Type).ElementType).Fields[i_field].Type;
 }
Exemple #14
0
 public ScaleCell(PaCell oscale)
 {
     this.oscale = oscale;
     if (!oscale.IsEmpty)
     {
         CalculateRange();
     }
 }
Exemple #15
0
        public DataNode(string path)
        {
            this.path = path;
            //this.tp_element = tp_element;
            string     dbpath     = path + "DataNodeStorage.bin";
            bool       fob_exists = File.Exists(dbpath);
            FileStream fs         = new FileStream(dbpath, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            fob = new FileOfBlocks(fs);
            Stream first_stream = fob.GetFirstAsStream();

            if (!fob_exists)
            {
                PagedStream.InitPagedStreamHead(first_stream, 8L, 0, PagedStream.HEAD_SIZE);
                fob.Flush();
            }
            main_stream = new PagedStream(fob, fob.GetFirstAsStream(), 8L);

            //long sz = PagedStream.HEAD_SIZE;

            // Если main_stream нулевой длины, надо инициировать конфигурацию стримов
            bool toinit = main_stream.Length == 0;

            if (toinit)
            {
                // инициируем 2 головы для потоков
                PagedStream.InitPagedStreamHead(main_stream, 0L, 0L, -1L);
                PagedStream.InitPagedStreamHead(main_stream, PagedStream.HEAD_SIZE, 0L, -1L);
                //PagedStream.InitPagedStreamHead(main_stream, 2 * sz, 0L, -1L);

                main_stream.Flush(); fob.Flush();
            }
            // создадим 2 потока
            Stream stream_common_params = new FileStream(path + "common.pac", FileMode.OpenOrCreate, FileAccess.ReadWrite); //new PagedStream(fob, main_stream, 0L);
            Stream stream_SP_list       = new FileStream(path + "splist.pac", FileMode.OpenOrCreate, FileAccess.ReadWrite); //new PagedStream(fob, main_stream, 1 * PagedStream.HEAD_SIZE);

            //PagedStream stream_offsets = new PagedStream(fob, main_stream, 2 * sz); // пока не знаю для чего...

            // Создадим ячейки
            tp_common = new PTypeRecord(
                new NamedType("configuration", tp_configuration));
            cell_common = new PaCell(tp_common, stream_common_params, false);
            tp_list     = new PTypeSequence(KVSequencePortion.tp_pobj);
            cell_list   = new PaCell(tp_list, stream_SP_list, false);

            // Инициализируем
            if (toinit)
            {
                cell_common.Fill(new object[] { new object[0] });
                cell_list.Fill(new object[0]);
            }
            common_data = cell_common.Root.Get();
            foreach (object[] p in cell_list.Root.ElementValues())
            {
                KVSequencePortion kvsp = new KVSequencePortion(this, p);
                sportion_list.Add(kvsp);
            }
        }
Exemple #16
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();
        }
Exemple #17
0
 public ScaleCell(System.IO.Stream stream)
 {
     this.scell = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.longinteger)),
                             stream, false);
     if (!this.scell.IsEmpty)
     {
         this.n = this.scell.Root.Count();
     }
 }
        private static void Check(PType tp_rec, PaCell cell, Func <int, long> OffsetByKey, int cod)
        {
            var entry = cell.Root.Element(0);

            entry.SetOffset(OffsetByKey(cod));
            var rec = entry.Get();

            Console.WriteLine(tp_rec.Interpret(rec));
        }
Exemple #19
0
        public IndexHalfkeyImmutable(System.IO.Stream stream)
        {
            PType tp_hkey  = new PType(PTypeEnumeration.integer);
            PType tp_index = new PTypeSequence(new PTypeRecord(
                                                   new NamedType("halfkey", tp_hkey),
                                                   new NamedType("offset", new PType(PTypeEnumeration.longinteger))));

            index_cell = new PaCell(tp_index, stream, false);
        }
Exemple #20
0
 public UnitTestCells()
 {
     tp_rec = new PTypeRecord(
         new NamedType("id", new PType(PTypeEnumeration.integer)),
         new NamedType("name", new PType(PTypeEnumeration.sstring)),
         new NamedType("age", new PType(PTypeEnumeration.real)));
     ss   = new MemoryStream();
     cell = new PaCell(tp_rec, ss, false);
 }
Exemple #21
0
        public IndexHalfkeyImmutable(string path_name)
        {
            PType tp_hkey  = new PType(PTypeEnumeration.integer);
            PType tp_index = new PTypeSequence(new PTypeRecord(
                                                   new NamedType("halfkey", tp_hkey),
                                                   new NamedType("offset", new PType(PTypeEnumeration.longinteger))));

            index_cell = new PaCell(tp_index, path_name + ".pac", false);
        }
Exemple #22
0
 public LiteralStore(string path, NameSpaceStore nameSpaceStore) : base(path, nameSpaceStore)
 {
     dataCellPath = path + "data.pac";
     dataCell     = new PaCell(tp_data_seq, dataCellPath, false);
     if (dataCell.IsEmpty)
     {
         dataCell.Fill(new object[0]);
     }
 }
Exemple #23
0
 private Func <object, Key> keyFunction; // превращает объектное представление элемента в ключ
 public DiapasonElementsScanner(PaCell sequ, Func <object, Key> keyFunction)
 {
     this.cell        = sequ;
     this.keyFunction = keyFunction;
     if (!this.cell.IsEmpty)
     {
         Start();
     }
 }
Exemple #24
0
 public DiapasonScanner(PaCell sequ, Func <PaEntry, Key> keyFunction)
 {
     this.cell        = sequ;
     this.keyFunction = keyFunction;
     if (!this.cell.IsEmpty)
     {
         Start();
     }
 }
Exemple #25
0
 // Конструктор
 public TGraph(string path)
 {
     LoadTypes();
     this.path = path;
     otriples  = new PaCell(tp_otriples, path + "otriples.pac", false);
     literals  = new PaCell(tp_rliteral_seq, path + "literals.pac", false);
     dtriples  = new PaCell(tp_dtriples, path + "dtriples.pac", false);
     tree_fix  = new PxCell(tp_entitiesTree, path + "tree_fix.pxc", false);
     FillDictionary();
 }
Exemple #26
0
 public FixedIndex(string indexName, PaEntry table, Func <PaEntry, Tkey> keyProducer)
 {
     this.table       = table;
     this.keyProducer = keyProducer;
     index_cell       = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.longinteger)), indexName + ".pac", false);
     if (index_cell.IsEmpty)
     {
         index_cell.Fill(new object[0]);
     }
 }
Exemple #27
0
 private void Open(bool readOnlyMode)
 {
     objPredicates     = new PaCell(tp_entities_column, objPredicatesColumn_filePath, readOnlyMode);
     objects           = new PaCell(tp_entities_column, objectsColumn_filePath, readOnlyMode);
     inversePredicates = new PaCell(tp_entities_column, invPredicatesColumn_filePath, readOnlyMode);
     inverses          = new PaCell(tp_entities_column, invSubjectsColumn_filePath, readOnlyMode);
     dataPredicates    = new PaCell(tp_entities_column, dataPredicatesColumn_filePath, readOnlyMode);
     data = new PaCell(tp_Data_column, dataColumn_filePath, readOnlyMode);
     // LiteralStore.Literals.Open(readOnlyMode);
 }
Exemple #28
0
        public SemiIndex(string indexName, PType field_type)
        {
            PType tp_index = new PTypeSequence(new PTypeRecord(
                                                   new NamedType("key", field_type),
                                                   new NamedType("value", new PType(PTypeEnumeration.longinteger)),
                                                   new NamedType("deleted", new PType(PTypeEnumeration.boolean))));

            acell = new PaCell(tp_index, indexName + ".pac", false);
            xcell = new PxCell(tp_index, indexName + ".pxc", false);
        }
Exemple #29
0
 private void InitCells()
 {
     if (!File.Exists(path + "triplets.pac") ||
         !File.Exists(path + "graph_x.pxc"))
     {
         return;
     }
     triplets    = new PaCell(tp_triplets, path + "triplets.pac");
     any_triplet = triplets.Root.Element(0);
     graph_x     = new PxCell(tp_graph, path + "graph_x.pxc");
 }
Exemple #30
0
        public ScaleCell(string index_path_name)
        {
            //this.index_cell = index_cell;

            this.scell = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.longinteger)),
                                    index_path_name + "_scale.pac", false);
            if (!this.scell.IsEmpty)
            {
                this.n = this.scell.Root.Count();
            }
        }