Beispiel #1
0
 public Block(int index, short exponent, byte nb, bool isSignNegative, long biggestNumber, Blockfinding.Blockfinding context, Blockfinding.Blockfinding.Methods method, bool hasPattern)
 {
     Index            = index;
     HasExponent      = exponent != 0;
     HasPattern       = hasPattern;
     Pattern          = PatternType.Same;
     Method           = context.GetInitializedMethod(method);
     Exponent         = exponent;
     NeededBits       = nb;
     AbsoluteSign     = true;
     IsSignNegative   = isSignNegative;
     BiggestNumber    = biggestNumber;
     OverrideGlobalNb = false;
     Length           = 0;
 }
Beispiel #2
0
        private void PostCompressionOptimisation()
        {
            // creating huffman data now so we can leave out values that are in a block ;)
            // results in better speed + more accuracy
            #region calculating huffman data
            var currentBlockIndex  = 0;
            var valueCount         = Values.Count;
            var blockCount         = Blocks.Count;
            var nextStop           = blockCount == 0 ? valueCount : Blocks[currentBlockIndex].Index;
            var currentBlockLength = blockCount == 0 ? 0 : Blocks[currentBlockIndex].Length;
            var totalBlockValues   = currentBlockLength;

            //if (!Metadata.NoExponent)
            //{
            //    _huffman = new HuffmanCreator((ushort)Math.Pow(2, 10));

            //    var huffIndex = 0;
            //    while (huffIndex < valueCount)
            //    {
            //        for (; huffIndex < nextStop; huffIndex++)
            //        {
            //            _huffman.AddOccurence(Values[huffIndex].Exponent);
            //        }

            //        if (++currentBlockIndex >= Blocks.Count)
            //            nextStop = valueCount;
            //        else
            //        {
            //            huffIndex += currentBlockLength;
            //            nextStop = Blocks[currentBlockIndex].Index;
            //            currentBlockLength = Blocks[currentBlockIndex].Length;
            //            totalBlockValues += currentBlockLength;
            //        }
            //    }
            //}
            _totalPostCompressionOptimisationBlockValues = totalBlockValues;
            #endregion

            #region putting multiple "pattern same" blocks to one pingpong block

            if (Blocks.Count == 0)
            {
                return;
            }
            var  ppp          = (PatternPingPongCompression)_blockfinding.GetInitializedMethod(Blockfinding.Blockfinding.Methods.PatternPingPong);
            var  recentBlock  = Blocks[0];
            byte lastppLength = 0;
            for (var i = 1; i < Blocks.Count; i++)
            {
                var currentBlock = Blocks[i];

                if (currentBlock.HasPattern && currentBlock.Pattern == Block.PatternType.Same && recentBlock.HasPattern)
                {
                    if (recentBlock.Pattern == Block.PatternType.Pingpong && lastppLength * recentBlock.Length + recentBlock.Index == currentBlock.Index)
                    {
                        var initValue             = Values[currentBlock.Index];
                        var recentBlockRealLength = lastppLength * recentBlock.Length;
                        if (currentBlock.Length != lastppLength || initValue.Number == Values[recentBlock.Index + recentBlockRealLength - 1].Number || initValue.Number != Values[recentBlock.Index + recentBlockRealLength - 1 - lastppLength].Number)
                        {
                            continue;
                        }
                        recentBlock.Length++;
                        Blocks[i - 1] = recentBlock;
                        Blocks.RemoveAt(i--);
                    }
                    else if (recentBlock.Pattern == Block.PatternType.Same && recentBlock.Index + recentBlock.Length == currentBlock.Index && currentBlock.Length == recentBlock.Length)
                    {
                        recentBlock.Pattern = Block.PatternType.Pingpong;
                        recentBlock.Method  = ppp;
                        ppp.PingPongPatternLengths.Add(new PatternPingPongCompression.PatternPingPongMetadata(recentBlock.Length, recentBlock.Index));
                        lastppLength       = recentBlock.Length;
                        recentBlock.Length = 2;
                        Blocks[i - 1]      = recentBlock;
                        Blocks.RemoveAt(i--);
                    }
                    else
                    {
                        recentBlock = currentBlock;
                    }
                }
            }
            #endregion
        }