binary.java

来自「哈夫曼编码 文件压缩 使用java语言对文件进行编码压缩」· Java 代码 · 共 79 行

JAVA
79
字号
package hfmCompress;


public class Binary {
	protected  Binary left=null;
	protected Binary right=null;
	private int numberFound=0;//出现的频率
	private byte byteToCoded=0;//代表的字节
	private int nowCode=0;//本节点保存的编码
	private int nowLength=0;//本节点保存编码的长度
	
public Binary(){
	left=null;
	right=null;
	numberFound=0;
	byteToCoded=0;
	nowCode=0;
	nowLength=0;
}
public Binary(Binary leftArg,Binary rightArg){
	left=leftArg;
	right=rightArg;
	numberFound=0;
	byteToCoded=0;
	nowCode=0;
	nowLength=0;
}


public void addOneBitInLeft(boolean isLeftArg){
	if(isLeftArg){
		left.nowCode=(nowCode << 1) | 1;
		left.nowLength=nowLength+1;
	}else{
		right.nowCode=(nowCode << 1) | 0;
		right.nowLength=nowLength+1;
	}	
}

public boolean isLeaf(){
	return (this.left==null)&&(this.right==null);
}

public static Binary explainCode(long nowReadingLongArg,int nowMoveBits,Binary nowBinaryArg){
			if((nowReadingLongArg&(1<<nowMoveBits))!=0){
				return nowBinaryArg.left;
			}else{
				return nowBinaryArg.right;
			}	
}

public byte getByteToCoded() {
	return byteToCoded;
}
public void setByteToCoded(byte byteToCoded) {
	this.byteToCoded = byteToCoded;
}

public int getNowCode() {
	return nowCode;
}
public void setNowCode(int nowCodeArg) {
	this.nowCode = nowCodeArg;
}
public int getNowLength() {
	return nowLength;
}
public void setNowLength(int nowLengthArg) {
	this.nowLength = nowLengthArg;
}
public int getNumberFound() {
	return numberFound;
}
public void setNumberFound(int numberFoundArg) {
	this.numberFound = numberFoundArg;
}

}

⌨️ 快捷键说明

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