コード例 #1
0
 public TreeWalker(HuffmanTreeBase tree, IDecodingInputStream input, IDecodingOutputStream output, long seqLength)
 {
     this.tree      = tree;
     this.input     = input;
     this.output    = output;
     this.seqLength = seqLength;
 }
コード例 #2
0
        public CodingTable BuildCodingTable(HuffmanTreeBase huffmanTree)
        {
            Guard.IsNotNull(huffmanTree, nameof(huffmanTree));
            TreeVisitor visitor = new TreeVisitor();

            huffmanTree.DoPOT(visitor);
            return(visitor.CodingTable);
        }
コード例 #3
0
        const int ChunkSize = 128 * 1024; // 128Kb throttling

        public EncodingToken CreateEncodingToken(IEncodingInputStream inputStream, CancellationToken cancellationToken)
        {
            Guard.IsNotNull(inputStream, nameof(inputStream));

            WeightsTable    weightsTable = BuildWeightsTable(inputStream, cancellationToken);
            HuffmanTreeBase huffmanTree  = BuildHuffmanTree(weightsTable);
            CodingTable     codingTable  = BuildCodingTable(huffmanTree);

            return(new EncodingToken(weightsTable, huffmanTree, codingTable));
        }
コード例 #4
0
        public void Decode(IDecodingInputStream inputStream, HuffmanTreeBase tree, IDecodingOutputStream outputStream, long sequenceLength, CancellationToken cancellationToken, IProgressHandler progress)
        {
            Guard.IsNotNull(inputStream, nameof(inputStream));
            Guard.IsNotNull(tree, nameof(tree));
            Guard.IsNotNull(outputStream, nameof(outputStream));
            Guard.IsNotNegative(sequenceLength, nameof(sequenceLength));

            const int chunkSize      = 0x20000 * 8; // 128Kb
            long      progressValue  = progress?.State.CastTo <CodingProgressState>()?.Value ?? 0;
            long      streamPosition = inputStream.Position;

            TreeWalker walker = new TreeWalker(tree, inputStream, outputStream, sequenceLength);

            while (!walker.Exhausted && !inputStream.IsEmpty)
            {
                if (!tree.Walk(walker))
                {
                    throw new ArgumentException();
                }
                // Throttling
                progressValue += inputStream.Position - streamPosition;
                streamPosition = inputStream.Position;

                if (progressValue >= chunkSize)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    progress?.Report(progressValue / 8, outputStream.Path);
                    progressValue %= 8;
                }
            }
            if (progress != null)
            {
                CodingProgressState progressState = (CodingProgressState)progress.State ?? new CodingProgressState();
                progress.State = progressState.WithValue(progressValue);
            }
        }
コード例 #5
0
 public EncodingToken(WeightsTable weightsTable, HuffmanTreeBase huffmanTree, CodingTable codingTable)
 {
     CodingTable  = codingTable;
     WeightsTable = weightsTable;
     HuffmanTree  = huffmanTree;
 }