Пример #1
0
        /// <summary>
        /// Tworzy indeks na plik macierzy
        /// 
        /// Użycie dozwolone w trybie Mode.CREATE.
        /// </summary>
        public void createIndex()
        {
            IxHalMatrixReader halReader = new IxHalMatrixReader(this.workingDirPath);

            using (BinaryWriter indexWriter = new BinaryWriter(File.Create(workingDirPath + "halMatrix.idx")))
            {
                KeyValuePair<uint, ArrayRow<uint>> row;
                uint lastAddedId = 0;
                long positionBefore = halReader.getPositionInFile();

                while ((row = halReader.readNextArrayRow()).Key != 0)
                {
                    while (lastAddedId++ != row.Key)
                    {
                        indexWriter.Write((long)-1);
                    }

                    indexWriter.Write(positionBefore);

                    positionBefore = halReader.getPositionInFile();
                }
            }

            halReader.finalize();
        }
Пример #2
0
        /// <summary>
        /// Optymalizuje macierz HAL zapisaną na dysku
        /// 
        /// Zostaną usunięte wiersze i komórki tokenów, które wystąpiły mniej niż IxSettings.halMinCount razy.
        /// </summary>
        public void optimizeMatrix()
        {
            IxHalMatrixReader reader = new IxHalMatrixReader(workingDirPath);

            if (IxSettings.consoleDebug)
                Console.WriteLine("Calculating tokens for removal set...");

            HashSet<uint> tokenRemovalSet = new HashSet<uint>();

            KeyValuePair<uint, ArrayRow<uint>> row = reader.readNextArrayRow();

            while (row.Key != 0)
            {
                if (row.Value.count < IxSettings.halMinCount)
                    tokenRemovalSet.Add(row.Key);

                row = reader.readNextArrayRow();
                reader.getPositionInFile();
            }

            reader.reset();

            if (IxSettings.consoleDebug)
                Console.WriteLine("Removing rows and cells...");

            row = reader.readNextArrayRow();

            using (BinaryWriter writer = new BinaryWriter(File.Create(altWorkingDirPath + "halMatrixOptimized.dat")))
            {
                while (row.Key != 0)
                {
                    if (!tokenRemovalSet.Contains(row.Key))
                    {
                        Row<uint> newRow = new Row<uint>();
                        newRow.count = row.Value.count;

                        for (int i = 0, count = row.Value.cells.Length; i < count; i++)
                        {
                            if (!tokenRemovalSet.Contains(row.Value.cells[i].Key))
                                newRow.cells.Add(row.Value.cells[i].Key, row.Value.cells[i].Value);
                        }

                        IxHalStorage.writeRow(writer, new KeyValuePair<uint,Row<uint>>(row.Key, newRow));
                    }

                    row = reader.readNextArrayRow();
                    reader.getPositionInFile();
                }
            }

            reader.finalize();

            File.Delete(workingDirPath + "halMatrix.dat");
            File.Move(altWorkingDirPath + "halMatrixOptimized.dat", workingDirPath + "halMatrix.dat");
        }