コード例 #1
0
        public void ParralelBloking(bool save, bool compress)
        {
            var rangePartitioner = Partitioner.Create(0, file.BufferArraySize, file.BufferArraySize / file.CountThreads);
            var partBlockList    = new BlockList[file.CountThreads];

            for (int part = 0; part < file.CountPartReadFile; part++)
            {
                Parallel.ForEach(rangePartitioner,

                                 (range, loopState, threadNum) =>
                {
                    partBlockList[threadNum] = new BlockListReference();

                    for (int i = range.Item1; i < range.Item2; i++)
                    {
                        if (partBlockList[threadNum].CurrentBlockLength <= 4)
                        {
                            partBlockList[threadNum].AddToBlock(file.GetByte(i));
                            continue;
                        }

                        if (partBlockList[threadNum].CurrentBlockEntropy() < blockEntropy)
                        {
                            partBlockList[threadNum].AddToBlock(file.GetByte(i));
                        }
                        else
                        {
                            partBlockList[threadNum].CreateNewBlock();
                            partBlockList[threadNum].AddToBlock(file.GetByte(i));
                        }
                    }
                    partBlockList[threadNum].EndCurrentBlock();
                });
                for (int i = 0; i < partBlockList.Length; i++)
                {
                    BlockList.AddToList(partBlockList[i]);
                }
                if (save)
                {
                    SaveBlock(compress);
                }
                file.ReadNewPartFile();
            }

            Task <BlockList> EndOfFileTask = new Task <BlockList>(() => BlokingEndOfFile());

            EndOfFileTask.Start();
            EndOfFileTask.Wait();
            BlockList.AddToList(EndOfFileTask.Result);
            FileEntropy = BlockList.FullEntropy();

            if (save)
            {
                SaveBlock(compress);
            }
        }
コード例 #2
0
ファイル: BlockSaver.cs プロジェクト: Fenix506/Magister_Work
        private void SaveReferenceBlocks(BlockListReference blockList)
        {
            var file = new ByteFile(fullFileName);

            BinaryWriter writer;
            int          start;

            foreach (var block in blockList.Blocks)
            {
                if (block.GetFirst >= ByteFile.bufferSize)
                {
                    file.ReadNewPartFile();
                }
                start  = (int)(block.GetFirst % ByteFile.bufferSize);
                writer = new BinaryWriter(File.Create(fullDirectoryPath + "\\" + String.Format("{0:d8}", blockName)));
                blockName++;
                writer.Write(file.Buffer, start, block.CountBytesInBlock);
                writer.Close();
            }
        }