⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 floatcompressorold.h

📁 对浮点型数据进行压缩
💻 H
字号:
/*
===============================================================================

	FILE:	floatcompressorold.h
	
	CONTENTS:
	
    first codes the sign, then the exponent, then the mantissa
    
    - codes the sign in dependence of the predicted exponent
    - codes the exponent in dependence of the predicted exponent only if the
      sign was correct ...
      ... otherwise encodes a single-context exponent distribution
    - codes a corrector between predicted and actual mantissa in dependence
      of the actual exponent.
      for this it breaks the corrector into three chunks of 11 and 11 bits and
      a sign bit and codes them while using the exponent to switch contexts
	
    the compressor has three contexts to compress (none, last, across) in case
    you have predictions of differing quality. i use them like this:

    none for floats without prediction (uses the last float it saw)
    last for floats with delta predictions
    across for floats with the best predictions

    offering three contexts is somewhat arbitrary and a leftover from the
    fact that there were three position predictions of different quality
    (none, last, across) ... but it should should work for now ...

  PROGRAMMERS:
	
		martin isenburg@cs.unc.edu
	
	COPYRIGHT:
	
		Copyright (C) 2000  Martin Isenburg (isenburg@cs.unc.edu)
		
		This software is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	
	CHANGE HISTORY:
	
		30 September 2003 -- created initial version after Ajith's good-bye lunch
	
===============================================================================
*/
#ifndef FLOAT_COMPRESSOR_OLD_H
#define FLOAT_COMPRESSOR_OLD_H

#include "mydefs.h"

#include "rangeencoder.h"
#include "rangedecoder.h"
#include "rangemodel.h"

class FloatCompressorOld
{
public:

	// SetPrecision:
	void SetPrecision(I32 iBits);
	// GetPrecision:
	I32 GetPrecision();

	// UpdateMinMax:
	void UpdateMinMax(F32 fFloat);
	// SetMinMax:
	void SetMinMax(F32 fMin, F32 fMax);
	// GetMinMax:
	void GetMinMax(F32& fMin, F32& fMax);

	// SetupCompressor:
	void SetupCompressor(RangeEncoder* re, bool within=false);
	void FinishCompressor(bool within=false);

	// Compress:
	F32 CompressNone(F32 fReal);
	F32 CompressLast(F32 fPred, F32 fReal);
	F32 CompressAcross(F32 fPred, F32 fReal);
	F32 CompressWithin(F32 fPred, F32 fReal);

	// Decompress:
	void SetupDecompressor(RangeDecoder* rd, bool within=false);
	void FinishDecompressor(bool within=false);

	// Compress:
	F32 DecompressNone();
	F32 DecompressLast(F32 fPred);
	F32 DecompressAcross(F32 fPred);
	F32 DecompressWithin(F32 fPred);

	// Constructor:
	FloatCompressorOld();
	// Destructor:
  ~FloatCompressorOld();

  // for experiments
  int GetTotalBytes();
  int GetSignBytes();
  int GetExponentBytes();
  int GetMantissaBytes();

private:
	// Private Functions
	void alloc_range_tables(bool within);
	void dealloc_range_tables(bool within);

	void reset_precision();
	void update_precision(float number);

	void compress_exponent(int exponentPred, int exponentReal, RangeEncoder* re_exponent, RangeModel** rmExponent);
	int decompress_exponent(int exponentPred, RangeDecoder* rd_exponent, RangeModel** rmExponent);

	void compress_sign(int exponent, int sign, RangeEncoder* re_sign, RangeModel** rmSign);
	int decompress_sign(int exponent, RangeDecoder* rd_sign, RangeModel** rmSign);

	int compress_mantissa(int exponent, int mantissaPred, int mantissaReal, RangeEncoder* re_mantissa, RangeModel** rmMantissaHigh, RangeModel** rmMantissaLow);
	int decompress_mantissa(int exponent, int mantissaPred, RangeDecoder* rd_mantissa, RangeModel** rmMantissaHigh, RangeModel** rmMantissaLow);

  // Private Variables
	RangeEncoder* ae_sign_none;
	RangeEncoder* ae_exponent_none;
	RangeEncoder* ae_mantissa_none;

	RangeEncoder* ae_sign_last;
	RangeEncoder* ae_exponent_last;
	RangeEncoder* ae_mantissa_last;

	RangeEncoder* ae_sign_across;
	RangeEncoder* ae_exponent_across;
	RangeEncoder* ae_mantissa_across;

	RangeEncoder* ae_sign_within;
	RangeEncoder* ae_exponent_within;
	RangeEncoder* ae_mantissa_within;

  RangeDecoder* ad_sign_none;
	RangeDecoder* ad_exponent_none;
	RangeDecoder* ad_mantissa_none;

	RangeDecoder* ad_sign_last;
	RangeDecoder* ad_exponent_last;
	RangeDecoder* ad_mantissa_last;

	RangeDecoder* ad_sign_across;
	RangeDecoder* ad_exponent_across;
	RangeDecoder* ad_mantissa_across;

	RangeDecoder* ad_sign_within;
	RangeDecoder* ad_exponent_within;
	RangeDecoder* ad_mantissa_within;

	RangeModel** rmSignNone;
	RangeModel** rmExponentNone;
	RangeModel** rmMantissaNoneLow;
	RangeModel** rmMantissaNoneHigh;
  RangeModel** rmCorrectorBitsNone;

	RangeModel** rmSignLast;
	RangeModel** rmExponentLast;
	RangeModel** rmMantissaLastLow;
	RangeModel** rmMantissaLastHigh;
  RangeModel** rmCorrectorBitsLast;

	RangeModel** rmSignAcross;
	RangeModel** rmExponentAcross;
	RangeModel** rmMantissaAcrossLow;
	RangeModel** rmMantissaAcrossHigh;
  RangeModel** rmCorrectorBitsAcross;

	RangeModel** rmSignWithin;
	RangeModel** rmExponentWithin;
	RangeModel** rmMantissaWithinLow;
	RangeModel** rmMantissaWithinHigh;
  RangeModel** rmCorrectorBitsWithin;

	RangeModel** rmZeroOrExtremeValue;
	RangeModel** rmPositiveOrNegativeValue;

	int* bits_for_mantissa;
	int range_exponent;
	float min_float;
	float max_float;
	int bits;

  // for statistics only
  int** stats_on_k;
  int num_predictions_none;
  int num_predictions_last;
  int num_predictions_across;
  int num_predictions_within;
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -